Mercurial > public > mercurial-scm > hg
comparison mercurial/patch.py @ 12825:61f48581d8ef stable
Test applying context diffs
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 24 Oct 2010 12:56:38 +0200 |
parents | 80a3d1121c10 |
children | df1b65f8b4d4 66d7a1250c9b |
comparison
equal
deleted
inserted
replaced
12824:93d6559a9cbc | 12825:61f48581d8ef |
---|---|
684 if self.starta: | 684 if self.starta: |
685 self.lena += 1 | 685 self.lena += 1 |
686 for x in xrange(self.lena): | 686 for x in xrange(self.lena): |
687 l = lr.readline() | 687 l = lr.readline() |
688 if l.startswith('---'): | 688 if l.startswith('---'): |
689 # lines addition, old block is empty | |
689 lr.push(l) | 690 lr.push(l) |
690 break | 691 break |
691 s = l[2:] | 692 s = l[2:] |
692 if l.startswith('- ') or l.startswith('! '): | 693 if l.startswith('- ') or l.startswith('! '): |
693 u = '-' + s | 694 u = '-' + s |
717 self.lenb += 1 | 718 self.lenb += 1 |
718 hunki = 1 | 719 hunki = 1 |
719 for x in xrange(self.lenb): | 720 for x in xrange(self.lenb): |
720 l = lr.readline() | 721 l = lr.readline() |
721 if l.startswith('\ '): | 722 if l.startswith('\ '): |
723 # XXX: the only way to hit this is with an invalid line range. | |
724 # The no-eol marker is not counted in the line range, but I | |
725 # guess there are diff(1) out there which behave differently. | |
722 s = self.b[-1][:-1] | 726 s = self.b[-1][:-1] |
723 self.b[-1] = s | 727 self.b[-1] = s |
724 self.hunk[hunki - 1] = s | 728 self.hunk[hunki - 1] = s |
725 continue | 729 continue |
726 if not l: | 730 if not l: |
731 # line deletions, new block is empty and we hit EOF | |
727 lr.push(l) | 732 lr.push(l) |
728 break | 733 break |
729 s = l[2:] | 734 s = l[2:] |
730 if l.startswith('+ ') or l.startswith('! '): | 735 if l.startswith('+ ') or l.startswith('! '): |
731 u = '+' + s | 736 u = '+' + s |
732 elif l.startswith(' '): | 737 elif l.startswith(' '): |
733 u = ' ' + s | 738 u = ' ' + s |
734 elif len(self.b) == 0: | 739 elif len(self.b) == 0: |
735 # this can happen when the hunk does not add any lines | 740 # line deletions, new block is empty |
736 lr.push(l) | 741 lr.push(l) |
737 break | 742 break |
738 else: | 743 else: |
739 raise PatchError(_("bad hunk #%d old text line %d") % | 744 raise PatchError(_("bad hunk #%d old text line %d") % |
740 (self.number, x)) | 745 (self.number, x)) |