summaryrefslogtreecommitdiff
path: root/object-store.h
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 /object-store.h
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 'object-store.h')
-rw-r--r--object-store.h27
1 files changed, 13 insertions, 14 deletions
diff --git a/object-store.h b/object-store.h
index b2fa0d0..30faf7b 100644
--- a/object-store.h
+++ b/object-store.h
@@ -24,20 +24,15 @@ struct object_directory {
* Path to the alternative object store. If this is a relative path,
* it is relative to the current working directory.
*/
- char path[FLEX_ARRAY];
+ char *path;
};
+
void prepare_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
typedef int alt_odb_fn(struct object_directory *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
/*
- * Allocate a "struct alternate_object_database" but do _not_ actually
- * add it to the list of alternates.
- */
-struct object_directory *alloc_alt_odb(const char *dir);
-
-/*
* Add the directory to the on-disk alternates file; the new entry will also
* take effect in the current process.
*/
@@ -80,17 +75,21 @@ struct multi_pack_index;
struct raw_object_store {
/*
- * Path to the repository's object store.
- * Cannot be NULL after initialization.
+ * Set of all object directories; the main directory is first (and
+ * cannot be NULL after initialization). Subsequent directories are
+ * alternates.
*/
- char *objectdir;
+ struct object_directory *odb;
+ struct object_directory **odb_tail;
+ int loaded_alternates;
- /* Path to extra alternate object database if not NULL */
+ /*
+ * A list of alternate object directories loaded from the environment;
+ * this should not generally need to be accessed directly, but will
+ * populate the "odb" list when prepare_alt_odb() is run.
+ */
char *alternate_db;
- struct object_directory *alt_odb_list;
- struct object_directory **alt_odb_tail;
-
/*
* Objects that should be substituted by other objects
* (see git-replace(1)).