changeset 6179:36ab165abbe2

patch: fix iterhunks() with trailing binary file removal Like some renames or copy operations, binary file removal does not generate any "file" or "hunk" action, but was not tagged as such and let iterhunk() assume no hunk was applied for the deleted file.
author Patrick Mezard <pmezard@gmail.com>
date Thu, 28 Feb 2008 00:07:37 +0100
parents 81afdd016867
children d98ef03893e6
files mercurial/patch.py tests/test-import tests/test-import.out
diffstat 3 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Wed Feb 27 14:58:44 2008 -0800
+++ b/mercurial/patch.py	Thu Feb 28 00:07:37 2008 +0100
@@ -890,6 +890,9 @@
     context = None
     lr = linereader(fp)
     dopatch = True
+    # gitworkdone is True if a git operation (copy, rename, ...) was
+    # performed already for the current file. Useful when the file
+    # section may have no hunk.
     gitworkdone = False
 
     while True:
@@ -938,8 +941,8 @@
                         changed[gp.path] = (gp.op, gp)
                 # else error?
                 # copy/rename + modify should modify target, not source
-                if changed.get(bfile[2:], (None, None))[0] in ('COPY',
-                                                               'RENAME'):
+                gitop = changed.get(bfile[2:], (None, None))[0]
+                if gitop in ('COPY', 'DELETE', 'RENAME'):
                     afile = bfile
                     gitworkdone = True
             newfile = True
--- a/tests/test-import	Wed Feb 27 14:58:44 2008 -0800
+++ b/tests/test-import	Thu Feb 28 00:07:37 2008 +0100
@@ -207,3 +207,21 @@
 done
 cd ..
 
+# Test importing a patch ending with a binary file removal
+echo % test trailing binary removal
+hg init binaryremoval
+cd binaryremoval
+echo a > a
+python -c "file('b', 'wb').write('a\x00b')"
+hg ci -Am addall
+hg rm a
+hg rm b
+hg st
+hg ci -m remove
+hg export --git . > remove.diff
+cat remove.diff | grep git
+hg up -C 0
+hg import remove.diff
+hg manifest
+cd ..
+
--- a/tests/test-import.out	Wed Feb 27 14:58:44 2008 -0800
+++ b/tests/test-import.out	Thu Feb 28 00:07:37 2008 +0100
@@ -223,3 +223,12 @@
 % c2 file
 c
 % d file
+% test trailing binary removal
+adding a
+adding b
+R a
+R b
+diff --git a/a b/a
+diff --git a/b b/b
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+applying remove.diff