##// END OF EJS Templates
patch: check filename is /dev/null for creation or deletion (issue 1033)...
Patrick Mezard -
r6280:9db24a36 default
parent child Browse files
Show More
@@ -505,7 +505,7 b' class patchfile:'
505 return -1
505 return -1
506
506
507 class hunk:
507 class hunk:
508 def __init__(self, desc, num, lr, context, gitpatch=None):
508 def __init__(self, desc, num, lr, context, create=False, remove=False):
509 self.number = num
509 self.number = num
510 self.desc = desc
510 self.desc = desc
511 self.hunk = [ desc ]
511 self.hunk = [ desc ]
@@ -515,7 +515,8 b' class hunk:'
515 self.read_context_hunk(lr)
515 self.read_context_hunk(lr)
516 else:
516 else:
517 self.read_unified_hunk(lr)
517 self.read_unified_hunk(lr)
518 self.gitpatch = gitpatch
518 self.create = create
519 self.remove = remove and not create
519
520
520 def read_unified_hunk(self, lr):
521 def read_unified_hunk(self, lr):
521 m = unidesc.match(self.desc)
522 m = unidesc.match(self.desc)
@@ -640,6 +641,7 b' class hunk:'
640 self.hunk[0] = self.desc
641 self.hunk[0] = self.desc
641
642
642 def reverse(self):
643 def reverse(self):
644 self.create, self.remove = self.remove, self.create
643 origlena = self.lena
645 origlena = self.lena
644 origstarta = self.starta
646 origstarta = self.starta
645 self.lena = self.lenb
647 self.lena = self.lenb
@@ -670,12 +672,10 b' class hunk:'
670 return len(self.a) == self.lena and len(self.b) == self.lenb
672 return len(self.a) == self.lena and len(self.b) == self.lenb
671
673
672 def createfile(self):
674 def createfile(self):
673 create = self.gitpatch is None or self.gitpatch.op == 'ADD'
675 return self.starta == 0 and self.lena == 0 and self.create
674 return self.starta == 0 and self.lena == 0 and create
675
676
676 def rmfile(self):
677 def rmfile(self):
677 remove = self.gitpatch is None or self.gitpatch.op == 'DELETE'
678 return self.startb == 0 and self.lenb == 0 and self.remove
678 return self.startb == 0 and self.lenb == 0 and remove
679
679
680 def fuzzit(self, l, fuzz, toponly):
680 def fuzzit(self, l, fuzz, toponly):
681 # this removes context lines from the top and bottom of list 'l'. It
681 # this removes context lines from the top and bottom of list 'l'. It
@@ -912,7 +912,9 b' def iterhunks(ui, fp, sourcefile=None):'
912 if context == None and x.startswith('***************'):
912 if context == None and x.startswith('***************'):
913 context = True
913 context = True
914 gpatch = changed.get(bfile[2:], (None, None))[1]
914 gpatch = changed.get(bfile[2:], (None, None))[1]
915 current_hunk = hunk(x, hunknum + 1, lr, context, gpatch)
915 create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD'
916 remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE'
917 current_hunk = hunk(x, hunknum + 1, lr, context, create, remove)
916 except PatchError, err:
918 except PatchError, err:
917 ui.debug(err)
919 ui.debug(err)
918 current_hunk = None
920 current_hunk = None
@@ -487,3 +487,13 b' cd qclonedest2'
487 qlog
487 qlog
488 cd ..
488 cd ..
489
489
490 echo % 'test applying on an empty file (issue 1033)'
491 hg init empty
492 cd empty
493 touch a
494 hg ci -Am addempty
495 echo a > a
496 hg qnew -f -e changea
497 hg qpop
498 hg qpush
499 cd ..
@@ -472,3 +472,8 b' main repo:'
472 rev 0: add foo
472 rev 0: add foo
473 patch repo:
473 patch repo:
474 rev 0: checkpoint
474 rev 0: checkpoint
475 % test applying on an empty file (issue 1033)
476 adding a
477 Patch queue now empty
478 applying changea
479 Now at: changea
General Comments 0
You need to be logged in to leave comments. Login now