Skip to content

Commit e97774a

Browse files
committed
#5 Accept different files for patching
Signed-off-by: Uilian Ries <uilianries@gmail.com>
1 parent 6cf9e21 commit e97774a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

patch_ng.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ def tostr(b):
8282
# Logging is controlled by logger named after the
8383
# module name (e.g. 'patch' for patch_ng.py module)
8484

85-
logger = logging.getLogger(__name__)
85+
logger = logging.getLogger("patch_ng")
8686

8787
debug = logger.debug
8888
info = logger.info
8989
warning = logger.warning
90+
error = logger.error
9091

9192
class NullHandler(logging.Handler):
9293
""" Copied from Python 2.7 to avoid getting
@@ -1008,11 +1009,11 @@ def apply(self, strip=0, root=None):
10081009
filenameo, filenamen = self.findfiles(old, new)
10091010

10101011
if not filenameo or not filenamen:
1011-
warning("source/target file does not exist:\n --- %s\n +++ %s" % (old, new))
1012+
error("source/target file does not exist:\n --- %s\n +++ %s" % (old, new))
10121013
errors += 1
10131014
continue
10141015
if not isfile(filenameo):
1015-
warning("not a file - %s" % filenameo)
1016+
error("not a file - %s" % filenameo)
10161017
errors += 1
10171018
continue
10181019

@@ -1040,7 +1041,11 @@ def apply(self, strip=0, root=None):
10401041

10411042
# check hunks in source file
10421043
if lineno+1 < hunk.startsrc+len(hunkfind)-1:
1043-
if line.rstrip(b"\r\n") == hunkfind[hunklineno]:
1044+
raw_line = line.rstrip(b"\r\n")
1045+
patch_line = hunkfind[hunklineno]
1046+
if (raw_line == patch_line) or \
1047+
((not raw_line.startswith(b"+") and not patch_line.startswith(b"+")) and
1048+
(not raw_line.startswith(b"-") and not patch_line.startswith(b"-"))):
10441049
hunklineno+=1
10451050
else:
10461051
info("file %d/%d:\t %s" % (i+1, total, filenamen))
@@ -1076,7 +1081,7 @@ def apply(self, strip=0, root=None):
10761081
break
10771082
else:
10781083
if hunkno < len(p.hunks):
1079-
warning("premature end of source file %s at hunk %d" % (filenameo, hunkno+1))
1084+
error("premature end of source file %s at hunk %d" % (filenameo, hunkno+1))
10801085
errors += 1
10811086

10821087
f2fp.close()
@@ -1086,7 +1091,6 @@ def apply(self, strip=0, root=None):
10861091
warning("already patched %s" % filenameo)
10871092
else:
10881093
warning("source file is different - %s" % filenameo)
1089-
errors += 1
10901094
if canpatch:
10911095
backupname = filenamen+b".orig"
10921096
if exists(backupname):

tests/10fuzzy/10fuzzy.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ index a6981dd..0c08f09 100644
44
+++ b/Jamroot
55
@@ -1,3 +1,4 @@
66
X
7-
Y
7+
YYYY
88
+V
99
W

0 commit comments

Comments
 (0)