[PATCH 3 of 5] patch: remove files while patching, not in updatedir()

Patrick Mezard pmezard at gmail.com
Wed May 18 15:57:16 CDT 2011


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1305751482 -7200
# Node ID 8f2ad395b7417584efe22f0c27e141854198f28f
# Parent  851311154f343af70b56288e135dc6dbc25ade0b
patch: remove files while patching, not in updatedir()

At this point, updatedir() only reads the working directory and update the
dirstate.

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -440,7 +440,11 @@
                 util.setflags(self._join(fname), False, True)
 
     def unlink(self, fname):
-        os.unlink(self._join(fname))
+        try:
+            util.unlinkpath(self._join(fname))
+        except OSError, inst:
+            if inst.errno != errno.ENOENT:
+                raise
 
     def writerej(self, fname, failed, total, lines):
         fname = fname + ".rej"
@@ -1217,14 +1221,23 @@
         rejects += current_file.close()
 
     # Handle mode changes without hunk
+    removed = set()
     for gp in changed.itervalues():
-        if not gp or not gp.mode:
+        if not gp:
             continue
-        if gp.op == 'ADD' and not backend.exists(gp.path):
-            # Added files without content have no hunk and must be created
-            backend.writelines(gp.path, [], gp.mode)
-        else:
-            backend.setmode(gp.path, gp.mode[0], gp.mode[1])
+        if gp.op == 'DELETE':
+            removed.add(gp.path)
+            continue
+        if gp.op == 'RENAME':
+            removed.add(gp.oldpath)
+        if gp.mode:
+            if gp.op == 'ADD' and not backend.exists(gp.path):
+                # Added files without content have no hunk and must be created
+                backend.writelines(gp.path, [], gp.mode)
+            else:
+                backend.setmode(gp.path, gp.mode[0], gp.mode[1])
+    for path in sorted(removed):
+        backend.unlink(path)
 
     if rejects:
         return -1
@@ -1256,7 +1269,7 @@
     for src, dst in copies:
         scmutil.dirstatecopy(ui, repo, wctx, src, dst, cwd=cwd)
     if (not similarity) and removes:
-        wctx.remove(sorted(removes), True)
+        wctx.remove(sorted(removes))
 
     scmutil.addremove(repo, cfiles, similarity=similarity)
     files = patches.keys()


More information about the Mercurial-devel mailing list