Commit | Line | Data |
---|---|---|
34e49164 C |
1 | open Common |
2 | ||
3 | type patch = patchitem list | |
4 | and patchitem = File of filename * string (* header line *) * string list | |
5 | ||
ae4735db | 6 | let parse_patch filename = |
34e49164 C |
7 | let xs = Common.cat filename in |
8 | let xxs = Common.split_list_regexp "^diff" xs in | |
ae4735db | 9 | xxs +> List.map (fun (s, body) -> |
34e49164 C |
10 | if s =~ "^diff --git a/\\([^ ]*\\) b/\\([^ ]*\\)" |
11 | then begin | |
12 | let (a,b) = matched2 s in | |
13 | assert(a =$= b); | |
14 | File (a, s, body) | |
15 | end | |
16 | else failwith ("wrong line in git diff:" ^ s) | |
17 | ) | |
34e49164 | 18 | |
ae4735db C |
19 | |
20 | let unparse_patch xs outfile = | |
21 | Common.with_open_outfile outfile (fun (pr_no_nl, _chan) -> | |
34e49164 C |
22 | let pr s = pr_no_nl (s ^ "\n") in |
23 | ||
ae4735db | 24 | xs +> List.iter (function (File (file, header, body)) -> |
34e49164 C |
25 | pr header; |
26 | body +> List.iter pr; | |
27 | ) | |
28 | ) | |
ae4735db C |
29 | |
30 |