Commits

Luke Plant committed 62e78ef

Added compatibility for the way mercurial.patch.patch works in hg 1.9

Comments (0)

Files changed (1)

 
 Inspired by git rebase --interactive.
 """
+from inspect import getargspec
 try:
     import cPickle as pickle
 except ImportError:
 except AttributeError:
     hidepassword = url.hidepassword
 
+# Different signatures to patch.patch, and different cleanup requirements
+if 'cwd' in getargspec(patch.patch)[0]:
+    # mercurial < 1.9:
+    #  - patch.patch takes cwd
+    #  - use cmdutil.updatedir to cleanup
+    def applypatch(ui, repo, patchname, strip=1, files=None, eolmode='strict',
+                    similarity=0):
+        # in mercurial < 1.9, patch.patch expects files to be a dictionary that
+        # will be filled with filenames that have been changed, and requires
+        # that this be run through updatedir
+        if files is None:
+            files = set()
+        filedict = {}
+        try:
+            retval = patch.patch(patchname, ui, strip=strip, cwd=repo.root,
+                                 files=filedict, eolmode=eolmode)
+        finally:
+            updatedir(ui, repo, filedict)
+        files.update(filedict.keys())
+        return retval
+else:
+    # mercurial > 1.9
+    applypatch = patch.patch
+
 # almost entirely stolen from the git-rebase--interactive.sh source
 editcomment = """
 
         fp.write(chunk)
     fp.close()
     try:
-        files = {}
+        files = set()
         try:
-            patch.patch(patchfile, ui, cwd=repo.root, files=files, eolmode=None)
+            applypatch(ui, repo, patchfile, files=files, eolmode=None)
             if not files:
                 ui.warn(_('%s: empty changeset')
                              % node.hex(ha))
                 return ctx, [], [], []
         finally:
-            files = updatedir(ui, repo, files)
             os.unlink(patchfile)
     except Exception, inst:
         raise util.Abort(_('Fix up the change and run '
         fp.write(chunk)
     fp.close()
     try:
-        files = {}
+        files = set()
         try:
-            patch.patch(patchfile, ui, cwd=repo.root, files=files, eolmode=None)
+            applypatch(ui, repo, patchfile, files=files, eolmode=None)
         finally:
-            files = updatedir(ui, repo, files)
             os.unlink(patchfile)
     except Exception, inst:
         pass
         fp.write(chunk)
     fp.close()
     try:
-        files = {}
+        files = set()
         try:
-            patch.patch(patchfile, ui, cwd=repo.root, files=files, eolmode=None)
+            applypatch(ui, repo, patchfile, files=files, eolmode=None)
             if not files:
                 ui.warn(_('%s: empty changeset')
                              % node.hex(ha))
                 return ctx, [], [], []
         finally:
-            files = updatedir(ui, repo, files)
             os.unlink(patchfile)
     except Exception, inst:
         raise util.Abort(_('Fix up the change and run '
     for chunk in gen:
         fp.write(chunk)
     fp.close()
-    files = {}
+    files = set()
     try:
-        patch.patch(patchfile, ui, cwd=repo.root, files=files, eolmode=None)
+        applypatch(ui, repo, patchfile, files=files, eolmode=None)
     finally:
-        files = updatedir(ui, repo, files)
         os.unlink(patchfile)
     newmessage = '\n***\n'.join(
         [ctx.description(), ] +
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.