[PATCH 5 of 5] annotate: pass in wdir rev and node to formatter (BC)

Yuya Nishihara yuya at tcha.org
Sun Sep 23 09:28:21 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1536999983 -32400
#      Sat Sep 15 17:26:23 2018 +0900
# Node ID ff5e12ca25bf69f79cb4fad5118ac98c7172dd81
# Parent  d9a367af9890ff10b1c46fc036b541945182756f
annotate: pass in wdir rev and node to formatter (BC)

This is a part of the unification series. The 'ff..' hash is preferred over
None as it is a valid revision specifier.

https://www.mercurial-scm.org/wiki/GenericTemplatingPlan#Sanity_check_output

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -19,6 +19,8 @@ from .node import (
     nullid,
     nullrev,
     short,
+    wdirhex,
+    wdirrev,
 )
 from . import (
     archival,
@@ -313,37 +315,31 @@ def annotate(ui, repo, *pats, **opts):
     else:
         datefunc = dateutil.datestr
     if ctx.rev() is None:
-        def hexfn(node):
-            if node is None:
-                return None
-            else:
-                return hex(node)
         if opts.get('changeset'):
             # omit "+" suffix which is appended to node hex
             def formatrev(rev):
-                if rev is None:
+                if rev == wdirrev:
                     return '%d' % ctx.p1().rev()
                 else:
                     return '%d' % rev
         else:
             def formatrev(rev):
-                if rev is None:
+                if rev == wdirrev:
                     return '%d+' % ctx.p1().rev()
                 else:
                     return '%d ' % rev
         def formathex(h):
-            if h is None:
+            if h == wdirhex:
                 return '%s+' % shorthex(hex(ctx.p1().node()))
             else:
                 return '%s ' % shorthex(h)
     else:
-        hexfn = hex
         formatrev = b'%d'.__mod__
         formathex = shorthex
 
     opmap = [('user', ' ', lambda x: x.fctx.user(), ui.shortuser),
-             ('rev', ' ', lambda x: x.fctx.rev(), formatrev),
-             ('node', ' ', lambda x: hexfn(x.fctx.node()), formathex),
+             ('rev', ' ', lambda x: scmutil.intrev(x.fctx), formatrev),
+             ('node', ' ', lambda x: hex(scmutil.binnode(x.fctx)), formathex),
              ('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)),
              ('path', ' ', lambda x: x.fctx.path(), pycompat.bytestr),
              ('line_number', ':', lambda x: x.lineno, pycompat.bytestr),
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -564,7 +564,7 @@ annotate modified file
   $ hg annotate -ncr "wdir()" -Tjson foo
   [
    {
-    "lines": [{"line": "foo\n", "node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11}, {"line": "foofoo\n", "node": null, "rev": null}],
+    "lines": [{"line": "foo\n", "node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11}, {"line": "foofoo\n", "node": "ffffffffffffffffffffffffffffffffffffffff", "rev": 2147483647}],
     "path": "foo"
    }
   ]
diff --git a/tests/test-fastannotate-hg.t b/tests/test-fastannotate-hg.t
--- a/tests/test-fastannotate-hg.t
+++ b/tests/test-fastannotate-hg.t
@@ -569,7 +569,7 @@ annotate modified file
   $ hg annotate -ncr "wdir()" -Tjson foo
   [
    {
-    "lines": [{"line": "foo\n", "node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11}, {"line": "foofoo\n", "node": null, "rev": null}],
+    "lines": [{"line": "foo\n", "node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11}, {"line": "foofoo\n", "node": "ffffffffffffffffffffffffffffffffffffffff", "rev": 2147483647}],
     "path": "foo"
    }
   ]


More information about the Mercurial-devel mailing list