Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 9393:23c4e772c172
patch: remove the unused, broken reverse() function
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Sun, 23 Aug 2009 14:32:58 +0200 |
parents | 039bce1b505f |
children | 4c041f1ee1b4 |
comparison
equal
deleted
inserted
replaced
9392:039bce1b505f | 9393:23c4e772c172 |
---|---|
376 | 376 |
377 def close(self): | 377 def close(self): |
378 self.write() | 378 self.write() |
379 self.write_rej() | 379 self.write_rej() |
380 | 380 |
381 def apply(self, h, reverse): | 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) |
393 return -1 | 391 return -1 |
394 | 392 |
598 # @@ -start,len +start,len @@ | 596 # @@ -start,len +start,len @@ |
599 self.desc = "@@ -%d,%d +%d,%d @@\n" % (self.starta, self.lena, | 597 self.desc = "@@ -%d,%d +%d,%d @@\n" % (self.starta, self.lena, |
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 |
631 def complete(self): | 604 def complete(self): |
632 return len(self.a) == self.lena and len(self.b) == self.lenb | 605 return len(self.a) == self.lena and len(self.b) == self.lenb |
760 i = s.find(' ') | 733 i = s.find(' ') |
761 if i < 0: | 734 if i < 0: |
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, reverse): | 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 |
769 if count == 0: | 742 if count == 0: |
770 return '', path.rstrip() | 743 return '', path.rstrip() |
788 if afile == bfile: | 761 if afile == bfile: |
789 goodb = gooda | 762 goodb = gooda |
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 |
798 # afile is not /dev/null, but rather the same name as the bfile | 769 # afile is not /dev/null, but rather the same name as the bfile |
799 if missing and afile == bfile: | 770 if missing and afile == bfile: |
975 current_hunk.desc)) | 946 current_hunk.desc)) |
976 | 947 |
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, reverse=False, | 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 |
985 The dict 'changed' is filled in with all of the filenames changed | 955 The dict 'changed' is filled in with all of the filenames changed |
986 by the patch. Returns 0 for a clean patch, -1 if any rejects were | 956 by the patch. Returns 0 for a clean patch, -1 if any rejects were |
1006 for state, values in iterhunks(ui, fp, sourcefile, textmode): | 976 for state, values in iterhunks(ui, fp, sourcefile, textmode): |
1007 if state == 'hunk': | 977 if state == 'hunk': |
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, reverse) | 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: |
1015 err = 1 | 985 err = 1 |
1016 elif state == 'file': | 986 elif state == 'file': |
1019 try: | 989 try: |
1020 if sourcefile: | 990 if sourcefile: |
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, reverse) | 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') |
1028 current_file, current_hunk = None, None | 998 current_file, current_hunk = None, None |
1029 rejects += 1 | 999 rejects += 1 |