diff mercurial/patch.py @ 5581:8a8c341bd292

mq: missing target files do not make qpush to fail immediately (issue 835) Reported and explained by Peter Arrenbrecht <peter.arrenbrecht@gmail.com>. Following file additions were skipped but empty files were still created. This situation could lead to qrefresh losing patch information.
author Patrick Mezard <pmezard@gmail.com>
date Sun, 02 Dec 2007 13:53:29 +0100
parents 777996744942
children a583117b536a a0eb8a418442
line wrap: on
line diff
--- a/mercurial/patch.py	Tue Nov 27 23:55:03 2007 +0100
+++ b/mercurial/patch.py	Sun Dec 02 13:53:29 2007 +0100
@@ -885,6 +885,19 @@
     dopatch = True
     gitworkdone = False
 
+    def getpatchfile(afile, bfile, hunk):
+         try:
+             if sourcefile:
+                 targetfile = patchfile(ui, sourcefile)
+             else:
+                 targetfile = selectfile(afile, bfile, hunk,
+                                         strip, reverse)
+                 targetfile = patchfile(ui, targetfile)
+             return targetfile
+         except PatchError, err:
+             ui.warn(str(err) + '\n')
+             return None
+
     while True:
         newfile = False
         x = lr.readline()
@@ -912,22 +925,20 @@
                 continue
             hunknum += 1
             if not current_file:
-                if sourcefile:
-                    current_file = patchfile(ui, sourcefile)
-                else:
-                    current_file = selectfile(afile, bfile, current_hunk,
-                                              strip, reverse)
-                    current_file = patchfile(ui, current_file)
+                current_file = getpatchfile(afile, bfile, current_hunk)
+                if not current_file:
+                    current_file, current_hunk = None, None
+                    rejects += 1
+                    continue
         elif state == BFILE and x.startswith('GIT binary patch'):
             current_hunk = binhunk(changed[bfile[2:]][1])
+            hunknum += 1
             if not current_file:
-                if sourcefile:
-                    current_file = patchfile(ui, sourcefile)
-                else:
-                    current_file = selectfile(afile, bfile, current_hunk,
-                                              strip, reverse)
-                    current_file = patchfile(ui, current_file)
-            hunknum += 1
+                current_file = getpatchfile(afile, bfile, current_hunk)
+                if not current_file:
+                    current_file, current_hunk = None, None
+                    rejects += 1
+                    continue
             current_hunk.extract(fp)
         elif x.startswith('diff --git'):
             # check for git diff, scanning the whole patch file if needed