updated on Mon Jan 23 12:00:23 UTC 2012
[aur-mirror.git] / monotone-viz / monotone-viz-0_46.patch
blobe245d5564a2534c3fa9c5b20400ff983f7463e9c
2 # old_revision [78a87d334b15645b2bb54afec96ac5d3e1e45350]
4 # patch "automate.ml"
5 # from [bc697ff6c3768259b1838e5638552f448433b53a]
6 # to [81cd3139b4ac5a13091737bf47b0c2e1b62eea62]
8 ============================================================
9 *** automate.ml bc697ff6c3768259b1838e5638552f448433b53a
10 --- automate.ml 81cd3139b4ac5a13091737bf47b0c2e1b62eea62
11 *************** type output = [
12 *** 44,50 ****
13 | `OUTPUT of string
14 | `ERROR of string
15 | `SYNTAX_ERROR of string]
16 ! type chunk = command_id * int * bool * string
17 type process = {
18 p_in : in_watch ;
19 p_out : out_watch ;
20 --- 44,50 ----
21 | `OUTPUT of string
22 | `ERROR of string
23 | `SYNTAX_ERROR of string]
24 ! type chunk = command_id * bool * string
25 type process = {
26 p_in : in_watch ;
27 p_out : out_watch ;
28 *************** let _read_cb w conditions =
29 *** 152,158 ****
30 try
31 match Giochannel.read_chars w.out_w.w_chan w.out_sb with
32 | `NORMAL read ->
33 ! if debug then log "%s cb: read %d" w.out_w.w_name read ;
34 Buffer.add_substring w.out_buffer w.out_sb 0 read ;
35 w.out_cb w.out_buffer
36 | `EOF ->
37 --- 152,158 ----
38 try
39 match Giochannel.read_chars w.out_w.w_chan w.out_sb with
40 | `NORMAL read ->
41 ! if debug then log "%s cb: read %d" w.out_w.w_name read;
42 Buffer.add_substring w.out_buffer w.out_sb 0 read ;
43 w.out_cb w.out_buffer
44 | `EOF ->
45 *************** let encode_stdio cmd =
46 *** 258,265 ****
50 ! let find_four_colon b =
51 ! let to_find = ref 4 in
52 let i = ref 0 in
53 while !to_find > 0 do
54 let c = Buffer.nth b !i in
55 --- 258,265 ----
59 ! let find_three_colon b =
60 ! let to_find = ref 3 in
61 let i = ref 0 in
62 while !to_find > 0 do
63 let c = Buffer.nth b !i in
64 *************** let decode_stdio_chunk b =
65 *** 277,298 ****
67 let decode_stdio_chunk b =
68 try
69 ! let header_len = find_four_colon b in
70 let h = Buffer.sub b 0 header_len in
71 let c1 = String.index_from h 0 ':' in
72 let number = int_of_string (string_slice ~e:c1 h) in
73 - let code = int_of_char h.[c1 + 1] - int_of_char '0' in
74 let c2 = String.index_from h (c1 + 1) ':' in
75 ! let last = h.[c2 + 1] in
76 let c3 = String.index_from h (c2 + 1) ':' in
77 ! let c4 = String.index_from h (c3 + 1) ':' in
78 ! let len = int_of_string (string_slice ~s:(c3 + 1) ~e:c4 h) in
79 if Buffer.length b < header_len + len
80 then
81 `INCOMPLETE
82 else
83 let data = truncate_buffer b header_len len in
84 ! `CHUNK (number, code, last = 'l', data)
85 with Invalid_argument _ ->
86 `INCOMPLETE
88 --- 277,296 ----
90 let decode_stdio_chunk b =
91 try
92 ! let header_len = find_three_colon b in
93 let h = Buffer.sub b 0 header_len in
94 let c1 = String.index_from h 0 ':' in
95 let number = int_of_string (string_slice ~e:c1 h) in
96 let c2 = String.index_from h (c1 + 1) ':' in
97 ! let last = h.[c1 + 1] in
98 let c3 = String.index_from h (c2 + 1) ':' in
99 ! let len = int_of_string (string_slice ~s:(c2 + 1) ~e:c3 h) in
100 if Buffer.length b < header_len + len
101 then
102 `INCOMPLETE
103 else
104 let data = truncate_buffer b header_len len in
105 ! `CHUNK (number, last = 'l', data)
106 with Invalid_argument _ ->
107 `INCOMPLETE
109 *************** let rec out_cb p b =
110 *** 305,315 ****
111 | `INCOMPLETE ->
114 ! | `CHUNK (nb, _, _, _) when aborted_cmd p nb ->
115 p.chunks <- List.remove_assoc nb p.chunks ;
116 out_cb p b
118 ! | `CHUNK ((nb, code, false, data) as chunk) ->
119 if debug then log "decoded a chunk" ;
120 let previous_chunks =
121 try List.assoc nb p.chunks
122 --- 303,313 ----
123 | `INCOMPLETE ->
126 ! | `CHUNK (nb, _, _) when aborted_cmd p nb ->
127 p.chunks <- List.remove_assoc nb p.chunks ;
128 out_cb p b
130 ! | `CHUNK ((nb, false, data) as chunk) ->
131 if debug then log "decoded a chunk" ;
132 let previous_chunks =
133 try List.assoc nb p.chunks
134 *************** let rec out_cb p b =
135 *** 320,326 ****
136 previous_chunks := chunk :: !previous_chunks ;
137 out_cb p b
139 ! | `CHUNK ((nb, code, true, data) as chunk) ->
140 if debug then log "decoded last chunk" ;
141 let chunks =
142 try
143 --- 318,324 ----
144 previous_chunks := chunk :: !previous_chunks ;
145 out_cb p b
147 ! | `CHUNK ((nb, true, data) as chunk) ->
148 if debug then log "decoded last chunk" ;
149 let chunks =
150 try
151 *************** let rec out_cb p b =
152 *** 333,346 ****
153 p.callbacks <- List.remove_assoc nb p.callbacks ;
154 let msg =
155 String.concat ""
156 ! (List.map (fun (_, _, _, d) -> d) chunks) in
157 ! let data =
158 ! match code with
159 ! | 0 -> `OUTPUT msg
160 ! | 1 -> `SYNTAX_ERROR msg
161 ! | 2 -> `ERROR msg
162 | _ -> failwith "invalid_code in automate stdio output" in
163 ! ignore (Glib.Idle.add ~prio:0 (fun () -> cb data ; false)) ;
164 out_cb p b
167 --- 331,344 ----
168 p.callbacks <- List.remove_assoc nb p.callbacks ;
169 let msg =
170 String.concat ""
171 ! (List.map (function (_, false, d) -> d | (_, true, d) -> "") chunks) in
172 ! let code =
173 ! match data with
174 ! | "0" -> `OUTPUT msg
175 ! | "1" -> `SYNTAX_ERROR msg
176 ! | "2" -> `ERROR msg
177 | _ -> failwith "invalid_code in automate stdio output" in
178 ! ignore (Glib.Idle.add ~prio:0 (fun () -> cb code ; false)) ;
179 out_cb p b
182 *************** let spawn mtn db =
183 *** 409,414 ****
184 --- 407,426 ----
185 chunks = [] ;
186 exit_cb = (fun _ -> assert false)
187 } in
188 + let rec check_version buf =
189 + if String.contains buf '\n' then
190 + String.length buf >= 18 && String.sub buf 0 18 = "format-version: 2\n"
191 + else
192 + match Giochannel.read_chars p.p_out.out_w.w_chan p.p_out.out_sb with
193 + | `NORMAL read -> check_version (buf ^ String.sub p.p_out.out_sb 0 read)
194 + | `EOF ->
195 + Giochannel.shutdown p.p_out.out_w.w_chan false;
196 + Giochannel.shutdown p.p_err.out_w.w_chan false;
197 + failwith "mtn version 0.46 or above is required";
198 + | `AGAIN -> check_version buf
199 + in
200 + if not (check_version "")
201 + then failwith "mtn stdio uses an unknown format-version";
202 let pid = some child.Gspawn.pid in
203 ignore (Gspawn.add_child_watch ~prio:50 pid (reap_cb p pid)) ;
204 p.p_out.out_cb <- out_cb p ;