changeset 6280:9db24a36d182

patch: check filename is /dev/null for creation or deletion (issue 1033) Otherwise, file creation or deletion is ambiguous with file being filled or emptied.
author Patrick Mezard <pmezard@gmail.com>
date Sun, 16 Mar 2008 00:35:12 +0100
parents c50ac875ffcb
children 3e5f99b13998
files mercurial/patch.py tests/test-mq tests/test-mq.out
diffstat 3 files changed, 24 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Sat Mar 15 16:51:53 2008 -0500
+++ b/mercurial/patch.py	Sun Mar 16 00:35:12 2008 +0100
@@ -505,7 +505,7 @@
         return -1
 
 class hunk:
-    def __init__(self, desc, num, lr, context, gitpatch=None):
+    def __init__(self, desc, num, lr, context, create=False, remove=False):
         self.number = num
         self.desc = desc
         self.hunk = [ desc ]
@@ -515,7 +515,8 @@
             self.read_context_hunk(lr)
         else:
             self.read_unified_hunk(lr)
-        self.gitpatch = gitpatch
+        self.create = create
+        self.remove = remove and not create
 
     def read_unified_hunk(self, lr):
         m = unidesc.match(self.desc)
@@ -640,6 +641,7 @@
         self.hunk[0] = self.desc
 
     def reverse(self):
+        self.create, self.remove = self.remove, self.create
         origlena = self.lena
         origstarta = self.starta
         self.lena = self.lenb
@@ -670,12 +672,10 @@
         return len(self.a) == self.lena and len(self.b) == self.lenb
 
     def createfile(self):
-        create = self.gitpatch is None or self.gitpatch.op == 'ADD'
-        return self.starta == 0 and self.lena == 0 and create
+        return self.starta == 0 and self.lena == 0 and self.create
 
     def rmfile(self):
-        remove = self.gitpatch is None or self.gitpatch.op == 'DELETE'
-        return self.startb == 0 and self.lenb == 0 and remove
+        return self.startb == 0 and self.lenb == 0 and self.remove
 
     def fuzzit(self, l, fuzz, toponly):
         # this removes context lines from the top and bottom of list 'l'.  It
@@ -912,7 +912,9 @@
                 if context == None and x.startswith('***************'):
                     context = True
                 gpatch = changed.get(bfile[2:], (None, None))[1]
-                current_hunk = hunk(x, hunknum + 1, lr, context, gpatch)
+                create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD'
+                remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE'
+                current_hunk = hunk(x, hunknum + 1, lr, context, create, remove)
             except PatchError, err:
                 ui.debug(err)
                 current_hunk = None
--- a/tests/test-mq	Sat Mar 15 16:51:53 2008 -0500
+++ b/tests/test-mq	Sun Mar 16 00:35:12 2008 +0100
@@ -487,3 +487,13 @@
 qlog
 cd ..
 
+echo % 'test applying on an empty file (issue 1033)'
+hg init empty
+cd empty
+touch a
+hg ci -Am addempty
+echo a > a
+hg qnew -f -e changea
+hg qpop
+hg qpush
+cd ..
--- a/tests/test-mq.out	Sat Mar 15 16:51:53 2008 -0500
+++ b/tests/test-mq.out	Sun Mar 16 00:35:12 2008 +0100
@@ -472,3 +472,8 @@
     rev 0: add foo
 patch repo:
     rev 0: checkpoint
+% test applying on an empty file (issue 1033)
+adding a
+Patch queue now empty
+applying changea
+Now at: changea