Patchwork [1,of,5] committablectx: override hex() to return None

login
register
mail settings
Submitter Yuya Nishihara
Date April 7, 2015, 2:07 p.m.
Message ID <6e0da90c09aab6f350af.1428415659@mimosa>
Download mbox | patch
Permalink /patch/8530/
State Changes Requested
Headers show

Comments

Yuya Nishihara - April 7, 2015, 2:07 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1428141006 -32400
#      Sat Apr 04 18:50:06 2015 +0900
# Node ID 6e0da90c09aab6f350afe167f176d37c4bb83a0e
# Parent  b2fb1403994e033584aed8a487ab162a9d75fa80
committablectx: override hex() to return None

wctx.hex() crashed before because wctx.node() is None. It could be changed
to return "{p1node}+" but I chose None for consistency with node().
"{p1node}+" is sometimes useful, but not always. Machine-readable output such
as XML does not want it and "|short" filter can't process "+" suffix.
Sean Farley - April 7, 2015, 4:44 p.m.
Yuya Nishihara <yuya@tcha.org> writes:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1428141006 -32400
> #      Sat Apr 04 18:50:06 2015 +0900
> # Node ID 6e0da90c09aab6f350afe167f176d37c4bb83a0e
> # Parent  b2fb1403994e033584aed8a487ab162a9d75fa80
> committablectx: override hex() to return None
>
> wctx.hex() crashed before because wctx.node() is None. It could be changed
> to return "{p1node}+" but I chose None for consistency with node().
> "{p1node}+" is sometimes useful, but not always. Machine-readable output such
> as XML does not want it and "|short" filter can't process "+" suffix.

Could we not just improve 'short' to handle '+'? We seem to have a
precedent with 'hg id' appending '+' and also with the actual node used
in the code. I'm unsure what to tell machine-readable output since they
still have to deal with it for 'hg id'.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1203,6 +1203,9 @@  class committablectx(basectx):
     def subrev(self, subpath):
         return None
 
+    def hex(self):
+        return None
+
     def user(self):
         return self._user or self._repo.ui.username()
     def date(self):
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
@@ -51,6 +51,12 @@  Second branch starting at nullrev:
   8 t
   7 f
 
+Templater does not translate working-directory revision to readable form
+because there are several ways to:
+
+  $ hg log -r 'wdir()' -T '{node}\n'
+  
+
 Quoting for ui.logtemplate
 
   $ hg tip --config "ui.logtemplate={rev}\n"
@@ -239,9 +245,14 @@  Compact style works:
 
 Test xml styles:
 
-  $ hg log --style xml
+  $ hg log --style xml -r 'wdir() + 8:0'
   <?xml version="1.0"?>
   <log>
+  <logentry revision="" node="">
+  <author email="test">test</author>
+  <date>[T0-9:+\- ]+</date> (re)
+  <msg xml:space="preserve"></msg>
+  </logentry>
   <logentry revision="8" node="95c24699272ef57d062b8bccc32c878bf841784a">
   <tag>tip</tag>
   <author email="test">test</author>
@@ -299,9 +310,16 @@  Test xml styles:
   </logentry>
   </log>
 
-  $ hg log -v --style xml
+  $ hg log -v --style xml -r 'wdir() + 8:0'
   <?xml version="1.0"?>
   <log>
+  <logentry revision="" node="">
+  <author email="test">test</author>
+  <date>[T0-9:+\- ]+</date> (re)
+  <msg xml:space="preserve"></msg>
+  <paths>
+  </paths>
+  </logentry>
   <logentry revision="8" node="95c24699272ef57d062b8bccc32c878bf841784a">
   <tag>tip</tag>
   <author email="test">test</author>
@@ -389,9 +407,19 @@  Test xml styles:
   </logentry>
   </log>
 
-  $ hg log --debug --style xml
+  $ hg log --debug --style xml -r 'wdir() + 8:0'
   <?xml version="1.0"?>
   <log>
+  <logentry revision="" node="">
+  <parent revision="8" node="95c24699272ef57d062b8bccc32c878bf841784a" />
+  <parent revision="-1" node="0000000000000000000000000000000000000000" />
+  <author email="test">test</author>
+  <date>[T0-9:+\- ]+</date> (re)
+  <msg xml:space="preserve"></msg>
+  <paths>
+  </paths>
+  <extra key="branch">default</extra>
+  </logentry>
   <logentry revision="8" node="95c24699272ef57d062b8bccc32c878bf841784a">
   <tag>tip</tag>
   <parent revision="7" node="29114dbae42b9f078cf2714dbe3a86bba8ec7453" />