Skip to content

Commit

Permalink
Make sure refs, heads, remotes won't be dangling symlinks.
Browse files Browse the repository at this point in the history
  • Loading branch information
g2p committed Feb 19, 2010
1 parent e8a215e commit 05cc394
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Map more stuff
BISECT_LOG BISECT_RUN BISECT_NAMES
configuration
remote urls
optional symlinks, that only exist when their target does
uses: various symbolic refs, the origin remote.

Get a library to access the repo without fork/malloc/die cycles
that cost (in memory latency? whatever, it's very slow).
Expand Down
14 changes: 12 additions & 2 deletions src/git_fs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ let ref_names () =
let rec ref_tree_add tree path hash =
(* this traversal relies on the sort order *)
match tree, path with
(* git maintains that invariant for us anyway. *)
(* git maintains that invariant for us anyway. Except if someone manages to
create refs/{heads,remotes,tags} as a ref instead of a ref prefix. *)
|_, [] -> failwith "Can't make an internal node into a leaf"
|((name, RefTreeInternalNode grand_children)::children_tl), name_::tl
when name = name_ ->
Expand All @@ -369,9 +370,18 @@ let rec ref_tree_add tree path hash =
|children, name::tl -> (* sort order *)
(name, RefTreeInternalNode (ref_tree_add [] tl hash))::children

(* So we don't have dangling symlinks *)
let skel_tree = [
"refs", RefTreeInternalNode [
"heads", RefTreeInternalNode [];
"remotes", RefTreeInternalNode [];
"tags", RefTreeInternalNode [];
];
]

let ref_tree_uncached () =
let refs = ref_names () in
let tree = ref [] in
let tree = ref skel_tree in
List.iter (fun (refname, hash) ->
let refpath = BatString.nsplit refname "/" in
tree := ref_tree_add !tree refpath hash;
Expand Down

0 comments on commit 05cc394

Please sign in to comment.