[PATCH 3 of 3 gca-revset] revset: add a new commonancestorheads method

Sean Farley sean at farley.io
Fri Jun 15 14:19:47 EDT 2018


Yuya Nishihara <yuya at tcha.org> writes:

> On Fri, 15 Jun 2018 00:10:25 -0700, Sean Farley wrote:
>> # HG changeset patch
>> # User Sean Farley <sean at farley.io>
>> # Date 1527357855 -7200
>> #      Sat May 26 20:04:15 2018 +0200
>> # Branch gca-revset
>> # Node ID d44266127f1a86af521df2b2c088528c3f3b803a
>> # Parent  ab29cfd39f48432d8e7c38cdceb62980d5c22f09
>> revset: add a new commonancestorheads method
>> 
>> This is a new revset that provides a public interface to the
>> ancestor.commonancestorsheads method. Currently, we have no fast revset
>> way to get the ancestors of a list of changesets as returned by the
>> consensus bid merge algorithm (the one needed by criss-cross merges).
>> 
>> Previously, the only way to get these commits were (tested on
>> mozilla-central):
>> 
>> hg perfrevset 'heads(::a7cf55 and ::d8b15)'
>> ! wall 4.988366 comb 4.960000 user 4.780000 sys 0.180000 (best of 3)
>> 
>> After this patch:
>> 
>> hg perfrevset 'commonancestorheads(a7cf55, d8b15)'
>> ! wall 0.001790 comb 0.000000 user 0.000000 sys 0.000000 (best of 1340)
>> 
>> I'm not a fan of added more revset methods for performance but, yet,
>> here we are.
>> 
>> diff --git a/mercurial/revset.py b/mercurial/revset.py
>> index de543df..4004f4b 100644
>> --- a/mercurial/revset.py
>> +++ b/mercurial/revset.py
>> @@ -299,10 +299,34 @@ def adds(repo, subset, x):
>>      """
>>      # i18n: "adds" is a keyword
>>      pat = getstring(x, _("adds requires a pattern"))
>>      return checkstatus(repo, subset, pat, 1)
>>  
>> + at predicate('commonancestorheads(*changeset)', safe=True, weight=0.5)
>> +def commonancestorheads(repo, subset, x):
>> +    """Returns all greatest common ancestors of the changesets.
>> +
>> +    Accepts 0 or more changesets. Will return empty list when passed no args.
>> +    Greatest common ancestor of a single changeset is that changeset.
>> +
>> +    These greatest common ancestors the same ones that the consesus bid merge
>> +    will find.
>> +
>> +    """
>> +    # i18n: "ancestor" is a keyword
>
> Nit: garbage comment.

Oops; yes, bad copy paste.

>> +    from .ancestor import commonancestorsheads as cah
>
> Please move the import line to top. I don't think there's import cycle.

D'oh.

>> +    l = getlist(x)
>> +    rl = fullreposet(repo)
>> +    input_revs = []
>> +
>> +    # (getset(repo, rl, i) for i in l) generates a list of lists
>> +    for revs in (getset(repo, rl, i) for i in l):
>> +        for r in revs:
>> +            input_revs.append(r)
>> +
>> +    return subset & cah(repo.changelog.parentrevs, *input_revs)
>
> So, we no longer need the first two patches?

... I didn't realize that until now. Yes, you're totally correct.

>> +  $ hg log -r 'commonancestorheads(head())'
>> +  changeset:   1:0f6b37dbe527
>> +  user:        test
>> +  date:        Thu Jan 01 00:00:00 1970 +0000
>> +  summary:     1 first change f1
>> +  
>> +  changeset:   2:d1d156401c1b
>> +  parent:      0:40494bf2444c
>> +  user:        test
>> +  date:        Thu Jan 01 00:00:00 1970 +0000
>> +  summary:     2 first change f2
>
> Can you add a test for variable number (0, 1, 2...) of arguments? I think
> that's likely to regress.

Ah, yeah, sure.

Further discussion: should introduce this new revset and deprecate the
older one? Or would it be possible to optimize the heads(::x and ::y)
syntax? Thoughts?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20180615/50ab0c1b/attachment.sig>


More information about the Mercurial-devel mailing list