60
69
| Unix.Unix_error ((Unix.ENOENT | Unix.ENOTDIR), _, _) -> Ok false
61
70
| Unix.Unix_error (error, _, _) -> Error (filesystem_error path error)
62
71
63
-
Removed:
let is_git_directory_result path =
72
+
Added:
(* A directory is a Git directory when it holds both HEAD and objects/. *)
73
+
Added:
let is_git_directory path =
64
74
let ( let* ) = Result.bind in
65
-
Removed:
let* directory = is_directory_result path in
75
+
Added:
let* directory = is_directory path in
66
76
if not directory then Ok false
67
77
else
68
-
Removed:
let* has_head = file_exists_result (Filename.concat path "HEAD") in
69
-
Removed:
let* has_objects = is_directory_result (Filename.concat path "objects") in
78
+
Added:
let* has_head = file_exists (Filename.concat path "HEAD") in
79
+
Added:
let* has_objects = is_directory (Filename.concat path "objects") in
70
80
Ok (has_head && has_objects)
71
81
72
-
Removed:
let repository_layout_result path =
82
+
Added:
(* [Ok None] means "readable, but not a repository"; [Error _] means "could not
83
+
Added:
tell". Keeping them apart is the whole point of this layer. *)
84
+
Added:
let repository_layout path =
73
85
let ( let* ) = Result.bind in
74
86
let dotgit = Filename.concat path ".git" in
75
-
Removed:
let* worktree = is_directory_result path in
87
+
Added:
let* worktree = is_directory path in
76
88
if not worktree then Ok None
77
89
else
78
-
Removed:
let* non_bare = is_git_directory_result dotgit in
90
+
Added:
let* non_bare = is_git_directory dotgit in
79
91
if non_bare then Ok (Some { worktree = path; git_dir = dotgit })
80
92
else
81
-
Removed:
let* bare = is_git_directory_result path in
93
+
Added:
let* bare = is_git_directory path in
82
94
if bare then Ok (Some { worktree = path; git_dir = path }) else Ok None
83
95
84
-
Removed:
let repository_layout path =
85
-
Removed:
match repository_layout_result path with
86
-
Removed:
| Ok layout -> layout
87
-
Removed:
| Error _ -> None
96
+
Added:
(** Collapse an unreadable path to [None], for the callers that cannot act on
97
+
Added:
the difference anyway. Prefer {!repository_layout} where the distinction
98
+
Added:
between "not a repository" and "could not tell" matters. *)
99
+
Added:
let repository_layout_or_none path =
100
+
Added:
match repository_layout path with Ok layout -> layout | Error _ -> None
88
101
89
-
Removed:
let is_repository path = Option.is_some (repository_layout path)
102
+
Added:
let is_repository path = Option.is_some (repository_layout_or_none path)
90
103
91
104
let repositories config =
92
105
try