object-store: migrate alternates struct and functions from cache.h

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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Mar 23, 2018 at 18:20 UTC 0d4a132144a14ae6801523960cbc1939a9bab6c1
12 files changed +61 -51
builtin/clone.c
+1
@@ -27,6 +27,7 @@
27 #include "connected.h"
28 #include "packfile.h"
29 #include "list-objects-filter-options.h"
30 +#include "object-store.h"
31
32 /*
33 * Overall FIXMEs:
builtin/count-objects.c
+1
@@ -11,6 +11,7 @@
11 #include "parse-options.h"
12 #include "quote.h"
13 #include "packfile.h"
14 +#include "object-store.h"
15
16 static unsigned long garbage;
17 static off_t size_garbage;
builtin/fsck.c
+1
@@ -16,6 +16,7 @@
16 #include "streaming.h"
17 #include "decorate.h"
18 #include "packfile.h"
19 +#include "object-store.h"
20
21 #define REACHABLE 0x0001
22 #define SEEN 0x0002
builtin/submodule--helper.c
+1
@@ -16,6 +16,7 @@
16 #include "revision.h"
17 #include "diffcore.h"
18 #include "diff.h"
19 +#include "object-store.h"
20
21 #define OPT_QUIET (1 << 0)
22 #define OPT_CACHED (1 << 1)
cache.h
-51
@@ -1576,57 +1576,6 @@ extern int has_dirs_only_path(const char *name, int len, int prefix_len);
1576 extern void schedule_dir_for_removal(const char *name, int len);
1577 extern void remove_scheduled_dirs(void);
1578
1579 -extern struct alternate_object_database {
1580 - struct alternate_object_database *next;
1581 -
1582 - /* see alt_scratch_buf() */
1583 - struct strbuf scratch;
1584 - size_t base_len;
1585 -
1586 - /*
1587 - * Used to store the results of readdir(3) calls when searching
1588 - * for unique abbreviated hashes. This cache is never
1589 - * invalidated, thus it's racy and not necessarily accurate.
1590 - * That's fine for its purpose; don't use it for tasks requiring
1591 - * greater accuracy!
1592 - */
1593 - char loose_objects_subdir_seen[256];
1594 - struct oid_array loose_objects_cache;
1595 -
1596 - char path[FLEX_ARRAY];
1597 -} *alt_odb_list;
1598 -extern void prepare_alt_odb(void);
1599 -extern char *compute_alternate_path(const char *path, struct strbuf *err);
1600 -typedef int alt_odb_fn(struct alternate_object_database *, void *);
1601 -extern int foreach_alt_odb(alt_odb_fn, void*);
1602 -
1603 -/*
1604 - * Allocate a "struct alternate_object_database" but do _not_ actually
1605 - * add it to the list of alternates.
1606 - */
1607 -struct alternate_object_database *alloc_alt_odb(const char *dir);
1608 -
1609 -/*
1610 - * Add the directory to the on-disk alternates file; the new entry will also
1611 - * take effect in the current process.
1612 - */
1613 -extern void add_to_alternates_file(const char *dir);
1614 -
1615 -/*
1616 - * Add the directory to the in-memory list of alternates (along with any
1617 - * recursive alternates it points to), but do not modify the on-disk alternates
1618 - * file.
1619 - */
1620 -extern void add_to_alternates_memory(const char *dir);
1621 -
1622 -/*
1623 - * Returns a scratch strbuf pre-filled with the alternate object directory,
1624 - * including a trailing slash, which can be used to access paths in the
1625 - * alternate. Always use this over direct access to alt->scratch, as it
1626 - * cleans up any previous use of the scratch buffer.
1627 - */
1628 -extern struct strbuf *alt_scratch_buf(struct alternate_object_database *alt);
1629 -
1579 struct pack_window {
1580 struct pack_window *next;
1581 unsigned char *base;
object-store.h
+51
@@ -1,6 +1,57 @@
1 #ifndef OBJECT_STORE_H
2 #define OBJECT_STORE_H
3
4 +extern struct alternate_object_database {
5 + struct alternate_object_database *next;
6 +
7 + /* see alt_scratch_buf() */
8 + struct strbuf scratch;
9 + size_t base_len;
10 +
11 + /*
12 + * Used to store the results of readdir(3) calls when searching
13 + * for unique abbreviated hashes. This cache is never
14 + * invalidated, thus it's racy and not necessarily accurate.
15 + * That's fine for its purpose; don't use it for tasks requiring
16 + * greater accuracy!
17 + */
18 + char loose_objects_subdir_seen[256];
19 + struct oid_array loose_objects_cache;
20 +
21 + char path[FLEX_ARRAY];
22 +} *alt_odb_list;
23 +void prepare_alt_odb(void);
24 +char *compute_alternate_path(const char *path, struct strbuf *err);
25 +typedef int alt_odb_fn(struct alternate_object_database *, void *);
26 +int foreach_alt_odb(alt_odb_fn, void*);
27 +
28 +/*
29 + * Allocate a "struct alternate_object_database" but do _not_ actually
30 + * add it to the list of alternates.
31 + */
32 +struct alternate_object_database *alloc_alt_odb(const char *dir);
33 +
34 +/*
35 + * Add the directory to the on-disk alternates file; the new entry will also
36 + * take effect in the current process.
37 + */
38 +void add_to_alternates_file(const char *dir);
39 +
40 +/*
41 + * Add the directory to the in-memory list of alternates (along with any
42 + * recursive alternates it points to), but do not modify the on-disk alternates
43 + * file.
44 + */
45 +void add_to_alternates_memory(const char *dir);
46 +
47 +/*
48 + * Returns a scratch strbuf pre-filled with the alternate object directory,
49 + * including a trailing slash, which can be used to access paths in the
50 + * alternate. Always use this over direct access to alt->scratch, as it
51 + * cleans up any previous use of the scratch buffer.
52 + */
53 +struct strbuf *alt_scratch_buf(struct alternate_object_database *alt);
54 +
55 struct raw_object_store {
56 /*
57 * Path to the repository's object store.
packfile.c
+1
@@ -13,6 +13,7 @@
13 #include "tag.h"
14 #include "tree-walk.h"
15 #include "tree.h"
16 +#include "object-store.h"
17
18 char *odb_pack_name(struct strbuf *buf,
19 const unsigned char *sha1,
sha1_name.c
+1
@@ -10,6 +10,7 @@
10 #include "dir.h"
11 #include "sha1-array.h"
12 #include "packfile.h"
13 +#include "object-store.h"
14
15 static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
16
submodule.c
+1
@@ -21,6 +21,7 @@
21 #include "remote.h"
22 #include "worktree.h"
23 #include "parse-options.h"
24 +#include "object-store.h"
25
26 static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
27 static struct string_list changed_submodule_names = STRING_LIST_INIT_DUP;
t/helper/test-ref-store.c
+1
@@ -1,6 +1,7 @@
1 #include "cache.h"
2 #include "refs.h"
3 #include "worktree.h"
4 +#include "object-store.h"
5
6 static const char *notnull(const char *arg, const char *name)
7 {
tmp-objdir.c
+1
@@ -6,6 +6,7 @@
6 #include "strbuf.h"
7 #include "argv-array.h"
8 #include "quote.h"
9 +#include "object-store.h"
10
11 struct tmp_objdir {
12 struct strbuf path;
transport.c
+1
@@ -18,6 +18,7 @@
18 #include "sha1-array.h"
19 #include "sigchain.h"
20 #include "transport-internal.h"
21 +#include "object-store.h"
22
23 static void set_upstreams(struct transport *transport, struct ref *refs,
24 int pretend)