##// END OF EJS Templates
patch: fix fuzzing of hunks without previous lines (issue3264)...
Patrick Mezard -
r16123:b0c7525f stable
parent child Browse files
Show More
@@ -748,20 +748,21 b' class patchfile(object):'
748 748 self.hash = {}
749 749 for x, s in enumerate(self.lines):
750 750 self.hash.setdefault(s, []).append(x)
751 if h.hunk[-1][0] != ' ':
752 # if the hunk tried to put something at the bottom of the file
753 # override the start line and use eof here
754 search_start = len(self.lines)
755 else:
756 search_start = orig_start + self.skew
757 751
758 752 for fuzzlen in xrange(3):
759 753 for toponly in [True, False]:
760 754 old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly)
755 oldstart = oldstart + self.offset + self.skew
756 oldstart = min(oldstart, len(self.lines))
757 if old:
758 cand = self.findlines(old[0][1:], oldstart)
759 else:
760 # Only adding lines with no or fuzzed context, just
761 # take the skew in account
762 cand = [oldstart]
761 763
762 cand = self.findlines(old[0][1:], search_start)
763 764 for l in cand:
764 if diffhelpers.testhunk(old, self.lines, l) == 0:
765 if not old or diffhelpers.testhunk(old, self.lines, l) == 0:
765 766 self.lines[l : l + len(old)] = new
766 767 self.offset += len(new) - len(old)
767 768 self.skew = l - orig_start
@@ -996,3 +996,79 b' import a unified diff with no lines of c'
996 996 c2
997 997 c3
998 998 c4
999
1000 Test corner case involving fuzz and skew
1001
1002 $ hg init morecornercases
1003 $ cd morecornercases
1004
1005 $ cat > 01-no-context-beginning-of-file.diff <<EOF
1006 > diff --git a/a b/a
1007 > --- a/a
1008 > +++ b/a
1009 > @@ -1,0 +1,1 @@
1010 > +line
1011 > EOF
1012
1013 $ cat > 02-no-context-middle-of-file.diff <<EOF
1014 > diff --git a/a b/a
1015 > --- a/a
1016 > +++ b/a
1017 > @@ -1,1 +1,1 @@
1018 > -2
1019 > +add some skew
1020 > @@ -2,0 +2,1 @@
1021 > +line
1022 > EOF
1023
1024 $ cat > 03-no-context-end-of-file.diff <<EOF
1025 > diff --git a/a b/a
1026 > --- a/a
1027 > +++ b/a
1028 > @@ -10,0 +10,1 @@
1029 > +line
1030 > EOF
1031
1032 $ cat > a <<EOF
1033 > 1
1034 > 2
1035 > 3
1036 > 4
1037 > EOF
1038 $ hg ci -Am adda a
1039 $ for p in *.diff; do
1040 > hg import -v --no-commit $p
1041 > cat a
1042 > hg revert -aqC a
1043 > # patch -p1 < $p
1044 > # cat a
1045 > # hg revert -aC a
1046 > done
1047 applying 01-no-context-beginning-of-file.diff
1048 patching file a
1049 applied to working directory
1050 1
1051 line
1052 2
1053 3
1054 4
1055 applying 02-no-context-middle-of-file.diff
1056 patching file a
1057 Hunk #1 succeeded at 2 (offset 1 lines).
1058 Hunk #2 succeeded at 4 (offset 1 lines).
1059 applied to working directory
1060 1
1061 add some skew
1062 3
1063 line
1064 4
1065 applying 03-no-context-end-of-file.diff
1066 patching file a
1067 Hunk #1 succeeded at 5 (offset -6 lines).
1068 applied to working directory
1069 1
1070 2
1071 3
1072 4
1073 line
1074
General Comments 0
You need to be logged in to leave comments. Login now