exception SvnError of string;;
-let mutex = Mutex.create ();;
-
-let to_be_committed = ref [];;
-
let exec_process cmd =
let (stdout, stdin, stderr) as chs = Unix.open_process_full cmd [||] in
let outlines = ref [] in
let count p l =
List.length (List.filter p l)
+exception Unimplemented
+
+let matita_flag_of_stat fs =
+ if List.mem Conflict fs then MConflict
+ else if List.mem Modified fs then MModified
+ else if List.mem Add fs then MAdd
+ else if List.mem Delete fs then raise Unimplemented
+ else if List.mem NotAdded fs then MUnversioned
+ else MSynchronized
+
let stat_user user =
let rt_dir = Helm_registry.get "matita.rt_base_dir" in
- let repo = Helm_registry.get "matita.weblib" in
+ let _repo = Helm_registry.get "matita.weblib" in
let errno, outlines, errlines = exec_process
("svn stat " ^ rt_dir ^ "/users/" ^ user ^ "/")
with
| SvnAnomaly l -> facc, l::eacc) ([],[]) outlines
in
+ let files =
+ List.map (fun (fname,flags) -> fname,Some (matita_flag_of_stat flags)) files
+ in
+
if errno = 0 then files, anomalies
else raise (SvnError ("Anomalies: " ^ (String.concat "\n" anomalies) ^ "\n\n" ^ (string_of_output outlines errlines)))
;;
ignore (Sys.command ("rm -rf " ^ to_be_removed))
;;
-(* adds a user to the commit queue; concurrent instances possible, so we
- * enclose the update in a CS
- *)
-let add_user uid =
- Mutex.lock mutex;
- to_be_committed := uid::List.filter (fun x -> x <> uid) !to_be_committed;
- Mutex.unlock mutex;
-;;
-
let update_user user =
let rt_dir = Helm_registry.get "matita.rt_base_dir" in
- let repo = Helm_registry.get "matita.weblib" in
+ let _repo = Helm_registry.get "matita.weblib" in
let errno, outlines, errlines = exec_process
("svn up --non-interactive " ^ rt_dir ^ "/users/" ^ user ^ "/")
else raise (SvnError (string_of_output outlines errlines))
;;
-(* this function and the next one should only be called by the server itself (or
+let add_files user files =
+ let rt_dir = Helm_registry.get "matita.rt_base_dir" in
+ let _repo = Helm_registry.get "matita.weblib" in
+
+ let files = String.concat " "
+ (List.map ((^) (rt_dir ^ "/users/" ^ user ^ "/")) files) in
+
+ let errno, outlines, errlines =
+ if files <> "" then
+ exec_process ("svn add --non-interactive " ^ files)
+ else 0,[],[]
+ in
+ if errno = 0 then
+ "BEGIN ADD - " ^ user ^ ":\n" ^ (string_of_output outlines errlines) ^ "END ADD - " ^ user ^ "\n\n"
+ else raise (SvnError (string_of_output outlines errlines))
+;;
+
+(* this function should only be called by the server itself (or
* the admin) at a scheduled time, so no concurrent instances and no CS needed
* also, svn should already be safe as far as concurrency is concerned *)
-let commit user =
+let commit user files =
let rt_dir = Helm_registry.get "matita.rt_base_dir" in
- let repo = Helm_registry.get "matita.weblib" in
+ let _repo = Helm_registry.get "matita.weblib" in
+
+ let files = String.concat " "
+ (List.map ((^) (rt_dir ^ "/users/" ^ user ^ "/")) files) in
let errno, outlines, errlines = exec_process
- ("svn ci --non-interactive --message \"commit by user " ^ user ^ "\" " ^ rt_dir ^ "/users/" ^ user ^ "/")
+ ("svn ci --non-interactive --message \"commit by user " ^ user ^ "\" " ^ files)
in
if errno = 0 then
"BEGIN COMMIT - " ^ user ^ ":\n" ^ (string_of_output outlines errlines) ^ "END COMMIT - " ^ user ^ "\n\n"
else raise (SvnError (string_of_output outlines errlines))
;;
-let do_global_commit () =
- prerr_endline ("to be committed: " ^ String.concat " " !to_be_committed);
- List.fold_left
- (fun (acc,out) u ->
- try
- let newout = commit u in
- acc, out ^ newout
- with
- | SvnError outstr ->
- prerr_endline ("COMMIT OF " ^ user ^ "FAILED:" ^ outstr);
- u::acc,out)
- ([],"") (List.rev !to_be_committed)
-;;