Skip to content

Commit b0b0f93

Browse files
committed
Add detailed patching status information and abort the patching process in the event of a malformed hunk.
1 parent f87339e commit b0b0f93

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

xtra/PATCH.LUA

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ local function patch(p)
5656
elseif ls == '-' then
5757
if l:sub(2,4) == "-- " then
5858
local filename = parseFileName(l)
59-
if setPatchFile(filename) then cp = filename end
6059
if bf then writeRemainder() end
60+
if setPatchFile(filename) then cp = filename print("\n'" .. cp .. "':") end
6161
else
6262
local cmp = bf:read("*l") bl = bl + 1
63-
if cmp ~= l:sub(2) then
64-
print("Malformed Hunk")
65-
end
63+
if cmp ~= l:sub(2) then print("malformed")os.exit(1) end
6664
end
6765
elseif ls == ' ' then
6866
--TODO: context line verification
@@ -72,7 +70,7 @@ local function patch(p)
7270
if cmp == line then
7371
if of then of:write(line .. '\n') ol = ol + 1 end
7472
else
75-
print("Malformed Hunk")
73+
print("malformed")os.exit(1)
7674
end
7775
end
7876

@@ -96,13 +94,16 @@ local function patch(p)
9694
end
9795
if hunk then
9896
if bl - hunk.old.start ~= hunk.old.lines or ol - hunk.new.start ~= hunk.new.lines then
99-
print("Malformed Hunk")
97+
print("malformed")os.exit(1)
98+
else
99+
print("patched")
100100
end
101101
end
102102
hunk=parseHunkHeader()
103103
if hunk then
104+
io.write("\t@@ -" .. hunk.old.start .. "," .. hunk.old.lines .. " +" .. hunk.new.start .. "," .. hunk.new.lines .. " @@: ")
104105
local skip, line = hunk.old.start - 1
105-
if hunk.new.start - 1 ~= skip then print("Malformed Hunk") end
106+
if hunk.new.start - 1 ~= skip then print("malformed")os.exit(1) end
106107
while bl < skip do
107108
line, bl = bf:read("*l"), bl + 1
108109
if of then of:write(line .. '\n') ol = ol + 1 end
@@ -112,6 +113,7 @@ local function patch(p)
112113
end
113114
end
114115
pf:close()
116+
if hunk then print("patched") end
115117
if bf then writeRemainder() end
116118
end
117119

0 commit comments

Comments
 (0)