mq: explicitly updatedir() even if patch() fails
authorPatrick Mezard <pmezard@gmail.com>
Sun, 08 May 2011 17:48:29 +0200
changeset 14257 d035ede73434
parent 14256 d04ba50e104d
child 14258 50e3fb2ab9fa
mq: explicitly updatedir() even if patch() fails It already works that way in practice, and we intend to merge updatedir() into patch().
hgext/mq.py
mercurial/cmdutil.py
tests/test-mq-missingfiles.t
--- a/hgext/mq.py	Fri May 06 19:55:46 2011 +0300
+++ b/hgext/mq.py	Sun May 08 17:48:29 2011 +0200
@@ -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)
 
@@ -2280,7 +2281,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)
--- a/mercurial/cmdutil.py	Fri May 06 19:55:46 2011 +0300
+++ b/mercurial/cmdutil.py	Sun May 08 17:48:29 2011 +0200
@@ -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()
--- a/tests/test-mq-missingfiles.t	Fri May 06 19:55:46 2011 +0300
+++ b/tests/test-mq-missingfiles.t	Sun May 08 17:48:29 2011 +0200
@@ -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]