Skip to content

Commit 92f21b0

Browse files
committed
Smoke test patch diff parsing.
1 parent da7a183 commit 92f21b0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

xtra/PATCH.LUA

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,40 @@ local function patch(p)
88
if ls == "+" then
99
if l:sub(2,4) == "++ " then
1010
--TODO: New file
11+
print("New File: '" .. l:sub(5) .. "'")
1112
else
1213
--TODO: Add Line
14+
print("Add Line: '" .. l:sub(2) .. "'")
1315
end
1416
elseif ls == '-' then
1517
if l:sub(2,4) == "-- " then
1618
--TODO: Old file
19+
print("Old File: '" .. l:sub(5) .. "'")
1720
else
1821
--TODO: Del Line
22+
print("Del Line: '" .. l:sub(2) .. "'")
1923
end
2024
elseif ls == ' ' then
2125
--TODO: context line verification
26+
print("Context: '" .. l:sub(2) .. "'")
27+
elseif ls == '@' then
28+
if l:sub(2,3) == "@ " then
29+
--TODO: Jump through file to when hunk starts
30+
local function hunkData()
31+
local function split(i,d)
32+
local r={}
33+
for m in (i..d):gmatch("(.-)"..d)do table.insert(r,m)end
34+
return r
35+
end
36+
local words,old,new=split(l," "),{},{}
37+
if words[2] then old=split(words[2],",")end
38+
if words[3] then new=split(words[3],",")end
39+
if old[1] then old[1]=old[1]:sub(2)end
40+
if new[1] then new[1]=new[1]:sub(2)end
41+
return old[1],old[2]or"1",new[1],new[2]or"1"
42+
end
43+
local a,b,c,d=hunkData()print("Hunk Header",a,b,c,d)
44+
end
2245
end
2346
end
2447
pf:close()

0 commit comments

Comments
 (0)