[PATCH RESEND] committablectx: override hex() to return None
Yuya Nishihara
yuya at tcha.org
Wed Apr 15 14:49:28 UTC 2015
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1428141006 -32400
# Sat Apr 04 18:50:06 2015 +0900
# Node ID 39d70aef0e406cf1ccfc1723d5b48070a6e86074
# Parent c560d8c687916cb70a6d54c2c9ddcb5c9e457be2
committablectx: override hex() to return None
This allows us to evaluate "{node}" in workingctx, which is necessary to
make the default template generate the same output as changeset_printer.
wctx.hex() crashed before due to wctx.node() -> None. It could return
"{p1node}+" instead, but it wouldn't work well in templater because:
- "{node|short}" filter can't process "+" suffix
- even if it could, we would have to do "{if(rev, rev, p1rev)}:{node|short}"
to display both p1rev and p1node (can't avoid "if" anyway)
- "{p1node}+" is a phony value only for display, which shouldn't appear in XML
(and JSON) output
I won't argue against wctx.hex() -> "{p1node}+", which is sometimes useful.
But even in that case, I think "{node}" template should return None.
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1191,6 +1191,9 @@ class committablectx(basectx):
def subrev(self, subpath):
return None
+ def hex(self):
+ return None
+
def manifestnode(self):
return None
def user(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"
@@ -245,9 +251,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>
@@ -305,9 +316,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>
@@ -395,9 +413,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" />
More information about the Mercurial-devel
mailing list