indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Our previous shortest node length of 5 was arbitrarily chosen.
  
  shortest() already does the work of ensuring that a partial node
  isn't ambiguous with an integer revision, which is our primary risk
  of a collision for very short nodes. It should be safe to go with the
  shortest node possible.
  
  So, we decrease the minimum hash length from 5 to 3.
  
  We also add a test for prefix collisions increasing the hash length
  consistently for `hg show work`, which is a feature from the previous
  commit.
  
  .. feature::
  
    show: decrease minimum displayed hash length from 5 to 3

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/show.py
  tests/test-show-stack.t
  tests/test-show-work.t
  tests/test-show.t

CHANGE DETAILS

diff --git a/tests/test-show.t b/tests/test-show.t
--- a/tests/test-show.t
+++ b/tests/test-show.t
@@ -95,8 +95,8 @@
   $ hg bookmark a-longer-bookmark
 
   $ hg show bookmarks
-  * a-longer-bookmark    7b570
-    book1                b757f
+  * a-longer-bookmark    7b5
+    book1                b75
 
 A custom bookmarks template works
 
@@ -113,14 +113,14 @@
     "bookmark": "a-longer-bookmark",
     "longestbookmarklen": 17,
     "node": "7b5709ab64cbc34da9b4367b64afff47f2c4ee83",
-    "nodelen": 5
+    "nodelen": 3
    },
    {
     "active": false,
     "bookmark": "book1",
     "longestbookmarklen": 17,
     "node": "b757f780b8ffd71267c6ccb32e0882d9d32a8cc0",
-    "nodelen": 5
+    "nodelen": 3
    }
   ]
 
@@ -138,19 +138,19 @@
   (no bookmarks set)
 
   $ hg --config commands.show.aliasprefix=sh shwork
-  @  7b570 commit for book2
-  o  b757f commit for book1
-  o  ba592 initial
+  @  7b5 commit for book2
+  o  b75 commit for book1
+  o  ba5 initial
 
   $ hg --config commands.show.aliasprefix='s sh' swork
-  @  7b570 commit for book2
-  o  b757f commit for book1
-  o  ba592 initial
+  @  7b5 commit for book2
+  o  b75 commit for book1
+  o  ba5 initial
 
   $ hg --config commands.show.aliasprefix='s sh' shwork
-  @  7b570 commit for book2
-  o  b757f commit for book1
-  o  ba592 initial
+  @  7b5 commit for book2
+  o  b75 commit for book1
+  o  ba5 initial
 
 The aliases don't appear in `hg config`
 
diff --git a/tests/test-show-work.t b/tests/test-show-work.t
--- a/tests/test-show-work.t
+++ b/tests/test-show-work.t
@@ -16,47 +16,47 @@
   $ hg -q commit -A -m 'commit 0'
 
   $ hg show work
-  @  9f171 commit 0
+  @  9f1 commit 0
 
 Even when it isn't the wdir
 
   $ hg -q up null
 
   $ hg show work
-  o  9f171 commit 0
+  o  9f1 commit 0
 
 Single changeset is still there when public because it is a head
 
   $ hg phase --public -r 0
   $ hg show work
-  o  9f171 commit 0
+  o  9f1 commit 0
 
 A draft child will show both it and public parent
 
   $ hg -q up 0
   $ echo 1 > foo
   $ hg commit -m 'commit 1'
 
   $ hg show work
-  @  181cc commit 1
-  o  9f171 commit 0
+  @  181 commit 1
+  o  9f1 commit 0
 
 Multiple draft children will be shown
 
   $ echo 2 > foo
   $ hg commit -m 'commit 2'
 
   $ hg show work
-  @  128c8 commit 2
-  o  181cc commit 1
-  o  9f171 commit 0
+  @  128 commit 2
+  o  181 commit 1
+  o  9f1 commit 0
 
 Bumping first draft changeset to public will hide its parent
 
   $ hg phase --public -r 1
   $ hg show work
-  @  128c8 commit 2
-  o  181cc commit 1
+  @  128 commit 2
+  o  181 commit 1
   |
   ~
 
@@ -68,22 +68,22 @@
   created new head
 
   $ hg show work
-  @  f0abc commit 3
-  | o  128c8 commit 2
+  @  f0a commit 3
+  | o  128 commit 2
   |/
-  o  181cc commit 1
+  o  181 commit 1
   |
   ~
 
 Even when wdir is something else
 
   $ hg -q up null
 
   $ hg show work
-  o  f0abc commit 3
-  | o  128c8 commit 2
+  o  f0a commit 3
+  | o  128 commit 2
   |/
-  o  181cc commit 1
+  o  181 commit 1
   |
   ~
 
@@ -95,13 +95,13 @@
   created new head
 
   $ hg show work
-  @  668ca commit 4
-  | o  f0abc commit 3
-  | | o  128c8 commit 2
+  @  668 commit 4
+  | o  f0a commit 3
+  | | o  128 commit 2
   | |/
