[PATCH 1 of 3] identify: change p1/p2 to a list of parents

Matt Harbison mharbison72 at gmail.com
Tue Jun 27 21:44:35 EDT 2017


On Mon, 26 Jun 2017 09:17:59 -0400, Yuya Nishihara <yuya at tcha.org> wrote:

> On Sun, 25 Jun 2017 23:55:26 -0400, Matt Harbison wrote:
>> On Sun, 25 Jun 2017 21:48:02 -0400, Yuya Nishihara <yuya at tcha.org>  
>> wrote:
>>
>> > # HG changeset patch
>> > # User Yuya Nishihara <yuya at tcha.org>
>> > # Date 1498436335 -32400
>> > #      Mon Jun 26 09:18:55 2017 +0900
>> > # Node ID 556d2afe74385fe2a6dd7cdff5651080a827813f
>> > # Parent  a49ab7f5e7e765a94a1dfab2ee3b1da695789eb6
>> > identify: change p1/p2 to a list of parents
>> >
>> > It makes sense because the nested data structure is a list of items.
>>
>> Having them rolled into one list makes it a little more difficult to
>> access in a -T pattern, but maybe that's OK.  (I know nothing about the
>> json parsing aspect.)
>>
>> What I'm hoping to do is build the version string with the template.   
>> The
>> closest I came is:
>>
>> $ ../hg id -T "{latesttag}{if('{dirty}', '+{latesttag % \'{changes}\'}',
>> '+{parents % \'{latesttag % \"{changes}\"}\'}')}-{id}{if('{dirty}',
>> '{date(date, \"%Y%m%d\")}')}"
>>
>> Yikes.  This won't work for a (clean) merge revision, since there's no  
>> way
>> to select only p1.
>
> You could use revset(".").
>
>   hg identify -T '{revset(".") % "{latesttag % "{changes}"}"}\n'
>
> Well, it doesn't look nice, we might want map operator for non-list so we
> can do '{p1rev % "{latesttag ...}"}' for example. But the point of this  
> patch
> is that {p1} and {p2} are not lists. {parents} is.

OK.  IDK how to implement the map operator, but this works, thanks.

Related to this example, I noticed that the RHS of 'revset(..) %' isn't  
reevaluated for fields injected with fm.data().  I'm guessing it's caching  
for performance.  But:

$ ../hg identify -r '4.2' -T '{revset("tagged() and rev(%d)::", rev) %  
"{rev}\n"}'
35618
36319

vs an injected field:

$ ../hg identify -r '4.2' -T '{revset("tagged() and rev(%d)::", rev) %  
"{tags % "{tag}"}\n"}'
4.2
4.2

That query works fine if I comment out 'fm.data(tags=...)':

$ ../hg identify -r '4.2' -T '{revset("tagged() and rev(%d)::", rev) %  
"{tags % "{tag}"}\n"}'
4.2
4.2.1

Maybe it's a small reason to automatically populate the ctx attributes in  
json, so that these don't need to be manually set in the formatter?

(I saw that github shows the descendant tags of a commit, and wanted to  
see if I could (ab)use the existing templates to get the same results  
without writing python code for it.  I realize that log would be a better  
command for this query.)


More information about the Mercurial-devel mailing list