Show More
@@ -378,15 +378,13 b' class patchfile(object):' | |||||
378 | self.write() |
|
378 | self.write() | |
379 | self.write_rej() |
|
379 | self.write_rej() | |
380 |
|
380 | |||
381 |
def apply(self, h |
|
381 | def apply(self, h): | |
382 | if not h.complete(): |
|
382 | if not h.complete(): | |
383 | raise PatchError(_("bad hunk #%d %s (%d %d %d %d)") % |
|
383 | raise PatchError(_("bad hunk #%d %s (%d %d %d %d)") % | |
384 | (h.number, h.desc, len(h.a), h.lena, len(h.b), |
|
384 | (h.number, h.desc, len(h.a), h.lena, len(h.b), | |
385 | h.lenb)) |
|
385 | h.lenb)) | |
386 |
|
386 | |||
387 | self.hunks += 1 |
|
387 | self.hunks += 1 | |
388 | if reverse: |
|
|||
389 | h.reverse() |
|
|||
390 |
|
388 | |||
391 | if self.missing: |
|
389 | if self.missing: | |
392 | self.rej.append(h) |
|
390 | self.rej.append(h) | |
@@ -600,31 +598,6 b' class hunk(object):' | |||||
600 | self.startb, self.lenb) |
|
598 | self.startb, self.lenb) | |
601 | self.hunk[0] = self.desc |
|
599 | self.hunk[0] = self.desc | |
602 |
|
600 | |||
603 | def reverse(self): |
|
|||
604 | self.create, self.remove = self.remove, self.create |
|
|||
605 | origlena = self.lena |
|
|||
606 | origstarta = self.starta |
|
|||
607 | self.lena = self.lenb |
|
|||
608 | self.starta = self.startb |
|
|||
609 | self.lenb = origlena |
|
|||
610 | self.startb = origstarta |
|
|||
611 | self.a = [] |
|
|||
612 | self.b = [] |
|
|||
613 | # self.hunk[0] is the @@ description |
|
|||
614 | for x in xrange(1, len(self.hunk)): |
|
|||
615 | o = self.hunk[x] |
|
|||
616 | if o.startswith('-'): |
|
|||
617 | n = '+' + o[1:] |
|
|||
618 | self.b.append(o[1:]) |
|
|||
619 | elif o.startswith('+'): |
|
|||
620 | n = '-' + o[1:] |
|
|||
621 | self.a.append(n) |
|
|||
622 | else: |
|
|||
623 | n = o |
|
|||
624 | self.b.append(o[1:]) |
|
|||
625 | self.a.append(o) |
|
|||
626 | self.hunk[x] = o |
|
|||
627 |
|
||||
628 | def fix_newline(self): |
|
601 | def fix_newline(self): | |
629 | diffhelpers.fix_newline(self.hunk, self.a, self.b) |
|
602 | diffhelpers.fix_newline(self.hunk, self.a, self.b) | |
630 |
|
603 | |||
@@ -762,7 +735,7 b' def parsefilename(str):' | |||||
762 | return s |
|
735 | return s | |
763 | return s[:i] |
|
736 | return s[:i] | |
764 |
|
737 | |||
765 |
def selectfile(afile_orig, bfile_orig, hunk, strip |
|
738 | def selectfile(afile_orig, bfile_orig, hunk, strip): | |
766 | def pathstrip(path, count=1): |
|
739 | def pathstrip(path, count=1): | |
767 | pathlen = len(path) |
|
740 | pathlen = len(path) | |
768 | i = 0 |
|
741 | i = 0 | |
@@ -790,8 +763,6 b' def selectfile(afile_orig, bfile_orig, h' | |||||
790 | else: |
|
763 | else: | |
791 | goodb = not nullb and os.path.exists(bfile) |
|
764 | goodb = not nullb and os.path.exists(bfile) | |
792 | createfunc = hunk.createfile |
|
765 | createfunc = hunk.createfile | |
793 | if reverse: |
|
|||
794 | createfunc = hunk.rmfile |
|
|||
795 | missing = not goodb and not gooda and not createfunc() |
|
766 | missing = not goodb and not gooda and not createfunc() | |
796 |
|
767 | |||
797 | # some diff programs apparently produce create patches where the |
|
768 | # some diff programs apparently produce create patches where the | |
@@ -977,8 +948,7 b' def iterhunks(ui, fp, sourcefile=None, t' | |||||
977 | if hunknum == 0 and dopatch and not gitworkdone: |
|
948 | if hunknum == 0 and dopatch and not gitworkdone: | |
978 | raise NoHunks |
|
949 | raise NoHunks | |
979 |
|
950 | |||
980 |
def applydiff(ui, fp, changed, strip=1, sourcefile=None, |
|
951 | def applydiff(ui, fp, changed, strip=1, sourcefile=None, eol=None): | |
981 | eol=None): |
|
|||
982 | """ |
|
952 | """ | |
983 | Reads a patch from fp and tries to apply it. |
|
953 | Reads a patch from fp and tries to apply it. | |
984 |
|
954 | |||
@@ -1008,7 +978,7 b' def applydiff(ui, fp, changed, strip=1, ' | |||||
1008 | if not current_file: |
|
978 | if not current_file: | |
1009 | continue |
|
979 | continue | |
1010 | current_hunk = values |
|
980 | current_hunk = values | |
1011 |
ret = current_file.apply(current_hunk |
|
981 | ret = current_file.apply(current_hunk) | |
1012 | if ret >= 0: |
|
982 | if ret >= 0: | |
1013 | changed.setdefault(current_file.fname, None) |
|
983 | changed.setdefault(current_file.fname, None) | |
1014 | if ret > 0: |
|
984 | if ret > 0: | |
@@ -1021,7 +991,7 b' def applydiff(ui, fp, changed, strip=1, ' | |||||
1021 | current_file = patchfile(ui, sourcefile, opener, eol=eol) |
|
991 | current_file = patchfile(ui, sourcefile, opener, eol=eol) | |
1022 | else: |
|
992 | else: | |
1023 | current_file, missing = selectfile(afile, bfile, first_hunk, |
|
993 | current_file, missing = selectfile(afile, bfile, first_hunk, | |
1024 |
strip |
|
994 | strip) | |
1025 | current_file = patchfile(ui, current_file, opener, missing, eol) |
|
995 | current_file = patchfile(ui, current_file, opener, missing, eol) | |
1026 | except PatchError, err: |
|
996 | except PatchError, err: | |
1027 | ui.warn(str(err) + '\n') |
|
997 | ui.warn(str(err) + '\n') |
General Comments 0
You need to be logged in to leave comments.
Login now