summaryrefslogtreecommitdiff
path: root/environment.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-11-12 14:50:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-11-13 05:22:03 (GMT)
commitf0eaf638195a6510254b075026dcad955b8b607d (patch)
tree405fd2aeb1e4384f0df3166aef14304145c1370d /environment.c
parentf3f043a103b7a7da57272ecf3252bda6089e41ae (diff)
downloadgit-f0eaf638195a6510254b075026dcad955b8b607d.zip
git-f0eaf638195a6510254b075026dcad955b8b607d.tar.gz
git-f0eaf638195a6510254b075026dcad955b8b607d.tar.bz2
sha1-file: use an object_directory for the main object dir
Our handling of alternate object directories is needlessly different from the main object directory. As a result, many places in the code basically look like this: do_something(r->objects->objdir); for (odb = r->objects->alt_odb_list; odb; odb = odb->next) do_something(odb->path); That gets annoying when do_something() is non-trivial, and we've resorted to gross hacks like creating fake alternates (see find_short_object_filename()). Instead, let's give each raw_object_store a unified list of object_directory structs. The first will be the main store, and everything after is an alternate. Very few callers even care about the distinction, and can just loop over the whole list (and those who care can just treat the first element differently). A few observations: - we don't need r->objects->objectdir anymore, and can just mechanically convert that to r->objects->odb->path - object_directory's path field needs to become a real pointer rather than a FLEX_ARRAY, in order to fill it with expand_base_dir() - we'll call prepare_alt_odb() earlier in many functions (i.e., outside of the loop). This may result in us calling it even when our function would be satisfied looking only at the main odb. But this doesn't matter in practice. It's not a very expensive operation in the first place, and in the majority of cases it will be a noop. We call it already (and cache its results) in prepare_packed_git(), and we'll generally check packs before loose objects. So essentially every program is going to call it immediately once per program. Arguably we should just prepare_alt_odb() immediately upon setting up the repository's object directory, which would save us sprinkling calls throughout the code base (and forgetting to do so has been a source of subtle bugs in the past). But I've stopped short of that here, since there are already a lot of other moving parts in this patch. - Most call sites just get shorter. The check_and_freshen() functions are an exception, because they have entry points to handle local and nonlocal directories separately. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'environment.c')
-rw-r--r--environment.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/environment.c b/environment.c
index 3f3c8746..441ce56 100644
--- a/environment.c
+++ b/environment.c
@@ -274,9 +274,9 @@ const char *get_git_work_tree(void)
char *get_object_directory(void)
{
- if (!the_repository->objects->objectdir)
+ if (!the_repository->objects->odb)
BUG("git environment hasn't been setup");
- return the_repository->objects->objectdir;
+ return the_repository->objects->odb->path;
}
int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)