changeset_printer: display p1rev:p1node with "+" suffix for workingctx
authorYuya Nishihara <yuya@tcha.org>
Sat, 14 Mar 2015 20:01:30 +0900
changeset 24584 5a40b5d45396
parent 24583 6117a29e9e76
child 24585 e191d5d8d515
changeset_printer: display p1rev:p1node with "+" suffix for workingctx Still templater can't handle workingctx, which will be fixed later.
mercurial/cmdutil.py
tests/test-log.t
--- a/mercurial/cmdutil.py	Sat Mar 14 17:29:48 2015 +0900
+++ b/mercurial/cmdutil.py	Sat Mar 14 20:01:30 2015 +0900
@@ -1101,21 +1101,24 @@
         '''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
--- a/tests/test-log.t	Sat Mar 14 17:29:48 2015 +0900
+++ b/tests/test-log.t	Sat Mar 14 20:01:30 2015 +0900
@@ -1623,6 +1623,16 @@
   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