changeset 3759:e96f97ca0358

transplant: split filter args into changelog entry and patch
author Brendan Cully <brendan@kublai.com>
date Fri, 01 Dec 2006 15:43:48 -0800
parents 889f7e74a0d9
children aeafd80c1e78
files hgext/transplant.py
diffstat 1 files changed, 45 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/transplant.py	Fri Dec 01 15:00:33 2006 -0800
+++ b/hgext/transplant.py	Fri Dec 01 15:43:48 2006 -0800
@@ -140,7 +140,7 @@
                 else:
                     fd, patchfile = tempfile.mkstemp(prefix='hg-transplant-')
                     fp = os.fdopen(fd, 'w')
-                    patch.export(source, [node], fp=fp, opts=diffopts)
+                    patch.diff(source, parents[0], node, fp=fp, opts=diffopts)
                     fp.close()
 
                 del revmap[rev]
@@ -171,9 +171,27 @@
         '''arbitrarily rewrite changeset before applying it'''
 
         self.ui.status('filtering %s\n' % patchfile)
-        util.system('%s %s' % (filter, util.shellquote(patchfile)),
-                    environ={'HGUSER': changelog[1]},
-                    onerr=util.Abort, errprefix=_('filter failed'))
+        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")
+        fp.write("# User %s\n" % user)
+        fp.write("# Date %d %d\n" % date)
+        fp.write(changelog[4].rstrip())
+        fp.write("\n\n")
+        fp.close()
+
+        try:
+            util.system('%s %s %s' % (filter, util.shellquote(headerfile),
+                                   util.shellquote(patchfile)),
+                        environ={'HGUSER': changelog[1]},
+                        onerr=util.Abort, errprefix=_('filter failed'))
+            user, date, msg = self.parselog(file(headerfile))[1:4]
+        finally:
+            os.unlink(headerfile)
+
+        return (user, date, msg)
 
     def applyone(self, repo, node, cl, patchfile, merge=False, log=False,
                  filter=None, lock=None, wlock=None):
@@ -182,8 +200,7 @@
         date = "%d %d" % (time, timezone)
         extra = {'transplant_source': node}
         if filter:
-            self.filter(filter, cl, patchfile)
-            patchfile, message, user, date = patch.extract(self.ui, file(patchfile))
+            (user, date, message) = self.filter(filter, cl, patchfile)
 
         if log:
             message += '\n(transplanted from %s)' % revlog.hex(node)
@@ -204,8 +221,6 @@
                         return
                 finally:
                     files = patch.updatedir(self.ui, repo, files, wlock=wlock)
-                if filter:
-                    os.unlink(patchfile)
             except Exception, inst:
                 if filter:
                     os.unlink(patchfile)
@@ -302,6 +317,27 @@
                 series.write(revlog.hex(m) + '\n')
         series.close()
 
+    def parselog(self, fp):
+        parents = []
+        message = []
+        node = revlog.nullid
+        inmsg = False
+        for line in fp.read().splitlines():
+            if inmsg:
+                message.append(line)
+            elif line.startswith('# User '):
+                user = line[7:]
+            elif line.startswith('# Date '):
+                date = line[7:]
+            elif line.startswith('# Node ID '):
+                node = revlog.bin(line[10:])
+            elif line.startswith('# Parent '):
+                parents.append(revlog.bin(line[9:]))
+            elif not line.startswith('#'):
+                inmsg = True
+                message.append(line)
+        return (node, user, date, '\n'.join(message), parents)
+            
     def log(self, user, date, message, p1, p2, merge=False):
         '''journal changelog metadata for later recover'''
 
@@ -318,20 +354,7 @@
         fp.close()
 
     def readlog(self):
-        parents = []
-        message = []
-        for line in self.opener('journal').read().splitlines():
-            if line.startswith('# User '):
-                user = line[7:]
-            elif line.startswith('# Date '):
-                date = line[7:]
-            elif line.startswith('# Node ID '):
-                node = revlog.bin(line[10:])
-            elif line.startswith('# Parent '):
-                parents.append(revlog.bin(line[9:]))
-            else:
-                message.append(line)
-        return (node, user, date, '\n'.join(message), parents)
+        return self.parselog(self.opener('journal'))
 
     def unlog(self):
         '''remove changelog journal'''