[PATCH] Make revision ID available to transplant --filter command via environment

Luke Plant L.Plant.98 at cantab.net
Fri Mar 11 10:34:57 CST 2011


Sometimes it is necessary to know the original revision ID in order to
correctly rewrite the patch or commit message when transplanting.  This
patch follows the pattern set by the existing HGUSER environment 
variable, and adds a test that covers both HGUSER and HGREVISION.

Patch below and attached.

# HG changeset patch
# User Luke Plant <L.Plant.98 at cantab.net>
# Date 1299858524 0
# Node ID 77980260c92c8599495e45bd97767c34e425e16e
# Parent  1bb2a56a9d73b386378564381807fdf8df38ea3f
transplant: added 'HGREVISION' variable to the environment passed to the 
'filter' command

Sometimes it is necessary to know the original revision ID in order to
correctly rewrite the patch or commit message when transplanting.  This
patch follows the pattern set by the existing 'HGUSER' environment variable,
and adds a test that covers both HGUSER and HGREVISION.

diff -r 1bb2a56a9d73 -r 77980260c92c hgext/transplant.py
--- a/hgext/transplant.py	Thu Mar 10 13:43:47 2011 +0100
+++ b/hgext/transplant.py	Fri Mar 11 15:48:44 2011 +0000
@@ -177,12 +177,11 @@
              lock.release()
              wlock.release()

-    def filter(self, filter, changelog, patchfile):
+    def filter(self, filter, node, changelog, patchfile):
          '''arbitrarily rewrite changeset before applying it'''

          self.ui.status(_('filtering %s\n') % patchfile)
          user, date, msg = (changelog[1], changelog[2], changelog[4])
-
          fd, headerfile = tempfile.mkstemp(prefix='hg-transplant-')
          fp = os.fdopen(fd, 'w')
          fp.write("# HG changeset patch\n")
@@ -194,7 +193,9 @@
          try:
              util.system('%s %s %s' % (filter, util.shellquote(headerfile),
                                     util.shellquote(patchfile)),
-                        environ={'HGUSER': changelog[1]},
+                        environ={'HGUSER': changelog[1],
+                                 'HGREVISION': revlog.hex(node),
+                                 },
                          onerr=util.Abort, errprefix=_('filter failed'))
              user, date, msg = self.parselog(file(headerfile))[1:4]
          finally:
@@ -209,7 +210,7 @@
          date = "%d %d" % (time, timezone)
          extra = {'transplant_source': node}
          if filter:
-            (user, date, message) = self.filter(filter, cl, patchfile)
+            (user, date, message) = self.filter(filter, node, cl, 
patchfile)

          if log:
              # we don't translate messages inserted into commits
diff -r 1bb2a56a9d73 -r 77980260c92c tests/test-transplant.t
--- a/tests/test-transplant.t	Thu Mar 10 13:43:47 2011 +0100
+++ b/tests/test-transplant.t	Fri Mar 11 15:48:44 2011 +0000
@@ -330,6 +330,27 @@
    [255]
    $ cd ..

+test environment passed to filter
+
+  $ hg init filter-environment
+  $ cd filter-environment
+  $ cat <<'EOF' >test-filter-environment
+  > #!/bin/sh
+  > echo "Transplant by $HGUSER" >> $1
+  > echo "Transplant from rev $HGREVISION" >> $1
+  > EOF
+  $ chmod +x test-filter-environment
+  $ hg transplant -s ../t --filter ./test-filter-environment 0
+  filtering * (glob)
+  applying 17ab29e464c6
+  17ab29e464c6 transplanted to 5190e68026a0
+
+  $ hg log --template '{rev} {parents} {desc}\n'
+  0  r1
+  Transplant by test
+  Transplant from rev 17ab29e464c6ca53e329470efe2a9918ac617a6f
+  $ cd ..
+

  test with a win32ext like setup (differing EOLs)





--------------------------------
I confess to be pretty confused by your requests about submitting 
patches (<http://mercurial.selenic.com/wiki/ContributingChanges>), because:

1) Every mail client I have ever tried, including my current one, 
mangles patches in the body if you send plain text.

2) the patchbomb extension failed for me, due to the need for 
authentication (which has surely got to be *very* common with SMTP 
servers these days!)

3) Looking at the mail archives, lots of people include the patch in the 
body and as an attachment - is that what you prefer? That's what I did 
anyway. It would be nice if ContributingChanges was clarified.

-- 
"Don't mention it. Oh, you didn't." (Marvin the paranoid android)

Luke Plant || http://lukeplant.me.uk/
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: hg_transplant_filter_revision_id.diff.txt
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110311/9c571b80/attachment.txt>


More information about the Mercurial-devel mailing list