From 0d4a132144a14ae6801523960cbc1939a9bab6c1 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:20:56 +0100 Subject: [PATCH] object-store: migrate alternates struct and functions from cache.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migrate the struct alternate_object_database and all its related functions to the object store as these functions are easier found in that header. The migration is just a verbatim copy, no need to include the object store header at any C file, because cache.h includes repository.h which in turn includes the object-store.h Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/clone.c | 1 + builtin/count-objects.c | 1 + builtin/fsck.c | 1 + builtin/submodule--helper.c | 1 + cache.h | 51 ------------------------------------- object-store.h | 51 +++++++++++++++++++++++++++++++++++++ packfile.c | 1 + sha1_name.c | 1 + submodule.c | 1 + t/helper/test-ref-store.c | 1 + tmp-objdir.c | 1 + transport.c | 1 + 12 files changed, 61 insertions(+), 51 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 101c27a593..855947f1ab 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -27,6 +27,7 @@ #include "connected.h" #include "packfile.h" #include "list-objects-filter-options.h" +#include "object-store.h" /* * Overall FIXMEs: diff --git a/builtin/count-objects.c b/builtin/count-objects.c index 33343818c8..ced8958e43 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -11,6 +11,7 @@ #include "parse-options.h" #include "quote.h" #include "packfile.h" +#include "object-store.h" static unsigned long garbage; static off_t size_garbage; diff --git a/builtin/fsck.c b/builtin/fsck.c index 7a8a679d4f..b0eba4c3c9 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -16,6 +16,7 @@ #include "streaming.h" #include "decorate.h" #include "packfile.h" +#include "object-store.h" #define REACHABLE 0x0001 #define SEEN 0x0002 diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b1daca995f..6d8e002be7 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -16,6 +16,7 @@ #include "revision.h" #include "diffcore.h" #include "diff.h" +#include "object-store.h" #define OPT_QUIET (1 << 0) #define OPT_CACHED (1 << 1) diff --git a/cache.h b/cache.h index 41ba67cc16..41530d5d16 100644 --- a/cache.h +++ b/cache.h @@ -1576,57 +1576,6 @@ extern int has_dirs_only_path(const char *name, int len, int prefix_len); extern void schedule_dir_for_removal(const char *name, int len); extern void remove_scheduled_dirs(void); -extern struct alternate_object_database { - struct alternate_object_database *next; - - /* see alt_scratch_buf() */ - struct strbuf scratch; - size_t base_len; - - /* - * Used to store the results of readdir(3) calls when searching - * for unique abbreviated hashes. This cache is never - * invalidated, thus it's racy and not necessarily accurate. - * That's fine for its purpose; don't use it for tasks requiring - * greater accuracy! - */ - char loose_objects_subdir_seen[256]; - struct oid_array loose_objects_cache; - - char path[FLEX_ARRAY]; -} *alt_odb_list; -extern void prepare_alt_odb(void); -extern char *compute_alternate_path(const char *path, struct strbuf *err); -typedef int alt_odb_fn(struct alternate_object_database *, void *); -extern 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 alternate_object_database *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. - */ -extern void add_to_alternates_file(const char *dir); - -/* - * Add the directory to the in-memory list of alternates (along with any - * recursive alternates it points to), but do not modify the on-disk alternates - * file. - */ -extern void add_to_alternates_memory(const char *dir); - -/* - * Returns a scratch strbuf pre-filled with the alternate object directory, - * including a trailing slash, which can be used to access paths in the - * alternate. Always use this over direct access to alt->scratch, as it - * cleans up any previous use of the scratch buffer. - */ -extern struct strbuf *alt_scratch_buf(struct alternate_object_database *alt); - struct pack_window { struct pack_window *next; unsigned char *base; diff --git a/object-store.h b/object-store.h index abfaae059b..5002e373cd 100644 --- a/object-store.h +++ b/object-store.h @@ -1,6 +1,57 @@ #ifndef OBJECT_STORE_H #define OBJECT_STORE_H +extern struct alternate_object_database { + struct alternate_object_database *next; + + /* see alt_scratch_buf() */ + struct strbuf scratch; + size_t base_len; + + /* + * Used to store the results of readdir(3) calls when searching + * for unique abbreviated hashes. This cache is never + * invalidated, thus it's racy and not necessarily accurate. + * That's fine for its purpose; don't use it for tasks requiring + * greater accuracy! + */ + char loose_objects_subdir_seen[256]; + struct oid_array loose_objects_cache; + + char path[FLEX_ARRAY]; +} *alt_odb_list; +void prepare_alt_odb(void); +char *compute_alternate_path(const char *path, struct strbuf *err); +typedef int alt_odb_fn(struct alternate_object_database *, 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 alternate_object_database *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. + */ +void add_to_alternates_file(const char *dir); + +/* + * Add the directory to the in-memory list of alternates (along with any + * recursive alternates it points to), but do not modify the on-disk alternates + * file. + */ +void add_to_alternates_memory(const char *dir); + +/* + * Returns a scratch strbuf pre-filled with the alternate object directory, + * including a trailing slash, which can be used to access paths in the + * alternate. Always use this over direct access to alt->scratch, as it + * cleans up any previous use of the scratch buffer. + */ +struct strbuf *alt_scratch_buf(struct alternate_object_database *alt); + struct raw_object_store { /* * Path to the repository's object store. diff --git a/packfile.c b/packfile.c index 7dbe8739d1..c6651682a7 100644 --- a/packfile.c +++ b/packfile.c @@ -13,6 +13,7 @@ #include "tag.h" #include "tree-walk.h" #include "tree.h" +#include "object-store.h" char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, diff --git a/sha1_name.c b/sha1_name.c index 611c7d24dd..434025bf03 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -10,6 +10,7 @@ #include "dir.h" #include "sha1-array.h" #include "packfile.h" +#include "object-store.h" static int get_oid_oneline(const char *, struct object_id *, struct commit_list *); diff --git a/submodule.c b/submodule.c index 47ddc9b273..b03e5f5045 100644 --- a/submodule.c +++ b/submodule.c @@ -21,6 +21,7 @@ #include "remote.h" #include "worktree.h" #include "parse-options.h" +#include "object-store.h" static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF; static struct string_list changed_submodule_names = STRING_LIST_INIT_DUP; diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 7120634b04..7314b5943e 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -1,6 +1,7 @@ #include "cache.h" #include "refs.h" #include "worktree.h" +#include "object-store.h" static const char *notnull(const char *arg, const char *name) { diff --git a/tmp-objdir.c b/tmp-objdir.c index b2d9280f10..fea3f55545 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -6,6 +6,7 @@ #include "strbuf.h" #include "argv-array.h" #include "quote.h" +#include "object-store.h" struct tmp_objdir { struct strbuf path; diff --git a/transport.c b/transport.c index 00d48b5b56..3afc632472 100644 --- a/transport.c +++ b/transport.c @@ -18,6 +18,7 @@ #include "sha1-array.h" #include "sigchain.h" #include "transport-internal.h" +#include "object-store.h" static void set_upstreams(struct transport *transport, struct ref *refs, int pretend)