[PATCH 1 of 2] templatekw: use a list of tags in getlatesttags() instead of joining them

Matt Harbison mharbison72 at gmail.com
Sat Jun 27 11:12:21 CDT 2015


On Sat, 27 Jun 2015 09:15:25 -0400, Yuya Nishihara <yuya at tcha.org> wrote:

> On Sat, 27 Jun 2015 00:01:23 -0400, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison at yahoo.com>
>> # Date 1435375390 14400
>> #      Fri Jun 26 23:23:10 2015 -0400
>> # Node ID c673a9cb5668ed84c13d69505cd6523a5469e385
>> # Parent  6368c51cfad6dc5f9c46369ed5e17cf8bd09efae
>> templatekw: use a list of tags in getlatesttags() instead of joining  
>> them
>>
>> This will be used in the next patch.
>>
>> It also points out that the documentation for '{latesttag}' is not quite
>> accurate, since it says "most recent global tag" (singular).  I assume  
>> it is too
>> radical of a change to convert it to a list of strings.  At least ':' is
>> currently a reserved character in tag names.
>>
>> diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
>> --- a/mercurial/templatekw.py
>> +++ b/mercurial/templatekw.py
>> @@ -120,7 +120,7 @@
>>      if 'latesttags' not in cache:
>>          # Cache mapping from rev to a tuple with tag date, tag
>>          # distance and tag name
>> -        cache['latesttags'] = {-1: (0, 0, 'null')}
>> +        cache['latesttags'] = {-1: (0, 0, ['null'])}
>>      latesttags = cache['latesttags']
>>
>>      rev = ctx.rev()
>> @@ -133,7 +133,7 @@
>>          tags = [t for t in ctx.tags()
>>                  if (repo.tagtype(t) and repo.tagtype(t) != 'local')]
>>          if tags:
>> -            latesttags[rev] = ctx.date()[0], 0, ':'.join(sorted(tags))
>> +            latesttags[rev] = ctx.date()[0], 0, [t for t in  
>> sorted(tags)]
>>              continue
>>          try:
>>              # The tuples are laid out so the right one can be found by
>> @@ -328,7 +328,7 @@
>>      """:latesttag: String. Most recent global tag in the ancestors of  
>> this
>>      changeset.
>>      """
>> -    return getlatesttags(repo, ctx, cache)[2]
>> +    return ':'.join(getlatesttags(repo, ctx, cache)[2])
>
> Looks good to me.
>
> If you think showlist() is overkill, you could make a _hybrid object  
> directly:
>
>   return _hybrid(iter([':'.join(tags)]), tags, lambda x: {'tag': x})

I'm not sure what you mean, but this templater stuff is all pretty unknown  
territory to me.  I'm not sure why this wasn't a list in the first place,  
but this change is simply maintaining existing behavior with a minimal  
delta.

I think we should probably come up with a list based one, maybe with  
consideration of http://bz.selenic.com/show_bug.cgi?id=4184 so we don't  
have too many tag related variants.


More information about the Mercurial-devel mailing list