How to write tags

Augie Fackler durin42 at gmail.com
Thu Dec 24 21:06:01 CST 2009


On Dec 24, 2009, at 8:37 PM, Frank A. Kingswood wrote:

> Steve Borho wrote:
>> Slightly off-topic, but you may want to store the perforce tags in a
>> localtags file to avoid this memctx issue, and to avoid the future
>> issue of knowing not to push changes to the .hgtags file back to
>> perforce.

hgsubversion did this, and honestly I can't recommend the approach.

> I've just implemented the writes to .hgtags, that was not too bad.  
> Most difficult was finding out where to get the file data - the API  
> spec does not really cover much. The convert extension does not do  
> this yet either.
>> Since p4 tags are not allowed to move (AFAIK), they don't need to be
>> versioned like native tags.
>>
> No, p4 tags can move, and often do. There even appears to be  
> something to make them move automagically (p4 help labelsync???)

At this point, it sounds like maybe we should make some kind of set of  
context manipulation tools that your Perforce integration tool and  
hgsubversion could share that'd be part of hg itself. hgsubversion has  
to deal with mutability of svn tags as well, and it's mostly annoying  
more than anything (once you finish the thought experiment to get to a  
workable solution).

Does Perforce have a notion of first-class tags? If so, then pushing a  
change to .hgtags could just create the correct matching tag in  
perforce land. The tricky part would be automatically rewriting the  
file (probably need to add some sort of context-filtering closure  
argument to rebase) to always have a valid revision hash for the tag.

> Frank
>
> # HG changeset patch
> # User Frank Kingswood <frank at kingswood-consulting.co.uk>
> # Date 1261708108 0
> # Node ID 3ef91c14b4fba9c8c026525bba063da6caab5d86
> # Parent  74b50742f9a1326aaa922ad0f55d1927bb300404
> [mq]: p4-tags
>
> diff -r 74b50742f9a1 -r 3ef91c14b4fb perfarce.py
> --- a/perfarce.py    Thu Dec 24 10:08:20 2009 +0000
> +++ b/perfarce.py    Fri Dec 25 02:28:28 2009 +0000
> @@ -317,6 +317,18 @@
>        return mode, contents
> +    def labels(self, change):
> +        'Return p4 labels a.k.a. tags at the given changelist'
> +
> +        tags = []
> +        for d in self.run('labels @%d,%d' % (change, change)):
> +            l = d.get('label')
> +            if l:
> +                tags.append(l)
> +
> +        return tags
> +
> +
>    @staticmethod
>    def pullcommon(original, ui, repo, source, **opts):
>        'Shared code for pull and incoming'
> @@ -486,10 +498,12 @@
>    client, p4rev, p4id, changes = r
>    for c in changes:
>        desc, user, date, files = client.describe(c, files=ui.verbose)
> +        tags = client.labels(c)
>        ui.write(_('changelist:  %d\n') % c)
>        # ui.write(_('branch:      %s\n') % branch)
> -        # ui.write(_('tag:         %s\n') % tag)
> +        for tag in tags:
> +            ui.write(_('tag:         %s\n') % tag)
>        # ui.write(_('parent:      %d:%s\n') % parent)
>        ui.write(_('user:        %s\n') % user)
>        ui.write(_('date:        %s\n') % util.datestr(date))
> @@ -524,6 +538,7 @@
>        mode, contents = client.getfile(revcache[fn], c)
>        return context.memfilectx(fn, contents, 'l' in mode, 'x' in  
> mode, None)
> +    tags = []
>    for c in changes:
>        desc, user, date, files = client.describe(c, files=True)
> @@ -545,8 +560,34 @@
>        p4rev = repo.commitctx(ctx)
>        ctx = repo[p4rev]
> +
> +        labels = client.labels(c)
> +        if labels:
> +            tags.append((c, ctx.hex(), labels))
> +
>        ui.note(_('added changeset %d:%s\n') % (ctx.rev(), ctx))
> +    if tags:
> +        if '.hgtags' in ctx:
> +            tagdata = ctx.filectx('.hgtags').data()
> +        else:
> +            tagdata = ''
> +
> +        desc = ['p4 tags']
> +        for t in tags:
> +            for l in t[2]:
> +                desc.append('   %s @ %d' % (l, t[0]))
> +                tagdata += '%s %s\n' % (t[1], l)
> +
> +        def getfilectx(repo, memctx, fn):
> +            'callback to read file data'
> +            assert fn=='.hgtags'
> +            return context.memfilectx(fn, tagdata, False, False,  
> None)
> +
> +        ctx = context.memctx(repo, (p4rev, None), '\n'.join(desc),
> +                             ['.hgtags'], getfilectx)
> +        repo.commitctx(ctx)
> +
>    client.close()
>    if opts['update']:
> diff -r 74b50742f9a1 -r 3ef91c14b4fb test-push-perforce
> --- a/test-push-perforce    Thu Dec 24 10:08:20 2009 +0000
> +++ b/test-push-perforce    Fri Dec 25 02:28:28 2009 +0000
> @@ -2,11 +2,39 @@
> set -e
> +HELP=0
> +DEBUG=0
> +SHELL=0
> +P4ROOT=$PWD/depot
> +
> +while getopts "dr:s" OPT ; do
> +   case "$OPT" in
> +      d)
> +         DEBUG=1
> +         ;;
> +      r)
> +         P4ROOT=$OPTARG
> +         ;;
> +      s)
> +         SHELL=1
> +         ;;
> +      \?)
> +     HELP=1
> +     break
> +         ;;
> +   esac
> +done
> +
> +shift $(($OPTIND-1))
> +
> +if [ $HELP -ne 0 ] ; then
> +   echo "Usage: $0 [-ds] [-r DIR]"
> +   exit 1
> +fi
> +
> echo % create p4 depot
> -DEBUG=0
> -
> -P4ROOT=${P4ROOT:-$PWD/depot}; export P4ROOT
> +export P4ROOT
> P4AUDIT=$P4ROOT/audit; export P4AUDIT
> P4JOURNAL=$P4ROOT/journal; export P4JOURNAL
> P4LOG=$P4ROOT/log; export P4LOG
> @@ -62,6 +90,7 @@
> data > b/c
> p4 add a b/c
> p4 submit -d initial
> +p4 tag -l change-one ...
> echo % change some files
> p4 edit a
> @@ -75,6 +104,7 @@
> data >>b/d
> p4 add b/d
> p4 submit -d "p4 add b/d"
> +p4 tag -l change-four ...
> p4 delete b/c
> p4 submit -d "p4 delete b/c"
> @@ -143,6 +173,8 @@
> p4 changes       | filter
> p4 describe -s 7 | filter
> +p4 tag -l change-seven ...
> +
> cd ../dst
> echo % incoming
> @@ -163,5 +195,7 @@
> echo % p4stat
> head .hg/p4stat
> -#echo % run bash
> -#bash
> +if [ $SHELL -ne 0 ] ; then
> +   echo % run bash
> +   bash
> +fi
>
> -- 
> ------------------------------------------------------------------------
> Frank A. Kingswood                      frank at kingswood-consulting.co.uk
> Cambridge, United Kingdom                               +44-7545-209  
> 100
>



More information about the Mercurial-devel mailing list