-  | o  181cc commit 1
+  | o  181 commit 1
   |/
-  o  9f171 commit 0
+  o  9f1 commit 0
 
   $ cd ..
 
@@ -126,11 +126,11 @@
   $ hg commit -m 'commit 4'
 
   $ hg show work
-  @  f8dd3 (mybranch) commit 4
-  o  90cfc (mybranch) commit 3
-  | o  128c8 commit 2
+  @  f8d (mybranch) commit 4
+  o  90c (mybranch) commit 3
+  | o  128 commit 2
   |/
-  o  181cc commit 1
+  o  181 commit 1
   |
   ~
 
@@ -157,11 +157,11 @@
   $ hg bookmark mybook
 
   $ hg show work
-  @  cac82 (mybook) commit 4
-  o  f0abc commit 3
-  | o  128c8 (@) commit 2
+  @  cac (mybook) commit 4
+  o  f0a commit 3
+  | o  128 (@) commit 2
   |/
-  o  181cc commit 1
+  o  181 commit 1
   |
   ~
 
@@ -182,9 +182,9 @@
   $ hg tag 0.2
 
   $ hg show work
-  @  37582 Added tag 0.2 for changeset 6379c25b76f1
-  o  6379c (0.2) commit 3
-  o  a2ad9 Added tag 0.1 for changeset 6a75536ea0b1
+  @  375 Added tag 0.2 for changeset 6379c25b76f1
+  o  637 (0.2) commit 3
+  o  a2a Added tag 0.1 for changeset 6a75536ea0b1
   |
   ~
 
@@ -205,15 +205,15 @@
   $ hg commit -m 'commit 2'
 
   $ hg show work
-  @  34834 (mybook) (mybranch) commit 2
-  o  97fcc commit 1
+  @  348 (mybook) (mybranch) commit 2
+  o  97f commit 1
 
 Multiple bookmarks on same changeset render properly
 
   $ hg book mybook2
   $ hg show work
-  @  34834 (mybook mybook2) (mybranch) commit 2
-  o  97fcc commit 1
+  @  348 (mybook mybook2) (mybranch) commit 2
+  o  97f commit 1
 
   $ cd ..
 
@@ -230,8 +230,38 @@
   $ hg commit -m 'commit 3'
 
   $ hg --config extensions.revnames=$TESTDIR/revnamesext.py show work
-  @  32f3e (r2) commit 3
-  o  6a755 (r1) commit 2
-  o  97fcc (r0) commit 1
+  @  32f (r2) commit 3
+  o  6a7 (r1) commit 2
+  o  97f (r0) commit 1
 
   $ cd ..
+
+Prefix collision on hashes increases shortest node length
+
+  $ hg init hashcollision
+  $ cd hashcollision
+  $ echo 0 > a
+  $ hg -q commit -Am 0
+  $ for i in 17 1057 2857 4025; do
+  >   hg -q up 0
+  >   echo $i > a
+  >   hg -q commit -m $i
+  >   echo 0 > a
+  >   hg commit -m "$i commit 2"
+  > done
+
+  $ hg show work
+  @  cfd04 4025 commit 2
+  o  c562d 4025
+  | o  08048 2857 commit 2
+  | o  c5623 2857
+  |/
+  | o  6a6b6 1057 commit 2
+  | o  c5625 1057
+  |/
+  | o  96b4e 17 commit 2
+  | o  11424 17
+  |/
+  o  b4e73 0
+
+  $ cd ..
diff --git a/tests/test-show-stack.t b/tests/test-show-stack.t
--- a/tests/test-show-stack.t
+++ b/tests/test-show-stack.t
@@ -17,7 +17,7 @@
   $ echo 0 > foo
   $ hg -q commit -A -m 'commit 0'
   $ hg show stack
-    @  9f171 commit 0
+    @  9f1 commit 0
 
 Stack displays multiple draft changesets
 
@@ -30,48 +30,48 @@
   $ echo 4 > foo
   $ hg commit -m 'commit 4'
   $ hg show stack
-    @  2737b commit 4
-    o  d1a69 commit 3
-    o  128c8 commit 2
-    o  181cc commit 1
-    o  9f171 commit 0
+    @  273 commit 4
+    o  d1a commit 3
+    o  128 commit 2
+    o  181 commit 1
+    o  9f1 commit 0
 
 Public parent of draft base is displayed, separated from stack
 
   $ hg phase --public -r 0
   $ hg show stack
-    @  2737b commit 4
-    o  d1a69 commit 3
-    o  128c8 commit 2
-    o  181cc commit 1
+    @  273 commit 4
+    o  d1a commit 3
+    o  128 commit 2
+    o  181 commit 1
    /   (stack base)
-  o  9f171 commit 0
+  o  9f1 commit 0
 
   $ hg phase --public -r 1
   $ hg show stack
-    @  2737b commit 4
-    o  d1a69 commit 3
-    o  128c8 commit 2
+    @  273 commit 4
+    o  d1a commit 3
+    o  128 commit 2
    /   (stack base)
-  o  181cc commit 1
+  o  181 commit 1
 
 Draft descendants are shown
 
   $ hg -q up 2
   $ hg show stack
-    o  2737b commit 4
-    o  d1a69 commit 3
-    @  128c8 commit 2
+    o  273 commit 4
+    o  d1a commit 3
+    @  128 commit 2
    /   (stack base)
-  o  181cc commit 1
+  o  181 commit 1
 
   $ hg -q up 3
   $ hg show stack
-    o  2737b commit 4
-    @  d1a69 commit 3
-    o  128c8 commit 2
+    o  273 commit 4
+    @  d1a commit 3
+    o  128 commit 2
    /   (stack base)
-  o  181cc commit 1
+  o  181 commit 1
 
 working dir on public changeset should display special message
 
@@ -89,10 +89,10 @@
   $ hg show stack
    \ /  (multiple children)
     |
-    o  d1a69 commit 3
-    @  128c8 commit 2
+    o  d1a commit 3
+    @  128 commit 2
    /   (stack base)
-  o  181cc commit 1
+  o  181 commit 1
 
   $ cd ..
 
@@ -117,20 +117,20 @@
 TODO doesn't yet handle case where wdir is a draft merge
 
   $ hg show stack
-    @  8ee90 merge heads
+    @  8ee merge heads
    /   (stack base)
-  o  59478 head 1
+  o  594 head 1
 
   $ echo d1 > foo
   $ hg commit -m 'draft 1'
   $ echo d2 > foo
   $ hg commit -m 'draft 2'
 
   $ hg show stack
-    @  430d5 draft 2
-    o  787b1 draft 1
+    @  430 draft 2
+    o  787 draft 1
    /   (stack base)
-  o  8ee90 merge heads
+  o  8ee merge heads
 
   $ cd ..
 
@@ -156,36 +156,36 @@
 Newer draft heads don't impact output
 
   $ hg show stack
-    @  eaffc draft 2
-    o  2b218 draft 1
+    @  eaf draft 2
+    o  2b2 draft 1
    /   (stack base)
-  o  b66bb base
+  o  b66 base
 
 Newer public heads are rendered
 
   $ hg phase --public -r '::tip'
 
   $ hg show stack
-    o  baa4b new 2
+    o  baa new 2
    /    (2 commits ahead)
   :
   :    (stack head)
-  : @  eaffc draft 2
-  : o  2b218 draft 1
+  : @  eaf draft 2
+  : o  2b2 draft 1
   :/   (stack base)
-  o  b66bb base
+  o  b66 base
 
 If rebase is available, we show a hint how to rebase to that head
 
   $ hg --config extensions.rebase= show stack
-    o  baa4b new 2
-   /    (2 commits ahead; hg rebase --source 2b218 --dest baa4b)
+    o  baa new 2
+   /    (2 commits ahead; hg rebase --source 2b2 --dest baa)
   :
   :    (stack head)
-  : @  eaffc draft 2
-  : o  2b218 draft 1
+  : @  eaf draft 2
+  : o  2b2 draft 1
   :/   (stack base)
-  o  b66bb base
+  o  b66 base
 
 Similar tests but for multiple heads
 
@@ -196,25 +196,25 @@
   $ hg -q up 2
 
   $ hg show stack
-    o  baa4b new 2
+    o  baa new 2
    /    (2 commits ahead)
-  : o  9a848 new head 2
+  : o  9a8 new head 2
   :/    (1 commits ahead)
   :
   :    (stack head)
-  : @  eaffc draft 2
-  : o  2b218 draft 1
+  : @  eaf draft 2
+  : o  2b2 draft 1
   :/   (stack base)
-  o  b66bb base
+  o  b66 base
 
   $ hg --config extensions.rebase= show stack
-    o  baa4b new 2
-   /    (2 commits ahead; hg rebase --source 2b218 --dest baa4b)
-  : o  9a848 new head 2
-  :/    (1 commits ahead; hg rebase --source 2b218 --dest 9a848)
+    o  baa new 2
+   /    (2 commits ahead; hg rebase --source 2b2 --dest baa)
+  : o  9a8 new head 2
+  :/    (1 commits ahead; hg rebase --source 2b2 --dest 9a8)
   :
   :    (stack head)
-  : @  eaffc draft 2
-  : o  2b218 draft 1
+  : @  eaf draft 2
+  : o  2b2 draft 1
   :/   (stack base)
-  o  b66bb base
+  o  b66 base
diff --git a/hgext/show.py b/hgext/show.py
--- a/hgext/show.py
+++ b/hgext/show.py
@@ -425,7 +425,7 @@
 
             ui.setconfig('alias', name, 'show %s' % view, source='show')
 
-def longestshortest(repo, revs, minlen=5):
+def longestshortest(repo, revs, minlen=3):
     """Return the length of the longest shortest node to identify revisions.
 
     The result of this function can be used with the ``shortest()`` template



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

Reply via email to