# HG changeset patch # User Patrick Mezard # Date 1305755293 -7200 # Node ID baf2807b9a7d17568f45f1dd40155b76b2053e96 # Parent 468d7d1744b40e5198a3a7bb4b1e1ced618c6ef6 patch: remove files while patching, not in updatedir() At this point, updatedir() only reads the working directory and update the dirstate. diff -r 468d7d1744b4 -r baf2807b9a7d mercurial/patch.py --- a/mercurial/patch.py Wed May 18 23:48:13 2011 +0200 +++ b/mercurial/patch.py Wed May 18 23:48:13 2011 +0200 @@ -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 == 'DELETE': + removed.add(gp.path) 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 == '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()