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

mail settings
Submitter Yuya Nishihara
Date July 2, 2015, 3:17 p.m.
Message ID <cf8091ddb4c8555580d6.1435850220@mimosa>
Download mbox | patch
Permalink /patch/9871/
State Accepted
Headers show


Yuya Nishihara - July 2, 2015, 3:17 p.m.
# HG changeset patch
# User Yuya Nishihara <>
# 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/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -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"