@@ -957,9 +957,12 @@ def strip_path(self, path, base_path, strip=0):
957957
958958
959959
960- def apply (self , strip = 0 , root = None ):
960+ def apply (self , strip = 0 , root = None , fuzz = False ):
961961 """ Apply parsed patch, optionally stripping leading components
962962 from file paths. `root` parameter specifies working dir.
963+ :param strip: Strip patch path
964+ :param root: Folder to apply the patch
965+ :param fuzz: Accept fuzzy patches
963966 return True on success
964967 """
965968 items = []
@@ -1044,7 +1047,7 @@ def apply(self, strip=0, root=None):
10441047 raw_line = line .rstrip (b"\r \n " )
10451048 patch_line = hunkfind [hunklineno ]
10461049 if (raw_line == patch_line ) or \
1047- ((not raw_line .startswith (b"+" ) and not patch_line .startswith (b"+" )) and
1050+ (fuzz and (not raw_line .startswith (b"+" ) and not patch_line .startswith (b"+" )) and
10481051 (not raw_line .startswith (b"-" ) and not patch_line .startswith (b"-" ))):
10491052 hunklineno += 1
10501053 else :
@@ -1090,7 +1093,11 @@ def apply(self, strip=0, root=None):
10901093 if self ._match_file_hunks (filenameo , p .hunks ):
10911094 warning ("already patched %s" % filenameo )
10921095 else :
1093- warning ("source file is different - %s" % filenameo )
1096+ if fuzz :
1097+ warning ("source file is different - %s" % filenameo )
1098+ else :
1099+ error ("source file is different - %s" % filenameo )
1100+ errors += 1
10941101 if canpatch :
10951102 backupname = filenamen + b".orig"
10961103 if exists (backupname ):
0 commit comments