# HG changeset patch # User Luke Plant # Date 1299858524 0 # Node ID 3cbb3c57a50e1c0461d9633637329fa81a83ce3a # Parent e720b3324e35b5fcc184e0b3a57cfeeffe7ee0f4 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 e720b3324e35 -r 3cbb3c57a50e hgext/transplant.py --- a/hgext/transplant.py Fri Mar 11 12:42:07 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 e720b3324e35 -r 3cbb3c57a50e tests/test-transplant.t --- a/tests/test-transplant.t Fri Mar 11 12:42:07 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)