##// END OF EJS Templates
patch: fuzz more aggressively to match patch(1) behaviour...
Patrick Mezard -
r16124:0e0060bf stable
parent child Browse files
Show More
@@ -973,7 +973,7 b' class hunk(object):'
973 # this removes context lines from the top and bottom of list 'l'. It
973 # this removes context lines from the top and bottom of list 'l'. It
974 # checks the hunk to make sure only context lines are removed, and then
974 # checks the hunk to make sure only context lines are removed, and then
975 # returns a new shortened list of lines.
975 # returns a new shortened list of lines.
976 fuzz = min(fuzz, len(old)-1)
976 fuzz = min(fuzz, len(old))
977 if fuzz:
977 if fuzz:
978 top = 0
978 top = 0
979 bot = 0
979 bot = 0
@@ -991,18 +991,8 b' class hunk(object):'
991 else:
991 else:
992 break
992 break
993
993
994 # top and bot now count context in the hunk
994 bot = min(fuzz, bot)
995 # adjust them if either one is short
995 top = min(fuzz, top)
996 context = max(top, bot, 3)
997 if bot < context:
998 bot = max(0, fuzz - (context - bot))
999 else:
1000 bot = min(fuzz, bot)
1001 if top < context:
1002 top = max(0, fuzz - (context - top))
1003 else:
1004 top = min(fuzz, top)
1005
1006 return old[top:len(old)-bot], new[top:len(new)-bot], top
996 return old[top:len(old)-bot], new[top:len(new)-bot], top
1007 return old, new, 0
997 return old, new, 0
1008
998
@@ -111,7 +111,15 b' Test unsupported combinations'
111
111
112 Test commit editor
112 Test commit editor
113
113
114 $ hg diff -c 1 > ../test.diff
114 $ cat > ../test.diff <<EOF
115 > diff -r 07f494440405 -r 4e322f7ce8e3 a
116 > --- a/a Thu Jan 01 00:00:00 1970 +0000
117 > +++ b/a Thu Jan 01 00:00:00 1970 +0000
118 > @@ -1,1 +1,2 @@
119 > -a
120 > +b
121 > +c
122 > EOF
115 $ HGEDITOR=cat hg import --bypass ../test.diff
123 $ HGEDITOR=cat hg import --bypass ../test.diff
116 applying ../test.diff
124 applying ../test.diff
117
125
@@ -138,7 +146,7 b' Test patch.eol is handled'
138 $ hg --config patch.eol=auto import -d '0 0' -m 'test patch.eol' --bypass ../test.diff
146 $ hg --config patch.eol=auto import -d '0 0' -m 'test patch.eol' --bypass ../test.diff
139 applying ../test.diff
147 applying ../test.diff
140 $ shortlog
148 $ shortlog
141 o 3:d7805b4d2cb3 test 0 0 - default - test patch.eol
149 o 3:c606edafba99 test 0 0 - default - test patch.eol
142 |
150 |
143 @ 2:872023de769d test 0 0 - default - makeacrlf
151 @ 2:872023de769d test 0 0 - default - makeacrlf
144 |
152 |
@@ -445,7 +445,7 b' Test fuzziness (ambiguous patch location'
445 $ hg import --no-commit -v fuzzy-tip.patch
445 $ hg import --no-commit -v fuzzy-tip.patch
446 applying fuzzy-tip.patch
446 applying fuzzy-tip.patch
447 patching file a
447 patching file a
448 Hunk #1 succeeded at 1 with fuzz 2 (offset -2 lines).
448 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
449 applied to working directory
449 applied to working directory
450 $ hg revert -a
450 $ hg revert -a
451 reverting a
451 reverting a
@@ -462,7 +462,7 b' test fuzziness with eol=auto'
462 $ hg --config patch.eol=auto import --no-commit -v fuzzy-tip.patch
462 $ hg --config patch.eol=auto import --no-commit -v fuzzy-tip.patch
463 applying fuzzy-tip.patch
463 applying fuzzy-tip.patch
464 patching file a
464 patching file a
465 Hunk #1 succeeded at 1 with fuzz 2 (offset -2 lines).
465 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
466 applied to working directory
466 applied to working directory
467 $ cd ..
467 $ cd ..
468
468
@@ -1029,6 +1029,19 b' Test corner case involving fuzz and skew'
1029 > +line
1029 > +line
1030 > EOF
1030 > EOF
1031
1031
1032 $ cat > 04-middle-of-file-completely-fuzzed.diff <<EOF
1033 > diff --git a/a b/a
1034 > --- a/a
1035 > +++ b/a
1036 > @@ -1,1 +1,1 @@
1037 > -2
1038 > +add some skew
1039 > @@ -2,2 +2,3 @@
1040 > not matching, should fuzz
1041 > ... a bit
1042 > +line
1043 > EOF
1044
1032 $ cat > a <<EOF
1045 $ cat > a <<EOF
1033 > 1
1046 > 1
1034 > 2
1047 > 2
@@ -1071,4 +1084,14 b' Test corner case involving fuzz and skew'
1071 3
1084 3
1072 4
1085 4
1073 line
1086 line
1087 applying 04-middle-of-file-completely-fuzzed.diff
1088 patching file a
1089 Hunk #1 succeeded at 2 (offset 1 lines).
1090 Hunk #2 succeeded at 5 with fuzz 2 (offset 1 lines).
1091 applied to working directory
1092 1
1093 add some skew
1094 3
1095 4
1096 line
1074
1097
@@ -125,12 +125,10 b' Merge:'
125 merging with queue at: $TESTTMP/t2/.hg/refqueue (glob)
125 merging with queue at: $TESTTMP/t2/.hg/refqueue (glob)
126 applying patcha
126 applying patcha
127 patching file a
127 patching file a
128 Hunk #1 FAILED at 0
128 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
129 1 out of 1 hunks FAILED -- saving rejects to file a.rej
129 fuzz found when applying patch, stopping
130 patch failed, unable to continue (try -v)
131 patch failed, rejects left in working dir
132 patch didn't work out, merging patcha
130 patch didn't work out, merging patcha
133 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
131 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
134 0 files updated, 2 files merged, 0 files removed, 0 files unresolved
132 0 files updated, 2 files merged, 0 files removed, 0 files unresolved
135 (branch merge, don't forget to commit)
133 (branch merge, don't forget to commit)
136 applying patcha2
134 applying patcha2
General Comments 0
You need to be logged in to leave comments. Login now