This is an archive of the discontinued Mercurial Phabricator instance.

scmutil: make shortest() respect disambiguation revset
ClosedPublic

Authored by martinvonz on Aug 1 2018, 5:57 PM.

Details

Summary

The previous patch would let you use a shorter prefix if the prefix is
unique within a configured revset. However, that's not very useful if
there's no simple way of knowing what that shorter prefix is. This
patch adapts the shortest() template function to use the shorter
prefixes for nodes in the configured revset.

This is currently extremely slow, because it calculates the revset for
each call to shortest(). To make this faster, the next patch will
start caching the revset instance. Ideally we'd cache a prefix tree
instance instead.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

martinvonz created this revision.Aug 1 2018, 5:57 PM
yuja added a subscriber: yuja.Aug 3 2018, 11:10 PM

Queued up to this patch, thanks.

+ revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')
+ if revset:
+ revs = repo.anyrevs([revset], user=True)
+ if cl.rev(node) in revs:
+ hexnode = hex(node)
+ for length in range(minlength, len(hexnode) + 1):
+ matches = []
+ prefix = hexnode[:length]
+ for rev in revs:
+ otherhexnode = repo[rev].hex()
+ if prefix == otherhexnode[:length]:

For micro optimization, this could be hex(cl.node(rev)).startswith(prefix).

This revision was automatically updated to reflect the committed changes.