patch: keep patching after missing copy source (issue3480) stable
authorPatrick Mezard <patrick@mezard.eu>
Fri, 01 Jun 2012 17:37:56 +0200
branchstable
changeset 16813 6d42c797ca6e
parent 16805 9a99224a6409
child 16814 9da5a2864f3f
patch: keep patching after missing copy source (issue3480) When applying a patch renaming/copying 'a' to 'b' on a revision where 'a' does not exist, the patching process would abort immediately, without processing the remaining hunks and without reporting it. This patch makes the patching no longer abort and possible hunks applied on the copied/renamed file be written in reject files.
mercurial/patch.py
tests/test-mq-missingfiles.t
--- a/mercurial/patch.py	Tue May 29 18:27:12 2012 +0300
+++ b/mercurial/patch.py	Fri Jun 01 17:37:56 2012 +0200
@@ -1343,8 +1343,17 @@
         elif state == 'git':
             for gp in values:
                 path = pstrip(gp.oldpath)
-                data, mode = backend.getfile(path)
-                store.setfile(path, data, mode)
+                try:
+                    data, mode = backend.getfile(path)
+                except IOError, e:
+                    if e.errno != errno.ENOENT:
+                        raise
+                    # The error ignored here will trigger a getfile()
+                    # error in a place more appropriate for error
+                    # handling, and will not interrupt the patching
+                    # process.
+                else:
+                    store.setfile(path, data, mode)
         else:
             raise util.Abort(_('unsupported parser state: %s') % state)
 
--- a/tests/test-mq-missingfiles.t	Tue May 29 18:27:12 2012 +0300
+++ b/tests/test-mq-missingfiles.t	Fri Jun 01 17:37:56 2012 +0200
@@ -73,6 +73,53 @@
   +c
   +c
 
+Test missing renamed file
+
+  $ hg qpop
+  popping changeb
+  patch queue now empty
+  $ hg up -qC 0
+  $ echo a > a
+  $ hg mv b bb
+  $ python ../writelines.py bb 2 'b\n' 10 'a\n' 2 'c\n'
+  $ echo c > c
+  $ hg add a c
+  $ hg qnew changebb
+  $ hg qpop
+  popping changebb
+  patch queue now empty
+  $ hg up -qC 1
+  $ hg qpush
+  applying changebb
+  patching file bb
+  Hunk #1 FAILED at 0
+  Hunk #2 FAILED at 7
+  2 out of 2 hunks FAILED -- saving rejects to file bb.rej
+  b not tracked!
+  patch failed, unable to continue (try -v)
+  patch failed, rejects left in working dir
+  errors during apply, please fix and refresh changebb
+  [2]
+  $ cat a
+  a
+  $ cat c
+  c
+  $ cat bb.rej
+  --- bb
+  +++ bb
+  @@ -1,3 +1,5 @@
+  +b
+  +b
+   a
+   a
+   a
+  @@ -8,3 +10,5 @@
+   a
+   a
+   a
+  +c
+  +c
+
   $ cd ..