Mercurial > hg-stable
changeset 5853:deb0d3518674
Merge with crew-stable
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sat, 12 Jan 2008 20:49:07 +0100 |
parents | a76395713691 (current diff) 03ce5a919ae3 (diff) |
children | 8b95f598097c |
files | mercurial/patch.py tests/test-import tests/test-import.out |
diffstat | 3 files changed, 82 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Fri Jan 11 18:33:10 2008 -0800 +++ b/mercurial/patch.py Sat Jan 12 20:49:07 2008 +0100 @@ -505,7 +505,7 @@ return -1 class hunk: - def __init__(self, desc, num, lr, context): + def __init__(self, desc, num, lr, context, gitpatch=None): self.number = num self.desc = desc self.hunk = [ desc ] @@ -515,6 +515,7 @@ self.read_context_hunk(lr) else: self.read_unified_hunk(lr) + self.gitpatch = gitpatch def read_unified_hunk(self, lr): m = unidesc.match(self.desc) @@ -669,10 +670,12 @@ return len(self.a) == self.lena and len(self.b) == self.lenb def createfile(self): - return self.starta == 0 and self.lena == 0 + create = self.gitpatch is None or self.gitpatch.op == 'ADD' + return self.starta == 0 and self.lena == 0 and create def rmfile(self): - return self.startb == 0 and self.lenb == 0 + remove = self.gitpatch is None or self.gitpatch.op == 'DELETE' + return self.startb == 0 and self.lenb == 0 and remove def fuzzit(self, l, fuzz, toponly): # this removes context lines from the top and bottom of list 'l'. It @@ -773,7 +776,7 @@ def parsefilename(str): # --- filename \t|space stuff - s = str[4:] + s = str[4:].rstrip('\r\n') i = s.find('\t') if i < 0: i = s.find(' ') @@ -905,7 +908,8 @@ try: if context == None and x.startswith('***************'): context = True - current_hunk = hunk(x, hunknum + 1, lr, context) + gpatch = changed.get(bfile[2:], (None, None))[1] + current_hunk = hunk(x, hunknum + 1, lr, context, gpatch) except PatchError, err: ui.debug(err) current_hunk = None
--- a/tests/test-import Fri Jan 11 18:33:10 2008 -0800 +++ b/tests/test-import Sat Jan 12 20:49:07 2008 +0100 @@ -153,3 +153,31 @@ hg ci -m brancha hg import -v tip.patch cd .. + +# Test hunk touching empty files (issue906) +hg init empty +cd empty +touch a +touch b1 +touch c1 +echo d > d +hg ci -Am init +echo a > a +echo b > b1 +hg mv b1 b2 +echo c > c1 +hg copy c1 c2 +rm d +touch d +hg diff --git +hg ci -m empty +hg export --git tip > empty.diff +hg up -C 0 +hg import empty.diff +for name in a b1 b2 c1 c2 d; +do + echo % $name file + test -f $name && cat $name +done +cd .. +
--- a/tests/test-import.out Fri Jan 11 18:33:10 2008 -0800 +++ b/tests/test-import.out Sat Jan 12 20:49:07 2008 +0100 @@ -134,3 +134,48 @@ patching file a Hunk #1 succeeded at 1 with fuzz 2 (offset -2 lines). a +adding a +adding b1 +adding c1 +adding d +diff --git a/a b/a +--- a/a ++++ b/a +@@ -0,0 +1,1 @@ ++a +diff --git a/b1 b/b2 +rename from b1 +rename to b2 +--- a/b1 ++++ b/b2 +@@ -0,0 +1,1 @@ ++b +diff --git a/c1 b/c1 +--- a/c1 ++++ b/c1 +@@ -0,0 +1,1 @@ ++c +diff --git a/c1 b/c2 +copy from c1 +copy to c2 +--- a/c1 ++++ b/c2 +@@ -0,0 +1,1 @@ ++c +diff --git a/d b/d +--- a/d ++++ b/d +@@ -1,1 +0,0 @@ +-d +4 files updated, 0 files merged, 2 files removed, 0 files unresolved +applying empty.diff +% a file +a +% b1 file +% b2 file +b +% c1 file +c +% c2 file +c +% d file