MCPcopy Create free account
hub / github.com/git/git / odb_is_source_usable

Function odb_is_source_usable

odb.c:59–100  ·  view source on GitHub ↗

* Return non-zero iff the path is usable as an alternate object database. */

Source from the content-addressed store, hash-verified

57 * Return non-zero iff the path is usable as an alternate object database.
58 */
59static bool odb_is_source_usable(struct object_database *o, const char *path)
60{
61 int r;
62 struct strbuf normalized_objdir = STRBUF_INIT;
63 bool usable = false;
64
65 strbuf_realpath(&normalized_objdir, o->sources->path, 1);
66
67 /* Detect cases where alternate disappeared */
68 if (!is_directory(path)) {
69 error(_("object directory %s does not exist; "
70 "check .git/objects/info/alternates"),
71 path);
72 goto out;
73 }
74
75 /*
76 * Prevent the common mistake of listing the same
77 * thing twice, or object directory itself.
78 */
79 if (!o->source_by_path) {
80 khiter_t p;
81
82 o->source_by_path = kh_init_odb_path_map();
83 assert(!o->sources->next);
84 p = kh_put_odb_path_map(o->source_by_path, o->sources->path, &r);
85 assert(r == 1); /* never used */
86 kh_value(o->source_by_path, p) = o->sources;
87 }
88
89 if (fspatheq(path, normalized_objdir.buf))
90 goto out;
91
92 if (kh_get_odb_path_map(o->source_by_path, path) < kh_end(o->source_by_path))
93 goto out;
94
95 usable = true;
96
97out:
98 strbuf_release(&normalized_objdir);
99 return usable;
100}
101
102void parse_alternates(const char *string,
103 int sep,

Callers 1

Calls 5

strbuf_realpathFunction · 0.85
is_directoryFunction · 0.85
errorFunction · 0.85
fspatheqFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected