[PATCH 7 of 8 RFC] annotate: use context methods to get short/long hex of changeset hash

Yuya Nishihara yuya at tcha.org
Tue Aug 19 22:56:21 UTC 2014


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1408180120 -32400
#      Sat Aug 16 18:08:40 2014 +0900
# Node ID c8ad2080d3f4031851a84f12cee37439da405048
# Parent  5b82336b237f8f45a01f31d4d0788464a1198843
annotate: use context methods to get short/long hex of changeset hash

This prepares for workingctx support.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -268,13 +268,16 @@ def annotate(ui, repo, *pats, **opts):
         # to mimic the behavior of Mercurial before version 1.5
         opts['file'] = True
 
+    if ui.debugflag:
+        getchangeset = lambda x: x[0].hex()
+    else:
+        getchangeset = lambda x: str(x[0].changectx())
     datefunc = ui.quiet and util.shortdate or util.datestr
     getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
-    hexfn = ui.debugflag and hex or short
 
     opmap = [('user', ' ', lambda x: ui.shortuser(x[0].user())),
              ('number', ' ', lambda x: str(x[0].rev())),
-             ('changeset', ' ', lambda x: hexfn(x[0].node())),
+             ('changeset', ' ', getchangeset),
              ('date', ' ', getdate),
              ('file', ' ', lambda x: x[0].path()),
              ('line_number', ':', lambda x: str(x[1])),
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -16,6 +16,9 @@ annotate -c
   $ hg annotate -c a
   8435f90966e4: a
 
+  $ hg annotate --debug -c a
+  8435f90966e442695d2ded29fdade2bac5ad8065: a
+
 annotate -cl
 
   $ hg annotate -cl a



More information about the Mercurial-devel mailing list