# HG changeset patch # User Patrick Mezard # Date 2008-02-27 23:07:37 # Node ID 36ab165abbe2856ac0893cece1c3a78dcada3325 # Parent 81afdd01686772dec02082065fc6a209a8e694aa 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. diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -890,6 +890,9 @@ def iterhunks(ui, fp, sourcefile=None): 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 @@ def iterhunks(ui, fp, sourcefile=None): 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 diff --git a/tests/test-import b/tests/test-import --- a/tests/test-import +++ b/tests/test-import @@ -207,3 +207,21 @@ do 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 .. + diff --git a/tests/test-import.out b/tests/test-import.out --- a/tests/test-import.out +++ b/tests/test-import.out @@ -223,3 +223,12 @@ c % 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