33local function patch (p )
44 local pf , e = io.open (p )
55 if not pf then print (e ) os.exit (1 ) end
6+
7+ local function split (i ,d )
8+ local r = {}
9+ for m in (i .. d ):gmatch (" (.-)" .. d )do table.insert (r ,m )end
10+ return r
11+ end
12+
13+ local function parseFileName (l )
14+ local first = l :sub (5 ,5 )
15+ if first == ' "' or first == " '" then
16+ return l :match (first .. " ([^" .. first .. " ]+)" .. first , 5 )
17+ else
18+ local words = {}
19+ for v in string.gmatch (l , " %S+" ) do table.insert (words , v ) end
20+ return words [2 ]
21+ end
22+ end
23+
624 for l in pf :lines () do
725 local ls = l :sub (1 , 1 )
826 if ls == " +" then
927 if l :sub (2 ,4 ) == " ++ " then
1028 -- TODO: New file
11- print (" New File: '" .. l : sub ( 5 ) .. " '" )
29+ print (" New File: '" .. parseFileName ( l ) .. " '" )
1230 else
1331 -- TODO: Add Line
1432 print (" Add Line: '" .. l :sub (2 ) .. " '" )
1533 end
1634 elseif ls == ' -' then
1735 if l :sub (2 ,4 ) == " -- " then
1836 -- TODO: Old file
19- print (" Old File: '" .. l : sub ( 5 ) .. " '" )
37+ print (" Old File: '" .. parseFileName ( l ) .. " '" )
2038 else
2139 -- TODO: Del Line
2240 print (" Del Line: '" .. l :sub (2 ) .. " '" )
@@ -27,11 +45,6 @@ local function patch(p)
2745 elseif ls == ' @' then
2846 if l :sub (2 ,3 ) == " @ " then
2947 local function parseHunkHeader ()
30- local function split (i ,d )
31- local r = {}
32- for m in (i .. d ):gmatch (" (.-)" .. d )do table.insert (r ,m )end
33- return r
34- end
3548 local words ,old ,new = split (l ," " ),{},{}
3649 if words [2 ] then old = split (words [2 ]," ," )end
3750 if words [3 ] then new = split (words [3 ]," ," )end
0 commit comments