[PATCH 3 of 3] hgk: support templater for changeset description
Patrick Mezard
pmezard at gmail.com
Thu Sep 18 11:53:04 UTC 2008
# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1221737491 -7200
# Node ID 48218c3c3597b25e0a3f7e1d9cfae2f87995aab7
# Parent 39f8e50e5cfe202d8fe5db4ec0e0b1eac16ccb42
hgk: support templater for changeset description
diff --git a/hgext/hgk.py b/hgext/hgk.py
--- a/hgext/hgk.py
+++ b/hgext/hgk.py
@@ -42,10 +42,18 @@
vdiff=vdiff
Revisions context menu will now display additional entries to fire
-vdiff on hovered and selected revisions.'''
+vdiff on hovered and selected revisions.
+
+ [hgk]
+ template=my description: {desc}
+
+Use the template parameter to customize changeset description. Useful
+to display converted revision identifiers for instance.
+'''
import os
from mercurial import commands, util, patch, revlog, cmdutil
+from mercurial import templater
from mercurial.node import nullid, nullrev, short
from mercurial.i18n import _
@@ -69,8 +77,8 @@
for f in removed:
ui.write(":100664 000000 %s %s D\t%s\t%s\n" %
(short(mmap[f]), empty, f, f))
- ##
+ tmpl = maketemplater(ui, repo)
while True:
if opts['stdin']:
try:
@@ -90,7 +98,7 @@
node1 = repo.changelog.parents(node1)[0]
if opts['patch']:
if opts['pretty']:
- catcommit(ui, repo, node2, "")
+ catcommit(ui, repo, node2, "", tmpl=tmpl)
m = cmdutil.match(repo, files)
patch.diff(repo, node1, node2, match=m,
opts=patch.diffopts(ui, {'git': True}))
@@ -99,7 +107,19 @@
if not opts['stdin']:
break
-def catcommit(ui, repo, n, prefix, ctx=None):
+def maketemplater(ui, repo):
+ tmpl = ui.config("hgk", "template")
+ if not tmpl:
+ return None
+ tmpl = templater.parsestring(tmpl, quoted=False)
+ try:
+ t = cmdutil.changeset_templater(ui, repo, False, None, False)
+ except SyntaxError, inst:
+ raise util.Abort(inst.args[0])
+ t.use_template(tmpl)
+ return t
+
+def catcommit(ui, repo, n, prefix, ctx=None, tmpl=None):
nlprefix = '\n' + prefix;
if ctx is None:
ctx = repo[n]
@@ -108,7 +128,13 @@
ui.write("parent %s\n" % p)
date = ctx.date()
- description = ctx.description().replace("\0", "")
+ if tmpl:
+ ui.pushbuffer()
+ tmpl.show(changenode=ctx.node())
+ description = ui.popbuffer()
+ else:
+ description = ctx.description()
+ description = description.replace("\0", "")
lines = description.splitlines()
if lines and lines[-1].startswith('committer:'):
committer = lines[-1].split(': ')[1].rstrip()
@@ -153,12 +179,13 @@
ui.warn(_("cat-file: type or revision not supplied\n"))
commands.help_(ui, 'cat-file')
+ tmpl = maketemplater(ui, repo)
while r:
if type != "commit":
ui.warn(_("aborting hg cat-file only understands commits\n"))
return 1;
n = repo.lookup(r)
- catcommit(ui, repo, n, prefix)
+ catcommit(ui, repo, n, prefix, tmpl=tmpl)
if opts['stdin']:
try:
(type, r) = raw_input().split(' ');
@@ -243,6 +270,7 @@
if p in stop_sha1:
continue
+ tmpl = maketemplater(ui, repo)
# walk the repository looking for commits that are in our
# reachability graph
for i, ctx in chlogwalk():
@@ -260,7 +288,7 @@
ui.write("%s%s\n" % (short(n), parentstr))
elif full == "commit":
ui.write("%s%s\n" % (short(n), parentstr))
- catcommit(ui, repo, n, ' ', ctx)
+ catcommit(ui, repo, n, ' ', ctx, tmpl)
else:
(p1, p2) = repo.changelog.parents(n)
(h, h1, h2) = map(short, (n, p1, p2))
@@ -314,6 +342,9 @@
def view(ui, repo, *etc, **opts):
"start interactive history viewer"
+ # Validate the templater in startup command
+ maketemplater(ui, repo)
+
os.chdir(repo.root)
optstr = ' '.join(['--%s %s' % (k, v) for k, v in opts.iteritems() if v])
cmd = ui.config("hgk", "path", "hgk") + " %s %s" % (optstr, " ".join(etc))
More information about the Mercurial-devel
mailing list