[PATCH 1 of 6] templatekw: apply manifest template only if ctx.manifestnode() exists

Yuya Nishihara yuya at tcha.org
Thu Jul 2 10:17:00 CDT 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1426323498 -32400
#      Sat Mar 14 17:58:18 2015 +0900
# Node ID cf8091ddb4c8555580d64e352581689d2901d478
# Parent  e5fd479a399dad8e02f13d557f488b895999e3a6
templatekw: apply manifest template only if ctx.manifestnode() exists

This will prevent crash by "hg log -r 'wdir()' -Tdefault". We could use the
pseudo ff... hash introduced by 183965a00c76, but it isn't proven idea yet.
For now, I want to make "hg log" just works in order to test 'wdir()' revset.

Note that unlike its name, "{manifest}" is not a list of files in that
revision, but a pair of (manifestrev, manifestnode).

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -337,6 +337,9 @@ def showlatesttagdistance(repo, ctx, tem
 def showmanifest(**args):
     repo, ctx, templ = args['repo'], args['ctx'], args['templ']
     mnode = ctx.manifestnode()
+    if mnode is None:
+        # just avoid crash, we might want to use the 'ff...' hash in future
+        return
     args = args.copy()
     args.update({'rev': repo.manifest.rev(mnode), 'node': hex(mnode)})
     return templ('manifest', **args)
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
 
+Some keywords are invalid for working-directory revision, but they should
+never cause crash:
+
+  $ hg log -r 'wdir()' -T '{manifest}\n'
+  
+
 Quoting for ui.logtemplate
 
   $ hg tip --config "ui.logtemplate={rev}\n"


More information about the Mercurial-devel mailing list