Patchwork D8256: git: make {shortest()} return shortest *unique* prefix

login
register
mail settings
Submitter phabricator
Date March 6, 2020, 10:18 p.m.
Message ID <differential-rev-PHID-DREV-65ct6t75gw2dso4wkd4k-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45578/
State Superseded
Headers show

Comments

phabricator - March 6, 2020, 10:18 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  It used to return the prefix of the specified length as long as the
  full node was unique (i.e. always).

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/git/gitlog.py
  tests/test-git-interop.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-git-interop.t b/tests/test-git-interop.t
--- a/tests/test-git-interop.t
+++ b/tests/test-git-interop.t
@@ -180,10 +180,6 @@ 
      summary:     Add beta
   
 
-node|shortest works correctly
-  $ hg log -r tip --template "{node|shortest}\n"
-  6626
-
 hg annotate
 
   $ hg annotate alpha
@@ -221,3 +217,15 @@ 
   nothing to commit, working tree clean
   $ hg status
 
+
+node|shortest works correctly
+  $ hg log -T '{node}\n' | sort
+  3d9be8deba43482be2c81a4cb4be1f10d85fa8bc
+  6626247b7dc8f231b183b8a4761c89139baca2ad
+  a1983dd7fb19cbd83ad5a1c2fc8bf3d775dea12f
+  ae1ab744f95bfd5b07cf573baef98a778058537b
+  c5864c9d16fb3431fe2c175ff84dc6accdbb2c18
+  d8ee22687733a1991813560b15128cd9734f4b48
+  $ hg log -r ae1ab744f95bfd5b07cf573baef98a778058537b --template "{shortest(node,1)}\n"
+  ae
+
diff --git a/hgext/git/gitlog.py b/hgext/git/gitlog.py
--- a/hgext/git/gitlog.py
+++ b/hgext/git/gitlog.py
@@ -170,7 +170,7 @@ 
             matches = int(
                 self._db.execute(
                     'SELECT COUNT(*) FROM changelog WHERE node LIKE ?',
-                    (pycompat.sysstr(nodehex + b'%'),),
+                    (pycompat.sysstr(candidate + b'%'),),
                 ).fetchone()[0]
             )
             if matches == 1: