Patchwork [3,of,4] identify: use fm.hexfunc thoroughly

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 14, 2018, 2 p.m.
Message ID <604fb529bf149da0637f.1536933623@mimosa>
Download mbox | patch
Permalink /patch/34644/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 14, 2018, 2 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1535771362 -32400
#      Sat Sep 01 12:09:22 2018 +0900
# Node ID 604fb529bf149da0637f355b00920a2b39e20e2d
# Parent  1ad0f7146d0ef9d3d84c431f2c5dab67602c5083
identify: use fm.hexfunc thoroughly

This fixes the length of {id} in JSON and template outputs.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2983,10 +2983,6 @@  def identify(ui, repo, source=None, rev=
         raise error.Abort(_("there is no Mercurial repository here "
                            "(.hg not found)"))
 
-    if ui.debugflag:
-        hexfunc = hex
-    else:
-        hexfunc = short
     default = not (num or id or branch or tags or bookmarks)
     output = []
     revs = []
@@ -3010,7 +3006,7 @@  def identify(ui, repo, source=None, rev=
             rev = "tip"
 
         remoterev = peer.lookup(rev)
-        hexrev = hexfunc(remoterev)
+        hexrev = fm.hexfunc(remoterev)
         if default or id:
             output = [hexrev]
         fm.data(id=hexrev)
@@ -3053,7 +3049,7 @@  def identify(ui, repo, source=None, rev=
                 dirty = '+'
             fm.data(dirty=dirty)
 
-            hexoutput = [hexfunc(p.node()) for p in parents]
+            hexoutput = [fm.hexfunc(p.node()) for p in parents]
             if default or id:
                 output = ["%s%s" % ('+'.join(hexoutput), dirty)]
             fm.data(id="%s%s" % ('+'.join(hexoutput), dirty))
@@ -3070,7 +3066,7 @@  def identify(ui, repo, source=None, rev=
                 fn.context(ctx=p)
             fn.end()
         else:
-            hexoutput = hexfunc(ctx.node())
+            hexoutput = fm.hexfunc(ctx.node())
             if default or id:
                 output = [hexoutput]
             fm.data(id=hexoutput)
diff --git a/tests/test-identify.t b/tests/test-identify.t
--- a/tests/test-identify.t
+++ b/tests/test-identify.t
@@ -49,7 +49,7 @@  with options
     "bookmarks": [],
     "branch": "default",
     "dirty": "",
-    "id": "cb9a9f314b8b",
+    "id": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b",
     "node": "ffffffffffffffffffffffffffffffffffffffff",
     "parents": [{"node": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b", "rev": 0}],
     "tags": ["tip"]
@@ -71,7 +71,7 @@  for '{id}' (issue5612)
 
   $ hg id -T '{tags}\n'
   tip
-  $ hg id -T '{revset("null:.") % "{rev}:{node|short} {tags} {id}\n"}'
+  $ hg id -T '{revset("null:.") % "{rev}:{node|short} {tags} {id|short}\n"}'
   -1:000000000000  cb9a9f314b8b
   0:cb9a9f314b8b tip cb9a9f314b8b
 
@@ -86,7 +86,7 @@  with modifications
     "bookmarks": [],
     "branch": "default",
     "dirty": "+",
-    "id": "cb9a9f314b8b+",
+    "id": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b+",
     "node": "ffffffffffffffffffffffffffffffffffffffff",
     "parents": [{"node": "cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b", "rev": 0}],
     "tags": ["tip"]
diff --git a/tests/test-merge-default.t b/tests/test-merge-default.t
--- a/tests/test-merge-default.t
+++ b/tests/test-merge-default.t
@@ -55,7 +55,7 @@  Should succeed:
     "bookmarks": [],
     "branch": "default",
     "dirty": "+",
-    "id": "f25cbe84d8b3+2d95304fed5d+",
+    "id": "f25cbe84d8b320e298e7703f18a25a3959518c23+2d95304fed5d89bc9d70b2a0d02f0d567469c3ab+",
     "node": "ffffffffffffffffffffffffffffffffffffffff",
     "parents": [{"node": "f25cbe84d8b320e298e7703f18a25a3959518c23", "rev": 4}, {"node": "2d95304fed5d89bc9d70b2a0d02f0d567469c3ab", "rev": 2}],
     "tags": ["tip"]
@@ -82,7 +82,7 @@  Should succeed - 2 heads:
    {
     "bookmarks": [],
     "branch": "default",
-    "id": "1846eede8b68",
+    "id": "1846eede8b6886d8cc8a88c96a687b7fe8f3b9d1",
     "node": "1846eede8b6886d8cc8a88c96a687b7fe8f3b9d1",
     "tags": []
    }