[PATCH 1 of 5] changeset_printer: display wdirrev/wdirnode values for workingctx

Yuya Nishihara yuya at tcha.org
Thu Jul 9 14:42:49 UTC 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1435997989 -32400
#      Sat Jul 04 17:19:49 2015 +0900
# Node ID bbaf3b6b60a3e5215a6964ceb7ee34cdad79490d
# Parent  befe8a7138c8bf6c6383a31065339804390ff136
changeset_printer: display wdirrev/wdirnode values for workingctx

Because we want to eliminate "if"s in the default template, it makes sense to
display wdirrev/wdirnode values for now. wdir() is still experimental, so the
output of "log -r'wdir()'" may change in future.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -5,7 +5,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-from node import hex, nullid, nullrev, short
+from node import hex, bin, nullid, nullrev, short
 from i18n import _
 import os, sys, errno, re, tempfile, cStringIO, shutil
 import util, scmutil, templater, patch, error, templatekw, revlog, copies
@@ -1152,11 +1152,9 @@ class changeset_printer(object):
             hexfunc = hex
         else:
             hexfunc = short
-        if rev is None:
-            pctx = ctx.p1()
-            revnode = (pctx.rev(), hexfunc(pctx.node()) + '+')
-        else:
-            revnode = (rev, hexfunc(changenode))
+        # as of now, wctx.node() and wctx.rev() return None, but we want to
+        # show the same values as {node} and {rev} templatekw
+        revnode = (scmutil.intrev(rev), hexfunc(bin(ctx.hex())))
 
         if self.ui.quiet:
             self.ui.write("%d:%s\n" % revnode, label='log.node')
diff --git a/tests/test-add.t b/tests/test-add.t
--- a/tests/test-add.t
+++ b/tests/test-add.t
@@ -109,7 +109,7 @@ should fail
 wdir doesn't cause a crash, and can be dynamically selected if dirty
 
   $ hg log -r "heads(. or wdir() & file('**'))"
-  changeset:   2:*+ (glob)
+  changeset:   2147483647:ffffffffffff
   parent:      2:* (glob)
   parent:      1:* (glob)
   user:        test
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -180,6 +180,26 @@ as default style, except for extra phase
   $ hg log --debug -T phases > phases.out
   $ cmp log.out phases.out || diff -u log.out phases.out
 
+Default style of working-directory revision should also be the same (but
+date may change while running tests):
+
+  $ hg log -r 'wdir()' | sed 's|^date:.*|date:|' > log.out
+  $ hg log -r 'wdir()' --style default | sed 's|^date:.*|date:|' > style.out
+  $ cmp log.out style.out || diff -u log.out style.out
+
+  $ hg log -r 'wdir()' -v | sed 's|^date:.*|date:|' > log.out
+  $ hg log -r 'wdir()' -v --style default | sed 's|^date:.*|date:|' > style.out
+  $ cmp log.out style.out || diff -u log.out style.out
+
+  $ hg log -r 'wdir()' -q > log.out
+  $ hg log -r 'wdir()' -q --style default > style.out
+  $ cmp log.out style.out || diff -u log.out style.out
+
+  $ hg log -r 'wdir()' --debug | sed 's|^date:.*|date:|' > log.out
+  $ hg log -r 'wdir()' --debug --style default \
+  > | sed 's|^date:.*|date:|' > style.out
+  $ cmp log.out style.out || diff -u log.out style.out
+
 Default style should also preserve color information (issue2866):
 
   $ cp $HGRCPATH $HGRCPATH-bak
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -1626,16 +1626,16 @@ issue3772: hg log -r :null showing revis
 working-directory revision requires special treatment
 
   $ hg log -r 'wdir()'
-  changeset:   0:65624cd9070a+
+  changeset:   2147483647:ffffffffffff
   parent:      0:65624cd9070a
   user:        test
   date:        [A-Za-z0-9:+ ]+ (re)
   
   $ hg log -r 'wdir()' -q
-  0:65624cd9070a+
+  2147483647:ffffffffffff
 
   $ hg log -r 'wdir()' --debug
-  changeset:   0:65624cd9070a035fa7191a54f2b8af39f16b0c08+
+  changeset:   2147483647:ffffffffffffffffffffffffffffffffffffffff
   phase:       draft
   parent:      0:65624cd9070a035fa7191a54f2b8af39f16b0c08
   parent:      -1:0000000000000000000000000000000000000000


More information about the Mercurial-devel mailing list