diff options
-rw-r--r-- | README.rst | 13 | ||||
-rw-r--r-- | context_mirror_bot.ml | 46 |
2 files changed, 57 insertions, 2 deletions
@@ -46,6 +46,17 @@ If the dependencies are in place, simply issue ``omake`` in the repository directory and the executable ``context_mirror_bot`` is created. +Prerequisites +************* + +The *Context Mirror Bot* assumes an ``unzip(1)`` executable accessible +from the ``$PATH``. The same goes for standard userland utilities like +``cp(1)`` and ``rm(1)``. In dubious cases, the `GNU Coreutils`_ are +assumed the canonical implementation. + +It goes without saying that ``git(1)`` must be installed on the system +as well. + Run *** @@ -57,6 +68,7 @@ Currently this presents you with this list of options: --check check source timestamps --status print status of local repo +--sync sync local repo and remotes --update update from sources --prepare prepare local repository --download download source packages @@ -121,4 +133,5 @@ under the name ``COPYING``. .. _Omake: http://omake.metaprl.org/index.html .. _Philipp Gesang: mailto:philipp.gesang@alumni.uni-heidelberg.de .. _original script: https://gitorious.org/context/context/source/d493b9c93ad826044bd17889da2ee099c8ed72d5:context_git_update.pl +.. _GNU Coreutils: http://www.gnu.org/s/coreutils/ diff --git a/context_mirror_bot.ml b/context_mirror_bot.ml index 76f247f..a2dec76 100644 --- a/context_mirror_bot.ml +++ b/context_mirror_bot.ml @@ -76,7 +76,8 @@ let sources = let bot_owner = "Philipp Gesang" let owner_contact = "phg42.2a@gmail.com" -let repo_root = "/home/mirror/mirror" +(*let repo_root = "/home/mirror/mirror"*) +let repo_root = "/home/phg/src/mirror" let repo_subdir = "context-git" let repo_dir = Filename.concat repo_root repo_subdir let git_dir = Filename.concat repo_dir ".git" @@ -295,6 +296,8 @@ module Git : sig val import : extract_status -> import_status val push : string -> status val install_files : unit -> unit + val fetch : string -> unit + val pull : ?rbr:string -> string -> unit exception Git_checkout_failed of string end = struct exception Git_init_failed @@ -303,6 +306,8 @@ end = struct exception Git_checkout_failed of string exception Git_branch_failed of string exception Git_commit_failed of string + exception Git_fetch_failed of string + exception Git_pull_failed of string exception Import_files_failed exception Copy_ssh_key_failed @@ -349,6 +354,29 @@ end = struct | Bad _ -> raise Git_init_failed | Good -> install_files (); true + let fetch remote = + msg ("Fetching remote " ^ remote); + match list_of_pipe ("git fetch " ^ remote) with + | None -> raise (Git_fetch_failed remote) + | Some _ -> () + + let pull ?rbr:(rbr="mirror") br = + msg ~lev:1 (Printf.sprintf "tentatively checkout new branch %s from remote %s" br rbr); + let () = match list_of_pipe (* this fails if the branch already exists *) + (Printf.sprintf "git checkout -b \"%s\" \"%s\"" br rbr) with + | Some _ -> msg (Printf.sprintf "new branch %s created" br) + | None -> (* branch exists, do regular checkout *) + begin + msg ~lev:1 (Printf.sprintf "branch %s already exists; performing normal checkout" br); + match list_of_pipe (Printf.sprintf "git checkout \"%s\"" br) with + | None -> raise (Git_checkout_failed br) + | Some _ -> () + end + in + match list_of_pipe ("git pull --ff") with + | Some _ -> msg ~lev:1 (Printf.sprintf "pulled branch %s just fine" br) + | None -> raise (Git_pull_failed (Printf.sprintf "%s (remote: %s)" br rbr)) + let last_commit br = match list_of_pipe ("git checkout " ^ br) with | None -> raise (Git_checkout_failed br) @@ -710,6 +738,19 @@ let run_update () = in () +let run_sync () = + Git.fetch "mirror"; + Git.fetch "garden"; + Git.pull "beta"; + Git.pull "current"; + Git.pull ~rbr:"garden/master" "garden-master"; + let name = "garden-master" in + msg "Pushing changes from context garden repo to mirror"; + match Git.push name with + | Good -> msg "Success!" + | Bad errmsg -> + err (Printf.sprintf "Failed to push %s: ā%sā" name errmsg) + let run_cleanup () = forall_sources (fun src -> @@ -755,6 +796,7 @@ let parse_argv () = ("--check", Arg.Unit (fun () -> j.kind <- Action ("status" , run_status ); ()), "check source timestamps"); ("--status", Arg.Unit (fun () -> j.kind <- Action ("check" , run_check ); ()), "print status of local repo"); ("--update", Arg.Unit (fun () -> j.kind <- Action ("update" , run_update ); ()), "update from sources"); + ("--sync", Arg.Unit (fun () -> j.kind <- Action ("sync" , run_sync ); ()), "sync local repo"); ("--prepare", Arg.Unit (fun () -> j.kind <- Action ("prepare" , run_prepare ); ()), "prepare local repository"); ("--download", Arg.Unit (fun () -> j.kind <- Action ("download", run_download); ()), "download source packages"); ("--clean", Arg.Unit (fun () -> j.kind <- Action ("cleanup" , run_cleanup ); ()), "remove leftover files"); @@ -773,7 +815,7 @@ let () = Git.set_path repo_dir; dispatch_job job.kind; log_info (Printf.sprintf - "mirror bot finished in %.2f ms." + "mirror bot finished in %.2f s." (Unix.gettimeofday () -. t_start)); ;; |