equal
deleted
inserted
replaced
503 self.ui.warn(_("Hunk #%d FAILED at %d\n") % (h.number, orig_start)) |
503 self.ui.warn(_("Hunk #%d FAILED at %d\n") % (h.number, orig_start)) |
504 self.rej.append(h) |
504 self.rej.append(h) |
505 return -1 |
505 return -1 |
506 |
506 |
507 class hunk: |
507 class hunk: |
508 def __init__(self, desc, num, lr, context): |
508 def __init__(self, desc, num, lr, context, gitpatch=None): |
509 self.number = num |
509 self.number = num |
510 self.desc = desc |
510 self.desc = desc |
511 self.hunk = [ desc ] |
511 self.hunk = [ desc ] |
512 self.a = [] |
512 self.a = [] |
513 self.b = [] |
513 self.b = [] |
514 if context: |
514 if context: |
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 |
519 |
519 def read_unified_hunk(self, lr): |
520 def read_unified_hunk(self, lr): |
520 m = unidesc.match(self.desc) |
521 m = unidesc.match(self.desc) |
521 if not m: |
522 if not m: |
522 raise PatchError(_("bad hunk #%d") % self.number) |
523 raise PatchError(_("bad hunk #%d") % self.number) |
667 |
668 |
668 def complete(self): |
669 def complete(self): |
669 return len(self.a) == self.lena and len(self.b) == self.lenb |
670 return len(self.a) == self.lena and len(self.b) == self.lenb |
670 |
671 |
671 def createfile(self): |
672 def createfile(self): |
672 return self.starta == 0 and self.lena == 0 |
673 create = self.gitpatch is None or self.gitpatch.op == 'ADD' |
|
674 return self.starta == 0 and self.lena == 0 and create |
673 |
675 |
674 def rmfile(self): |
676 def rmfile(self): |
675 return self.startb == 0 and self.lenb == 0 |
677 remove = self.gitpatch is None or self.gitpatch.op == 'DELETE' |
|
678 return self.startb == 0 and self.lenb == 0 and remove |
676 |
679 |
677 def fuzzit(self, l, fuzz, toponly): |
680 def fuzzit(self, l, fuzz, toponly): |
678 # 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 |
679 # checks the hunk to make sure only context lines are removed, and then |
682 # checks the hunk to make sure only context lines are removed, and then |
680 # returns a new shortened list of lines. |
683 # returns a new shortened list of lines. |
771 len(text), size) |
774 len(text), size) |
772 self.text = text |
775 self.text = text |
773 |
776 |
774 def parsefilename(str): |
777 def parsefilename(str): |
775 # --- filename \t|space stuff |
778 # --- filename \t|space stuff |
776 s = str[4:] |
779 s = str[4:].rstrip('\r\n') |
777 i = s.find('\t') |
780 i = s.find('\t') |
778 if i < 0: |
781 if i < 0: |
779 i = s.find(' ') |
782 i = s.find(' ') |
780 if i < 0: |
783 if i < 0: |
781 return s |
784 return s |
903 if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or |
906 if ((sourcefile or state == BFILE) and ((not context and x[0] == '@') or |
904 ((context or context == None) and x.startswith('***************')))): |
907 ((context or context == None) and x.startswith('***************')))): |
905 try: |
908 try: |
906 if context == None and x.startswith('***************'): |
909 if context == None and x.startswith('***************'): |
907 context = True |
910 context = True |
908 current_hunk = hunk(x, hunknum + 1, lr, context) |
911 gpatch = changed.get(bfile[2:], (None, None))[1] |
|
912 current_hunk = hunk(x, hunknum + 1, lr, context, gpatch) |
909 except PatchError, err: |
913 except PatchError, err: |
910 ui.debug(err) |
914 ui.debug(err) |
911 current_hunk = None |
915 current_hunk = None |
912 continue |
916 continue |
913 hunknum += 1 |
917 hunknum += 1 |