Below is the file 'main.ml' from this revision. You can also download the file.

open Viz_misc

let parse_options args =
  match args with
  | db :: _ -> Some db
  | [] ->
      if Sys.file_exists ".dircache" || Sys.file_exists ".git"
      then Some "."
      else None

let parse_cli () =
  let anons = ref Q.empty in
  let aa = ref true in
  let cli_args = [ "-noaa", Arg.Clear aa, "don't use an anti-aliased canvas" ] in
  let usg_msg =
    Printf.sprintf "usage: %s [options] [git-controlled directory]"
      (Filename.basename Sys.executable_name) in
  Arg.parse cli_args (fun a -> anons := Q.push !anons a) usg_msg ;
  (!aa, parse_options (Q.to_list !anons))


let exn_handler w exn =
  View.error_notice ~parent:w
    (match exn with
    | Viz_types.Error msg -> msg
    | exn -> Printexc.to_string exn)

let main =
  let w = GWindow.window
      ~title:"git-viz"
      ~icon:(Lazy.force Icon.monotone) () in
  ignore (w#connect#destroy GMain.quit) ;

  let (aa, mt_options) = parse_cli () in

  GtkSignal.user_handler := exn_handler w ;

  let prefs = Viz_style.load () in

  let v = Ui.get_view (Ui.make w ~aa ~prefs) in

  ignore
    (Glib.Idle.add
       (fun () ->
	 begin
	   try
	     match mt_options with
	     | None -> ()
	     | Some fname ->
		 View.open_db v fname None
	   with Viz_types.Error msg ->
	     View.error_notice ~parent:w msg
	 end ;
	 false)) ;

  w#show () ;
  GMain.main () ;

  (* just close the db, without updating the widgets *)
  View.finalize v