Skip to content

Commit

Permalink
Merge pull request #320 from talex5/head-to-id
Browse files Browse the repository at this point in the history
Change "type head" to "type commit_id"
  • Loading branch information
samoht committed Oct 13, 2015
2 parents 1937b5e + 9ed6589 commit 7edfe37
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 236 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Expand Up @@ -73,6 +73,13 @@
`Repo.config` to be removed and allowing sharing of the back-end's
internal state with the sync code. For example, the Git back-end
no longer needs to create a new Git store object for sync.
* Change `type head` to `type commit_id`. `head` was confusing because
it applied to all commits, not just branch heads. Putting `id` in the
name makes it clear that this is just data and (for example) holding
an ID will not prevent the corresponding commit from being GC'd (once
we have GC). `of_head` is now `of_commit_id`, `task_of_head` is now
`task_of_commit_id`, `Internals.commit_of_head` is now
`Internals.commit_of_id` and `BC.Head` is now `BC.Hash`.


### 0.9.10
Expand Down
4 changes: 2 additions & 2 deletions bin/ir_cli.ml
Expand Up @@ -349,7 +349,7 @@ let snapshot = {
run begin
store >>= fun t ->
S.head_exn (t "Snapshot") >>= fun k ->
print "%s" (S.Head.to_hum k);
print "%s" (S.Hash.to_hum k);
return_unit
end
in
Expand All @@ -368,7 +368,7 @@ let revert = {
let revert (S ((module S), store)) snapshot =
run begin
store >>= fun t ->
let s = S.Head.of_hum snapshot in
let s = S.Hash.of_hum snapshot in
S.update_head (t "Revert") s
end
in
Expand Down
16 changes: 5 additions & 11 deletions lib/git/irmin_git.ml
Expand Up @@ -650,7 +650,7 @@ module Make_ext
module Sync = Git.Sync.Make(IO)(G)

type t = G.t
type head = X.Commit.key
type commit_id = X.Commit.key
type branch_id = XRef.key

let head_of_git key = H.of_raw (X.GK.to_raw (Git.SHA.of_commit key))
Expand Down Expand Up @@ -723,8 +723,8 @@ module Make_ext
include Irmin.Make_ext(P)

module Internals = struct
let commit_of_head repo h =
let h = Head.to_raw h |> Cstruct.to_string |> Git.SHA.of_raw in
let commit_of_id repo h =
let h = Hash.to_raw h |> Cstruct.to_string |> Git.SHA.of_raw in
Git_store.read repo.g h >|= function
| Some Git.Value.Commit c -> Some c
| _ -> None
Expand Down Expand Up @@ -804,13 +804,7 @@ module type S = sig
include Irmin.S

module Internals: sig

(** {1 Access to the Git objects} *)

val commit_of_head: Repo.t -> head -> Git.Commit.t option Lwt.t
(** [commit_of_head repo h] is the commit corresponding to [h] in the
repository [repo]. *)

val commit_of_id: Repo.t -> commit_id -> Git.Commit.t option Lwt.t
end
end

Expand All @@ -821,6 +815,6 @@ module type S_MAKER =
S with type key = C.Path.t
and type value = C.t
and type branch_id = R.t
and type head = H.t
and type commit_id = H.t

include Conf
6 changes: 3 additions & 3 deletions lib/git/irmin_git.mli
Expand Up @@ -86,8 +86,8 @@ module type S = sig

(** {1 Access to the Git objects} *)

val commit_of_head: Repo.t -> head -> Git.Commit.t option Lwt.t
(** [commit_of_head repo h] is the commit corresponding to [h] in the
val commit_of_id: Repo.t -> commit_id -> Git.Commit.t option Lwt.t
(** [commit_of_id repo h] is the commit corresponding to [h] in the
repository [repo]. *)

end
Expand All @@ -100,7 +100,7 @@ module type S_MAKER =
S with type key = C.Path.t
and type value = C.t
and type branch_id = R.t
and type head = H.t
and type commit_id = H.t

module Memory (IO: Git.Sync.IO) (I: Git.Inflate.S):
S_MAKER
Expand Down
60 changes: 30 additions & 30 deletions lib/http/irmin_http.ml
Expand Up @@ -446,7 +446,7 @@ struct

end

module Head = H
module Hash = H
module Val = C

include Helper (Client)
Expand All @@ -464,7 +464,7 @@ struct
(* The high-level bindings: every high-level operation is simply
forwarded to the HTTP server. *much* more efficient than using
[L]. *)
module L = Low(Client)(Val)(Ref)(Head)
module L = Low(Client)(Val)(Ref)(Hash)
module LP = L.Private
module S = RW(Client)(Key)(Val)

Expand All @@ -475,7 +475,7 @@ struct

let head_query name = function
| [] -> []
| l -> [name, List.map (Tc.write_string (module Head)) l]
| l -> [name, List.map (Tc.write_string (module Hash)) l]

module Repo = struct
type t = {
Expand Down Expand Up @@ -508,7 +508,7 @@ struct

let remove_branch t branch_id = delete t ["remove-tag"; Ref.to_hum branch_id] Tc.unit

let heads t = get t ["heads"] (module Tc.List(Head))
let heads t = get t ["heads"] (module Tc.List(Hash))

let watch_branches t = L.Repo.watch_branches t.l

Expand All @@ -531,8 +531,8 @@ struct
let import t slice =
post_json t ["import"] ~body:(slice_tc, slice) ok_or_error

let task_of_head t head =
LP.Commit.read_exn (commit_t t) head >>= fun commit ->
let task_of_commit_id t commit_id =
LP.Commit.read_exn (commit_t t) commit_id >>= fun commit ->
Lwt.return (LP.Commit.Val.task commit)

end
Expand All @@ -542,13 +542,13 @@ struct
- `$uri/tree/$tag` if head_ref = `Branch tag
- `$uri/tree/$key if key = `Key key *)
type t = {
head_ref: [`Branch of Ref.t | `Head of Head.t | `Empty] ref;
head_ref: [`Branch of Ref.t | `Head of Hash.t | `Empty] ref;
l: L.t;
repo: Repo.t;
read_node: L.key -> LP.Node.key option Lwt.t;
mem_node: L.key -> bool Lwt.t;
update_node: L.key -> LP.Node.key -> unit Lwt.t;
merge_node: L.key -> (L.head * LP.Node.key) -> unit Irmin.Merge.result Lwt.t;
merge_node: L.key -> (L.commit_id * LP.Node.key) -> unit Irmin.Merge.result Lwt.t;
remove_node: L.key -> unit Lwt.t;
iter_node: LP.Node.key -> (L.key -> L.value Lwt.t -> unit Lwt.t) -> unit Lwt.t;
lock: Lwt_mutex.t;
Expand All @@ -563,7 +563,7 @@ struct
if Ref.equal name Ref.master then base
else uri_append base ["tree"; Ref.to_hum name]
| `Empty -> uri_append base ["empty"]
| `Head h -> uri_append base ["tree"; Head.to_hum h]
| `Head h -> uri_append base ["tree"; Hash.to_hum h]

let repo t = t.repo
let task t = L.task t.l
Expand All @@ -575,11 +575,11 @@ struct

type key = S.key
type value = S.value
type head = L.head
type commit_id = L.commit_id
type branch_id = L.branch_id

let v: Val.t Tc.t = (module Val)
let head_tc: Head.t Tc.t = (module Head)
let head_tc: Hash.t Tc.t = (module Hash)

let create_aux head_ref repo l =
let fn a =
Expand Down Expand Up @@ -607,9 +607,9 @@ struct
let head_ref = ref (`Branch branch_id) in
create_aux head_ref repo l

let of_head task head repo =
L.of_head task head repo.Repo.l >>= fun l ->
let head_ref = ref (`Head head) in
let of_commit_id task commit_id repo =
L.of_commit_id task commit_id repo.Repo.l >>= fun l ->
let head_ref = ref (`Head commit_id) in
create_aux head_ref repo l

let empty task repo =
Expand Down Expand Up @@ -649,7 +649,7 @@ struct
| `Branch _ -> Lwt.return_unit

let remove t key =
delete t ["remove"; Key.to_hum key] (module Head) >>= fun h ->
delete t ["remove"; Key.to_hum key] (module Hash) >>= fun h ->
match head_ref t with
| `Empty
| `Head _ -> set_head t (Some h)
Expand All @@ -673,7 +673,7 @@ struct
let head t = match head_ref t with
| `Empty -> Lwt.return_none
| `Head h -> Lwt.return (Some h)
| `Branch _ -> get t ["head"] (module Tc.Option(Head))
| `Branch _ -> get t ["head"] (module Tc.Option(Hash))

let head_exn t =
head t >>= function
Expand All @@ -689,9 +689,9 @@ struct
let update_head t head = match head_ref t with
| `Empty
| `Head _ -> set_head t (Some head)
| `Branch _ -> get t ["update-head"; Head.to_hum head] Tc.unit
| `Branch _ -> get t ["update-head"; Hash.to_hum head] Tc.unit

module CSH = Tc.Pair(Tc.Option(Head))(Tc.Option(Head))
module CSH = Tc.Pair(Tc.Option(Hash))(Tc.Option(Hash))
let csh: CSH.t Tc.t = (module CSH)

let compare_and_set_head_unsafe t ~test ~set =
Expand All @@ -709,7 +709,7 @@ struct
compare_and_set_head_unsafe t ~test ~set
)

module M = Tc.App1 (Irmin.Merge.Result) (Head)
module M = Tc.App1 (Irmin.Merge.Result) (Hash)
let m: M.t Tc.t = (module M)

let mk_query ?max_depth ?n () =
Expand All @@ -727,7 +727,7 @@ struct

let fast_forward_head_unsafe t ?max_depth ?n head =
let query = mk_query ?max_depth ?n () in
post t ?query ["fast-forward-head"; Head.to_hum head] Tc.bool >>= fun b ->
post t ?query ["fast-forward-head"; Hash.to_hum head] Tc.bool >>= fun b ->
match head_ref t with
| `Branch _ -> Lwt.return b
| `Empty
Expand All @@ -741,7 +741,7 @@ struct

let merge_head t ?max_depth ?n head =
let query = mk_query ?max_depth ?n () in
post t ?query ["merge-head"; Head.to_hum head] m >>| fun h ->
post t ?query ["merge-head"; Hash.to_hum head] m >>| fun h ->
match head_ref t with
| `Empty
| `Head _ -> set_head t (Some h) >>= ok
Expand All @@ -765,7 +765,7 @@ struct
| Some v -> fn @@ `Added (x, v)
end
| `Updated (x, y) ->
assert (not (Head.equal x y));
assert (not (Hash.equal x y));
value_of_head x >>= fun vx ->
value_of_head y >>= fun vy ->
match vx, vy with
Expand All @@ -783,7 +783,7 @@ struct
| Some (h, _) -> Some h
in
let value_of_head h =
of_head (fun () -> task t) h t.repo >>= fun t ->
of_commit_id (fun () -> task t) h t.repo >>= fun t ->
read (t ()) key
in
watch_head t ?init:init_head (lift value_of_head fn)
Expand Down Expand Up @@ -818,28 +818,28 @@ struct
let merge_exn a ?max_depth ?n t ~into =
merge a ?max_depth ?n t ~into >>= Irmin.Merge.exn

let lca = lca (module Head)
let lca = lca (module Hash)

let lcas_branch t ?max_depth ?n other =
let query = mk_query ?max_depth ?n () in
get t ?query ["lcas-tag"; Ref.to_hum other] lca

let lcas_head t ?max_depth ?n head =
let query = mk_query ?max_depth ?n () in
get t ?query ["lcas-head"; Head.to_hum head] lca
get t ?query ["lcas-head"; Hash.to_hum head] lca

let lcas a ?max_depth ?n t1 t2 =
match head_ref (t2 a) with
| `Branch name -> lcas_branch (t1 a) ?max_depth ?n name
| `Head head -> lcas_head (t1 a) ?max_depth ?n head
| `Empty -> Lwt.return (`Ok [])

module E = Tc.Pair (Tc.List(Head)) (Tc.Option(Tc.List(Head)))
module E = Tc.Pair (Tc.List(Hash)) (Tc.Option(Tc.List(Hash)))

module I = Tc.List(Ref)

let remove_rec t dir =
delete t ["remove-rec"; Key.to_hum dir] (module Head) >>= fun h ->
delete t ["remove-rec"; Key.to_hum dir] (module Hash) >>= fun h ->
match head_ref t with
| `Empty
| `Head _ -> set_head t (Some h)
Expand All @@ -848,8 +848,8 @@ struct
let list t dir =
get t ["list"; Key.to_hum dir] (module Tc.List(Key))

module History = Graph.Persistent.Digraph.ConcreteBidirectional(Head)
module G = Tc.Pair (Tc.List (Head))(Tc.List (Tc.Pair(Head)(Head)))
module History = Graph.Persistent.Digraph.ConcreteBidirectional(Hash)
module G = Tc.Pair (Tc.List (Hash))(Tc.List (Tc.Pair(Hash)(Hash)))
module Conv = struct
type t = History.t
let to_t (vertices, edges) =
Expand All @@ -862,7 +862,7 @@ struct
vertices, edges
end
module HTC = Tc.Biject (G)(Conv)
module EO = Tc.Pair (Tc.Option(Tc.List(Head))) (Tc.Option(Tc.List(Head)))
module EO = Tc.Pair (Tc.Option(Tc.List(Hash))) (Tc.Option(Tc.List(Hash)))

let history ?depth ?(min=[]) ?(max=[]) t =
let query =
Expand Down

0 comments on commit 7edfe37

Please sign in to comment.