Skip to content

Commit 6e56d8d

Browse files
committed
Fixed numeric logic in PATCH.LUA
1 parent ee322cd commit 6e56d8d

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

xtra/PATCH.LUA

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,14 @@ local function patch(p)
9292
new = { start = tonumber(new[1]), lines = tonumber(new[2]) or 1 }
9393
}
9494
end
95-
if hunk then
96-
if bl - hunk.old.start ~= hunk.old.lines or ol - hunk.new.start ~= hunk.new.lines then
97-
print("malformed")os.exit(1)
98-
else
99-
print("patched")
100-
end
101-
end
102-
hunk=parseHunkHeader()
103-
if hunk then
104-
io.write("\t@@ -" .. hunk.old.start .. "," .. hunk.old.lines .. " +" .. hunk.new.start .. "," .. hunk.new.lines .. " @@: ")
105-
local skip, line = hunk.old.start > 0 and hunk.old.start - 1 or 0
106-
if hunk.new.start - 1 ~= skip then print("malformed")os.exit(1) end
107-
while bl < skip do
108-
line, bl = bf:read("*l"), bl + 1
109-
if of then of:write(line .. '\n') ol = ol + 1 end
110-
end
111-
end
112-
end
113-
end
114-
end
95+
if hunk then if hunk.old.lines~=bl-(hunk.old.start-1)or hunk.new.lines~=ol-(hunk.new.start-1)then print("malformed")os.exit(1)else print("patched")end end
96+
hunk=parseHunkHeader()if hunk then
97+
io.write("\t@@ -"..hunk.old.start..","..hunk.old.lines.." +"..hunk.new.start..","..hunk.new.lines.." @@: ")
98+
local skip=hunk.old.start>0 and(hunk.old.start-1)-bl or 0
99+
if skip<0 then print("malformed (overlapping hunk)")os.exit(1)end
100+
for _=1,skip do
101+
local ctx=bf:read("*l")if not ctx then print("malformed (unexpected EOF in context)")os.exit(1)end
102+
bl=bl+1 if of then of:write(ctx.."\n")ol=ol+1 end end end end end end
115103
pf:close()
116104
if hunk then print("patched") end
117105
if bf then writeRemainder() end

0 commit comments

Comments
 (0)