D4038: scmutil: make shortest() respect disambiguation revset

2018-08-03 Thread martinvonz (Martin von Zweigbergk)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG6f7c9527030b: scmutil: make shortest() respect 
disambiguation revset (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4038?vs=9754=9877

REVISION DETAIL
  https://phab.mercurial-scm.org/D4038

AFFECTED FILES
  mercurial/scmutil.py
  tests/test-revisions.t

CHANGE DETAILS

diff --git a/tests/test-revisions.t b/tests/test-revisions.t
--- a/tests/test-revisions.t
+++ b/tests/test-revisions.t
@@ -23,6 +23,12 @@
   > [experimental]
   > revisions.disambiguatewithin=:3
   > EOF
+  $ hg l
+  4:7ba5d
+  3:7b
+  2:72
+  1:9
+  0:b
 9 was unambiguous and still is
   $ hg l -r 9
   1:9
@@ -32,6 +38,6 @@
   [255]
 7b is no longer ambiguous
   $ hg l -r 7b
-  3:7ba57
+  3:7b
 
   $ cd ..
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -489,6 +489,21 @@
 if not isrev(prefix):
 return prefix
 
+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]:
+matches.append(otherhexnode)
+if len(matches) == 1:
+return disambiguate(prefix)
+
 try:
 return disambiguate(cl.shortest(node, minlength))
 except error.LookupError:



To: martinvonz, #hg-reviewers
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: D4038: scmutil: make shortest() respect disambiguation revset

2018-08-03 Thread Yuya Nishihara
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)`.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4038: scmutil: make shortest() respect disambiguation revset

2018-08-03 Thread yuja (Yuya Nishihara)
yuja added a comment.


  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)`.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4038

To: martinvonz, #hg-reviewers
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4038: scmutil: make shortest() respect disambiguation revset

2018-08-01 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION 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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4038

AFFECTED FILES
  mercurial/scmutil.py
  tests/test-revisions.t

CHANGE DETAILS

diff --git a/tests/test-revisions.t b/tests/test-revisions.t
--- a/tests/test-revisions.t
+++ b/tests/test-revisions.t
@@ -23,6 +23,12 @@
   > [experimental]
   > revisions.disambiguatewithin=:3
   > EOF
+  $ hg l
+  4:7ba5d
+  3:7b
+  2:72
+  1:9
+  0:b
 9 was unambiguous and still is
   $ hg l -r 9
   1:9
@@ -32,6 +38,6 @@
   [255]
 7b is no longer ambiguous
   $ hg l -r 7b
-  3:7ba57
+  3:7b
 
   $ cd ..
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -489,6 +489,21 @@
 if not isrev(prefix):
 return prefix
 
+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]:
+matches.append(otherhexnode)
+if len(matches) == 1:
+return disambiguate(prefix)
+
 try:
 return disambiguate(cl.shortest(node, minlength))
 except error.LookupError:



To: martinvonz, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel