[patch] --template option for transplant
Dustin Sallings
dustin at spy.net
Sat Feb 9 01:11:54 CST 2008
I'd like to be able to add custom log messages to the bottom of
transplants without feeding them through a script. I added a --
template option to accomplish this.
The patch is a lot more complicated than I'd like, which leads me to
believe that I may not understand the template mechanism. Please let
me know if there's an easier way to do this, or whether it's just
generally the wrong direction.
# HG changeset patch
# User Dustin Sallings <dustin at spy.net>
# Date 1202540880 28800
# Node ID 9b500368db060749d17436dce06c4da5fec13049
# Parent 57c1a705298204b659d04adc42425df815ef03cd
Allow log templates in transplant.
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -8,7 +8,7 @@
from mercurial.i18n import _
import os, tempfile
from mercurial import bundlerepo, changegroup, cmdutil, commands,
hg, merge
-from mercurial import patch, revlog, util
+from mercurial import patch, revlog, util, templater
'''patch transplanting tool
@@ -146,11 +146,11 @@
del revmap[rev]
if patchfile or domerge:
try:
- n = self.applyone(repo, node,
- source.changelog.read(node),
+ n = self.applyone(repo, node, source,
patchfile, merge=domerge,
log=opts.get('log'),
- filter=opts.get('filter'))
+ filter=opts.get('filter'),
+
template=opts.get('template'))
if n and domerge:
self.ui.status(_('%s merged at %s\n') %
(revstr,
revlog.short(n)))
@@ -193,9 +193,10 @@
return (user, date, msg)
- def applyone(self, repo, node, cl, patchfile, merge=False,
log=False,
- filter=None):
+ def applyone(self, repo, node, source, patchfile, merge=False,
log=False,
+ filter=None, template=None):
'''apply the patch in patchfile to the repository as a
transplant'''
+ cl=source.changelog.read(node)
(manifest, user, (time, timezone), files, message) = cl[:5]
date = "%d %d" % (time, timezone)
extra = {'transplant_source': node}
@@ -203,7 +204,20 @@
(user, date, message) = self.filter(filter, cl, patchfile)
if log:
- message += '\n(transplanted from %s)' % revlog.hex(node)
+ import copy
+ if template:
+ template = template[0]
+ else:
+ template = '(transplanted from {node})'
+ content=[]
+ def intercept(stuff):
+ content.append(stuff)
+ ui = copy.copy(self.ui)
+ ui.write = intercept
+ t=cmdutil.changeset_templater(ui, source, None, None,
False)
+ t.use_template(templater.parsestring(template, False))
+ t.show(changenode=node)
+ message += '\n%s' % ''.join(content)
self.ui.status(_('applying %s\n') % revlog.short(node))
self.ui.note('%s %s\n%s\n' % (user, date, message))
@@ -591,6 +605,7 @@
('p', 'prune', [], _('skip over REV')),
('m', 'merge', [], _('merge at REV')),
('', 'log', None, _('append transplant info to log
message')),
+ ('', 'template', [], _('template for transplant info')),
('c', 'continue', None, _('continue last transplant
session after repair')),
('', 'filter', '', _('filter changesets through FILTER'))],
_('hg transplant [-s REPOSITORY] [-b BRANCH [-a]] [-p REV]
[-m REV] [REV]...'))
diff --git a/tests/test-transplant b/tests/test-transplant
--- a/tests/test-transplant
+++ b/tests/test-transplant
@@ -35,7 +35,7 @@
hg up -C 1
echo '% rebase b onto r1, skipping b2'
-hg transplant -a -b tip -p 3
+hg transplant --log --template 'xplant: {node|short}' -a -b tip -p 3
hg log --template '{rev} {parents} {desc}\n'
echo '% remote transplant'
diff --git a/tests/test-transplant.out b/tests/test-transplant.out
--- a/tests/test-transplant.out
+++ b/tests/test-transplant.out
@@ -30,11 +30,13 @@
1 files updated, 0 files merged, 3 files removed, 0 files unresolved
% rebase b onto r1, skipping b2
applying 37a1297eb21b
-37a1297eb21b transplanted to e234d668f844
+37a1297eb21b transplanted to 183d55964123
applying a53251cdf717
-a53251cdf717 transplanted to 7275fda4d04f
+a53251cdf717 transplanted to bfa8a70a36bc
6 b3
+xplant: a53251cdf717
5 1:d11e3596cc1a b1
+xplant: 37a1297eb21b
4 b3
3 b2
2 0:17ab29e464c6 b1
--
Dustin Sallings
More information about the Mercurial
mailing list