@@ -1044,31 +1044,30 @@ def apply(self, strip=0, root=None, fuzz=False):
10441044
10451045 # check hunks in source file
10461046 if lineno + 1 < hunk .startsrc + len (hunkfind )- 1 :
1047- raw_line = line .rstrip (b"\r \n " )
1048- patch_line = hunkfind [hunklineno ]
1049- if (raw_line == patch_line ) or \
1050- (fuzz and (not raw_line .startswith (b"+" ) and not patch_line .startswith (b"+" )) and
1051- (not raw_line .startswith (b"-" ) and not patch_line .startswith (b"-" ))):
1052- hunklineno += 1
1047+ if line .rstrip (b"\r \n " ) == hunkfind [hunklineno ]:
1048+ hunklineno += 1
10531049 else :
1054- info ("file %d/%d:\t %s" % (i + 1 , total , filenamen ))
1055- info (" hunk no.%d doesn't match source file at line %d" % (hunkno + 1 , lineno + 1 ))
1056- info (" expected: %s" % hunkfind [hunklineno ])
1057- info (" actual : %s" % line .rstrip (b"\r \n " ))
1058- # not counting this as error, because file may already be patched.
1059- # check if file is already patched is done after the number of
1060- # invalid hunks if found
1061- # TODO: check hunks against source/target file in one pass
1062- # API - check(stream, srchunks, tgthunks)
1063- # return tuple (srcerrs, tgterrs)
1064-
1065- # continue to check other hunks for completeness
1066- hunkno += 1
1067- if hunkno < len (p .hunks ):
1068- hunk = p .hunks [hunkno ]
1069- continue
1050+ warning ("file %d/%d:\t %s" % (i + 1 , total , filenamen ))
1051+ warning (" hunk no.%d doesn't match source file at line %d" % (hunkno + 1 , lineno + 1 ))
1052+ warning (" expected: %s" % hunkfind [hunklineno ])
1053+ warning (" actual : %s" % line .rstrip (b"\r \n " ))
1054+ if fuzz :
1055+ hunklineno += 1
10701056 else :
1071- break
1057+ # not counting this as error, because file may already be patched.
1058+ # check if file is already patched is done after the number of
1059+ # invalid hunks if found
1060+ # TODO: check hunks against source/target file in one pass
1061+ # API - check(stream, srchunks, tgthunks)
1062+ # return tuple (srcerrs, tgterrs)
1063+
1064+ # continue to check other hunks for completeness
1065+ hunkno += 1
1066+ if hunkno < len (p .hunks ):
1067+ hunk = p .hunks [hunkno ]
1068+ continue
1069+ else :
1070+ break
10721071
10731072 # check if processed line is the last line
10741073 if len (hunkfind ) == 0 or lineno + 1 == hunk .startsrc + len (hunkfind )- 1 :
@@ -1312,6 +1311,7 @@ def main():
13121311 help = "strip N path components from filenames" )
13131312 opt .add_option ("--revert" , action = "store_true" ,
13141313 help = "apply patch in reverse order (unpatch)" )
1314+ opt .add_option ("-f" , "--fuzz" , action = "store_true" , dest = "fuzz" , help = "Accept fuuzzy patches" )
13151315 (options , args ) = opt .parse_args ()
13161316
13171317 if not args and sys .argv [- 1 :] != ['--' ]:
@@ -1350,7 +1350,7 @@ def main():
13501350 if options .revert :
13511351 patch .revert (options .strip , root = options .directory ) or sys .exit (- 1 )
13521352 else :
1353- patch .apply (options .strip , root = options .directory ) or sys .exit (- 1 )
1353+ patch .apply (options .strip , root = options .directory , fuzz = options . fuzz ) or sys .exit (- 1 )
13541354
13551355 # todo: document and test line ends handling logic - patch_ng.py detects proper line-endings
13561356 # for inserted hunks and issues a warning if patched file has incosistent line ends
0 commit comments