[PATCH 2 of 2] workingctx: eliminate remove function

Adrian Buehlmann adrian at cadifra.com
Thu Jun 2 15:48:05 CDT 2011


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1306967613 -7200
# Node ID 563c0e992382d785f10eb6cfbda8a16d82b70e4b
# Parent  461b44a80d761438499e4421b896754a81933ec8
workingctx: eliminate remove function

Inlining it into it's last remaining call place in cmdutil.copy.

Note that cmdutil.copy is called with the wlock already held, so no additional
locking is needed to call util.unlinkpath.

We do not need to wrap the util.unlinkpath call into a try block, because
at that point we already know whether abssrc exists or not -- thanks to the
preceding util.copyfile call. Adding a new local 'srcexists' in cmdutil.copy
for that purpose.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -281,9 +281,11 @@
                 if not os.path.isdir(targetdir):
                     os.makedirs(targetdir)
                 util.copyfile(src, target)
+                srcexists = True
             except IOError, inst:
                 if inst.errno == errno.ENOENT:
                     ui.warn(_('%s: deleted in working copy\n') % relsrc)
+                    srcexists = False
                 else:
                     ui.warn(_('%s: cannot copy - %s\n') %
                             (relsrc, inst.strerror))
@@ -301,7 +303,9 @@
         scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget,
                              dryrun=dryrun, cwd=cwd)
         if rename and not dryrun:
-            wctx.remove([abssrc], not after)
+            if not after and srcexists:
+                util.unlinkpath(repo.wjoin(abssrc))
+            wctx.forget([abssrc])
 
     # pat: ossep
     # dest ossep
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -853,20 +853,6 @@
             *[p.rev() for p in self._parents]):
             yield changectx(self._repo, a)
 
-    def remove(self, list, unlink=False):
-        wlock = self._repo.wlock()
-        try:
-            if unlink:
-                for f in list:
-                    try:
-                        util.unlinkpath(self._repo.wjoin(f))
-                    except OSError, inst:
-                        if inst.errno != errno.ENOENT:
-                            raise
-            self.forget(list)
-        finally:
-            wlock.release()
-
     def undelete(self, list):
         pctxs = self.parents()
         wlock = self._repo.wlock()


More information about the Mercurial-devel mailing list