[PATCH 1 of 4] mq: explicitely updatedir() even if patch() fails

Patrick Mezard pmezard at gmail.com
Sat May 7 12:16:46 CDT 2011


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1304787686 -7200
# Node ID a6cee4c55e77581afaafc3eb3bb11ddbd30ff533
# Parent  c9720ada999c17cc9d1d7aa64f0851cd68df428b
mq: explicitely updatedir() even if patch() fails

It already works that way in practice, and we intend to merge updatedir() into
patch().

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -614,16 +614,18 @@
         patchfile: name of patch file'''
         files = {}
         try:
-            fuzz = patchmod.patch(patchfile, self.ui, strip=1, cwd=repo.root,
-                               files=files, eolmode=None)
+            try:
+                fuzz = patchmod.patch(patchfile, self.ui, strip=1,
+                                      cwd=repo.root, files=files, eolmode=None)
+            finally:
+                files = cmdutil.updatedir(self.ui, repo, files)
+            return (True, files, fuzz)
         except Exception, inst:
             self.ui.note(str(inst) + '\n')
             if not self.ui.verbose:
                 self.ui.warn(_("patch failed, unable to continue (try -v)\n"))
             return (False, files, False)
 
-        return (True, files, fuzz)
-
     def apply(self, repo, series, list=False, update_status=True,
               strict=False, patchdir=None, merge=None, all_files=None):
         wlock = lock = tr = None
@@ -707,7 +709,6 @@
                 p1, p2 = repo.dirstate.parents()
                 repo.dirstate.setparents(p1, merge)
 
-            files = cmdutil.updatedir(self.ui, repo, files)
             match = cmdutil.matchfiles(repo, files or [])
             n = repo.commit(message, ph.user, ph.date, match=match, force=True)
 
@@ -2263,7 +2264,6 @@
         (patchsuccess, files, fuzz) = q.patch(repo, pf)
         if not patchsuccess:
             raise util.Abort(_('error folding patch %s') % p)
-        cmdutil.updatedir(ui, repo, files)
 
     if not message:
         ph = patchheader(q.join(parent), q.plainmode)
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -335,7 +335,7 @@
 def updatedir(ui, repo, patches, similarity=0):
     '''Update dirstate after patch application according to metadata'''
     if not patches:
-        return
+        return []
     copies = []
     removes = set()
     cfiles = patches.keys()
diff --git a/tests/test-mq-missingfiles.t b/tests/test-mq-missingfiles.t
--- a/tests/test-mq-missingfiles.t
+++ b/tests/test-mq-missingfiles.t
@@ -101,8 +101,8 @@
   applying changeb
   unable to find 'b' for patching
   1 out of 1 hunks FAILED -- saving rejects to file b.rej
+  b: No such file or directory
   patch failed, unable to continue (try -v)
-  b: No such file or directory
   patch failed, rejects left in working dir
   errors during apply, please fix and refresh changeb
   [2]


More information about the Mercurial-devel mailing list