Patchwork [3,of,4] changeset_printer: display p1rev:p1node with "+" suffix for workingctx

login
register
mail settings
Submitter Yuya Nishihara
Date April 2, 2015, 1:35 p.m.
Message ID <6df350f6ea11b913d6d2.1427981758@mimosa>
Download mbox | patch
Permalink /patch/8454/
State Accepted
Headers show

Comments

Yuya Nishihara - April 2, 2015, 1:35 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1426330890 -32400
#      Sat Mar 14 20:01:30 2015 +0900
# Node ID 6df350f6ea11b913d6d263b0af3250408efc2db3
# Parent  398d78e415506124dd758574a36ee3dba3e53598
changeset_printer: display p1rev:p1node with "+" suffix for workingctx

Still templater can't handle workingctx, which will be fixed later.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1101,21 +1101,24 @@  class changeset_printer(object):
         '''show a single changeset or file revision'''
         changenode = ctx.node()
         rev = ctx.rev()
-
-        if self.ui.quiet:
-            self.ui.write("%d:%s\n" % (rev, short(changenode)),
-                          label='log.node')
-            return
-
-        date = util.datestr(ctx.date())
-
         if self.ui.debugflag:
             hexfunc = hex
         else:
             hexfunc = short
+        if rev is None:
+            pctx = ctx.p1()
+            revnode = (pctx.rev(), hexfunc(pctx.node()) + '+')
+        else:
+            revnode = (rev, hexfunc(changenode))
+
+        if self.ui.quiet:
+            self.ui.write("%d:%s\n" % revnode, label='log.node')
+            return
+
+        date = util.datestr(ctx.date())
 
         # i18n: column positioning for "hg log"
-        self.ui.write(_("changeset:   %d:%s\n") % (rev, hexfunc(changenode)),
+        self.ui.write(_("changeset:   %d:%s\n") % revnode,
                       label='log.changeset changeset.%s' % ctx.phasestr())
 
         # branches are shown first before any other names due to backwards
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -1623,6 +1623,16 @@  issue3772: hg log -r :null showing revis
   user:        
   date:        Thu Jan 01 00:00:00 1970 +0000
   
+working-directory revision requires special treatment
+
+  $ hg log -r 'wdir()'
+  changeset:   0:65624cd9070a+
+  user:        test
+  date:        [A-Za-z0-9:+ ]+ (re)
+  
+  $ hg log -r 'wdir()' -q
+  0:65624cd9070a+
+
 Check that adding an arbitrary name shows up in log automatically
 
   $ cat > ../names.py <<EOF