[PATCH] templatekw: add parent1, parent1node, parent2, parent2node keywords

Evan Priestley epriestley at phacility.com
Thu Aug 9 19:00:54 CDT 2012


Thanks for the pointers, that's way better. I was following _meaningful_parentrevs() in changeset_templater() which is how I arrived at the crazy implementations, but that function is accomplishing some slightly different and more awkward goals. New patch coming in a second...

On Aug 8, 2012, at 6:54 PM, Greg Ward wrote:

> On 07 August 2012, Evan Priestley said:
>> (Redux from a couple weeks ago, giving this another shot as per ContributingChanges on the wiki.)
>> 
>> # HG changeset patch
>> # User epriestley <hg at yghe.net>
>> # Date 1341935012 25200
>> # Node ID 1c053d939f42f9face52f8c991e624e111189d97
>> # Parent  2e13c1bd34dc6afda8fc7cfa22a8cd658276724f
>> templatekw: add parent1, parent1node, parent2, parent2node keywords
> 
> Echoing Patrick: I would name them p1rev, p1node, etc. I think.
> 
>> +def showparent1(repo, ctx, templ, **args):
>> +    """:parent1: Integer. The repository-local revision number of the
>> +    changeset's first parent, or -1 if the changeset has no parents."""
>> +    return ctx.parents()[0].rev()
> 
> Why not ctx.p1().rev()?
> 
>> +def showparent2(repo, ctx, templ, **args):
>> +    """:parent2: Integer. The repository-local revision number of the
>> +    changeset's second parent, or -1 if the changeset has no second parent."""
>> +    parents = ctx.parents()
>> +    if len(parents) > 1:
>> +        return parents[1].rev()
>> +    else:
>> +        return repo['null'].rev()
> 
> Pretty sure this could be a one-liner: ctx.p2().rev().
> 
>> +def showparent1node(repo, ctx, templ, **args):
>> +    """:parent1node: String. The identification hash of the changeset's
>> +    first parent, as a 40 digit hexadecimal string. If the changeset has no
>> +    parents, all digits are 0."""
>> +    return ctx.parents()[0].hex()
>> +
>> +def showparent2node(repo, ctx, templ, **args):
>> +    """:parent2node: String. The identification hash of the changeset's
>> +    second parent, as a 40 digit hexadecimal string. If the changeset has no
>> +    second parent, all digits are 0."""
>> +    parents = ctx.parents()
>> +    if len(parents) > 1:
>> +        return parents[1].hex()
>> +    else:
>> +        return repo['null'].hex()
> 
> Similarly, I belive these could be reduced to
> 
>  ctx.p1().hex()
> 
> and
> 
>  ctx.p2().hex()
> 
> Oh yeah: thanks for this! Sounds like a useful addition to me.
> 
>       Greg
> -- 
> Greg Ward                                http://www.gerg.ca/
> All right, you degenerates!  I want this place evacuated in 20 seconds!



More information about the Mercurial-devel mailing list