* [PATCH 01/17] object-store: rename `raw_object_store` to `object_database`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-07 0:47 ` Derrick Stolee
2025-05-06 11:09 ` [PATCH 02/17] object-store: rename `object_directory` to `odb_backend` Patrick Steinhardt
` (22 subsequent siblings)
23 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
The `raw_object_store` structure is the central entry point for reading
and writing objects in a repository. The main purpose of this structure
is to manage object directories and provide an interface to access and
write objects in those object directories.
Right now, many of the functions associated with the raw object store
implicitly rely on `the_repository` to get access to its `objects`
pointer, which is the `raw_object_store`. As we want to generally get
rid of using `the_repository` across our codebase we will have to
convert this implicit dependency on this global variable into an
explicit parameter.
This conversion can be done by simply passing in an explicit pointer to
a repository and then using its `->objects` pointer. But there is a
second effort underway, which is to make the object subsystem more
selfcontained so that we can eventually have pluggale object backends.
As such, passing in a repository wouldn't make a ton of sense, and the
goal is to convert the object store interfaces such that we always pass
in a reference to the `raw_object_store` instead.
This will expose the `raw_object_store` type to a lot more callers
though, which surfaces that this type is named somewhat awkwardly. The
"raw_" prefix makes readers wonder whether there is a non-raw variant of
the object store, but there isn't. Furthermore, we nowadays want to name
functions in a way that they can be clearly attributed to a specific
subsystem, but calling them e.g. `raw_object_store_has_object()` is just
too unwieldy, even when dropping the "raw_" prefix.
Instead, rename the structure to `object_database`. This term is already
used a lot throughout our codebase, and it cannot easily be mistaken for
"object directories", either. Furthermore, its acronym ODB is already
well-known and works well as part of a function's name, like for example
`odb_has_object()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
commit-graph.c | 2 +-
commit-graph.h | 4 ++--
object-store.c | 12 ++++++------
object-store.h | 11 ++++++++---
packfile.c | 2 +-
packfile.h | 4 ++--
repository.c | 4 ++--
repository.h | 4 ++--
8 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index 6394752b0b0..1b66486b9c9 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -829,7 +829,7 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
return NULL;
}
-void close_commit_graph(struct raw_object_store *o)
+void close_commit_graph(struct object_database *o)
{
if (!o->commit_graph)
return;
diff --git a/commit-graph.h b/commit-graph.h
index 13f662827d4..20d38c100ce 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -26,7 +26,7 @@ void git_test_write_commit_graph_or_die(void);
struct commit;
struct bloom_filter_settings;
struct repository;
-struct raw_object_store;
+struct object_database;
struct string_list;
char *get_commit_graph_filename(struct object_directory *odb);
@@ -186,7 +186,7 @@ int write_commit_graph(struct object_directory *odb,
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
-void close_commit_graph(struct raw_object_store *);
+void close_commit_graph(struct object_database *);
void free_commit_graph(struct commit_graph *);
/*
diff --git a/object-store.c b/object-store.c
index 2f51d0e3b03..1effcb12273 100644
--- a/object-store.c
+++ b/object-store.c
@@ -44,7 +44,7 @@ struct cached_object_entry {
} value;
};
-static const struct cached_object *find_cached_object(struct raw_object_store *object_store,
+static const struct cached_object *find_cached_object(struct object_database *object_store,
const struct object_id *oid)
{
static const struct cached_object empty_tree = {
@@ -86,7 +86,7 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
/*
* Return non-zero iff the path is usable as an alternate object database.
*/
-static int alt_odb_usable(struct raw_object_store *o,
+static int alt_odb_usable(struct object_database *o,
struct strbuf *path,
const char *normalized_objdir, khiter_t *pos)
{
@@ -959,9 +959,9 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct raw_object_store *raw_object_store_new(void)
+struct object_database *odb_new(void)
{
- struct raw_object_store *o = xmalloc(sizeof(*o));
+ struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
INIT_LIST_HEAD(&o->packed_git_mru);
@@ -970,7 +970,7 @@ struct raw_object_store *raw_object_store_new(void)
return o;
}
-static void free_object_directories(struct raw_object_store *o)
+static void free_object_directories(struct object_database *o)
{
while (o->odb) {
struct object_directory *next;
@@ -983,7 +983,7 @@ static void free_object_directories(struct raw_object_store *o)
o->odb_by_path = NULL;
}
-void raw_object_store_clear(struct raw_object_store *o)
+void odb_clear(struct object_database *o)
{
FREE_AND_NULL(o->alternate_db);
diff --git a/object-store.h b/object-store.h
index c2fe5a19605..34b8efbbb83 100644
--- a/object-store.h
+++ b/object-store.h
@@ -86,7 +86,12 @@ struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
-struct raw_object_store {
+/*
+ * The object database encapsulates access to objects in a repository. It
+ * manages one or more backends that store the actual objects which are
+ * configured via alternates.
+ */
+struct object_database {
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -168,8 +173,8 @@ struct raw_object_store {
unsigned packed_git_initialized : 1;
};
-struct raw_object_store *raw_object_store_new(void);
-void raw_object_store_clear(struct raw_object_store *o);
+struct object_database *odb_new(void);
+void odb_clear(struct object_database *o);
/*
* Create a temporary file rooted in the object database directory, or
diff --git a/packfile.c b/packfile.c
index d91016f1c7f..8f51665266d 100644
--- a/packfile.c
+++ b/packfile.c
@@ -359,7 +359,7 @@ void close_pack(struct packed_git *p)
oidset_clear(&p->bad_objects);
}
-void close_object_store(struct raw_object_store *o)
+void close_object_store(struct object_database *o)
{
struct packed_git *p;
diff --git a/packfile.h b/packfile.h
index 3a3c77cf05a..826eb7f475f 100644
--- a/packfile.h
+++ b/packfile.h
@@ -183,12 +183,12 @@ int close_pack_fd(struct packed_git *p);
uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
-struct raw_object_store;
+struct object_database;
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
void close_pack_windows(struct packed_git *);
void close_pack(struct packed_git *);
-void close_object_store(struct raw_object_store *o);
+void close_object_store(struct object_database *o);
void unuse_pack(struct pack_window **);
void clear_delta_base_cache(void);
struct packed_git *add_packed_git(struct repository *r, const char *path,
diff --git a/repository.c b/repository.c
index 9b3d6665fc6..07757e6e0c9 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = raw_object_store_new();
+ repo->objects = odb_new();
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -374,7 +374,7 @@ void repo_clear(struct repository *repo)
FREE_AND_NULL(repo->worktree);
FREE_AND_NULL(repo->submodule_prefix);
- raw_object_store_clear(repo->objects);
+ odb_clear(repo->objects);
FREE_AND_NULL(repo->objects);
parsed_object_pool_clear(repo->parsed_objects);
diff --git a/repository.h b/repository.h
index c4c92b2ab9c..3a5ef9c781e 100644
--- a/repository.h
+++ b/repository.h
@@ -9,7 +9,7 @@ struct git_hash_algo;
struct index_state;
struct lock_file;
struct pathspec;
-struct raw_object_store;
+struct object_database;
struct submodule_cache;
struct promisor_remote_config;
struct remote_state;
@@ -47,7 +47,7 @@ struct repository {
/*
* Holds any information related to accessing the raw object content.
*/
- struct raw_object_store *objects;
+ struct object_database *objects;
/*
* All objects in this repository that have been parsed. This structure
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 01/17] object-store: rename `raw_object_store` to `object_database`
2025-05-06 11:09 ` [PATCH 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
@ 2025-05-07 0:47 ` Derrick Stolee
2025-05-07 15:27 ` Junio C Hamano
0 siblings, 1 reply; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 0:47 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> Instead, rename the structure to `object_database`. This term is already
> used a lot throughout our codebase, and it cannot easily be mistaken for
> "object directories", either. Furthermore, its acronym ODB is already
> well-known and works well as part of a function's name, like for example
> `odb_has_object()`.
The patch is the kind where "it's correct if and only if it compiles,"
which is good!
I just wanted to chime in to approve of the term "object database" and
using ODB for short.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 01/17] object-store: rename `raw_object_store` to `object_database`
2025-05-07 0:47 ` Derrick Stolee
@ 2025-05-07 15:27 ` Junio C Hamano
0 siblings, 0 replies; 166+ messages in thread
From: Junio C Hamano @ 2025-05-07 15:27 UTC (permalink / raw)
To: Derrick Stolee; +Cc: Patrick Steinhardt, git
Derrick Stolee <stolee@gmail.com> writes:
> On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
>
>> Instead, rename the structure to `object_database`. This term is already
>> used a lot throughout our codebase, and it cannot easily be mistaken for
>> "object directories", either. Furthermore, its acronym ODB is already
>> well-known and works well as part of a function's name, like for example
>> `odb_has_object()`.
>
> The patch is the kind where "it's correct if and only if it compiles,"
> which is good!
Yes, unless there are topics in flight that adds more uses
independently; I think there weren't any, though, which is good.
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH 02/17] object-store: rename `object_directory` to `odb_backend`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
2025-05-06 11:09 ` [PATCH 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-07 0:51 ` Derrick Stolee
2025-05-06 11:09 ` [PATCH 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
` (21 subsequent siblings)
23 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
The `object_directory` structure is used as an access point for a single
object directory like ".git/objects". While the structure isn't yet
fully self-contained, the intent is for it to eventually contain all
information required to access objects in one specific location.
While the name "object directory" is a good fit for now, this will
change over time as we continue with the agenda to make pluggable object
databases a thing. Eventually, objects may not be accessed via any kind
of directory at all anymore, but they could instead be backed by any
kind of durable storage mechanism. While it seems quite far-fetched for
now, it is thinkable that eventually this might even be some form of a
database, for example.
As such, the current name of this structure will become worse over time
as we evolve into the direction of pluggable ODBs. Immediate next steps
will start to carve out proper self-contained object directories, which
requires us to pass in these object directories as parameters. Based on
our modern naming schema this means that those functions should then be
named after their subsystem, which means that we would start to bake the
current name into the codebase more and more.
Let's preempt this by renaming the structure to `odb_backend` now
already. This name is agnostic of how exactly objects are stored and
allows us to easily introduce e.g. a `files_odb_backend` and other
specific implementations over time.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 4 +-
builtin/count-objects.c | 2 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 14 +++----
builtin/gc.c | 14 +++----
builtin/grep.c | 2 +-
builtin/multi-pack-index.c | 4 +-
builtin/submodule--helper.c | 2 +-
bundle.c | 2 +-
commit-graph.c | 44 +++++++++----------
commit-graph.h | 14 +++----
diagnose.c | 4 +-
http-walker.c | 2 +-
http.c | 4 +-
loose.c | 20 ++++-----
midx.c | 6 +--
object-file.c | 46 ++++++++++----------
object-file.h | 8 ++--
object-name.c | 6 +--
object-store.c | 100 ++++++++++++++++++++++----------------------
object-store.h | 23 +++++-----
packfile.c | 16 +++----
path.c | 2 +-
refs.c | 2 +-
repository.c | 17 ++++----
submodule-config.c | 2 +-
t/helper/test-read-graph.c | 6 +--
tmp-objdir.c | 4 +-
28 files changed, 187 insertions(+), 185 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index a783a86e797..b4cbdbb1f7b 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb = NULL;
+ struct odb_backend *odb = NULL;
char *graph_name;
char *chain_name;
enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE;
@@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
struct string_list pack_indexes = STRING_LIST_INIT_DUP;
struct strbuf buf = STRBUF_INIT;
struct oidset commits = OIDSET_INIT;
- struct object_directory *odb = NULL;
+ struct odb_backend *odb = NULL;
int result = 0;
enum commit_graph_write_flags flags = 0;
struct progress *progress = NULL;
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index a88c0c9c09a..80f2693ac3c 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -80,7 +80,7 @@ static int count_cruft(const char *basename UNUSED, const char *path,
return 0;
}
-static int print_alternate(struct object_directory *odb, void *data UNUSED)
+static int print_alternate(struct odb_backend *odb, void *data UNUSED)
{
printf("alternate: ");
quote_c_style(odb->path, NULL, stdout, 0);
diff --git a/builtin/fetch.c b/builtin/fetch.c
index cda6eaf1fd6..0b15121ff7c 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2652,7 +2652,7 @@ int cmd_fetch(int argc,
commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
trace2_region_enter("fetch", "write-commit-graph", the_repository);
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->backends,
commit_graph_flags,
NULL);
trace2_region_leave("fetch", "write-commit-graph", the_repository);
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6cac28356ce..0c1df302129 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -965,7 +965,7 @@ int cmd_fsck(int argc,
struct repository *repo UNUSED)
{
int i;
- struct object_directory *odb;
+ struct odb_backend *backend;
/* fsck knows how to handle missing promisor objects */
fetch_if_missing = 0;
@@ -1007,8 +1007,8 @@ int cmd_fsck(int argc,
mark_packed_for_connectivity, NULL, 0);
} else {
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next)
- fsck_object_dir(odb->path);
+ for (backend = the_repository->objects->backends; backend; backend = backend->next)
+ fsck_object_dir(backend->path);
if (check_full) {
struct packed_git *p;
@@ -1118,11 +1118,11 @@ int cmd_fsck(int argc,
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (backend = the_repository->objects->backends; backend; backend = backend->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
strvec_pushl(&commit_graph_verify.args, "commit-graph",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", backend->path, NULL);
if (show_progress)
strvec_push(&commit_graph_verify.args, "--progress");
else
@@ -1136,11 +1136,11 @@ int cmd_fsck(int argc,
struct child_process midx_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (backend = the_repository->objects->backends; backend; backend = backend->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", backend->path, NULL);
if (show_progress)
strvec_push(&midx_verify.args, "--progress");
else
diff --git a/builtin/gc.c b/builtin/gc.c
index 78a2751aa8a..ea13660dba1 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -944,7 +944,7 @@ struct repository *repo UNUSED)
}
if (the_repository->settings.gc_write_commit_graph == 1)
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->backends,
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
NULL);
@@ -1197,7 +1197,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
if (loose_object_auto_limit < 0)
return 1;
- return for_each_loose_file_in_objdir(the_repository->objects->odb->path,
+ return for_each_loose_file_in_objdir(the_repository->objects->backends->path,
loose_object_count,
NULL, NULL, &count);
}
@@ -1232,7 +1232,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
* Do not start pack-objects process
* if there are no loose objects.
*/
- if (!for_each_loose_file_in_objdir(r->objects->odb->path,
+ if (!for_each_loose_file_in_objdir(r->objects->backends->path,
bail_on_loose,
NULL, NULL, NULL))
return 0;
@@ -1244,7 +1244,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
strvec_push(&pack_proc.args, "--quiet");
else
strvec_push(&pack_proc.args, "--no-quiet");
- strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
+ strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->backends->path);
pack_proc.in = -1;
@@ -1272,7 +1272,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
else if (data.batch_size > 0)
data.batch_size--; /* Decrease for equality on limit. */
- for_each_loose_file_in_objdir(r->objects->odb->path,
+ for_each_loose_file_in_objdir(r->objects->backends->path,
write_loose_object_to_stdin,
NULL,
NULL,
@@ -1525,7 +1525,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
int result = 0;
struct lock_file lk;
struct repository *r = the_repository;
- char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path);
+ char *lock_path = xstrfmt("%s/maintenance", r->objects->backends->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
/*
@@ -2997,7 +2997,7 @@ static int update_background_schedule(const struct maintenance_start_opts *opts,
unsigned int i;
int result = 0;
struct lock_file lk;
- char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path);
+ char *lock_path = xstrfmt("%s/schedule", the_repository->objects->backends->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
if (errno == EEXIST)
diff --git a/builtin/grep.c b/builtin/grep.c
index 3ce574a605b..3affe523df1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,7 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->odb->path);
+ add_submodule_odb_by_path(subrepo->objects->backends->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 69a97507324..87173307bf3 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -294,8 +294,8 @@ int cmd_multi_pack_index(int argc,
if (the_repository &&
the_repository->objects &&
- the_repository->objects->odb)
- opts.object_dir = xstrdup(the_repository->objects->odb->path);
+ the_repository->objects->backends)
+ opts.object_dir = xstrdup(the_repository->objects->backends->path);
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 53da2116ddf..13fb4ecfaac 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1582,7 +1582,7 @@ static const char alternate_error_advice[] = N_(
);
static int add_possible_reference_from_superproject(
- struct object_directory *odb, void *sas_cb)
+ struct odb_backend *odb, void *sas_cb)
{
struct submodule_alternate_setup *sas = sas_cb;
size_t len;
diff --git a/bundle.c b/bundle.c
index b0a3fee2efa..dd4c082f8e7 100644
--- a/bundle.c
+++ b/bundle.c
@@ -233,7 +233,7 @@ int verify_bundle(struct repository *r,
.quiet = 1,
};
- if (!r || !r->objects || !r->objects->odb)
+ if (!r || !r->objects || !r->objects->backends)
return error(_("need a repository to verify a bundle"));
for (i = 0; i < p->nr; i++) {
diff --git a/commit-graph.c b/commit-graph.c
index 1b66486b9c9..7a85b73cd99 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -37,7 +37,7 @@ void git_test_write_commit_graph_or_die(void)
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- if (write_commit_graph_reachable(the_repository->objects->odb,
+ if (write_commit_graph_reachable(the_repository->objects->backends,
flags, NULL))
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
}
@@ -191,19 +191,19 @@ static int commit_gen_cmp(const void *va, const void *vb)
return 0;
}
-char *get_commit_graph_filename(struct object_directory *obj_dir)
+char *get_commit_graph_filename(struct odb_backend *obj_dir)
{
return xstrfmt("%s/info/commit-graph", obj_dir->path);
}
-static char *get_split_graph_filename(struct object_directory *odb,
+static char *get_split_graph_filename(struct odb_backend *odb,
const char *oid_hex)
{
return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb->path,
oid_hex);
}
-char *get_commit_graph_chain_filename(struct object_directory *odb)
+char *get_commit_graph_chain_filename(struct odb_backend *odb)
{
return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
}
@@ -250,7 +250,7 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb)
+ struct odb_backend *odb)
{
void *graph_map;
size_t graph_size;
@@ -487,7 +487,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
static struct commit_graph *load_commit_graph_one(struct repository *r,
const char *graph_file,
- struct object_directory *odb)
+ struct odb_backend *odb)
{
struct stat st;
@@ -507,7 +507,7 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
}
static struct commit_graph *load_commit_graph_v1(struct repository *r,
- struct object_directory *odb)
+ struct odb_backend *odb)
{
char *graph_name = get_commit_graph_filename(odb);
struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
@@ -652,7 +652,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
prepare_alt_odb(r);
for (i = 0; i < count; i++) {
- struct object_directory *odb;
+ struct odb_backend *backend;
if (strbuf_getline_lf(&line, fp) == EOF)
break;
@@ -665,9 +665,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
valid = 0;
- for (odb = r->objects->odb; odb; odb = odb->next) {
- char *graph_name = get_split_graph_filename(odb, line.buf);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ for (backend = r->objects->backends; backend; backend = backend->next) {
+ char *graph_name = get_split_graph_filename(backend, line.buf);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, backend);
free(graph_name);
@@ -701,7 +701,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
static struct commit_graph *load_commit_graph_chain(struct repository *r,
- struct object_directory *odb)
+ struct odb_backend *odb)
{
char *chain_file = get_commit_graph_chain_filename(odb);
struct stat st;
@@ -719,7 +719,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
}
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_backend *odb)
{
struct commit_graph *g = load_commit_graph_v1(r, odb);
@@ -730,7 +730,7 @@ struct commit_graph *read_commit_graph_one(struct repository *r,
}
static void prepare_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_backend *odb)
{
if (r->objects->commit_graph)
@@ -747,7 +747,7 @@ static void prepare_commit_graph_one(struct repository *r,
*/
static int prepare_commit_graph(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_backend *backend;
/*
* Early return if there is no git dir or if the commit graph is
@@ -779,10 +779,10 @@ static int prepare_commit_graph(struct repository *r)
return 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb;
- !r->objects->commit_graph && odb;
- odb = odb->next)
- prepare_commit_graph_one(r, odb);
+ for (backend = r->objects->backends;
+ !r->objects->commit_graph && backend;
+ backend = backend->next)
+ prepare_commit_graph_one(r, backend);
return !!r->objects->commit_graph;
}
@@ -1137,7 +1137,7 @@ struct packed_commit_list {
struct write_commit_graph_context {
struct repository *r;
- struct object_directory *odb;
+ struct odb_backend *odb;
char *graph_name;
struct oid_array oids;
struct packed_commit_list commits;
@@ -1870,7 +1870,7 @@ static int add_ref_to_set(const char *refname UNUSED,
return 0;
}
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_backend *odb,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts)
{
@@ -2502,7 +2502,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
strbuf_release(&path);
}
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_backend *odb,
const struct string_list *const pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
diff --git a/commit-graph.h b/commit-graph.h
index 20d38c100ce..437cb48081d 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -29,8 +29,8 @@ struct repository;
struct object_database;
struct string_list;
-char *get_commit_graph_filename(struct object_directory *odb);
-char *get_commit_graph_chain_filename(struct object_directory *odb);
+char *get_commit_graph_filename(struct odb_backend *odb);
+char *get_commit_graph_chain_filename(struct odb_backend *odb);
int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st);
@@ -89,7 +89,7 @@ struct commit_graph {
uint32_t num_commits;
struct object_id oid;
char *filename;
- struct object_directory *odb;
+ struct odb_backend *odb;
uint32_t num_commits_in_base;
unsigned int read_generation_data;
@@ -115,12 +115,12 @@ struct commit_graph {
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb);
+ struct odb_backend *odb);
struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
int fd, struct stat *st,
int *incomplete_chain);
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb);
+ struct odb_backend *odb);
struct repo_settings;
@@ -173,10 +173,10 @@ struct commit_graph_opts {
* is not compatible with the commit-graph feature, then the
* methods will return 0 without writing a commit-graph.
*/
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_backend *odb,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts);
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_backend *odb,
const struct string_list *pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
diff --git a/diagnose.c b/diagnose.c
index b1be74be983..3016ad223d2 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -59,7 +59,7 @@ static void dir_file_stats_objects(const char *full_path,
(uintmax_t)st.st_size);
}
-static int dir_file_stats(struct object_directory *object_dir, void *data)
+static int dir_file_stats(struct odb_backend *object_dir, void *data)
{
struct strbuf *buf = data;
@@ -228,7 +228,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(r->objects->odb, &buf);
+ dir_file_stats(r->objects->backends, &buf);
foreach_alt_odb(dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
diff --git a/http-walker.c b/http-walker.c
index 463f7b119ad..abb44d73067 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
ret = error("File %s has bad hash", hex);
} else if (req->rename < 0) {
struct strbuf buf = STRBUF_INIT;
- odb_loose_path(the_repository->objects->odb, &buf, &req->oid);
+ odb_loose_path(the_repository->objects->backends, &buf, &req->oid);
ret = error("unable to write sha1 filename %s", buf.buf);
strbuf_release(&buf);
}
diff --git a/http.c b/http.c
index 3c029cf8947..302738dd29b 100644
--- a/http.c
+++ b/http.c
@@ -2662,7 +2662,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
oidcpy(&freq->oid, oid);
freq->localfile = -1;
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->backends, &filename, oid);
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2814,7 +2814,7 @@ int finish_http_object_request(struct http_object_request *freq)
unlink_or_warn(freq->tmpfile.buf);
return -1;
}
- odb_loose_path(the_repository->objects->odb, &filename, &freq->oid);
+ odb_loose_path(the_repository->objects->backends, &filename, &freq->oid);
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
strbuf_release(&filename);
diff --git a/loose.c b/loose.c
index bb602aaa366..fab7f99868d 100644
--- a/loose.c
+++ b/loose.c
@@ -44,7 +44,7 @@ static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *key, const
return 1;
}
-static int insert_loose_map(struct object_directory *odb,
+static int insert_loose_map(struct odb_backend *odb,
const struct object_id *oid,
const struct object_id *compat_oid)
{
@@ -59,7 +59,7 @@ static int insert_loose_map(struct object_directory *odb,
return inserted;
}
-static int load_one_loose_object_map(struct repository *repo, struct object_directory *dir)
+static int load_one_loose_object_map(struct repository *repo, struct odb_backend *dir)
{
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
FILE *fp;
@@ -107,15 +107,15 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
int repo_read_loose_object_map(struct repository *repo)
{
- struct object_directory *dir;
+ struct odb_backend *backend;
if (!should_use_loose_object_map(repo))
return 0;
prepare_alt_odb(repo);
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- if (load_one_loose_object_map(repo, dir) < 0) {
+ for (backend = repo->objects->backends; backend; backend = backend->next) {
+ if (load_one_loose_object_map(repo, backend) < 0) {
return -1;
}
}
@@ -124,7 +124,7 @@ int repo_read_loose_object_map(struct repository *repo)
int repo_write_loose_object_map(struct repository *repo)
{
- kh_oid_map_t *map = repo->objects->odb->loose_map->to_compat;
+ kh_oid_map_t *map = repo->objects->backends->loose_map->to_compat;
struct lock_file lock;
int fd;
khiter_t iter;
@@ -212,7 +212,7 @@ int repo_add_loose_object_map(struct repository *repo, const struct object_id *o
if (!should_use_loose_object_map(repo))
return 0;
- inserted = insert_loose_map(repo->objects->odb, oid, compat_oid);
+ inserted = insert_loose_map(repo->objects->backends, oid, compat_oid);
if (inserted)
return write_one_object(repo, oid, compat_oid);
return 0;
@@ -223,12 +223,12 @@ int repo_loose_object_map_oid(struct repository *repo,
const struct git_hash_algo *to,
struct object_id *dest)
{
- struct object_directory *dir;
+ struct odb_backend *backend;
kh_oid_map_t *map;
khiter_t pos;
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- struct loose_object_map *loose_map = dir->loose_map;
+ for (backend = repo->objects->backends; backend; backend = backend->next) {
+ struct loose_object_map *loose_map = backend->loose_map;
if (!loose_map)
continue;
map = (to == repo->compat_hash_algo) ?
diff --git a/midx.c b/midx.c
index 3d0015f7828..767217678eb 100644
--- a/midx.c
+++ b/midx.c
@@ -824,7 +824,7 @@ void clear_midx_file(struct repository *r)
{
struct strbuf midx = STRBUF_INIT;
- get_midx_filename(r->hash_algo, &midx, r->objects->odb->path);
+ get_midx_filename(r->hash_algo, &midx, r->objects->backends->path);
if (r->objects && r->objects->multi_pack_index) {
close_midx(r->objects->multi_pack_index);
@@ -834,8 +834,8 @@ void clear_midx_file(struct repository *r)
if (remove_path(midx.buf))
die(_("failed to clear multi-pack-index at %s"), midx.buf);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_BITMAP, NULL);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_REV, NULL);
+ clear_midx_files_ext(r->objects->backends->path, MIDX_EXT_BITMAP, NULL);
+ clear_midx_files_ext(r->objects->backends->path, MIDX_EXT_REV, NULL);
strbuf_release(&midx);
}
diff --git a/object-file.c b/object-file.c
index dc56a4766df..4940103ac6d 100644
--- a/object-file.c
+++ b/object-file.c
@@ -55,7 +55,7 @@ static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
}
}
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_backend *odb,
struct strbuf *buf,
const struct object_id *oid)
{
@@ -88,7 +88,7 @@ int check_and_freshen_file(const char *fn, int freshen)
return 1;
}
-static int check_and_freshen_odb(struct object_directory *odb,
+static int check_and_freshen_odb(struct odb_backend *odb,
const struct object_id *oid,
int freshen)
{
@@ -99,16 +99,16 @@ static int check_and_freshen_odb(struct object_directory *odb,
static int check_and_freshen_local(const struct object_id *oid, int freshen)
{
- return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
+ return check_and_freshen_odb(the_repository->objects->backends, oid, freshen);
}
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
- struct object_directory *odb;
+ struct odb_backend *backend;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
- if (check_and_freshen_odb(odb, oid, freshen))
+ for (backend = the_repository->objects->backends->next; backend; backend = backend->next) {
+ if (check_and_freshen_odb(backend, oid, freshen))
return 1;
}
return 0;
@@ -208,12 +208,12 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct stat *st, const char **path)
{
- struct object_directory *odb;
+ struct odb_backend *backend;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (backend = r->objects->backends; backend; backend = backend->next) {
+ *path = odb_loose_path(backend, &buf, oid);
if (!lstat(*path, st))
return 0;
}
@@ -229,13 +229,13 @@ static int open_loose_object(struct repository *r,
const struct object_id *oid, const char **path)
{
int fd;
- struct object_directory *odb;
+ struct odb_backend *backend;
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (backend = r->objects->backends; backend; backend = backend->next) {
+ *path = odb_loose_path(backend, &buf, oid);
fd = git_open(*path);
if (fd >= 0)
return fd;
@@ -250,11 +250,11 @@ static int open_loose_object(struct repository *r,
static int quick_has_loose(struct repository *r,
const struct object_id *oid)
{
- struct object_directory *odb;
+ struct odb_backend *backend;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- if (oidtree_contains(odb_loose_cache(odb, oid), oid))
+ for (backend = r->objects->backends; backend; backend = backend->next) {
+ if (oidtree_contains(odb_loose_cache(backend, oid), oid))
return 1;
}
return 0;
@@ -750,7 +750,7 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
/* Finalize a file on disk, and close it. */
static void close_loose_object(int fd, const char *filename)
{
- if (the_repository->objects->odb->will_destroy)
+ if (the_repository->objects->backends->will_destroy)
goto out;
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
@@ -932,7 +932,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
prepare_loose_object_bulk_checkin();
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->backends, &filename, oid);
fd = start_loose_object_common(&tmp_file, filename.buf, flags,
&stream, compressed, sizeof(compressed),
@@ -1079,7 +1079,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
goto cleanup;
}
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->backends, &filename, oid);
/* We finally know the object path, and create the missing dir. */
dirlen = directory_size(filename.buf);
@@ -1540,11 +1540,11 @@ int for_each_loose_file_in_objdir(const char *path,
int for_each_loose_object(each_loose_object_fn cb, void *data,
enum for_each_object_flags flags)
{
- struct object_directory *odb;
+ struct odb_backend *backend;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
- int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
+ for (backend = the_repository->objects->backends; backend; backend = backend->next) {
+ int r = for_each_loose_file_in_objdir(backend->path, cb, NULL,
NULL, data);
if (r)
return r;
@@ -1564,7 +1564,7 @@ static int append_loose_object(const struct object_id *oid,
return 0;
}
-struct oidtree *odb_loose_cache(struct object_directory *odb,
+struct oidtree *odb_loose_cache(struct odb_backend *odb,
const struct object_id *oid)
{
int subdir_nr = oid->hash[0];
@@ -1595,7 +1595,7 @@ struct oidtree *odb_loose_cache(struct object_directory *odb,
return odb->loose_objects_cache;
}
-void odb_clear_loose_cache(struct object_directory *odb)
+void odb_clear_loose_cache(struct odb_backend *odb)
{
oidtree_clear(odb->loose_objects_cache);
FREE_AND_NULL(odb->loose_objects_cache);
diff --git a/object-file.h b/object-file.h
index a85b2e5b494..630a8ef1cbd 100644
--- a/object-file.h
+++ b/object-file.h
@@ -24,23 +24,23 @@ enum {
int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
-struct object_directory;
+struct odb_backend;
/*
* Populate and return the loose object cache array corresponding to the
* given object ID.
*/
-struct oidtree *odb_loose_cache(struct object_directory *odb,
+struct oidtree *odb_loose_cache(struct odb_backend *odb,
const struct object_id *oid);
/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
+void odb_clear_loose_cache(struct odb_backend *odb);
/*
* Put in `buf` the name of the file in the local object database that
* would be used to store a loose object with the specified oid.
*/
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_backend *odb,
struct strbuf *buf,
const struct object_id *oid);
diff --git a/object-name.c b/object-name.c
index 9288b2dd245..b80791a9018 100644
--- a/object-name.c
+++ b/object-name.c
@@ -112,10 +112,10 @@ static enum cb_next match_prefix(const struct object_id *oid, void *arg)
static void find_short_object_filename(struct disambiguate_state *ds)
{
- struct object_directory *odb;
+ struct odb_backend *backend;
- for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next)
- oidtree_each(odb_loose_cache(odb, &ds->bin_pfx),
+ for (backend = ds->repo->objects->backends; backend && !ds->ambiguous; backend = backend->next)
+ oidtree_each(odb_loose_cache(backend, &ds->bin_pfx),
&ds->bin_pfx, ds->len, match_prefix, ds);
}
diff --git a/object-store.c b/object-store.c
index 1effcb12273..1c57c7b1a32 100644
--- a/object-store.c
+++ b/object-store.c
@@ -27,7 +27,7 @@
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
- struct object_directory *, 1, fspathhash, fspatheq)
+ struct odb_backend *, 1, fspathhash, fspatheq)
/*
* This is meant to hold a *small* number of objects that you would
@@ -104,18 +104,18 @@ static int alt_odb_usable(struct object_database *o,
* Prevent the common mistake of listing the same
* thing twice, or object directory itself.
*/
- if (!o->odb_by_path) {
+ if (!o->backend_by_path) {
khiter_t p;
- o->odb_by_path = kh_init_odb_path_map();
- assert(!o->odb->next);
- p = kh_put_odb_path_map(o->odb_by_path, o->odb->path, &r);
+ o->backend_by_path = kh_init_odb_path_map();
+ assert(!o->backends->next);
+ p = kh_put_odb_path_map(o->backend_by_path, o->backends->path, &r);
assert(r == 1); /* never used */
- kh_value(o->odb_by_path, p) = o->odb;
+ kh_value(o->backend_by_path, p) = o->backends;
}
if (fspatheq(path->buf, normalized_objdir))
return 0;
- *pos = kh_put_odb_path_map(o->odb_by_path, path->buf, &r);
+ *pos = kh_put_odb_path_map(o->backend_by_path, path->buf, &r);
/* r: 0 = exists, 1 = never used, 2 = deleted */
return r == 0 ? 0 : 1;
}
@@ -124,7 +124,7 @@ static int alt_odb_usable(struct object_database *o,
* Prepare alternate object database registry.
*
* The variable alt_odb_list points at the list of struct
- * object_directory. The elements on this list come from
+ * odb_backend. The elements on this list come from
* non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
* environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
* whose contents is similar to that environment variable but can be
@@ -141,7 +141,7 @@ static void read_info_alternates(struct repository *r,
static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
const char *relative_base, int depth, const char *normalized_objdir)
{
- struct object_directory *ent;
+ struct odb_backend *backend;
struct strbuf pathbuf = STRBUF_INIT;
struct strbuf tmp = STRBUF_INIT;
khiter_t pos;
@@ -170,19 +170,19 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
goto error;
- CALLOC_ARRAY(ent, 1);
- /* pathbuf.buf is already in r->objects->odb_by_path */
- ent->path = strbuf_detach(&pathbuf, NULL);
+ CALLOC_ARRAY(backend, 1);
+ /* pathbuf.buf is already in r->objects->backend_by_path */
+ backend->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->odb_tail = ent;
- r->objects->odb_tail = &(ent->next);
- ent->next = NULL;
- assert(r->objects->odb_by_path);
- kh_value(r->objects->odb_by_path, pos) = ent;
+ *r->objects->backends_tail = backend;
+ r->objects->backends_tail = &(backend->next);
+ backend->next = NULL;
+ assert(r->objects->backend_by_path);
+ kh_value(r->objects->backend_by_path, pos) = backend;
/* recursively add alternates */
- read_info_alternates(r, ent->path, depth + 1);
+ read_info_alternates(r, backend->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -234,7 +234,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->odb->path, 1);
+ strbuf_realpath(&objdirbuf, r->objects->backends->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
@@ -321,9 +321,9 @@ void add_to_alternates_memory(const char *reference)
'\n', NULL, 0);
}
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy)
{
- struct object_directory *new_odb;
+ struct odb_backend *backend;
/*
* Make sure alternates are initialized, or else our entry may be
@@ -335,21 +335,21 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
- new_odb = xcalloc(1, sizeof(*new_odb));
- new_odb->path = xstrdup(dir);
+ backend = xcalloc(1, sizeof(*backend));
+ backend->path = xstrdup(dir);
/*
* Disable ref updates while a temporary odb is active, since
* the objects in the database may roll back.
*/
- new_odb->disable_ref_updates = 1;
- new_odb->will_destroy = will_destroy;
- new_odb->next = the_repository->objects->odb;
- the_repository->objects->odb = new_odb;
- return new_odb->next;
+ backend->disable_ref_updates = 1;
+ backend->will_destroy = will_destroy;
+ backend->next = the_repository->objects->backends;
+ the_repository->objects->backends = backend;
+ return backend->next;
}
-static void free_object_directory(struct object_directory *odb)
+static void free_object_directory(struct odb_backend *odb)
{
free(odb->path);
odb_clear_loose_cache(odb);
@@ -357,9 +357,9 @@ static void free_object_directory(struct object_directory *odb)
free(odb);
}
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
+void restore_primary_odb(struct odb_backend *restore_odb, const char *old_path)
{
- struct object_directory *cur_odb = the_repository->objects->odb;
+ struct odb_backend *cur_odb = the_repository->objects->backends;
if (strcmp(old_path, cur_odb->path))
BUG("expected %s as primary object store; found %s",
@@ -368,7 +368,7 @@ void restore_primary_odb(struct object_directory *restore_odb, const char *old_p
if (cur_odb->next != restore_odb)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->odb = restore_odb;
+ the_repository->objects->backends = restore_odb;
free_object_directory(cur_odb);
}
@@ -442,14 +442,14 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct object_directory *find_odb(struct repository *r, const char *obj_dir)
+struct odb_backend *find_odb(struct repository *r, const char *obj_dir)
{
- struct object_directory *odb;
+ struct odb_backend *odb;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
+ for (odb = r->objects->backends; odb; odb = odb->next) {
strbuf_realpath(&odb_path_real, odb->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
@@ -527,7 +527,7 @@ struct alternate_refs_data {
void *data;
};
-static int refs_from_alternate_cb(struct object_directory *e,
+static int refs_from_alternate_cb(struct odb_backend *e,
void *data)
{
struct strbuf path = STRBUF_INIT;
@@ -563,12 +563,12 @@ void for_each_alternate_ref(alternate_ref_fn fn, void *data)
int foreach_alt_odb(alt_odb_fn fn, void *cb)
{
- struct object_directory *ent;
+ struct odb_backend *backend;
int r = 0;
prepare_alt_odb(the_repository);
- for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {
- r = fn(ent, cb);
+ for (backend = the_repository->objects->backends->next; backend; backend = backend->next) {
+ r = fn(backend, cb);
if (r)
break;
}
@@ -582,14 +582,14 @@ void prepare_alt_odb(struct repository *r)
link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->odb->path, 0);
+ read_info_alternates(r, r->objects->backends->path, 0);
r->objects->loaded_alternates = 1;
}
int has_alt_odb(struct repository *r)
{
prepare_alt_odb(r);
- return !!r->objects->odb->next;
+ return !!r->objects->backends->next;
}
int obj_read_use_lock = 0;
@@ -959,7 +959,7 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct object_database *odb_new(void)
+struct object_database *odb_new(struct repository *repo)
{
struct object_database *o = xmalloc(sizeof(*o));
@@ -972,15 +972,15 @@ struct object_database *odb_new(void)
static void free_object_directories(struct object_database *o)
{
- while (o->odb) {
- struct object_directory *next;
+ while (o->backends) {
+ struct odb_backend *next;
- next = o->odb->next;
- free_object_directory(o->odb);
- o->odb = next;
+ next = o->backends->next;
+ free_object_directory(o->backends);
+ o->backends = next;
}
- kh_destroy_odb_path_map(o->odb_by_path);
- o->odb_by_path = NULL;
+ kh_destroy_odb_path_map(o->backend_by_path);
+ o->backend_by_path = NULL;
}
void odb_clear(struct object_database *o)
@@ -996,7 +996,7 @@ void odb_clear(struct object_database *o)
o->commit_graph_attempted = 0;
free_object_directories(o);
- o->odb_tail = NULL;
+ o->backends_tail = NULL;
o->loaded_alternates = 0;
for (size_t i = 0; i < o->cached_object_nr; i++)
diff --git a/object-store.h b/object-store.h
index 34b8efbbb83..94b678eb63c 100644
--- a/object-store.h
+++ b/object-store.h
@@ -12,8 +12,9 @@ struct oidtree;
struct strbuf;
struct repository;
-struct object_directory {
- struct object_directory *next;
+/* The backend used to access objects in a specific object directory. */
+struct odb_backend {
+ struct odb_backend *next;
/*
* Used to store the results of readdir(3) calls when we are OK
@@ -52,8 +53,8 @@ struct object_directory {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
+struct odb_backend *find_odb(struct repository *r, const char *obj_dir);
+typedef int alt_odb_fn(struct odb_backend *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
@@ -75,12 +76,12 @@ void add_to_alternates_memory(const char *dir);
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
*/
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy);
/*
* Restore a previous ODB replaced by set_temporary_main_odb.
*/
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+void restore_primary_odb(struct odb_backend *restore_odb, const char *old_path);
struct packed_git;
struct multi_pack_index;
@@ -97,16 +98,16 @@ struct object_database {
* cannot be NULL after initialization). Subsequent directories are
* alternates.
*/
- struct object_directory *odb;
- struct object_directory **odb_tail;
- struct kh_odb_path_map *odb_by_path;
+ struct odb_backend *backends;
+ struct odb_backend **backends_tail;
+ struct kh_odb_path_map *backend_by_path;
int loaded_alternates;
/*
* 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.
+ * populate the "backends" list when prepare_alt_odb() is run.
*/
char *alternate_db;
@@ -173,7 +174,7 @@ struct object_database {
unsigned packed_git_initialized : 1;
};
-struct object_database *odb_new(void);
+struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
/*
diff --git a/packfile.c b/packfile.c
index 8f51665266d..69096849654 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1018,16 +1018,16 @@ static void prepare_packed_git_mru(struct repository *r)
static void prepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_backend *backend;
if (r->objects->packed_git_initialized)
return;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- int local = (odb == r->objects->odb);
- prepare_multi_pack_index_one(r, odb->path, local);
- prepare_packed_git_one(r, odb->path, local);
+ for (backend = r->objects->backends; backend; backend = backend->next) {
+ int local = (backend == r->objects->backends);
+ prepare_multi_pack_index_one(r, backend->path, local);
+ prepare_packed_git_one(r, backend->path, local);
}
rearrange_packed_git(r);
@@ -1037,7 +1037,7 @@ static void prepare_packed_git(struct repository *r)
void reprepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_backend *backend;
obj_read_lock();
@@ -1050,8 +1050,8 @@ void reprepare_packed_git(struct repository *r)
r->objects->loaded_alternates = 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next)
- odb_clear_loose_cache(odb);
+ for (backend = r->objects->backends; backend; backend = backend->next)
+ odb_clear_loose_cache(backend);
r->objects->approximate_object_count_valid = 0;
r->objects->packed_git_initialized = 0;
diff --git a/path.c b/path.c
index 3b598b2847f..04a9ef5a1b1 100644
--- a/path.c
+++ b/path.c
@@ -397,7 +397,7 @@ static void adjust_git_path(struct repository *repo,
strbuf_splice(buf, 0, buf->len,
repo->index_file, strlen(repo->index_file));
else if (dir_prefix(base, "objects"))
- replace_dir(buf, git_dir_len + 7, repo->objects->odb->path);
+ replace_dir(buf, git_dir_len + 7, repo->objects->backends->path);
else if (repo_settings_get_hooks_path(repo) && dir_prefix(base, "hooks"))
replace_dir(buf, git_dir_len + 5, repo_settings_get_hooks_path(repo));
else if (repo->different_commondir)
diff --git a/refs.c b/refs.c
index dce5c49ca2b..ff2d5d6e92b 100644
--- a/refs.c
+++ b/refs.c
@@ -2477,7 +2477,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
break;
}
- if (refs->repo->objects->odb->disable_ref_updates) {
+ if (refs->repo->objects->backends->disable_ref_updates) {
strbuf_addstr(err,
_("ref updates forbidden inside quarantine environment"));
return -1;
diff --git a/repository.c b/repository.c
index 07757e6e0c9..0ab73846de3 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = odb_new();
+ repo->objects = odb_new(repo);
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -107,9 +107,9 @@ const char *repo_get_common_dir(struct repository *repo)
const char *repo_get_object_directory(struct repository *repo)
{
- if (!repo->objects->odb)
+ if (!repo->objects->backends)
BUG("repository hasn't been set up");
- return repo->objects->odb->path;
+ return repo->objects->backends->path;
}
const char *repo_get_index_file(struct repository *repo)
@@ -165,14 +165,15 @@ void repo_set_gitdir(struct repository *repo,
repo_set_commondir(repo, o->commondir);
- if (!repo->objects->odb) {
- CALLOC_ARRAY(repo->objects->odb, 1);
- repo->objects->odb_tail = &repo->objects->odb->next;
+ if (!repo->objects->backends) {
+ CALLOC_ARRAY(repo->objects->backends, 1);
+ repo->objects->backends->odb = repo->objects;
+ repo->objects->backends_tail = &repo->objects->backends->next;
}
- expand_base_dir(&repo->objects->odb->path, o->object_dir,
+ expand_base_dir(&repo->objects->backends->path, o->object_dir,
repo->commondir, "objects");
- repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
+ repo->objects->backends->disable_ref_updates = o->disable_ref_updates;
free(repo->objects->alternate_db);
repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
diff --git a/submodule-config.c b/submodule-config.c
index 8630e27947d..c9418f51265 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->odb->path);
+ add_submodule_odb_by_path(repo->objects->backends->path);
} else {
goto out;
}
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 8b413b644be..45b0043eb93 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -73,15 +73,15 @@ static void dump_graph_bloom_filters(struct commit_graph *graph)
int cmd__read_graph(int argc, const char **argv)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb;
+ struct odb_backend *backend;
int ret = 0;
setup_git_directory();
- odb = the_repository->objects->odb;
+ backend = the_repository->objects->backends;
prepare_repo_settings(the_repository);
- graph = read_commit_graph_one(the_repository, odb);
+ graph = read_commit_graph_one(the_repository, backend);
if (!graph) {
ret = 1;
goto done;
diff --git a/tmp-objdir.c b/tmp-objdir.c
index c38fbeb5e8a..cc4efb3d816 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -17,7 +17,7 @@ struct tmp_objdir {
struct repository *repo;
struct strbuf path;
struct strvec env;
- struct object_directory *prev_odb;
+ struct odb_backend *prev_odb;
int will_destroy;
};
@@ -277,7 +277,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
return 0;
if (t->prev_odb) {
- if (t->repo->objects->odb->will_destroy)
+ if (t->repo->objects->backends->will_destroy)
BUG("migrating an ODB that was marked for destruction");
restore_primary_odb(t->prev_odb, t->path.buf);
t->prev_odb = NULL;
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 02/17] object-store: rename `object_directory` to `odb_backend`
2025-05-06 11:09 ` [PATCH 02/17] object-store: rename `object_directory` to `odb_backend` Patrick Steinhardt
@ 2025-05-07 0:51 ` Derrick Stolee
2025-05-07 1:00 ` Derrick Stolee
0 siblings, 1 reply; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 0:51 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> The `object_directory` structure is used as an access point for a single
> object directory like ".git/objects". While the structure isn't yet
> fully self-contained, the intent is for it to eventually contain all
> information required to access objects in one specific location.
>
> While the name "object directory" is a good fit for now, this will
> change over time as we continue with the agenda to make pluggable object
> databases a thing. Eventually, objects may not be accessed via any kind
> of directory at all anymore, but they could instead be backed by any
> kind of durable storage mechanism. While it seems quite far-fetched for
> now, it is thinkable that eventually this might even be some form of a
> database, for example.
I agree that "object directory" is leaking some of the abstraction, and
that we'd want to be able to have pluggable ODB backends.
> As such, the current name of this structure will become worse over time
> as we evolve into the direction of pluggable ODBs. Immediate next steps
> will start to carve out proper self-contained object directories, which
> requires us to pass in these object directories as parameters. Based on
> our modern naming schema this means that those functions should then be
> named after their subsystem, which means that we would start to bake the
> current name into the codebase more and more.
>
> Let's preempt this by renaming the structure to `odb_backend` now
> already. This name is agnostic of how exactly objects are stored and
> allows us to easily introduce e.g. a `files_odb_backend` and other
> specific implementations over time.
But here's where I'll get a little nitpicky and say that these are
"odb"s not "odb_backend"s.
* odb: a single object database. A repo can have multiple, currently
only one that is read/write and multiple read-only alternates.
* odb backend: an _implementation_ of an object database. This would
be the structure that containts a vtable of implementation methods.
Each individual 'odb' would point to a single backend describing
how to access the data in it.
Does that make sense? If we are going through the effort of renaming
things, I think it's worth being a little more future-proof here.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 02/17] object-store: rename `object_directory` to `odb_backend`
2025-05-07 0:51 ` Derrick Stolee
@ 2025-05-07 1:00 ` Derrick Stolee
2025-05-09 11:25 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 1:00 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 8:51 PM, Derrick Stolee wrote:
> On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
>> Let's preempt this by renaming the structure to `odb_backend` now
>> already. This name is agnostic of how exactly objects are stored and
>> allows us to easily introduce e.g. a `files_odb_backend` and other
>> specific implementations over time.
>
> But here's where I'll get a little nitpicky and say that these are
> "odb"s not "odb_backend"s.
>
> * odb: a single object database. A repo can have multiple, currently
> only one that is read/write and multiple read-only alternates.
>
> * odb backend: an _implementation_ of an object database. This would
> be the structure that containts a vtable of implementation methods.
> Each individual 'odb' would point to a single backend describing
> how to access the data in it.
>
> Does that make sense? If we are going through the effort of renaming
> things, I think it's worth being a little more future-proof here.
And immediately upon sending this message, I went and looked at
another patch and realized that the rename in Patch 1 would be
confusing with 'struct object_database' containing a list of
'struct odb's.
Perhaps in my head I was thinking that each repository has an
"object store" which is an abstraction over possibly multiple
"odb"s which each are interacted with via one "odb backend"
(and there may be multiple potential odb backends in the future,
but only one right now).
If we want to keep the 'object_database' name from patch 1 (or
replace it with 'odb' for brevity) then we might want a different
name for each sub-odb. Perhaps 'odb_shard'? 'odb_slice'? Do any
of these sound better?
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 02/17] object-store: rename `object_directory` to `odb_backend`
2025-05-07 1:00 ` Derrick Stolee
@ 2025-05-09 11:25 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 11:25 UTC (permalink / raw)
To: Derrick Stolee; +Cc: git
On Tue, May 06, 2025 at 09:00:04PM -0400, Derrick Stolee wrote:
> On 5/6/25 8:51 PM, Derrick Stolee wrote:
> > On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
>
> > > Let's preempt this by renaming the structure to `odb_backend` now
> > > already. This name is agnostic of how exactly objects are stored and
> > > allows us to easily introduce e.g. a `files_odb_backend` and other
> > > specific implementations over time.
> >
> > But here's where I'll get a little nitpicky and say that these are
> > "odb"s not "odb_backend"s.
> >
> > * odb: a single object database. A repo can have multiple, currently
> > only one that is read/write and multiple read-only alternates.
> >
> > * odb backend: an _implementation_ of an object database. This would
> > be the structure that containts a vtable of implementation methods.
> > Each individual 'odb' would point to a single backend describing
> > how to access the data in it.
> >
> > Does that make sense? If we are going through the effort of renaming
> > things, I think it's worth being a little more future-proof here.
Yeah, I agree with you that this can be somewhat confusing indeed. The
problem is that we basically have a database of databases, and that
makes it somewhat awkward to name things.
> And immediately upon sending this message, I went and looked at
> another patch and realized that the rename in Patch 1 would be
> confusing with 'struct object_database' containing a list of
> 'struct odb's.
>
> Perhaps in my head I was thinking that each repository has an
> "object store" which is an abstraction over possibly multiple
> "odb"s which each are interacted with via one "odb backend"
> (and there may be multiple potential odb backends in the future,
> but only one right now).
I don't think that "store" buys us much over "database" -- it's
ultimately the same thing, from my perspective. The only reason why I
decided to drop "store" in favor of "database" is that it allows us to
use the `odb_` prefix in many places, which is nice.
> If we want to keep the 'object_database' name from patch 1 (or
> replace it with 'odb' for brevity) then we might want a different
> name for each sub-odb. Perhaps 'odb_shard'? 'odb_slice'? Do any
> of these sound better?
I don't quite like either of them. "shard" is a bit too close to the
shards we have in ".git/objects/[0-9a-f]{2}" and may thus easily cause
confusion. And "slice" feels a bit weird because... I dunno. I have to
think too much about slices in Golang.
How about `odb_alternate`? That's exactly what this is -- an alternate
part of the object database. We already use this term, and it does make
sense even in the future once we have pluggable ODBs. Honestly, now that
I think about it's kind of the obvious choice. Lots of the parts of the
codebase were already called accordingly.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH 03/17] object-store: rename files to "odb.{c,h}"
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
2025-05-06 11:09 ` [PATCH 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
2025-05-06 11:09 ` [PATCH 02/17] object-store: rename `object_directory` to `odb_backend` Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-06 18:06 ` Derrick Stolee
2025-05-06 11:09 ` [PATCH 04/17] odb: introduce parent pointers Patrick Steinhardt
` (20 subsequent siblings)
23 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
In the preceding commits we have renamed the structures contained in
"object-store.h" to `struct object_database` and `struct odb_backend`.
As such, the code files "object-store.{c,h}" are confusingly named now.
Rename them to "odb.{c,h}" accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Makefile | 2 +-
apply.c | 2 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 2 +-
blame.c | 2 +-
builtin/backfill.c | 2 +-
builtin/blame.c | 2 +-
builtin/cat-file.c | 2 +-
builtin/checkout.c | 2 +-
builtin/clone.c | 2 +-
builtin/commit-graph.c | 2 +-
builtin/commit-tree.c | 2 +-
builtin/describe.c | 2 +-
builtin/difftool.c | 2 +-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 2 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 2 +-
builtin/grep.c | 2 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 2 +-
builtin/log.c | 2 +-
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 2 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 2 +-
builtin/mktag.c | 2 +-
builtin/mktree.c | 2 +-
builtin/multi-pack-index.c | 2 +-
builtin/notes.c | 2 +-
builtin/pack-objects.c | 2 +-
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 2 +-
builtin/receive-pack.c | 2 +-
builtin/remote.c | 2 +-
builtin/repack.c | 2 +-
builtin/replace.c | 2 +-
builtin/rev-list.c | 2 +-
builtin/show-ref.c | 2 +-
builtin/submodule--helper.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 2 +-
bulk-checkin.c | 2 +-
bundle-uri.c | 2 +-
bundle.c | 2 +-
cache-tree.c | 2 +-
combine-diff.c | 2 +-
commit-graph.c | 2 +-
commit-graph.h | 2 +-
commit.c | 2 +-
config.c | 2 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 2 +-
diff.c | 2 +-
entry.c | 2 +-
fetch-pack.c | 2 +-
fmt-merge-msg.c | 2 +-
fsck.c | 2 +-
grep.c | 2 +-
http-backend.c | 2 +-
http-push.c | 2 +-
http-walker.c | 2 +-
http.c | 2 +-
list-objects-filter.c | 2 +-
list-objects.c | 2 +-
loose.c | 2 +-
mailmap.c | 2 +-
match-trees.c | 2 +-
merge-blobs.c | 2 +-
merge-ort.c | 2 +-
meson.build | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 2 +-
object-file.c | 2 +-
object-file.h | 2 +-
object-store.c => odb.c | 2 +-
object-store.h => odb.h | 6 +++---
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 2 +-
pack-bitmap.c | 2 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
packfile.c | 2 +-
packfile.h | 4 ++--
path.c | 2 +-
promisor-remote.c | 2 +-
protocol-caps.c | 2 +-
read-cache.c | 2 +-
ref-filter.c | 2 +-
reflog.c | 2 +-
refs.c | 2 +-
remote.c | 2 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 2 +-
rerere.c | 2 +-
revision.c | 2 +-
send-pack.c | 2 +-
sequencer.c | 2 +-
server-info.c | 2 +-
shallow.c | 2 +-
streaming.c | 2 +-
submodule-config.c | 2 +-
submodule.c | 2 +-
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 2 +-
t/helper/test-read-graph.c | 2 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 2 +-
tag.c | 2 +-
tmp-objdir.c | 2 +-
tree-walk.c | 2 +-
tree.c | 2 +-
unpack-trees.c | 2 +-
upload-pack.c | 2 +-
walker.c | 2 +-
xdiff-interface.c | 2 +-
126 files changed, 129 insertions(+), 129 deletions(-)
diff --git a/Makefile b/Makefile
index 8a7f1c76543..d2d65f30907 100644
--- a/Makefile
+++ b/Makefile
@@ -1083,8 +1083,8 @@ LIB_OBJS += notes.o
LIB_OBJS += object-file-convert.o
LIB_OBJS += object-file.o
LIB_OBJS += object-name.o
-LIB_OBJS += object-store.o
LIB_OBJS += object.o
+LIB_OBJS += odb.o
LIB_OBJS += oid-array.o
LIB_OBJS += oidmap.o
LIB_OBJS += oidset.o
diff --git a/apply.c b/apply.c
index 381d2e3652f..879f04df31e 100644
--- a/apply.c
+++ b/apply.c
@@ -14,7 +14,7 @@
#include "abspath.h"
#include "base85.h"
#include "config.h"
-#include "object-store.h"
+#include "odb.h"
#include "delta.h"
#include "diff.h"
#include "dir.h"
diff --git a/archive-tar.c b/archive-tar.c
index 282b48196f9..249164ea77d 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -11,7 +11,7 @@
#include "hex.h"
#include "tar.h"
#include "archive.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "streaming.h"
#include "run-command.h"
diff --git a/archive-zip.c b/archive-zip.c
index 405da6f3d83..df8866d5bae 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -12,7 +12,7 @@
#include "hex.h"
#include "streaming.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "userdiff.h"
#include "write-or-die.h"
diff --git a/archive.c b/archive.c
index 8309ea213e6..7fa2cc2596a 100644
--- a/archive.c
+++ b/archive.c
@@ -14,7 +14,7 @@
#include "pretty.h"
#include "setup.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 86b6109fc4e..e5680db7f65 100644
--- a/attr.c
+++ b/attr.c
@@ -22,7 +22,7 @@
#include "read-cache-ll.h"
#include "refs.h"
#include "revision.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/bisect.c b/bisect.c
index a327468c75b..a7939216d00 100644
--- a/bisect.c
+++ b/bisect.c
@@ -20,7 +20,7 @@
#include "commit-slab.h"
#include "commit-reach.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "dir.h"
diff --git a/blame.c b/blame.c
index 57daa45e899..0ceea080a80 100644
--- a/blame.c
+++ b/blame.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "cache-tree.h"
#include "mergesort.h"
#include "commit.h"
diff --git a/builtin/backfill.c b/builtin/backfill.c
index fa82ad2f6ff..0b49baa39fa 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -13,7 +13,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "promisor-remote.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 944952e30eb..15eda60af90 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -28,7 +28,7 @@
#include "line-log.h"
#include "progress.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "blame.h"
#include "refs.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 3914a2a3f61..2fa5e3f43bd 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -24,7 +24,7 @@
#include "pack-bitmap.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "mailmap.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d185982f3a6..e7dd66173dd 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,7 +20,7 @@
#include "merge-ort-wrappers.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "path.h"
#include "preload-index.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 91b9cd0d164..1eafeefb48d 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -25,7 +25,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "tree-walk.h"
#include "unpack-trees.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index b4cbdbb1f7b..0a184d39720 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -6,7 +6,7 @@
#include "hex.h"
#include "parse-options.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "progress.h"
#include "replace-object.h"
#include "strbuf.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index ad6b2c93209..546069f8682 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -9,7 +9,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "parse-options.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 2d50883b729..96cb68e5e5d 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -19,7 +19,7 @@
#include "setup.h"
#include "strvec.h"
#include "run-command.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects.h"
#include "commit-slab.h"
#include "wildmatch.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index a3b64ce6942..fac613e3bc3 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -30,7 +30,7 @@
#include "strbuf.h"
#include "lockfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "entry.h"
#include "setup.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 37c01d6c6fe..0505f289a94 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "object.h"
#include "tag.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index b2839c5f439..52c792488e1 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -24,7 +24,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "mem-pool.h"
#include "commit-reach.h"
#include "khash.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 0b15121ff7c..851c0a9419e 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "oid-array.h"
#include "commit.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 0c1df302129..895c9ca5381 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "read-cache-ll.h"
#include "replace-object.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 3affe523df1..7b1940be2a1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -26,7 +26,7 @@
#include "submodule-config.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pager.h"
#include "path.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index cd53fa3bde8..9ce0b87c30b 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -11,7 +11,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 147e9b8b479..8ce446064e8 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -21,7 +21,7 @@
#include "packfile.h"
#include "pack-revindex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "path.h"
diff --git a/builtin/log.c b/builtin/log.c
index b450cd3bde8..fe9cc5ebecb 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -15,7 +15,7 @@
#include "hex.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "color.h"
#include "commit.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index be74f0a03b2..821339b07d4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -25,7 +25,7 @@
#include "setup.h"
#include "sparse-index.h"
#include "submodule.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 8aafc30ca48..62b6fd58c16 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -10,7 +10,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "path.h"
#include "quote.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 2b16b10d2ca..9464f275629 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -7,7 +7,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "gettext.h"
#include "setup.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 4aafa73c615..709ae3966a6 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -10,7 +10,7 @@
#include "commit-reach.h"
#include "merge-ort.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "blob.h"
#include "merge-blobs.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 7ac11c46d53..1809b38f937 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -6,7 +6,7 @@
#include "strbuf.h"
#include "replace-object.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "fsck.h"
#include "config.h"
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 4b478034675..016b0e5b224 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -12,7 +12,7 @@
#include "tree.h"
#include "parse-options.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static struct treeent {
unsigned mode;
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 87173307bf3..ca77d71d5a4 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -7,7 +7,7 @@
#include "midx.h"
#include "strbuf.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index a3f433ca4c0..783d4932ca6 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -16,7 +16,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "pretty.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 8b33edc2ff5..99b63cb0980 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -32,7 +32,7 @@
#include "list.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "dir.h"
#include "midx.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 5d1fc781761..3134cb8c689 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -13,7 +13,7 @@
#include "hex.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#define BLKSIZE 512
diff --git a/builtin/prune.c b/builtin/prune.c
index e930caa0c0a..7bbfb14c2be 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -17,7 +17,7 @@
#include "replace-object.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "shallow.h"
static const char * const prune_usage[] = {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index c92e57ba188..cb5fd55a8e4 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -33,7 +33,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "protocol.h"
#include "commit-reach.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 0d6755bcb71..ac5b8d2a1a6 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -14,7 +14,7 @@
#include "rebase.h"
#include "refs.h"
#include "refspec.h"
-#include "object-store.h"
+#include "odb.h"
#include "strvec.h"
#include "commit-reach.h"
#include "progress.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 59214dbdfdf..16782320058 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -17,7 +17,7 @@
#include "midx.h"
#include "packfile.h"
#include "prune-packed.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "shallow.h"
#include "pack.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 48c7c6a2d56..11c7e2d4c0c 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "tag.h"
#include "wildmatch.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index c4cd4ed5c81..ee25d61c802 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -14,7 +14,7 @@
#include "object.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "parse-options.h"
#include "log-tree.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 623a52a45f8..90ec1de78f9 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "refs/refs-internal.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "string-list.h"
#include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 13fb4ecfaac..7f672e4808c 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -28,7 +28,7 @@
#include "diff.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "advice.h"
#include "branch.h"
#include "list-objects-filter-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 4742b27d16e..cf2ea4b4993 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -19,7 +19,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "tag.h"
#include "parse-options.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index e33acfc4ee4..b92fd4710a9 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
static char *create_temp_file(struct object_id *oid)
{
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index e905d5f4e19..7bf395eec84 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -9,7 +9,7 @@
#include "git-zlib.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "delta.h"
#include "pack.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 678e2ecc2c2..55406a539e7 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -17,7 +17,7 @@
#include "tmp-objdir.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static int odb_transaction_nesting;
diff --git a/bundle-uri.c b/bundle-uri.c
index 96d2ba726d9..993ac62c271 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -14,7 +14,7 @@
#include "fetch-pack.h"
#include "remote.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
static struct {
enum bundle_list_heuristic heuristic;
diff --git a/bundle.c b/bundle.c
index dd4c082f8e7..90c8ec4166a 100644
--- a/bundle.c
+++ b/bundle.c
@@ -7,7 +7,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "object.h"
#include "commit.h"
diff --git a/cache-tree.c b/cache-tree.c
index fa3858e2829..9786b32b3a1 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -10,7 +10,7 @@
#include "cache-tree.h"
#include "bulk-checkin.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "read-cache-ll.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/combine-diff.c b/combine-diff.c
index dfae9f7995d..cf23a753407 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -2,7 +2,7 @@
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "convert.h"
#include "diff.h"
diff --git a/commit-graph.c b/commit-graph.c
index 7a85b73cd99..d58d1bf39ed 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -13,7 +13,7 @@
#include "refs.h"
#include "hash-lookup.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "alloc.h"
diff --git a/commit-graph.h b/commit-graph.h
index 437cb48081d..eaec7d13f3a 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -1,7 +1,7 @@
#ifndef COMMIT_GRAPH_H
#define COMMIT_GRAPH_H
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
diff --git a/commit.c b/commit.c
index e915b2b9a12..1d30f8ce15a 100644
--- a/commit.c
+++ b/commit.c
@@ -9,7 +9,7 @@
#include "hex.h"
#include "repository.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "diff.h"
#include "revision.h"
diff --git a/config.c b/config.c
index b18b5617fcd..883dd066827 100644
--- a/config.c
+++ b/config.c
@@ -31,7 +31,7 @@
#include "hashmap.h"
#include "string-list.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "path.h"
#include "utf8.h"
diff --git a/connected.c b/connected.c
index 4415388beba..18c13245d8e 100644
--- a/connected.c
+++ b/connected.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "run-command.h"
#include "sigchain.h"
#include "connected.h"
diff --git a/contrib/coccinelle/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
index 765ad689678..ea7fe1c8db7 100644
--- a/contrib/coccinelle/the_repository.cocci
+++ b/contrib/coccinelle/the_repository.cocci
@@ -77,7 +77,7 @@
|
- diff_setup
+ repo_diff_setup
-// object-store.h
+// odb.h
|
- read_object_file
+ repo_read_object_file
diff --git a/diagnose.c b/diagnose.c
index 3016ad223d2..6ec07761a0f 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -7,7 +7,7 @@
#include "gettext.h"
#include "hex.h"
#include "strvec.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "repository.h"
diff --git a/diff.c b/diff.c
index 63e9ecb30c6..193da8bee68 100644
--- a/diff.c
+++ b/diff.c
@@ -23,7 +23,7 @@
#include "color.h"
#include "run-command.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "userdiff.h"
#include "submodule.h"
#include "hashmap.h"
diff --git a/entry.c b/entry.c
index f36ec5ad242..75d55038d7c 100644
--- a/entry.c
+++ b/entry.c
@@ -1,7 +1,7 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index fa4231fee74..cf157f5d7e5 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -24,7 +24,7 @@
#include "oid-array.h"
#include "oidset.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "connected.h"
#include "fetch-negotiator.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 501b5acdd44..1a8c972adf3 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -6,7 +6,7 @@
#include "environment.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "diff.h"
#include "diff-merges.h"
#include "hex.h"
diff --git a/fsck.c b/fsck.c
index 8dc8472ceb3..e69baab3af7 100644
--- a/fsck.c
+++ b/fsck.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "dir.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "object.h"
diff --git a/grep.c b/grep.c
index f8d535182c3..dc77e6c4631 100644
--- a/grep.c
+++ b/grep.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "grep.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "userdiff.h"
#include "xdiff-interface.h"
diff --git a/http-backend.c b/http-backend.c
index 0c575aa88aa..ad8c4037493 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -18,7 +18,7 @@
#include "url.h"
#include "strvec.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "protocol.h"
#include "date.h"
#include "write-or-die.h"
diff --git a/http-push.c b/http-push.c
index f9e67cabd4b..d1b1bb23711 100644
--- a/http-push.c
+++ b/http-push.c
@@ -20,7 +20,7 @@
#include "url.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#ifdef EXPAT_NEEDS_XMLPARSE_H
diff --git a/http-walker.c b/http-walker.c
index abb44d73067..12767e65a79 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -10,7 +10,7 @@
#include "transport.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct alt_base {
char *base;
diff --git a/http.c b/http.c
index 302738dd29b..a33914dc02d 100644
--- a/http.c
+++ b/http.c
@@ -19,7 +19,7 @@
#include "packfile.h"
#include "string-list.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tempfile.h"
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 7765761b3c6..cb9c16734b1 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -12,7 +12,7 @@
#include "oidmap.h"
#include "oidset.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
/* Remember to update object flag allocation in object.h */
/*
diff --git a/list-objects.c b/list-objects.c
index 597114281f6..c50b9578584 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -14,7 +14,7 @@
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace.h"
#include "environment.h"
diff --git a/loose.c b/loose.c
index fab7f99868d..e52397bb3e5 100644
--- a/loose.c
+++ b/loose.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
#include "repository.h"
#include "wrapper.h"
diff --git a/mailmap.c b/mailmap.c
index 9e2642a043b..b18e74c2110 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -6,7 +6,7 @@
#include "string-list.h"
#include "mailmap.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
char *git_mailmap_file;
diff --git a/match-trees.c b/match-trees.c
index 72922d5d64e..4704f95c340 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -7,7 +7,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
static int score_missing(unsigned mode)
diff --git a/merge-blobs.c b/merge-blobs.c
index 53f36dbc175..ba8a3fdfd82 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -4,7 +4,7 @@
#include "merge-ll.h"
#include "blob.h"
#include "merge-blobs.h"
-#include "object-store.h"
+#include "odb.h"
static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
{
diff --git a/merge-ort.c b/merge-ort.c
index 77310a4a52c..f86c84635f0 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -39,7 +39,7 @@
#include "mem-pool.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/meson.build b/meson.build
index 270ce933d0f..a3c917b1345 100644
--- a/meson.build
+++ b/meson.build
@@ -394,8 +394,8 @@ libgit_sources = [
'object-file-convert.c',
'object-file.c',
'object-name.c',
- 'object-store.c',
'object.c',
+ 'odb.c',
'oid-array.c',
'oidmap.c',
'oidset.c',
diff --git a/notes-cache.c b/notes-cache.c
index 150241b15e0..344f67762b8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "notes-cache.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "repository.h"
#include "commit.h"
diff --git a/notes-merge.c b/notes-merge.c
index dae8e6a281a..de6a52e2e7f 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -8,7 +8,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "diff.h"
diff --git a/notes.c b/notes.c
index 0a128f1de98..fc000e501d2 100644
--- a/notes.c
+++ b/notes.c
@@ -8,7 +8,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "strbuf.h"
#include "tree-walk.h"
diff --git a/object-file.c b/object-file.c
index 4940103ac6d..cc81729ae25 100644
--- a/object-file.c
+++ b/object-file.c
@@ -21,7 +21,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidtree.h"
#include "pack.h"
#include "packfile.h"
diff --git a/object-file.h b/object-file.h
index 630a8ef1cbd..aff33f61bb4 100644
--- a/object-file.h
+++ b/object-file.h
@@ -3,7 +3,7 @@
#include "git-zlib.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
struct index_state;
diff --git a/object-store.c b/odb.c
similarity index 99%
rename from object-store.c
rename to odb.c
index 1c57c7b1a32..435f532a9c4 100644
--- a/object-store.c
+++ b/odb.c
@@ -13,7 +13,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/object-store.h b/odb.h
similarity index 99%
rename from object-store.h
rename to odb.h
index 94b678eb63c..5774e1d615b 100644
--- a/object-store.h
+++ b/odb.h
@@ -1,5 +1,5 @@
-#ifndef OBJECT_STORE_H
-#define OBJECT_STORE_H
+#ifndef ODB_H
+#define ODB_H
#include "hashmap.h"
#include "object.h"
@@ -343,4 +343,4 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
-#endif /* OBJECT_STORE_H */
+#endif /* ODB_H */
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 609a343ee3e..d2a92f34d98 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 7f400ee0121..37648b57125 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -4,7 +4,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index b9f1d866046..467a3e91035 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "repository.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects-filter-options.h"
#include "midx.h"
#include "config.h"
diff --git a/pack-check.c b/pack-check.c
index 874897d6cba..67cb2cf72f2 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -8,7 +8,7 @@
#include "progress.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct idx_entry {
off_t offset;
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 20900ca88d3..8e1f2dec0ef 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-mtimes.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
diff --git a/pack-objects.h b/pack-objects.h
index 475a2d67ce3..1ac8644201b 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -1,7 +1,7 @@
#ifndef PACK_OBJECTS_H
#define PACK_OBJECTS_H
-#include "object-store.h"
+#include "odb.h"
#include "thread-utils.h"
#include "pack.h"
#include "packfile.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index ffcde48870d..0cc422a1e67 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-revindex.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
#include "trace2.h"
diff --git a/packfile.c b/packfile.c
index 69096849654..0f3d60721a9 100644
--- a/packfile.c
+++ b/packfile.c
@@ -19,7 +19,7 @@
#include "tree-walk.h"
#include "tree.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "midx.h"
#include "commit-graph.h"
#include "pack-revindex.h"
diff --git a/packfile.h b/packfile.h
index 826eb7f475f..53c3b7d3b43 100644
--- a/packfile.h
+++ b/packfile.h
@@ -3,10 +3,10 @@
#include "list.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
-/* in object-store.h */
+/* in odb.h */
struct object_info;
struct packed_git {
diff --git a/path.c b/path.c
index 04a9ef5a1b1..8b4d7d8aba2 100644
--- a/path.c
+++ b/path.c
@@ -15,7 +15,7 @@
#include "submodule-config.h"
#include "path.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "lockfile.h"
#include "exec-cmd.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 9d058586dfa..2baa286bfd0 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "config.h"
#include "trace2.h"
diff --git a/protocol-caps.c b/protocol-caps.c
index 9b8db37a210..3022f69a1bd 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -6,7 +6,7 @@
#include "hash.h"
#include "hex.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "string-list.h"
#include "strbuf.h"
diff --git a/read-cache.c b/read-cache.c
index 73f83a7e7a1..dce1056ec7c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -20,7 +20,7 @@
#include "refs.h"
#include "dir.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "tree.h"
#include "commit.h"
diff --git a/ref-filter.c b/ref-filter.c
index 7a274633cfc..4ce45440ad1 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "wildmatch.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "repo-settings.h"
#include "repository.h"
diff --git a/reflog.c b/reflog.c
index 15d81ebea97..4f8a3b717cd 100644
--- a/reflog.c
+++ b/reflog.c
@@ -5,7 +5,7 @@
#include "config.h"
#include "gettext.h"
#include "parse-options.h"
-#include "object-store.h"
+#include "odb.h"
#include "reflog.h"
#include "refs.h"
#include "revision.h"
diff --git a/refs.c b/refs.c
index ff2d5d6e92b..d91063bab09 100644
--- a/refs.c
+++ b/refs.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "hook.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "path.h"
#include "submodule.h"
diff --git a/remote.c b/remote.c
index 4099183cacd..17a842f5684 100644
--- a/remote.c
+++ b/remote.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "commit.h"
#include "diff.h"
diff --git a/replace-object.c b/replace-object.c
index 7b8a09b5cb4..65b3c108629 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -2,7 +2,7 @@
#include "gettext.h"
#include "hex.h"
#include "oidmap.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "refs.h"
#include "repository.h"
diff --git a/replace-object.h b/replace-object.h
index ba478eb30c4..b1b059ed2fe 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -3,7 +3,7 @@
#include "oidmap.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
struct replace_object {
struct oidmap_entry original;
diff --git a/repository.c b/repository.c
index 0ab73846de3..bcf31ad8e42 100644
--- a/repository.c
+++ b/repository.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "object.h"
#include "lockfile.h"
diff --git a/rerere.c b/rerere.c
index 3cd37c5f0ae..951e4bf8b41 100644
--- a/rerere.c
+++ b/rerere.c
@@ -18,7 +18,7 @@
#include "path.h"
#include "pathspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "strmap.h"
#define RESOLVED 0
diff --git a/revision.c b/revision.c
index 2c36a9c179e..cdefe7d6e48 100644
--- a/revision.c
+++ b/revision.c
@@ -8,7 +8,7 @@
#include "hex.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "tag.h"
#include "blob.h"
diff --git a/send-pack.c b/send-pack.c
index 86592ce526d..abca2dd38a7 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pkt-line.h"
#include "sideband.h"
#include "run-command.h"
diff --git a/sequencer.c b/sequencer.c
index b5c4043757e..35f4e68d59f 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -13,7 +13,7 @@
#include "dir.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "pager.h"
#include "commit.h"
diff --git a/server-info.c b/server-info.c
index d6cd20a39d7..9bb30d9ab71 100644
--- a/server-info.c
+++ b/server-info.c
@@ -11,7 +11,7 @@
#include "packfile.h"
#include "path.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "server-info.h"
#include "strbuf.h"
#include "tempfile.h"
diff --git a/shallow.c b/shallow.c
index faeeeb45f98..d379756e39a 100644
--- a/shallow.c
+++ b/shallow.c
@@ -5,7 +5,7 @@
#include "repository.h"
#include "tempfile.h"
#include "lockfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tag.h"
#include "pkt-line.h"
diff --git a/streaming.c b/streaming.c
index 127d6b5d6ac..29cc877f22a 100644
--- a/streaming.c
+++ b/streaming.c
@@ -10,7 +10,7 @@
#include "streaming.h"
#include "repository.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "packfile.h"
diff --git a/submodule-config.c b/submodule-config.c
index c9418f51265..4abef906f26 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -13,7 +13,7 @@
#include "submodule.h"
#include "strbuf.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/submodule.c b/submodule.c
index ead3fb5dadc..9b1018877df 100644
--- a/submodule.c
+++ b/submodule.c
@@ -27,7 +27,7 @@
#include "parse-options.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index 76c2f4eba85..611a13a3261 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -2,7 +2,7 @@
#include "test-tool.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "setup.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index fdf1b13437b..d51aaa3dc40 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pack-mtimes.h"
#include "setup.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 34f1aee5581..dba227259a2 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "hex.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
/*
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 45b0043eb93..8a6af828153 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "bloom.h"
#include "setup.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index ac81390899a..da2aa036b57 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "midx.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "packfile.h"
#include "setup.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 4cfc7c90b59..2920ca59d72 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -5,7 +5,7 @@
#include "refs.h"
#include "setup.h"
#include "worktree.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "strbuf.h"
diff --git a/tag.c b/tag.c
index 05be39067cf..5f6868bf7b1 100644
--- a/tag.c
+++ b/tag.c
@@ -5,7 +5,7 @@
#include "environment.h"
#include "tag.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "blob.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index cc4efb3d816..f9e8277fd7c 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -10,7 +10,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "quote.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
struct tmp_objdir {
diff --git a/tree-walk.c b/tree-walk.c
index 90655d52378..34b0fff4873 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -6,7 +6,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace2.h"
#include "tree.h"
#include "pathspec.h"
diff --git a/tree.c b/tree.c
index b85f56267fb..341b7c2ff3f 100644
--- a/tree.c
+++ b/tree.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "tree.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "alloc.h"
#include "tree-walk.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 471837f0329..f38c761ab98 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -26,7 +26,7 @@
#include "symlinks.h"
#include "trace2.h"
#include "fsmonitor.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "entry.h"
#include "parallel-checkout.h"
diff --git a/upload-pack.c b/upload-pack.c
index 956da5b061a..cec12cb478a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -10,7 +10,7 @@
#include "pkt-line.h"
#include "sideband.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "object.h"
#include "commit.h"
diff --git a/walker.c b/walker.c
index b470d43e54d..a8abe8a2e78 100644
--- a/walker.c
+++ b/walker.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "walker.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "strbuf.h"
#include "tree.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 1edcd319e6e..01e6e378ea6 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "config.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "xdiff-interface.h"
#include "xdiff/xtypes.h"
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 03/17] object-store: rename files to "odb.{c,h}"
2025-05-06 11:09 ` [PATCH 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
@ 2025-05-06 18:06 ` Derrick Stolee
0 siblings, 0 replies; 166+ messages in thread
From: Derrick Stolee @ 2025-05-06 18:06 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/2025 7:09 AM, Patrick Steinhardt wrote:
> In the preceding commits we have renamed the structures contained in
> "object-store.h" to `struct object_database` and `struct odb_backend`.
> As such, the code files "object-store.{c,h}" are confusingly named now.
> Rename them to "odb.{c,h}" accordingly.
While I appreciate the goal of this series, I'm not sold on the need to
rename these files. Not only is it a tree-wide change to the headers, but
it now requires tracking changes across the rename which can complicate
history spelunking.
At minimum, the method renames are likely to create semantic merge issues
with parallel work. If the rename is truly valuable, then maybe it could
be done in an isolated change after the method renames are landed?
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH 04/17] odb: introduce parent pointers
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (2 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-06 11:09 ` [PATCH 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
` (19 subsequent siblings)
23 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
In subsequent commits we'll get rid of our use of `the_repository` in
"odb.c" in favor of explicitly passing in a `struct object_database` or
a `struct odb_backend`. In some cases though we'll need access to the
repository, for example to read a config value from it, but we don't
have a way to access the repository owning a specific object database.
Introduce parent pointers for `struct object_database` to its owning
repository as well as for `struct odb_backend` to its owning object
database, which will allow us to adapt those use cases.
Note that this change requires us to pass through the object database to
`link_alt_odb_entry()` so that we can set up the parent pointers for any
alternative backends there. The callchain is adapted to pass through the
object database accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 43 +++++++++++++++++++++++++------------------
odb.h | 6 ++++++
2 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/odb.c b/odb.c
index 435f532a9c4..67207ce636d 100644
--- a/odb.c
+++ b/odb.c
@@ -135,11 +135,15 @@ static int alt_odb_usable(struct object_database *o,
* of the object ID, an extra slash for the first level indirection, and
* the terminating NUL.
*/
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth);
-static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
- const char *relative_base, int depth, const char *normalized_objdir)
+
+static int link_alt_odb_entry(struct object_database *odb,
+ const struct strbuf *entry,
+ const char *relative_base,
+ int depth,
+ const char *normalized_objdir)
{
struct odb_backend *backend;
struct strbuf pathbuf = STRBUF_INIT;
@@ -167,22 +171,23 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
strbuf_setlen(&pathbuf, pathbuf.len - 1);
- if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
+ if (!alt_odb_usable(odb, &pathbuf, normalized_objdir, &pos))
goto error;
CALLOC_ARRAY(backend, 1);
+ backend->odb = odb;
/* pathbuf.buf is already in r->objects->backend_by_path */
backend->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->backends_tail = backend;
- r->objects->backends_tail = &(backend->next);
+ *odb->backends_tail = backend;
+ odb->backends_tail = &(backend->next);
backend->next = NULL;
- assert(r->objects->backend_by_path);
- kh_value(r->objects->backend_by_path, pos) = backend;
+ assert(odb->backend_by_path);
+ kh_value(odb->backend_by_path, pos) = backend;
/* recursively add alternates */
- read_info_alternates(r, backend->path, depth + 1);
+ read_info_alternates(odb, backend->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -219,7 +224,7 @@ static const char *parse_alt_odb_entry(const char *string,
return end;
}
-static void link_alt_odb_entries(struct repository *r, const char *alt,
+static void link_alt_odb_entries(struct object_database *odb, const char *alt,
int sep, const char *relative_base, int depth)
{
struct strbuf objdirbuf = STRBUF_INIT;
@@ -234,20 +239,20 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->backends->path, 1);
+ strbuf_realpath(&objdirbuf, odb->backends->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
if (!entry.len)
continue;
- link_alt_odb_entry(r, &entry,
+ link_alt_odb_entry(odb, &entry,
relative_base, depth, objdirbuf.buf);
}
strbuf_release(&entry);
strbuf_release(&objdirbuf);
}
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth)
{
@@ -261,7 +266,7 @@ static void read_info_alternates(struct repository *r,
return;
}
- link_alt_odb_entries(r, buf.buf, '\n', relative_base, depth);
+ link_alt_odb_entries(odb, buf.buf, '\n', relative_base, depth);
strbuf_release(&buf);
free(path);
}
@@ -303,7 +308,7 @@ void add_to_alternates_file(const char *reference)
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
free(alts);
@@ -317,7 +322,7 @@ void add_to_alternates_memory(const char *reference)
*/
prepare_alt_odb(the_repository);
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
@@ -336,6 +341,7 @@ struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy)
* alternate
*/
backend = xcalloc(1, sizeof(*backend));
+ backend->odb = the_repository->objects;
backend->path = xstrdup(dir);
/*
@@ -580,9 +586,9 @@ void prepare_alt_odb(struct repository *r)
if (r->objects->loaded_alternates)
return;
- link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->backends->path, 0);
+ read_info_alternates(r->objects, r->objects->backends->path, 0);
r->objects->loaded_alternates = 1;
}
@@ -964,6 +970,7 @@ struct object_database *odb_new(struct repository *repo)
struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
+ o->repo = repo;
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
diff --git a/odb.h b/odb.h
index 5774e1d615b..1617a9bac2c 100644
--- a/odb.h
+++ b/odb.h
@@ -16,6 +16,9 @@ struct repository;
struct odb_backend {
struct odb_backend *next;
+ /* Object database that owns this backend. */
+ struct object_database *odb;
+
/*
* Used to store the results of readdir(3) calls when we are OK
* sacrificing accuracy due to races for speed. That includes
@@ -93,6 +96,9 @@ struct cached_object_entry;
* configured via alternates.
*/
struct object_database {
+ /* Repository that owns this database. */
+ struct repository *repo;
+
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH 05/17] odb: get rid of `the_repository` in `find_odb()`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (3 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 04/17] odb: introduce parent pointers Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-07 1:10 ` Derrick Stolee
2025-05-06 11:09 ` [PATCH 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
` (18 subsequent siblings)
23 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
Get rid of our dependency on `the_repository` in `find_odb()` by passing
in the object database in which we want to search for the backend and
adjusting all callers.
Rename the function to `odb_find_backend()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 18 +++++++++---------
midx-write.c | 2 +-
odb.c | 14 +++++++-------
odb.h | 7 ++++++-
4 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 0a184d39720..28550d3bcc9 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
struct commit_graph *graph = NULL;
- struct odb_backend *odb = NULL;
+ struct odb_backend *backend = NULL;
char *graph_name;
char *chain_name;
enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE;
@@ -101,9 +101,9 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- odb = find_odb(the_repository, opts.obj_dir);
- graph_name = get_commit_graph_filename(odb);
- chain_name = get_commit_graph_chain_filename(odb);
+ backend = odb_find_backend(the_repository->objects, opts.obj_dir);
+ graph_name = get_commit_graph_filename(backend);
+ chain_name = get_commit_graph_chain_filename(backend);
if (open_commit_graph(graph_name, &fd, &st))
opened = OPENED_GRAPH;
else if (errno != ENOENT)
@@ -120,7 +120,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opened == OPENED_NONE)
return 0;
else if (opened == OPENED_GRAPH)
- graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb);
+ graph = load_commit_graph_one_fd_st(the_repository, fd, &st, backend);
else
graph = load_commit_graph_chain_fd_st(the_repository, fd, &st,
&incomplete_chain);
@@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
struct string_list pack_indexes = STRING_LIST_INIT_DUP;
struct strbuf buf = STRBUF_INIT;
struct oidset commits = OIDSET_INIT;
- struct odb_backend *odb = NULL;
+ struct odb_backend *backend = NULL;
int result = 0;
enum commit_graph_write_flags flags = 0;
struct progress *progress = NULL;
@@ -289,10 +289,10 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- odb = find_odb(the_repository, opts.obj_dir);
+ backend = odb_find_backend(the_repository->objects, opts.obj_dir);
if (opts.reachable) {
- if (write_commit_graph_reachable(odb, flags, &write_opts))
+ if (write_commit_graph_reachable(backend, flags, &write_opts))
result = 1;
goto cleanup;
}
@@ -318,7 +318,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
stop_progress(&progress);
}
- if (write_commit_graph(odb,
+ if (write_commit_graph(backend,
opts.stdin_packs ? &pack_indexes : NULL,
opts.stdin_commits ? &commits : NULL,
flags,
diff --git a/midx-write.c b/midx-write.c
index dd3b3070e55..e8371a84a14 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -922,7 +922,7 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
struct strbuf cur_path_real = STRBUF_INIT;
/* Ensure the given object_dir is local, or a known alternate. */
- find_odb(r, obj_dir_real);
+ odb_find_backend(r->objects, obj_dir_real);
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
strbuf_realpath(&cur_path_real, cur->object_dir, 1);
diff --git a/odb.c b/odb.c
index 67207ce636d..6359c541d78 100644
--- a/odb.c
+++ b/odb.c
@@ -448,15 +448,15 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct odb_backend *find_odb(struct repository *r, const char *obj_dir)
+struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir)
{
- struct odb_backend *odb;
+ struct odb_backend *backend;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(r);
- for (odb = r->objects->backends; odb; odb = odb->next) {
- strbuf_realpath(&odb_path_real, odb->path, 1);
+ prepare_alt_odb(odb->repo);
+ for (backend = odb->backends; backend; backend = backend->next) {
+ strbuf_realpath(&odb_path_real, backend->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
}
@@ -464,9 +464,9 @@ struct odb_backend *find_odb(struct repository *r, const char *obj_dir)
free(obj_dir_real);
strbuf_release(&odb_path_real);
- if (!odb)
+ if (!backend)
die(_("could not find object directory matching %s"), obj_dir);
- return odb;
+ return backend;
}
static void fill_alternate_refs_command(struct child_process *cmd,
diff --git a/odb.h b/odb.h
index 1617a9bac2c..a8c0f788969 100644
--- a/odb.h
+++ b/odb.h
@@ -56,7 +56,6 @@ struct odb_backend {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct odb_backend *find_odb(struct repository *r, const char *obj_dir);
typedef int alt_odb_fn(struct odb_backend *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
@@ -183,6 +182,12 @@ struct object_database {
struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
+/*
+ * Find backend by its object directory path. Dies in case the object directory
+ * couldn't be found.
+ */
+struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir);
+
/*
* Create a temporary file rooted in the object database directory, or
* die on failure. The filename is taken from "pattern", which should have the
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 05/17] odb: get rid of `the_repository` in `find_odb()`
2025-05-06 11:09 ` [PATCH 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
@ 2025-05-07 1:10 ` Derrick Stolee
2025-05-09 11:25 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 1:10 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
> index 0a184d39720..28550d3bcc9 100644
> --- a/builtin/commit-graph.c
> +++ b/builtin/commit-graph.c
> @@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
> struct repository *repo UNUSED)
> {
> struct commit_graph *graph = NULL;
> - struct odb_backend *odb = NULL;
> + struct odb_backend *backend = NULL;
nit: this looks like a misplaced variable rename that should be in
an earlier patch.
> @@ -101,9 +101,9 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
> if (opts.progress)
> flags |= COMMIT_GRAPH_WRITE_PROGRESS;
>
> - odb = find_odb(the_repository, opts.obj_dir);
> - graph_name = get_commit_graph_filename(odb);
> - chain_name = get_commit_graph_chain_filename(odb);
> + backend = odb_find_backend(the_repository->objects, opts.obj_dir);
> + graph_name = get_commit_graph_filename(backend);
> + chain_name = get_commit_graph_chain_filename(backend);
I like how your use of specific backends here cleaans up a lot of
garbage around the --object-dir parameter of the commit-graph
builtin.
This is a real structural improvement that is made possible by
this refactoring.
> @@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
> struct string_list pack_indexes = STRING_LIST_INIT_DUP;
> struct strbuf buf = STRBUF_INIT;
> struct oidset commits = OIDSET_INIT;
> - struct odb_backend *odb = NULL;
> + struct odb_backend *backend = NULL;
Here's another of those delayed renames.
> -struct odb_backend *find_odb(struct repository *r, const char *obj_dir)
> +struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir)
I was looking at this implementation and wondering why it wasn't
renamed earlier, but upon closer inspection I agree that the
rename is worthwhile _and_ the method shouldn't have been
changed until now.
> {
> - struct odb_backend *odb;
> + struct odb_backend *backend;
> char *obj_dir_real = real_pathdup(obj_dir, 1);
> struct strbuf odb_path_real = STRBUF_INIT;
>
> - prepare_alt_odb(r);
> - for (odb = r->objects->backends; odb; odb = odb->next) {
> - strbuf_realpath(&odb_path_real, odb->path, 1);
> + prepare_alt_odb(odb->repo);
This does make me wonder if we should be able to prepare the
alternates for a given odb without using an owning repo. Yes,
we'd need to assign the repo parent when creating new odbs, but
the info/alternates file is in the object dir.
Perhaps this is waiting for me in a later patch...
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 05/17] odb: get rid of `the_repository` in `find_odb()`
2025-05-07 1:10 ` Derrick Stolee
@ 2025-05-09 11:25 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 11:25 UTC (permalink / raw)
To: Derrick Stolee; +Cc: git
On Tue, May 06, 2025 at 09:10:06PM -0400, Derrick Stolee wrote:
> On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
>
> > diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
> > index 0a184d39720..28550d3bcc9 100644
> > --- a/builtin/commit-graph.c
> > +++ b/builtin/commit-graph.c
> > @@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
> > struct repository *repo UNUSED)
> > {
> > struct commit_graph *graph = NULL;
> > - struct odb_backend *odb = NULL;
> > + struct odb_backend *backend = NULL;
>
> nit: this looks like a misplaced variable rename that should be in
> an earlier patch.
Fixed.
> > @@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
> > struct string_list pack_indexes = STRING_LIST_INIT_DUP;
> > struct strbuf buf = STRBUF_INIT;
> > struct oidset commits = OIDSET_INIT;
> > - struct odb_backend *odb = NULL;
> > + struct odb_backend *backend = NULL;
>
> Here's another of those delayed renames.
Fixed.
> > -struct odb_backend *find_odb(struct repository *r, const char *obj_dir)
> > +struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir)
>
> I was looking at this implementation and wondering why it wasn't
> renamed earlier, but upon closer inspection I agree that the
> rename is worthwhile _and_ the method shouldn't have been
> changed until now.
>
> > {
> > - struct odb_backend *odb;
> > + struct odb_backend *backend;
> > char *obj_dir_real = real_pathdup(obj_dir, 1);
> > struct strbuf odb_path_real = STRBUF_INIT;
> > - prepare_alt_odb(r);
> > - for (odb = r->objects->backends; odb; odb = odb->next) {
> > - strbuf_realpath(&odb_path_real, odb->path, 1);
> > + prepare_alt_odb(odb->repo);
> This does make me wonder if we should be able to prepare the
> alternates for a given odb without using an owning repo. Yes,
> we'd need to assign the repo parent when creating new odbs, but
> the info/alternates file is in the object dir.
>
> Perhaps this is waiting for me in a later patch...
Things are still somewhat mixed at the end of this patch series, but we
do reduce the dependency over time. Eventually, the goal is that we only
need a repository to read its configuration, which may even happen once
and then never again for the object database so that we can stop
tracking the parent repository.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH 06/17] odb: get rid of `the_repository` in `assert_oid_type()`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (4 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-06 11:09 ` [PATCH 07/17] " Patrick Steinhardt
` (17 subsequent siblings)
23 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
Get rid of our dependency on `the_repository` in `assert_oid_type()` by
passing in the object database as a parameter and adjusting all callers.
Rename the function to `odb_assert_oid_type()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-tree.c | 2 +-
commit.c | 2 +-
odb.c | 5 +++--
odb.h | 3 ++-
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 546069f8682..31cfd9bd15d 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -48,7 +48,7 @@ static int parse_parent_arg_callback(const struct option *opt,
if (repo_get_oid_commit(the_repository, arg, &oid))
die(_("not a valid object name %s"), arg);
- assert_oid_type(&oid, OBJ_COMMIT);
+ odb_assert_oid_type(the_repository->objects, &oid, OBJ_COMMIT);
new_parent(lookup_commit(the_repository, &oid), parents);
return 0;
}
diff --git a/commit.c b/commit.c
index 1d30f8ce15a..aa65183d8b6 100644
--- a/commit.c
+++ b/commit.c
@@ -1706,7 +1706,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
/* Not having i18n.commitencoding is the same as having utf-8 */
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
- assert_oid_type(tree, OBJ_TREE);
+ odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);
if (memchr(msg, '\0', msg_len))
return error("a NUL byte in commit log message not allowed.");
diff --git a/odb.c b/odb.c
index 6359c541d78..b4265da2993 100644
--- a/odb.c
+++ b/odb.c
@@ -955,9 +955,10 @@ int has_object(struct repository *r, const struct object_id *oid,
return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
}
-void assert_oid_type(const struct object_id *oid, enum object_type expect)
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = oid_object_info(odb->repo, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index a8c0f788969..7e634db16f2 100644
--- a/odb.h
+++ b/odb.h
@@ -293,7 +293,8 @@ enum {
int has_object(struct repository *r, const struct object_id *oid,
unsigned flags);
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect);
/*
* Enabling the object read lock allows multiple threads to safely call the
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH 07/17] odb: get rid of `the_repository` in `assert_oid_type()`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (5 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-07 1:12 ` Derrick Stolee
2025-05-06 11:09 ` [PATCH 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
` (16 subsequent siblings)
23 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
Get rid of our dependency on `the_repository` in `assert_oid_type()` by
passing in the object database as a parameter and adjusting all callers.
Rename the function to `odb_assert_oid_type()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 3 ++-
builtin/index-pack.c | 2 +-
bundle-uri.c | 3 ++-
odb.c | 9 +++++----
odb.h | 11 ++++++-----
pack-bitmap-write.c | 3 ++-
pack-write.c | 10 ++++++----
7 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 52c792488e1..413304db9b5 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -763,7 +763,8 @@ static void start_packfile(void)
struct packed_git *p;
int pack_fd;
- pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX");
+ pack_fd = odb_mkstemp(the_repository->objects, &tmp_file,
+ "pack/tmp_pack_XXXXXX");
FLEX_ALLOC_STR(p, pack_name, tmp_file.buf);
strbuf_release(&tmp_file);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 8ce446064e8..8e5acefde40 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -362,7 +362,7 @@ static const char *open_pack_file(const char *pack_name)
input_fd = 0;
if (!pack_name) {
struct strbuf tmp_file = STRBUF_INIT;
- output_fd = odb_mkstemp(&tmp_file,
+ output_fd = odb_mkstemp(the_repository->objects, &tmp_file,
"pack/tmp_pack_XXXXXX");
pack_name = strbuf_detach(&tmp_file, NULL);
} else {
diff --git a/bundle-uri.c b/bundle-uri.c
index 993ac62c271..87a5ba50945 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -278,7 +278,8 @@ static char *find_temp_filename(void)
* Find a temporary filename that is available. This is briefly
* racy, but unlikely to collide.
*/
- fd = odb_mkstemp(&name, "bundles/tmp_uri_XXXXXX");
+ fd = odb_mkstemp(the_repository->objects, &name,
+ "bundles/tmp_uri_XXXXXX");
if (fd < 0) {
warning(_("failed to create temporary file"));
return NULL;
diff --git a/odb.c b/odb.c
index b4265da2993..9bd87204737 100644
--- a/odb.c
+++ b/odb.c
@@ -63,7 +63,8 @@ static const struct cached_object *find_cached_object(struct object_database *ob
return NULL;
}
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern)
{
int fd;
/*
@@ -71,15 +72,15 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
* restrictive except to remove write permission.
*/
int mode = 0444;
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
fd = git_mkstemp_mode(temp_filename->buf, mode);
if (0 <= fd)
return fd;
/* slow path */
/* some mkstemp implementations erase temp_filename on failure */
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
- safe_create_leading_directories(the_repository, temp_filename->buf);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
+ safe_create_leading_directories(odb->repo, temp_filename->buf);
return xmkstemp_mode(temp_filename->buf, mode);
}
diff --git a/odb.h b/odb.h
index 7e634db16f2..62967da6cf6 100644
--- a/odb.h
+++ b/odb.h
@@ -189,12 +189,13 @@ void odb_clear(struct object_database *o);
struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir);
/*
- * Create a temporary file rooted in the object database directory, or
- * die on failure. The filename is taken from "pattern", which should have the
- * usual "XXXXXX" trailer, and the resulting filename is written into the
- * "template" buffer. Returns the open descriptor.
+ * Create a temporary file rooted in the primary object database backend's
+ * directory, or die on failure. The filename is taken from "pattern", which
+ * should have the usual "XXXXXX" trailer, and the resulting filename is
+ * written into the "template" buffer. Returns the open descriptor.
*/
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern);
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 37648b57125..c847369eaaa 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1052,7 +1052,8 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
struct bitmap_disk_header header;
- int fd = odb_mkstemp(&tmp_file, "pack/tmp_bitmap_XXXXXX");
+ int fd = odb_mkstemp(writer->repo->objects, &tmp_file,
+ "pack/tmp_bitmap_XXXXXX");
if (writer->pseudo_merges_nr)
options |= BITMAP_OPT_PSEUDO_MERGES;
diff --git a/pack-write.c b/pack-write.c
index 6b06315f80a..eccdc798e36 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -84,7 +84,8 @@ const char *write_idx_file(struct repository *repo,
} else {
if (!index_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_idx_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_idx_XXXXXX");
index_name = strbuf_detach(&tmp_file, NULL);
} else {
unlink(index_name);
@@ -259,7 +260,8 @@ char *write_rev_file_order(struct repository *repo,
if (flags & WRITE_REV) {
if (!rev_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_rev_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_rev_XXXXXX");
path = strbuf_detach(&tmp_file, NULL);
} else {
unlink(rev_name);
@@ -342,7 +344,7 @@ static char *write_mtimes_file(struct repository *repo,
if (!to_pack)
BUG("cannot call write_mtimes_file with NULL packing_data");
- fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file, "pack/tmp_mtimes_XXXXXX");
mtimes_name = strbuf_detach(&tmp_file, NULL);
f = hashfd(repo->hash_algo, fd, mtimes_name);
@@ -531,7 +533,7 @@ struct hashfile *create_tmp_packfile(struct repository *repo,
struct strbuf tmpname = STRBUF_INIT;
int fd;
- fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmpname, "pack/tmp_pack_XXXXXX");
*pack_tmp_name = strbuf_detach(&tmpname, NULL);
return hashfd(repo->hash_algo, fd, *pack_tmp_name);
}
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 07/17] odb: get rid of `the_repository` in `assert_oid_type()`
2025-05-06 11:09 ` [PATCH 07/17] " Patrick Steinhardt
@ 2025-05-07 1:12 ` Derrick Stolee
2025-05-09 11:25 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 1:12 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> Get rid of our dependency on `the_repository` in `assert_oid_type()` by
> passing in the object database as a parameter and adjusting all callers.
Oops! This patch has the same message as patch 6 but is actually a
different change, removing the_repository from odb_mkstemp():
> - pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX");
> + pack_fd = odb_mkstemp(the_repository->objects, &tmp_file,
> + "pack/tmp_pack_XXXXXX");
...
> /*
> - * Create a temporary file rooted in the object database directory, or
> - * die on failure. The filename is taken from "pattern", which should have the
> - * usual "XXXXXX" trailer, and the resulting filename is written into the
> - * "template" buffer. Returns the open descriptor.
> + * Create a temporary file rooted in the primary object database backend's
> + * directory, or die on failure. The filename is taken from "pattern", which
> + * should have the usual "XXXXXX" trailer, and the resulting filename is
> + * written into the "template" buffer. Returns the open descriptor.
> */
> -int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
> +int odb_mkstemp(struct object_database *odb,
> + struct strbuf *temp_filename, const char *pattern);
I'm happy with the code change, though.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 07/17] odb: get rid of `the_repository` in `assert_oid_type()`
2025-05-07 1:12 ` Derrick Stolee
@ 2025-05-09 11:25 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 11:25 UTC (permalink / raw)
To: Derrick Stolee; +Cc: git
On Tue, May 06, 2025 at 09:12:34PM -0400, Derrick Stolee wrote:
> On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> > Get rid of our dependency on `the_repository` in `assert_oid_type()` by
> > passing in the object database as a parameter and adjusting all callers.
>
> Oops! This patch has the same message as patch 6 but is actually a
> different change, removing the_repository from odb_mkstemp():
Good catch. Repetetive changes invite copy & paste invite errors.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH 08/17] odb: get rid of `the_repository` when handling alternates
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (6 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 07/17] " Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-07 1:14 ` Derrick Stolee
2025-05-06 11:09 ` [PATCH 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
` (15 subsequent siblings)
23 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
The functions to manage alternates all depend on `the_repository`.
Refactor them to accept an object database as parameter and adjusting
all callers. The functions are renamed accordingly.
Note that right now the situation is still somewhat weird because we end
up using the path provided by the object store's repository anyway. This
will be adapted over time though so that we instead store the path to
the primary object directory in the object database itself.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/clone.c | 10 +++++----
builtin/fsck.c | 6 +++---
builtin/grep.c | 2 +-
builtin/repack.c | 3 ++-
commit-graph.c | 4 ++--
loose.c | 2 +-
object-file.c | 10 ++++-----
object-name.c | 2 +-
odb.c | 44 ++++++++++++++++++---------------------
odb.h | 53 ++++++++++++++++++++++++++++++++---------------
packfile.c | 4 ++--
submodule.c | 3 ++-
t/helper/test-ref-store.c | 2 +-
tmp-objdir.c | 2 +-
14 files changed, 83 insertions(+), 64 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 1eafeefb48d..3aabdf6570b 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -171,7 +171,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
} else {
struct strbuf sb = STRBUF_INIT;
strbuf_addf(&sb, "%s/objects", ref_git);
- add_to_alternates_file(sb.buf);
+ odb_add_to_alternates_file(the_repository->objects, sb.buf);
strbuf_release(&sb);
}
@@ -212,12 +212,14 @@ static void copy_alternates(struct strbuf *src, const char *src_repo)
if (!line.len || line.buf[0] == '#')
continue;
if (is_absolute_path(line.buf)) {
- add_to_alternates_file(line.buf);
+ odb_add_to_alternates_file(the_repository->objects,
+ line.buf);
continue;
}
abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
if (!normalize_path_copy(abs_path, abs_path))
- add_to_alternates_file(abs_path);
+ odb_add_to_alternates_file(the_repository->objects,
+ abs_path);
else
warning("skipping invalid relative alternate: %s/%s",
src_repo, line.buf);
@@ -352,7 +354,7 @@ static void clone_local(const char *src_repo, const char *dest_repo)
struct strbuf alt = STRBUF_INIT;
get_common_dir(&alt, src_repo);
strbuf_addstr(&alt, "/objects");
- add_to_alternates_file(alt.buf);
+ odb_add_to_alternates_file(the_repository->objects, alt.buf);
strbuf_release(&alt);
} else {
struct strbuf src = STRBUF_INIT;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 895c9ca5381..ffae00b1723 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1006,7 +1006,7 @@ int cmd_fsck(int argc,
for_each_packed_object(the_repository,
mark_packed_for_connectivity, NULL, 0);
} else {
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (backend = the_repository->objects->backends; backend; backend = backend->next)
fsck_object_dir(backend->path);
@@ -1117,7 +1117,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_commit_graph) {
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (backend = the_repository->objects->backends; backend; backend = backend->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
@@ -1135,7 +1135,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_multi_pack_index) {
struct child_process midx_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (backend = the_repository->objects->backends; backend; backend = backend->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
diff --git a/builtin/grep.c b/builtin/grep.c
index 7b1940be2a1..610428e6298 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -462,7 +462,7 @@ static int grep_submodule(struct grep_opt *opt,
/*
* NEEDSWORK: repo_read_gitmodules() might call
- * add_to_alternates_memory() via config_from_gitmodules(). This
+ * odb_add_to_alternates_memory() via config_from_gitmodules(). This
* operation causes a race condition with concurrent object readings
* performed by the worker threads. That's why we need obj_read_lock()
* here. It should be removed once it's no longer necessary to add the
diff --git a/builtin/repack.c b/builtin/repack.c
index 16782320058..8145474cf8d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1256,7 +1256,8 @@ int cmd_repack(int argc,
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
die(_(incremental_bitmap_conflict_error));
- if (write_bitmaps && po_args.local && has_alt_odb(the_repository)) {
+ if (write_bitmaps && po_args.local &&
+ odb_has_alternates(the_repository->objects)) {
/*
* When asked to do a local repack, but we have
* packfiles that are inherited from an alternate, then
diff --git a/commit-graph.c b/commit-graph.c
index d58d1bf39ed..ff72f7e32ae 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -649,7 +649,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
count = st->st_size / (the_hash_algo->hexsz + 1);
CALLOC_ARRAY(oids, count);
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (i = 0; i < count; i++) {
struct odb_backend *backend;
@@ -778,7 +778,7 @@ static int prepare_commit_graph(struct repository *r)
if (!commit_graph_compatible(r))
return 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (backend = r->objects->backends;
!r->objects->commit_graph && backend;
backend = backend->next)
diff --git a/loose.c b/loose.c
index e52397bb3e5..dbeafe05c3b 100644
--- a/loose.c
+++ b/loose.c
@@ -112,7 +112,7 @@ int repo_read_loose_object_map(struct repository *repo)
if (!should_use_loose_object_map(repo))
return 0;
- prepare_alt_odb(repo);
+ odb_prepare_alternates(repo->objects);
for (backend = repo->objects->backends; backend; backend = backend->next) {
if (load_one_loose_object_map(repo, backend) < 0) {
diff --git a/object-file.c b/object-file.c
index cc81729ae25..c70a3fc317a 100644
--- a/object-file.c
+++ b/object-file.c
@@ -106,7 +106,7 @@ static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
struct odb_backend *backend;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (backend = the_repository->objects->backends->next; backend; backend = backend->next) {
if (check_and_freshen_odb(backend, oid, freshen))
return 1;
@@ -211,7 +211,7 @@ static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct odb_backend *backend;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (backend = r->objects->backends; backend; backend = backend->next) {
*path = odb_loose_path(backend, &buf, oid);
if (!lstat(*path, st))
@@ -233,7 +233,7 @@ static int open_loose_object(struct repository *r,
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (backend = r->objects->backends; backend; backend = backend->next) {
*path = odb_loose_path(backend, &buf, oid);
fd = git_open(*path);
@@ -252,7 +252,7 @@ static int quick_has_loose(struct repository *r,
{
struct odb_backend *backend;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (backend = r->objects->backends; backend; backend = backend->next) {
if (oidtree_contains(odb_loose_cache(backend, oid), oid))
return 1;
@@ -1542,7 +1542,7 @@ int for_each_loose_object(each_loose_object_fn cb, void *data,
{
struct odb_backend *backend;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (backend = the_repository->objects->backends; backend; backend = backend->next) {
int r = for_each_loose_file_in_objdir(backend->path, cb, NULL,
NULL, data);
diff --git a/object-name.c b/object-name.c
index b80791a9018..919a3e7a9f8 100644
--- a/object-name.c
+++ b/object-name.c
@@ -376,7 +376,7 @@ static int init_object_disambiguation(struct repository *r,
ds->hex_pfx[len] = '\0';
ds->repo = r;
ds->bin_pfx.algo = algo ? hash_algo_by_ptr(algo) : GIT_HASH_UNKNOWN;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
return 0;
}
diff --git a/odb.c b/odb.c
index 9bd87204737..229e048d573 100644
--- a/odb.c
+++ b/odb.c
@@ -272,10 +272,11 @@ static void read_info_alternates(struct object_database *odb,
free(path);
}
-void add_to_alternates_file(const char *reference)
+void odb_add_to_alternates_file(struct object_database *odb,
+ const char *reference)
{
struct lock_file lock = LOCK_INIT;
- char *alts = repo_git_path(the_repository, "objects/info/alternates");
+ char *alts = repo_git_path(odb->repo, "objects/info/alternates");
FILE *in, *out;
int found = 0;
@@ -308,22 +309,23 @@ void add_to_alternates_file(const char *reference)
fprintf_or_die(out, "%s\n", reference);
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
- if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository->objects, reference,
+ if (odb->loaded_alternates)
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
free(alts);
}
-void add_to_alternates_memory(const char *reference)
+void odb_add_to_alternates_memory(struct object_database *odb,
+ const char *reference)
{
/*
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(odb);
- link_alt_odb_entries(the_repository->objects, reference,
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
@@ -335,7 +337,7 @@ struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy)
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
/*
* Make a new primary odb and link the old primary ODB in as an
@@ -379,12 +381,6 @@ void restore_primary_odb(struct odb_backend *restore_odb, const char *old_path)
free_object_directory(cur_odb);
}
-/*
- * Compute the exact path an alternate is at and returns it. In case of
- * error NULL is returned and the human readable error is added to `err`
- * `path` may be relative and should point to $GIT_DIR.
- * `err` must not be null.
- */
char *compute_alternate_path(const char *path, struct strbuf *err)
{
char *ref_git = NULL;
@@ -455,7 +451,7 @@ struct odb_backend *odb_find_backend(struct object_database *odb, const char *ob
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(odb->repo);
+ odb_prepare_alternates(odb);
for (backend = odb->backends; backend; backend = backend->next) {
strbuf_realpath(&odb_path_real, backend->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
@@ -573,7 +569,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
struct odb_backend *backend;
int r = 0;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (backend = the_repository->objects->backends->next; backend; backend = backend->next) {
r = fn(backend, cb);
if (r)
@@ -582,21 +578,21 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
return r;
}
-void prepare_alt_odb(struct repository *r)
+void odb_prepare_alternates(struct object_database *odb)
{
- if (r->objects->loaded_alternates)
+ if (odb->loaded_alternates)
return;
- link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(odb, odb->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r->objects, r->objects->backends->path, 0);
- r->objects->loaded_alternates = 1;
+ read_info_alternates(odb, odb->backends->path, 0);
+ odb->loaded_alternates = 1;
}
-int has_alt_odb(struct repository *r)
+int odb_has_alternates(struct object_database *odb)
{
- prepare_alt_odb(r);
- return !!r->objects->backends->next;
+ odb_prepare_alternates(odb);
+ return !!odb->backends->next;
}
int obj_read_use_lock = 0;
diff --git a/odb.h b/odb.h
index 62967da6cf6..2221af208ee 100644
--- a/odb.h
+++ b/odb.h
@@ -12,6 +12,14 @@ struct oidtree;
struct strbuf;
struct repository;
+/*
+ * Compute the exact path an alternate is at and returns it. In case of
+ * error NULL is returned and the human readable error is added to `err`
+ * `path` may be relative and should point to $GIT_DIR.
+ * `err` must not be null.
+ */
+char *compute_alternate_path(const char *path, struct strbuf *err);
+
/* The backend used to access objects in a specific object directory. */
struct odb_backend {
struct odb_backend *next;
@@ -53,27 +61,11 @@ struct odb_backend {
char *path;
};
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
typedef int alt_odb_fn(struct odb_backend *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
-/*
- * 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);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -112,7 +104,7 @@ struct object_database {
/*
* A list of alternate object directories loaded from the environment;
* this should not generally need to be accessed directly, but will
- * populate the "backends" list when prepare_alt_odb() is run.
+ * populate the "backends" list when odb_prepare_alternates() is run.
*/
char *alternate_db;
@@ -197,6 +189,33 @@ struct odb_backend *odb_find_backend(struct object_database *odb, const char *ob
int odb_mkstemp(struct object_database *odb,
struct strbuf *temp_filename, const char *pattern);
+/*
+ * Prepare alternate object backends for the given database by reading
+ * "objects/info/alternates" and opening the respective backends.
+ */
+void odb_prepare_alternates(struct object_database *odb);
+
+/*
+ * Check whether the object database has any alternate backends. The primary
+ * object backend does not count as alternate.
+ */
+int odb_has_alternates(struct object_database *odb);
+
+/*
+ * Add the directory to the on-disk alternates file; the new entry will also
+ * take effect in the current process.
+ */
+void odb_add_to_alternates_file(struct object_database *odb,
+ 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 odb_add_to_alternates_memory(struct object_database *odb,
+ const char *dir);
+
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,
diff --git a/packfile.c b/packfile.c
index 0f3d60721a9..263056a6279 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1023,7 +1023,7 @@ static void prepare_packed_git(struct repository *r)
if (r->objects->packed_git_initialized)
return;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (backend = r->objects->backends; backend; backend = backend->next) {
int local = (backend == r->objects->backends);
prepare_multi_pack_index_one(r, backend->path, local);
@@ -1048,7 +1048,7 @@ void reprepare_packed_git(struct repository *r)
* the lifetime of the process.
*/
r->objects->loaded_alternates = 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (backend = r->objects->backends; backend; backend = backend->next)
odb_clear_loose_cache(backend);
diff --git a/submodule.c b/submodule.c
index 9b1018877df..386be234230 100644
--- a/submodule.c
+++ b/submodule.c
@@ -189,7 +189,8 @@ int register_all_submodule_odb_as_alternates(void)
int ret = added_submodule_odb_paths.nr;
for (i = 0; i < added_submodule_odb_paths.nr; i++)
- add_to_alternates_memory(added_submodule_odb_paths.items[i].string);
+ odb_add_to_alternates_memory(the_repository->objects,
+ added_submodule_odb_paths.items[i].string);
if (ret) {
string_list_clear(&added_submodule_odb_paths, 0);
trace2_data_intmax("submodule", the_repository,
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 2920ca59d72..8d9a271845c 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -79,7 +79,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)
if (!repo_submodule_path_append(the_repository,
&sb, gitdir, "objects/"))
die("computing submodule path failed");
- add_to_alternates_memory(sb.buf);
+ odb_add_to_alternates_memory(the_repository->objects, sb.buf);
strbuf_release(&sb);
*refs = repo_get_submodule_ref_store(the_repository, gitdir);
diff --git a/tmp-objdir.c b/tmp-objdir.c
index f9e8277fd7c..2982c646569 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -304,7 +304,7 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)
void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
{
- add_to_alternates_memory(t->path.buf);
+ odb_add_to_alternates_memory(t->repo->objects, t->path.buf);
}
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 08/17] odb: get rid of `the_repository` when handling alternates
2025-05-06 11:09 ` [PATCH 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
@ 2025-05-07 1:14 ` Derrick Stolee
0 siblings, 0 replies; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 1:14 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> The functions to manage alternates all depend on `the_repository`.
> Refactor them to accept an object database as parameter and adjusting
> all callers. The functions are renamed accordingly.
...
> - prepare_alt_odb(odb->repo);
> + odb_prepare_alternates(odb);
I was looking forward to this change in an earlier patch that
introduced the line being edited here. Thanks for making this
cleaner (and the other callers will get cleaner eventually,
too).
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH 09/17] odb: get rid of `the_repository` in `for_each()` functions
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (7 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-07 1:21 ` Derrick Stolee
2025-05-06 11:09 ` [PATCH 10/17] odb: get rid of `the_repository` when handling the primary backend Patrick Steinhardt
` (14 subsequent siblings)
23 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
There are a couple of iterator-style functions that execute a callback
for each instance of a given set, all of which currently depend on
`the_repository`. Refactor them to instead take an object database as
parameter so that we can get rid of this dependency.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/count-objects.c | 2 +-
builtin/receive-pack.c | 3 ++-
builtin/submodule--helper.c | 3 ++-
diagnose.c | 2 +-
fetch-pack.c | 3 ++-
odb.c | 36 +++++++++++++++++++-----------------
odb.h | 23 ++++++++++++++++++-----
revision.c | 3 ++-
8 files changed, 47 insertions(+), 28 deletions(-)
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 80f2693ac3c..5ca806d53e3 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -159,7 +159,7 @@ int cmd_count_objects(int argc,
printf("prune-packable: %lu\n", packed_loose);
printf("garbage: %lu\n", garbage);
printf("size-garbage: %s\n", garbage_buf.buf);
- foreach_alt_odb(print_alternate, NULL);
+ odb_for_each_backend(the_repository->objects, print_alternate, NULL);
strbuf_release(&loose_buf);
strbuf_release(&pack_buf);
strbuf_release(&garbage_buf);
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index cb5fd55a8e4..8c157ea7d1b 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -358,7 +358,8 @@ static void write_head_info(void)
refs_for_each_fullref_in(get_main_ref_store(the_repository), "",
exclude_patterns, show_ref_cb, &seen);
- for_each_alternate_ref(show_one_alternate_ref, &seen);
+ odb_for_each_alternate_ref(the_repository->objects,
+ show_one_alternate_ref, &seen);
oidset_clear(&seen);
strvec_clear(&excludes_vector);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 7f672e4808c..d54546df9da 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1668,7 +1668,8 @@ static void prepare_possible_alternates(const char *sm_name,
die(_("Value '%s' for submodule.alternateErrorStrategy is not recognized"), error_strategy);
if (!strcmp(sm_alternate, "superproject"))
- foreach_alt_odb(add_possible_reference_from_superproject, &sas);
+ odb_for_each_backend(the_repository->objects,
+ add_possible_reference_from_superproject, &sas);
else if (!strcmp(sm_alternate, "no"))
; /* do nothing */
else
diff --git a/diagnose.c b/diagnose.c
index 6ec07761a0f..0529e239837 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -229,7 +229,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
dir_file_stats(r->objects->backends, &buf);
- foreach_alt_odb(dir_file_stats, &buf);
+ odb_for_each_backend(r->objects, dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
strbuf_reset(&buf);
diff --git a/fetch-pack.c b/fetch-pack.c
index cf157f5d7e5..47fa7fa4c49 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -115,7 +115,8 @@ static void for_each_cached_alternate(struct fetch_negotiator *negotiator,
size_t i;
if (!initialized) {
- for_each_alternate_ref(cache_one_alternate, &cache);
+ odb_for_each_alternate_ref(the_repository->objects,
+ cache_one_alternate, &cache);
initialized = 1;
}
diff --git a/odb.c b/odb.c
index 229e048d573..66cad14f538 100644
--- a/odb.c
+++ b/odb.c
@@ -494,8 +494,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
}
static void read_alternate_refs(const char *path,
- alternate_ref_fn *cb,
- void *data)
+ odb_for_each_alternate_ref_fn *cb,
+ void *payload)
{
struct child_process cmd = CHILD_PROCESS_INIT;
struct strbuf line = STRBUF_INIT;
@@ -517,7 +517,7 @@ static void read_alternate_refs(const char *path,
break;
}
- cb(&oid, data);
+ cb(&oid, payload);
}
fclose(fh);
@@ -526,16 +526,16 @@ static void read_alternate_refs(const char *path,
}
struct alternate_refs_data {
- alternate_ref_fn *fn;
- void *data;
+ odb_for_each_alternate_ref_fn *fn;
+ void *payload;
};
static int refs_from_alternate_cb(struct odb_backend *e,
- void *data)
+ void *payload)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
- struct alternate_refs_data *cb = data;
+ struct alternate_refs_data *cb = payload;
if (!strbuf_realpath(&path, e->path, 0))
goto out;
@@ -549,29 +549,31 @@ static int refs_from_alternate_cb(struct odb_backend *e,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->data);
+ read_alternate_refs(path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
return 0;
}
-void for_each_alternate_ref(alternate_ref_fn fn, void *data)
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload)
{
- struct alternate_refs_data cb;
- cb.fn = fn;
- cb.data = data;
- foreach_alt_odb(refs_from_alternate_cb, &cb);
+ struct alternate_refs_data data;
+ data.fn = cb;
+ data.payload = payload;
+ odb_for_each_backend(odb, refs_from_alternate_cb, &data);
}
-int foreach_alt_odb(alt_odb_fn fn, void *cb)
+int odb_for_each_backend(struct object_database *odb,
+ odb_for_each_backend_fn cb, void *payload)
{
struct odb_backend *backend;
int r = 0;
- odb_prepare_alternates(the_repository->objects);
- for (backend = the_repository->objects->backends->next; backend; backend = backend->next) {
- r = fn(backend, cb);
+ odb_prepare_alternates(odb);
+ for (backend = odb->backends->next; backend; backend = backend->next) {
+ r = cb(backend, payload);
if (r)
break;
}
diff --git a/odb.h b/odb.h
index 2221af208ee..2165396a165 100644
--- a/odb.h
+++ b/odb.h
@@ -61,11 +61,6 @@ struct odb_backend {
char *path;
};
-typedef int alt_odb_fn(struct odb_backend *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -180,6 +175,24 @@ void odb_clear(struct object_database *o);
*/
struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir);
+/*
+ * Iterate through all backends of the database and execute the provided
+ * callback function for each of them. Stop iterating once the callback
+ * function returns a non-zero value, in which case the value is bubbled up
+ * from the callback.
+ */
+typedef int odb_for_each_backend_fn(struct odb_backend *, void *);
+int odb_for_each_backend(struct object_database *odb,
+ odb_for_each_backend_fn cb, void *payload);
+
+/*
+ * Iterate through all alternative object backends of the database and yield
+ * their respective references.
+ */
+typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload);
+
/*
* Create a temporary file rooted in the primary object database backend's
* directory, or die on failure. The filename is taken from "pattern", which
diff --git a/revision.c b/revision.c
index cdefe7d6e48..b0364f556ee 100644
--- a/revision.c
+++ b/revision.c
@@ -1907,7 +1907,8 @@ static void add_alternate_refs_to_pending(struct rev_info *revs,
struct add_alternate_refs_data data;
data.revs = revs;
data.flags = flags;
- for_each_alternate_ref(add_one_alternate_ref, &data);
+ odb_for_each_alternate_ref(the_repository->objects,
+ add_one_alternate_ref, &data);
}
static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 09/17] odb: get rid of `the_repository` in `for_each()` functions
2025-05-06 11:09 ` [PATCH 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
@ 2025-05-07 1:21 ` Derrick Stolee
2025-05-09 11:25 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 1:21 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> There are a couple of iterator-style functions that execute a callback
> for each instance of a given set, all of which currently depend on
> `the_repository`. Refactor them to instead take an object database as
> parameter so that we can get rid of this dependency.
...
> +/*
> + * Iterate through all backends of the database and execute the provided
> + * callback function for each of them. Stop iterating once the callback
> + * function returns a non-zero value, in which case the value is bubbled up
> + * from the callback.
> + */
> +typedef int odb_for_each_backend_fn(struct odb_backend *, void *);
> +int odb_for_each_backend(struct object_database *odb,
> + odb_for_each_backend_fn cb, void *payload);
> +
> +/*
> + * Iterate through all alternative object backends of the database and yield
> + * their respective references.
> + */
> +typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
> +void odb_for_each_alternate_ref(struct object_database *odb,
> + odb_for_each_alternate_ref_fn cb, void *payload);
> +
Here's another occasion where we should be careful about how we rename
an "alternate odb". What is an "alternate ref" if we have different 'odb
backend's (or slices/shards/odbs etc.). Should we be updating the term
"alternate ref" here?
Changing 'alternate ref' would be quite difficult seeing how it is based
on the 'core.alternateRefsCommand' and 'core.alternateRefsPrefix' config
keys.
Perhaps this is motivation to keep the word 'alternate' but as a way to
differentiate the repo's odb from ones it is borrowing.
I'm sorry to nitpick so much here, but your thorough series is helping
to bring to mind all of the different aspects that are being conflated
by our current nomenclature that grew organically and is now being
carefully designed for the better.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 09/17] odb: get rid of `the_repository` in `for_each()` functions
2025-05-07 1:21 ` Derrick Stolee
@ 2025-05-09 11:25 ` Patrick Steinhardt
2025-05-12 18:28 ` Derrick Stolee
0 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 11:25 UTC (permalink / raw)
To: Derrick Stolee; +Cc: git
On Tue, May 06, 2025 at 09:21:15PM -0400, Derrick Stolee wrote:
> On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> > There are a couple of iterator-style functions that execute a callback
> > for each instance of a given set, all of which currently depend on
> > `the_repository`. Refactor them to instead take an object database as
> > parameter so that we can get rid of this dependency.
> ...
> > +/*
> > + * Iterate through all backends of the database and execute the provided
> > + * callback function for each of them. Stop iterating once the callback
> > + * function returns a non-zero value, in which case the value is bubbled up
> > + * from the callback.
> > + */
> > +typedef int odb_for_each_backend_fn(struct odb_backend *, void *);
> > +int odb_for_each_backend(struct object_database *odb,
> > + odb_for_each_backend_fn cb, void *payload);
> > +
> > +/*
> > + * Iterate through all alternative object backends of the database and yield
> > + * their respective references.
> > + */
> > +typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
> > +void odb_for_each_alternate_ref(struct object_database *odb,
> > + odb_for_each_alternate_ref_fn cb, void *payload);
> > +
>
> Here's another occasion where we should be careful about how we rename
> an "alternate odb". What is an "alternate ref" if we have different 'odb
> backend's (or slices/shards/odbs etc.). Should we be updating the term
> "alternate ref" here?
>
> Changing 'alternate ref' would be quite difficult seeing how it is based
> on the 'core.alternateRefsCommand' and 'core.alternateRefsPrefix' config
> keys.
>
> Perhaps this is motivation to keep the word 'alternate' but as a way to
> differentiate the repo's odb from ones it is borrowing.
Yeah, the next iteration will call things `odb_alternate` instead of
`odb_backend`, which I think makes a lot of the terminology fall out
naturally. The only thing that may be confusing at first is that we also
have a "primary alternate" now, but I think that's bearable.
> I'm sorry to nitpick so much here, but your thorough series is helping
> to bring to mind all of the different aspects that are being conflated
> by our current nomenclature that grew organically and is now being
> carefully designed for the better.
I very much invite this nitpicking on this series, so please don't be
sorry.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 09/17] odb: get rid of `the_repository` in `for_each()` functions
2025-05-09 11:25 ` Patrick Steinhardt
@ 2025-05-12 18:28 ` Derrick Stolee
0 siblings, 0 replies; 166+ messages in thread
From: Derrick Stolee @ 2025-05-12 18:28 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
On 5/9/2025 7:25 AM, Patrick Steinhardt wrote:
> On Tue, May 06, 2025 at 09:21:15PM -0400, Derrick Stolee wrote:
>> On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
>>> There are a couple of iterator-style functions that execute a callback
>>> for each instance of a given set, all of which currently depend on
>>> `the_repository`. Refactor them to instead take an object database as
>>> parameter so that we can get rid of this dependency.
>> ...
>>> +/*
>>> + * Iterate through all backends of the database and execute the provided
>>> + * callback function for each of them. Stop iterating once the callback
>>> + * function returns a non-zero value, in which case the value is bubbled up
>>> + * from the callback.
>>> + */
>>> +typedef int odb_for_each_backend_fn(struct odb_backend *, void *);
>>> +int odb_for_each_backend(struct object_database *odb,
>>> + odb_for_each_backend_fn cb, void *payload);
>>> +
>>> +/*
>>> + * Iterate through all alternative object backends of the database and yield
>>> + * their respective references.
>>> + */
>>> +typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
>>> +void odb_for_each_alternate_ref(struct object_database *odb,
>>> + odb_for_each_alternate_ref_fn cb, void *payload);
>>> +
>>
>> Here's another occasion where we should be careful about how we rename
>> an "alternate odb". What is an "alternate ref" if we have different 'odb
>> backend's (or slices/shards/odbs etc.). Should we be updating the term
>> "alternate ref" here?
>>
>> Changing 'alternate ref' would be quite difficult seeing how it is based
>> on the 'core.alternateRefsCommand' and 'core.alternateRefsPrefix' config
>> keys.
>>
>> Perhaps this is motivation to keep the word 'alternate' but as a way to
>> differentiate the repo's odb from ones it is borrowing.
>
> Yeah, the next iteration will call things `odb_alternate` instead of
> `odb_backend`, which I think makes a lot of the terminology fall out
> naturally. The only thing that may be confusing at first is that we also
> have a "primary alternate" now, but I think that's bearable.
I like odb_alternate over odb_backend. Thanks.
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH 10/17] odb: get rid of `the_repository` when handling the primary backend
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (8 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-06 11:09 ` [PATCH 11/17] odb: get rid of `the_repository` when handling submodule backends Patrick Steinhardt
` (13 subsequent siblings)
23 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
The functions `set_temporary_primary_odb()` and `restore_primary_odb()`
are responsible for managing a temporary primary backend for the
database. Both of these fucntions implicitly rely on `the_repository`.
Refactor them to instead take an explicit object database parameter as
argument and adjust callers. Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 19 +++++++++++--------
odb.h | 25 ++++++++++++++-----------
tmp-objdir.c | 10 ++++++----
3 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/odb.c b/odb.c
index 66cad14f538..8be5d4fb2d6 100644
--- a/odb.c
+++ b/odb.c
@@ -329,7 +329,8 @@ void odb_add_to_alternates_memory(struct object_database *odb,
'\n', NULL, 0);
}
-struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_backend *odb_set_temporary_primary_backend(struct object_database *odb,
+ const char *dir, int will_destroy)
{
struct odb_backend *backend;
@@ -337,14 +338,14 @@ struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy)
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- odb_prepare_alternates(the_repository->objects);
+ odb_prepare_alternates(odb);
/*
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
backend = xcalloc(1, sizeof(*backend));
- backend->odb = the_repository->objects;
+ backend->odb = odb;
backend->path = xstrdup(dir);
/*
@@ -353,8 +354,8 @@ struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy)
*/
backend->disable_ref_updates = 1;
backend->will_destroy = will_destroy;
- backend->next = the_repository->objects->backends;
- the_repository->objects->backends = backend;
+ backend->next = odb->backends;
+ odb->backends = backend;
return backend->next;
}
@@ -366,9 +367,11 @@ static void free_object_directory(struct odb_backend *odb)
free(odb);
}
-void restore_primary_odb(struct odb_backend *restore_odb, const char *old_path)
+void odb_restore_primary_backend(struct object_database *odb,
+ struct odb_backend *restore_odb,
+ const char *old_path)
{
- struct odb_backend *cur_odb = the_repository->objects->backends;
+ struct odb_backend *cur_odb = odb->backends;
if (strcmp(old_path, cur_odb->path))
BUG("expected %s as primary object store; found %s",
@@ -377,7 +380,7 @@ void restore_primary_odb(struct odb_backend *restore_odb, const char *old_path)
if (cur_odb->next != restore_odb)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->backends = restore_odb;
+ odb->backends = restore_odb;
free_object_directory(cur_odb);
}
diff --git a/odb.h b/odb.h
index 2165396a165..e80ee5efec6 100644
--- a/odb.h
+++ b/odb.h
@@ -61,17 +61,6 @@ struct odb_backend {
char *path;
};
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy);
-
-/*
- * Restore a previous ODB replaced by set_temporary_main_odb.
- */
-void restore_primary_odb(struct odb_backend *restore_odb, const char *old_path);
-
struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
@@ -175,6 +164,20 @@ void odb_clear(struct object_database *o);
*/
struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir);
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary backend.
+ */
+struct odb_backend *odb_set_temporary_primary_backend(struct object_database *odb,
+ const char *dir, int will_destroy);
+
+/*
+ * Restore a previous bakcend replaced by `odb_set_temporary_primary_backend()`.
+ */
+void odb_restore_primary_backend(struct object_database *odb,
+ struct odb_backend *restore_odb,
+ const char *old_path);
+
/*
* Iterate through all backends of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 2982c646569..e6221879395 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -47,7 +47,7 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
the_tmp_objdir = NULL;
if (t->prev_odb)
- restore_primary_odb(t->prev_odb, t->path.buf);
+ odb_restore_primary_backend(t->repo->objects, t->prev_odb, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -279,7 +279,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (t->prev_odb) {
if (t->repo->objects->backends->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_odb, t->path.buf);
+ odb_restore_primary_backend(t->repo->objects, t->prev_odb, t->path.buf);
t->prev_odb = NULL;
}
@@ -311,7 +311,8 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
if (t->prev_odb)
BUG("the primary object database is already replaced");
- t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_odb = odb_set_temporary_primary_backend(t->repo->objects,
+ t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
@@ -320,7 +321,8 @@ struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
+ odb_restore_primary_backend(the_tmp_objdir->repo->objects,
+ the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
the_tmp_objdir->prev_odb = NULL;
return the_tmp_objdir;
}
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH 11/17] odb: get rid of `the_repository` when handling submodule backends
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (9 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 10/17] odb: get rid of `the_repository` when handling the primary backend Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-07 1:25 ` Derrick Stolee
2025-05-06 11:09 ` [PATCH 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
` (12 subsequent siblings)
23 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
The "--recursive" flag for git-grep(1) allows users to grep for a string
across submodule boundaries. To make this work we add each submodule's
object backend to our own object database so that the objects can be
accessed directly.
The infrastructure for this depends on a global string list of submodule
paths. The caller is expected to call `add_submodule_odb_by_path()` for
each backend and the object database will then eventually register all
submodule backends via `do_oid_object_info_extended()` in case it isn't
able to look up a specific object.
This reliance on global state is of course suboptimal with regards to
our libification efforts.
Refactor the logic so that the list of submodule backends is instead
tracked in the object database itself. This allows us to lose the
condition of `r == the_repository` before registering submodule backends
as we only ever add submodule backends to `the_repository` anyway. As
such, behaviour before and after this refactoring should always be the
same.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/grep.c | 3 ++-
odb.c | 37 +++++++++++++++++++++++++++++++------
odb.h | 15 +++++++++++++++
submodule-config.c | 3 ++-
submodule.c | 26 --------------------------
submodule.h | 9 ---------
6 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 610428e6298..e9816cce8cd 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,8 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->backends->path);
+ odb_add_submodule_backend_by_path(the_repository->objects,
+ subrepo->objects->backends->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/odb.c b/odb.c
index 8be5d4fb2d6..bfdf36751e0 100644
--- a/odb.c
+++ b/odb.c
@@ -24,6 +24,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "submodule.h"
+#include "trace2.h"
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
@@ -469,6 +470,12 @@ struct odb_backend *odb_find_backend(struct object_database *odb, const char *ob
return backend;
}
+void odb_add_submodule_backend_by_path(struct object_database *odb,
+ const char *path)
+{
+ string_list_insert(&odb->submodule_backend_paths, path);
+}
+
static void fill_alternate_refs_command(struct child_process *cmd,
const char *repo_path)
{
@@ -623,6 +630,23 @@ void disable_obj_read_lock(void)
int fetch_if_missing = 1;
+static int register_all_submodule_backends(struct object_database *odb)
+{
+ int ret = odb->submodule_backend_paths.nr;
+
+ for (size_t i = 0; i < odb->submodule_backend_paths.nr; i++)
+ odb_add_to_alternates_memory(odb,
+ odb->submodule_backend_paths.items[i].string);
+ if (ret) {
+ string_list_clear(&odb->submodule_backend_paths, 0);
+ trace2_data_intmax("submodule", odb->repo,
+ "register_all_submodule_backends/registered", ret);
+ if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
+ BUG("register_all_submodule_backends() called");
+ }
+ return ret;
+}
+
static int do_oid_object_info_extended(struct repository *r,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
@@ -678,13 +702,12 @@ static int do_oid_object_info_extended(struct repository *r,
}
/*
- * If r is the_repository, this might be an attempt at
- * accessing a submodule object as if it were in the_repository
- * (having called add_submodule_odb() on that submodule's ODB).
- * If any such ODBs exist, register them and try again.
+ * This might be an attempt at accessing a submodule object as
+ * if it were in main object store (having called
+ * `odb_add_submodule_backend_by_path()` on that submodule's
+ * ODB). If any such ODBs exist, register them and try again.
*/
- if (r == the_repository &&
- register_all_submodule_odb_as_alternates())
+ if (register_all_submodule_backends(r->objects))
/* We added some alternates; retry */
continue;
@@ -977,6 +1000,7 @@ struct object_database *odb_new(struct repository *repo)
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
+ string_list_init_dup(&o->submodule_backend_paths);
return o;
}
@@ -1027,4 +1051,5 @@ void odb_clear(struct object_database *o)
o->packed_git = NULL;
hashmap_clear(&o->pack_map);
+ string_list_clear(&o->submodule_backend_paths, 0);
}
diff --git a/odb.h b/odb.h
index e80ee5efec6..1558f467425 100644
--- a/odb.h
+++ b/odb.h
@@ -5,6 +5,7 @@
#include "object.h"
#include "list.h"
#include "oidset.h"
+#include "string-list.h"
#include "thread-utils.h"
struct oidmap;
@@ -153,6 +154,12 @@ struct object_database {
* packs.
*/
unsigned packed_git_initialized : 1;
+
+ /*
+ * Submodule backend paths that will be added as alternatives to allow
+ * lookup of submodule objects via the main object database.
+ */
+ struct string_list submodule_backend_paths;
};
struct object_database *odb_new(struct repository *repo);
@@ -178,6 +185,14 @@ void odb_restore_primary_backend(struct object_database *odb,
struct odb_backend *restore_odb,
const char *old_path);
+/*
+ * Call odb_add_submodule_backend_by_path() to add the submodule at the given
+ * path to a list. The object stores of all submodules in that list will be
+ * added as alternates in the object store when looking up objects.
+ */
+void odb_add_submodule_backend_by_path(struct object_database *odb,
+ const char *path);
+
/*
* Iterate through all backends of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/submodule-config.c b/submodule-config.c
index 4abef906f26..ed4bb32dc37 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,8 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->backends->path);
+ odb_add_submodule_backend_by_path(the_repository->objects,
+ repo->objects->backends->path);
} else {
goto out;
}
diff --git a/submodule.c b/submodule.c
index 386be234230..788c9e55ed3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -31,7 +31,6 @@
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
-#include "trace2.h"
static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
static int initialized_fetch_ref_tips;
@@ -176,31 +175,6 @@ void stage_updated_gitmodules(struct index_state *istate)
die(_("staging updated .gitmodules failed"));
}
-static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_DUP;
-
-void add_submodule_odb_by_path(const char *path)
-{
- string_list_insert(&added_submodule_odb_paths, path);
-}
-
-int register_all_submodule_odb_as_alternates(void)
-{
- int i;
- int ret = added_submodule_odb_paths.nr;
-
- for (i = 0; i < added_submodule_odb_paths.nr; i++)
- odb_add_to_alternates_memory(the_repository->objects,
- added_submodule_odb_paths.items[i].string);
- if (ret) {
- string_list_clear(&added_submodule_odb_paths, 0);
- trace2_data_intmax("submodule", the_repository,
- "register_all_submodule_odb_as_alternates/registered", ret);
- if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
- BUG("register_all_submodule_odb_as_alternates() called");
- }
- return ret;
-}
-
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
const char *path)
{
diff --git a/submodule.h b/submodule.h
index db980c1d083..b10e16e6c06 100644
--- a/submodule.h
+++ b/submodule.h
@@ -104,15 +104,6 @@ int submodule_uses_gitfile(const char *path);
#define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
int bad_to_remove_submodule(const char *path, unsigned flags);
-/*
- * Call add_submodule_odb_by_path() to add the submodule at the given
- * path to a list. When register_all_submodule_odb_as_alternates() is
- * called, the object stores of all submodules in that list will be
- * added as alternates in the_repository.
- */
-void add_submodule_odb_by_path(const char *path);
-int register_all_submodule_odb_as_alternates(void);
-
/*
* Checks if there are submodule changes in a..b. If a is the null OID,
* checks b and all its ancestors instead.
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 11/17] odb: get rid of `the_repository` when handling submodule backends
2025-05-06 11:09 ` [PATCH 11/17] odb: get rid of `the_repository` when handling submodule backends Patrick Steinhardt
@ 2025-05-07 1:25 ` Derrick Stolee
2025-05-07 1:29 ` Derrick Stolee
0 siblings, 1 reply; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 1:25 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> The "--recursive" flag for git-grep(1) allows users to grep for a string
> across submodule boundaries. To make this work we add each submodule's
> object backend to our own object database so that the objects can be
> accessed directly.
> +static int register_all_submodule_backends(struct object_database *odb)
> +{
> + int ret = odb->submodule_backend_paths.nr;
> +
> + for (size_t i = 0; i < odb->submodule_backend_paths.nr; i++)
> + odb_add_to_alternates_memory(odb,
> + odb->submodule_backend_paths.items[i].string);
> + if (ret) {
> + string_list_clear(&odb->submodule_backend_paths, 0);
> + trace2_data_intmax("submodule", odb->repo,
> + "register_all_submodule_backends/registered", ret);
> + if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
> + BUG("register_all_submodule_backends() called");
Did you plan to create a test around this test variable?
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 11/17] odb: get rid of `the_repository` when handling submodule backends
2025-05-07 1:25 ` Derrick Stolee
@ 2025-05-07 1:29 ` Derrick Stolee
0 siblings, 0 replies; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 1:29 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 9:25 PM, Derrick Stolee wrote:
> On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
>> + if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
>> + BUG("register_all_submodule_backends() called");
>
> Did you plan to create a test around this test variable?
Please ignore me. This was re-used from before. It was just in
code that looks like a new hunk.
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH 12/17] odb: trivial refactorings to get rid of `the_repository`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (10 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 11/17] odb: get rid of `the_repository` when handling submodule backends Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-07 1:25 ` Derrick Stolee
2025-05-06 11:09 ` [PATCH 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
` (11 subsequent siblings)
23 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
All of the external functions provided by the object database subsystem
don't depend on `the_repository` anymore, but some internal functions
still do. Refactor those cases by plumbing through the repository that
owns the object database.
This change allows us to get rid of the `USE_THE_REPOSITORY_VARIABLE`
preprocessor define.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/odb.c b/odb.c
index bfdf36751e0..8901e3f43a3 100644
--- a/odb.c
+++ b/odb.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "abspath.h"
#include "commit-graph.h"
@@ -476,12 +474,13 @@ void odb_add_submodule_backend_by_path(struct object_database *odb,
string_list_insert(&odb->submodule_backend_paths, path);
}
-static void fill_alternate_refs_command(struct child_process *cmd,
+static void fill_alternate_refs_command(struct repository *repo,
+ struct child_process *cmd,
const char *repo_path)
{
const char *value;
- if (!git_config_get_value("core.alternateRefsCommand", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsCommand", &value)) {
cmd->use_shell = 1;
strvec_push(&cmd->args, value);
@@ -493,7 +492,7 @@ static void fill_alternate_refs_command(struct child_process *cmd,
strvec_push(&cmd->args, "for-each-ref");
strvec_push(&cmd->args, "--format=%(objectname)");
- if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsPrefixes", &value)) {
strvec_push(&cmd->args, "--");
strvec_split(&cmd->args, value);
}
@@ -503,7 +502,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
cmd->out = -1;
}
-static void read_alternate_refs(const char *path,
+static void read_alternate_refs(struct repository *repo,
+ const char *path,
odb_for_each_alternate_ref_fn *cb,
void *payload)
{
@@ -511,7 +511,7 @@ static void read_alternate_refs(const char *path,
struct strbuf line = STRBUF_INIT;
FILE *fh;
- fill_alternate_refs_command(&cmd, path);
+ fill_alternate_refs_command(repo, &cmd, path);
if (start_command(&cmd))
return;
@@ -521,7 +521,7 @@ static void read_alternate_refs(const char *path,
struct object_id oid;
const char *p;
- if (parse_oid_hex(line.buf, &oid, &p) || *p) {
+ if (parse_oid_hex_algop(line.buf, &oid, &p, repo->hash_algo) || *p) {
warning(_("invalid line while parsing alternate refs: %s"),
line.buf);
break;
@@ -559,7 +559,7 @@ static int refs_from_alternate_cb(struct odb_backend *e,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->payload);
+ read_alternate_refs(e->odb->repo, path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, the_repository->hash_algo);
+ oidclr(oi->delta_base_oid, r->hash_algo);
if (oi->type_name)
strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
@@ -765,10 +765,10 @@ static int oid_object_info_convert(struct repository *r,
void *content;
int ret;
- if (repo_oid_to_algop(r, input_oid, the_hash_algo, &oid)) {
+ if (repo_oid_to_algop(r, input_oid, r->hash_algo, &oid)) {
if (do_die)
die(_("missing mapping of %s to %s"),
- oid_to_hex(input_oid), the_hash_algo->name);
+ oid_to_hex(input_oid), r->hash_algo->name);
return -1;
}
@@ -804,8 +804,8 @@ static int oid_object_info_convert(struct repository *r,
if (type == -1)
return -1;
if (type != OBJ_BLOB) {
- ret = convert_object_file(the_repository, &outbuf,
- the_hash_algo, input_algo,
+ ret = convert_object_file(r, &outbuf,
+ r->hash_algo, input_algo,
content, size, type, !do_die);
free(content);
if (ret == -1)
@@ -953,9 +953,9 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + the_hash_algo->hexsz > isize ||
+ if (ref_length + r->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
free(buffer);
return NULL;
}
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 12/17] odb: trivial refactorings to get rid of `the_repository`
2025-05-06 11:09 ` [PATCH 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
@ 2025-05-07 1:25 ` Derrick Stolee
2025-05-07 16:38 ` Junio C Hamano
0 siblings, 1 reply; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 1:25 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> All of the external functions provided by the object database subsystem
> don't depend on `the_repository` anymore, but some internal functions
> still do. Refactor those cases by plumbing through the repository that
> owns the object database.
>
> This change allows us to get rid of the `USE_THE_REPOSITORY_VARIABLE`
> preprocessor define.
> --- a/odb.c
> +++ b/odb.c
> @@ -1,5 +1,3 @@
> -#define USE_THE_REPOSITORY_VARIABLE
> -
Very satisfying! Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 12/17] odb: trivial refactorings to get rid of `the_repository`
2025-05-07 1:25 ` Derrick Stolee
@ 2025-05-07 16:38 ` Junio C Hamano
2025-05-09 11:25 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Junio C Hamano @ 2025-05-07 16:38 UTC (permalink / raw)
To: Derrick Stolee; +Cc: Patrick Steinhardt, git
Derrick Stolee <stolee@gmail.com> writes:
> On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
>> All of the external functions provided by the object database subsystem
>> don't depend on `the_repository` anymore, but some internal functions
>> still do. Refactor those cases by plumbing through the repository that
>> owns the object database.
>> This change allows us to get rid of the
>> `USE_THE_REPOSITORY_VARIABLE`
>> preprocessor define.
>
>> --- a/odb.c
>> +++ b/odb.c
>> @@ -1,5 +1,3 @@
>> -#define USE_THE_REPOSITORY_VARIABLE
>> -
>
> Very satisfying! Thanks,
Yes, nice outcome. I looked at the resulting odb.c and was a bit
unhappy to see that we still need to pass "struct repository *"
(instead of "struct object_database *") around. But that is not
because we assume we can get to an odb via repo, but primarily
because repo has many things like config access and hash-algo that
we rely on, so it is perfectly OK.
At some places, where we pass odb around, we can and do go from it
to its repository (e.g. odb->repo->hash_algo), which was what I am
expecting to see more of in the future.
Thanks.
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 12/17] odb: trivial refactorings to get rid of `the_repository`
2025-05-07 16:38 ` Junio C Hamano
@ 2025-05-09 11:25 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 11:25 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Derrick Stolee, git
On Wed, May 07, 2025 at 09:38:52AM -0700, Junio C Hamano wrote:
> Derrick Stolee <stolee@gmail.com> writes:
>
> > On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> >> All of the external functions provided by the object database subsystem
> >> don't depend on `the_repository` anymore, but some internal functions
> >> still do. Refactor those cases by plumbing through the repository that
> >> owns the object database.
> >> This change allows us to get rid of the
> >> `USE_THE_REPOSITORY_VARIABLE`
> >> preprocessor define.
> >
> >> --- a/odb.c
> >> +++ b/odb.c
> >> @@ -1,5 +1,3 @@
> >> -#define USE_THE_REPOSITORY_VARIABLE
> >> -
> >
> > Very satisfying! Thanks,
>
> Yes, nice outcome. I looked at the resulting odb.c and was a bit
> unhappy to see that we still need to pass "struct repository *"
> (instead of "struct object_database *") around. But that is not
> because we assume we can get to an odb via repo, but primarily
> because repo has many things like config access and hash-algo that
> we rely on, so it is perfectly OK.
>
> At some places, where we pass odb around, we can and do go from it
> to its repository (e.g. odb->repo->hash_algo), which was what I am
> expecting to see more of in the future.
Yup. Over time I very much have the intent to reduce the reliance on
`odb->repo` even further. Ideally, the object database should have all
info, or at least almost all of it, to function correctly.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH 13/17] odb: rename `oid_object_info()`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (11 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-06 11:09 ` [PATCH 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
` (10 subsequent siblings)
23 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
Rename `oid_object_info()` to `odb_read_object_info()` as well as their
`_extended()` variant to match other functions related to the object
database and our modern coding guidelines.
Introduce compatibility wrappers so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
archive.c | 2 +-
blame.c | 4 +--
builtin/blame.c | 4 +--
builtin/cat-file.c | 26 ++++++++++---------
builtin/describe.c | 3 ++-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 17 ++++++------
builtin/fsck.c | 7 ++---
builtin/gc.c | 2 +-
builtin/grep.c | 2 +-
builtin/index-pack.c | 13 +++++-----
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 4 +--
builtin/mktree.c | 8 +++---
builtin/pack-objects.c | 30 ++++++++++++----------
builtin/prune.c | 4 +--
builtin/repack.c | 2 +-
builtin/replace.c | 10 ++++----
builtin/rev-list.c | 6 +++--
builtin/tag.c | 4 +--
builtin/unpack-objects.c | 2 +-
commit-graph.c | 2 +-
commit.c | 3 ++-
diff.c | 18 ++++++-------
fetch-pack.c | 4 +--
list-objects-filter.c | 2 +-
log-tree.c | 2 +-
merge-ort.c | 4 +--
object-file.c | 2 +-
object-file.h | 2 +-
object-name.c | 16 ++++++------
object.c | 6 ++---
odb.c | 60 ++++++++++++++++++++++---------------------
odb.h | 46 +++++++++++++++++++++++++++------
pack-bitmap-write.c | 4 +--
pack-bitmap.c | 8 +++---
packfile.c | 5 ++--
promisor-remote.c | 4 +--
protocol-caps.c | 2 +-
reachable.c | 2 +-
read-cache.c | 6 ++---
ref-filter.c | 4 +--
remote.c | 5 ++--
sequencer.c | 5 ++--
streaming.c | 8 +++---
submodule.c | 5 ++--
t/helper/test-partial-clone.c | 2 +-
tag.c | 2 +-
48 files changed, 213 insertions(+), 170 deletions(-)
diff --git a/archive.c b/archive.c
index 7fa2cc2596a..f2511d530d5 100644
--- a/archive.c
+++ b/archive.c
@@ -215,7 +215,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
/* Stream it? */
if (S_ISREG(mode) && !args->convert &&
- oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
+ odb_read_object_info(args->repo->objects, oid, &size) == OBJ_BLOB &&
size > repo_settings_get_big_file_threshold(the_repository))
return write_entry(args, oid, path.buf, path.len, mode, NULL, size);
diff --git a/blame.c b/blame.c
index 0ceea080a80..97db3355af4 100644
--- a/blame.c
+++ b/blame.c
@@ -116,7 +116,7 @@ static void verify_working_tree_path(struct repository *r,
unsigned short mode;
if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
- oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
+ odb_read_object_info(r->objects, &blob_oid, NULL) == OBJ_BLOB)
return;
}
@@ -1245,7 +1245,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
return 0;
if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
goto error_out;
- if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
+ if (odb_read_object_info(r->objects, &origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out;
return 0;
error_out:
diff --git a/builtin/blame.c b/builtin/blame.c
index 15eda60af90..91586e6852b 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -837,7 +837,7 @@ static int is_a_rev(const char *name)
if (repo_get_oid(the_repository, name, &oid))
return 0;
- return OBJ_NONE < oid_object_info(the_repository, &oid, NULL);
+ return OBJ_NONE < odb_read_object_info(the_repository->objects, &oid, NULL);
}
static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
@@ -848,7 +848,7 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
oidcpy(&oid, oid_ret);
while (1) {
struct object *obj;
- int kind = oid_object_info(r, &oid, NULL);
+ int kind = odb_read_object_info(r->objects, &oid, NULL);
if (kind == OBJ_COMMIT) {
oidcpy(oid_ret, &oid);
return 0;
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 2fa5e3f43bd..da172155c85 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -137,7 +137,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
switch (opt) {
case 't':
oi.type_name = &sb;
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (sb.len) {
printf("%s\n", sb.buf);
@@ -155,7 +155,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
oi.contentp = (void**)&buf;
}
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
@@ -189,7 +189,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
/* else fallthrough */
case 'p':
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("Not a valid object name %s", obj_name);
@@ -226,7 +226,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
if (exp_type_id == OBJ_BLOB) {
struct object_id blob_oid;
- if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
+ if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_TAG) {
char *buffer = repo_read_object_file(the_repository,
&oid,
&type,
@@ -244,7 +245,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
} else
oidcpy(&blob_oid, &oid);
- if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB) {
+ if (odb_read_object_info(the_repository->objects,
+ &blob_oid, NULL) == OBJ_BLOB) {
ret = stream_blob(&blob_oid);
goto cleanup;
}
@@ -303,7 +305,7 @@ struct expand_data {
/*
* After a mark_query run, this object_info is set up to be
- * passed to oid_object_info_extended. It will point to the data
+ * passed to odb_read_object_info_extended. It will point to the data
* elements above, so you can retrieve the response from there.
*/
struct object_info info;
@@ -493,12 +495,12 @@ static void batch_object_write(const char *obj_name,
data->info.sizep = &data->size;
if (pack)
- ret = packed_object_info(the_repository, pack, offset,
- &data->info);
+ ret = packed_object_info(the_repository, pack,
+ offset, &data->info);
else
- ret = oid_object_info_extended(the_repository,
- &data->oid, &data->info,
- OBJECT_INFO_LOOKUP_REPLACE);
+ ret = odb_read_object_info_extended(the_repository->objects,
+ &data->oid, &data->info,
+ OBJECT_INFO_LOOKUP_REPLACE);
if (ret < 0) {
report_object_status(opt, obj_name, &data->oid, "missing");
return;
@@ -881,7 +883,7 @@ static int batch_objects(struct batch_options *opt)
/*
* Expand once with our special mark_query flag, which will prime the
- * object_info to be handed to oid_object_info_extended for each
+ * object_info to be handed to odb_read_object_info_extended for each
* object.
*/
memset(&data, 0, sizeof(data));
diff --git a/builtin/describe.c b/builtin/describe.c
index 96cb68e5e5d..fbf305d7624 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -552,7 +552,8 @@ static void describe(const char *arg, int last_one)
if (cmit)
describe_commit(&oid, &sb);
- else if (oid_object_info(the_repository, &oid, NULL) == OBJ_BLOB)
+ else if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_BLOB)
describe_blob(oid, &sb);
else
die(_("%s is neither a commit nor blob"), arg);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 0505f289a94..6c93cf0a8aa 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -1200,7 +1200,7 @@ static void import_marks(char *input_file, int check_exists)
if (last_idnum < mark)
last_idnum = mark;
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(&oid));
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 413304db9b5..2718376f2c9 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1756,8 +1756,8 @@ static void insert_object_entry(struct mark_set **s, struct object_id *oid, uint
struct object_entry *e;
e = find_object(oid);
if (!e) {
- enum object_type type = oid_object_info(the_repository,
- oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
e = insert_object(oid);
@@ -2416,8 +2416,8 @@ static void file_change_m(const char *p, struct branch *b)
enum object_type expected = S_ISDIR(mode) ?
OBJ_TREE: OBJ_BLOB;
enum object_type type = oe ? oe->type :
- oid_object_info(the_repository, &oid,
- NULL);
+ odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("%s not found: %s",
S_ISDIR(mode) ? "Tree" : "Blob",
@@ -2553,7 +2553,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
die("Not a blob (actually a %s): %s",
type_name(oe->type), command_buf.buf);
} else if (!is_null_oid(&oid)) {
- enum object_type type = oid_object_info(the_repository, &oid,
+ enum object_type type = odb_read_object_info(the_repository->objects, &oid,
NULL);
if (type < 0)
die("Blob not found: %s", command_buf.buf);
@@ -2895,7 +2895,8 @@ static void parse_new_tag(const char *arg)
} else if (!repo_get_oid(the_repository, from, &oid)) {
struct object_entry *oe = find_object(&oid);
if (!oe) {
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("Not a valid object: %s", from);
} else
@@ -3085,8 +3086,8 @@ static struct object_entry *dereference(struct object_entry *oe,
const unsigned hexsz = the_hash_algo->hexsz;
if (!oe) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
/* cache it! */
diff --git a/builtin/fsck.c b/builtin/fsck.c
index ffae00b1723..f1da67eb26b 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -71,7 +71,8 @@ static const char *printable_type(const struct object_id *oid,
const char *ret;
if (type == OBJ_NONE)
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
ret = type_name(type);
if (!ret)
@@ -232,8 +233,8 @@ static void mark_unreachable_referents(const struct object_id *oid)
* (and we want to avoid parsing blobs).
*/
if (obj->type == OBJ_NONE) {
- enum object_type type = oid_object_info(the_repository,
- &obj->oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ &obj->oid, NULL);
if (type > 0)
object_as_type(obj, type, 0);
}
diff --git a/builtin/gc.c b/builtin/gc.c
index ea13660dba1..1876d4b230b 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1006,7 +1006,7 @@ static int dfs_on_ref(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
commit = lookup_commit(the_repository, oid);
diff --git a/builtin/grep.c b/builtin/grep.c
index e9816cce8cd..83da86405fa 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -520,7 +520,7 @@ static int grep_submodule(struct grep_opt *opt,
struct strbuf base = STRBUF_INIT;
obj_read_lock();
- object_type = oid_object_info(subrepo, oid, NULL);
+ object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
data = read_object_with_reference(subrepo,
oid, OBJ_TREE,
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 8e5acefde40..82cf80b89d1 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -260,7 +260,8 @@ static unsigned check_object(struct object *obj)
if (!(obj->flags & FLAG_CHECKED)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects,
+ &obj->oid, &size);
if (type <= 0)
die(_("did not receive expected object %s"),
oid_to_hex(&obj->oid));
@@ -908,7 +909,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
enum object_type has_type;
unsigned long has_size;
read_lock();
- has_type = oid_object_info(the_repository, oid, &has_size);
+ has_type = odb_read_object_info(the_repository->objects, oid, &has_size);
if (has_type < 0)
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
@@ -1495,9 +1496,9 @@ static void fix_unresolved_deltas(struct hashfile *f)
struct oid_array to_fetch = OID_ARRAY_INIT;
for (i = 0; i < nr_ref_deltas; i++) {
struct ref_delta_entry *d = sorted_by_pos[i];
- if (!oid_object_info_extended(the_repository, &d->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &d->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &d->oid);
}
@@ -1823,7 +1824,7 @@ static void repack_local_links(void)
oidset_iter_init(&outgoing_links, &iter);
while ((oid = oidset_iter_next(&iter))) {
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info, 0))
/* Missing; assume it is a promisor object */
continue;
if (info.whence == OI_PACKED && info.u.packed.pack->pack_promisor)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 821339b07d4..ff975e7be06 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -251,7 +251,7 @@ static void expand_objectsize(struct repository *repo, struct strbuf *line,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(repo, oid, &size) < 0)
+ if (odb_read_object_info(repo->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 62b6fd58c16..4d616dd5282 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -27,7 +27,7 @@ static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
@@ -217,7 +217,7 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base,
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
+ if (odb_read_object_info(the_repository->objects, oid, &size) == OBJ_BAD)
xsnprintf(size_text, sizeof(size_text), "BAD");
else
xsnprintf(size_text, sizeof(size_text),
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 016b0e5b224..81df7f6099f 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -124,10 +124,10 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
/* Check the type of object identified by oid without fetching objects */
oi.typep = &obj_type;
- if (oid_object_info_extended(the_repository, &oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_QUICK |
- OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_QUICK |
+ OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
obj_type = -1;
if (obj_type < 0) {
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 99b63cb0980..da35d684081 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2154,10 +2154,10 @@ static void prefetch_to_pack(uint32_t object_index_start) {
for (i = object_index_start; i < to_pack.nr_objects; i++) {
struct object_entry *entry = to_pack.objects + i;
- if (!oid_object_info_extended(the_repository,
- &entry->idx.oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &entry->idx.oid,
+ NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &entry->idx.oid);
}
@@ -2298,19 +2298,19 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
/*
* No choice but to fall back to the recursive delta walk
- * with oid_object_info() to find about the object type
+ * with odb_read_object_info() to find about the object type
* at this point...
*/
give_up:
unuse_pack(&w_curs);
}
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
if (repo_has_promisor_remote(the_repository)) {
prefetch_to_pack(object_index);
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
type = -1;
} else {
type = -1;
@@ -2384,12 +2384,13 @@ static void drop_reused_delta(struct object_entry *entry)
if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
/*
* We failed to get the info from this pack for some reason;
- * fall back to oid_object_info, which may find another copy.
+ * fall back to odb_read_object_info, which may find another copy.
* And if that fails, the error will be recorded in oe_type(entry)
* and dealt with in prepare_pack().
*/
oe_set_type(entry,
- oid_object_info(the_repository, &entry->idx.oid, &size));
+ odb_read_object_info(the_repository->objects,
+ &entry->idx.oid, &size));
} else {
oe_set_type(entry, type);
}
@@ -2677,7 +2678,8 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
packing_data_lock(&to_pack);
- if (oid_object_info(the_repository, &e->idx.oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects,
+ &e->idx.oid, &size) < 0)
die(_("unable to get size of %s"),
oid_to_hex(&e->idx.oid));
packing_data_unlock(&to_pack);
@@ -4063,7 +4065,7 @@ static void add_objects_in_unpacked_packs(void)
static int add_loose_object(const struct object_id *oid, const char *path,
void *data UNUSED)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0) {
warning(_("loose object at %s could not be examined"), path);
@@ -4449,7 +4451,7 @@ static int option_parse_cruft_expiration(const struct option *opt UNUSED,
static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED)
{
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, &obj->oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0))
BUG("should_include_obj should only be called on existing objects");
return info.whence != OI_PACKED || !info.u.packed.pack->pack_promisor;
}
diff --git a/builtin/prune.c b/builtin/prune.c
index 7bbfb14c2be..339017c7ccf 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -99,8 +99,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
if (st.st_mtime > expire)
return 0;
if (show_only || verbose) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? type_name(type) : "unknown");
}
diff --git a/builtin/repack.c b/builtin/repack.c
index 8145474cf8d..a89c2b704fb 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -707,7 +707,7 @@ static int midx_snapshot_ref_one(const char *refname UNUSED,
if (oidset_insert(&data->seen, oid))
return 0; /* already seen */
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
fprintf(data->f->fp, "%s%s\n", data->preferred ? "+" : "",
diff --git a/builtin/replace.c b/builtin/replace.c
index 11c7e2d4c0c..5ff2ab723cb 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -65,8 +65,8 @@ static int show_reference(const char *refname,
if (repo_get_oid(data->repo, refname, &object))
return error(_("failed to resolve '%s' as a valid ref"), refname);
- obj_type = oid_object_info(data->repo, &object, NULL);
- repl_type = oid_object_info(data->repo, oid, NULL);
+ obj_type = odb_read_object_info(data->repo->objects, &object, NULL);
+ repl_type = odb_read_object_info(data->repo->objects, oid, NULL);
printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
oid_to_hex(oid), type_name(repl_type));
@@ -185,8 +185,8 @@ static int replace_object_oid(const char *object_ref,
struct strbuf err = STRBUF_INIT;
int res = 0;
- obj_type = oid_object_info(the_repository, object, NULL);
- repl_type = oid_object_info(the_repository, repl, NULL);
+ obj_type = odb_read_object_info(the_repository->objects, object, NULL);
+ repl_type = odb_read_object_info(the_repository->objects, repl, NULL);
if (!force && obj_type != repl_type)
return error(_("Objects must be of the same type.\n"
"'%s' points to a replaced object of type '%s'\n"
@@ -334,7 +334,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
if (repo_get_oid(the_repository, object_ref, &old_oid) < 0)
return error(_("not a valid object name: '%s'"), object_ref);
- type = oid_object_info(the_repository, &old_oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &old_oid, NULL);
if (type < 0)
return error(_("unable to get object type for %s"),
oid_to_hex(&old_oid));
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index ee25d61c802..eed73f5fc0b 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -110,7 +110,8 @@ static off_t get_object_disk_usage(struct object *obj)
off_t size;
struct object_info oi = OBJECT_INFO_INIT;
oi.disk_sizep = &size;
- if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid));
return size;
}
@@ -346,7 +347,8 @@ static void show_commit(struct commit *commit, void *data)
static int finish_object(struct object *obj, const char *name, void *cb_data)
{
struct rev_list_info *info = cb_data;
- if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, NULL, 0) < 0) {
finish_object__ma(obj, name);
return 1;
}
diff --git a/builtin/tag.c b/builtin/tag.c
index cf2ea4b4993..e0b27396c6b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -304,7 +304,7 @@ static void create_tag(const struct object_id *object, const char *object_ref,
struct strbuf header = STRBUF_INIT;
int should_edit;
- type = oid_object_info(the_repository, object, NULL);
+ type = odb_read_object_info(the_repository->objects, object, NULL);
if (type <= OBJ_NONE)
die(_("bad object type."));
@@ -401,7 +401,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
}
strbuf_addstr(sb, " (");
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
switch (type) {
default:
strbuf_addstr(sb, "object of unknown type");
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 7bf395eec84..405e78bc592 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -232,7 +232,7 @@ static int check_object(struct object *obj, enum object_type type,
if (!(obj->flags & FLAG_OPEN)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects, &obj->oid, &size);
if (type != obj->type || type <= 0)
die("object of unexpected type");
obj->flags |= FLAG_WRITTEN;
diff --git a/commit-graph.c b/commit-graph.c
index ff72f7e32ae..9c2740a8cab 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1862,7 +1862,7 @@ static int add_ref_to_set(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) == OBJ_COMMIT)
oidset_insert(data->commits, oid);
display_progress(data->progress, oidset_size(data->commits));
diff --git a/commit.c b/commit.c
index aa65183d8b6..d4aa9c7a5f8 100644
--- a/commit.c
+++ b/commit.c
@@ -585,7 +585,8 @@ int repo_parse_commit_internal(struct repository *r,
return 0;
}
- if (oid_object_info_extended(r, &item->object.oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(r->objects, &item->object.oid,
+ &oi, flags) < 0)
return quiet_on_missing ? -1 :
error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/diff.c b/diff.c
index 193da8bee68..75cfedf18a5 100644
--- a/diff.c
+++ b/diff.c
@@ -4230,14 +4230,14 @@ int diff_populate_filespec(struct repository *r,
info.contentp = &s->data;
if (options && options->missing_object_cb) {
- if (!oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_SKIP_FETCH_OBJECT))
+ if (!odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_SKIP_FETCH_OBJECT))
goto object_read;
options->missing_object_cb(options->missing_object_data);
}
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
object_read:
@@ -4252,8 +4252,8 @@ int diff_populate_filespec(struct repository *r,
}
if (!info.contentp) {
info.contentp = &s->data;
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
}
s->should_free = 1;
@@ -7019,8 +7019,8 @@ void diff_add_if_missing(struct repository *r,
{
if (filespec && filespec->oid_valid &&
!S_ISGITLINK(filespec->mode) &&
- oid_object_info_extended(r, &filespec->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(r->objects, &filespec->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(to_fetch, &filespec->oid);
}
diff --git a/fetch-pack.c b/fetch-pack.c
index 47fa7fa4c49..0f5de1c94d1 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -149,8 +149,8 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
}
while (1) {
- if (oid_object_info_extended(the_repository, oid, &info,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
return NULL;
if (type == OBJ_TAG) {
struct tag *tag = (struct tag *)
diff --git a/list-objects-filter.c b/list-objects-filter.c
index cb9c16734b1..ec7aebaffd0 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -310,7 +310,7 @@ static enum list_objects_filter_result filter_blobs_limit(
assert(obj->type == OBJ_BLOB);
assert((obj->flags & SEEN) == 0);
- t = oid_object_info(r, &obj->oid, &object_length);
+ t = odb_read_object_info(r->objects, &obj->oid, &object_length);
if (t != OBJ_BLOB) { /* probably OBJ_NONE */
/*
* We DO NOT have the blob locally, so we cannot
diff --git a/log-tree.c b/log-tree.c
index 1d05dc1c701..233bf9f227c 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -176,7 +176,7 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
return 0;
}
- objtype = oid_object_info(the_repository, oid, NULL);
+ objtype = odb_read_object_info(the_repository->objects, oid, NULL);
if (objtype < 0)
return 0;
obj = lookup_object_by_type(the_repository, oid, objtype);
diff --git a/merge-ort.c b/merge-ort.c
index f86c84635f0..5d4501085e9 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -4374,8 +4374,8 @@ static void prefetch_for_content_merges(struct merge_options *opt,
if ((ci->filemask & side_mask) &&
S_ISREG(vi->mode) &&
- oid_object_info_extended(opt->repo, &vi->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(opt->repo->objects, &vi->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&to_fetch, &vi->oid);
}
}
diff --git a/object-file.c b/object-file.c
index c70a3fc317a..25db71dc1e6 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1211,7 +1211,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
oi.typep = &type;
oi.sizep = &len;
oi.contentp = &buf;
- if (oid_object_info_extended(the_repository, oid, &oi, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &oi, 0))
return error(_("cannot read object for %s"), oid_to_hex(oid));
if (compat) {
if (repo_oid_to_algop(repo, oid, compat, &compat_oid))
diff --git a/object-file.h b/object-file.h
index aff33f61bb4..c7a559a0502 100644
--- a/object-file.h
+++ b/object-file.h
@@ -8,7 +8,7 @@
struct index_state;
/*
- * Set this to 0 to prevent oid_object_info_extended() from fetching missing
+ * Set this to 0 to prevent odb_read_object_info_extended() from fetching missing
* blobs. This has a difference only if extensions.partialClone is set.
*
* Its default value is 1.
diff --git a/object-name.c b/object-name.c
index 919a3e7a9f8..1745f97757c 100644
--- a/object-name.c
+++ b/object-name.c
@@ -251,7 +251,7 @@ static int disambiguate_commit_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_COMMIT;
}
@@ -262,7 +262,7 @@ static int disambiguate_committish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -279,7 +279,7 @@ static int disambiguate_tree_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_TREE;
}
@@ -290,7 +290,7 @@ static int disambiguate_treeish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_TREE || kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -307,7 +307,7 @@ static int disambiguate_blob_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_BLOB;
}
@@ -399,7 +399,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
return 0;
hash = repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV);
- type = oid_object_info(ds->repo, oid, NULL);
+ type = odb_read_object_info(ds->repo->objects, oid, NULL);
if (type < 0) {
/*
@@ -514,8 +514,8 @@ static int sort_ambiguous(const void *va, const void *vb, void *ctx)
{
struct repository *sort_ambiguous_repo = ctx;
const struct object_id *a = va, *b = vb;
- int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
- int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
+ int a_type = odb_read_object_info(sort_ambiguous_repo->objects, a, NULL);
+ int b_type = odb_read_object_info(sort_ambiguous_repo->objects, b, NULL);
int a_type_sort;
int b_type_sort;
diff --git a/object.c b/object.c
index 3b15469139d..868d89eed42 100644
--- a/object.c
+++ b/object.c
@@ -214,7 +214,7 @@ enum peel_status peel_object(struct repository *r,
struct object *o = lookup_unknown_object(r, name);
if (o->type == OBJ_NONE) {
- int type = oid_object_info(r, name, NULL);
+ int type = odb_read_object_info(r->objects, name, NULL);
if (type < 0 || !object_as_type(o, type, 0))
return PEEL_INVALID;
}
@@ -315,7 +315,7 @@ struct object *parse_object_with_flags(struct repository *r,
}
if ((!obj || obj->type == OBJ_BLOB) &&
- oid_object_info(r, oid, NULL) == OBJ_BLOB) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
if (!skip_hash && stream_object_signature(r, repl) < 0) {
error(_("hash mismatch %s"), oid_to_hex(oid));
return NULL;
@@ -331,7 +331,7 @@ struct object *parse_object_with_flags(struct repository *r,
*/
if (skip_hash && discard_tree &&
(!obj || obj->type == OBJ_TREE) &&
- oid_object_info(r, oid, NULL) == OBJ_TREE) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_TREE) {
return &lookup_tree(r, oid)->object;
}
diff --git a/odb.c b/odb.c
index 8901e3f43a3..919b8772f86 100644
--- a/odb.c
+++ b/odb.c
@@ -647,7 +647,7 @@ static int register_all_submodule_backends(struct object_database *odb)
return ret;
}
-static int do_oid_object_info_extended(struct repository *r,
+static int do_oid_object_info_extended(struct object_database *odb,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
{
@@ -660,7 +660,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
- real = lookup_replace_object(r, oid);
+ real = lookup_replace_object(odb->repo, oid);
if (is_null_oid(real))
return -1;
@@ -668,7 +668,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (!oi)
oi = &blank_oi;
- co = find_cached_object(r->objects, real);
+ co = find_cached_object(odb, real);
if (co) {
if (oi->typep)
*(oi->typep) = co->type;
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, r->hash_algo);
+ oidclr(oi->delta_base_oid, odb->repo->hash_algo);
if (oi->type_name)
strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
@@ -687,17 +687,17 @@ static int do_oid_object_info_extended(struct repository *r,
}
while (1) {
- if (find_pack_entry(r, real, &e))
+ if (find_pack_entry(odb->repo, real, &e))
break;
/* Most likely it's a loose object. */
- if (!loose_object_info(r, real, oi, flags))
+ if (!loose_object_info(odb->repo, real, oi, flags))
return 0;
/* Not a loose object; someone else may have just packed it. */
if (!(flags & OBJECT_INFO_QUICK)) {
- reprepare_packed_git(r);
- if (find_pack_entry(r, real, &e))
+ reprepare_packed_git(odb->repo);
+ if (find_pack_entry(odb->repo, real, &e))
break;
}
@@ -707,15 +707,15 @@ static int do_oid_object_info_extended(struct repository *r,
* `odb_add_submodule_backend_by_path()` on that submodule's
* ODB). If any such ODBs exist, register them and try again.
*/
- if (register_all_submodule_backends(r->objects))
+ if (register_all_submodule_backends(odb))
/* We added some alternates; retry */
continue;
/* Check if it is a missing object */
- if (fetch_if_missing && repo_has_promisor_remote(r) &&
+ if (fetch_if_missing && repo_has_promisor_remote(odb->repo) &&
!already_retried &&
!(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) {
- promisor_remote_get_direct(r, real, 1);
+ promisor_remote_get_direct(odb->repo, real, 1);
already_retried = 1;
continue;
}
@@ -725,7 +725,7 @@ static int do_oid_object_info_extended(struct repository *r,
if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid))
die(_("replacement %s not found for %s"),
oid_to_hex(real), oid_to_hex(oid));
- if ((p = has_packed_and_bad(r, real)))
+ if ((p = has_packed_and_bad(odb->repo, real)))
die(_("packed object %s (stored in %s) is corrupt"),
oid_to_hex(real), p->pack_name);
}
@@ -738,10 +738,10 @@ static int do_oid_object_info_extended(struct repository *r,
* information below, so return early.
*/
return 0;
- rtype = packed_object_info(r, e.p, e.offset, oi);
+ rtype = packed_object_info(odb->repo, e.p, e.offset, oi);
if (rtype < 0) {
mark_bad_packed_object(e.p, real);
- return do_oid_object_info_extended(r, real, oi, 0);
+ return do_oid_object_info_extended(odb, real, oi, 0);
} else if (oi->whence == OI_PACKED) {
oi->u.packed.offset = e.offset;
oi->u.packed.pack = e.p;
@@ -789,7 +789,7 @@ static int oid_object_info_convert(struct repository *r,
oi = &new_oi;
}
- ret = oid_object_info_extended(r, &oid, oi, flags);
+ ret = odb_read_object_info_extended(r->objects, &oid, oi, flags);
if (ret)
return -1;
if (oi == input_oi)
@@ -839,33 +839,35 @@ static int oid_object_info_convert(struct repository *r,
return ret;
}
-int oid_object_info_extended(struct repository *r, const struct object_id *oid,
- struct object_info *oi, unsigned flags)
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
{
int ret;
- if (oid->algo && (hash_algo_by_ptr(r->hash_algo) != oid->algo))
- return oid_object_info_convert(r, oid, oi, flags);
+ if (oid->algo && (hash_algo_by_ptr(odb->repo->hash_algo) != oid->algo))
+ return oid_object_info_convert(odb->repo, oid, oi, flags);
obj_read_lock();
- ret = do_oid_object_info_extended(r, oid, oi, flags);
+ ret = do_oid_object_info_extended(odb, oid, oi, flags);
obj_read_unlock();
return ret;
}
/* returns enum object_type or negative */
-int oid_object_info(struct repository *r,
- const struct object_id *oid,
- unsigned long *sizep)
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep)
{
enum object_type type;
struct object_info oi = OBJECT_INFO_INIT;
oi.typep = &type;
oi.sizep = sizep;
- if (oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(odb, oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE) < 0)
return -1;
return type;
}
@@ -896,7 +898,7 @@ int pretend_object_file(struct repository *repo,
/*
* This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call oid_object_info_extended() and give
+ * deal with them should arrange to call odb_read_object_info_extended() and give
* error messages themselves.
*/
void *repo_read_object_file(struct repository *r,
@@ -911,7 +913,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (oid_object_info_extended(r, oid, &oi, flags))
+ if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
return NULL;
return data;
@@ -977,13 +979,13 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(odb->repo, oid, NULL);
+ enum object_type type = odb_read_object_info(odb, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index 1558f467425..2613f2c6c03 100644
--- a/odb.h
+++ b/odb.h
@@ -252,9 +252,6 @@ void *repo_read_object_file(struct repository *r,
enum object_type *type,
unsigned long *size);
-/* Read and unpack an object file into memory, write memory to an object file */
-int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
-
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -326,9 +323,24 @@ struct object_info {
/* Die if object corruption (not just an object being missing) was detected. */
#define OBJECT_INFO_DIE_IF_CORRUPT 32
-int oid_object_info_extended(struct repository *r,
- const struct object_id *,
- struct object_info *, unsigned flags);
+/*
+ * Read object info from the object database and populate the `object_info`
+ * structure. Returns 0 on success, a negative error code otherwise.
+ */
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags);
+
+/*
+ * Read a subset of object info for the given object ID. Returns an `enum
+ * object_type` on success, a negative error code otherwise. If successful and
+ * `sizep` is non-NULL, then the size of the object will be written to the
+ * pointer.
+ */
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep);
enum {
/* Retry packed storage after checking packed and loose storage */
@@ -350,7 +362,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: repo_read_object_file(),
- * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
+ * read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -358,7 +370,7 @@ void odb_assert_oid_type(struct object_database *odb,
* reading functions. However, beware that in these cases zlib inflation won't
* be performed in parallel, losing performance.
*
- * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
+ * TODO: odb_read_object_info_extended()'s call stack has a recursive behavior. If
* any of its callees end up calling it, this recursive call won't benefit from
* parallel inflation.
*/
@@ -406,4 +418,22 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
+/* Compatibility wrappers, to be removed once Git 2.50 has been released. */
+#include "repository.h"
+
+static inline int oid_object_info_extended(struct repository *r,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
+{
+ return odb_read_object_info_extended(r->objects, oid, oi, flags);
+}
+
+static inline int oid_object_info(struct repository *r,
+ const struct object_id *oid,
+ unsigned long *sizep)
+{
+ return odb_read_object_info(r->objects, oid, sizep);
+}
+
#endif /* ODB_H */
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index c847369eaaa..c5183b619c1 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -144,8 +144,8 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
break;
default:
- real_type = oid_object_info(writer->to_pack->repo,
- &entry->idx.oid, NULL);
+ real_type = odb_read_object_info(writer->to_pack->repo->objects,
+ &entry->idx.oid, NULL);
break;
}
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 467a3e91035..0bd6f1c282f 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1868,8 +1868,8 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
size_t eindex_pos = pos - bitmap_num_objects_total(bitmap_git);
struct eindex *eindex = &bitmap_git->ext_index;
struct object *obj = eindex->objects[eindex_pos];
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects, &obj->oid,
+ &oi, 0) < 0)
die(_("unable to get size of %s"), oid_to_hex(&obj->oid));
}
@@ -3220,8 +3220,8 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)
i)))
continue;
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of '%s'"),
oid_to_hex(&obj->oid));
diff --git a/packfile.c b/packfile.c
index 263056a6279..61920744168 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1310,7 +1310,7 @@ static int retry_bad_packed_offset(struct repository *r,
return OBJ_BAD;
nth_packed_object_id(&oid, p, pack_pos_to_index(p, pos));
mark_bad_packed_object(p, &oid);
- type = oid_object_info(r, &oid, NULL);
+ type = odb_read_object_info(r->objects, &oid, NULL);
if (type <= OBJ_NONE)
return OBJ_BAD;
return type;
@@ -1843,7 +1843,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
oi.typep = &type;
oi.sizep = &base_size;
oi.contentp = &base;
- if (oid_object_info_extended(r, &base_oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(r->objects, &base_oid,
+ &oi, 0) < 0)
base = NULL;
external_base = base;
diff --git a/promisor-remote.c b/promisor-remote.c
index 2baa286bfd0..be6f82d12f8 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -245,8 +245,8 @@ static int remove_fetched_oids(struct repository *repo,
struct object_id *new_oids;
for (i = 0; i < oid_nr; i++)
- if (oid_object_info_extended(repo, &old_oids[i], NULL,
- OBJECT_INFO_SKIP_FETCH_OBJECT)) {
+ if (odb_read_object_info_extended(repo->objects, &old_oids[i], NULL,
+ OBJECT_INFO_SKIP_FETCH_OBJECT)) {
remaining[i] = 1;
remaining_nr++;
}
diff --git a/protocol-caps.c b/protocol-caps.c
index 3022f69a1bd..ecdd0dc58d5 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -64,7 +64,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
strbuf_addstr(&send_buffer, oid_str);
if (info->size) {
- if (oid_object_info(r, &oid, &object_size) < 0) {
+ if (odb_read_object_info(r->objects, &oid, &object_size) < 0) {
strbuf_addstr(&send_buffer, " ");
} else {
strbuf_addf(&send_buffer, " %lu", object_size);
diff --git a/reachable.c b/reachable.c
index 9dc748f0b9a..e984b68a0c4 100644
--- a/reachable.c
+++ b/reachable.c
@@ -211,7 +211,7 @@ static void add_recent_object(const struct object_id *oid,
* later processing, and the revision machinery expects
* commits and tags to have been parsed.
*/
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0)
die("unable to get object info for %s", oid_to_hex(oid));
diff --git a/read-cache.c b/read-cache.c
index dce1056ec7c..be664f857b4 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3758,9 +3758,9 @@ void prefetch_cache_entries(const struct index_state *istate,
if (S_ISGITLINK(ce->ce_mode) || !must_prefetch(ce))
continue;
- if (!oid_object_info_extended(the_repository, &ce->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &ce->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &ce->oid);
}
diff --git a/ref-filter.c b/ref-filter.c
index 4ce45440ad1..f9f2c512a8c 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2302,8 +2302,8 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
oi->info.sizep = &oi->size;
oi->info.typep = &oi->type;
}
- if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(the_repository->objects, &oi->oid, &oi->info,
+ OBJECT_INFO_LOOKUP_REPLACE))
return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
oid_to_hex(&oi->oid), ref->refname);
if (oi->info.disk_sizep && oi->disk_size < 0)
diff --git a/remote.c b/remote.c
index 17a842f5684..72c36239d31 100644
--- a/remote.c
+++ b/remote.c
@@ -1182,7 +1182,7 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
BUG("'%s' is not a valid object, "
"match_explicit_lhs() should catch this!",
matched_src_name);
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type == OBJ_COMMIT) {
advise(_("The <src> part of the refspec is a commit object.\n"
"Did you mean to create a new branch by pushing to\n"
@@ -1412,7 +1412,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
continue; /* not a tag */
if (string_list_has_string(&dst_tag, ref->name))
continue; /* they already have it */
- if (oid_object_info(the_repository, &ref->new_oid, NULL) != OBJ_TAG)
+ if (odb_read_object_info(the_repository->objects,
+ &ref->new_oid, NULL) != OBJ_TAG)
continue; /* be conservative */
item = string_list_append(&src_tag, ref->name);
item->util = ref;
diff --git a/sequencer.c b/sequencer.c
index 35f4e68d59f..bb012a4bfd9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5502,9 +5502,8 @@ int sequencer_pick_revisions(struct repository *r,
if (!repo_get_oid(r, name, &oid)) {
if (!lookup_commit_reference_gently(r, &oid, 1)) {
- enum object_type type = oid_object_info(r,
- &oid,
- NULL);
+ enum object_type type = odb_read_object_info(r->objects,
+ &oid, NULL);
res = error(_("%s: can't cherry-pick a %s"),
name, type_name(type));
goto out;
diff --git a/streaming.c b/streaming.c
index 29cc877f22a..032f134dc10 100644
--- a/streaming.c
+++ b/streaming.c
@@ -44,7 +44,7 @@ struct git_istream {
union {
struct {
- char *buf; /* from oid_object_info_extended() */
+ char *buf; /* from odb_read_object_info_extended() */
unsigned long read_ptr;
} incore;
@@ -403,8 +403,8 @@ static int open_istream_incore(struct git_istream *st, struct repository *r,
oi.typep = type;
oi.sizep = &st->size;
oi.contentp = (void **)&st->u.incore.buf;
- return oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_DIE_IF_CORRUPT);
+ return odb_read_object_info_extended(r->objects, oid, &oi,
+ OBJECT_INFO_DIE_IF_CORRUPT);
}
/*****************************************************************************
@@ -422,7 +422,7 @@ static int istream_source(struct git_istream *st,
oi.typep = type;
oi.sizep = &size;
- status = oid_object_info_extended(r, oid, &oi, 0);
+ status = odb_read_object_info_extended(r->objects, oid, &oi, 0);
if (status < 0)
return status;
diff --git a/submodule.c b/submodule.c
index 788c9e55ed3..f8373a9ea7d 100644
--- a/submodule.c
+++ b/submodule.c
@@ -968,7 +968,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
return 0;
}
- type = oid_object_info(&subrepo, oid, NULL);
+ type = odb_read_object_info(subrepo.objects, oid, NULL);
switch (type) {
case OBJ_COMMIT:
@@ -1752,8 +1752,7 @@ static int fetch_start_failure(struct strbuf *err UNUSED,
static int commit_missing_in_sub(const struct object_id *oid, void *data)
{
struct repository *subrepo = data;
-
- enum object_type type = oid_object_info(subrepo, oid, NULL);
+ enum object_type type = odb_read_object_info(subrepo->objects, oid, NULL);
return type != OBJ_COMMIT;
}
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index dba227259a2..d8488007493 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -23,7 +23,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
die("could not init repo");
if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
die("could not parse oid");
- if (oid_object_info_extended(&r, &oid, &oi, 0))
+ if (odb_read_object_info_extended(r.objects, &oid, &oi, 0))
die("could not obtain object info");
printf("%d\n", (int) size);
diff --git a/tag.c b/tag.c
index 5f6868bf7b1..144048fd5e0 100644
--- a/tag.c
+++ b/tag.c
@@ -52,7 +52,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
unsigned long size;
int ret;
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type != OBJ_TAG)
return error("%s: cannot verify a non-tag object of type %s.",
name_to_report ?
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH 14/17] odb: rename `repo_read_object_file()`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (12 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-06 11:09 ` [PATCH 15/17] odb: rename `has_object()` Patrick Steinhardt
` (9 subsequent siblings)
23 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
Rename `repo_read_object_file()` to `odb_read_object()` to match other
functions related to the object database and our modern coding
guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 10 +++++-----
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 6 +++---
blame.c | 13 ++++++-------
builtin/cat-file.c | 26 +++++++++++---------------
builtin/difftool.c | 2 +-
builtin/fast-export.c | 6 +++---
builtin/fast-import.c | 8 ++++----
builtin/grep.c | 8 ++++----
builtin/index-pack.c | 8 ++++----
builtin/log.c | 2 +-
builtin/merge-tree.c | 12 ++++++------
builtin/mktag.c | 4 ++--
builtin/notes.c | 6 +++---
builtin/pack-objects.c | 30 +++++++++++++++---------------
builtin/tag.c | 4 ++--
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 4 ++--
bundle.c | 2 +-
combine-diff.c | 2 +-
commit.c | 6 +++---
config.c | 2 +-
dir.c | 2 +-
entry.c | 4 ++--
fmt-merge-msg.c | 4 ++--
fsck.c | 2 +-
grep.c | 4 ++--
http-push.c | 4 ++--
mailmap.c | 2 +-
match-trees.c | 4 ++--
merge-blobs.c | 8 ++++----
merge-ort.c | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 13 +++++++------
object.c | 2 +-
odb.c | 19 +++++++------------
odb.h | 29 +++++++++++++++++++++++------
read-cache.c | 6 +++---
reflog.c | 4 ++--
rerere.c | 5 ++---
submodule-config.c | 4 ++--
tag.c | 6 +++---
tree-walk.c | 6 +++---
tree.c | 4 ++--
xdiff-interface.c | 2 +-
47 files changed, 157 insertions(+), 150 deletions(-)
diff --git a/apply.c b/apply.c
index 879f04df31e..56cd0540350 100644
--- a/apply.c
+++ b/apply.c
@@ -3210,8 +3210,8 @@ static int apply_binary(struct apply_state *state,
unsigned long size;
char *result;
- result = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ result = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!result)
return error(_("the necessary postimage %s for "
"'%s' cannot be read"),
@@ -3273,8 +3273,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
unsigned long sz;
char *result;
- result = repo_read_object_file(the_repository, oid, &type,
- &sz);
+ result = odb_read_object(the_repository->objects, oid,
+ &type, &sz);
if (!result)
return -1;
/* XXX read_sha1_file NUL-terminates */
@@ -3503,7 +3503,7 @@ static int resolve_to(struct image *image, const struct object_id *result_id)
image_clear(image);
- data = repo_read_object_file(the_repository, result_id, &type, &size);
+ data = odb_read_object(the_repository->objects, result_id, &type, &size);
if (!data || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(result_id));
strbuf_attach(&image->buf, data, size, size + 1);
diff --git a/archive.c b/archive.c
index f2511d530d5..f5a9d45c8d3 100644
--- a/archive.c
+++ b/archive.c
@@ -98,7 +98,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
(args->tree ? &args->tree->object.oid : NULL), oid);
path += args->baselen;
- buffer = repo_read_object_file(the_repository, oid, type, sizep);
+ buffer = odb_read_object(the_repository->objects, oid, type, sizep);
if (buffer && S_ISREG(mode)) {
struct strbuf buf = STRBUF_INIT;
size_t size = 0;
diff --git a/attr.c b/attr.c
index e5680db7f65..d1daeb0b4d9 100644
--- a/attr.c
+++ b/attr.c
@@ -779,7 +779,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
if (get_tree_entry(istate->repo, tree_oid, path, &oid, &mode))
return NULL;
- buf = repo_read_object_file(istate->repo, &oid, &type, &sz);
+ buf = odb_read_object(istate->repo->objects, &oid, &type, &sz);
if (!buf || type != OBJ_BLOB) {
free(buf);
return NULL;
diff --git a/bisect.c b/bisect.c
index a7939216d00..f24474542ec 100644
--- a/bisect.c
+++ b/bisect.c
@@ -155,9 +155,9 @@ static void show_list(const char *debug, int counted, int nr,
unsigned commit_flags = commit->object.flags;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository,
- &commit->object.oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects,
+ &commit->object.oid, &type,
+ &size);
const char *subject_start;
int subject_len;
diff --git a/blame.c b/blame.c
index 97db3355af4..858d2d74df9 100644
--- a/blame.c
+++ b/blame.c
@@ -1041,9 +1041,9 @@ static void fill_origin_blob(struct diff_options *opt,
&o->blob_oid, 1, &file->ptr, &file_size))
;
else
- file->ptr = repo_read_object_file(the_repository,
- &o->blob_oid, &type,
- &file_size);
+ file->ptr = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &file_size);
file->size = file_size;
if (!file->ptr)
@@ -2869,10 +2869,9 @@ void setup_scoreboard(struct blame_scoreboard *sb,
&sb->final_buf_size))
;
else
- sb->final_buf = repo_read_object_file(the_repository,
- &o->blob_oid,
- &type,
- &sb->final_buf_size);
+ sb->final_buf = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &sb->final_buf_size);
if (!sb->final_buf)
die(_("cannot read blob %s for path %s"),
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index da172155c85..d6b9afca06e 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -74,7 +74,7 @@ static int filter_object(const char *path, unsigned mode,
{
enum object_type type;
- *buf = repo_read_object_file(the_repository, oid, &type, size);
+ *buf = odb_read_object(the_repository->objects, oid, &type, size);
if (!*buf)
return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path);
@@ -206,8 +206,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
ret = stream_blob(&oid);
goto cleanup;
}
- buf = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!buf)
die("Cannot read object %s", obj_name);
@@ -228,10 +228,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
struct object_id blob_oid;
if (odb_read_object_info(the_repository->objects,
&oid, NULL) == OBJ_TAG) {
- char *buffer = repo_read_object_file(the_repository,
- &oid,
- &type,
- &size);
+ char *buffer = odb_read_object(the_repository->objects,
+ &oid, &type, &size);
const char *target;
if (!buffer)
@@ -412,10 +410,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
if (!textconv_object(the_repository,
data->rest, 0100644, oid,
1, &contents, &size))
- contents = repo_read_object_file(the_repository,
- oid,
- &type,
- &size);
+ contents = odb_read_object(the_repository->objects,
+ oid, &type, &size);
if (!contents)
die("could not convert '%s' %s",
oid_to_hex(oid), data->rest);
@@ -432,8 +428,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
unsigned long size;
void *contents;
- contents = repo_read_object_file(the_repository, oid, &type,
- &size);
+ contents = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!contents)
die("object %s disappeared", oid_to_hex(oid));
@@ -542,8 +538,8 @@ static void batch_object_write(const char *obj_name,
size_t s = data->size;
char *buf = NULL;
- buf = repo_read_object_file(the_repository, &data->oid, &data->type,
- &data->size);
+ buf = odb_read_object(the_repository->objects, &data->oid,
+ &data->type, &data->size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&data->oid));
buf = replace_idents_using_mailmap(buf, &s);
diff --git a/builtin/difftool.c b/builtin/difftool.c
index fac613e3bc3..e4bc1f83169 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -320,7 +320,7 @@ static char *get_symlink(struct repository *repo,
} else {
enum object_type type;
unsigned long size;
- data = repo_read_object_file(repo, oid, &type, &size);
+ data = odb_read_object(repo->objects, oid, &type, &size);
if (!data)
die(_("could not read object %s for symlink %s"),
oid_to_hex(oid), path);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 6c93cf0a8aa..33f304dd0ad 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -323,7 +323,7 @@ static void export_blob(const struct object_id *oid)
object = (struct object *)lookup_blob(the_repository, oid);
eaten = 0;
} else {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
die("could not read blob %s", oid_to_hex(oid));
if (check_object_signature(the_repository, oid, buf, size,
@@ -869,8 +869,8 @@ static void handle_tag(const char *name, struct tag *tag)
return;
}
- buf = repo_read_object_file(the_repository, &tag->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &tag->object.oid,
+ &type, &size);
if (!buf)
die("could not read tag %s", oid_to_hex(&tag->object.oid));
message = memmem(buf, size, "\n\n", 2);
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 2718376f2c9..1973c504e25 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1265,7 +1265,7 @@ static void load_tree(struct tree_entry *root)
die("Can't load tree %s", oid_to_hex(oid));
} else {
enum object_type type;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_TREE)
die("Can't load tree %s", oid_to_hex(oid));
}
@@ -3002,7 +3002,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
char *buf;
if (!oe || oe->pack_id == MAX_PACK_ID) {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
} else {
type = oe->type;
buf = gfi_unpack_entry(oe, &size);
@@ -3110,8 +3110,8 @@ static struct object_entry *dereference(struct object_entry *oe,
buf = gfi_unpack_entry(oe, &size);
} else {
enum object_type unused;
- buf = repo_read_object_file(the_repository, oid, &unused,
- &size);
+ buf = odb_read_object(the_repository->objects, oid,
+ &unused, &size);
}
if (!buf)
die("Can't load object %s", oid_to_hex(oid));
diff --git a/builtin/grep.c b/builtin/grep.c
index 83da86405fa..45681579b6d 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -573,8 +573,8 @@ static int grep_cache(struct grep_opt *opt,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository, &ce->oid,
- &type, &size);
+ data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &size);
if (!data)
die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
init_tree_desc(&tree, &ce->oid, data, size);
@@ -666,8 +666,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository,
- &entry.oid, &type, &size);
+ data = odb_read_object(the_repository->objects,
+ &entry.oid, &type, &size);
if (!data)
die(_("unable to read tree (%s)"),
oid_to_hex(&entry.oid));
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 82cf80b89d1..d33392cab65 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -914,8 +914,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
- has_data = repo_read_object_file(the_repository, oid,
- &has_type, &has_size);
+ has_data = odb_read_object(the_repository->objects, oid,
+ &has_type, &has_size);
read_unlock();
if (!data)
data = new_data = get_data_from_pack(obj_entry);
@@ -1515,8 +1515,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue;
- data = repo_read_object_file(the_repository, &d->oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &d->oid,
+ &type, &size);
if (!data)
continue;
diff --git a/builtin/log.c b/builtin/log.c
index fe9cc5ebecb..f2040b18159 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -714,7 +714,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
unsigned long offset = 0;
if (!buf)
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 709ae3966a6..21fb0b2df1d 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -75,9 +75,9 @@ static void *result(struct merge_list *entry, unsigned long *size)
const char *path = entry->path;
if (!entry->stage)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid, &type,
- size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid, &type,
+ size);
base = NULL;
if (entry->stage == 1) {
base = entry->blob;
@@ -100,9 +100,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)
enum object_type type;
while (entry) {
if (entry->stage == 2)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid,
+ &type, size);
entry = entry->link;
}
return NULL;
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 1809b38f937..1b391119de8 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -54,8 +54,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
void *buffer;
const struct object_id *repl;
- buffer = repo_read_object_file(the_repository, tagged_oid, &type,
- &size);
+ buffer = odb_read_object(the_repository->objects, tagged_oid,
+ &type, &size);
if (!buffer)
die(_("could not read tagged object '%s'"),
oid_to_hex(tagged_oid));
diff --git a/builtin/notes.c b/builtin/notes.c
index 783d4932ca6..a9529b1696a 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -152,7 +152,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (buf) {
if (size)
write_or_die(fd, buf, size);
@@ -319,7 +319,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
strbuf_init(&msg->buf, 0);
if (repo_get_oid(the_repository, arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
- if (!(value = repo_read_object_file(the_repository, &object, &type, &len)))
+ if (!(value = odb_read_object(the_repository->objects, &object, &type, &len)))
die(_("failed to read object '%s'."), arg);
if (type != OBJ_BLOB) {
strbuf_release(&msg->buf);
@@ -722,7 +722,7 @@ static int append_edit(int argc, const char **argv, const char *prefix,
unsigned long size;
enum object_type type;
struct strbuf buf = STRBUF_INIT;
- char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
+ char *prev_buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!prev_buf)
die(_("unable to read %s"), oid_to_hex(note));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index da35d684081..580a5c1996b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -337,13 +337,13 @@ static void *get_delta(struct object_entry *entry)
void *buf, *base_buf, *delta_buf;
enum object_type type;
- buf = repo_read_object_file(the_repository, &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &entry->idx.oid,
+ &type, &size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
- base_buf = repo_read_object_file(the_repository,
- &DELTA(entry)->idx.oid, &type,
- &base_size);
+ base_buf = odb_read_object(the_repository->objects,
+ &DELTA(entry)->idx.oid, &type,
+ &base_size);
if (!base_buf)
die("unable to read %s",
oid_to_hex(&DELTA(entry)->idx.oid));
@@ -506,9 +506,9 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
&size, NULL)) != NULL)
buf = NULL;
else {
- buf = repo_read_object_file(the_repository,
- &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects,
+ &entry->idx.oid, &type,
+ &size);
if (!buf)
die(_("unable to read %s"),
oid_to_hex(&entry->idx.oid));
@@ -1895,7 +1895,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
/* Did not find one. Either we got a bogus request or
* we need to read and perhaps cache.
*/
- data = repo_read_object_file(the_repository, oid, &type, &size);
+ data = odb_read_object(the_repository->objects, oid, &type, &size);
if (!data)
return NULL;
if (type != OBJ_TREE) {
@@ -2762,9 +2762,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
/* Load data if not already done */
if (!trg->data) {
packing_data_lock(&to_pack);
- trg->data = repo_read_object_file(the_repository,
- &trg_entry->idx.oid, &type,
- &sz);
+ trg->data = odb_read_object(the_repository->objects,
+ &trg_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!trg->data)
die(_("object %s cannot be read"),
@@ -2777,9 +2777,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
}
if (!src->data) {
packing_data_lock(&to_pack);
- src->data = repo_read_object_file(the_repository,
- &src_entry->idx.oid, &type,
- &sz);
+ src->data = odb_read_object(the_repository->objects,
+ &src_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!src->data) {
if (src_entry->preferred_base) {
diff --git a/builtin/tag.c b/builtin/tag.c
index e0b27396c6b..46cbf892e34 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -244,7 +244,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
struct strbuf payload = STRBUF_INIT;
struct strbuf signature = STRBUF_INIT;
- orig = buf = repo_read_object_file(the_repository, oid, &type, &size);
+ orig = buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return;
if (parse_signature(buf, size, &payload, &signature)) {
@@ -407,7 +407,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
strbuf_addstr(sb, "object of unknown type");
break;
case OBJ_COMMIT:
- if ((buf = repo_read_object_file(the_repository, oid, &type, &size))) {
+ if ((buf = odb_read_object(the_repository->objects, oid, &type, &size))) {
subject_len = find_commit_subject(buf, &subject_start);
strbuf_insert(sb, sb->len, subject_start, subject_len);
} else {
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index b92fd4710a9..4360872ae07 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -14,7 +14,7 @@ static char *create_temp_file(struct object_id *oid)
unsigned long size;
int fd;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 405e78bc592..4bc6575a574 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -516,8 +516,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
return;
- base = repo_read_object_file(the_repository, &base_oid, &type,
- &base_size);
+ base = odb_read_object(the_repository->objects, &base_oid,
+ &type, &base_size);
if (!base) {
error("failed to read delta-pack base object %s",
oid_to_hex(&base_oid));
diff --git a/bundle.c b/bundle.c
index 90c8ec4166a..cca561308a0 100644
--- a/bundle.c
+++ b/bundle.c
@@ -305,7 +305,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
if (revs->max_age == -1 && revs->min_age == -1)
goto out;
- buf = repo_read_object_file(the_repository, &tag->oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &tag->oid, &type, &size);
if (!buf)
goto out;
line = memmem(buf, size, "\ntagger ", 8);
diff --git a/combine-diff.c b/combine-diff.c
index cf23a753407..4ea2dc93c4f 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -325,7 +325,7 @@ static char *grab_blob(struct repository *r,
*size = fill_textconv(r, textconv, df, &blob);
free_filespec(df);
} else {
- blob = repo_read_object_file(r, oid, &type, size);
+ blob = odb_read_object(r->objects, oid, &type, size);
if (!blob)
die(_("unable to read %s"), oid_to_hex(oid));
if (type != OBJ_BLOB)
diff --git a/commit.c b/commit.c
index d4aa9c7a5f8..28ee6b73ae6 100644
--- a/commit.c
+++ b/commit.c
@@ -374,7 +374,7 @@ const void *repo_get_commit_buffer(struct repository *r,
if (!ret) {
enum object_type type;
unsigned long size;
- ret = repo_read_object_file(r, &commit->object.oid, &type, &size);
+ ret = odb_read_object(r->objects, &commit->object.oid, &type, &size);
if (!ret)
die("cannot read commit object %s",
oid_to_hex(&commit->object.oid));
@@ -1275,8 +1275,8 @@ static void handle_signed_tag(const struct commit *parent, struct commit_extra_h
desc = merge_remote_util(parent);
if (!desc || !desc->obj)
return;
- buf = repo_read_object_file(the_repository, &desc->obj->oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &desc->obj->oid,
+ &type, &size);
if (!buf || type != OBJ_TAG)
goto free_return;
if (!parse_signature(buf, size, &payload, &signature))
diff --git a/config.c b/config.c
index 883dd066827..142c37215a8 100644
--- a/config.c
+++ b/config.c
@@ -1942,7 +1942,7 @@ int git_config_from_blob_oid(config_fn_t fn,
unsigned long size;
int ret;
- buf = repo_read_object_file(repo, oid, &type, &size);
+ buf = odb_read_object(repo->objects, oid, &type, &size);
if (!buf)
return error(_("unable to load config blob object '%s'"), name);
if (type != OBJ_BLOB) {
diff --git a/dir.c b/dir.c
index e11342e1366..251dedf1f5e 100644
--- a/dir.c
+++ b/dir.c
@@ -302,7 +302,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
*size_out = 0;
*data_out = NULL;
- data = repo_read_object_file(the_repository, oid, &type, &sz);
+ data = odb_read_object(the_repository->objects, oid, &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return -1;
diff --git a/entry.c b/entry.c
index 75d55038d7c..cae02eb5039 100644
--- a/entry.c
+++ b/entry.c
@@ -93,8 +93,8 @@ void *read_blob_entry(const struct cache_entry *ce, size_t *size)
{
enum object_type type;
unsigned long ul;
- void *blob_data = repo_read_object_file(the_repository, &ce->oid,
- &type, &ul);
+ void *blob_data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &ul);
*size = ul;
if (blob_data) {
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 1a8c972adf3..40174efa3de 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -526,8 +526,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
struct object_id *oid = origins.items[i].util;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository, oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects, oid,
+ &type, &size);
char *origbuf = buf;
unsigned long len = size;
struct signature_check sigc = { NULL };
diff --git a/fsck.c b/fsck.c
index e69baab3af7..23965e1880f 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1293,7 +1293,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
if (oidset_contains(blobs_done, oid))
continue;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
if (is_promisor_object(the_repository, oid))
continue;
diff --git a/grep.c b/grep.c
index dc77e6c4631..932647e4a65 100644
--- a/grep.c
+++ b/grep.c
@@ -1931,8 +1931,8 @@ static int grep_source_load_oid(struct grep_source *gs)
{
enum object_type type;
- gs->buf = repo_read_object_file(gs->repo, gs->identifier, &type,
- &gs->size);
+ gs->buf = odb_read_object(gs->repo->objects, gs->identifier,
+ &type, &gs->size);
if (!gs->buf)
return error(_("'%s': unable to read %s"),
gs->name,
diff --git a/http-push.c b/http-push.c
index d1b1bb23711..9481825abfb 100644
--- a/http-push.c
+++ b/http-push.c
@@ -369,8 +369,8 @@ static void start_put(struct transfer_request *request)
ssize_t size;
git_zstream stream;
- unpacked = repo_read_object_file(the_repository, &request->obj->oid,
- &type, &len);
+ unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
+ &type, &len);
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
/* Set it up */
diff --git a/mailmap.c b/mailmap.c
index b18e74c2110..56c72102d9e 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -196,7 +196,7 @@ int read_mailmap_blob(struct string_list *map, const char *name)
if (repo_get_oid(the_repository, name, &oid) < 0)
return 0;
- buf = repo_read_object_file(the_repository, &oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &oid, &type, &size);
if (!buf)
return error("unable to read mailmap object at %s", name);
if (type != OBJ_BLOB) {
diff --git a/match-trees.c b/match-trees.c
index 4704f95c340..5a8a5c39b04 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -63,7 +63,7 @@ static void *fill_tree_desc_strict(struct repository *r,
enum object_type type;
unsigned long size;
- buffer = repo_read_object_file(r, hash, &type, &size);
+ buffer = odb_read_object(r->objects, hash, &type, &size);
if (!buffer)
die("unable to read tree (%s)", oid_to_hex(hash));
if (type != OBJ_TREE)
@@ -199,7 +199,7 @@ static int splice_tree(struct repository *r,
if (*subpath)
subpath++;
- buf = repo_read_object_file(r, oid1, &type, &sz);
+ buf = odb_read_object(r->objects, oid1, &type, &sz);
if (!buf)
die("cannot read tree %s", oid_to_hex(oid1));
init_tree_desc(&desc, oid1, buf, sz);
diff --git a/merge-blobs.c b/merge-blobs.c
index ba8a3fdfd82..6fc27994171 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -12,8 +12,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
unsigned long size;
enum object_type type;
- buf = repo_read_object_file(the_repository, &obj->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &obj->object.oid,
+ &type, &size);
if (!buf)
return -1;
if (type != OBJ_BLOB) {
@@ -79,8 +79,8 @@ void *merge_blobs(struct index_state *istate, const char *path,
return NULL;
if (!our)
our = their;
- return repo_read_object_file(the_repository, &our->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects, &our->object.oid,
+ &type, size);
}
if (fill_mmfile_blob(&f1, our) < 0)
diff --git a/merge-ort.c b/merge-ort.c
index 5d4501085e9..53417d399c7 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -3624,7 +3624,7 @@ static int read_oid_strbuf(struct merge_options *opt,
void *buf;
enum object_type type;
unsigned long size;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
path, NULL, NULL, NULL,
diff --git a/notes-cache.c b/notes-cache.c
index 344f67762b8..dd56feed6e8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -87,7 +87,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
value_oid = get_note(&c->tree, key_oid);
if (!value_oid)
return NULL;
- value = repo_read_object_file(the_repository, value_oid, &type, &size);
+ value = odb_read_object(the_repository->objects, value_oid, &type, &size);
*outsize = size;
return value;
diff --git a/notes-merge.c b/notes-merge.c
index de6a52e2e7f..586939939f2 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -340,7 +340,7 @@ static void write_note_to_worktree(const struct object_id *obj,
{
enum object_type type;
unsigned long size;
- void *buf = repo_read_object_file(the_repository, note, &type, &size);
+ void *buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!buf)
die("cannot read note %s for object %s",
diff --git a/notes.c b/notes.c
index fc000e501d2..73eb5f00cf5 100644
--- a/notes.c
+++ b/notes.c
@@ -816,15 +816,15 @@ int combine_notes_concatenate(struct object_id *cur_oid,
/* read in both note blob objects */
if (!is_null_oid(new_oid))
- new_msg = repo_read_object_file(the_repository, new_oid,
- &new_type, &new_len);
+ new_msg = odb_read_object(the_repository->objects, new_oid,
+ &new_type, &new_len);
if (!new_msg || !new_len || new_type != OBJ_BLOB) {
free(new_msg);
return 0;
}
if (!is_null_oid(cur_oid))
- cur_msg = repo_read_object_file(the_repository, cur_oid,
- &cur_type, &cur_len);
+ cur_msg = odb_read_object(the_repository->objects, cur_oid,
+ &cur_type, &cur_len);
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
free(cur_msg);
free(new_msg);
@@ -880,7 +880,7 @@ static int string_list_add_note_lines(struct string_list *list,
return 0;
/* read_sha1_file NUL-terminates */
- data = repo_read_object_file(the_repository, oid, &t, &len);
+ data = odb_read_object(the_repository->objects, oid, &t, &len);
if (t != OBJ_BLOB || !data || !len) {
free(data);
return t != OBJ_BLOB || !data;
@@ -1290,7 +1290,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!oid)
return;
- if (!(msg = repo_read_object_file(the_repository, oid, &type, &msglen)) || type != OBJ_BLOB) {
+ if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
+ type != OBJ_BLOB) {
free(msg);
return;
}
diff --git a/object.c b/object.c
index 868d89eed42..c1553ee4330 100644
--- a/object.c
+++ b/object.c
@@ -335,7 +335,7 @@ struct object *parse_object_with_flags(struct repository *r,
return &lookup_tree(r, oid)->object;
}
- buffer = repo_read_object_file(r, oid, &type, &size);
+ buffer = odb_read_object(r->objects, oid, &type, &size);
if (buffer) {
if (!skip_hash &&
check_object_signature(r, repl, buffer, size, type) < 0) {
diff --git a/odb.c b/odb.c
index 919b8772f86..4a8b7e7df56 100644
--- a/odb.c
+++ b/odb.c
@@ -30,7 +30,7 @@ KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -896,15 +896,10 @@ int pretend_object_file(struct repository *repo,
return 0;
}
-/*
- * This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call odb_read_object_info_extended() and give
- * error messages themselves.
- */
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size)
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
{
struct object_info oi = OBJECT_INFO_INIT;
unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT | OBJECT_INFO_LOOKUP_REPLACE;
@@ -913,7 +908,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
+ if (odb_read_object_info_extended(odb, oid, &oi, flags))
return NULL;
return data;
@@ -935,7 +930,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = repo_read_object_file(r, &actual_oid, &type, &isize);
+ buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
diff --git a/odb.h b/odb.h
index 2613f2c6c03..6b5286a8bd6 100644
--- a/odb.h
+++ b/odb.h
@@ -128,7 +128,7 @@ struct object_database {
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -247,10 +247,19 @@ void odb_add_to_alternates_file(struct object_database *odb,
void odb_add_to_alternates_memory(struct object_database *odb,
const char *dir);
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size);
+/*
+ * Read an object from the database. Returns the object data and assigns object
+ * type and size to the `type` and `size` pointers, if these pointers are
+ * non-NULL. Returns a `NULL` pointer in case the object does not exist.
+ *
+ * This function dies on corrupt objects; the callers who want to deal with
+ * them should arrange to call odb_read_object_info_extended() and give error
+ * messages themselves.
+ */
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size);
/*
* Add an object file to the in-memory object store, without writing it
@@ -361,7 +370,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
- * following functions in parallel: repo_read_object_file(),
+ * following functions in parallel: odb_read_object(),
* read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
@@ -436,4 +445,12 @@ static inline int oid_object_info(struct repository *r,
return odb_read_object_info(r->objects, oid, sizep);
}
+static inline void *repo_read_object_file(struct repository *r,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
+{
+ return odb_read_object(r->objects, oid, type, size);
+}
+
#endif /* ODB_H */
diff --git a/read-cache.c b/read-cache.c
index be664f857b4..46986798a38 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -254,7 +254,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
if (strbuf_readlink(&sb, ce->name, expected_size))
return -1;
- buffer = repo_read_object_file(the_repository, &ce->oid, &type, &size);
+ buffer = odb_read_object(the_repository->objects, &ce->oid, &type, &size);
if (buffer) {
if (size == sb.len)
match = memcmp(buffer, sb.buf, size);
@@ -3514,8 +3514,8 @@ void *read_blob_data_from_index(struct index_state *istate,
}
if (pos < 0)
return NULL;
- data = repo_read_object_file(the_repository, &istate->cache[pos]->oid,
- &type, &sz);
+ data = odb_read_object(the_repository->objects, &istate->cache[pos]->oid,
+ &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return NULL;
diff --git a/reflog.c b/reflog.c
index 4f8a3b717cd..747b82eada8 100644
--- a/reflog.c
+++ b/reflog.c
@@ -140,8 +140,8 @@ static int tree_is_complete(const struct object_id *oid)
if (!tree->buffer) {
enum object_type type;
unsigned long size;
- void *data = repo_read_object_file(the_repository, oid, &type,
- &size);
+ void *data = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!data) {
tree->object.flags |= INCOMPLETE;
return 0;
diff --git a/rerere.c b/rerere.c
index 951e4bf8b41..8bb97c98229 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1000,9 +1000,8 @@ static int handle_cache(struct index_state *istate,
break;
i = ce_stage(ce) - 1;
if (!mmfile[i].ptr) {
- mmfile[i].ptr = repo_read_object_file(the_repository,
- &ce->oid, &type,
- &size);
+ mmfile[i].ptr = odb_read_object(the_repository->objects,
+ &ce->oid, &type, &size);
if (!mmfile[i].ptr)
die(_("unable to read %s"),
oid_to_hex(&ce->oid));
diff --git a/submodule-config.c b/submodule-config.c
index ed4bb32dc37..c13d60d217b 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -743,8 +743,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
if (submodule)
goto out;
- config = repo_read_object_file(the_repository, &oid, &type,
- &config_size);
+ config = odb_read_object(the_repository->objects, &oid,
+ &type, &config_size);
if (!config || type != OBJ_BLOB)
goto out;
diff --git a/tag.c b/tag.c
index 144048fd5e0..1d52686ee10 100644
--- a/tag.c
+++ b/tag.c
@@ -60,7 +60,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV),
type_name(type));
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return error("%s: unable to read file.",
name_to_report ?
@@ -222,8 +222,8 @@ int parse_tag(struct tag *item)
if (item->object.parsed)
return 0;
- data = repo_read_object_file(the_repository, &item->object.oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!data)
return error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/tree-walk.c b/tree-walk.c
index 34b0fff4873..766af99f466 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -795,9 +795,9 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
*/
retval = DANGLING_SYMLINK;
- contents = repo_read_object_file(r,
- ¤t_tree_oid, &type,
- &link_len);
+ contents = odb_read_object(r->objects,
+ ¤t_tree_oid, &type,
+ &link_len);
if (!contents)
goto done;
diff --git a/tree.c b/tree.c
index 341b7c2ff3f..1ef743d90f4 100644
--- a/tree.c
+++ b/tree.c
@@ -193,8 +193,8 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
if (item->object.parsed)
return 0;
- buffer = repo_read_object_file(the_repository, &item->object.oid,
- &type, &size);
+ buffer = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!buffer)
return quiet_on_missing ? -1 :
error("Could not read %s",
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 01e6e378ea6..0e5d38c9600 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -187,7 +187,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
return;
}
- ptr->ptr = repo_read_object_file(the_repository, oid, &type, &size);
+ ptr->ptr = odb_read_object(the_repository->objects, oid, &type, &size);
if (!ptr->ptr || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
ptr->size = size;
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH 15/17] odb: rename `has_object()`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (13 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-06 11:09 ` [PATCH 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
` (8 subsequent siblings)
23 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
Rename `has_object()` to `odb_has_object()` to match other functions
related to the object database and our modern coding guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 2 +-
builtin/backfill.c | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/clone.c | 2 +-
builtin/fetch.c | 17 +++++++++--------
builtin/fsck.c | 2 +-
builtin/index-pack.c | 4 ++--
builtin/pack-objects.c | 4 ++--
builtin/receive-pack.c | 4 ++--
builtin/remote.c | 4 ++--
builtin/show-ref.c | 4 ++--
builtin/unpack-objects.c | 4 ++--
bulk-checkin.c | 4 ++--
cache-tree.c | 15 ++++++++-------
commit-graph.c | 2 +-
commit.c | 2 +-
fetch-pack.c | 8 ++++----
http-push.c | 14 ++++++++------
http-walker.c | 8 ++++----
list-objects.c | 4 ++--
notes.c | 4 ++--
odb.c | 6 +++---
odb.h | 12 ++++++++++--
reflog.c | 2 +-
refs.c | 3 ++-
remote.c | 2 +-
send-pack.c | 2 +-
shallow.c | 12 ++++++------
upload-pack.c | 2 +-
walker.c | 4 ++--
30 files changed, 87 insertions(+), 74 deletions(-)
diff --git a/apply.c b/apply.c
index 56cd0540350..7fb56517649 100644
--- a/apply.c
+++ b/apply.c
@@ -3204,7 +3204,7 @@ static int apply_binary(struct apply_state *state,
return 0; /* deletion patch */
}
- if (has_object(the_repository, &oid, 0)) {
+ if (odb_has_object(the_repository->objects, &oid, 0)) {
/* We already have the postimage */
enum object_type type;
unsigned long size;
diff --git a/builtin/backfill.c b/builtin/backfill.c
index 0b49baa39fa..80056abe473 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -67,8 +67,8 @@ static int fill_missing_blobs(const char *path UNUSED,
return 0;
for (size_t i = 0; i < list->nr; i++) {
- if (!has_object(ctx->repo, &list->oid[i],
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_has_object(ctx->repo->objects, &list->oid[i],
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&ctx->current_batch, &list->oid[i]);
}
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index d6b9afca06e..571b5cc2ad5 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -169,8 +169,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
goto cleanup;
case 'e':
- ret = !has_object(the_repository, &oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
+ ret = !odb_has_object(the_repository->objects, &oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
goto cleanup;
case 'w':
diff --git a/builtin/clone.c b/builtin/clone.c
index 3aabdf6570b..6d08abed37c 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -506,7 +506,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
continue;
if (ends_with(ref->name, "^{}"))
continue;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
refs_update_ref(get_main_ref_store(the_repository), msg,
ref->name, &ref->old_oid, NULL, 0,
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 851c0a9419e..8e1d30fc33e 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -366,9 +366,9 @@ static void find_non_local_tags(const struct ref *refs,
*/
if (ends_with(ref->name, "^{}")) {
if (item &&
- !has_object(the_repository, &ref->old_oid, 0) &&
+ !odb_has_object(the_repository->objects, &ref->old_oid, 0) &&
!oidset_contains(&fetch_oids, &ref->old_oid) &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
item = NULL;
@@ -382,7 +382,7 @@ static void find_non_local_tags(const struct ref *refs,
* fetch.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -403,7 +403,7 @@ static void find_non_local_tags(const struct ref *refs,
* checked to see if it needs fetching.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -910,8 +910,8 @@ static int update_local_ref(struct ref *ref,
struct commit *current = NULL, *updated;
int fast_forward = 0;
- if (!has_object(the_repository, &ref->new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &ref->new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
if (oideq(&ref->old_oid, &ref->new_oid)) {
@@ -1330,7 +1330,8 @@ static int check_exist_and_connected(struct ref *ref_map)
* we need all direct targets to exist.
*/
for (r = rm; r; r = r->next) {
- if (!has_object(the_repository, &r->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ if (!odb_has_object(the_repository->objects, &r->old_oid,
+ HAS_OBJECT_RECHECK_PACKED))
return -1;
}
@@ -1485,7 +1486,7 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
struct object_id oid;
if (repo_get_oid(the_repository, s, &oid))
die(_("%s is not a valid object"), s);
- if (!has_object(the_repository, &oid, 0))
+ if (!odb_has_object(the_repository->objects, &oid, 0))
die(_("the object %s does not exist"), s);
oid_array_append(oids, &oid);
continue;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index f1da67eb26b..397abfa1216 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -161,7 +161,7 @@ static int mark_object(struct object *obj, enum object_type type,
return 0;
if (!(obj->flags & HAS_OBJ)) {
- if (parent && !has_object(the_repository, &obj->oid, 1)) {
+ if (parent && !odb_has_object(the_repository->objects, &obj->oid, 1)) {
printf_ln(_("broken link from %7s %s\n"
" to %7s %s"),
printable_type(&parent->oid, parent->type),
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index d33392cab65..0aa2f099cbe 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -893,8 +893,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (startup_info->have_repository) {
read_lock();
- collision_test_needed = has_object(the_repository, oid,
- HAS_OBJECT_FETCH_PROMISOR);
+ collision_test_needed = odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_FETCH_PROMISOR);
read_unlock();
}
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 580a5c1996b..06bdeb4223b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3968,7 +3968,7 @@ static void show_object__ma_allow_any(struct object *obj, const char *name, void
* Quietly ignore ALL missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0))
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0))
return;
show_object(obj, name, data);
@@ -3982,7 +3982,7 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
* Quietly ignore EXPECTED missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0) &&
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0) &&
is_promisor_object(to_pack.repo, &obj->oid))
return;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 8c157ea7d1b..27684dce3a4 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1508,8 +1508,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
}
if (!is_null_oid(new_oid) &&
- !has_object(the_repository, new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error("unpack should have generated %s, "
"but I can't find it!", oid_to_hex(new_oid));
ret = "bad pack";
diff --git a/builtin/remote.c b/builtin/remote.c
index ac5b8d2a1a6..7cbda285ebe 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -454,8 +454,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
info->status = PUSH_STATUS_UPTODATE;
else if (is_null_oid(&ref->old_oid))
info->status = PUSH_STATUS_CREATE;
- else if (has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ else if (odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
ref_newer(&ref->new_oid, &ref->old_oid))
info->status = PUSH_STATUS_FASTFORWARD;
else
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 90ec1de78f9..117709cb076 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -35,8 +35,8 @@ static void show_one(const struct show_one_options *opts,
const char *hex;
struct object_id peeled;
- if (!has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die("git show-ref: bad ref %s (%s)", refname,
oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 4bc6575a574..a69d59eb50c 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -449,8 +449,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
delta_data = get_data(delta_size);
if (!delta_data)
return;
- if (has_object(the_repository, &base_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &base_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
; /* Ok we have this one */
else if (resolve_against_held(nr, &base_oid,
delta_data, delta_size))
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 55406a539e7..16df86c0ba8 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -130,8 +130,8 @@ static void flush_batch_fsync(void)
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
{
/* The object may already exist in the repository */
- if (has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 1;
/* Might want to keep the list sorted */
diff --git a/cache-tree.c b/cache-tree.c
index 9786b32b3a1..a4bc14ad15c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -239,8 +239,8 @@ int cache_tree_fully_valid(struct cache_tree *it)
if (!it)
return 0;
if (it->entry_count < 0 ||
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
for (i = 0; i < it->subtree_nr; i++) {
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -292,8 +292,8 @@ static int update_one(struct cache_tree *it,
}
if (0 <= it->entry_count &&
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return it->entry_count;
/*
@@ -399,8 +399,9 @@ static int update_one(struct cache_tree *it,
ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
!must_check_existence(ce);
if (is_null_oid(oid) ||
- (!ce_missing_ok && !has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
+ (!ce_missing_ok &&
+ !odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
strbuf_release(&buffer);
if (expected_missing)
return -1;
@@ -448,7 +449,7 @@ static int update_one(struct cache_tree *it,
struct object_id oid;
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
OBJ_TREE, &oid);
- if (has_object(the_repository, &oid, HAS_OBJECT_RECHECK_PACKED))
+ if (odb_has_object(the_repository->objects, &oid, HAS_OBJECT_RECHECK_PACKED))
oidcpy(&it->oid, &oid);
else
to_invalidate = 1;
diff --git a/commit-graph.c b/commit-graph.c
index 9c2740a8cab..1597b831d8c 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1040,7 +1040,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
return NULL;
if (!search_commit_pos_in_graph(id, repo->objects->commit_graph, &pos))
return NULL;
- if (commit_graph_paranoia && !has_object(repo, id, 0))
+ if (commit_graph_paranoia && !odb_has_object(repo->objects, id, 0))
return NULL;
commit = lookup_commit(repo, id);
diff --git a/commit.c b/commit.c
index 28ee6b73ae6..15115125c36 100644
--- a/commit.c
+++ b/commit.c
@@ -575,7 +575,7 @@ int repo_parse_commit_internal(struct repository *r,
if (commit_graph_paranoia == -1)
commit_graph_paranoia = git_env_bool(GIT_COMMIT_GRAPH_PARANOIA, 0);
- if (commit_graph_paranoia && !has_object(r, &item->object.oid, 0)) {
+ if (commit_graph_paranoia && !odb_has_object(r->objects, &item->object.oid, 0)) {
unparse_commit(r, &item->object.oid);
return quiet_on_missing ? -1 :
error(_("commit %s exists in commit-graph but not in the object database"),
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f5de1c94d1..5e74235fc06 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -142,7 +142,7 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
commit = lookup_commit_in_graph(the_repository, oid);
if (commit) {
if (mark_tags_complete_and_check_obj_db) {
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
die_in_commit_graph_only(oid);
}
return commit;
@@ -770,7 +770,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
if (!commit) {
struct object *o;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
o = parse_object(the_repository, &ref->old_oid);
if (!o || o->type != OBJ_COMMIT)
@@ -1984,8 +1984,8 @@ static void update_shallow(struct fetch_pack_args *args,
struct oid_array extra = OID_ARRAY_INIT;
struct object_id *oid = si->shallow->oid;
for (i = 0; i < si->shallow->nr; i++)
- if (has_object(the_repository, &oid[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &oid[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
oid_array_append(&extra, &oid[i]);
if (extra.nr) {
setup_alternate_shallow(&shallow_lock,
diff --git a/http-push.c b/http-push.c
index 9481825abfb..beb41732fb6 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1447,8 +1447,8 @@ static void one_remote_ref(const char *refname)
* may be required for updating server info later.
*/
if (repo->can_update_info_refs &&
- !has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
obj = lookup_unknown_object(the_repository, &ref->old_oid);
fprintf(stderr, " fetch %s for %s\n",
oid_to_hex(&ref->old_oid), refname);
@@ -1653,14 +1653,16 @@ static int delete_remote_branch(const char *pattern, int force)
return error("Remote HEAD symrefs too deep");
if (is_null_oid(&head_oid))
return error("Unable to resolve remote HEAD");
- if (!has_object(the_repository, &head_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &head_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", oid_to_hex(&head_oid));
/* Remote branch must resolve to a known object */
if (is_null_oid(&remote_ref->old_oid))
return error("Unable to resolve remote branch %s",
remote_ref->name);
- if (!has_object(the_repository, &remote_ref->old_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &remote_ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, oid_to_hex(&remote_ref->old_oid));
/* Remote branch must be an ancestor of remote HEAD */
@@ -1881,8 +1883,8 @@ int cmd_main(int argc, const char **argv)
if (!force_all &&
!is_null_oid(&ref->old_oid) &&
!ref->force) {
- if (!has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
+ if (!odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
!ref_newer(&ref->peer_ref->new_oid,
&ref->old_oid)) {
/*
diff --git a/http-walker.c b/http-walker.c
index 12767e65a79..91a6de2126d 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -138,8 +138,8 @@ static int fill_active_slot(void *data UNUSED)
list_for_each_safe(pos, tmp, head) {
obj_req = list_entry(pos, struct object_request, node);
if (obj_req->state == WAITING) {
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
obj_req->state = COMPLETE;
else {
start_object_request(obj_req);
@@ -497,8 +497,8 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
if (!obj_req)
return error("Couldn't find request for %s in the queue", hex);
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
if (obj_req->req)
abort_http_object_request(&obj_req->req);
abort_object_request(obj_req);
diff --git a/list-objects.c b/list-objects.c
index c50b9578584..42c17d95739 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -74,8 +74,8 @@ static void process_blob(struct traversal_context *ctx,
* of missing objects.
*/
if (ctx->revs->exclude_promisor_objects &&
- !has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ !odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
is_promisor_object(ctx->revs->repo, &obj->oid))
return;
diff --git a/notes.c b/notes.c
index 73eb5f00cf5..97b995f3f2d 100644
--- a/notes.c
+++ b/notes.c
@@ -794,8 +794,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
struct note_delete_list **l = (struct note_delete_list **) cb_data;
struct note_delete_list *n;
- if (has_object(the_repository, object_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, object_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0; /* nothing to do for this note */
/* failed to find object => prune this note */
diff --git a/odb.c b/odb.c
index 4a8b7e7df56..e7c83d96361 100644
--- a/odb.c
+++ b/odb.c
@@ -880,7 +880,7 @@ int pretend_object_file(struct repository *repo,
char *co_buf;
hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (has_object(repo, oid, 0) ||
+ if (odb_has_object(repo->objects, oid, 0) ||
find_cached_object(repo->objects, oid))
return 0;
@@ -962,7 +962,7 @@ void *read_object_with_reference(struct repository *r,
}
}
-int has_object(struct repository *r, const struct object_id *oid,
+int odb_has_object(struct object_database *odb, const struct object_id *oid,
unsigned flags)
{
unsigned object_info_flags = 0;
@@ -974,7 +974,7 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(odb, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
diff --git a/odb.h b/odb.h
index 6b5286a8bd6..fd4f1c55b6d 100644
--- a/odb.h
+++ b/odb.h
@@ -362,8 +362,9 @@ enum {
* Returns 1 if the object exists. This function will not lazily fetch objects
* in a partial clone by default.
*/
-int has_object(struct repository *r, const struct object_id *oid,
- unsigned flags);
+int odb_has_object(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned flags);
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect);
@@ -453,4 +454,11 @@ static inline void *repo_read_object_file(struct repository *r,
return odb_read_object(r->objects, oid, type, size);
}
+static inline int has_object(struct repository *r,
+ const struct object_id *oid,
+ unsigned flags)
+{
+ return odb_has_object(r->objects, oid, flags);
+}
+
#endif /* ODB_H */
diff --git a/reflog.c b/reflog.c
index 747b82eada8..39c205fd26e 100644
--- a/reflog.c
+++ b/reflog.c
@@ -152,7 +152,7 @@ static int tree_is_complete(const struct object_id *oid)
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
complete = 1;
while (tree_entry(&desc, &entry)) {
- if (!has_object(the_repository, &entry.oid,
+ if (!odb_has_object(the_repository->objects, &entry.oid,
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
(S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) {
tree->object.flags |= INCOMPLETE;
diff --git a/refs.c b/refs.c
index d91063bab09..567fff3cc34 100644
--- a/refs.c
+++ b/refs.c
@@ -376,7 +376,8 @@ int ref_resolves_to_object(const char *refname,
{
if (flags & REF_ISBROKEN)
return 0;
- if (!has_object(repo, oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (!odb_has_object(repo->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error(_("%s does not point to a valid object!"), refname);
return 0;
}
diff --git a/remote.c b/remote.c
index 72c36239d31..5edf2a9f4b2 100644
--- a/remote.c
+++ b/remote.c
@@ -1703,7 +1703,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
if (starts_with(ref->name, "refs/tags/"))
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
- else if (!has_object(the_repository, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ else if (!odb_has_object(the_repository->objects, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||
!lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))
diff --git a/send-pack.c b/send-pack.c
index abca2dd38a7..d029f748232 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -45,7 +45,7 @@ int option_parse_push_signed(const struct option *opt,
static void feed_object(struct repository *r,
const struct object_id *oid, FILE *fh, int negative)
{
- if (negative && !has_object(r, oid, 0))
+ if (negative && !odb_has_object(r->objects, oid, 0))
return;
if (negative)
diff --git a/shallow.c b/shallow.c
index d379756e39a..ef3adb635fd 100644
--- a/shallow.c
+++ b/shallow.c
@@ -310,8 +310,8 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
if (graft->nr_parent != -1)
return 0;
if (data->flags & QUICK) {
- if (!has_object(the_repository, &graft->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &graft->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
} else if (data->flags & SEEN_ONLY) {
struct commit *c = lookup_commit(the_repository, &graft->oid);
@@ -477,8 +477,8 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
ALLOC_ARRAY(info->ours, sa->nr);
ALLOC_ARRAY(info->theirs, sa->nr);
for (size_t i = 0; i < sa->nr; i++) {
- if (has_object(the_repository, sa->oid + i,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, sa->oid + i,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
struct commit_graft *graft;
graft = lookup_commit_graft(the_repository,
&sa->oid[i]);
@@ -515,8 +515,8 @@ void remove_nonexistent_theirs_shallow(struct shallow_info *info)
for (i = dst = 0; i < info->nr_theirs; i++) {
if (i != dst)
info->theirs[dst] = info->theirs[i];
- if (has_object(the_repository, oid + info->theirs[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid + info->theirs[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
dst++;
}
info->nr_theirs = dst;
diff --git a/upload-pack.c b/upload-pack.c
index cec12cb478a..98cda156434 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -509,7 +509,7 @@ static int got_oid(struct upload_pack_data *data,
{
if (get_oid_hex(hex, oid))
die("git upload-pack: expected SHA1 object, got '%s'", hex);
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
return -1;
return do_got_oid(data, oid);
}
diff --git a/walker.c b/walker.c
index a8abe8a2e78..d131af04c7b 100644
--- a/walker.c
+++ b/walker.c
@@ -150,8 +150,8 @@ static int process(struct walker *walker, struct object *obj)
return 0;
obj->flags |= SEEN;
- if (has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
/* We already have it, so we should scan it now. */
obj->flags |= TO_SCAN;
}
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH 16/17] odb: rename `pretend_object_file()`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (14 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 15/17] odb: rename `has_object()` Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-06 11:09 ` [PATCH 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
` (7 subsequent siblings)
23 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
Rename `pretend_object_file()` to `odb_pretend_object()` to match other
functions related to the object database and our modern coding
guidelines.
No compatibility wrapper is introduces as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
blame.c | 3 ++-
odb.c | 18 +++++++++---------
odb.h | 6 +++---
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/blame.c b/blame.c
index 858d2d74df9..dce5c8d855c 100644
--- a/blame.c
+++ b/blame.c
@@ -277,7 +277,8 @@ static struct commit *fake_working_tree_commit(struct repository *r,
convert_to_git(r->index, path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
- pretend_object_file(the_repository, buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
+ odb_pretend_object(the_repository->objects, buf.buf, buf.len,
+ OBJ_BLOB, &origin->blob_oid);
/*
* Read the current index, replace the path entry with
diff --git a/odb.c b/odb.c
index e7c83d96361..3931020fa80 100644
--- a/odb.c
+++ b/odb.c
@@ -872,21 +872,21 @@ int odb_read_object_info(struct object_database *odb,
return type;
}
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid)
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid)
{
struct cached_object_entry *co;
char *co_buf;
- hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (odb_has_object(repo->objects, oid, 0) ||
- find_cached_object(repo->objects, oid))
+ hash_object_file(odb->repo->hash_algo, buf, len, type, oid);
+ if (odb_has_object(odb, oid, 0) ||
+ find_cached_object(odb, oid))
return 0;
- ALLOC_GROW(repo->objects->cached_objects,
- repo->objects->cached_object_nr + 1, repo->objects->cached_object_alloc);
- co = &repo->objects->cached_objects[repo->objects->cached_object_nr++];
+ ALLOC_GROW(odb->cached_objects,
+ odb->cached_object_nr + 1, odb->cached_object_alloc);
+ co = &odb->cached_objects[odb->cached_object_nr++];
co->value.size = len;
co->value.type = type;
co_buf = xmalloc(len);
diff --git a/odb.h b/odb.h
index fd4f1c55b6d..b9aefca639c 100644
--- a/odb.h
+++ b/odb.h
@@ -269,9 +269,9 @@ void *odb_read_object(struct object_database *odb,
* object in persistent storage before writing any other new objects
* that reference it.
*/
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid);
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid);
struct object_info {
/* Request */
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH 17/17] odb: rename `read_object_with_reference()`
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (15 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
@ 2025-05-06 11:09 ` Patrick Steinhardt
2025-05-07 1:40 ` [PATCH 00/17] object-store: carve out the object database subsystem Derrick Stolee
` (6 subsequent siblings)
23 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-06 11:09 UTC (permalink / raw)
To: git
Rename `read_object_with_reference()` to `odb_read_object_peeled()` to
match other functions related to the object database and our modern
coding guidelines. Furthermore though, the old name didn't really
describe very well what this function actually does, which is to walk
down any commit and tag objects until an object of the required type has
been found. This is generally referred to as "peeling", so the new name
should be way more descriptive.
No compatibility wrapper is introduces as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Documentation/user-manual.adoc | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/fast-import.c | 19 ++++++++-----------
builtin/grep.c | 9 +++------
builtin/pack-objects.c | 4 ++--
odb.c | 17 +++++++++--------
odb.h | 15 +++++++--------
tree-walk.c | 10 ++++------
8 files changed, 37 insertions(+), 45 deletions(-)
diff --git a/Documentation/user-manual.adoc b/Documentation/user-manual.adoc
index d2b478ad232..e86b2ad9f8a 100644
--- a/Documentation/user-manual.adoc
+++ b/Documentation/user-manual.adoc
@@ -4301,11 +4301,11 @@ Now, for the meat:
-----------------------------------------------------------------------------
case 0:
- buf = read_object_with_reference(sha1, argv[1], &size, NULL);
+ buf = odb_read_object_peeled(r->objects, sha1, argv[1], &size, NULL);
-----------------------------------------------------------------------------
This is how you read a blob (actually, not only a blob, but any type of
-object). To know how the function `read_object_with_reference()` actually
+object). To know how the function `odb_read_object_peeled()` actually
works, find the source code for it (something like `git grep
read_object_with | grep ":[a-z]"` in the Git repository), and read
the source.
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 571b5cc2ad5..ed0fce9b490 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -255,8 +255,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
* fall-back to the usual case.
*/
}
- buf = read_object_with_reference(the_repository, &oid,
- exp_type_id, &size, NULL);
+ buf = odb_read_object_peeled(the_repository->objects, &oid,
+ exp_type_id, &size, NULL);
if (use_mailmap) {
size_t s = size;
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 1973c504e25..b1389c59211 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2535,10 +2535,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
oidcpy(&commit_oid, &commit_oe->idx.oid);
} else if (!repo_get_oid(the_repository, p, &commit_oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &commit_oid,
- OBJ_COMMIT, &size,
- &commit_oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &commit_oid, OBJ_COMMIT, &size,
+ &commit_oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", p);
free(buf);
@@ -2604,9 +2603,8 @@ static void parse_from_existing(struct branch *b)
unsigned long size;
char *buf;
- buf = read_object_with_reference(the_repository,
- &b->oid, OBJ_COMMIT, &size,
- &b->oid);
+ buf = odb_read_object_peeled(the_repository->objects, &b->oid,
+ OBJ_COMMIT, &size, &b->oid);
parse_from_commit(b, buf, size);
free(buf);
}
@@ -2699,10 +2697,9 @@ static struct hash_list *parse_merge(unsigned int *count)
oidcpy(&n->oid, &oe->idx.oid);
} else if (!repo_get_oid(the_repository, from, &n->oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &n->oid,
- OBJ_COMMIT,
- &size, &n->oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &n->oid, OBJ_COMMIT,
+ &size, &n->oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", from);
free(buf);
diff --git a/builtin/grep.c b/builtin/grep.c
index 45681579b6d..d49c7002037 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -522,9 +522,7 @@ static int grep_submodule(struct grep_opt *opt,
obj_read_lock();
object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
- data = read_object_with_reference(subrepo,
- oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(subrepo->objects, oid, OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
@@ -705,9 +703,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
struct strbuf base;
int hit, len;
- data = read_object_with_reference(opt->repo,
- &obj->oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(opt->repo->objects, &obj->oid,
+ OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 06bdeb4223b..e88a13dbb9f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2055,8 +2055,8 @@ static void add_preferred_base(struct object_id *oid)
if (window <= num_preferred_base++)
return;
- data = read_object_with_reference(the_repository, oid,
- OBJ_TREE, &size, &tree_oid);
+ data = odb_read_object_peeled(the_repository->objects, oid,
+ OBJ_TREE, &size, &tree_oid);
if (!data)
return;
diff --git a/odb.c b/odb.c
index 3931020fa80..8b4f18f9ffb 100644
--- a/odb.c
+++ b/odb.c
@@ -914,11 +914,11 @@ void *odb_read_object(struct object_database *odb,
return data;
}
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *actual_oid_return)
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *actual_oid_return)
{
enum object_type type;
void *buffer;
@@ -930,7 +930,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
+ buffer = odb_read_object(odb, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
@@ -950,9 +950,10 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + r->hash_algo->hexsz > isize ||
+ if (ref_length + odb->repo->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid,
+ odb->repo->hash_algo)) {
free(buffer);
return NULL;
}
diff --git a/odb.h b/odb.h
index b9aefca639c..03f269c4e82 100644
--- a/odb.h
+++ b/odb.h
@@ -261,6 +261,12 @@ void *odb_read_object(struct object_database *odb,
enum object_type *type,
unsigned long *size);
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *oid_ret);
+
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -372,7 +378,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: odb_read_object(),
- * read_object_with_reference(), odb_read_object_info() and odb().
+ * odb_read_object_peeled(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -421,13 +427,6 @@ enum for_each_object_flags {
FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
};
-
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *oid_ret);
-
/* Compatibility wrappers, to be removed once Git 2.50 has been released. */
#include "repository.h"
diff --git a/tree-walk.c b/tree-walk.c
index 766af99f466..e449a1320e5 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -90,7 +90,7 @@ void *fill_tree_descriptor(struct repository *r,
void *buf = NULL;
if (oid) {
- buf = read_object_with_reference(r, oid, OBJ_TREE, &size, NULL);
+ buf = odb_read_object_peeled(r->objects, oid, OBJ_TREE, &size, NULL);
if (!buf)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
}
@@ -611,7 +611,7 @@ int get_tree_entry(struct repository *r,
unsigned long size;
struct object_id root;
- tree = read_object_with_reference(r, tree_oid, OBJ_TREE, &size, &root);
+ tree = odb_read_object_peeled(r->objects, tree_oid, OBJ_TREE, &size, &root);
if (!tree)
return -1;
@@ -681,10 +681,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
void *tree;
struct object_id root;
unsigned long size;
- tree = read_object_with_reference(r,
- ¤t_tree_oid,
- OBJ_TREE, &size,
- &root);
+ tree = odb_read_object_peeled(r->objects, ¤t_tree_oid,
+ OBJ_TREE, &size, &root);
if (!tree)
goto done;
--
2.49.0.1045.g170613ef41.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 00/17] object-store: carve out the object database subsystem
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (16 preceding siblings ...)
2025-05-06 11:09 ` [PATCH 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
@ 2025-05-07 1:40 ` Derrick Stolee
2025-05-07 17:02 ` Junio C Hamano
2025-05-09 11:25 ` Patrick Steinhardt
2025-05-07 23:22 ` Junio C Hamano
` (5 subsequent siblings)
23 siblings, 2 replies; 166+ messages in thread
From: Derrick Stolee @ 2025-05-07 1:40 UTC (permalink / raw)
To: Patrick Steinhardt, git
On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
> this patch series refactors the object store subsystem to become more
> self-contained by getting rid of `the_repository`. Instead of passing in
> the repository explicitly, we start to pass in the object store itself,
> which is in contrast to many other refactorings we did, but in line with
> what we did for the ref store, as well.
>
> This series also starts to properly scope functions to the carved out
> object database subsystem, which requires a bit of shuffling. This
> allows us to have a short-and-sweet `odb_` prefix for functions and
> prepares us for a future with pluggable object backends.
>
> The series is structured as follows:
>
> - Patches 1 to 3 rename `struct object_store` and `struct
> object_directory` as well as the code files.
Patches 1 and 2 involve renaming some core structures, and I had
some questions around these names (since we hope to be stuck with
the new names for a long time). I was thinking out loud on a per-
patch basis, but now want to collect my thoughts around these:
* raw_object_store currently describes the abstraction that contains
all objects that can be accessed within the repository. This may
include multiple alternates. Patch 1 renames this to
'object_database'.
* object_directory currently describes a single directory that
has the same structure as $GIT_DIR/objects/ but may be an alternate
or a submodule object directory. Patch 2 renames this to
'odb_backend'.
My concerns around this are basically around not liking "backend" for
this purpose. When I think of a backend, I'm thinking about the
implementation details (like the refs backend being files or reftable)
and not multiple distinct locations that have their own objects.
In this sense, I'm partial to being brief for the most-common structure
that will be passed around and then more descriptive about the smaller
pieces:
* 'struct raw_object_store' could be renamed to 'struct odb' to match
its use in all of the new odb_*() methods. This represents the
"object database abstraction" and consumers don't care if this is
one or many object directories in a trench coat.
* 'struct object_directory' could be renamed to 'struct odb_shard' or
'struct odb_slice' or similar. I may even recommend 'odb_partition'
though that does imply some disjointness that is not guaranteed (an
object can exist in multiple parts).
* In the event that we create multiple implementations for storing
objects, then a 'struct odb_shard' could point to a backend to help
find the appropriate methods for interacting with its storage.
* "alternate refs" are locked in as names based on the following
config key names:
- core.alternateRefsCommand
- core.alternateRefsPrefix
These user-facing names should not change. This may be valuable to
make sure that the 'odb_shard's still have a state of "I'm an
alternate" or "I'm the base read/write shard for this repo".
> - Patches 4 to 12 refactor "odb.c" to get rid of `the_repository`.
These are carefully done. Thanks. I only have a few nitpicks here
and there.
> - Patches 13 to 17 adjust the name of remaining functions so that they
> can be clearly attributed to the ODB. I'm happy to kick these
> patches out of this series and resend them at a later point in case
> they create too much turmoil.
I like that these are present, especially because you included
compatibility macros for in-flight topics.
I do mention that the rename of the object-store.[c|h] files may be
unnecessary, or perhaps could be delayed until this series is merged
and the collateral is calmed.
---
This was clearly a lot of work to put together. Thanks for working
hard to thoughtfully rename things while refactoring to reduce our
dependence on global state.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 00/17] object-store: carve out the object database subsystem
2025-05-07 1:40 ` [PATCH 00/17] object-store: carve out the object database subsystem Derrick Stolee
@ 2025-05-07 17:02 ` Junio C Hamano
2025-05-09 11:25 ` Patrick Steinhardt
2025-05-09 11:25 ` Patrick Steinhardt
1 sibling, 1 reply; 166+ messages in thread
From: Junio C Hamano @ 2025-05-07 17:02 UTC (permalink / raw)
To: Derrick Stolee; +Cc: Patrick Steinhardt, git
Derrick Stolee <stolee@gmail.com> writes:
> Patches 1 and 2 involve renaming some core structures, and I had
> some questions around these names (since we hope to be stuck with
> the new names for a long time). I was thinking out loud on a per-
> patch basis, but now want to collect my thoughts around these:
>
> * raw_object_store currently describes the abstraction that contains
> all objects that can be accessed within the repository. This may
> include multiple alternates. Patch 1 renames this to
> 'object_database'.
>
> * object_directory currently describes a single directory that
> has the same structure as $GIT_DIR/objects/ but may be an alternate
> or a submodule object directory. Patch 2 renames this to
> 'odb_backend'.
>
> My concerns around this are basically around not liking "backend" for
> this purpose. When I think of a backend, I'm thinking about the
> implementation details (like the refs backend being files or reftable)
> and not multiple distinct locations that have their own objects.
Yup, odb_backend_files (aot odb_backend_redis) or something?
> * 'struct object_directory' could be renamed to 'struct odb_shard' or
> 'struct odb_slice' or similar. I may even recommend 'odb_partition'
> though that does imply some disjointness that is not guaranteed (an
> object can exist in multiple parts).
>
> * In the event that we create multiple implementations for storing
> objects, then a 'struct odb_shard' could point to a backend to help
> find the appropriate methods for interacting with its storage.
Hmph, I do not have strong opinions, but I consider it an
implementation detail of one particular backend, namely, the
filesystem based backend, that it can link together multiple
object_directory instances and present them as if they form a single
object database, just like all files within a single object_directory
form an illusion of a single object database (aka key-value store) even
though some objects are stored in individual loose object files while
many others are packed in a single packfile.
I did not expect you would want to go to the world where a single
"shard" consists of an object_directory backed by the filesystem and
some other more database-y backend. It is an interesting idea, but
we'd need to worry about many things we do not have to worry about
right now. E.g. what do the precedence rules among different
components within a single "shard" look like? How do we express "in
this repository, local filesystem-backed piece is consulted first,
and then check this piece backed by low-cost but high-latency
storage backend"?
> I do mention that the rename of the object-store.[c|h] files may be
> unnecessary, or perhaps could be delayed until this series is merged
> and the collateral is calmed.
Right now, merge-fix needed against all other topics in flight look
like this, in order to merge it to 'seen'.
$ git show --oneline -U0 merge-fix/ps/object-store
c8afa0ab8e merge-fix/ps/object-store
diff --git a/fetch-object-info.c b/fetch-object-info.c
index 1b2c6c4d27..6c2abb7805 100644
--- a/fetch-object-info.c
+++ b/fetch-object-info.c
@@ -7 +7 @@
-#include "object-store.h"
+#include "odb.h"
diff --git a/fetch-object-info.h b/fetch-object-info.h
index 7910d7f153..d35284bd6b 100644
--- a/fetch-object-info.h
+++ b/fetch-object-info.h
@@ -6 +6 @@
-#include "object-store.h"
+#include "odb.h"
diff --git a/transport.h b/transport.h
index 5a4f27451a..3ef3acf865 100644
--- a/transport.h
+++ b/transport.h
@@ -8 +8 @@
-#include "object-store.h"
+#include "odb.h"
IOW, not too horrible.
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH 00/17] object-store: carve out the object database subsystem
2025-05-07 17:02 ` Junio C Hamano
@ 2025-05-09 11:25 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 11:25 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Derrick Stolee, git
On Wed, May 07, 2025 at 10:02:12AM -0700, Junio C Hamano wrote:
> Derrick Stolee <stolee@gmail.com> writes:
>
> > Patches 1 and 2 involve renaming some core structures, and I had
> > some questions around these names (since we hope to be stuck with
> > the new names for a long time). I was thinking out loud on a per-
> > patch basis, but now want to collect my thoughts around these:
> >
> > * raw_object_store currently describes the abstraction that contains
> > all objects that can be accessed within the repository. This may
> > include multiple alternates. Patch 1 renames this to
> > 'object_database'.
> >
> > * object_directory currently describes a single directory that
> > has the same structure as $GIT_DIR/objects/ but may be an alternate
> > or a submodule object directory. Patch 2 renames this to
> > 'odb_backend'.
> >
> > My concerns around this are basically around not liking "backend" for
> > this purpose. When I think of a backend, I'm thinking about the
> > implementation details (like the refs backend being files or reftable)
> > and not multiple distinct locations that have their own objects.
>
> Yup, odb_backend_files (aot odb_backend_redis) or something?
Yeah, that was my vision indeed. I think it works equally well though in
case we name this `odb_alternate`. The benefit of the "alternate"
terminology is that we already use it and it's almost a perfect fit, and
it gives the reader a hint that we may have multiple alternates. On the
other hand, `odb_backend` sounds as if there would only be a single
backend for a `struct object_database`.
So Stolee caused me to reconsider and favor `odb_alternate`. But in the
end I guess that both names would work alright.
> > * 'struct object_directory' could be renamed to 'struct odb_shard' or
> > 'struct odb_slice' or similar. I may even recommend 'odb_partition'
> > though that does imply some disjointness that is not guaranteed (an
> > object can exist in multiple parts).
> >
> > * In the event that we create multiple implementations for storing
> > objects, then a 'struct odb_shard' could point to a backend to help
> > find the appropriate methods for interacting with its storage.
>
> Hmph, I do not have strong opinions, but I consider it an
> implementation detail of one particular backend, namely, the
> filesystem based backend, that it can link together multiple
> object_directory instances and present them as if they form a single
> object database, just like all files within a single object_directory
> form an illusion of a single object database (aka key-value store) even
> though some objects are stored in individual loose object files while
> many others are packed in a single packfile.
>
> I did not expect you would want to go to the world where a single
> "shard" consists of an object_directory backed by the filesystem and
> some other more database-y backend. It is an interesting idea, but
> we'd need to worry about many things we do not have to worry about
> right now. E.g. what do the precedence rules among different
> components within a single "shard" look like? How do we express "in
> this repository, local filesystem-backed piece is consulted first,
> and then check this piece backed by low-cost but high-latency
> storage backend"?
Well, in fact I want to design this from the start so that you can mix
and match different backends. I think it falls out naturally from the
design if an alternate can be backed by anything, and it has a lot of
very interesting features.
Furthermore, it would cause a bunch of problems if we _didn't_ allow for
this, at least for hosting providers:
- Migrations would now need to be atomic across fork networks where
all forks need to be migrated at once so that we don't mix backends.
- Migrations in general would be a pain if we had to do an atomic
migration even for a single object directory. With mixed backends we
can already make a partially-migrated backend available while the
old backend is still in use.
- High-latency storage backends may work well for binary files, but
not for smallish text files.
This all of course still needs to be hashed out. I do want to send an
RFC document to the mailing list soonish, probably in the first half of
the Git 2.51 release cycle, so that we can discuss where to go.
> > I do mention that the rename of the object-store.[c|h] files may be
> > unnecessary, or perhaps could be delayed until this series is merged
> > and the collateral is calmed.
>
> Right now, merge-fix needed against all other topics in flight look
> like this, in order to merge it to 'seen'.
Okay. In that case I'll keep that patch for now.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 00/17] object-store: carve out the object database subsystem
2025-05-07 1:40 ` [PATCH 00/17] object-store: carve out the object database subsystem Derrick Stolee
2025-05-07 17:02 ` Junio C Hamano
@ 2025-05-09 11:25 ` Patrick Steinhardt
2025-05-13 19:28 ` Toon Claes
1 sibling, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 11:25 UTC (permalink / raw)
To: Derrick Stolee; +Cc: git
On Tue, May 06, 2025 at 09:40:16PM -0400, Derrick Stolee wrote:
> On 5/6/25 7:09 AM, Patrick Steinhardt wrote:
>
> > this patch series refactors the object store subsystem to become more
> > self-contained by getting rid of `the_repository`. Instead of passing in
> > the repository explicitly, we start to pass in the object store itself,
> > which is in contrast to many other refactorings we did, but in line with
> > what we did for the ref store, as well.
> >
> > This series also starts to properly scope functions to the carved out
> > object database subsystem, which requires a bit of shuffling. This
> > allows us to have a short-and-sweet `odb_` prefix for functions and
> > prepares us for a future with pluggable object backends.
> >
> > The series is structured as follows:
> >
> > - Patches 1 to 3 rename `struct object_store` and `struct
> > object_directory` as well as the code files.
>
> Patches 1 and 2 involve renaming some core structures, and I had
> some questions around these names (since we hope to be stuck with
> the new names for a long time). I was thinking out loud on a per-
> patch basis, but now want to collect my thoughts around these:
>
> * raw_object_store currently describes the abstraction that contains
> all objects that can be accessed within the repository. This may
> include multiple alternates. Patch 1 renames this to
> 'object_database'.
>
> * object_directory currently describes a single directory that
> has the same structure as $GIT_DIR/objects/ but may be an alternate
> or a submodule object directory. Patch 2 renames this to
> 'odb_backend'.
>
> My concerns around this are basically around not liking "backend" for
> this purpose. When I think of a backend, I'm thinking about the
> implementation details (like the refs backend being files or reftable)
> and not multiple distinct locations that have their own objects.
That is very much the intent eventually. Right now the backend is always
the one that uses loose objects and packfiles. But eventually, the goal
is to introduce different backends.
But regardless of that, ...
> In this sense, I'm partial to being brief for the most-common structure
> that will be passed around and then more descriptive about the smaller
> pieces:
>
> * 'struct raw_object_store' could be renamed to 'struct odb' to match
> its use in all of the new odb_*() methods. This represents the
> "object database abstraction" and consumers don't care if this is
> one or many object directories in a trench coat.
NB: I think having a long name here is nicer, even if it's
abbreviated in the functions. But that's mostly my own preference, I
don't care too much. I'll keep this as-is in the next iteration, but
if you feel strongly I'm certainly happy to rename it to `struct
odb`. Just give me a ping and I'll do so.
> * 'struct object_directory' could be renamed to 'struct odb_shard' or
> 'struct odb_slice' or similar. I may even recommend 'odb_partition'
> though that does imply some disjointness that is not guaranteed (an
> object can exist in multiple parts).
>
> * In the event that we create multiple implementations for storing
> objects, then a 'struct odb_shard' could point to a backend to help
> find the appropriate methods for interacting with its storage.
... I have decided to rename this to `odb_alternate`. I don't think
"shard" works well, as shard is an extremely generic term that doesn't
really convey much meaning.
On the other hand, I think that `odb_alternate` is quite a good fit. We
already use it all over the place to mean almost exactly what we are
after here. And it doesn't seem far-fetched to have an
`odb_packed_alternate`, `odb_loose_alternate` and `odb_redis_alternate`
for different backends.
The only stretch is that the primary object directory is now the primary
alternate. I think that this is acceptable though'
> * "alternate refs" are locked in as names based on the following
> config key names:
>
> - core.alternateRefsCommand
> - core.alternateRefsPrefix
>
> These user-facing names should not change. This may be valuable to
> make sure that the 'odb_shard's still have a state of "I'm an
> alternate" or "I'm the base read/write shard for this repo".
Agreed.
> > - Patches 4 to 12 refactor "odb.c" to get rid of `the_repository`.
>
> These are carefully done. Thanks. I only have a few nitpicks here
> and there.
>
> > - Patches 13 to 17 adjust the name of remaining functions so that they
> > can be clearly attributed to the ODB. I'm happy to kick these
> > patches out of this series and resend them at a later point in case
> > they create too much turmoil.
>
> I like that these are present, especially because you included
> compatibility macros for in-flight topics.
>
> I do mention that the rename of the object-store.[c|h] files may be
> unnecessary, or perhaps could be delayed until this series is merged
> and the collateral is calmed.
>
> ---
>
> This was clearly a lot of work to put together. Thanks for working
> hard to thoughtfully rename things while refactoring to reduce our
> dependence on global state.
Well. Frankly, the hard work is only just starting. Next step: push down
`struct packed_git` from `struct object_database` to `odb_alternate`.
I'm scared what I'll find there.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 00/17] object-store: carve out the object database subsystem
2025-05-09 11:25 ` Patrick Steinhardt
@ 2025-05-13 19:28 ` Toon Claes
2025-05-14 4:31 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Toon Claes @ 2025-05-13 19:28 UTC (permalink / raw)
To: Patrick Steinhardt, Derrick Stolee; +Cc: git
Patrick Steinhardt <ps@pks.im> writes:
> ... I have decided to rename this to `odb_alternate`. I don't think
> "shard" works well, as shard is an extremely generic term that doesn't
> really convey much meaning.
>
> On the other hand, I think that `odb_alternate` is quite a good fit. We
> already use it all over the place to mean almost exactly what we are
> after here. And it doesn't seem far-fetched to have an
> `odb_packed_alternate`, `odb_loose_alternate` and `odb_redis_alternate`
> for different backends.
So a database is a collection of alternates? And the alternates are
stored as a linked list?
> The only stretch is that the primary object directory is now the primary
> alternate. I think that this is acceptable though'
This is a very important nuance, and with that knowledge it starts to
click with me. I didn't read this in the commit messages though, so I
think it's worth adding something about that in [PATCH 02/17].
--
Toon
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 00/17] object-store: carve out the object database subsystem
2025-05-13 19:28 ` Toon Claes
@ 2025-05-14 4:31 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 4:31 UTC (permalink / raw)
To: Toon Claes; +Cc: Derrick Stolee, git
On Tue, May 13, 2025 at 09:28:30PM +0200, Toon Claes wrote:
> Patrick Steinhardt <ps@pks.im> writes:
>
> > ... I have decided to rename this to `odb_alternate`. I don't think
> > "shard" works well, as shard is an extremely generic term that doesn't
> > really convey much meaning.
> >
> > On the other hand, I think that `odb_alternate` is quite a good fit. We
> > already use it all over the place to mean almost exactly what we are
> > after here. And it doesn't seem far-fetched to have an
> > `odb_packed_alternate`, `odb_loose_alternate` and `odb_redis_alternate`
> > for different backends.
>
> So a database is a collection of alternates? And the alternates are
> stored as a linked list?
Yes.
> > The only stretch is that the primary object directory is now the primary
> > alternate. I think that this is acceptable though'
>
> This is a very important nuance, and with that knowledge it starts to
> click with me. I didn't read this in the commit messages though, so I
> think it's worth adding something about that in [PATCH 02/17].
Good point, done now.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH 00/17] object-store: carve out the object database subsystem
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (17 preceding siblings ...)
2025-05-07 1:40 ` [PATCH 00/17] object-store: carve out the object database subsystem Derrick Stolee
@ 2025-05-07 23:22 ` Junio C Hamano
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (4 subsequent siblings)
23 siblings, 0 replies; 166+ messages in thread
From: Junio C Hamano @ 2025-05-07 23:22 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
Patrick Steinhardt <ps@pks.im> writes:
> this patch series refactors the object store subsystem to become more
> self-contained by getting rid of `the_repository`. Instead of passing in
> the repository explicitly, we start to pass in the object store itself,
> which is in contrast to many other refactorings we did, but in line with
> what we did for the ref store, as well.
Nice. I do prefer to keep the scope of the "what's affected" object
smaller than just assume that passing a repository is fine. The
interaction among object database, the index and the ref database is
a bit subtle, in that the former should mostly be usable without the
latter (i.e. "you throw a stream of data at it, and it registers it
as an object and returns an object name") but some operations you'd
need all (e.g. prunability). With use of alternate object store, we
cannot say "by specifying a repository, we can specify its object
store", as there is no "the single object store" linked to the
repository.
> This series also starts to properly scope functions to the carved out
> object database subsystem, which requires a bit of shuffling. This
> allows us to have a short-and-sweet `odb_` prefix for functions and
> prepares us for a future with pluggable object backends.
Good.
> The series is structured as follows:
>
> - Patches 1 to 3 rename `struct object_store` and `struct
> object_directory` as well as the code files.
>
> - Patches 4 to 12 refactor "odb.c" to get rid of `the_repository`.
>
> - Patches 13 to 17 adjust the name of remaining functions so that they
> can be clearly attributed to the ODB. I'm happy to kick these
> patches out of this series and resend them at a later point in case
> they create too much turmoil.
>
> This series is built on top of 6f84262c44a (The eleventh batch,
> 2025-05-05) with ps/object-store-cleanup at 8a9e27be821 (object-store:
> drop `repo_has_object_file()`, 2025-04-29) merged into it. There are a
> couple of trivial conflicts when merged with "seen", I have appended the
> merge conflict resolution as a patch at the end of this mail.
>
> Thanks!
>
> Patrick
>
> -- >8 --
>
> diff --cc builtin/pack-objects.c
> index e88a13dbb9f,2936a08e130..00000000000
> --- a/builtin/pack-objects.c
> +++ b/builtin/pack-objects.c
> @@@ -4063,9 -4318,10 +4320,10 @@@ static void add_objects_in_unpacked_pac
> }
>
> static int add_loose_object(const struct object_id *oid, const char *path,
> - void *data UNUSED)
> + void *data)
> {
> + struct rev_info *revs = data;
> - enum object_type type = oid_object_info(the_repository, oid, NULL);
> + enum object_type type = odb_read_object_info(the_repository->objects, oid, NULL);
>
> if (type < 0) {
> warning(_("loose object at %s could not be examined"), path);
> diff --cc odb.h
> index 03f269c4e82,af0b3d856f5..00000000000
> --- a/odb.h
> +++ b/odb.h
> @@@ -338,25 -258,10 +338,28 @@@ struct object_info
> /* Die if object corruption (not just an object being missing) was detected. */
> #define OBJECT_INFO_DIE_IF_CORRUPT 32
>
> -int oid_object_info_extended(struct repository *r,
> - const struct object_id *,
> - struct object_info *, unsigned flags);
> +/*
> + * Read object info from the object database and populate the `object_info`
> + * structure. Returns 0 on success, a negative error code otherwise.
> + */
> +int odb_read_object_info_extended(struct object_database *odb,
> + const struct object_id *oid,
> + struct object_info *oi,
> + unsigned flags);
> +
> +/*
> + * Read a subset of object info for the given object ID. Returns an `enum
> + * object_type` on success, a negative error code otherwise. If successful and
> + * `sizep` is non-NULL, then the size of the object will be written to the
> + * pointer.
> + */
> +int odb_read_object_info(struct object_database *odb,
> + const struct object_id *oid,
> + unsigned long *sizep);
> +
> ++/* Free pointers inside of object_info, but not object_info itself */
> ++void free_object_info_contents(struct object_info *object_info);
> +
> enum {
> /* Retry packed storage after checking packed and loose storage */
> HAS_OBJECT_RECHECK_PACKED = (1 << 0),
> diff --git a/fetch-object-info.c b/fetch-object-info.c
> index 1b2c6c4d27c..6c2abb78055 100644
> --- a/fetch-object-info.c
> +++ b/fetch-object-info.c
> @@ -4,7 +4,7 @@
> #include "pkt-line.h"
> #include "connect.h"
> #include "oid-array.h"
> -#include "object-store.h"
> +#include "odb.h"
> #include "fetch-object-info.h"
> #include "string-list.h"
>
> diff --git a/fetch-object-info.h b/fetch-object-info.h
> index 7910d7f1532..d35284bd6bc 100644
> --- a/fetch-object-info.h
> +++ b/fetch-object-info.h
> @@ -3,7 +3,7 @@
>
> #include "pkt-line.h"
> #include "protocol.h"
> -#include "object-store.h"
> +#include "odb.h"
>
> struct object_info_args {
> struct string_list *object_info_options;
> diff --git a/transport.h b/transport.h
> index 5a4f27451ae..3ef3acf8650 100644
> --- a/transport.h
> +++ b/transport.h
> @@ -5,7 +5,7 @@
> #include "remote.h"
> #include "list-objects-filter-options.h"
> #include "string-list.h"
> -#include "object-store.h"
> +#include "odb.h"
>
> struct git_transport_options {
> unsigned thin : 1;
>
> ---
> Patrick Steinhardt (17):
> object-store: rename `raw_object_store` to `object_database`
> object-store: rename `object_directory` to `odb_backend`
> object-store: rename files to "odb.{c,h}"
> odb: introduce parent pointers
> odb: get rid of `the_repository` in `find_odb()`
> odb: get rid of `the_repository` in `assert_oid_type()`
> odb: get rid of `the_repository` in `assert_oid_type()`
> odb: get rid of `the_repository` when handling alternates
> odb: get rid of `the_repository` in `for_each()` functions
> odb: get rid of `the_repository` when handling the primary backend
> odb: get rid of `the_repository` when handling submodule backends
> odb: trivial refactorings to get rid of `the_repository`
> odb: rename `oid_object_info()`
> odb: rename `repo_read_object_file()`
> odb: rename `has_object()`
> odb: rename `pretend_object_file()`
> odb: rename `read_object_with_reference()`
>
> Documentation/user-manual.adoc | 4 +-
> Makefile | 2 +-
> apply.c | 14 +-
> archive-tar.c | 2 +-
> archive-zip.c | 2 +-
> archive.c | 6 +-
> attr.c | 4 +-
> bisect.c | 8 +-
> blame.c | 22 +-
> builtin/backfill.c | 6 +-
> builtin/blame.c | 6 +-
> builtin/cat-file.c | 62 +++--
> builtin/checkout.c | 2 +-
> builtin/clone.c | 14 +-
> builtin/commit-graph.c | 20 +-
> builtin/commit-tree.c | 4 +-
> builtin/count-objects.c | 4 +-
> builtin/describe.c | 5 +-
> builtin/difftool.c | 4 +-
> builtin/fast-export.c | 10 +-
> builtin/fast-import.c | 49 ++--
> builtin/fetch.c | 21 +-
> builtin/fsck.c | 31 +--
> builtin/gc.c | 16 +-
> builtin/grep.c | 26 +--
> builtin/hash-object.c | 2 +-
> builtin/index-pack.c | 29 +--
> builtin/log.c | 4 +-
> builtin/ls-files.c | 4 +-
> builtin/ls-tree.c | 6 +-
> builtin/merge-file.c | 2 +-
> builtin/merge-tree.c | 14 +-
> builtin/mktag.c | 6 +-
> builtin/mktree.c | 10 +-
> builtin/multi-pack-index.c | 6 +-
> builtin/notes.c | 8 +-
> builtin/pack-objects.c | 70 +++---
> builtin/pack-redundant.c | 2 +-
> builtin/prune.c | 6 +-
> builtin/receive-pack.c | 9 +-
> builtin/remote.c | 6 +-
> builtin/repack.c | 7 +-
> builtin/replace.c | 12 +-
> builtin/rev-list.c | 8 +-
> builtin/show-ref.c | 6 +-
> builtin/submodule--helper.c | 7 +-
> builtin/tag.c | 10 +-
> builtin/unpack-file.c | 4 +-
> builtin/unpack-objects.c | 12 +-
> bulk-checkin.c | 6 +-
> bundle-uri.c | 5 +-
> bundle.c | 6 +-
> cache-tree.c | 17 +-
> combine-diff.c | 4 +-
> commit-graph.c | 56 ++---
> commit-graph.h | 20 +-
> commit.c | 15 +-
> config.c | 4 +-
> connected.c | 2 +-
> contrib/coccinelle/the_repository.cocci | 2 +-
> diagnose.c | 8 +-
> diff.c | 20 +-
> dir.c | 2 +-
> entry.c | 6 +-
> fetch-pack.c | 17 +-
> fmt-merge-msg.c | 6 +-
> fsck.c | 4 +-
> grep.c | 6 +-
> http-backend.c | 2 +-
> http-push.c | 20 +-
> http-walker.c | 12 +-
> http.c | 6 +-
> list-objects-filter.c | 4 +-
> list-objects.c | 6 +-
> log-tree.c | 2 +-
> loose.c | 24 +-
> mailmap.c | 4 +-
> match-trees.c | 6 +-
> merge-blobs.c | 10 +-
> merge-ort.c | 8 +-
> meson.build | 2 +-
> midx-write.c | 2 +-
> midx.c | 6 +-
> notes-cache.c | 4 +-
> notes-merge.c | 4 +-
> notes.c | 19 +-
> object-file.c | 60 ++---
> object-file.h | 12 +-
> object-name.c | 24 +-
> object.c | 8 +-
> object-store.c => odb.c | 395 +++++++++++++++++---------------
> object-store.h => odb.h | 271 ++++++++++++++++------
> oss-fuzz/fuzz-pack-idx.c | 2 +-
> pack-bitmap-write.c | 9 +-
> pack-bitmap.c | 10 +-
> pack-check.c | 2 +-
> pack-mtimes.c | 2 +-
> pack-objects.h | 2 +-
> pack-revindex.c | 2 +-
> pack-write.c | 10 +-
> packfile.c | 29 +--
> packfile.h | 8 +-
> path.c | 4 +-
> promisor-remote.c | 6 +-
> protocol-caps.c | 4 +-
> reachable.c | 2 +-
> read-cache.c | 14 +-
> ref-filter.c | 6 +-
> reflog.c | 8 +-
> refs.c | 7 +-
> remote.c | 9 +-
> replace-object.c | 2 +-
> replace-object.h | 2 +-
> repository.c | 21 +-
> repository.h | 4 +-
> rerere.c | 7 +-
> revision.c | 5 +-
> send-pack.c | 4 +-
> sequencer.c | 7 +-
> server-info.c | 2 +-
> shallow.c | 14 +-
> streaming.c | 10 +-
> submodule-config.c | 9 +-
> submodule.c | 32 +--
> submodule.h | 9 -
> t/helper/test-find-pack.c | 2 +-
> t/helper/test-pack-mtimes.c | 2 +-
> t/helper/test-partial-clone.c | 4 +-
> t/helper/test-read-graph.c | 8 +-
> t/helper/test-read-midx.c | 2 +-
> t/helper/test-ref-store.c | 4 +-
> tag.c | 10 +-
> tmp-objdir.c | 18 +-
> tree-walk.c | 18 +-
> tree.c | 6 +-
> unpack-trees.c | 2 +-
> upload-pack.c | 4 +-
> walker.c | 6 +-
> xdiff-interface.c | 4 +-
> 139 files changed, 1104 insertions(+), 961 deletions(-)
>
>
> ---
> base-commit: 046efb6f2b050efd580e1c1750b77328a1790c0e
> change-id: 20250505-pks-object-store-wo-the-repository-9c6cbdf8d4b1
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v2 00/17] object-store: carve out the object database subsystem
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (18 preceding siblings ...)
2025-05-07 23:22 ` Junio C Hamano
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
` (17 more replies)
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (3 subsequent siblings)
23 siblings, 18 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
Hi,
this patch series refactors the object store subsystem to become more
self-contained by getting rid of `the_repository`. Instead of passing in
the repository explicitly, we start to pass in the object store itself,
which is in contrast to many other refactorings we did, but in line with
what we did for the ref store, as well.
This series also starts to properly scope functions to the carved out
object database subsystem, which requires a bit of shuffling. This
allows us to have a short-and-sweet `odb_` prefix for functions and
prepares us for a future with pluggable object backends.
The series is structured as follows:
- Patches 1 to 3 rename `struct object_store` and `struct
object_directory` as well as the code files.
- Patches 4 to 12 refactor "odb.c" to get rid of `the_repository`.
- Patches 13 to 17 adjust the name of remaining functions so that they
can be clearly attributed to the ODB. I'm happy to kick these
patches out of this series and resend them at a later point in case
they create too much turmoil.
This series is built on top of 6f84262c44a (The eleventh batch,
2025-05-05) with ps/object-store-cleanup at 8a9e27be821 (object-store:
drop `repo_has_object_file()`, 2025-04-29) merged into it. There are a
couple of trivial conflicts when merged with "seen", I have appended the
merge conflict resolution as a patch at the end of this mail.
Changes in v2:
- Fix for a copy-and-pasted commit message.
- Rename `struct odb_backend` to `struct odb_alternate`. I'm happy to
revert to the previous name if we ultimately think it's the better
suited one.
- A couple of fixes to move changes into the correct commit. `git
rebase -x 'meson compile -C build'` is now clean.
- I _didn't_ back out the rename to "odb.{c,h}". Junio has already
fixed the fallout, so it's probably more work for him to kick it out
again than to just leave it in.
- Link to v1: https://lore.kernel.org/r/20250506-pks-object-store-wo-the-repository-v1-0-c05b82e7b126@pks.im
Thanks!
Patrick
---
Patrick Steinhardt (17):
object-store: rename `raw_object_store` to `object_database`
object-store: rename `object_directory` to `odb_alternate`
object-store: rename files to "odb.{c,h}"
odb: introduce parent pointers
odb: get rid of `the_repository` in `find_odb()`
odb: get rid of `the_repository` in `assert_oid_type()`
odb: get rid of `the_repository` in `odb_mkstemp()`
odb: get rid of `the_repository` when handling alternates
odb: get rid of `the_repository` in `for_each()` functions
odb: get rid of `the_repository` when handling the primary alternate
odb: get rid of `the_repository` when handling submodule alternates
odb: trivial refactorings to get rid of `the_repository`
odb: rename `oid_object_info()`
odb: rename `repo_read_object_file()`
odb: rename `has_object()`
odb: rename `pretend_object_file()`
odb: rename `read_object_with_reference()`
Documentation/user-manual.adoc | 4 +-
Makefile | 2 +-
apply.c | 14 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 6 +-
attr.c | 4 +-
bisect.c | 8 +-
blame.c | 22 +-
builtin/backfill.c | 6 +-
builtin/blame.c | 6 +-
builtin/cat-file.c | 62 +++--
builtin/checkout.c | 2 +-
builtin/clone.c | 14 +-
builtin/commit-graph.c | 20 +-
builtin/commit-tree.c | 4 +-
builtin/count-objects.c | 6 +-
builtin/describe.c | 5 +-
builtin/difftool.c | 4 +-
builtin/fast-export.c | 10 +-
builtin/fast-import.c | 49 ++--
builtin/fetch.c | 21 +-
builtin/fsck.c | 31 +--
builtin/gc.c | 16 +-
builtin/grep.c | 26 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 29 +--
builtin/log.c | 4 +-
builtin/ls-files.c | 4 +-
builtin/ls-tree.c | 6 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 14 +-
builtin/mktag.c | 6 +-
builtin/mktree.c | 10 +-
builtin/multi-pack-index.c | 6 +-
builtin/notes.c | 8 +-
builtin/pack-objects.c | 70 +++---
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 6 +-
builtin/receive-pack.c | 9 +-
builtin/remote.c | 6 +-
builtin/repack.c | 7 +-
builtin/replace.c | 12 +-
builtin/rev-list.c | 8 +-
builtin/show-ref.c | 6 +-
builtin/submodule--helper.c | 11 +-
builtin/tag.c | 10 +-
builtin/unpack-file.c | 4 +-
builtin/unpack-objects.c | 12 +-
bulk-checkin.c | 6 +-
bundle-uri.c | 5 +-
bundle.c | 6 +-
cache-tree.c | 17 +-
combine-diff.c | 4 +-
commit-graph.c | 106 ++++----
commit-graph.h | 20 +-
commit.c | 15 +-
config.c | 4 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 12 +-
diff.c | 20 +-
dir.c | 2 +-
entry.c | 6 +-
fetch-pack.c | 17 +-
fmt-merge-msg.c | 6 +-
fsck.c | 4 +-
grep.c | 6 +-
http-backend.c | 2 +-
http-push.c | 20 +-
http-walker.c | 12 +-
http.c | 6 +-
list-objects-filter.c | 4 +-
list-objects.c | 6 +-
log-tree.c | 2 +-
loose.c | 46 ++--
mailmap.c | 4 +-
match-trees.c | 6 +-
merge-blobs.c | 10 +-
merge-ort.c | 8 +-
meson.build | 2 +-
midx-write.c | 2 +-
midx.c | 6 +-
notes-cache.c | 4 +-
notes-merge.c | 4 +-
notes.c | 19 +-
object-file.c | 94 ++++----
object-file.h | 12 +-
object-name.c | 24 +-
object.c | 8 +-
object-store.c => odb.c | 413 +++++++++++++++++---------------
object-store.h => odb.h | 269 +++++++++++++++------
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 9 +-
pack-bitmap.c | 10 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
pack-write.c | 10 +-
packfile.c | 29 +--
packfile.h | 8 +-
path.c | 4 +-
promisor-remote.c | 6 +-
protocol-caps.c | 4 +-
reachable.c | 2 +-
read-cache.c | 14 +-
ref-filter.c | 6 +-
reflog.c | 8 +-
refs.c | 7 +-
remote.c | 9 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 21 +-
repository.h | 4 +-
rerere.c | 7 +-
revision.c | 5 +-
send-pack.c | 4 +-
sequencer.c | 7 +-
server-info.c | 2 +-
shallow.c | 14 +-
streaming.c | 10 +-
submodule-config.c | 9 +-
submodule.c | 32 +--
submodule.h | 9 -
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 4 +-
t/helper/test-read-graph.c | 8 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 4 +-
tag.c | 10 +-
tmp-objdir.c | 30 +--
tree-walk.c | 18 +-
tree.c | 6 +-
unpack-trees.c | 2 +-
upload-pack.c | 4 +-
walker.c | 6 +-
xdiff-interface.c | 4 +-
139 files changed, 1177 insertions(+), 1032 deletions(-)
Range-diff versus v1:
1: 83f6482bffd = 1: 683857de5d7 object-store: rename `raw_object_store` to `object_database`
2: 1009722a206 < -: ----------- object-store: rename `object_directory` to `odb_backend`
-: ----------- > 2: 5b13164e353 object-store: rename `object_directory` to `odb_alternate`
3: fd36b863411 = 3: abd9ecd1589 object-store: rename files to "odb.{c,h}"
4: 910ef0beb61 ! 4: 25e30b9040b odb: introduce parent pointers
@@ Commit message
In subsequent commits we'll get rid of our use of `the_repository` in
"odb.c" in favor of explicitly passing in a `struct object_database` or
- a `struct odb_backend`. In some cases though we'll need access to the
+ a `struct odb_alternate`. In some cases though we'll need access to the
repository, for example to read a config value from it, but we don't
have a way to access the repository owning a specific object database.
Introduce parent pointers for `struct object_database` to its owning
- repository as well as for `struct odb_backend` to its owning object
+ repository as well as for `struct odb_alternate` to its owning object
database, which will allow us to adapt those use cases.
Note that this change requires us to pass through the object database to
`link_alt_odb_entry()` so that we can set up the parent pointers for any
- alternative backends there. The callchain is adapted to pass through the
- object database accordingly.
+ alternate there. The callchain is adapted to pass through the object
+ database accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
@@ odb.c: static int alt_odb_usable(struct object_database *o,
+ int depth,
+ const char *normalized_objdir)
{
- struct odb_backend *backend;
+ struct odb_alternate *alternate;
struct strbuf pathbuf = STRBUF_INIT;
@@ odb.c: static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
@@ odb.c: static int link_alt_odb_entry(struct repository *r, const struct strbuf *
+ if (!alt_odb_usable(odb, &pathbuf, normalized_objdir, &pos))
goto error;
- CALLOC_ARRAY(backend, 1);
-+ backend->odb = odb;
- /* pathbuf.buf is already in r->objects->backend_by_path */
- backend->path = strbuf_detach(&pathbuf, NULL);
+ CALLOC_ARRAY(alternate, 1);
++ alternate->odb = odb;
+ /* pathbuf.buf is already in r->objects->alternate_by_path */
+ alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
-- *r->objects->backends_tail = backend;
-- r->objects->backends_tail = &(backend->next);
-+ *odb->backends_tail = backend;
-+ odb->backends_tail = &(backend->next);
- backend->next = NULL;
-- assert(r->objects->backend_by_path);
-- kh_value(r->objects->backend_by_path, pos) = backend;
-+ assert(odb->backend_by_path);
-+ kh_value(odb->backend_by_path, pos) = backend;
+- *r->objects->alternates_tail = alternate;
+- r->objects->alternates_tail = &(alternate->next);
++ *odb->alternates_tail = alternate;
++ odb->alternates_tail = &(alternate->next);
+ alternate->next = NULL;
+- assert(r->objects->alternate_by_path);
+- kh_value(r->objects->alternate_by_path, pos) = alternate;
++ assert(odb->alternate_by_path);
++ kh_value(odb->alternate_by_path, pos) = alternate;
/* recursively add alternates */
-- read_info_alternates(r, backend->path, depth + 1);
-+ read_info_alternates(odb, backend->path, depth + 1);
+- read_info_alternates(r, alternate->path, depth + 1);
++ read_info_alternates(odb, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ odb.c: static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
-- strbuf_realpath(&objdirbuf, r->objects->backends->path, 1);
-+ strbuf_realpath(&objdirbuf, odb->backends->path, 1);
+- strbuf_realpath(&objdirbuf, r->objects->alternates->path, 1);
++ strbuf_realpath(&objdirbuf, odb->alternates->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
@@ odb.c: void add_to_alternates_memory(const char *reference)
'\n', NULL, 0);
}
-@@ odb.c: struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy)
+@@ odb.c: struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
* alternate
*/
- backend = xcalloc(1, sizeof(*backend));
-+ backend->odb = the_repository->objects;
- backend->path = xstrdup(dir);
+ alternate = xcalloc(1, sizeof(*alternate));
++ alternate->odb = the_repository->objects;
+ alternate->path = xstrdup(dir);
/*
@@ odb.c: void prepare_alt_odb(struct repository *r)
@@ odb.c: void prepare_alt_odb(struct repository *r)
- link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
-- read_info_alternates(r, r->objects->backends->path, 0);
-+ read_info_alternates(r->objects, r->objects->backends->path, 0);
+- read_info_alternates(r, r->objects->alternates->path, 0);
++ read_info_alternates(r->objects, r->objects->alternates->path, 0);
r->objects->loaded_alternates = 1;
}
-@@ odb.c: struct object_database *odb_new(struct repository *repo)
+@@ odb.c: void assert_oid_type(const struct object_id *oid, enum object_type expect)
+ type_name(expect));
+ }
+
+-struct object_database *odb_new(void)
++struct object_database *odb_new(struct repository *repo)
+ {
struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
@@ odb.c: struct object_database *odb_new(struct repository *repo)
## odb.h ##
@@ odb.h: struct repository;
- struct odb_backend {
- struct odb_backend *next;
+ struct odb_alternate {
+ struct odb_alternate *next;
-+ /* Object database that owns this backend. */
++ /* Object database that owns this alternate. */
+ struct object_database *odb;
+
/*
@@ odb.h: struct cached_object_entry;
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
+@@ odb.h: struct object_database {
+ unsigned packed_git_initialized : 1;
+ };
+
+-struct object_database *odb_new(void);
++struct object_database *odb_new(struct repository *repo);
+ void odb_clear(struct object_database *o);
+
+ /*
+
+ ## repository.c ##
+@@ repository.c: static void set_default_hash_algo(struct repository *repo)
+
+ void initialize_repository(struct repository *repo)
+ {
+- repo->objects = odb_new();
++ repo->objects = odb_new(repo);
+ repo->remote_state = remote_state_new();
+ repo->parsed_objects = parsed_object_pool_new(repo);
+ ALLOC_ARRAY(repo->index, 1);
+@@ repository.c: void repo_set_gitdir(struct repository *repo,
+
+ if (!repo->objects->alternates) {
+ CALLOC_ARRAY(repo->objects->alternates, 1);
++ repo->objects->alternates->odb = repo->objects;
+ repo->objects->alternates_tail = &repo->objects->alternates->next;
+ }
+ expand_base_dir(&repo->objects->alternates->path, o->object_dir,
5: a045ad2f30e < -: ----------- odb: get rid of `the_repository` in `find_odb()`
-: ----------- > 5: b642cc5bb8b odb: get rid of `the_repository` in `find_odb()`
6: e408fb9a963 = 6: 188240381ce odb: get rid of `the_repository` in `assert_oid_type()`
7: f2da8b8d507 ! 7: 61a27202f3e odb: get rid of `the_repository` in `assert_oid_type()`
@@ Metadata
Author: Patrick Steinhardt <ps@pks.im>
## Commit message ##
- odb: get rid of `the_repository` in `assert_oid_type()`
+ odb: get rid of `the_repository` in `odb_mkstemp()`
- Get rid of our dependency on `the_repository` in `assert_oid_type()` by
+ Get rid of our dependency on `the_repository` in `odb_mkstemp()` by
passing in the object database as a parameter and adjusting all callers.
- Rename the function to `odb_assert_oid_type()`.
-
Signed-off-by: Patrick Steinhardt <ps@pks.im>
## builtin/fast-import.c ##
@@ odb.c: int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
## odb.h ##
@@ odb.h: void odb_clear(struct object_database *o);
- struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir);
+ struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
/*
- * Create a temporary file rooted in the object database directory, or
- * die on failure. The filename is taken from "pattern", which should have the
-- * usual "XXXXXX" trailer, and the resulting filename is written into the
-- * "template" buffer. Returns the open descriptor.
-+ * Create a temporary file rooted in the primary object database backend's
-+ * directory, or die on failure. The filename is taken from "pattern", which
-+ * should have the usual "XXXXXX" trailer, and the resulting filename is
-+ * written into the "template" buffer. Returns the open descriptor.
++ * Create a temporary file rooted in the primary alternate's directory, or die
++ * on failure. The filename is taken from "pattern", which should have the
+ * usual "XXXXXX" trailer, and the resulting filename is written into the
+ * "template" buffer. Returns the open descriptor.
*/
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
+int odb_mkstemp(struct object_database *odb,
8: 852ff66ec5e ! 8: 8b6801ea2dd odb: get rid of `the_repository` when handling alternates
@@ builtin/fsck.c: int cmd_fsck(int argc,
} else {
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (backend = the_repository->objects->backends; backend; backend = backend->next)
- fsck_object_dir(backend->path);
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next)
+ fsck_object_dir(alternate->path);
@@ builtin/fsck.c: int cmd_fsck(int argc,
if (the_repository->settings.core_commit_graph) {
@@ builtin/fsck.c: int cmd_fsck(int argc,
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (backend = the_repository->objects->backends; backend; backend = backend->next) {
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
@@ builtin/fsck.c: int cmd_fsck(int argc,
@@ builtin/fsck.c: int cmd_fsck(int argc,
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (backend = the_repository->objects->backends; backend; backend = backend->next) {
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
@@ commit-graph.c: struct commit_graph *load_commit_graph_chain_fd_st(struct reposi
+ odb_prepare_alternates(r->objects);
for (i = 0; i < count; i++) {
- struct odb_backend *backend;
+ struct odb_alternate *alternate;
@@ commit-graph.c: static int prepare_commit_graph(struct repository *r)
if (!commit_graph_compatible(r))
return 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (backend = r->objects->backends;
- !r->objects->commit_graph && backend;
- backend = backend->next)
+ for (alternate = r->objects->alternates;
+ !r->objects->commit_graph && alternate;
+ alternate = alternate->next)
## loose.c ##
@@ loose.c: int repo_read_loose_object_map(struct repository *repo)
@@ loose.c: int repo_read_loose_object_map(struct repository *repo)
- prepare_alt_odb(repo);
+ odb_prepare_alternates(repo->objects);
- for (backend = repo->objects->backends; backend; backend = backend->next) {
- if (load_one_loose_object_map(repo, backend) < 0) {
+ for (alternate = repo->objects->alternates; alternate; alternate = alternate->next) {
+ if (load_one_loose_object_map(repo, alternate) < 0) {
## object-file.c ##
@@ object-file.c: static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
- struct odb_backend *backend;
+ struct odb_alternate *alternate;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (backend = the_repository->objects->backends->next; backend; backend = backend->next) {
- if (check_and_freshen_odb(backend, oid, freshen))
+ for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
+ if (check_and_freshen_odb(alternate, oid, freshen))
return 1;
@@ object-file.c: static int stat_loose_object(struct repository *r, const struct object_id *oid,
- struct odb_backend *backend;
+ struct odb_alternate *alternate;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (backend = r->objects->backends; backend; backend = backend->next) {
- *path = odb_loose_path(backend, &buf, oid);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ *path = odb_loose_path(alternate, &buf, oid);
if (!lstat(*path, st))
@@ object-file.c: static int open_loose_object(struct repository *r,
int most_interesting_errno = ENOENT;
@@ object-file.c: static int open_loose_object(struct repository *r,
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (backend = r->objects->backends; backend; backend = backend->next) {
- *path = odb_loose_path(backend, &buf, oid);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ *path = odb_loose_path(alternate, &buf, oid);
fd = git_open(*path);
@@ object-file.c: static int quick_has_loose(struct repository *r,
{
- struct odb_backend *backend;
+ struct odb_alternate *alternate;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (backend = r->objects->backends; backend; backend = backend->next) {
- if (oidtree_contains(odb_loose_cache(backend, oid), oid))
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ if (oidtree_contains(odb_loose_cache(alternate, oid), oid))
return 1;
@@ object-file.c: int for_each_loose_object(each_loose_object_fn cb, void *data,
{
- struct odb_backend *backend;
+ struct odb_alternate *alternate;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (backend = the_repository->objects->backends; backend; backend = backend->next) {
- int r = for_each_loose_file_in_objdir(backend->path, cb, NULL,
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
+ int r = for_each_loose_file_in_objdir(alternate->path, cb, NULL,
NULL, data);
## object-name.c ##
@@ odb.c: void add_to_alternates_file(const char *reference)
'\n', NULL, 0);
}
-@@ odb.c: struct odb_backend *set_temporary_primary_odb(const char *dir, int will_destroy)
+@@ odb.c: struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
@@ odb.c: struct odb_backend *set_temporary_primary_odb(const char *dir, int will_d
/*
* Make a new primary odb and link the old primary ODB in as an
-@@ odb.c: void restore_primary_odb(struct odb_backend *restore_odb, const char *old_path)
- free_object_directory(cur_odb);
+@@ odb.c: void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path
+ free_object_directory(cur_alt);
}
-/*
@@ odb.c: void restore_primary_odb(struct odb_backend *restore_odb, const char *old
char *compute_alternate_path(const char *path, struct strbuf *err)
{
char *ref_git = NULL;
-@@ odb.c: struct odb_backend *odb_find_backend(struct object_database *odb, const char *ob
+@@ odb.c: struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(odb->repo);
+ odb_prepare_alternates(odb);
- for (backend = odb->backends; backend; backend = backend->next) {
- strbuf_realpath(&odb_path_real, backend->path, 1);
+ for (alternate = odb->alternates; alternate; alternate = alternate->next) {
+ strbuf_realpath(&odb_path_real, alternate->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
@@ odb.c: int foreach_alt_odb(alt_odb_fn fn, void *cb)
- struct odb_backend *backend;
+ struct odb_alternate *alternate;
int r = 0;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (backend = the_repository->objects->backends->next; backend; backend = backend->next) {
- r = fn(backend, cb);
+ for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
+ r = fn(alternate, cb);
if (r)
@@ odb.c: int foreach_alt_odb(alt_odb_fn fn, void *cb)
return r;
@@ odb.c: int foreach_alt_odb(alt_odb_fn fn, void *cb)
- link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(odb, odb->alternate_db, PATH_SEP, NULL, 0);
-- read_info_alternates(r->objects, r->objects->backends->path, 0);
+- read_info_alternates(r->objects, r->objects->alternates->path, 0);
- r->objects->loaded_alternates = 1;
-+ read_info_alternates(odb, odb->backends->path, 0);
++ read_info_alternates(odb, odb->alternates->path, 0);
+ odb->loaded_alternates = 1;
}
@@ odb.c: int foreach_alt_odb(alt_odb_fn fn, void *cb)
+int odb_has_alternates(struct object_database *odb)
{
- prepare_alt_odb(r);
-- return !!r->objects->backends->next;
+- return !!r->objects->alternates->next;
+ odb_prepare_alternates(odb);
-+ return !!odb->backends->next;
++ return !!odb->alternates->next;
}
int obj_read_use_lock = 0;
@@ odb.h: struct oidtree;
+ */
+char *compute_alternate_path(const char *path, struct strbuf *err);
+
- /* The backend used to access objects in a specific object directory. */
- struct odb_backend {
- struct odb_backend *next;
-@@ odb.h: struct odb_backend {
+ /*
+ * An alternate part of an object database that stores the actual objects.
+ */
+@@ odb.h: struct odb_alternate {
char *path;
};
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
- typedef int alt_odb_fn(struct odb_backend *, void *);
+ typedef int alt_odb_fn(struct odb_alternate *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
@@ odb.h: struct object_database {
/*
* A list of alternate object directories loaded from the environment;
* this should not generally need to be accessed directly, but will
-- * populate the "backends" list when prepare_alt_odb() is run.
-+ * populate the "backends" list when odb_prepare_alternates() is run.
+- * populate the "alternates" list when prepare_alt_odb() is run.
++ * populate the "alternates" list when odb_prepare_alternates() is run.
*/
char *alternate_db;
-@@ odb.h: struct odb_backend *odb_find_backend(struct object_database *odb, const char *ob
+@@ odb.h: struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
int odb_mkstemp(struct object_database *odb,
struct strbuf *temp_filename, const char *pattern);
+/*
+ * Prepare alternate object backends for the given database by reading
-+ * "objects/info/alternates" and opening the respective backends.
++ * "objects/info/alternates" and opening the respective alternates.
+ */
+void odb_prepare_alternates(struct object_database *odb);
+
+/*
-+ * Check whether the object database has any alternate backends. The primary
-+ * object backend does not count as alternate.
++ * Check whether the object database has any alternates. The primary object
++ * backend does not count as alternate.
+ */
+int odb_has_alternates(struct object_database *odb);
+
@@ packfile.c: static void prepare_packed_git(struct repository *r)
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (backend = r->objects->backends; backend; backend = backend->next) {
- int local = (backend == r->objects->backends);
- prepare_multi_pack_index_one(r, backend->path, local);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ int local = (alternate == r->objects->alternates);
+ prepare_multi_pack_index_one(r, alternate->path, local);
@@ packfile.c: void reprepare_packed_git(struct repository *r)
* the lifetime of the process.
*/
@@ packfile.c: void reprepare_packed_git(struct repository *r)
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (backend = r->objects->backends; backend; backend = backend->next)
- odb_clear_loose_cache(backend);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next)
+ odb_clear_loose_cache(alternate);
## submodule.c ##
@@ submodule.c: int register_all_submodule_odb_as_alternates(void)
9: 00c4884c796 ! 9: cfaf09542ca odb: get rid of `the_repository` in `for_each()` functions
@@ builtin/count-objects.c: int cmd_count_objects(int argc,
printf("garbage: %lu\n", garbage);
printf("size-garbage: %s\n", garbage_buf.buf);
- foreach_alt_odb(print_alternate, NULL);
-+ odb_for_each_backend(the_repository->objects, print_alternate, NULL);
++ odb_for_each_alternate(the_repository->objects, print_alternate, NULL);
strbuf_release(&loose_buf);
strbuf_release(&pack_buf);
strbuf_release(&garbage_buf);
@@ builtin/submodule--helper.c: static void prepare_possible_alternates(const char
if (!strcmp(sm_alternate, "superproject"))
- foreach_alt_odb(add_possible_reference_from_superproject, &sas);
-+ odb_for_each_backend(the_repository->objects,
-+ add_possible_reference_from_superproject, &sas);
++ odb_for_each_alternate(the_repository->objects,
++ add_possible_reference_from_superproject, &sas);
else if (!strcmp(sm_alternate, "no"))
; /* do nothing */
else
@@ diagnose.c
@@ diagnose.c: int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(r->objects->backends, &buf);
+ dir_file_stats(r->objects->alternates, &buf);
- foreach_alt_odb(dir_file_stats, &buf);
-+ odb_for_each_backend(r->objects, dir_file_stats, &buf);
++ odb_for_each_alternate(r->objects, dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
strbuf_reset(&buf);
@@ odb.c: static void read_alternate_refs(const char *path,
+ void *payload;
};
- static int refs_from_alternate_cb(struct odb_backend *e,
+ static int refs_from_alternate_cb(struct odb_alternate *alternate,
- void *data)
+ void *payload)
{
@@ odb.c: static void read_alternate_refs(const char *path,
- struct alternate_refs_data *cb = data;
+ struct alternate_refs_data *cb = payload;
- if (!strbuf_realpath(&path, e->path, 0))
+ if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
-@@ odb.c: static int refs_from_alternate_cb(struct odb_backend *e,
+@@ odb.c: static int refs_from_alternate_cb(struct odb_alternate *alternate,
goto out;
strbuf_setlen(&path, base_len);
@@ odb.c: static int refs_from_alternate_cb(struct odb_backend *e,
+ struct alternate_refs_data data;
+ data.fn = cb;
+ data.payload = payload;
-+ odb_for_each_backend(odb, refs_from_alternate_cb, &data);
++ odb_for_each_alternate(odb, refs_from_alternate_cb, &data);
}
-int foreach_alt_odb(alt_odb_fn fn, void *cb)
-+int odb_for_each_backend(struct object_database *odb,
-+ odb_for_each_backend_fn cb, void *payload)
++int odb_for_each_alternate(struct object_database *odb,
++ odb_for_each_alternate_fn cb, void *payload)
{
- struct odb_backend *backend;
+ struct odb_alternate *alternate;
int r = 0;
- odb_prepare_alternates(the_repository->objects);
-- for (backend = the_repository->objects->backends->next; backend; backend = backend->next) {
-- r = fn(backend, cb);
+- for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
+- r = fn(alternate, cb);
+ odb_prepare_alternates(odb);
-+ for (backend = odb->backends->next; backend; backend = backend->next) {
-+ r = cb(backend, payload);
++ for (alternate = odb->alternates->next; alternate; alternate = alternate->next) {
++ r = cb(alternate, payload);
if (r)
break;
}
## odb.h ##
-@@ odb.h: struct odb_backend {
+@@ odb.h: struct odb_alternate {
char *path;
};
--typedef int alt_odb_fn(struct odb_backend *, void *);
+-typedef int alt_odb_fn(struct odb_alternate *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
@@ odb.h: struct odb_backend {
* object directory; returns the former primary object directory.
@@ odb.h: void odb_clear(struct object_database *o);
*/
- struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir);
+ struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
+/*
-+ * Iterate through all backends of the database and execute the provided
++ * Iterate through all alternates of the database and execute the provided
+ * callback function for each of them. Stop iterating once the callback
+ * function returns a non-zero value, in which case the value is bubbled up
+ * from the callback.
+ */
-+typedef int odb_for_each_backend_fn(struct odb_backend *, void *);
-+int odb_for_each_backend(struct object_database *odb,
-+ odb_for_each_backend_fn cb, void *payload);
++typedef int odb_for_each_alternate_fn(struct odb_alternate *, void *);
++int odb_for_each_alternate(struct object_database *odb,
++ odb_for_each_alternate_fn cb, void *payload);
+
+/*
-+ * Iterate through all alternative object backends of the database and yield
-+ * their respective references.
++ * Iterate through all alternates of the database and yield their respective
++ * references.
+ */
+typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload);
+
/*
- * Create a temporary file rooted in the primary object database backend's
- * directory, or die on failure. The filename is taken from "pattern", which
+ * Create a temporary file rooted in the primary alternate's directory, or die
+ * on failure. The filename is taken from "pattern", which should have the
## revision.c ##
@@ revision.c: static void add_alternate_refs_to_pending(struct rev_info *revs,
10: 758255fd936 < -: ----------- odb: get rid of `the_repository` when handling the primary backend
-: ----------- > 10: bc8c73b140d odb: get rid of `the_repository` when handling the primary alternate
11: d07a78aa858 ! 11: b0fb9566ae1 odb: get rid of `the_repository` when handling submodule backends
@@ Metadata
Author: Patrick Steinhardt <ps@pks.im>
## Commit message ##
- odb: get rid of `the_repository` when handling submodule backends
+ odb: get rid of `the_repository` when handling submodule alternates
The "--recursive" flag for git-grep(1) allows users to grep for a string
across submodule boundaries. To make this work we add each submodule's
- object backend to our own object database so that the objects can be
+ object alternate to our own object database so that the objects can be
accessed directly.
The infrastructure for this depends on a global string list of submodule
paths. The caller is expected to call `add_submodule_odb_by_path()` for
- each backend and the object database will then eventually register all
- submodule backends via `do_oid_object_info_extended()` in case it isn't
- able to look up a specific object.
+ each alternate and the object database will then eventually register all
+ submodule alternates via `do_oid_object_info_extended()` in case it
+ isn't able to look up a specific object.
This reliance on global state is of course suboptimal with regards to
our libification efforts.
- Refactor the logic so that the list of submodule backends is instead
+ Refactor the logic so that the list of submodule alternates is instead
tracked in the object database itself. This allows us to lose the
- condition of `r == the_repository` before registering submodule backends
- as we only ever add submodule backends to `the_repository` anyway. As
- such, behaviour before and after this refactoring should always be the
- same.
+ condition of `r == the_repository` before registering submodule
+ alternates as we only ever add submodule alternates to `the_repository`
+ anyway. As such, behaviour before and after this refactoring should
+ always be the same.
Rename the functions accordingly.
@@ builtin/grep.c: static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
-- add_submodule_odb_by_path(subrepo->objects->backends->path);
-+ odb_add_submodule_backend_by_path(the_repository->objects,
-+ subrepo->objects->backends->path);
+- add_submodule_odb_by_path(subrepo->objects->alternates->path);
++ odb_add_submodule_alternate_by_path(the_repository->objects,
++ subrepo->objects->alternates->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
@@ odb.c
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
-@@ odb.c: struct odb_backend *odb_find_backend(struct object_database *odb, const char *ob
- return backend;
+@@ odb.c: struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
+ return alternate;
}
-+void odb_add_submodule_backend_by_path(struct object_database *odb,
-+ const char *path)
++void odb_add_submodule_alternate_by_path(struct object_database *odb,
++ const char *path)
+{
-+ string_list_insert(&odb->submodule_backend_paths, path);
++ string_list_insert(&odb->submodule_alternate_paths, path);
+}
+
static void fill_alternate_refs_command(struct child_process *cmd,
@@ odb.c: void disable_obj_read_lock(void)
int fetch_if_missing = 1;
-+static int register_all_submodule_backends(struct object_database *odb)
++static int register_all_submodule_alternates(struct object_database *odb)
+{
-+ int ret = odb->submodule_backend_paths.nr;
++ int ret = odb->submodule_alternate_paths.nr;
+
-+ for (size_t i = 0; i < odb->submodule_backend_paths.nr; i++)
++ for (size_t i = 0; i < odb->submodule_alternate_paths.nr; i++)
+ odb_add_to_alternates_memory(odb,
-+ odb->submodule_backend_paths.items[i].string);
++ odb->submodule_alternate_paths.items[i].string);
+ if (ret) {
-+ string_list_clear(&odb->submodule_backend_paths, 0);
++ string_list_clear(&odb->submodule_alternate_paths, 0);
+ trace2_data_intmax("submodule", odb->repo,
-+ "register_all_submodule_backends/registered", ret);
++ "register_all_submodule_alternates/registered", ret);
+ if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
-+ BUG("register_all_submodule_backends() called");
++ BUG("register_all_submodule_alternates() called");
+ }
+ return ret;
+}
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
- * If any such ODBs exist, register them and try again.
+ * This might be an attempt at accessing a submodule object as
+ * if it were in main object store (having called
-+ * `odb_add_submodule_backend_by_path()` on that submodule's
++ * `odb_add_submodule_alternate_by_path()` on that submodule's
+ * ODB). If any such ODBs exist, register them and try again.
*/
- if (r == the_repository &&
- register_all_submodule_odb_as_alternates())
-+ if (register_all_submodule_backends(r->objects))
++ if (register_all_submodule_alternates(r->objects))
/* We added some alternates; retry */
continue;
@@ odb.c: struct object_database *odb_new(struct repository *repo)
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
-+ string_list_init_dup(&o->submodule_backend_paths);
++ string_list_init_dup(&o->submodule_alternate_paths);
return o;
}
@@ odb.c: void odb_clear(struct object_database *o)
o->packed_git = NULL;
hashmap_clear(&o->pack_map);
-+ string_list_clear(&o->submodule_backend_paths, 0);
++ string_list_clear(&o->submodule_alternate_paths, 0);
}
## odb.h ##
@@ odb.h: struct object_database {
unsigned packed_git_initialized : 1;
+
+ /*
-+ * Submodule backend paths that will be added as alternatives to allow
-+ * lookup of submodule objects via the main object database.
++ * Submodule alternate paths that will be added as alternatives to
++ * allow lookup of submodule objects via the main object database.
+ */
-+ struct string_list submodule_backend_paths;
++ struct string_list submodule_alternate_paths;
};
struct object_database *odb_new(struct repository *repo);
-@@ odb.h: void odb_restore_primary_backend(struct object_database *odb,
- struct odb_backend *restore_odb,
- const char *old_path);
+@@ odb.h: void odb_restore_primary_alternate(struct object_database *odb,
+ struct odb_alternate *restore_alt,
+ const char *old_path);
+/*
-+ * Call odb_add_submodule_backend_by_path() to add the submodule at the given
++ * Call odb_add_submodule_alternate_by_path() to add the submodule at the given
+ * path to a list. The object stores of all submodules in that list will be
+ * added as alternates in the object store when looking up objects.
+ */
-+void odb_add_submodule_backend_by_path(struct object_database *odb,
-+ const char *path);
++void odb_add_submodule_alternate_by_path(struct object_database *odb,
++ const char *path);
+
/*
- * Iterate through all backends of the database and execute the provided
+ * Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
## submodule-config.c ##
@@ submodule-config.c: static void config_from_gitmodules(config_fn_t fn, struct re
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
-- add_submodule_odb_by_path(repo->objects->backends->path);
-+ odb_add_submodule_backend_by_path(the_repository->objects,
-+ repo->objects->backends->path);
+- add_submodule_odb_by_path(repo->objects->alternates->path);
++ odb_add_submodule_alternate_by_path(the_repository->objects,
++ repo->objects->alternates->path);
} else {
goto out;
}
12: 2d431604aa8 ! 12: 193f65f87e6 odb: trivial refactorings to get rid of `the_repository`
@@ odb.c
#include "git-compat-util.h"
#include "abspath.h"
#include "commit-graph.h"
-@@ odb.c: void odb_add_submodule_backend_by_path(struct object_database *odb,
- string_list_insert(&odb->submodule_backend_paths, path);
+@@ odb.c: void odb_add_submodule_alternate_by_path(struct object_database *odb,
+ string_list_insert(&odb->submodule_alternate_paths, path);
}
-static void fill_alternate_refs_command(struct child_process *cmd,
@@ odb.c: static void read_alternate_refs(const char *path,
warning(_("invalid line while parsing alternate refs: %s"),
line.buf);
break;
-@@ odb.c: static int refs_from_alternate_cb(struct odb_backend *e,
+@@ odb.c: static int refs_from_alternate_cb(struct odb_alternate *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->payload);
-+ read_alternate_refs(e->odb->repo, path.buf, cb->fn, cb->payload);
++ read_alternate_refs(alternate->odb->repo, path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
13: b1182ab2498 ! 13: 24e46223958 odb: rename `oid_object_info()`
@@ object.c: struct object *parse_object_with_flags(struct repository *r,
## odb.c ##
-@@ odb.c: static int register_all_submodule_backends(struct object_database *odb)
+@@ odb.c: static int register_all_submodule_alternates(struct object_database *odb)
return ret;
}
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
}
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
- * `odb_add_submodule_backend_by_path()` on that submodule's
+ * `odb_add_submodule_alternate_by_path()` on that submodule's
* ODB). If any such ODBs exist, register them and try again.
*/
-- if (register_all_submodule_backends(r->objects))
-+ if (register_all_submodule_backends(odb))
+- if (register_all_submodule_alternates(r->objects))
++ if (register_all_submodule_alternates(odb))
/* We added some alternates; retry */
continue;
14: bdbd97d77a9 = 14: 42978727ce8 odb: rename `repo_read_object_file()`
15: ec2bb725b91 = 15: a793e6c0768 odb: rename `has_object()`
16: c576c9d1ccf = 16: 00e0f063635 odb: rename `pretend_object_file()`
17: d1dd84b5901 = 17: 8888b3320fb odb: rename `read_object_with_reference()`
---
base-commit: 046efb6f2b050efd580e1c1750b77328a1790c0e
change-id: 20250505-pks-object-store-wo-the-repository-9c6cbdf8d4b1
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v2 01/17] object-store: rename `raw_object_store` to `object_database`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-13 19:27 ` Toon Claes
2025-05-09 14:12 ` [PATCH v2 02/17] object-store: rename `object_directory` to `odb_alternate` Patrick Steinhardt
` (16 subsequent siblings)
17 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
The `raw_object_store` structure is the central entry point for reading
and writing objects in a repository. The main purpose of this structure
is to manage object directories and provide an interface to access and
write objects in those object directories.
Right now, many of the functions associated with the raw object store
implicitly rely on `the_repository` to get access to its `objects`
pointer, which is the `raw_object_store`. As we want to generally get
rid of using `the_repository` across our codebase we will have to
convert this implicit dependency on this global variable into an
explicit parameter.
This conversion can be done by simply passing in an explicit pointer to
a repository and then using its `->objects` pointer. But there is a
second effort underway, which is to make the object subsystem more
selfcontained so that we can eventually have pluggale object backends.
As such, passing in a repository wouldn't make a ton of sense, and the
goal is to convert the object store interfaces such that we always pass
in a reference to the `raw_object_store` instead.
This will expose the `raw_object_store` type to a lot more callers
though, which surfaces that this type is named somewhat awkwardly. The
"raw_" prefix makes readers wonder whether there is a non-raw variant of
the object store, but there isn't. Furthermore, we nowadays want to name
functions in a way that they can be clearly attributed to a specific
subsystem, but calling them e.g. `raw_object_store_has_object()` is just
too unwieldy, even when dropping the "raw_" prefix.
Instead, rename the structure to `object_database`. This term is already
used a lot throughout our codebase, and it cannot easily be mistaken for
"object directories", either. Furthermore, its acronym ODB is already
well-known and works well as part of a function's name, like for example
`odb_has_object()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
commit-graph.c | 2 +-
commit-graph.h | 4 ++--
object-store.c | 12 ++++++------
object-store.h | 11 ++++++++---
packfile.c | 2 +-
packfile.h | 4 ++--
repository.c | 4 ++--
repository.h | 4 ++--
8 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index 6394752b0b0..1b66486b9c9 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -829,7 +829,7 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
return NULL;
}
-void close_commit_graph(struct raw_object_store *o)
+void close_commit_graph(struct object_database *o)
{
if (!o->commit_graph)
return;
diff --git a/commit-graph.h b/commit-graph.h
index 13f662827d4..20d38c100ce 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -26,7 +26,7 @@ void git_test_write_commit_graph_or_die(void);
struct commit;
struct bloom_filter_settings;
struct repository;
-struct raw_object_store;
+struct object_database;
struct string_list;
char *get_commit_graph_filename(struct object_directory *odb);
@@ -186,7 +186,7 @@ int write_commit_graph(struct object_directory *odb,
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
-void close_commit_graph(struct raw_object_store *);
+void close_commit_graph(struct object_database *);
void free_commit_graph(struct commit_graph *);
/*
diff --git a/object-store.c b/object-store.c
index 2f51d0e3b03..1effcb12273 100644
--- a/object-store.c
+++ b/object-store.c
@@ -44,7 +44,7 @@ struct cached_object_entry {
} value;
};
-static const struct cached_object *find_cached_object(struct raw_object_store *object_store,
+static const struct cached_object *find_cached_object(struct object_database *object_store,
const struct object_id *oid)
{
static const struct cached_object empty_tree = {
@@ -86,7 +86,7 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
/*
* Return non-zero iff the path is usable as an alternate object database.
*/
-static int alt_odb_usable(struct raw_object_store *o,
+static int alt_odb_usable(struct object_database *o,
struct strbuf *path,
const char *normalized_objdir, khiter_t *pos)
{
@@ -959,9 +959,9 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct raw_object_store *raw_object_store_new(void)
+struct object_database *odb_new(void)
{
- struct raw_object_store *o = xmalloc(sizeof(*o));
+ struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
INIT_LIST_HEAD(&o->packed_git_mru);
@@ -970,7 +970,7 @@ struct raw_object_store *raw_object_store_new(void)
return o;
}
-static void free_object_directories(struct raw_object_store *o)
+static void free_object_directories(struct object_database *o)
{
while (o->odb) {
struct object_directory *next;
@@ -983,7 +983,7 @@ static void free_object_directories(struct raw_object_store *o)
o->odb_by_path = NULL;
}
-void raw_object_store_clear(struct raw_object_store *o)
+void odb_clear(struct object_database *o)
{
FREE_AND_NULL(o->alternate_db);
diff --git a/object-store.h b/object-store.h
index c2fe5a19605..34b8efbbb83 100644
--- a/object-store.h
+++ b/object-store.h
@@ -86,7 +86,12 @@ struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
-struct raw_object_store {
+/*
+ * The object database encapsulates access to objects in a repository. It
+ * manages one or more backends that store the actual objects which are
+ * configured via alternates.
+ */
+struct object_database {
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -168,8 +173,8 @@ struct raw_object_store {
unsigned packed_git_initialized : 1;
};
-struct raw_object_store *raw_object_store_new(void);
-void raw_object_store_clear(struct raw_object_store *o);
+struct object_database *odb_new(void);
+void odb_clear(struct object_database *o);
/*
* Create a temporary file rooted in the object database directory, or
diff --git a/packfile.c b/packfile.c
index d91016f1c7f..8f51665266d 100644
--- a/packfile.c
+++ b/packfile.c
@@ -359,7 +359,7 @@ void close_pack(struct packed_git *p)
oidset_clear(&p->bad_objects);
}
-void close_object_store(struct raw_object_store *o)
+void close_object_store(struct object_database *o)
{
struct packed_git *p;
diff --git a/packfile.h b/packfile.h
index 3a3c77cf05a..826eb7f475f 100644
--- a/packfile.h
+++ b/packfile.h
@@ -183,12 +183,12 @@ int close_pack_fd(struct packed_git *p);
uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
-struct raw_object_store;
+struct object_database;
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
void close_pack_windows(struct packed_git *);
void close_pack(struct packed_git *);
-void close_object_store(struct raw_object_store *o);
+void close_object_store(struct object_database *o);
void unuse_pack(struct pack_window **);
void clear_delta_base_cache(void);
struct packed_git *add_packed_git(struct repository *r, const char *path,
diff --git a/repository.c b/repository.c
index 9b3d6665fc6..07757e6e0c9 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = raw_object_store_new();
+ repo->objects = odb_new();
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -374,7 +374,7 @@ void repo_clear(struct repository *repo)
FREE_AND_NULL(repo->worktree);
FREE_AND_NULL(repo->submodule_prefix);
- raw_object_store_clear(repo->objects);
+ odb_clear(repo->objects);
FREE_AND_NULL(repo->objects);
parsed_object_pool_clear(repo->parsed_objects);
diff --git a/repository.h b/repository.h
index c4c92b2ab9c..3a5ef9c781e 100644
--- a/repository.h
+++ b/repository.h
@@ -9,7 +9,7 @@ struct git_hash_algo;
struct index_state;
struct lock_file;
struct pathspec;
-struct raw_object_store;
+struct object_database;
struct submodule_cache;
struct promisor_remote_config;
struct remote_state;
@@ -47,7 +47,7 @@ struct repository {
/*
* Holds any information related to accessing the raw object content.
*/
- struct raw_object_store *objects;
+ struct object_database *objects;
/*
* All objects in this repository that have been parsed. This structure
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v2 01/17] object-store: rename `raw_object_store` to `object_database`
2025-05-09 14:12 ` [PATCH v2 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
@ 2025-05-13 19:27 ` Toon Claes
0 siblings, 0 replies; 166+ messages in thread
From: Toon Claes @ 2025-05-13 19:27 UTC (permalink / raw)
To: Patrick Steinhardt, git; +Cc: Derrick Stolee, Junio C Hamano
Patrick Steinhardt <ps@pks.im> writes:
> The `raw_object_store` structure is the central entry point for reading
> and writing objects in a repository. The main purpose of this structure
> is to manage object directories and provide an interface to access and
> write objects in those object directories.
>
> Right now, many of the functions associated with the raw object store
> implicitly rely on `the_repository` to get access to its `objects`
> pointer, which is the `raw_object_store`. As we want to generally get
> rid of using `the_repository` across our codebase we will have to
> convert this implicit dependency on this global variable into an
> explicit parameter.
>
> This conversion can be done by simply passing in an explicit pointer to
> a repository and then using its `->objects` pointer. But there is a
> second effort underway, which is to make the object subsystem more
> selfcontained so that we can eventually have pluggale object backends.
Tiniest nit, but worth mentioning in case of a reroll:
s/pluggale/pluggable/
--
Toon
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v2 02/17] object-store: rename `object_directory` to `odb_alternate`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-13 19:28 ` Toon Claes
2025-05-09 14:12 ` [PATCH v2 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
` (15 subsequent siblings)
17 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
The `object_directory` structure is used as an access point for a single
object directory like ".git/objects". While the structure isn't yet
fully self-contained, the intent is for it to eventually contain all
information required to access objects in one specific location.
While the name "object directory" is a good fit for now, this will
change over time as we continue with the agenda to make pluggable object
databases a thing. Eventually, objects may not be accessed via any kind
of directory at all anymore, but they could instead be backed by any
kind of durable storage mechanism. While it seems quite far-fetched for
now, it is thinkable that eventually this might even be some form of a
database, for example.
As such, the current name of this structure will become worse over time
as we evolve into the direction of pluggable ODBs. Immediate next steps
will start to carve out proper self-contained object directories, which
requires us to pass in these object directories as parameters. Based on
our modern naming schema this means that those functions should then be
named after their subsystem, which means that we would start to bake the
current name into the codebase more and more.
Let's preempt this by renaming the structure to `odb_alternate` now
already. This name is agnostic of how exactly objects are stored while
still specifically pinpointing that this is about an alternate object
database. In the future, it allows us to easily introduce e.g. a
`odb_files_alternate` and other specific implementations over time.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 18 +++----
builtin/count-objects.c | 4 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 14 ++---
builtin/gc.c | 14 ++---
builtin/grep.c | 2 +-
builtin/multi-pack-index.c | 4 +-
builtin/submodule--helper.c | 6 +--
bundle.c | 2 +-
commit-graph.c | 94 +++++++++++++++++-----------------
commit-graph.h | 14 ++---
diagnose.c | 8 +--
http-walker.c | 2 +-
http.c | 4 +-
loose.c | 42 +++++++--------
midx.c | 6 +--
object-file.c | 80 ++++++++++++++---------------
object-file.h | 8 +--
object-name.c | 6 +--
object-store.c | 122 ++++++++++++++++++++++----------------------
object-store.h | 25 +++++----
packfile.c | 16 +++---
path.c | 2 +-
refs.c | 2 +-
repository.c | 14 ++---
submodule-config.c | 2 +-
t/helper/test-read-graph.c | 6 +--
tmp-objdir.c | 24 ++++-----
28 files changed, 273 insertions(+), 270 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index a783a86e797..628d3a1e92e 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb = NULL;
+ struct odb_alternate *alternate = NULL;
char *graph_name;
char *chain_name;
enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE;
@@ -101,9 +101,9 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- odb = find_odb(the_repository, opts.obj_dir);
- graph_name = get_commit_graph_filename(odb);
- chain_name = get_commit_graph_chain_filename(odb);
+ alternate = find_odb(the_repository, opts.obj_dir);
+ graph_name = get_commit_graph_filename(alternate);
+ chain_name = get_commit_graph_chain_filename(alternate);
if (open_commit_graph(graph_name, &fd, &st))
opened = OPENED_GRAPH;
else if (errno != ENOENT)
@@ -120,7 +120,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opened == OPENED_NONE)
return 0;
else if (opened == OPENED_GRAPH)
- graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb);
+ graph = load_commit_graph_one_fd_st(the_repository, fd, &st, alternate);
else
graph = load_commit_graph_chain_fd_st(the_repository, fd, &st,
&incomplete_chain);
@@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
struct string_list pack_indexes = STRING_LIST_INIT_DUP;
struct strbuf buf = STRBUF_INIT;
struct oidset commits = OIDSET_INIT;
- struct object_directory *odb = NULL;
+ struct odb_alternate *alternate = NULL;
int result = 0;
enum commit_graph_write_flags flags = 0;
struct progress *progress = NULL;
@@ -289,10 +289,10 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- odb = find_odb(the_repository, opts.obj_dir);
+ alternate = find_odb(the_repository, opts.obj_dir);
if (opts.reachable) {
- if (write_commit_graph_reachable(odb, flags, &write_opts))
+ if (write_commit_graph_reachable(alternate, flags, &write_opts))
result = 1;
goto cleanup;
}
@@ -318,7 +318,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
stop_progress(&progress);
}
- if (write_commit_graph(odb,
+ if (write_commit_graph(alternate,
opts.stdin_packs ? &pack_indexes : NULL,
opts.stdin_commits ? &commits : NULL,
flags,
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index a88c0c9c09a..da830fcee57 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -80,10 +80,10 @@ static int count_cruft(const char *basename UNUSED, const char *path,
return 0;
}
-static int print_alternate(struct object_directory *odb, void *data UNUSED)
+static int print_alternate(struct odb_alternate *alternate, void *data UNUSED)
{
printf("alternate: ");
- quote_c_style(odb->path, NULL, stdout, 0);
+ quote_c_style(alternate->path, NULL, stdout, 0);
putchar('\n');
return 0;
}
diff --git a/builtin/fetch.c b/builtin/fetch.c
index cda6eaf1fd6..4de6d3206d4 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2652,7 +2652,7 @@ int cmd_fetch(int argc,
commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
trace2_region_enter("fetch", "write-commit-graph", the_repository);
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->alternates,
commit_graph_flags,
NULL);
trace2_region_leave("fetch", "write-commit-graph", the_repository);
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6cac28356ce..9c54286540c 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -965,7 +965,7 @@ int cmd_fsck(int argc,
struct repository *repo UNUSED)
{
int i;
- struct object_directory *odb;
+ struct odb_alternate *alternate;
/* fsck knows how to handle missing promisor objects */
fetch_if_missing = 0;
@@ -1007,8 +1007,8 @@ int cmd_fsck(int argc,
mark_packed_for_connectivity, NULL, 0);
} else {
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next)
- fsck_object_dir(odb->path);
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next)
+ fsck_object_dir(alternate->path);
if (check_full) {
struct packed_git *p;
@@ -1118,11 +1118,11 @@ int cmd_fsck(int argc,
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
strvec_pushl(&commit_graph_verify.args, "commit-graph",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", alternate->path, NULL);
if (show_progress)
strvec_push(&commit_graph_verify.args, "--progress");
else
@@ -1136,11 +1136,11 @@ int cmd_fsck(int argc,
struct child_process midx_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", alternate->path, NULL);
if (show_progress)
strvec_push(&midx_verify.args, "--progress");
else
diff --git a/builtin/gc.c b/builtin/gc.c
index 78a2751aa8a..9e9d31c1f39 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -944,7 +944,7 @@ struct repository *repo UNUSED)
}
if (the_repository->settings.gc_write_commit_graph == 1)
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->alternates,
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
NULL);
@@ -1197,7 +1197,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
if (loose_object_auto_limit < 0)
return 1;
- return for_each_loose_file_in_objdir(the_repository->objects->odb->path,
+ return for_each_loose_file_in_objdir(the_repository->objects->alternates->path,
loose_object_count,
NULL, NULL, &count);
}
@@ -1232,7 +1232,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
* Do not start pack-objects process
* if there are no loose objects.
*/
- if (!for_each_loose_file_in_objdir(r->objects->odb->path,
+ if (!for_each_loose_file_in_objdir(r->objects->alternates->path,
bail_on_loose,
NULL, NULL, NULL))
return 0;
@@ -1244,7 +1244,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
strvec_push(&pack_proc.args, "--quiet");
else
strvec_push(&pack_proc.args, "--no-quiet");
- strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
+ strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->alternates->path);
pack_proc.in = -1;
@@ -1272,7 +1272,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
else if (data.batch_size > 0)
data.batch_size--; /* Decrease for equality on limit. */
- for_each_loose_file_in_objdir(r->objects->odb->path,
+ for_each_loose_file_in_objdir(r->objects->alternates->path,
write_loose_object_to_stdin,
NULL,
NULL,
@@ -1525,7 +1525,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
int result = 0;
struct lock_file lk;
struct repository *r = the_repository;
- char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path);
+ char *lock_path = xstrfmt("%s/maintenance", r->objects->alternates->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
/*
@@ -2997,7 +2997,7 @@ static int update_background_schedule(const struct maintenance_start_opts *opts,
unsigned int i;
int result = 0;
struct lock_file lk;
- char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path);
+ char *lock_path = xstrfmt("%s/schedule", the_repository->objects->alternates->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
if (errno == EEXIST)
diff --git a/builtin/grep.c b/builtin/grep.c
index 3ce574a605b..3c51a39c10d 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,7 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->odb->path);
+ add_submodule_odb_by_path(subrepo->objects->alternates->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 69a97507324..a77ae465d48 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -294,8 +294,8 @@ int cmd_multi_pack_index(int argc,
if (the_repository &&
the_repository->objects &&
- the_repository->objects->odb)
- opts.object_dir = xstrdup(the_repository->objects->odb->path);
+ the_repository->objects->alternates)
+ opts.object_dir = xstrdup(the_repository->objects->alternates->path);
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 53da2116ddf..cd7db11d825 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1582,7 +1582,7 @@ static const char alternate_error_advice[] = N_(
);
static int add_possible_reference_from_superproject(
- struct object_directory *odb, void *sas_cb)
+ struct odb_alternate *alt_odb, void *sas_cb)
{
struct submodule_alternate_setup *sas = sas_cb;
size_t len;
@@ -1591,12 +1591,12 @@ static int add_possible_reference_from_superproject(
* If the alternate object store is another repository, try the
* standard layout with .git/(modules/<name>)+/objects
*/
- if (strip_suffix(odb->path, "/objects", &len)) {
+ if (strip_suffix(alt_odb->path, "/objects", &len)) {
struct repository alternate;
char *sm_alternate;
struct strbuf sb = STRBUF_INIT;
struct strbuf err = STRBUF_INIT;
- strbuf_add(&sb, odb->path, len);
+ strbuf_add(&sb, alt_odb->path, len);
if (repo_init(&alternate, sb.buf, NULL) < 0)
die(_("could not get a repository handle for gitdir '%s'"),
diff --git a/bundle.c b/bundle.c
index b0a3fee2efa..0c7cd15bb12 100644
--- a/bundle.c
+++ b/bundle.c
@@ -233,7 +233,7 @@ int verify_bundle(struct repository *r,
.quiet = 1,
};
- if (!r || !r->objects || !r->objects->odb)
+ if (!r || !r->objects || !r->objects->alternates)
return error(_("need a repository to verify a bundle"));
for (i = 0; i < p->nr; i++) {
diff --git a/commit-graph.c b/commit-graph.c
index 1b66486b9c9..58d1eeedb1a 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -37,7 +37,7 @@ void git_test_write_commit_graph_or_die(void)
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- if (write_commit_graph_reachable(the_repository->objects->odb,
+ if (write_commit_graph_reachable(the_repository->objects->alternates,
flags, NULL))
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
}
@@ -191,21 +191,21 @@ static int commit_gen_cmp(const void *va, const void *vb)
return 0;
}
-char *get_commit_graph_filename(struct object_directory *obj_dir)
+char *get_commit_graph_filename(struct odb_alternate *alternate)
{
- return xstrfmt("%s/info/commit-graph", obj_dir->path);
+ return xstrfmt("%s/info/commit-graph", alternate->path);
}
-static char *get_split_graph_filename(struct object_directory *odb,
+static char *get_split_graph_filename(struct odb_alternate *alternate,
const char *oid_hex)
{
- return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb->path,
+ return xstrfmt("%s/info/commit-graphs/graph-%s.graph", alternate->path,
oid_hex);
}
-char *get_commit_graph_chain_filename(struct object_directory *odb)
+char *get_commit_graph_chain_filename(struct odb_alternate *alternate)
{
- return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
+ return xstrfmt("%s/info/commit-graphs/commit-graph-chain", alternate->path);
}
static struct commit_graph *alloc_commit_graph(void)
@@ -250,7 +250,7 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
void *graph_map;
size_t graph_size;
@@ -269,7 +269,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
ret = parse_commit_graph(&r->settings, graph_map, graph_size);
if (ret)
- ret->odb = odb;
+ ret->alternate = alternate;
else
munmap(graph_map, graph_size);
@@ -487,7 +487,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
static struct commit_graph *load_commit_graph_one(struct repository *r,
const char *graph_file,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
struct stat st;
@@ -498,7 +498,7 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
if (!open_ok)
return NULL;
- g = load_commit_graph_one_fd_st(r, fd, &st, odb);
+ g = load_commit_graph_one_fd_st(r, fd, &st, alternate);
if (g)
g->filename = xstrdup(graph_file);
@@ -507,10 +507,10 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
}
static struct commit_graph *load_commit_graph_v1(struct repository *r,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
- char *graph_name = get_commit_graph_filename(odb);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ char *graph_name = get_commit_graph_filename(alternate);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, alternate);
free(graph_name);
return g;
@@ -652,7 +652,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
prepare_alt_odb(r);
for (i = 0; i < count; i++) {
- struct object_directory *odb;
+ struct odb_alternate *alternate;
if (strbuf_getline_lf(&line, fp) == EOF)
break;
@@ -665,9 +665,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
valid = 0;
- for (odb = r->objects->odb; odb; odb = odb->next) {
- char *graph_name = get_split_graph_filename(odb, line.buf);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ char *graph_name = get_split_graph_filename(alternate, line.buf);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, alternate);
free(graph_name);
@@ -701,9 +701,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
static struct commit_graph *load_commit_graph_chain(struct repository *r,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
- char *chain_file = get_commit_graph_chain_filename(odb);
+ char *chain_file = get_commit_graph_chain_filename(alternate);
struct stat st;
int fd;
struct commit_graph *g = NULL;
@@ -719,24 +719,24 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
}
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
- struct commit_graph *g = load_commit_graph_v1(r, odb);
+ struct commit_graph *g = load_commit_graph_v1(r, alternate);
if (!g)
- g = load_commit_graph_chain(r, odb);
+ g = load_commit_graph_chain(r, alternate);
return g;
}
static void prepare_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
if (r->objects->commit_graph)
return;
- r->objects->commit_graph = read_commit_graph_one(r, odb);
+ r->objects->commit_graph = read_commit_graph_one(r, alternate);
}
/*
@@ -747,7 +747,7 @@ static void prepare_commit_graph_one(struct repository *r,
*/
static int prepare_commit_graph(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
/*
* Early return if there is no git dir or if the commit graph is
@@ -779,10 +779,10 @@ static int prepare_commit_graph(struct repository *r)
return 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb;
- !r->objects->commit_graph && odb;
- odb = odb->next)
- prepare_commit_graph_one(r, odb);
+ for (alternate = r->objects->alternates;
+ !r->objects->commit_graph && alternate;
+ alternate = alternate->next)
+ prepare_commit_graph_one(r, alternate);
return !!r->objects->commit_graph;
}
@@ -1137,7 +1137,7 @@ struct packed_commit_list {
struct write_commit_graph_context {
struct repository *r;
- struct object_directory *odb;
+ struct odb_alternate *alternate;
char *graph_name;
struct oid_array oids;
struct packed_commit_list commits;
@@ -1870,7 +1870,7 @@ static int add_ref_to_set(const char *refname UNUSED,
return 0;
}
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_alternate *alternate,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts)
{
@@ -1890,7 +1890,7 @@ int write_commit_graph_reachable(struct object_directory *odb,
stop_progress(&data.progress);
- result = write_commit_graph(odb, NULL, &commits,
+ result = write_commit_graph(alternate, NULL, &commits,
flags, opts);
oidset_clear(&commits);
@@ -1906,7 +1906,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
int dirlen;
int ret = 0;
- strbuf_addf(&packname, "%s/pack/", ctx->odb->path);
+ strbuf_addf(&packname, "%s/pack/", ctx->alternate->path);
dirlen = packname.len;
if (ctx->report_progress) {
strbuf_addf(&progress_title,
@@ -2058,10 +2058,10 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
strbuf_addf(&tmp_file,
"%s/info/commit-graphs/tmp_graph_XXXXXX",
- ctx->odb->path);
+ ctx->alternate->path);
ctx->graph_name = strbuf_detach(&tmp_file, NULL);
} else {
- ctx->graph_name = get_commit_graph_filename(ctx->odb);
+ ctx->graph_name = get_commit_graph_filename(ctx->alternate);
}
if (safe_create_leading_directories(the_repository, ctx->graph_name)) {
@@ -2071,7 +2071,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
if (ctx->split) {
- char *lock_name = get_commit_graph_chain_filename(ctx->odb);
+ char *lock_name = get_commit_graph_chain_filename(ctx->alternate);
hold_lock_file_for_update_mode(&lk, lock_name,
LOCK_DIE_ON_ERROR, 0444);
@@ -2159,7 +2159,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
char *new_base_hash = xstrdup(oid_to_hex(&ctx->new_base_graph->oid));
- char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb, new_base_hash);
+ char *new_base_name = get_split_graph_filename(ctx->new_base_graph->alternate, new_base_hash);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 2]);
@@ -2199,14 +2199,14 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
}
} else {
- char *graph_name = get_commit_graph_filename(ctx->odb);
+ char *graph_name = get_commit_graph_filename(ctx->alternate);
unlink(graph_name);
free(graph_name);
}
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(hash_to_hex(file_hash));
- final_graph_name = get_split_graph_filename(ctx->odb,
+ final_graph_name = get_split_graph_filename(ctx->alternate,
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1] = final_graph_name;
@@ -2257,7 +2257,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
flags != COMMIT_GRAPH_SPLIT_REPLACE) {
while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
(max_commits && num_commits > max_commits))) {
- if (g->odb != ctx->odb)
+ if (g->alternate != ctx->alternate)
break;
if (unsigned_add_overflows(num_commits, g->num_commits))
@@ -2279,10 +2279,10 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
"should be 1 with --split=replace");
if (ctx->num_commit_graphs_after == 2) {
- char *old_graph_name = get_commit_graph_filename(g->odb);
+ char *old_graph_name = get_commit_graph_filename(g->alternate);
if (!strcmp(g->filename, old_graph_name) &&
- g->odb != ctx->odb) {
+ g->alternate != ctx->alternate) {
ctx->num_commit_graphs_after = 1;
ctx->new_base_graph = NULL;
}
@@ -2454,13 +2454,13 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
if (ctx->opts && ctx->opts->expire_time)
expire_time = ctx->opts->expire_time;
if (!ctx->split) {
- char *chain_file_name = get_commit_graph_chain_filename(ctx->odb);
+ char *chain_file_name = get_commit_graph_chain_filename(ctx->alternate);
unlink(chain_file_name);
free(chain_file_name);
ctx->num_commit_graphs_after = 0;
}
- strbuf_addstr(&path, ctx->odb->path);
+ strbuf_addstr(&path, ctx->alternate->path);
strbuf_addstr(&path, "/info/commit-graphs");
dir = opendir(path.buf);
@@ -2502,7 +2502,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
strbuf_release(&path);
}
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_alternate *alternate,
const struct string_list *const pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
@@ -2533,7 +2533,7 @@ int write_commit_graph(struct object_directory *odb,
CALLOC_ARRAY(ctx, 1);
ctx->r = r;
- ctx->odb = odb;
+ ctx->alternate = alternate;
ctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;
ctx->report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0;
ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
diff --git a/commit-graph.h b/commit-graph.h
index 20d38c100ce..19d95ade6ea 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -29,8 +29,8 @@ struct repository;
struct object_database;
struct string_list;
-char *get_commit_graph_filename(struct object_directory *odb);
-char *get_commit_graph_chain_filename(struct object_directory *odb);
+char *get_commit_graph_filename(struct odb_alternate *alternate);
+char *get_commit_graph_chain_filename(struct odb_alternate *alternate);
int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st);
@@ -89,7 +89,7 @@ struct commit_graph {
uint32_t num_commits;
struct object_id oid;
char *filename;
- struct object_directory *odb;
+ struct odb_alternate *alternate;
uint32_t num_commits_in_base;
unsigned int read_generation_data;
@@ -115,12 +115,12 @@ struct commit_graph {
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb);
+ struct odb_alternate *alternate);
struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
int fd, struct stat *st,
int *incomplete_chain);
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb);
+ struct odb_alternate *alternate);
struct repo_settings;
@@ -173,10 +173,10 @@ struct commit_graph_opts {
* is not compatible with the commit-graph feature, then the
* methods will return 0 without writing a commit-graph.
*/
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_alternate *alternate,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts);
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_alternate *alternate,
const struct string_list *pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
diff --git a/diagnose.c b/diagnose.c
index b1be74be983..50129cf4be3 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -59,13 +59,13 @@ static void dir_file_stats_objects(const char *full_path,
(uintmax_t)st.st_size);
}
-static int dir_file_stats(struct object_directory *object_dir, void *data)
+static int dir_file_stats(struct odb_alternate *alternate, void *data)
{
struct strbuf *buf = data;
- strbuf_addf(buf, "Contents of %s:\n", object_dir->path);
+ strbuf_addf(buf, "Contents of %s:\n", alternate->path);
- for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects,
+ for_each_file_in_pack_dir(alternate->path, dir_file_stats_objects,
data);
return 0;
@@ -228,7 +228,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(r->objects->odb, &buf);
+ dir_file_stats(r->objects->alternates, &buf);
foreach_alt_odb(dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
diff --git a/http-walker.c b/http-walker.c
index 463f7b119ad..9e7bc37f02e 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
ret = error("File %s has bad hash", hex);
} else if (req->rename < 0) {
struct strbuf buf = STRBUF_INIT;
- odb_loose_path(the_repository->objects->odb, &buf, &req->oid);
+ odb_loose_path(the_repository->objects->alternates, &buf, &req->oid);
ret = error("unable to write sha1 filename %s", buf.buf);
strbuf_release(&buf);
}
diff --git a/http.c b/http.c
index 3c029cf8947..8ce2ec73947 100644
--- a/http.c
+++ b/http.c
@@ -2662,7 +2662,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
oidcpy(&freq->oid, oid);
freq->localfile = -1;
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->alternates, &filename, oid);
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2814,7 +2814,7 @@ int finish_http_object_request(struct http_object_request *freq)
unlink_or_warn(freq->tmpfile.buf);
return -1;
}
- odb_loose_path(the_repository->objects->odb, &filename, &freq->oid);
+ odb_loose_path(the_repository->objects->alternates, &filename, &freq->oid);
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
strbuf_release(&filename);
diff --git a/loose.c b/loose.c
index bb602aaa366..bce4e1c3ee7 100644
--- a/loose.c
+++ b/loose.c
@@ -44,36 +44,36 @@ static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *key, const
return 1;
}
-static int insert_loose_map(struct object_directory *odb,
+static int insert_loose_map(struct odb_alternate *alternate,
const struct object_id *oid,
const struct object_id *compat_oid)
{
- struct loose_object_map *map = odb->loose_map;
+ struct loose_object_map *map = alternate->loose_map;
int inserted = 0;
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
if (inserted)
- oidtree_insert(odb->loose_objects_cache, compat_oid);
+ oidtree_insert(alternate->loose_objects_cache, compat_oid);
return inserted;
}
-static int load_one_loose_object_map(struct repository *repo, struct object_directory *dir)
+static int load_one_loose_object_map(struct repository *repo, struct odb_alternate *alternate)
{
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
FILE *fp;
- if (!dir->loose_map)
- loose_object_map_init(&dir->loose_map);
- if (!dir->loose_objects_cache) {
- ALLOC_ARRAY(dir->loose_objects_cache, 1);
- oidtree_init(dir->loose_objects_cache);
+ if (!alternate->loose_map)
+ loose_object_map_init(&alternate->loose_map);
+ if (!alternate->loose_objects_cache) {
+ ALLOC_ARRAY(alternate->loose_objects_cache, 1);
+ oidtree_init(alternate->loose_objects_cache);
}
- insert_loose_map(dir, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
- insert_loose_map(dir, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
- insert_loose_map(dir, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
+ insert_loose_map(alternate, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
+ insert_loose_map(alternate, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
+ insert_loose_map(alternate, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
repo_common_path_replace(repo, &path, "objects/loose-object-idx");
fp = fopen(path.buf, "rb");
@@ -93,7 +93,7 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
parse_oid_hex_algop(p, &compat_oid, &p, repo->compat_hash_algo) ||
p != buf.buf + buf.len)
goto err;
- insert_loose_map(dir, &oid, &compat_oid);
+ insert_loose_map(alternate, &oid, &compat_oid);
}
strbuf_release(&buf);
@@ -107,15 +107,15 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
int repo_read_loose_object_map(struct repository *repo)
{
- struct object_directory *dir;
+ struct odb_alternate *alternate;
if (!should_use_loose_object_map(repo))
return 0;
prepare_alt_odb(repo);
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- if (load_one_loose_object_map(repo, dir) < 0) {
+ for (alternate = repo->objects->alternates; alternate; alternate = alternate->next) {
+ if (load_one_loose_object_map(repo, alternate) < 0) {
return -1;
}
}
@@ -124,7 +124,7 @@ int repo_read_loose_object_map(struct repository *repo)
int repo_write_loose_object_map(struct repository *repo)
{
- kh_oid_map_t *map = repo->objects->odb->loose_map->to_compat;
+ kh_oid_map_t *map = repo->objects->alternates->loose_map->to_compat;
struct lock_file lock;
int fd;
khiter_t iter;
@@ -212,7 +212,7 @@ int repo_add_loose_object_map(struct repository *repo, const struct object_id *o
if (!should_use_loose_object_map(repo))
return 0;
- inserted = insert_loose_map(repo->objects->odb, oid, compat_oid);
+ inserted = insert_loose_map(repo->objects->alternates, oid, compat_oid);
if (inserted)
return write_one_object(repo, oid, compat_oid);
return 0;
@@ -223,12 +223,12 @@ int repo_loose_object_map_oid(struct repository *repo,
const struct git_hash_algo *to,
struct object_id *dest)
{
- struct object_directory *dir;
+ struct odb_alternate *alternate;
kh_oid_map_t *map;
khiter_t pos;
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- struct loose_object_map *loose_map = dir->loose_map;
+ for (alternate = repo->objects->alternates; alternate; alternate = alternate->next) {
+ struct loose_object_map *loose_map = alternate->loose_map;
if (!loose_map)
continue;
map = (to == repo->compat_hash_algo) ?
diff --git a/midx.c b/midx.c
index 3d0015f7828..c1adff4404e 100644
--- a/midx.c
+++ b/midx.c
@@ -824,7 +824,7 @@ void clear_midx_file(struct repository *r)
{
struct strbuf midx = STRBUF_INIT;
- get_midx_filename(r->hash_algo, &midx, r->objects->odb->path);
+ get_midx_filename(r->hash_algo, &midx, r->objects->alternates->path);
if (r->objects && r->objects->multi_pack_index) {
close_midx(r->objects->multi_pack_index);
@@ -834,8 +834,8 @@ void clear_midx_file(struct repository *r)
if (remove_path(midx.buf))
die(_("failed to clear multi-pack-index at %s"), midx.buf);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_BITMAP, NULL);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_REV, NULL);
+ clear_midx_files_ext(r->objects->alternates->path, MIDX_EXT_BITMAP, NULL);
+ clear_midx_files_ext(r->objects->alternates->path, MIDX_EXT_REV, NULL);
strbuf_release(&midx);
}
diff --git a/object-file.c b/object-file.c
index dc56a4766df..e48d968c0e0 100644
--- a/object-file.c
+++ b/object-file.c
@@ -55,12 +55,12 @@ static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
}
}
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_alternate *alternate,
struct strbuf *buf,
const struct object_id *oid)
{
strbuf_reset(buf);
- strbuf_addstr(buf, odb->path);
+ strbuf_addstr(buf, alternate->path);
strbuf_addch(buf, '/');
fill_loose_path(buf, oid);
return buf->buf;
@@ -88,27 +88,27 @@ int check_and_freshen_file(const char *fn, int freshen)
return 1;
}
-static int check_and_freshen_odb(struct object_directory *odb,
+static int check_and_freshen_odb(struct odb_alternate *alternate,
const struct object_id *oid,
int freshen)
{
static struct strbuf path = STRBUF_INIT;
- odb_loose_path(odb, &path, oid);
+ odb_loose_path(alternate, &path, oid);
return check_and_freshen_file(path.buf, freshen);
}
static int check_and_freshen_local(const struct object_id *oid, int freshen)
{
- return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
+ return check_and_freshen_odb(the_repository->objects->alternates, oid, freshen);
}
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
- if (check_and_freshen_odb(odb, oid, freshen))
+ for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
+ if (check_and_freshen_odb(alternate, oid, freshen))
return 1;
}
return 0;
@@ -208,12 +208,12 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct stat *st, const char **path)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ *path = odb_loose_path(alternate, &buf, oid);
if (!lstat(*path, st))
return 0;
}
@@ -229,13 +229,13 @@ static int open_loose_object(struct repository *r,
const struct object_id *oid, const char **path)
{
int fd;
- struct object_directory *odb;
+ struct odb_alternate *alternate;
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ *path = odb_loose_path(alternate, &buf, oid);
fd = git_open(*path);
if (fd >= 0)
return fd;
@@ -250,11 +250,11 @@ static int open_loose_object(struct repository *r,
static int quick_has_loose(struct repository *r,
const struct object_id *oid)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- if (oidtree_contains(odb_loose_cache(odb, oid), oid))
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ if (oidtree_contains(odb_loose_cache(alternate, oid), oid))
return 1;
}
return 0;
@@ -750,7 +750,7 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
/* Finalize a file on disk, and close it. */
static void close_loose_object(int fd, const char *filename)
{
- if (the_repository->objects->odb->will_destroy)
+ if (the_repository->objects->alternates->will_destroy)
goto out;
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
@@ -932,7 +932,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
prepare_loose_object_bulk_checkin();
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->alternates, &filename, oid);
fd = start_loose_object_common(&tmp_file, filename.buf, flags,
&stream, compressed, sizeof(compressed),
@@ -1079,7 +1079,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
goto cleanup;
}
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->alternates, &filename, oid);
/* We finally know the object path, and create the missing dir. */
dirlen = directory_size(filename.buf);
@@ -1540,11 +1540,11 @@ int for_each_loose_file_in_objdir(const char *path,
int for_each_loose_object(each_loose_object_fn cb, void *data,
enum for_each_object_flags flags)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
- int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
+ int r = for_each_loose_file_in_objdir(alternate->path, cb, NULL,
NULL, data);
if (r)
return r;
@@ -1564,43 +1564,43 @@ static int append_loose_object(const struct object_id *oid,
return 0;
}
-struct oidtree *odb_loose_cache(struct object_directory *odb,
- const struct object_id *oid)
+struct oidtree *odb_loose_cache(struct odb_alternate *alternate,
+ const struct object_id *oid)
{
int subdir_nr = oid->hash[0];
struct strbuf buf = STRBUF_INIT;
- size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
+ size_t word_bits = bitsizeof(alternate->loose_objects_subdir_seen[0]);
size_t word_index = subdir_nr / word_bits;
size_t mask = (size_t)1u << (subdir_nr % word_bits);
uint32_t *bitmap;
if (subdir_nr < 0 ||
- subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
+ subdir_nr >= bitsizeof(alternate->loose_objects_subdir_seen))
BUG("subdir_nr out of range");
- bitmap = &odb->loose_objects_subdir_seen[word_index];
+ bitmap = &alternate->loose_objects_subdir_seen[word_index];
if (*bitmap & mask)
- return odb->loose_objects_cache;
- if (!odb->loose_objects_cache) {
- ALLOC_ARRAY(odb->loose_objects_cache, 1);
- oidtree_init(odb->loose_objects_cache);
+ return alternate->loose_objects_cache;
+ if (!alternate->loose_objects_cache) {
+ ALLOC_ARRAY(alternate->loose_objects_cache, 1);
+ oidtree_init(alternate->loose_objects_cache);
}
- strbuf_addstr(&buf, odb->path);
+ strbuf_addstr(&buf, alternate->path);
for_each_file_in_obj_subdir(subdir_nr, &buf,
append_loose_object,
NULL, NULL,
- odb->loose_objects_cache);
+ alternate->loose_objects_cache);
*bitmap |= mask;
strbuf_release(&buf);
- return odb->loose_objects_cache;
+ return alternate->loose_objects_cache;
}
-void odb_clear_loose_cache(struct object_directory *odb)
+void odb_clear_loose_cache(struct odb_alternate *alternate)
{
- oidtree_clear(odb->loose_objects_cache);
- FREE_AND_NULL(odb->loose_objects_cache);
- memset(&odb->loose_objects_subdir_seen, 0,
- sizeof(odb->loose_objects_subdir_seen));
+ oidtree_clear(alternate->loose_objects_cache);
+ FREE_AND_NULL(alternate->loose_objects_cache);
+ memset(&alternate->loose_objects_subdir_seen, 0,
+ sizeof(alternate->loose_objects_subdir_seen));
}
static int check_stream_oid(git_zstream *stream,
diff --git a/object-file.h b/object-file.h
index a85b2e5b494..f1601200938 100644
--- a/object-file.h
+++ b/object-file.h
@@ -24,23 +24,23 @@ enum {
int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
-struct object_directory;
+struct odb_alternate;
/*
* Populate and return the loose object cache array corresponding to the
* given object ID.
*/
-struct oidtree *odb_loose_cache(struct object_directory *odb,
+struct oidtree *odb_loose_cache(struct odb_alternate *alternate,
const struct object_id *oid);
/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
+void odb_clear_loose_cache(struct odb_alternate *alternate);
/*
* Put in `buf` the name of the file in the local object database that
* would be used to store a loose object with the specified oid.
*/
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_alternate *alternate,
struct strbuf *buf,
const struct object_id *oid);
diff --git a/object-name.c b/object-name.c
index 9288b2dd245..b83ba882b9e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -112,10 +112,10 @@ static enum cb_next match_prefix(const struct object_id *oid, void *arg)
static void find_short_object_filename(struct disambiguate_state *ds)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
- for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next)
- oidtree_each(odb_loose_cache(odb, &ds->bin_pfx),
+ for (alternate = ds->repo->objects->alternates; alternate && !ds->ambiguous; alternate = alternate->next)
+ oidtree_each(odb_loose_cache(alternate, &ds->bin_pfx),
&ds->bin_pfx, ds->len, match_prefix, ds);
}
diff --git a/object-store.c b/object-store.c
index 1effcb12273..673a9c6006b 100644
--- a/object-store.c
+++ b/object-store.c
@@ -27,7 +27,7 @@
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
- struct object_directory *, 1, fspathhash, fspatheq)
+ struct odb_alternate *, 1, fspathhash, fspatheq)
/*
* This is meant to hold a *small* number of objects that you would
@@ -104,18 +104,18 @@ static int alt_odb_usable(struct object_database *o,
* Prevent the common mistake of listing the same
* thing twice, or object directory itself.
*/
- if (!o->odb_by_path) {
+ if (!o->alternate_by_path) {
khiter_t p;
- o->odb_by_path = kh_init_odb_path_map();
- assert(!o->odb->next);
- p = kh_put_odb_path_map(o->odb_by_path, o->odb->path, &r);
+ o->alternate_by_path = kh_init_odb_path_map();
+ assert(!o->alternates->next);
+ p = kh_put_odb_path_map(o->alternate_by_path, o->alternates->path, &r);
assert(r == 1); /* never used */
- kh_value(o->odb_by_path, p) = o->odb;
+ kh_value(o->alternate_by_path, p) = o->alternates;
}
if (fspatheq(path->buf, normalized_objdir))
return 0;
- *pos = kh_put_odb_path_map(o->odb_by_path, path->buf, &r);
+ *pos = kh_put_odb_path_map(o->alternate_by_path, path->buf, &r);
/* r: 0 = exists, 1 = never used, 2 = deleted */
return r == 0 ? 0 : 1;
}
@@ -124,7 +124,7 @@ static int alt_odb_usable(struct object_database *o,
* Prepare alternate object database registry.
*
* The variable alt_odb_list points at the list of struct
- * object_directory. The elements on this list come from
+ * odb_alternate. The elements on this list come from
* non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
* environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
* whose contents is similar to that environment variable but can be
@@ -141,7 +141,7 @@ static void read_info_alternates(struct repository *r,
static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
const char *relative_base, int depth, const char *normalized_objdir)
{
- struct object_directory *ent;
+ struct odb_alternate *alternate;
struct strbuf pathbuf = STRBUF_INIT;
struct strbuf tmp = STRBUF_INIT;
khiter_t pos;
@@ -170,19 +170,19 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
goto error;
- CALLOC_ARRAY(ent, 1);
- /* pathbuf.buf is already in r->objects->odb_by_path */
- ent->path = strbuf_detach(&pathbuf, NULL);
+ CALLOC_ARRAY(alternate, 1);
+ /* pathbuf.buf is already in r->objects->alternate_by_path */
+ alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->odb_tail = ent;
- r->objects->odb_tail = &(ent->next);
- ent->next = NULL;
- assert(r->objects->odb_by_path);
- kh_value(r->objects->odb_by_path, pos) = ent;
+ *r->objects->alternates_tail = alternate;
+ r->objects->alternates_tail = &(alternate->next);
+ alternate->next = NULL;
+ assert(r->objects->alternate_by_path);
+ kh_value(r->objects->alternate_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, ent->path, depth + 1);
+ read_info_alternates(r, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -234,7 +234,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->odb->path, 1);
+ strbuf_realpath(&objdirbuf, r->objects->alternates->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
@@ -321,9 +321,9 @@ void add_to_alternates_memory(const char *reference)
'\n', NULL, 0);
}
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy)
{
- struct object_directory *new_odb;
+ struct odb_alternate *alternate;
/*
* Make sure alternates are initialized, or else our entry may be
@@ -335,41 +335,41 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
- new_odb = xcalloc(1, sizeof(*new_odb));
- new_odb->path = xstrdup(dir);
+ alternate = xcalloc(1, sizeof(*alternate));
+ alternate->path = xstrdup(dir);
/*
* Disable ref updates while a temporary odb is active, since
* the objects in the database may roll back.
*/
- new_odb->disable_ref_updates = 1;
- new_odb->will_destroy = will_destroy;
- new_odb->next = the_repository->objects->odb;
- the_repository->objects->odb = new_odb;
- return new_odb->next;
+ alternate->disable_ref_updates = 1;
+ alternate->will_destroy = will_destroy;
+ alternate->next = the_repository->objects->alternates;
+ the_repository->objects->alternates = alternate;
+ return alternate->next;
}
-static void free_object_directory(struct object_directory *odb)
+static void free_object_directory(struct odb_alternate *alternate)
{
- free(odb->path);
- odb_clear_loose_cache(odb);
- loose_object_map_clear(&odb->loose_map);
- free(odb);
+ free(alternate->path);
+ odb_clear_loose_cache(alternate);
+ loose_object_map_clear(&alternate->loose_map);
+ free(alternate);
}
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
+void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path)
{
- struct object_directory *cur_odb = the_repository->objects->odb;
+ struct odb_alternate *cur_alt = the_repository->objects->alternates;
- if (strcmp(old_path, cur_odb->path))
+ if (strcmp(old_path, cur_alt->path))
BUG("expected %s as primary object store; found %s",
- old_path, cur_odb->path);
+ old_path, cur_alt->path);
- if (cur_odb->next != restore_odb)
+ if (cur_alt->next != restore_alt)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->odb = restore_odb;
- free_object_directory(cur_odb);
+ the_repository->objects->alternates = restore_alt;
+ free_object_directory(cur_alt);
}
/*
@@ -442,15 +442,15 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct object_directory *find_odb(struct repository *r, const char *obj_dir)
+struct odb_alternate *find_odb(struct repository *r, const char *obj_dir)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- strbuf_realpath(&odb_path_real, odb->path, 1);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ strbuf_realpath(&odb_path_real, alternate->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
}
@@ -458,9 +458,9 @@ struct object_directory *find_odb(struct repository *r, const char *obj_dir)
free(obj_dir_real);
strbuf_release(&odb_path_real);
- if (!odb)
+ if (!alternate)
die(_("could not find object directory matching %s"), obj_dir);
- return odb;
+ return alternate;
}
static void fill_alternate_refs_command(struct child_process *cmd,
@@ -527,14 +527,14 @@ struct alternate_refs_data {
void *data;
};
-static int refs_from_alternate_cb(struct object_directory *e,
+static int refs_from_alternate_cb(struct odb_alternate *alternate,
void *data)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
struct alternate_refs_data *cb = data;
- if (!strbuf_realpath(&path, e->path, 0))
+ if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
if (!strbuf_strip_suffix(&path, "/objects"))
goto out;
@@ -563,12 +563,12 @@ void for_each_alternate_ref(alternate_ref_fn fn, void *data)
int foreach_alt_odb(alt_odb_fn fn, void *cb)
{
- struct object_directory *ent;
+ struct odb_alternate *alternate;
int r = 0;
prepare_alt_odb(the_repository);
- for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {
- r = fn(ent, cb);
+ for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
+ r = fn(alternate, cb);
if (r)
break;
}
@@ -582,14 +582,14 @@ void prepare_alt_odb(struct repository *r)
link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->odb->path, 0);
+ read_info_alternates(r, r->objects->alternates->path, 0);
r->objects->loaded_alternates = 1;
}
int has_alt_odb(struct repository *r)
{
prepare_alt_odb(r);
- return !!r->objects->odb->next;
+ return !!r->objects->alternates->next;
}
int obj_read_use_lock = 0;
@@ -972,15 +972,15 @@ struct object_database *odb_new(void)
static void free_object_directories(struct object_database *o)
{
- while (o->odb) {
- struct object_directory *next;
+ while (o->alternates) {
+ struct odb_alternate *next;
- next = o->odb->next;
- free_object_directory(o->odb);
- o->odb = next;
+ next = o->alternates->next;
+ free_object_directory(o->alternates);
+ o->alternates = next;
}
- kh_destroy_odb_path_map(o->odb_by_path);
- o->odb_by_path = NULL;
+ kh_destroy_odb_path_map(o->alternate_by_path);
+ o->alternate_by_path = NULL;
}
void odb_clear(struct object_database *o)
@@ -996,7 +996,7 @@ void odb_clear(struct object_database *o)
o->commit_graph_attempted = 0;
free_object_directories(o);
- o->odb_tail = NULL;
+ o->alternates_tail = NULL;
o->loaded_alternates = 0;
for (size_t i = 0; i < o->cached_object_nr; i++)
diff --git a/object-store.h b/object-store.h
index 34b8efbbb83..2dda6e85388 100644
--- a/object-store.h
+++ b/object-store.h
@@ -12,8 +12,11 @@ struct oidtree;
struct strbuf;
struct repository;
-struct object_directory {
- struct object_directory *next;
+/*
+ * An alternate part of an object database that stores the actual objects.
+ */
+struct odb_alternate {
+ struct odb_alternate *next;
/*
* Used to store the results of readdir(3) calls when we are OK
@@ -52,8 +55,8 @@ struct object_directory {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
+struct odb_alternate *find_odb(struct repository *r, const char *obj_dir);
+typedef int alt_odb_fn(struct odb_alternate *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
@@ -75,12 +78,12 @@ void add_to_alternates_memory(const char *dir);
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
*/
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy);
/*
* Restore a previous ODB replaced by set_temporary_main_odb.
*/
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+void restore_primary_odb(struct odb_alternate *restore_alternate, const char *old_path);
struct packed_git;
struct multi_pack_index;
@@ -88,7 +91,7 @@ struct cached_object_entry;
/*
* The object database encapsulates access to objects in a repository. It
- * manages one or more backends that store the actual objects which are
+ * manages one or more alternates that store the actual objects which are
* configured via alternates.
*/
struct object_database {
@@ -97,16 +100,16 @@ struct object_database {
* cannot be NULL after initialization). Subsequent directories are
* alternates.
*/
- struct object_directory *odb;
- struct object_directory **odb_tail;
- struct kh_odb_path_map *odb_by_path;
+ struct odb_alternate *alternates;
+ struct odb_alternate **alternates_tail;
+ struct kh_odb_path_map *alternate_by_path;
int loaded_alternates;
/*
* 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.
+ * populate the "alternates" list when prepare_alt_odb() is run.
*/
char *alternate_db;
diff --git a/packfile.c b/packfile.c
index 8f51665266d..e31e55f0c02 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1018,16 +1018,16 @@ static void prepare_packed_git_mru(struct repository *r)
static void prepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
if (r->objects->packed_git_initialized)
return;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- int local = (odb == r->objects->odb);
- prepare_multi_pack_index_one(r, odb->path, local);
- prepare_packed_git_one(r, odb->path, local);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ int local = (alternate == r->objects->alternates);
+ prepare_multi_pack_index_one(r, alternate->path, local);
+ prepare_packed_git_one(r, alternate->path, local);
}
rearrange_packed_git(r);
@@ -1037,7 +1037,7 @@ static void prepare_packed_git(struct repository *r)
void reprepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
obj_read_lock();
@@ -1050,8 +1050,8 @@ void reprepare_packed_git(struct repository *r)
r->objects->loaded_alternates = 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next)
- odb_clear_loose_cache(odb);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next)
+ odb_clear_loose_cache(alternate);
r->objects->approximate_object_count_valid = 0;
r->objects->packed_git_initialized = 0;
diff --git a/path.c b/path.c
index 3b598b2847f..7be0e0214df 100644
--- a/path.c
+++ b/path.c
@@ -397,7 +397,7 @@ static void adjust_git_path(struct repository *repo,
strbuf_splice(buf, 0, buf->len,
repo->index_file, strlen(repo->index_file));
else if (dir_prefix(base, "objects"))
- replace_dir(buf, git_dir_len + 7, repo->objects->odb->path);
+ replace_dir(buf, git_dir_len + 7, repo->objects->alternates->path);
else if (repo_settings_get_hooks_path(repo) && dir_prefix(base, "hooks"))
replace_dir(buf, git_dir_len + 5, repo_settings_get_hooks_path(repo));
else if (repo->different_commondir)
diff --git a/refs.c b/refs.c
index dce5c49ca2b..27325d2f3c6 100644
--- a/refs.c
+++ b/refs.c
@@ -2477,7 +2477,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
break;
}
- if (refs->repo->objects->odb->disable_ref_updates) {
+ if (refs->repo->objects->alternates->disable_ref_updates) {
strbuf_addstr(err,
_("ref updates forbidden inside quarantine environment"));
return -1;
diff --git a/repository.c b/repository.c
index 07757e6e0c9..dcc03fd9e0a 100644
--- a/repository.c
+++ b/repository.c
@@ -107,9 +107,9 @@ const char *repo_get_common_dir(struct repository *repo)
const char *repo_get_object_directory(struct repository *repo)
{
- if (!repo->objects->odb)
+ if (!repo->objects->alternates)
BUG("repository hasn't been set up");
- return repo->objects->odb->path;
+ return repo->objects->alternates->path;
}
const char *repo_get_index_file(struct repository *repo)
@@ -165,14 +165,14 @@ void repo_set_gitdir(struct repository *repo,
repo_set_commondir(repo, o->commondir);
- if (!repo->objects->odb) {
- CALLOC_ARRAY(repo->objects->odb, 1);
- repo->objects->odb_tail = &repo->objects->odb->next;
+ if (!repo->objects->alternates) {
+ CALLOC_ARRAY(repo->objects->alternates, 1);
+ repo->objects->alternates_tail = &repo->objects->alternates->next;
}
- expand_base_dir(&repo->objects->odb->path, o->object_dir,
+ expand_base_dir(&repo->objects->alternates->path, o->object_dir,
repo->commondir, "objects");
- repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
+ repo->objects->alternates->disable_ref_updates = o->disable_ref_updates;
free(repo->objects->alternate_db);
repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
diff --git a/submodule-config.c b/submodule-config.c
index 8630e27947d..0ee0a2884ef 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->odb->path);
+ add_submodule_odb_by_path(repo->objects->alternates->path);
} else {
goto out;
}
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 8b413b644be..cd8ba0c54e7 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -73,15 +73,15 @@ static void dump_graph_bloom_filters(struct commit_graph *graph)
int cmd__read_graph(int argc, const char **argv)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb;
+ struct odb_alternate *alternate;
int ret = 0;
setup_git_directory();
- odb = the_repository->objects->odb;
+ alternate = the_repository->objects->alternates;
prepare_repo_settings(the_repository);
- graph = read_commit_graph_one(the_repository, odb);
+ graph = read_commit_graph_one(the_repository, alternate);
if (!graph) {
ret = 1;
goto done;
diff --git a/tmp-objdir.c b/tmp-objdir.c
index c38fbeb5e8a..b8fe0fdd7d4 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -17,7 +17,7 @@ struct tmp_objdir {
struct repository *repo;
struct strbuf path;
struct strvec env;
- struct object_directory *prev_odb;
+ struct odb_alternate *prev_alt;
int will_destroy;
};
@@ -46,8 +46,8 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
if (t == the_tmp_objdir)
the_tmp_objdir = NULL;
- if (t->prev_odb)
- restore_primary_odb(t->prev_odb, t->path.buf);
+ if (t->prev_alt)
+ restore_primary_odb(t->prev_alt, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -276,11 +276,11 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (!t)
return 0;
- if (t->prev_odb) {
- if (t->repo->objects->odb->will_destroy)
+ if (t->prev_alt) {
+ if (t->repo->objects->alternates->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_odb, t->path.buf);
- t->prev_odb = NULL;
+ restore_primary_odb(t->prev_alt, t->path.buf);
+ t->prev_alt = NULL;
}
strbuf_addbuf(&src, &t->path);
@@ -309,19 +309,19 @@ void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
- if (t->prev_odb)
+ if (t->prev_alt)
BUG("the primary object database is already replaced");
- t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_alt = set_temporary_primary_odb(t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
{
- if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
+ if (!the_tmp_objdir || !the_tmp_objdir->prev_alt)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
- the_tmp_objdir->prev_odb = NULL;
+ restore_primary_odb(the_tmp_objdir->prev_alt, the_tmp_objdir->path.buf);
+ the_tmp_objdir->prev_alt = NULL;
return the_tmp_objdir;
}
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v2 02/17] object-store: rename `object_directory` to `odb_alternate`
2025-05-09 14:12 ` [PATCH v2 02/17] object-store: rename `object_directory` to `odb_alternate` Patrick Steinhardt
@ 2025-05-13 19:28 ` Toon Claes
2025-05-14 4:31 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Toon Claes @ 2025-05-13 19:28 UTC (permalink / raw)
To: Patrick Steinhardt, git; +Cc: Derrick Stolee, Junio C Hamano
Patrick Steinhardt <ps@pks.im> writes:
> The `object_directory` structure is used as an access point for a single
> object directory like ".git/objects". While the structure isn't yet
> fully self-contained, the intent is for it to eventually contain all
> information required to access objects in one specific location.
>
> While the name "object directory" is a good fit for now, this will
> change over time as we continue with the agenda to make pluggable object
> databases a thing. Eventually, objects may not be accessed via any kind
> of directory at all anymore, but they could instead be backed by any
> kind of durable storage mechanism. While it seems quite far-fetched for
> now, it is thinkable that eventually this might even be some form of a
> database, for example.
>
> As such, the current name of this structure will become worse over time
> as we evolve into the direction of pluggable ODBs. Immediate next steps
> will start to carve out proper self-contained object directories, which
> requires us to pass in these object directories as parameters. Based on
> our modern naming schema this means that those functions should then be
> named after their subsystem, which means that we would start to bake the
> current name into the codebase more and more.
>
> Let's preempt this by renaming the structure to `odb_alternate` now
> already. This name is agnostic of how exactly objects are stored while
> still specifically pinpointing that this is about an alternate object
> database. In the future, it allows us to easily introduce e.g. a
> `odb_files_alternate` and other specific implementations over time.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> builtin/commit-graph.c | 18 +++----
> builtin/count-objects.c | 4 +-
> builtin/fetch.c | 2 +-
> builtin/fsck.c | 14 ++---
> builtin/gc.c | 14 ++---
> builtin/grep.c | 2 +-
> builtin/multi-pack-index.c | 4 +-
> builtin/submodule--helper.c | 6 +--
> bundle.c | 2 +-
> commit-graph.c | 94 +++++++++++++++++-----------------
> commit-graph.h | 14 ++---
> diagnose.c | 8 +--
> http-walker.c | 2 +-
> http.c | 4 +-
> loose.c | 42 +++++++--------
> midx.c | 6 +--
> object-file.c | 80 ++++++++++++++---------------
> object-file.h | 8 +--
> object-name.c | 6 +--
> object-store.c | 122 ++++++++++++++++++++++----------------------
> object-store.h | 25 +++++----
> packfile.c | 16 +++---
> path.c | 2 +-
> refs.c | 2 +-
> repository.c | 14 ++---
> submodule-config.c | 2 +-
> t/helper/test-read-graph.c | 6 +--
> tmp-objdir.c | 24 ++++-----
> 28 files changed, 273 insertions(+), 270 deletions(-)
[snip]
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 53da2116ddf..cd7db11d825 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -1582,7 +1582,7 @@ static const char alternate_error_advice[] = N_(
> );
>
> static int add_possible_reference_from_superproject(
> - struct object_directory *odb, void *sas_cb)
> + struct odb_alternate *alt_odb, void *sas_cb)
> {
> struct submodule_alternate_setup *sas = sas_cb;
> size_t len;
> @@ -1591,12 +1591,12 @@ static int add_possible_reference_from_superproject(
> * If the alternate object store is another repository, try the
This comment reads weirdly if an "alternate" is a location where objects
are stored. Maybe say something like:
* It the alternate resides in another repository, try the
> * standard layout with .git/(modules/<name>)+/objects
> */
> - if (strip_suffix(odb->path, "/objects", &len)) {
> + if (strip_suffix(alt_odb->path, "/objects", &len)) {
> struct repository alternate;
> char *sm_alternate;
> struct strbuf sb = STRBUF_INIT;
> struct strbuf err = STRBUF_INIT;
> - strbuf_add(&sb, odb->path, len);
> + strbuf_add(&sb, alt_odb->path, len);
>
> if (repo_init(&alternate, sb.buf, NULL) < 0)
> die(_("could not get a repository handle for gitdir '%s'"),
[snip]
> diff --git a/object-file.h b/object-file.h
> index a85b2e5b494..f1601200938 100644
> --- a/object-file.h
> +++ b/object-file.h
> @@ -24,23 +24,23 @@ enum {
> int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
> int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
>
> -struct object_directory;
> +struct odb_alternate;
>
> /*
> * Populate and return the loose object cache array corresponding to the
> * given object ID.
> */
> -struct oidtree *odb_loose_cache(struct object_directory *odb,
> +struct oidtree *odb_loose_cache(struct odb_alternate *alternate,
> const struct object_id *oid);
>
> /* Empty the loose object cache for the specified object directory. */
Also here s/directory/alternate/ ? Or database?
> -void odb_clear_loose_cache(struct object_directory *odb);
> +void odb_clear_loose_cache(struct odb_alternate *alternate);
>
> /*
> * Put in `buf` the name of the file in the local object database that
> * would be used to store a loose object with the specified oid.
> */
Not sure if we should use "alternate" here?
> -const char *odb_loose_path(struct object_directory *odb,
> +const char *odb_loose_path(struct odb_alternate *alternate,
> struct strbuf *buf,
> const struct object_id *oid);
>
> diff --git a/object-name.c b/object-name.c
> index 9288b2dd245..b83ba882b9e 100644
> --- a/object-name.c
> +++ b/object-name.c
> @@ -112,10 +112,10 @@ static enum cb_next match_prefix(const struct object_id *oid, void *arg)
>
> static void find_short_object_filename(struct disambiguate_state *ds)
> {
> - struct object_directory *odb;
> + struct odb_alternate *alternate;
>
> - for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next)
> - oidtree_each(odb_loose_cache(odb, &ds->bin_pfx),
> + for (alternate = ds->repo->objects->alternates; alternate && !ds->ambiguous; alternate = alternate->next)
> + oidtree_each(odb_loose_cache(alternate, &ds->bin_pfx),
> &ds->bin_pfx, ds->len, match_prefix, ds);
> }
[snip]
> diff --git a/object-store.h b/object-store.h
> index 34b8efbbb83..2dda6e85388 100644
> --- a/object-store.h
> +++ b/object-store.h
> @@ -12,8 +12,11 @@ struct oidtree;
> struct strbuf;
> struct repository;
>
> -struct object_directory {
> - struct object_directory *next;
> +/*
> + * An alternate part of an object database that stores the actual objects.
I'm having a hard time trying to understand what you're saying here.
What do you think about:
* The alternate is the part of the object database that stores the actual objects.
> + */
> +struct odb_alternate {
> + struct odb_alternate *next;
>
> /*
> * Used to store the results of readdir(3) calls when we are OK
> @@ -52,8 +55,8 @@ struct object_directory {
> void prepare_alt_odb(struct repository *r);
> int has_alt_odb(struct repository *r);
> char *compute_alternate_path(const char *path, struct strbuf *err);
> -struct object_directory *find_odb(struct repository *r, const char *obj_dir);
> -typedef int alt_odb_fn(struct object_directory *, void *);
> +struct odb_alternate *find_odb(struct repository *r, const char *obj_dir);
> +typedef int alt_odb_fn(struct odb_alternate *, void *);
> int foreach_alt_odb(alt_odb_fn, void*);
> typedef void alternate_ref_fn(const struct object_id *oid, void *);
> void for_each_alternate_ref(alternate_ref_fn, void *);
> @@ -75,12 +78,12 @@ void add_to_alternates_memory(const char *dir);
> * Replace the current writable object directory with the specified temporary
> * object directory; returns the former primary object directory.
> */
> -struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
> +struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy);
>
> /*
> * Restore a previous ODB replaced by set_temporary_main_odb.
> */
> -void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
> +void restore_primary_odb(struct odb_alternate *restore_alternate, const char *old_path);
>
> struct packed_git;
> struct multi_pack_index;
> @@ -88,7 +91,7 @@ struct cached_object_entry;
>
> /*
> * The object database encapsulates access to objects in a repository. It
> - * manages one or more backends that store the actual objects which are
> + * manages one or more alternates that store the actual objects which are
> * configured via alternates.
> */
> struct object_database {
> @@ -97,16 +100,16 @@ struct object_database {
> * cannot be NULL after initialization). Subsequent directories are
> * alternates.
> */
The full original comment can use some love too:
*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
* alternates.
*/
How about:
*
* Set of all alternates, storing the actual objects.
* The primary alternate is first (and cannot be NULL after
* & initialization). More alternates are optional.
*/
> - struct object_directory *odb;
> - struct object_directory **odb_tail;
> - struct kh_odb_path_map *odb_by_path;
> + struct odb_alternate *alternates;
> + struct odb_alternate **alternates_tail;
> + struct kh_odb_path_map *alternate_by_path;
>
> int loaded_alternates;
>
> /*
> * 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.
> + * populate the "alternates" list when prepare_alt_odb() is run.
> */
> char *alternate_db;
>
[snip]
Huge patch, I scrolled through the changes, but focused on some naming
and comments.
--
Toon
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v2 02/17] object-store: rename `object_directory` to `odb_alternate`
2025-05-13 19:28 ` Toon Claes
@ 2025-05-14 4:31 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 4:31 UTC (permalink / raw)
To: Toon Claes; +Cc: git, Derrick Stolee, Junio C Hamano
On Tue, May 13, 2025 at 09:28:00PM +0200, Toon Claes wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> > index 53da2116ddf..cd7db11d825 100644
> > --- a/builtin/submodule--helper.c
> > +++ b/builtin/submodule--helper.c
> > @@ -1591,12 +1591,12 @@ static int add_possible_reference_from_superproject(
> > * If the alternate object store is another repository, try the
>
> This comment reads weirdly if an "alternate" is a location where objects
> are stored. Maybe say something like:
>
> * It the alternate resides in another repository, try the
Fair, but I'd prefer to not adapt too many of the surroundings yet.
Otherwise I fear that it'll open a can of worms that we can otherwise
address over time.
> > diff --git a/object-file.h b/object-file.h
> > index a85b2e5b494..f1601200938 100644
> > --- a/object-file.h
> > +++ b/object-file.h
> > @@ -24,23 +24,23 @@ enum {
> > int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
> > int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
> >
> > -struct object_directory;
> > +struct odb_alternate;
> >
> > /*
> > * Populate and return the loose object cache array corresponding to the
> > * given object ID.
> > */
> > -struct oidtree *odb_loose_cache(struct object_directory *odb,
> > +struct oidtree *odb_loose_cache(struct odb_alternate *alternate,
> > const struct object_id *oid);
> >
> > /* Empty the loose object cache for the specified object directory. */
>
> Also here s/directory/alternate/ ? Or database?
This one remains valid even with the new terminology. The loose cache is
specific to loose object files, which does have an associated object
directory. Refactoring loose objects to become a bit more self-contained
will be one of the next steps after these refactoring land.
> > -void odb_clear_loose_cache(struct object_directory *odb);
> > +void odb_clear_loose_cache(struct odb_alternate *alternate);
> >
> > /*
> > * Put in `buf` the name of the file in the local object database that
> > * would be used to store a loose object with the specified oid.
> > */
>
> Not sure if we should use "alternate" here?
Probably rather "loose object directory", as it is again specific to
loose objects.
> > diff --git a/object-store.h b/object-store.h
> > index 34b8efbbb83..2dda6e85388 100644
> > --- a/object-store.h
> > +++ b/object-store.h
> > @@ -12,8 +12,11 @@ struct oidtree;
> > struct strbuf;
> > struct repository;
> >
> > -struct object_directory {
> > - struct object_directory *next;
> > +/*
> > + * An alternate part of an object database that stores the actual objects.
>
> I'm having a hard time trying to understand what you're saying here.
> What do you think about:
>
> * The alternate is the part of the object database that stores the actual objects.
That reads better. I'll extend this even further to give a bit more
context around primary alternates.
> > @@ -97,16 +100,16 @@ struct object_database {
> > * cannot be NULL after initialization). Subsequent directories are
> > * alternates.
> > */
>
> The full original comment can use some love too:
>
> *
> * Set of all object directories; the main directory is first (and
> * cannot be NULL after initialization). Subsequent directories are
> * alternates.
> */
>
> How about:
>
> *
> * Set of all alternates, storing the actual objects.
> * The primary alternate is first (and cannot be NULL after
> * & initialization). More alternates are optional.
> */
Same here, I'd rather not touch this comment for now. We'd only catch a
small subset of outdated comments anyway, so I'd rather focus on the
required changes given that this patch is already quite large.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v2 03/17] object-store: rename files to "odb.{c,h}"
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 02/17] object-store: rename `object_directory` to `odb_alternate` Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-13 19:28 ` Toon Claes
2025-05-09 14:12 ` [PATCH v2 04/17] odb: introduce parent pointers Patrick Steinhardt
` (14 subsequent siblings)
17 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
In the preceding commits we have renamed the structures contained in
"object-store.h" to `struct object_database` and `struct odb_backend`.
As such, the code files "object-store.{c,h}" are confusingly named now.
Rename them to "odb.{c,h}" accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Makefile | 2 +-
apply.c | 2 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 2 +-
blame.c | 2 +-
builtin/backfill.c | 2 +-
builtin/blame.c | 2 +-
builtin/cat-file.c | 2 +-
builtin/checkout.c | 2 +-
builtin/clone.c | 2 +-
builtin/commit-graph.c | 2 +-
builtin/commit-tree.c | 2 +-
builtin/describe.c | 2 +-
builtin/difftool.c | 2 +-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 2 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 2 +-
builtin/grep.c | 2 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 2 +-
builtin/log.c | 2 +-
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 2 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 2 +-
builtin/mktag.c | 2 +-
builtin/mktree.c | 2 +-
builtin/multi-pack-index.c | 2 +-
builtin/notes.c | 2 +-
builtin/pack-objects.c | 2 +-
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 2 +-
builtin/receive-pack.c | 2 +-
builtin/remote.c | 2 +-
builtin/repack.c | 2 +-
builtin/replace.c | 2 +-
builtin/rev-list.c | 2 +-
builtin/show-ref.c | 2 +-
builtin/submodule--helper.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 2 +-
bulk-checkin.c | 2 +-
bundle-uri.c | 2 +-
bundle.c | 2 +-
cache-tree.c | 2 +-
combine-diff.c | 2 +-
commit-graph.c | 2 +-
commit-graph.h | 2 +-
commit.c | 2 +-
config.c | 2 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 2 +-
diff.c | 2 +-
entry.c | 2 +-
fetch-pack.c | 2 +-
fmt-merge-msg.c | 2 +-
fsck.c | 2 +-
grep.c | 2 +-
http-backend.c | 2 +-
http-push.c | 2 +-
http-walker.c | 2 +-
http.c | 2 +-
list-objects-filter.c | 2 +-
list-objects.c | 2 +-
loose.c | 2 +-
mailmap.c | 2 +-
match-trees.c | 2 +-
merge-blobs.c | 2 +-
merge-ort.c | 2 +-
meson.build | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 2 +-
object-file.c | 2 +-
object-file.h | 2 +-
object-store.c => odb.c | 2 +-
object-store.h => odb.h | 6 +++---
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 2 +-
pack-bitmap.c | 2 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
packfile.c | 2 +-
packfile.h | 4 ++--
path.c | 2 +-
promisor-remote.c | 2 +-
protocol-caps.c | 2 +-
read-cache.c | 2 +-
ref-filter.c | 2 +-
reflog.c | 2 +-
refs.c | 2 +-
remote.c | 2 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 2 +-
rerere.c | 2 +-
revision.c | 2 +-
send-pack.c | 2 +-
sequencer.c | 2 +-
server-info.c | 2 +-
shallow.c | 2 +-
streaming.c | 2 +-
submodule-config.c | 2 +-
submodule.c | 2 +-
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 2 +-
t/helper/test-read-graph.c | 2 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 2 +-
tag.c | 2 +-
tmp-objdir.c | 2 +-
tree-walk.c | 2 +-
tree.c | 2 +-
unpack-trees.c | 2 +-
upload-pack.c | 2 +-
walker.c | 2 +-
xdiff-interface.c | 2 +-
126 files changed, 129 insertions(+), 129 deletions(-)
diff --git a/Makefile b/Makefile
index 8a7f1c76543..d2d65f30907 100644
--- a/Makefile
+++ b/Makefile
@@ -1083,8 +1083,8 @@ LIB_OBJS += notes.o
LIB_OBJS += object-file-convert.o
LIB_OBJS += object-file.o
LIB_OBJS += object-name.o
-LIB_OBJS += object-store.o
LIB_OBJS += object.o
+LIB_OBJS += odb.o
LIB_OBJS += oid-array.o
LIB_OBJS += oidmap.o
LIB_OBJS += oidset.o
diff --git a/apply.c b/apply.c
index 381d2e3652f..879f04df31e 100644
--- a/apply.c
+++ b/apply.c
@@ -14,7 +14,7 @@
#include "abspath.h"
#include "base85.h"
#include "config.h"
-#include "object-store.h"
+#include "odb.h"
#include "delta.h"
#include "diff.h"
#include "dir.h"
diff --git a/archive-tar.c b/archive-tar.c
index 282b48196f9..249164ea77d 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -11,7 +11,7 @@
#include "hex.h"
#include "tar.h"
#include "archive.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "streaming.h"
#include "run-command.h"
diff --git a/archive-zip.c b/archive-zip.c
index 405da6f3d83..df8866d5bae 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -12,7 +12,7 @@
#include "hex.h"
#include "streaming.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "userdiff.h"
#include "write-or-die.h"
diff --git a/archive.c b/archive.c
index 8309ea213e6..7fa2cc2596a 100644
--- a/archive.c
+++ b/archive.c
@@ -14,7 +14,7 @@
#include "pretty.h"
#include "setup.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 86b6109fc4e..e5680db7f65 100644
--- a/attr.c
+++ b/attr.c
@@ -22,7 +22,7 @@
#include "read-cache-ll.h"
#include "refs.h"
#include "revision.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/bisect.c b/bisect.c
index a327468c75b..a7939216d00 100644
--- a/bisect.c
+++ b/bisect.c
@@ -20,7 +20,7 @@
#include "commit-slab.h"
#include "commit-reach.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "dir.h"
diff --git a/blame.c b/blame.c
index 57daa45e899..0ceea080a80 100644
--- a/blame.c
+++ b/blame.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "cache-tree.h"
#include "mergesort.h"
#include "commit.h"
diff --git a/builtin/backfill.c b/builtin/backfill.c
index fa82ad2f6ff..0b49baa39fa 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -13,7 +13,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "promisor-remote.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 944952e30eb..15eda60af90 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -28,7 +28,7 @@
#include "line-log.h"
#include "progress.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "blame.h"
#include "refs.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 3914a2a3f61..2fa5e3f43bd 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -24,7 +24,7 @@
#include "pack-bitmap.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "mailmap.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d185982f3a6..e7dd66173dd 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,7 +20,7 @@
#include "merge-ort-wrappers.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "path.h"
#include "preload-index.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 91b9cd0d164..1eafeefb48d 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -25,7 +25,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "tree-walk.h"
#include "unpack-trees.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 628d3a1e92e..ae8ac52a975 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -6,7 +6,7 @@
#include "hex.h"
#include "parse-options.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "progress.h"
#include "replace-object.h"
#include "strbuf.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index ad6b2c93209..546069f8682 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -9,7 +9,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "parse-options.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 2d50883b729..96cb68e5e5d 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -19,7 +19,7 @@
#include "setup.h"
#include "strvec.h"
#include "run-command.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects.h"
#include "commit-slab.h"
#include "wildmatch.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index a3b64ce6942..fac613e3bc3 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -30,7 +30,7 @@
#include "strbuf.h"
#include "lockfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "entry.h"
#include "setup.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 37c01d6c6fe..0505f289a94 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "object.h"
#include "tag.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index b2839c5f439..52c792488e1 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -24,7 +24,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "mem-pool.h"
#include "commit-reach.h"
#include "khash.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4de6d3206d4..82e9603ccab 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "oid-array.h"
#include "commit.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 9c54286540c..6a5181393a2 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "read-cache-ll.h"
#include "replace-object.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 3c51a39c10d..3858df2a82e 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -26,7 +26,7 @@
#include "submodule-config.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pager.h"
#include "path.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index cd53fa3bde8..9ce0b87c30b 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -11,7 +11,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 147e9b8b479..8ce446064e8 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -21,7 +21,7 @@
#include "packfile.h"
#include "pack-revindex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "path.h"
diff --git a/builtin/log.c b/builtin/log.c
index b450cd3bde8..fe9cc5ebecb 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -15,7 +15,7 @@
#include "hex.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "color.h"
#include "commit.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index be74f0a03b2..821339b07d4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -25,7 +25,7 @@
#include "setup.h"
#include "sparse-index.h"
#include "submodule.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 8aafc30ca48..62b6fd58c16 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -10,7 +10,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "path.h"
#include "quote.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 2b16b10d2ca..9464f275629 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -7,7 +7,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "gettext.h"
#include "setup.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 4aafa73c615..709ae3966a6 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -10,7 +10,7 @@
#include "commit-reach.h"
#include "merge-ort.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "blob.h"
#include "merge-blobs.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 7ac11c46d53..1809b38f937 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -6,7 +6,7 @@
#include "strbuf.h"
#include "replace-object.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "fsck.h"
#include "config.h"
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 4b478034675..016b0e5b224 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -12,7 +12,7 @@
#include "tree.h"
#include "parse-options.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static struct treeent {
unsigned mode;
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index a77ae465d48..01c4c8e62e3 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -7,7 +7,7 @@
#include "midx.h"
#include "strbuf.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index a3f433ca4c0..783d4932ca6 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -16,7 +16,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "pretty.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 8b33edc2ff5..99b63cb0980 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -32,7 +32,7 @@
#include "list.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "dir.h"
#include "midx.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 5d1fc781761..3134cb8c689 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -13,7 +13,7 @@
#include "hex.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#define BLKSIZE 512
diff --git a/builtin/prune.c b/builtin/prune.c
index e930caa0c0a..7bbfb14c2be 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -17,7 +17,7 @@
#include "replace-object.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "shallow.h"
static const char * const prune_usage[] = {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index c92e57ba188..cb5fd55a8e4 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -33,7 +33,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "protocol.h"
#include "commit-reach.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 0d6755bcb71..ac5b8d2a1a6 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -14,7 +14,7 @@
#include "rebase.h"
#include "refs.h"
#include "refspec.h"
-#include "object-store.h"
+#include "odb.h"
#include "strvec.h"
#include "commit-reach.h"
#include "progress.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 59214dbdfdf..16782320058 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -17,7 +17,7 @@
#include "midx.h"
#include "packfile.h"
#include "prune-packed.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "shallow.h"
#include "pack.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 48c7c6a2d56..11c7e2d4c0c 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "tag.h"
#include "wildmatch.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index c4cd4ed5c81..ee25d61c802 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -14,7 +14,7 @@
#include "object.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "parse-options.h"
#include "log-tree.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 623a52a45f8..90ec1de78f9 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "refs/refs-internal.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "string-list.h"
#include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index cd7db11d825..a6c936fb2bd 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -28,7 +28,7 @@
#include "diff.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "advice.h"
#include "branch.h"
#include "list-objects-filter-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 4742b27d16e..cf2ea4b4993 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -19,7 +19,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "tag.h"
#include "parse-options.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index e33acfc4ee4..b92fd4710a9 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
static char *create_temp_file(struct object_id *oid)
{
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index e905d5f4e19..7bf395eec84 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -9,7 +9,7 @@
#include "git-zlib.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "delta.h"
#include "pack.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 678e2ecc2c2..55406a539e7 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -17,7 +17,7 @@
#include "tmp-objdir.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static int odb_transaction_nesting;
diff --git a/bundle-uri.c b/bundle-uri.c
index 96d2ba726d9..993ac62c271 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -14,7 +14,7 @@
#include "fetch-pack.h"
#include "remote.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
static struct {
enum bundle_list_heuristic heuristic;
diff --git a/bundle.c b/bundle.c
index 0c7cd15bb12..c67f85126da 100644
--- a/bundle.c
+++ b/bundle.c
@@ -7,7 +7,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "object.h"
#include "commit.h"
diff --git a/cache-tree.c b/cache-tree.c
index fa3858e2829..9786b32b3a1 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -10,7 +10,7 @@
#include "cache-tree.h"
#include "bulk-checkin.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "read-cache-ll.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/combine-diff.c b/combine-diff.c
index dfae9f7995d..cf23a753407 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -2,7 +2,7 @@
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "convert.h"
#include "diff.h"
diff --git a/commit-graph.c b/commit-graph.c
index 58d1eeedb1a..4848198d7bf 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -13,7 +13,7 @@
#include "refs.h"
#include "hash-lookup.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "alloc.h"
diff --git a/commit-graph.h b/commit-graph.h
index 19d95ade6ea..0be594e2638 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -1,7 +1,7 @@
#ifndef COMMIT_GRAPH_H
#define COMMIT_GRAPH_H
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
diff --git a/commit.c b/commit.c
index e915b2b9a12..1d30f8ce15a 100644
--- a/commit.c
+++ b/commit.c
@@ -9,7 +9,7 @@
#include "hex.h"
#include "repository.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "diff.h"
#include "revision.h"
diff --git a/config.c b/config.c
index b18b5617fcd..883dd066827 100644
--- a/config.c
+++ b/config.c
@@ -31,7 +31,7 @@
#include "hashmap.h"
#include "string-list.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "path.h"
#include "utf8.h"
diff --git a/connected.c b/connected.c
index 4415388beba..18c13245d8e 100644
--- a/connected.c
+++ b/connected.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "run-command.h"
#include "sigchain.h"
#include "connected.h"
diff --git a/contrib/coccinelle/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
index 765ad689678..ea7fe1c8db7 100644
--- a/contrib/coccinelle/the_repository.cocci
+++ b/contrib/coccinelle/the_repository.cocci
@@ -77,7 +77,7 @@
|
- diff_setup
+ repo_diff_setup
-// object-store.h
+// odb.h
|
- read_object_file
+ repo_read_object_file
diff --git a/diagnose.c b/diagnose.c
index 50129cf4be3..d407c98d094 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -7,7 +7,7 @@
#include "gettext.h"
#include "hex.h"
#include "strvec.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "repository.h"
diff --git a/diff.c b/diff.c
index 63e9ecb30c6..193da8bee68 100644
--- a/diff.c
+++ b/diff.c
@@ -23,7 +23,7 @@
#include "color.h"
#include "run-command.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "userdiff.h"
#include "submodule.h"
#include "hashmap.h"
diff --git a/entry.c b/entry.c
index f36ec5ad242..75d55038d7c 100644
--- a/entry.c
+++ b/entry.c
@@ -1,7 +1,7 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index fa4231fee74..cf157f5d7e5 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -24,7 +24,7 @@
#include "oid-array.h"
#include "oidset.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "connected.h"
#include "fetch-negotiator.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 501b5acdd44..1a8c972adf3 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -6,7 +6,7 @@
#include "environment.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "diff.h"
#include "diff-merges.h"
#include "hex.h"
diff --git a/fsck.c b/fsck.c
index 8dc8472ceb3..e69baab3af7 100644
--- a/fsck.c
+++ b/fsck.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "dir.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "object.h"
diff --git a/grep.c b/grep.c
index f8d535182c3..dc77e6c4631 100644
--- a/grep.c
+++ b/grep.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "grep.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "userdiff.h"
#include "xdiff-interface.h"
diff --git a/http-backend.c b/http-backend.c
index 0c575aa88aa..ad8c4037493 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -18,7 +18,7 @@
#include "url.h"
#include "strvec.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "protocol.h"
#include "date.h"
#include "write-or-die.h"
diff --git a/http-push.c b/http-push.c
index f9e67cabd4b..d1b1bb23711 100644
--- a/http-push.c
+++ b/http-push.c
@@ -20,7 +20,7 @@
#include "url.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#ifdef EXPAT_NEEDS_XMLPARSE_H
diff --git a/http-walker.c b/http-walker.c
index 9e7bc37f02e..4b1cdd25a80 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -10,7 +10,7 @@
#include "transport.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct alt_base {
char *base;
diff --git a/http.c b/http.c
index 8ce2ec73947..e639d9fafef 100644
--- a/http.c
+++ b/http.c
@@ -19,7 +19,7 @@
#include "packfile.h"
#include "string-list.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tempfile.h"
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 7765761b3c6..cb9c16734b1 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -12,7 +12,7 @@
#include "oidmap.h"
#include "oidset.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
/* Remember to update object flag allocation in object.h */
/*
diff --git a/list-objects.c b/list-objects.c
index 597114281f6..c50b9578584 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -14,7 +14,7 @@
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace.h"
#include "environment.h"
diff --git a/loose.c b/loose.c
index bce4e1c3ee7..9febd1f3e9a 100644
--- a/loose.c
+++ b/loose.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
#include "repository.h"
#include "wrapper.h"
diff --git a/mailmap.c b/mailmap.c
index 9e2642a043b..b18e74c2110 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -6,7 +6,7 @@
#include "string-list.h"
#include "mailmap.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
char *git_mailmap_file;
diff --git a/match-trees.c b/match-trees.c
index 72922d5d64e..4704f95c340 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -7,7 +7,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
static int score_missing(unsigned mode)
diff --git a/merge-blobs.c b/merge-blobs.c
index 53f36dbc175..ba8a3fdfd82 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -4,7 +4,7 @@
#include "merge-ll.h"
#include "blob.h"
#include "merge-blobs.h"
-#include "object-store.h"
+#include "odb.h"
static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
{
diff --git a/merge-ort.c b/merge-ort.c
index 77310a4a52c..f86c84635f0 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -39,7 +39,7 @@
#include "mem-pool.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/meson.build b/meson.build
index 270ce933d0f..a3c917b1345 100644
--- a/meson.build
+++ b/meson.build
@@ -394,8 +394,8 @@ libgit_sources = [
'object-file-convert.c',
'object-file.c',
'object-name.c',
- 'object-store.c',
'object.c',
+ 'odb.c',
'oid-array.c',
'oidmap.c',
'oidset.c',
diff --git a/notes-cache.c b/notes-cache.c
index 150241b15e0..344f67762b8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "notes-cache.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "repository.h"
#include "commit.h"
diff --git a/notes-merge.c b/notes-merge.c
index dae8e6a281a..de6a52e2e7f 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -8,7 +8,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "diff.h"
diff --git a/notes.c b/notes.c
index 0a128f1de98..fc000e501d2 100644
--- a/notes.c
+++ b/notes.c
@@ -8,7 +8,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "strbuf.h"
#include "tree-walk.h"
diff --git a/object-file.c b/object-file.c
index e48d968c0e0..dabc238447a 100644
--- a/object-file.c
+++ b/object-file.c
@@ -21,7 +21,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidtree.h"
#include "pack.h"
#include "packfile.h"
diff --git a/object-file.h b/object-file.h
index f1601200938..e4810eee449 100644
--- a/object-file.h
+++ b/object-file.h
@@ -3,7 +3,7 @@
#include "git-zlib.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
struct index_state;
diff --git a/object-store.c b/odb.c
similarity index 99%
rename from object-store.c
rename to odb.c
index 673a9c6006b..81281db7e0a 100644
--- a/object-store.c
+++ b/odb.c
@@ -13,7 +13,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/object-store.h b/odb.h
similarity index 99%
rename from object-store.h
rename to odb.h
index 2dda6e85388..465820a3d5c 100644
--- a/object-store.h
+++ b/odb.h
@@ -1,5 +1,5 @@
-#ifndef OBJECT_STORE_H
-#define OBJECT_STORE_H
+#ifndef ODB_H
+#define ODB_H
#include "hashmap.h"
#include "object.h"
@@ -345,4 +345,4 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
-#endif /* OBJECT_STORE_H */
+#endif /* ODB_H */
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 609a343ee3e..d2a92f34d98 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 7f400ee0121..37648b57125 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -4,7 +4,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index b9f1d866046..467a3e91035 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "repository.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects-filter-options.h"
#include "midx.h"
#include "config.h"
diff --git a/pack-check.c b/pack-check.c
index 874897d6cba..67cb2cf72f2 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -8,7 +8,7 @@
#include "progress.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct idx_entry {
off_t offset;
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 20900ca88d3..8e1f2dec0ef 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-mtimes.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
diff --git a/pack-objects.h b/pack-objects.h
index 475a2d67ce3..1ac8644201b 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -1,7 +1,7 @@
#ifndef PACK_OBJECTS_H
#define PACK_OBJECTS_H
-#include "object-store.h"
+#include "odb.h"
#include "thread-utils.h"
#include "pack.h"
#include "packfile.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index ffcde48870d..0cc422a1e67 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-revindex.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
#include "trace2.h"
diff --git a/packfile.c b/packfile.c
index e31e55f0c02..8133948b58f 100644
--- a/packfile.c
+++ b/packfile.c
@@ -19,7 +19,7 @@
#include "tree-walk.h"
#include "tree.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "midx.h"
#include "commit-graph.h"
#include "pack-revindex.h"
diff --git a/packfile.h b/packfile.h
index 826eb7f475f..53c3b7d3b43 100644
--- a/packfile.h
+++ b/packfile.h
@@ -3,10 +3,10 @@
#include "list.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
-/* in object-store.h */
+/* in odb.h */
struct object_info;
struct packed_git {
diff --git a/path.c b/path.c
index 7be0e0214df..36ddfb24701 100644
--- a/path.c
+++ b/path.c
@@ -15,7 +15,7 @@
#include "submodule-config.h"
#include "path.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "lockfile.h"
#include "exec-cmd.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 9d058586dfa..2baa286bfd0 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "config.h"
#include "trace2.h"
diff --git a/protocol-caps.c b/protocol-caps.c
index 9b8db37a210..3022f69a1bd 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -6,7 +6,7 @@
#include "hash.h"
#include "hex.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "string-list.h"
#include "strbuf.h"
diff --git a/read-cache.c b/read-cache.c
index 73f83a7e7a1..dce1056ec7c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -20,7 +20,7 @@
#include "refs.h"
#include "dir.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "tree.h"
#include "commit.h"
diff --git a/ref-filter.c b/ref-filter.c
index 7a274633cfc..4ce45440ad1 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "wildmatch.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "repo-settings.h"
#include "repository.h"
diff --git a/reflog.c b/reflog.c
index 15d81ebea97..4f8a3b717cd 100644
--- a/reflog.c
+++ b/reflog.c
@@ -5,7 +5,7 @@
#include "config.h"
#include "gettext.h"
#include "parse-options.h"
-#include "object-store.h"
+#include "odb.h"
#include "reflog.h"
#include "refs.h"
#include "revision.h"
diff --git a/refs.c b/refs.c
index 27325d2f3c6..82a70b502f8 100644
--- a/refs.c
+++ b/refs.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "hook.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "path.h"
#include "submodule.h"
diff --git a/remote.c b/remote.c
index 4099183cacd..17a842f5684 100644
--- a/remote.c
+++ b/remote.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "commit.h"
#include "diff.h"
diff --git a/replace-object.c b/replace-object.c
index 7b8a09b5cb4..65b3c108629 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -2,7 +2,7 @@
#include "gettext.h"
#include "hex.h"
#include "oidmap.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "refs.h"
#include "repository.h"
diff --git a/replace-object.h b/replace-object.h
index ba478eb30c4..b1b059ed2fe 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -3,7 +3,7 @@
#include "oidmap.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
struct replace_object {
struct oidmap_entry original;
diff --git a/repository.c b/repository.c
index dcc03fd9e0a..dbc7fa8685f 100644
--- a/repository.c
+++ b/repository.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "object.h"
#include "lockfile.h"
diff --git a/rerere.c b/rerere.c
index 3cd37c5f0ae..951e4bf8b41 100644
--- a/rerere.c
+++ b/rerere.c
@@ -18,7 +18,7 @@
#include "path.h"
#include "pathspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "strmap.h"
#define RESOLVED 0
diff --git a/revision.c b/revision.c
index 2c36a9c179e..cdefe7d6e48 100644
--- a/revision.c
+++ b/revision.c
@@ -8,7 +8,7 @@
#include "hex.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "tag.h"
#include "blob.h"
diff --git a/send-pack.c b/send-pack.c
index 86592ce526d..abca2dd38a7 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pkt-line.h"
#include "sideband.h"
#include "run-command.h"
diff --git a/sequencer.c b/sequencer.c
index b5c4043757e..35f4e68d59f 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -13,7 +13,7 @@
#include "dir.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "pager.h"
#include "commit.h"
diff --git a/server-info.c b/server-info.c
index d6cd20a39d7..9bb30d9ab71 100644
--- a/server-info.c
+++ b/server-info.c
@@ -11,7 +11,7 @@
#include "packfile.h"
#include "path.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "server-info.h"
#include "strbuf.h"
#include "tempfile.h"
diff --git a/shallow.c b/shallow.c
index faeeeb45f98..d379756e39a 100644
--- a/shallow.c
+++ b/shallow.c
@@ -5,7 +5,7 @@
#include "repository.h"
#include "tempfile.h"
#include "lockfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tag.h"
#include "pkt-line.h"
diff --git a/streaming.c b/streaming.c
index 127d6b5d6ac..29cc877f22a 100644
--- a/streaming.c
+++ b/streaming.c
@@ -10,7 +10,7 @@
#include "streaming.h"
#include "repository.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "packfile.h"
diff --git a/submodule-config.c b/submodule-config.c
index 0ee0a2884ef..09034a587f1 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -13,7 +13,7 @@
#include "submodule.h"
#include "strbuf.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/submodule.c b/submodule.c
index ead3fb5dadc..9b1018877df 100644
--- a/submodule.c
+++ b/submodule.c
@@ -27,7 +27,7 @@
#include "parse-options.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index 76c2f4eba85..611a13a3261 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -2,7 +2,7 @@
#include "test-tool.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "setup.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index fdf1b13437b..d51aaa3dc40 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pack-mtimes.h"
#include "setup.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 34f1aee5581..dba227259a2 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "hex.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
/*
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index cd8ba0c54e7..bc37c00a3bd 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "bloom.h"
#include "setup.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index ac81390899a..da2aa036b57 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "midx.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "packfile.h"
#include "setup.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 4cfc7c90b59..2920ca59d72 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -5,7 +5,7 @@
#include "refs.h"
#include "setup.h"
#include "worktree.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "strbuf.h"
diff --git a/tag.c b/tag.c
index 05be39067cf..5f6868bf7b1 100644
--- a/tag.c
+++ b/tag.c
@@ -5,7 +5,7 @@
#include "environment.h"
#include "tag.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "blob.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index b8fe0fdd7d4..9e05fcbddd0 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -10,7 +10,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "quote.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
struct tmp_objdir {
diff --git a/tree-walk.c b/tree-walk.c
index 90655d52378..34b0fff4873 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -6,7 +6,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace2.h"
#include "tree.h"
#include "pathspec.h"
diff --git a/tree.c b/tree.c
index b85f56267fb..341b7c2ff3f 100644
--- a/tree.c
+++ b/tree.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "tree.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "alloc.h"
#include "tree-walk.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 471837f0329..f38c761ab98 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -26,7 +26,7 @@
#include "symlinks.h"
#include "trace2.h"
#include "fsmonitor.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "entry.h"
#include "parallel-checkout.h"
diff --git a/upload-pack.c b/upload-pack.c
index 956da5b061a..cec12cb478a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -10,7 +10,7 @@
#include "pkt-line.h"
#include "sideband.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "object.h"
#include "commit.h"
diff --git a/walker.c b/walker.c
index b470d43e54d..a8abe8a2e78 100644
--- a/walker.c
+++ b/walker.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "walker.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "strbuf.h"
#include "tree.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 1edcd319e6e..01e6e378ea6 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "config.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "xdiff-interface.h"
#include "xdiff/xtypes.h"
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v2 03/17] object-store: rename files to "odb.{c,h}"
2025-05-09 14:12 ` [PATCH v2 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
@ 2025-05-13 19:28 ` Toon Claes
2025-05-14 4:31 ` Patrick Steinhardt
2025-05-14 12:58 ` Junio C Hamano
0 siblings, 2 replies; 166+ messages in thread
From: Toon Claes @ 2025-05-13 19:28 UTC (permalink / raw)
To: Patrick Steinhardt, git; +Cc: Derrick Stolee, Junio C Hamano
Patrick Steinhardt <ps@pks.im> writes:
> In the preceding commits we have renamed the structures contained in
> "object-store.h" to `struct object_database` and `struct odb_backend`.
> As such, the code files "object-store.{c,h}" are confusingly named now.
> Rename them to "odb.{c,h}" accordingly.
Do we have plans to extract the object database subsystem into a
subdirectory? With us adding multiple backends in the future, I can
image us having a dozen files at some point. So since we're renaming,
shall we prepare for that at once? Or will `odb.h` always be the root-level
entry point for the object database, and only live backends live in
`odb/` for example?
--
Toon
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v2 03/17] object-store: rename files to "odb.{c,h}"
2025-05-13 19:28 ` Toon Claes
@ 2025-05-14 4:31 ` Patrick Steinhardt
2025-05-14 12:58 ` Junio C Hamano
1 sibling, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 4:31 UTC (permalink / raw)
To: Toon Claes; +Cc: git, Derrick Stolee, Junio C Hamano
On Tue, May 13, 2025 at 09:28:50PM +0200, Toon Claes wrote:
> Patrick Steinhardt <ps@pks.im> writes:
>
> > In the preceding commits we have renamed the structures contained in
> > "object-store.h" to `struct object_database` and `struct odb_backend`.
> > As such, the code files "object-store.{c,h}" are confusingly named now.
> > Rename them to "odb.{c,h}" accordingly.
>
> Do we have plans to extract the object database subsystem into a
> subdirectory? With us adding multiple backends in the future, I can
> image us having a dozen files at some point. So since we're renaming,
> shall we prepare for that at once? Or will `odb.h` always be the root-level
> entry point for the object database, and only live backends live in
> `odb/` for example?
Yes, my plan was to create "odb/alternate.h" in one of the next steps
and then also host alternative formats in that directory, similar to how
we do it with the "refs/" subsystem. But "odb.{c,h}" are files that I
rather want to keep in the root directory, similar again to "refs.h".
Most users shouldn't even need to be aware of anything in "odb/" and
should only need to use "odb.h", so everything in that subdirectory can
be considered as low-level implementation details.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v2 03/17] object-store: rename files to "odb.{c,h}"
2025-05-13 19:28 ` Toon Claes
2025-05-14 4:31 ` Patrick Steinhardt
@ 2025-05-14 12:58 ` Junio C Hamano
1 sibling, 0 replies; 166+ messages in thread
From: Junio C Hamano @ 2025-05-14 12:58 UTC (permalink / raw)
To: Toon Claes; +Cc: Patrick Steinhardt, git, Derrick Stolee
Toon Claes <toon@iotcl.com> writes:
> Do we have plans to extract the object database subsystem into a
> subdirectory? With us adding multiple backends in the future, I can
> image us having a dozen files at some point. So since we're renaming,
> shall we prepare for that at once? Or will `odb.h` always be the root-level
> entry point for the object database, and only live backends live in
> `odb/` for example?
Just like refs.h and refs/ directory holding code to support files
and reftable backends? I think that is what I've been assuming.
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v2 04/17] odb: introduce parent pointers
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (2 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
` (13 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
In subsequent commits we'll get rid of our use of `the_repository` in
"odb.c" in favor of explicitly passing in a `struct object_database` or
a `struct odb_alternate`. In some cases though we'll need access to the
repository, for example to read a config value from it, but we don't
have a way to access the repository owning a specific object database.
Introduce parent pointers for `struct object_database` to its owning
repository as well as for `struct odb_alternate` to its owning object
database, which will allow us to adapt those use cases.
Note that this change requires us to pass through the object database to
`link_alt_odb_entry()` so that we can set up the parent pointers for any
alternate there. The callchain is adapted to pass through the object
database accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 45 ++++++++++++++++++++++++++-------------------
odb.h | 8 +++++++-
repository.c | 3 ++-
3 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/odb.c b/odb.c
index 81281db7e0a..2b36735087e 100644
--- a/odb.c
+++ b/odb.c
@@ -135,11 +135,15 @@ static int alt_odb_usable(struct object_database *o,
* of the object ID, an extra slash for the first level indirection, and
* the terminating NUL.
*/
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth);
-static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
- const char *relative_base, int depth, const char *normalized_objdir)
+
+static int link_alt_odb_entry(struct object_database *odb,
+ const struct strbuf *entry,
+ const char *relative_base,
+ int depth,
+ const char *normalized_objdir)
{
struct odb_alternate *alternate;
struct strbuf pathbuf = STRBUF_INIT;
@@ -167,22 +171,23 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
strbuf_setlen(&pathbuf, pathbuf.len - 1);
- if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
+ if (!alt_odb_usable(odb, &pathbuf, normalized_objdir, &pos))
goto error;
CALLOC_ARRAY(alternate, 1);
+ alternate->odb = odb;
/* pathbuf.buf is already in r->objects->alternate_by_path */
alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->alternates_tail = alternate;
- r->objects->alternates_tail = &(alternate->next);
+ *odb->alternates_tail = alternate;
+ odb->alternates_tail = &(alternate->next);
alternate->next = NULL;
- assert(r->objects->alternate_by_path);
- kh_value(r->objects->alternate_by_path, pos) = alternate;
+ assert(odb->alternate_by_path);
+ kh_value(odb->alternate_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, alternate->path, depth + 1);
+ read_info_alternates(odb, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -219,7 +224,7 @@ static const char *parse_alt_odb_entry(const char *string,
return end;
}
-static void link_alt_odb_entries(struct repository *r, const char *alt,
+static void link_alt_odb_entries(struct object_database *odb, const char *alt,
int sep, const char *relative_base, int depth)
{
struct strbuf objdirbuf = STRBUF_INIT;
@@ -234,20 +239,20 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->alternates->path, 1);
+ strbuf_realpath(&objdirbuf, odb->alternates->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
if (!entry.len)
continue;
- link_alt_odb_entry(r, &entry,
+ link_alt_odb_entry(odb, &entry,
relative_base, depth, objdirbuf.buf);
}
strbuf_release(&entry);
strbuf_release(&objdirbuf);
}
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth)
{
@@ -261,7 +266,7 @@ static void read_info_alternates(struct repository *r,
return;
}
- link_alt_odb_entries(r, buf.buf, '\n', relative_base, depth);
+ link_alt_odb_entries(odb, buf.buf, '\n', relative_base, depth);
strbuf_release(&buf);
free(path);
}
@@ -303,7 +308,7 @@ void add_to_alternates_file(const char *reference)
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
free(alts);
@@ -317,7 +322,7 @@ void add_to_alternates_memory(const char *reference)
*/
prepare_alt_odb(the_repository);
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
@@ -336,6 +341,7 @@ struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
* alternate
*/
alternate = xcalloc(1, sizeof(*alternate));
+ alternate->odb = the_repository->objects;
alternate->path = xstrdup(dir);
/*
@@ -580,9 +586,9 @@ void prepare_alt_odb(struct repository *r)
if (r->objects->loaded_alternates)
return;
- link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->alternates->path, 0);
+ read_info_alternates(r->objects, r->objects->alternates->path, 0);
r->objects->loaded_alternates = 1;
}
@@ -959,11 +965,12 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct object_database *odb_new(void)
+struct object_database *odb_new(struct repository *repo)
{
struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
+ o->repo = repo;
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
diff --git a/odb.h b/odb.h
index 465820a3d5c..745e38c1931 100644
--- a/odb.h
+++ b/odb.h
@@ -18,6 +18,9 @@ struct repository;
struct odb_alternate {
struct odb_alternate *next;
+ /* Object database that owns this alternate. */
+ struct object_database *odb;
+
/*
* Used to store the results of readdir(3) calls when we are OK
* sacrificing accuracy due to races for speed. That includes
@@ -95,6 +98,9 @@ struct cached_object_entry;
* configured via alternates.
*/
struct object_database {
+ /* Repository that owns this database. */
+ struct repository *repo;
+
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -176,7 +182,7 @@ struct object_database {
unsigned packed_git_initialized : 1;
};
-struct object_database *odb_new(void);
+struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
/*
diff --git a/repository.c b/repository.c
index dbc7fa8685f..36c508f7cb2 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = odb_new();
+ repo->objects = odb_new(repo);
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -167,6 +167,7 @@ void repo_set_gitdir(struct repository *repo,
if (!repo->objects->alternates) {
CALLOC_ARRAY(repo->objects->alternates, 1);
+ repo->objects->alternates->odb = repo->objects;
repo->objects->alternates_tail = &repo->objects->alternates->next;
}
expand_base_dir(&repo->objects->alternates->path, o->object_dir,
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 05/17] odb: get rid of `the_repository` in `find_odb()`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (3 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 04/17] odb: introduce parent pointers Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
` (12 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
Get rid of our dependency on `the_repository` in `find_odb()` by passing
in the object database in which we want to search for the alternate and
adjusting all callers.
Rename the function to `odb_find_alternate()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 4 ++--
midx-write.c | 2 +-
odb.c | 6 +++---
odb.h | 7 ++++++-
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index ae8ac52a975..90c767797e2 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -101,7 +101,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- alternate = find_odb(the_repository, opts.obj_dir);
+ alternate = odb_find_alternate(the_repository->objects, opts.obj_dir);
graph_name = get_commit_graph_filename(alternate);
chain_name = get_commit_graph_chain_filename(alternate);
if (open_commit_graph(graph_name, &fd, &st))
@@ -289,7 +289,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- alternate = find_odb(the_repository, opts.obj_dir);
+ alternate = odb_find_alternate(the_repository->objects, opts.obj_dir);
if (opts.reachable) {
if (write_commit_graph_reachable(alternate, flags, &write_opts))
diff --git a/midx-write.c b/midx-write.c
index dd3b3070e55..dd65800e8b3 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -922,7 +922,7 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
struct strbuf cur_path_real = STRBUF_INIT;
/* Ensure the given object_dir is local, or a known alternate. */
- find_odb(r, obj_dir_real);
+ odb_find_alternate(r->objects, obj_dir_real);
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
strbuf_realpath(&cur_path_real, cur->object_dir, 1);
diff --git a/odb.c b/odb.c
index 2b36735087e..621a16b35ea 100644
--- a/odb.c
+++ b/odb.c
@@ -448,14 +448,14 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct odb_alternate *find_odb(struct repository *r, const char *obj_dir)
+struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir)
{
struct odb_alternate *alternate;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(r);
- for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ prepare_alt_odb(odb->repo);
+ for (alternate = odb->alternates; alternate; alternate = alternate->next) {
strbuf_realpath(&odb_path_real, alternate->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
diff --git a/odb.h b/odb.h
index 745e38c1931..60d6358c2c6 100644
--- a/odb.h
+++ b/odb.h
@@ -58,7 +58,6 @@ struct odb_alternate {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct odb_alternate *find_odb(struct repository *r, const char *obj_dir);
typedef int alt_odb_fn(struct odb_alternate *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
@@ -185,6 +184,12 @@ struct object_database {
struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
+/*
+ * Find backend by its object directory path. Dies in case the object directory
+ * couldn't be found.
+ */
+struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
+
/*
* Create a temporary file rooted in the object database directory, or
* die on failure. The filename is taken from "pattern", which should have the
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 06/17] odb: get rid of `the_repository` in `assert_oid_type()`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (4 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 07/17] odb: get rid of `the_repository` in `odb_mkstemp()` Patrick Steinhardt
` (11 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
Get rid of our dependency on `the_repository` in `assert_oid_type()` by
passing in the object database as a parameter and adjusting all callers.
Rename the function to `odb_assert_oid_type()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-tree.c | 2 +-
commit.c | 2 +-
odb.c | 5 +++--
odb.h | 3 ++-
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 546069f8682..31cfd9bd15d 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -48,7 +48,7 @@ static int parse_parent_arg_callback(const struct option *opt,
if (repo_get_oid_commit(the_repository, arg, &oid))
die(_("not a valid object name %s"), arg);
- assert_oid_type(&oid, OBJ_COMMIT);
+ odb_assert_oid_type(the_repository->objects, &oid, OBJ_COMMIT);
new_parent(lookup_commit(the_repository, &oid), parents);
return 0;
}
diff --git a/commit.c b/commit.c
index 1d30f8ce15a..aa65183d8b6 100644
--- a/commit.c
+++ b/commit.c
@@ -1706,7 +1706,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
/* Not having i18n.commitencoding is the same as having utf-8 */
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
- assert_oid_type(tree, OBJ_TREE);
+ odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);
if (memchr(msg, '\0', msg_len))
return error("a NUL byte in commit log message not allowed.");
diff --git a/odb.c b/odb.c
index 621a16b35ea..d09b8bf00cc 100644
--- a/odb.c
+++ b/odb.c
@@ -955,9 +955,10 @@ int has_object(struct repository *r, const struct object_id *oid,
return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
}
-void assert_oid_type(const struct object_id *oid, enum object_type expect)
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = oid_object_info(odb->repo, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index 60d6358c2c6..39d896ecd3f 100644
--- a/odb.h
+++ b/odb.h
@@ -295,7 +295,8 @@ enum {
int has_object(struct repository *r, const struct object_id *oid,
unsigned flags);
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect);
/*
* Enabling the object read lock allows multiple threads to safely call the
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 07/17] odb: get rid of `the_repository` in `odb_mkstemp()`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (5 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
` (10 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
Get rid of our dependency on `the_repository` in `odb_mkstemp()` by
passing in the object database as a parameter and adjusting all callers.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 3 ++-
builtin/index-pack.c | 2 +-
bundle-uri.c | 3 ++-
odb.c | 9 +++++----
odb.h | 7 ++++---
pack-bitmap-write.c | 3 ++-
pack-write.c | 10 ++++++----
7 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 52c792488e1..413304db9b5 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -763,7 +763,8 @@ static void start_packfile(void)
struct packed_git *p;
int pack_fd;
- pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX");
+ pack_fd = odb_mkstemp(the_repository->objects, &tmp_file,
+ "pack/tmp_pack_XXXXXX");
FLEX_ALLOC_STR(p, pack_name, tmp_file.buf);
strbuf_release(&tmp_file);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 8ce446064e8..8e5acefde40 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -362,7 +362,7 @@ static const char *open_pack_file(const char *pack_name)
input_fd = 0;
if (!pack_name) {
struct strbuf tmp_file = STRBUF_INIT;
- output_fd = odb_mkstemp(&tmp_file,
+ output_fd = odb_mkstemp(the_repository->objects, &tmp_file,
"pack/tmp_pack_XXXXXX");
pack_name = strbuf_detach(&tmp_file, NULL);
} else {
diff --git a/bundle-uri.c b/bundle-uri.c
index 993ac62c271..87a5ba50945 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -278,7 +278,8 @@ static char *find_temp_filename(void)
* Find a temporary filename that is available. This is briefly
* racy, but unlikely to collide.
*/
- fd = odb_mkstemp(&name, "bundles/tmp_uri_XXXXXX");
+ fd = odb_mkstemp(the_repository->objects, &name,
+ "bundles/tmp_uri_XXXXXX");
if (fd < 0) {
warning(_("failed to create temporary file"));
return NULL;
diff --git a/odb.c b/odb.c
index d09b8bf00cc..7ff614fb0c7 100644
--- a/odb.c
+++ b/odb.c
@@ -63,7 +63,8 @@ static const struct cached_object *find_cached_object(struct object_database *ob
return NULL;
}
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern)
{
int fd;
/*
@@ -71,15 +72,15 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
* restrictive except to remove write permission.
*/
int mode = 0444;
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
fd = git_mkstemp_mode(temp_filename->buf, mode);
if (0 <= fd)
return fd;
/* slow path */
/* some mkstemp implementations erase temp_filename on failure */
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
- safe_create_leading_directories(the_repository, temp_filename->buf);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
+ safe_create_leading_directories(odb->repo, temp_filename->buf);
return xmkstemp_mode(temp_filename->buf, mode);
}
diff --git a/odb.h b/odb.h
index 39d896ecd3f..3430089803b 100644
--- a/odb.h
+++ b/odb.h
@@ -191,12 +191,13 @@ void odb_clear(struct object_database *o);
struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
/*
- * Create a temporary file rooted in the object database directory, or
- * die on failure. The filename is taken from "pattern", which should have the
+ * Create a temporary file rooted in the primary alternate's directory, or die
+ * on failure. The filename is taken from "pattern", which should have the
* usual "XXXXXX" trailer, and the resulting filename is written into the
* "template" buffer. Returns the open descriptor.
*/
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern);
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 37648b57125..c847369eaaa 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1052,7 +1052,8 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
struct bitmap_disk_header header;
- int fd = odb_mkstemp(&tmp_file, "pack/tmp_bitmap_XXXXXX");
+ int fd = odb_mkstemp(writer->repo->objects, &tmp_file,
+ "pack/tmp_bitmap_XXXXXX");
if (writer->pseudo_merges_nr)
options |= BITMAP_OPT_PSEUDO_MERGES;
diff --git a/pack-write.c b/pack-write.c
index 6b06315f80a..eccdc798e36 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -84,7 +84,8 @@ const char *write_idx_file(struct repository *repo,
} else {
if (!index_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_idx_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_idx_XXXXXX");
index_name = strbuf_detach(&tmp_file, NULL);
} else {
unlink(index_name);
@@ -259,7 +260,8 @@ char *write_rev_file_order(struct repository *repo,
if (flags & WRITE_REV) {
if (!rev_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_rev_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_rev_XXXXXX");
path = strbuf_detach(&tmp_file, NULL);
} else {
unlink(rev_name);
@@ -342,7 +344,7 @@ static char *write_mtimes_file(struct repository *repo,
if (!to_pack)
BUG("cannot call write_mtimes_file with NULL packing_data");
- fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file, "pack/tmp_mtimes_XXXXXX");
mtimes_name = strbuf_detach(&tmp_file, NULL);
f = hashfd(repo->hash_algo, fd, mtimes_name);
@@ -531,7 +533,7 @@ struct hashfile *create_tmp_packfile(struct repository *repo,
struct strbuf tmpname = STRBUF_INIT;
int fd;
- fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmpname, "pack/tmp_pack_XXXXXX");
*pack_tmp_name = strbuf_detach(&tmpname, NULL);
return hashfd(repo->hash_algo, fd, *pack_tmp_name);
}
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 08/17] odb: get rid of `the_repository` when handling alternates
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (6 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 07/17] odb: get rid of `the_repository` in `odb_mkstemp()` Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
` (9 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
The functions to manage alternates all depend on `the_repository`.
Refactor them to accept an object database as parameter and adjusting
all callers. The functions are renamed accordingly.
Note that right now the situation is still somewhat weird because we end
up using the path provided by the object store's repository anyway. This
will be adapted over time though so that we instead store the path to
the primary object directory in the object database itself.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/clone.c | 10 +++++----
builtin/fsck.c | 6 +++---
builtin/grep.c | 2 +-
builtin/repack.c | 3 ++-
commit-graph.c | 4 ++--
loose.c | 2 +-
object-file.c | 10 ++++-----
object-name.c | 2 +-
odb.c | 44 ++++++++++++++++++---------------------
odb.h | 53 ++++++++++++++++++++++++++++++++---------------
packfile.c | 4 ++--
submodule.c | 3 ++-
t/helper/test-ref-store.c | 2 +-
tmp-objdir.c | 2 +-
14 files changed, 83 insertions(+), 64 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 1eafeefb48d..3aabdf6570b 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -171,7 +171,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
} else {
struct strbuf sb = STRBUF_INIT;
strbuf_addf(&sb, "%s/objects", ref_git);
- add_to_alternates_file(sb.buf);
+ odb_add_to_alternates_file(the_repository->objects, sb.buf);
strbuf_release(&sb);
}
@@ -212,12 +212,14 @@ static void copy_alternates(struct strbuf *src, const char *src_repo)
if (!line.len || line.buf[0] == '#')
continue;
if (is_absolute_path(line.buf)) {
- add_to_alternates_file(line.buf);
+ odb_add_to_alternates_file(the_repository->objects,
+ line.buf);
continue;
}
abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
if (!normalize_path_copy(abs_path, abs_path))
- add_to_alternates_file(abs_path);
+ odb_add_to_alternates_file(the_repository->objects,
+ abs_path);
else
warning("skipping invalid relative alternate: %s/%s",
src_repo, line.buf);
@@ -352,7 +354,7 @@ static void clone_local(const char *src_repo, const char *dest_repo)
struct strbuf alt = STRBUF_INIT;
get_common_dir(&alt, src_repo);
strbuf_addstr(&alt, "/objects");
- add_to_alternates_file(alt.buf);
+ odb_add_to_alternates_file(the_repository->objects, alt.buf);
strbuf_release(&alt);
} else {
struct strbuf src = STRBUF_INIT;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6a5181393a2..b961c2caa22 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1006,7 +1006,7 @@ int cmd_fsck(int argc,
for_each_packed_object(the_repository,
mark_packed_for_connectivity, NULL, 0);
} else {
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next)
fsck_object_dir(alternate->path);
@@ -1117,7 +1117,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_commit_graph) {
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
@@ -1135,7 +1135,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_multi_pack_index) {
struct child_process midx_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
diff --git a/builtin/grep.c b/builtin/grep.c
index 3858df2a82e..b19fee20425 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -462,7 +462,7 @@ static int grep_submodule(struct grep_opt *opt,
/*
* NEEDSWORK: repo_read_gitmodules() might call
- * add_to_alternates_memory() via config_from_gitmodules(). This
+ * odb_add_to_alternates_memory() via config_from_gitmodules(). This
* operation causes a race condition with concurrent object readings
* performed by the worker threads. That's why we need obj_read_lock()
* here. It should be removed once it's no longer necessary to add the
diff --git a/builtin/repack.c b/builtin/repack.c
index 16782320058..8145474cf8d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1256,7 +1256,8 @@ int cmd_repack(int argc,
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
die(_(incremental_bitmap_conflict_error));
- if (write_bitmaps && po_args.local && has_alt_odb(the_repository)) {
+ if (write_bitmaps && po_args.local &&
+ odb_has_alternates(the_repository->objects)) {
/*
* When asked to do a local repack, but we have
* packfiles that are inherited from an alternate, then
diff --git a/commit-graph.c b/commit-graph.c
index 4848198d7bf..cd34b71d270 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -649,7 +649,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
count = st->st_size / (the_hash_algo->hexsz + 1);
CALLOC_ARRAY(oids, count);
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (i = 0; i < count; i++) {
struct odb_alternate *alternate;
@@ -778,7 +778,7 @@ static int prepare_commit_graph(struct repository *r)
if (!commit_graph_compatible(r))
return 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates;
!r->objects->commit_graph && alternate;
alternate = alternate->next)
diff --git a/loose.c b/loose.c
index 9febd1f3e9a..9fbf2336822 100644
--- a/loose.c
+++ b/loose.c
@@ -112,7 +112,7 @@ int repo_read_loose_object_map(struct repository *repo)
if (!should_use_loose_object_map(repo))
return 0;
- prepare_alt_odb(repo);
+ odb_prepare_alternates(repo->objects);
for (alternate = repo->objects->alternates; alternate; alternate = alternate->next) {
if (load_one_loose_object_map(repo, alternate) < 0) {
diff --git a/object-file.c b/object-file.c
index dabc238447a..9e8649135ce 100644
--- a/object-file.c
+++ b/object-file.c
@@ -106,7 +106,7 @@ static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
struct odb_alternate *alternate;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
if (check_and_freshen_odb(alternate, oid, freshen))
return 1;
@@ -211,7 +211,7 @@ static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct odb_alternate *alternate;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
*path = odb_loose_path(alternate, &buf, oid);
if (!lstat(*path, st))
@@ -233,7 +233,7 @@ static int open_loose_object(struct repository *r,
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
*path = odb_loose_path(alternate, &buf, oid);
fd = git_open(*path);
@@ -252,7 +252,7 @@ static int quick_has_loose(struct repository *r,
{
struct odb_alternate *alternate;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
if (oidtree_contains(odb_loose_cache(alternate, oid), oid))
return 1;
@@ -1542,7 +1542,7 @@ int for_each_loose_object(each_loose_object_fn cb, void *data,
{
struct odb_alternate *alternate;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
int r = for_each_loose_file_in_objdir(alternate->path, cb, NULL,
NULL, data);
diff --git a/object-name.c b/object-name.c
index b83ba882b9e..2b757eb7948 100644
--- a/object-name.c
+++ b/object-name.c
@@ -376,7 +376,7 @@ static int init_object_disambiguation(struct repository *r,
ds->hex_pfx[len] = '\0';
ds->repo = r;
ds->bin_pfx.algo = algo ? hash_algo_by_ptr(algo) : GIT_HASH_UNKNOWN;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
return 0;
}
diff --git a/odb.c b/odb.c
index 7ff614fb0c7..bd601471cd7 100644
--- a/odb.c
+++ b/odb.c
@@ -272,10 +272,11 @@ static void read_info_alternates(struct object_database *odb,
free(path);
}
-void add_to_alternates_file(const char *reference)
+void odb_add_to_alternates_file(struct object_database *odb,
+ const char *reference)
{
struct lock_file lock = LOCK_INIT;
- char *alts = repo_git_path(the_repository, "objects/info/alternates");
+ char *alts = repo_git_path(odb->repo, "objects/info/alternates");
FILE *in, *out;
int found = 0;
@@ -308,22 +309,23 @@ void add_to_alternates_file(const char *reference)
fprintf_or_die(out, "%s\n", reference);
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
- if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository->objects, reference,
+ if (odb->loaded_alternates)
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
free(alts);
}
-void add_to_alternates_memory(const char *reference)
+void odb_add_to_alternates_memory(struct object_database *odb,
+ const char *reference)
{
/*
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(odb);
- link_alt_odb_entries(the_repository->objects, reference,
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
@@ -335,7 +337,7 @@ struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
/*
* Make a new primary odb and link the old primary ODB in as an
@@ -379,12 +381,6 @@ void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path
free_object_directory(cur_alt);
}
-/*
- * Compute the exact path an alternate is at and returns it. In case of
- * error NULL is returned and the human readable error is added to `err`
- * `path` may be relative and should point to $GIT_DIR.
- * `err` must not be null.
- */
char *compute_alternate_path(const char *path, struct strbuf *err)
{
char *ref_git = NULL;
@@ -455,7 +451,7 @@ struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(odb->repo);
+ odb_prepare_alternates(odb);
for (alternate = odb->alternates; alternate; alternate = alternate->next) {
strbuf_realpath(&odb_path_real, alternate->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
@@ -573,7 +569,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
struct odb_alternate *alternate;
int r = 0;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
r = fn(alternate, cb);
if (r)
@@ -582,21 +578,21 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
return r;
}
-void prepare_alt_odb(struct repository *r)
+void odb_prepare_alternates(struct object_database *odb)
{
- if (r->objects->loaded_alternates)
+ if (odb->loaded_alternates)
return;
- link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(odb, odb->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r->objects, r->objects->alternates->path, 0);
- r->objects->loaded_alternates = 1;
+ read_info_alternates(odb, odb->alternates->path, 0);
+ odb->loaded_alternates = 1;
}
-int has_alt_odb(struct repository *r)
+int odb_has_alternates(struct object_database *odb)
{
- prepare_alt_odb(r);
- return !!r->objects->alternates->next;
+ odb_prepare_alternates(odb);
+ return !!odb->alternates->next;
}
int obj_read_use_lock = 0;
diff --git a/odb.h b/odb.h
index 3430089803b..443af1b6154 100644
--- a/odb.h
+++ b/odb.h
@@ -12,6 +12,14 @@ struct oidtree;
struct strbuf;
struct repository;
+/*
+ * Compute the exact path an alternate is at and returns it. In case of
+ * error NULL is returned and the human readable error is added to `err`
+ * `path` may be relative and should point to $GIT_DIR.
+ * `err` must not be null.
+ */
+char *compute_alternate_path(const char *path, struct strbuf *err);
+
/*
* An alternate part of an object database that stores the actual objects.
*/
@@ -55,27 +63,11 @@ struct odb_alternate {
char *path;
};
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
typedef int alt_odb_fn(struct odb_alternate *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
-/*
- * 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);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -114,7 +106,7 @@ struct object_database {
/*
* A list of alternate object directories loaded from the environment;
* this should not generally need to be accessed directly, but will
- * populate the "alternates" list when prepare_alt_odb() is run.
+ * populate the "alternates" list when odb_prepare_alternates() is run.
*/
char *alternate_db;
@@ -199,6 +191,33 @@ struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
int odb_mkstemp(struct object_database *odb,
struct strbuf *temp_filename, const char *pattern);
+/*
+ * Prepare alternate object backends for the given database by reading
+ * "objects/info/alternates" and opening the respective alternates.
+ */
+void odb_prepare_alternates(struct object_database *odb);
+
+/*
+ * Check whether the object database has any alternates. The primary object
+ * backend does not count as alternate.
+ */
+int odb_has_alternates(struct object_database *odb);
+
+/*
+ * Add the directory to the on-disk alternates file; the new entry will also
+ * take effect in the current process.
+ */
+void odb_add_to_alternates_file(struct object_database *odb,
+ 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 odb_add_to_alternates_memory(struct object_database *odb,
+ const char *dir);
+
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,
diff --git a/packfile.c b/packfile.c
index 8133948b58f..ab9628eb3d4 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1023,7 +1023,7 @@ static void prepare_packed_git(struct repository *r)
if (r->objects->packed_git_initialized)
return;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
int local = (alternate == r->objects->alternates);
prepare_multi_pack_index_one(r, alternate->path, local);
@@ -1048,7 +1048,7 @@ void reprepare_packed_git(struct repository *r)
* the lifetime of the process.
*/
r->objects->loaded_alternates = 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates; alternate; alternate = alternate->next)
odb_clear_loose_cache(alternate);
diff --git a/submodule.c b/submodule.c
index 9b1018877df..386be234230 100644
--- a/submodule.c
+++ b/submodule.c
@@ -189,7 +189,8 @@ int register_all_submodule_odb_as_alternates(void)
int ret = added_submodule_odb_paths.nr;
for (i = 0; i < added_submodule_odb_paths.nr; i++)
- add_to_alternates_memory(added_submodule_odb_paths.items[i].string);
+ odb_add_to_alternates_memory(the_repository->objects,
+ added_submodule_odb_paths.items[i].string);
if (ret) {
string_list_clear(&added_submodule_odb_paths, 0);
trace2_data_intmax("submodule", the_repository,
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 2920ca59d72..8d9a271845c 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -79,7 +79,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)
if (!repo_submodule_path_append(the_repository,
&sb, gitdir, "objects/"))
die("computing submodule path failed");
- add_to_alternates_memory(sb.buf);
+ odb_add_to_alternates_memory(the_repository->objects, sb.buf);
strbuf_release(&sb);
*refs = repo_get_submodule_ref_store(the_repository, gitdir);
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 9e05fcbddd0..cbb50438d16 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -304,7 +304,7 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)
void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
{
- add_to_alternates_memory(t->path.buf);
+ odb_add_to_alternates_memory(t->repo->objects, t->path.buf);
}
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 09/17] odb: get rid of `the_repository` in `for_each()` functions
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (7 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 10/17] odb: get rid of `the_repository` when handling the primary alternate Patrick Steinhardt
` (8 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
There are a couple of iterator-style functions that execute a callback
for each instance of a given set, all of which currently depend on
`the_repository`. Refactor them to instead take an object database as
parameter so that we can get rid of this dependency.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/count-objects.c | 2 +-
builtin/receive-pack.c | 3 ++-
builtin/submodule--helper.c | 3 ++-
diagnose.c | 2 +-
fetch-pack.c | 3 ++-
odb.c | 36 +++++++++++++++++++-----------------
odb.h | 23 ++++++++++++++++++-----
revision.c | 3 ++-
8 files changed, 47 insertions(+), 28 deletions(-)
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index da830fcee57..2752a9b02f4 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -159,7 +159,7 @@ int cmd_count_objects(int argc,
printf("prune-packable: %lu\n", packed_loose);
printf("garbage: %lu\n", garbage);
printf("size-garbage: %s\n", garbage_buf.buf);
- foreach_alt_odb(print_alternate, NULL);
+ odb_for_each_alternate(the_repository->objects, print_alternate, NULL);
strbuf_release(&loose_buf);
strbuf_release(&pack_buf);
strbuf_release(&garbage_buf);
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index cb5fd55a8e4..8c157ea7d1b 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -358,7 +358,8 @@ static void write_head_info(void)
refs_for_each_fullref_in(get_main_ref_store(the_repository), "",
exclude_patterns, show_ref_cb, &seen);
- for_each_alternate_ref(show_one_alternate_ref, &seen);
+ odb_for_each_alternate_ref(the_repository->objects,
+ show_one_alternate_ref, &seen);
oidset_clear(&seen);
strvec_clear(&excludes_vector);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a6c936fb2bd..88bbd97820a 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1668,7 +1668,8 @@ static void prepare_possible_alternates(const char *sm_name,
die(_("Value '%s' for submodule.alternateErrorStrategy is not recognized"), error_strategy);
if (!strcmp(sm_alternate, "superproject"))
- foreach_alt_odb(add_possible_reference_from_superproject, &sas);
+ odb_for_each_alternate(the_repository->objects,
+ add_possible_reference_from_superproject, &sas);
else if (!strcmp(sm_alternate, "no"))
; /* do nothing */
else
diff --git a/diagnose.c b/diagnose.c
index d407c98d094..0405368f178 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -229,7 +229,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
dir_file_stats(r->objects->alternates, &buf);
- foreach_alt_odb(dir_file_stats, &buf);
+ odb_for_each_alternate(r->objects, dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
strbuf_reset(&buf);
diff --git a/fetch-pack.c b/fetch-pack.c
index cf157f5d7e5..47fa7fa4c49 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -115,7 +115,8 @@ static void for_each_cached_alternate(struct fetch_negotiator *negotiator,
size_t i;
if (!initialized) {
- for_each_alternate_ref(cache_one_alternate, &cache);
+ odb_for_each_alternate_ref(the_repository->objects,
+ cache_one_alternate, &cache);
initialized = 1;
}
diff --git a/odb.c b/odb.c
index bd601471cd7..feca14d9683 100644
--- a/odb.c
+++ b/odb.c
@@ -494,8 +494,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
}
static void read_alternate_refs(const char *path,
- alternate_ref_fn *cb,
- void *data)
+ odb_for_each_alternate_ref_fn *cb,
+ void *payload)
{
struct child_process cmd = CHILD_PROCESS_INIT;
struct strbuf line = STRBUF_INIT;
@@ -517,7 +517,7 @@ static void read_alternate_refs(const char *path,
break;
}
- cb(&oid, data);
+ cb(&oid, payload);
}
fclose(fh);
@@ -526,16 +526,16 @@ static void read_alternate_refs(const char *path,
}
struct alternate_refs_data {
- alternate_ref_fn *fn;
- void *data;
+ odb_for_each_alternate_ref_fn *fn;
+ void *payload;
};
static int refs_from_alternate_cb(struct odb_alternate *alternate,
- void *data)
+ void *payload)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
- struct alternate_refs_data *cb = data;
+ struct alternate_refs_data *cb = payload;
if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
@@ -549,29 +549,31 @@ static int refs_from_alternate_cb(struct odb_alternate *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->data);
+ read_alternate_refs(path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
return 0;
}
-void for_each_alternate_ref(alternate_ref_fn fn, void *data)
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload)
{
- struct alternate_refs_data cb;
- cb.fn = fn;
- cb.data = data;
- foreach_alt_odb(refs_from_alternate_cb, &cb);
+ struct alternate_refs_data data;
+ data.fn = cb;
+ data.payload = payload;
+ odb_for_each_alternate(odb, refs_from_alternate_cb, &data);
}
-int foreach_alt_odb(alt_odb_fn fn, void *cb)
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload)
{
struct odb_alternate *alternate;
int r = 0;
- odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
- r = fn(alternate, cb);
+ odb_prepare_alternates(odb);
+ for (alternate = odb->alternates->next; alternate; alternate = alternate->next) {
+ r = cb(alternate, payload);
if (r)
break;
}
diff --git a/odb.h b/odb.h
index 443af1b6154..03ac369bca9 100644
--- a/odb.h
+++ b/odb.h
@@ -63,11 +63,6 @@ struct odb_alternate {
char *path;
};
-typedef int alt_odb_fn(struct odb_alternate *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -182,6 +177,24 @@ void odb_clear(struct object_database *o);
*/
struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
+/*
+ * Iterate through all alternates of the database and execute the provided
+ * callback function for each of them. Stop iterating once the callback
+ * function returns a non-zero value, in which case the value is bubbled up
+ * from the callback.
+ */
+typedef int odb_for_each_alternate_fn(struct odb_alternate *, void *);
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload);
+
+/*
+ * Iterate through all alternates of the database and yield their respective
+ * references.
+ */
+typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload);
+
/*
* Create a temporary file rooted in the primary alternate's directory, or die
* on failure. The filename is taken from "pattern", which should have the
diff --git a/revision.c b/revision.c
index cdefe7d6e48..b0364f556ee 100644
--- a/revision.c
+++ b/revision.c
@@ -1907,7 +1907,8 @@ static void add_alternate_refs_to_pending(struct rev_info *revs,
struct add_alternate_refs_data data;
data.revs = revs;
data.flags = flags;
- for_each_alternate_ref(add_one_alternate_ref, &data);
+ odb_for_each_alternate_ref(the_repository->objects,
+ add_one_alternate_ref, &data);
}
static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 10/17] odb: get rid of `the_repository` when handling the primary alternate
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (8 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 11/17] odb: get rid of `the_repository` when handling submodule alternates Patrick Steinhardt
` (7 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
The functions `set_temporary_primary_odb()` and `restore_primary_odb()`
are responsible for managing a temporary primary alternate for the
database. Both of these functions implicitly rely on `the_repository`.
Refactor them to instead take an explicit object database parameter as
argument and adjust callers. Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 19 +++++++++++--------
odb.h | 25 ++++++++++++++-----------
tmp-objdir.c | 10 ++++++----
3 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/odb.c b/odb.c
index feca14d9683..100dd39cbe8 100644
--- a/odb.c
+++ b/odb.c
@@ -329,7 +329,8 @@ void odb_add_to_alternates_memory(struct object_database *odb,
'\n', NULL, 0);
}
-struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_alternate *odb_set_temporary_primary_alternate(struct object_database *odb,
+ const char *dir, int will_destroy)
{
struct odb_alternate *alternate;
@@ -337,14 +338,14 @@ struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- odb_prepare_alternates(the_repository->objects);
+ odb_prepare_alternates(odb);
/*
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
alternate = xcalloc(1, sizeof(*alternate));
- alternate->odb = the_repository->objects;
+ alternate->odb = odb;
alternate->path = xstrdup(dir);
/*
@@ -353,8 +354,8 @@ struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
*/
alternate->disable_ref_updates = 1;
alternate->will_destroy = will_destroy;
- alternate->next = the_repository->objects->alternates;
- the_repository->objects->alternates = alternate;
+ alternate->next = odb->alternates;
+ odb->alternates = alternate;
return alternate->next;
}
@@ -366,9 +367,11 @@ static void free_object_directory(struct odb_alternate *alternate)
free(alternate);
}
-void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path)
+void odb_restore_primary_alternate(struct object_database *odb,
+ struct odb_alternate *restore_alt,
+ const char *old_path)
{
- struct odb_alternate *cur_alt = the_repository->objects->alternates;
+ struct odb_alternate *cur_alt = odb->alternates;
if (strcmp(old_path, cur_alt->path))
BUG("expected %s as primary object store; found %s",
@@ -377,7 +380,7 @@ void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path
if (cur_alt->next != restore_alt)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->alternates = restore_alt;
+ odb->alternates = restore_alt;
free_object_directory(cur_alt);
}
diff --git a/odb.h b/odb.h
index 03ac369bca9..f61b391764f 100644
--- a/odb.h
+++ b/odb.h
@@ -63,17 +63,6 @@ struct odb_alternate {
char *path;
};
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy);
-
-/*
- * Restore a previous ODB replaced by set_temporary_main_odb.
- */
-void restore_primary_odb(struct odb_alternate *restore_alternate, const char *old_path);
-
struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
@@ -177,6 +166,20 @@ void odb_clear(struct object_database *o);
*/
struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary alternate.
+ */
+struct odb_alternate *odb_set_temporary_primary_alternate(struct object_database *odb,
+ const char *dir, int will_destroy);
+
+/*
+ * Restore a previous bakcend replaced by `odb_set_temporary_primary_alternate()`.
+ */
+void odb_restore_primary_alternate(struct object_database *odb,
+ struct odb_alternate *restore_alt,
+ const char *old_path);
+
/*
* Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/tmp-objdir.c b/tmp-objdir.c
index cbb50438d16..c2e58c4be5c 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -47,7 +47,7 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
the_tmp_objdir = NULL;
if (t->prev_alt)
- restore_primary_odb(t->prev_alt, t->path.buf);
+ odb_restore_primary_alternate(t->repo->objects, t->prev_alt, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -279,7 +279,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (t->prev_alt) {
if (t->repo->objects->alternates->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_alt, t->path.buf);
+ odb_restore_primary_alternate(t->repo->objects, t->prev_alt, t->path.buf);
t->prev_alt = NULL;
}
@@ -311,7 +311,8 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
if (t->prev_alt)
BUG("the primary object database is already replaced");
- t->prev_alt = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_alt = odb_set_temporary_primary_alternate(t->repo->objects,
+ t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
@@ -320,7 +321,8 @@ struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
if (!the_tmp_objdir || !the_tmp_objdir->prev_alt)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_alt, the_tmp_objdir->path.buf);
+ odb_restore_primary_alternate(the_tmp_objdir->repo->objects,
+ the_tmp_objdir->prev_alt, the_tmp_objdir->path.buf);
the_tmp_objdir->prev_alt = NULL;
return the_tmp_objdir;
}
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 11/17] odb: get rid of `the_repository` when handling submodule alternates
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (9 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 10/17] odb: get rid of `the_repository` when handling the primary alternate Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
` (6 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
The "--recursive" flag for git-grep(1) allows users to grep for a string
across submodule boundaries. To make this work we add each submodule's
object alternate to our own object database so that the objects can be
accessed directly.
The infrastructure for this depends on a global string list of submodule
paths. The caller is expected to call `add_submodule_odb_by_path()` for
each alternate and the object database will then eventually register all
submodule alternates via `do_oid_object_info_extended()` in case it
isn't able to look up a specific object.
This reliance on global state is of course suboptimal with regards to
our libification efforts.
Refactor the logic so that the list of submodule alternates is instead
tracked in the object database itself. This allows us to lose the
condition of `r == the_repository` before registering submodule
alternates as we only ever add submodule alternates to `the_repository`
anyway. As such, behaviour before and after this refactoring should
always be the same.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/grep.c | 3 ++-
odb.c | 37 +++++++++++++++++++++++++++++++------
odb.h | 15 +++++++++++++++
submodule-config.c | 3 ++-
submodule.c | 26 --------------------------
submodule.h | 9 ---------
6 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index b19fee20425..277bc121e4e 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,8 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->alternates->path);
+ odb_add_submodule_alternate_by_path(the_repository->objects,
+ subrepo->objects->alternates->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/odb.c b/odb.c
index 100dd39cbe8..72ff1ab5a7d 100644
--- a/odb.c
+++ b/odb.c
@@ -24,6 +24,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "submodule.h"
+#include "trace2.h"
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
@@ -469,6 +470,12 @@ struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
return alternate;
}
+void odb_add_submodule_alternate_by_path(struct object_database *odb,
+ const char *path)
+{
+ string_list_insert(&odb->submodule_alternate_paths, path);
+}
+
static void fill_alternate_refs_command(struct child_process *cmd,
const char *repo_path)
{
@@ -623,6 +630,23 @@ void disable_obj_read_lock(void)
int fetch_if_missing = 1;
+static int register_all_submodule_alternates(struct object_database *odb)
+{
+ int ret = odb->submodule_alternate_paths.nr;
+
+ for (size_t i = 0; i < odb->submodule_alternate_paths.nr; i++)
+ odb_add_to_alternates_memory(odb,
+ odb->submodule_alternate_paths.items[i].string);
+ if (ret) {
+ string_list_clear(&odb->submodule_alternate_paths, 0);
+ trace2_data_intmax("submodule", odb->repo,
+ "register_all_submodule_alternates/registered", ret);
+ if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
+ BUG("register_all_submodule_alternates() called");
+ }
+ return ret;
+}
+
static int do_oid_object_info_extended(struct repository *r,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
@@ -678,13 +702,12 @@ static int do_oid_object_info_extended(struct repository *r,
}
/*
- * If r is the_repository, this might be an attempt at
- * accessing a submodule object as if it were in the_repository
- * (having called add_submodule_odb() on that submodule's ODB).
- * If any such ODBs exist, register them and try again.
+ * This might be an attempt at accessing a submodule object as
+ * if it were in main object store (having called
+ * `odb_add_submodule_alternate_by_path()` on that submodule's
+ * ODB). If any such ODBs exist, register them and try again.
*/
- if (r == the_repository &&
- register_all_submodule_odb_as_alternates())
+ if (register_all_submodule_alternates(r->objects))
/* We added some alternates; retry */
continue;
@@ -977,6 +1000,7 @@ struct object_database *odb_new(struct repository *repo)
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
+ string_list_init_dup(&o->submodule_alternate_paths);
return o;
}
@@ -1027,4 +1051,5 @@ void odb_clear(struct object_database *o)
o->packed_git = NULL;
hashmap_clear(&o->pack_map);
+ string_list_clear(&o->submodule_alternate_paths, 0);
}
diff --git a/odb.h b/odb.h
index f61b391764f..ef8a8a544b2 100644
--- a/odb.h
+++ b/odb.h
@@ -5,6 +5,7 @@
#include "object.h"
#include "list.h"
#include "oidset.h"
+#include "string-list.h"
#include "thread-utils.h"
struct oidmap;
@@ -155,6 +156,12 @@ struct object_database {
* packs.
*/
unsigned packed_git_initialized : 1;
+
+ /*
+ * Submodule alternate paths that will be added as alternatives to
+ * allow lookup of submodule objects via the main object database.
+ */
+ struct string_list submodule_alternate_paths;
};
struct object_database *odb_new(struct repository *repo);
@@ -180,6 +187,14 @@ void odb_restore_primary_alternate(struct object_database *odb,
struct odb_alternate *restore_alt,
const char *old_path);
+/*
+ * Call odb_add_submodule_alternate_by_path() to add the submodule at the given
+ * path to a list. The object stores of all submodules in that list will be
+ * added as alternates in the object store when looking up objects.
+ */
+void odb_add_submodule_alternate_by_path(struct object_database *odb,
+ const char *path);
+
/*
* Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/submodule-config.c b/submodule-config.c
index 09034a587f1..0f775f93259 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,8 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->alternates->path);
+ odb_add_submodule_alternate_by_path(the_repository->objects,
+ repo->objects->alternates->path);
} else {
goto out;
}
diff --git a/submodule.c b/submodule.c
index 386be234230..788c9e55ed3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -31,7 +31,6 @@
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
-#include "trace2.h"
static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
static int initialized_fetch_ref_tips;
@@ -176,31 +175,6 @@ void stage_updated_gitmodules(struct index_state *istate)
die(_("staging updated .gitmodules failed"));
}
-static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_DUP;
-
-void add_submodule_odb_by_path(const char *path)
-{
- string_list_insert(&added_submodule_odb_paths, path);
-}
-
-int register_all_submodule_odb_as_alternates(void)
-{
- int i;
- int ret = added_submodule_odb_paths.nr;
-
- for (i = 0; i < added_submodule_odb_paths.nr; i++)
- odb_add_to_alternates_memory(the_repository->objects,
- added_submodule_odb_paths.items[i].string);
- if (ret) {
- string_list_clear(&added_submodule_odb_paths, 0);
- trace2_data_intmax("submodule", the_repository,
- "register_all_submodule_odb_as_alternates/registered", ret);
- if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
- BUG("register_all_submodule_odb_as_alternates() called");
- }
- return ret;
-}
-
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
const char *path)
{
diff --git a/submodule.h b/submodule.h
index db980c1d083..b10e16e6c06 100644
--- a/submodule.h
+++ b/submodule.h
@@ -104,15 +104,6 @@ int submodule_uses_gitfile(const char *path);
#define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
int bad_to_remove_submodule(const char *path, unsigned flags);
-/*
- * Call add_submodule_odb_by_path() to add the submodule at the given
- * path to a list. When register_all_submodule_odb_as_alternates() is
- * called, the object stores of all submodules in that list will be
- * added as alternates in the_repository.
- */
-void add_submodule_odb_by_path(const char *path);
-int register_all_submodule_odb_as_alternates(void);
-
/*
* Checks if there are submodule changes in a..b. If a is the null OID,
* checks b and all its ancestors instead.
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 12/17] odb: trivial refactorings to get rid of `the_repository`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (10 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 11/17] odb: get rid of `the_repository` when handling submodule alternates Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
` (5 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
All of the external functions provided by the object database subsystem
don't depend on `the_repository` anymore, but some internal functions
still do. Refactor those cases by plumbing through the repository that
owns the object database.
This change allows us to get rid of the `USE_THE_REPOSITORY_VARIABLE`
preprocessor define.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/odb.c b/odb.c
index 72ff1ab5a7d..c150c01db4a 100644
--- a/odb.c
+++ b/odb.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "abspath.h"
#include "commit-graph.h"
@@ -476,12 +474,13 @@ void odb_add_submodule_alternate_by_path(struct object_database *odb,
string_list_insert(&odb->submodule_alternate_paths, path);
}
-static void fill_alternate_refs_command(struct child_process *cmd,
+static void fill_alternate_refs_command(struct repository *repo,
+ struct child_process *cmd,
const char *repo_path)
{
const char *value;
- if (!git_config_get_value("core.alternateRefsCommand", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsCommand", &value)) {
cmd->use_shell = 1;
strvec_push(&cmd->args, value);
@@ -493,7 +492,7 @@ static void fill_alternate_refs_command(struct child_process *cmd,
strvec_push(&cmd->args, "for-each-ref");
strvec_push(&cmd->args, "--format=%(objectname)");
- if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsPrefixes", &value)) {
strvec_push(&cmd->args, "--");
strvec_split(&cmd->args, value);
}
@@ -503,7 +502,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
cmd->out = -1;
}
-static void read_alternate_refs(const char *path,
+static void read_alternate_refs(struct repository *repo,
+ const char *path,
odb_for_each_alternate_ref_fn *cb,
void *payload)
{
@@ -511,7 +511,7 @@ static void read_alternate_refs(const char *path,
struct strbuf line = STRBUF_INIT;
FILE *fh;
- fill_alternate_refs_command(&cmd, path);
+ fill_alternate_refs_command(repo, &cmd, path);
if (start_command(&cmd))
return;
@@ -521,7 +521,7 @@ static void read_alternate_refs(const char *path,
struct object_id oid;
const char *p;
- if (parse_oid_hex(line.buf, &oid, &p) || *p) {
+ if (parse_oid_hex_algop(line.buf, &oid, &p, repo->hash_algo) || *p) {
warning(_("invalid line while parsing alternate refs: %s"),
line.buf);
break;
@@ -559,7 +559,7 @@ static int refs_from_alternate_cb(struct odb_alternate *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->payload);
+ read_alternate_refs(alternate->odb->repo, path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, the_repository->hash_algo);
+ oidclr(oi->delta_base_oid, r->hash_algo);
if (oi->type_name)
strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
@@ -765,10 +765,10 @@ static int oid_object_info_convert(struct repository *r,
void *content;
int ret;
- if (repo_oid_to_algop(r, input_oid, the_hash_algo, &oid)) {
+ if (repo_oid_to_algop(r, input_oid, r->hash_algo, &oid)) {
if (do_die)
die(_("missing mapping of %s to %s"),
- oid_to_hex(input_oid), the_hash_algo->name);
+ oid_to_hex(input_oid), r->hash_algo->name);
return -1;
}
@@ -804,8 +804,8 @@ static int oid_object_info_convert(struct repository *r,
if (type == -1)
return -1;
if (type != OBJ_BLOB) {
- ret = convert_object_file(the_repository, &outbuf,
- the_hash_algo, input_algo,
+ ret = convert_object_file(r, &outbuf,
+ r->hash_algo, input_algo,
content, size, type, !do_die);
free(content);
if (ret == -1)
@@ -953,9 +953,9 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + the_hash_algo->hexsz > isize ||
+ if (ref_length + r->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
free(buffer);
return NULL;
}
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 13/17] odb: rename `oid_object_info()`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (11 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
` (4 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
Rename `oid_object_info()` to `odb_read_object_info()` as well as their
`_extended()` variant to match other functions related to the object
database and our modern coding guidelines.
Introduce compatibility wrappers so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
archive.c | 2 +-
blame.c | 4 +--
builtin/blame.c | 4 +--
builtin/cat-file.c | 26 ++++++++++---------
builtin/describe.c | 3 ++-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 17 ++++++------
builtin/fsck.c | 7 ++---
builtin/gc.c | 2 +-
builtin/grep.c | 2 +-
builtin/index-pack.c | 13 +++++-----
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 4 +--
builtin/mktree.c | 8 +++---
builtin/pack-objects.c | 30 ++++++++++++----------
builtin/prune.c | 4 +--
builtin/repack.c | 2 +-
builtin/replace.c | 10 ++++----
builtin/rev-list.c | 6 +++--
builtin/tag.c | 4 +--
builtin/unpack-objects.c | 2 +-
commit-graph.c | 2 +-
commit.c | 3 ++-
diff.c | 18 ++++++-------
fetch-pack.c | 4 +--
list-objects-filter.c | 2 +-
log-tree.c | 2 +-
merge-ort.c | 4 +--
object-file.c | 2 +-
object-file.h | 2 +-
object-name.c | 16 ++++++------
object.c | 6 ++---
odb.c | 60 ++++++++++++++++++++++---------------------
odb.h | 46 +++++++++++++++++++++++++++------
pack-bitmap-write.c | 4 +--
pack-bitmap.c | 8 +++---
packfile.c | 5 ++--
promisor-remote.c | 4 +--
protocol-caps.c | 2 +-
reachable.c | 2 +-
read-cache.c | 6 ++---
ref-filter.c | 4 +--
remote.c | 5 ++--
sequencer.c | 5 ++--
streaming.c | 8 +++---
submodule.c | 5 ++--
t/helper/test-partial-clone.c | 2 +-
tag.c | 2 +-
48 files changed, 213 insertions(+), 170 deletions(-)
diff --git a/archive.c b/archive.c
index 7fa2cc2596a..f2511d530d5 100644
--- a/archive.c
+++ b/archive.c
@@ -215,7 +215,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
/* Stream it? */
if (S_ISREG(mode) && !args->convert &&
- oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
+ odb_read_object_info(args->repo->objects, oid, &size) == OBJ_BLOB &&
size > repo_settings_get_big_file_threshold(the_repository))
return write_entry(args, oid, path.buf, path.len, mode, NULL, size);
diff --git a/blame.c b/blame.c
index 0ceea080a80..97db3355af4 100644
--- a/blame.c
+++ b/blame.c
@@ -116,7 +116,7 @@ static void verify_working_tree_path(struct repository *r,
unsigned short mode;
if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
- oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
+ odb_read_object_info(r->objects, &blob_oid, NULL) == OBJ_BLOB)
return;
}
@@ -1245,7 +1245,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
return 0;
if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
goto error_out;
- if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
+ if (odb_read_object_info(r->objects, &origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out;
return 0;
error_out:
diff --git a/builtin/blame.c b/builtin/blame.c
index 15eda60af90..91586e6852b 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -837,7 +837,7 @@ static int is_a_rev(const char *name)
if (repo_get_oid(the_repository, name, &oid))
return 0;
- return OBJ_NONE < oid_object_info(the_repository, &oid, NULL);
+ return OBJ_NONE < odb_read_object_info(the_repository->objects, &oid, NULL);
}
static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
@@ -848,7 +848,7 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
oidcpy(&oid, oid_ret);
while (1) {
struct object *obj;
- int kind = oid_object_info(r, &oid, NULL);
+ int kind = odb_read_object_info(r->objects, &oid, NULL);
if (kind == OBJ_COMMIT) {
oidcpy(oid_ret, &oid);
return 0;
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 2fa5e3f43bd..da172155c85 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -137,7 +137,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
switch (opt) {
case 't':
oi.type_name = &sb;
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (sb.len) {
printf("%s\n", sb.buf);
@@ -155,7 +155,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
oi.contentp = (void**)&buf;
}
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
@@ -189,7 +189,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
/* else fallthrough */
case 'p':
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("Not a valid object name %s", obj_name);
@@ -226,7 +226,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
if (exp_type_id == OBJ_BLOB) {
struct object_id blob_oid;
- if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
+ if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_TAG) {
char *buffer = repo_read_object_file(the_repository,
&oid,
&type,
@@ -244,7 +245,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
} else
oidcpy(&blob_oid, &oid);
- if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB) {
+ if (odb_read_object_info(the_repository->objects,
+ &blob_oid, NULL) == OBJ_BLOB) {
ret = stream_blob(&blob_oid);
goto cleanup;
}
@@ -303,7 +305,7 @@ struct expand_data {
/*
* After a mark_query run, this object_info is set up to be
- * passed to oid_object_info_extended. It will point to the data
+ * passed to odb_read_object_info_extended. It will point to the data
* elements above, so you can retrieve the response from there.
*/
struct object_info info;
@@ -493,12 +495,12 @@ static void batch_object_write(const char *obj_name,
data->info.sizep = &data->size;
if (pack)
- ret = packed_object_info(the_repository, pack, offset,
- &data->info);
+ ret = packed_object_info(the_repository, pack,
+ offset, &data->info);
else
- ret = oid_object_info_extended(the_repository,
- &data->oid, &data->info,
- OBJECT_INFO_LOOKUP_REPLACE);
+ ret = odb_read_object_info_extended(the_repository->objects,
+ &data->oid, &data->info,
+ OBJECT_INFO_LOOKUP_REPLACE);
if (ret < 0) {
report_object_status(opt, obj_name, &data->oid, "missing");
return;
@@ -881,7 +883,7 @@ static int batch_objects(struct batch_options *opt)
/*
* Expand once with our special mark_query flag, which will prime the
- * object_info to be handed to oid_object_info_extended for each
+ * object_info to be handed to odb_read_object_info_extended for each
* object.
*/
memset(&data, 0, sizeof(data));
diff --git a/builtin/describe.c b/builtin/describe.c
index 96cb68e5e5d..fbf305d7624 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -552,7 +552,8 @@ static void describe(const char *arg, int last_one)
if (cmit)
describe_commit(&oid, &sb);
- else if (oid_object_info(the_repository, &oid, NULL) == OBJ_BLOB)
+ else if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_BLOB)
describe_blob(oid, &sb);
else
die(_("%s is neither a commit nor blob"), arg);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 0505f289a94..6c93cf0a8aa 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -1200,7 +1200,7 @@ static void import_marks(char *input_file, int check_exists)
if (last_idnum < mark)
last_idnum = mark;
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(&oid));
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 413304db9b5..2718376f2c9 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1756,8 +1756,8 @@ static void insert_object_entry(struct mark_set **s, struct object_id *oid, uint
struct object_entry *e;
e = find_object(oid);
if (!e) {
- enum object_type type = oid_object_info(the_repository,
- oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
e = insert_object(oid);
@@ -2416,8 +2416,8 @@ static void file_change_m(const char *p, struct branch *b)
enum object_type expected = S_ISDIR(mode) ?
OBJ_TREE: OBJ_BLOB;
enum object_type type = oe ? oe->type :
- oid_object_info(the_repository, &oid,
- NULL);
+ odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("%s not found: %s",
S_ISDIR(mode) ? "Tree" : "Blob",
@@ -2553,7 +2553,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
die("Not a blob (actually a %s): %s",
type_name(oe->type), command_buf.buf);
} else if (!is_null_oid(&oid)) {
- enum object_type type = oid_object_info(the_repository, &oid,
+ enum object_type type = odb_read_object_info(the_repository->objects, &oid,
NULL);
if (type < 0)
die("Blob not found: %s", command_buf.buf);
@@ -2895,7 +2895,8 @@ static void parse_new_tag(const char *arg)
} else if (!repo_get_oid(the_repository, from, &oid)) {
struct object_entry *oe = find_object(&oid);
if (!oe) {
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("Not a valid object: %s", from);
} else
@@ -3085,8 +3086,8 @@ static struct object_entry *dereference(struct object_entry *oe,
const unsigned hexsz = the_hash_algo->hexsz;
if (!oe) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
/* cache it! */
diff --git a/builtin/fsck.c b/builtin/fsck.c
index b961c2caa22..08a79fe044d 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -71,7 +71,8 @@ static const char *printable_type(const struct object_id *oid,
const char *ret;
if (type == OBJ_NONE)
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
ret = type_name(type);
if (!ret)
@@ -232,8 +233,8 @@ static void mark_unreachable_referents(const struct object_id *oid)
* (and we want to avoid parsing blobs).
*/
if (obj->type == OBJ_NONE) {
- enum object_type type = oid_object_info(the_repository,
- &obj->oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ &obj->oid, NULL);
if (type > 0)
object_as_type(obj, type, 0);
}
diff --git a/builtin/gc.c b/builtin/gc.c
index 9e9d31c1f39..40bd2259c6a 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1006,7 +1006,7 @@ static int dfs_on_ref(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
commit = lookup_commit(the_repository, oid);
diff --git a/builtin/grep.c b/builtin/grep.c
index 277bc121e4e..311c940aa9e 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -520,7 +520,7 @@ static int grep_submodule(struct grep_opt *opt,
struct strbuf base = STRBUF_INIT;
obj_read_lock();
- object_type = oid_object_info(subrepo, oid, NULL);
+ object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
data = read_object_with_reference(subrepo,
oid, OBJ_TREE,
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 8e5acefde40..82cf80b89d1 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -260,7 +260,8 @@ static unsigned check_object(struct object *obj)
if (!(obj->flags & FLAG_CHECKED)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects,
+ &obj->oid, &size);
if (type <= 0)
die(_("did not receive expected object %s"),
oid_to_hex(&obj->oid));
@@ -908,7 +909,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
enum object_type has_type;
unsigned long has_size;
read_lock();
- has_type = oid_object_info(the_repository, oid, &has_size);
+ has_type = odb_read_object_info(the_repository->objects, oid, &has_size);
if (has_type < 0)
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
@@ -1495,9 +1496,9 @@ static void fix_unresolved_deltas(struct hashfile *f)
struct oid_array to_fetch = OID_ARRAY_INIT;
for (i = 0; i < nr_ref_deltas; i++) {
struct ref_delta_entry *d = sorted_by_pos[i];
- if (!oid_object_info_extended(the_repository, &d->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &d->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &d->oid);
}
@@ -1823,7 +1824,7 @@ static void repack_local_links(void)
oidset_iter_init(&outgoing_links, &iter);
while ((oid = oidset_iter_next(&iter))) {
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info, 0))
/* Missing; assume it is a promisor object */
continue;
if (info.whence == OI_PACKED && info.u.packed.pack->pack_promisor)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 821339b07d4..ff975e7be06 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -251,7 +251,7 @@ static void expand_objectsize(struct repository *repo, struct strbuf *line,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(repo, oid, &size) < 0)
+ if (odb_read_object_info(repo->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 62b6fd58c16..4d616dd5282 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -27,7 +27,7 @@ static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
@@ -217,7 +217,7 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base,
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
+ if (odb_read_object_info(the_repository->objects, oid, &size) == OBJ_BAD)
xsnprintf(size_text, sizeof(size_text), "BAD");
else
xsnprintf(size_text, sizeof(size_text),
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 016b0e5b224..81df7f6099f 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -124,10 +124,10 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
/* Check the type of object identified by oid without fetching objects */
oi.typep = &obj_type;
- if (oid_object_info_extended(the_repository, &oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_QUICK |
- OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_QUICK |
+ OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
obj_type = -1;
if (obj_type < 0) {
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 99b63cb0980..da35d684081 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2154,10 +2154,10 @@ static void prefetch_to_pack(uint32_t object_index_start) {
for (i = object_index_start; i < to_pack.nr_objects; i++) {
struct object_entry *entry = to_pack.objects + i;
- if (!oid_object_info_extended(the_repository,
- &entry->idx.oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &entry->idx.oid,
+ NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &entry->idx.oid);
}
@@ -2298,19 +2298,19 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
/*
* No choice but to fall back to the recursive delta walk
- * with oid_object_info() to find about the object type
+ * with odb_read_object_info() to find about the object type
* at this point...
*/
give_up:
unuse_pack(&w_curs);
}
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
if (repo_has_promisor_remote(the_repository)) {
prefetch_to_pack(object_index);
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
type = -1;
} else {
type = -1;
@@ -2384,12 +2384,13 @@ static void drop_reused_delta(struct object_entry *entry)
if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
/*
* We failed to get the info from this pack for some reason;
- * fall back to oid_object_info, which may find another copy.
+ * fall back to odb_read_object_info, which may find another copy.
* And if that fails, the error will be recorded in oe_type(entry)
* and dealt with in prepare_pack().
*/
oe_set_type(entry,
- oid_object_info(the_repository, &entry->idx.oid, &size));
+ odb_read_object_info(the_repository->objects,
+ &entry->idx.oid, &size));
} else {
oe_set_type(entry, type);
}
@@ -2677,7 +2678,8 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
packing_data_lock(&to_pack);
- if (oid_object_info(the_repository, &e->idx.oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects,
+ &e->idx.oid, &size) < 0)
die(_("unable to get size of %s"),
oid_to_hex(&e->idx.oid));
packing_data_unlock(&to_pack);
@@ -4063,7 +4065,7 @@ static void add_objects_in_unpacked_packs(void)
static int add_loose_object(const struct object_id *oid, const char *path,
void *data UNUSED)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0) {
warning(_("loose object at %s could not be examined"), path);
@@ -4449,7 +4451,7 @@ static int option_parse_cruft_expiration(const struct option *opt UNUSED,
static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED)
{
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, &obj->oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0))
BUG("should_include_obj should only be called on existing objects");
return info.whence != OI_PACKED || !info.u.packed.pack->pack_promisor;
}
diff --git a/builtin/prune.c b/builtin/prune.c
index 7bbfb14c2be..339017c7ccf 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -99,8 +99,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
if (st.st_mtime > expire)
return 0;
if (show_only || verbose) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? type_name(type) : "unknown");
}
diff --git a/builtin/repack.c b/builtin/repack.c
index 8145474cf8d..a89c2b704fb 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -707,7 +707,7 @@ static int midx_snapshot_ref_one(const char *refname UNUSED,
if (oidset_insert(&data->seen, oid))
return 0; /* already seen */
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
fprintf(data->f->fp, "%s%s\n", data->preferred ? "+" : "",
diff --git a/builtin/replace.c b/builtin/replace.c
index 11c7e2d4c0c..5ff2ab723cb 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -65,8 +65,8 @@ static int show_reference(const char *refname,
if (repo_get_oid(data->repo, refname, &object))
return error(_("failed to resolve '%s' as a valid ref"), refname);
- obj_type = oid_object_info(data->repo, &object, NULL);
- repl_type = oid_object_info(data->repo, oid, NULL);
+ obj_type = odb_read_object_info(data->repo->objects, &object, NULL);
+ repl_type = odb_read_object_info(data->repo->objects, oid, NULL);
printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
oid_to_hex(oid), type_name(repl_type));
@@ -185,8 +185,8 @@ static int replace_object_oid(const char *object_ref,
struct strbuf err = STRBUF_INIT;
int res = 0;
- obj_type = oid_object_info(the_repository, object, NULL);
- repl_type = oid_object_info(the_repository, repl, NULL);
+ obj_type = odb_read_object_info(the_repository->objects, object, NULL);
+ repl_type = odb_read_object_info(the_repository->objects, repl, NULL);
if (!force && obj_type != repl_type)
return error(_("Objects must be of the same type.\n"
"'%s' points to a replaced object of type '%s'\n"
@@ -334,7 +334,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
if (repo_get_oid(the_repository, object_ref, &old_oid) < 0)
return error(_("not a valid object name: '%s'"), object_ref);
- type = oid_object_info(the_repository, &old_oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &old_oid, NULL);
if (type < 0)
return error(_("unable to get object type for %s"),
oid_to_hex(&old_oid));
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index ee25d61c802..eed73f5fc0b 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -110,7 +110,8 @@ static off_t get_object_disk_usage(struct object *obj)
off_t size;
struct object_info oi = OBJECT_INFO_INIT;
oi.disk_sizep = &size;
- if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid));
return size;
}
@@ -346,7 +347,8 @@ static void show_commit(struct commit *commit, void *data)
static int finish_object(struct object *obj, const char *name, void *cb_data)
{
struct rev_list_info *info = cb_data;
- if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, NULL, 0) < 0) {
finish_object__ma(obj, name);
return 1;
}
diff --git a/builtin/tag.c b/builtin/tag.c
index cf2ea4b4993..e0b27396c6b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -304,7 +304,7 @@ static void create_tag(const struct object_id *object, const char *object_ref,
struct strbuf header = STRBUF_INIT;
int should_edit;
- type = oid_object_info(the_repository, object, NULL);
+ type = odb_read_object_info(the_repository->objects, object, NULL);
if (type <= OBJ_NONE)
die(_("bad object type."));
@@ -401,7 +401,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
}
strbuf_addstr(sb, " (");
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
switch (type) {
default:
strbuf_addstr(sb, "object of unknown type");
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 7bf395eec84..405e78bc592 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -232,7 +232,7 @@ static int check_object(struct object *obj, enum object_type type,
if (!(obj->flags & FLAG_OPEN)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects, &obj->oid, &size);
if (type != obj->type || type <= 0)
die("object of unexpected type");
obj->flags |= FLAG_WRITTEN;
diff --git a/commit-graph.c b/commit-graph.c
index cd34b71d270..84cfaf87639 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1862,7 +1862,7 @@ static int add_ref_to_set(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) == OBJ_COMMIT)
oidset_insert(data->commits, oid);
display_progress(data->progress, oidset_size(data->commits));
diff --git a/commit.c b/commit.c
index aa65183d8b6..d4aa9c7a5f8 100644
--- a/commit.c
+++ b/commit.c
@@ -585,7 +585,8 @@ int repo_parse_commit_internal(struct repository *r,
return 0;
}
- if (oid_object_info_extended(r, &item->object.oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(r->objects, &item->object.oid,
+ &oi, flags) < 0)
return quiet_on_missing ? -1 :
error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/diff.c b/diff.c
index 193da8bee68..75cfedf18a5 100644
--- a/diff.c
+++ b/diff.c
@@ -4230,14 +4230,14 @@ int diff_populate_filespec(struct repository *r,
info.contentp = &s->data;
if (options && options->missing_object_cb) {
- if (!oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_SKIP_FETCH_OBJECT))
+ if (!odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_SKIP_FETCH_OBJECT))
goto object_read;
options->missing_object_cb(options->missing_object_data);
}
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
object_read:
@@ -4252,8 +4252,8 @@ int diff_populate_filespec(struct repository *r,
}
if (!info.contentp) {
info.contentp = &s->data;
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
}
s->should_free = 1;
@@ -7019,8 +7019,8 @@ void diff_add_if_missing(struct repository *r,
{
if (filespec && filespec->oid_valid &&
!S_ISGITLINK(filespec->mode) &&
- oid_object_info_extended(r, &filespec->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(r->objects, &filespec->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(to_fetch, &filespec->oid);
}
diff --git a/fetch-pack.c b/fetch-pack.c
index 47fa7fa4c49..0f5de1c94d1 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -149,8 +149,8 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
}
while (1) {
- if (oid_object_info_extended(the_repository, oid, &info,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
return NULL;
if (type == OBJ_TAG) {
struct tag *tag = (struct tag *)
diff --git a/list-objects-filter.c b/list-objects-filter.c
index cb9c16734b1..ec7aebaffd0 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -310,7 +310,7 @@ static enum list_objects_filter_result filter_blobs_limit(
assert(obj->type == OBJ_BLOB);
assert((obj->flags & SEEN) == 0);
- t = oid_object_info(r, &obj->oid, &object_length);
+ t = odb_read_object_info(r->objects, &obj->oid, &object_length);
if (t != OBJ_BLOB) { /* probably OBJ_NONE */
/*
* We DO NOT have the blob locally, so we cannot
diff --git a/log-tree.c b/log-tree.c
index 1d05dc1c701..233bf9f227c 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -176,7 +176,7 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
return 0;
}
- objtype = oid_object_info(the_repository, oid, NULL);
+ objtype = odb_read_object_info(the_repository->objects, oid, NULL);
if (objtype < 0)
return 0;
obj = lookup_object_by_type(the_repository, oid, objtype);
diff --git a/merge-ort.c b/merge-ort.c
index f86c84635f0..5d4501085e9 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -4374,8 +4374,8 @@ static void prefetch_for_content_merges(struct merge_options *opt,
if ((ci->filemask & side_mask) &&
S_ISREG(vi->mode) &&
- oid_object_info_extended(opt->repo, &vi->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(opt->repo->objects, &vi->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&to_fetch, &vi->oid);
}
}
diff --git a/object-file.c b/object-file.c
index 9e8649135ce..d5f41cb73a2 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1211,7 +1211,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
oi.typep = &type;
oi.sizep = &len;
oi.contentp = &buf;
- if (oid_object_info_extended(the_repository, oid, &oi, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &oi, 0))
return error(_("cannot read object for %s"), oid_to_hex(oid));
if (compat) {
if (repo_oid_to_algop(repo, oid, compat, &compat_oid))
diff --git a/object-file.h b/object-file.h
index e4810eee449..86920bd4bb8 100644
--- a/object-file.h
+++ b/object-file.h
@@ -8,7 +8,7 @@
struct index_state;
/*
- * Set this to 0 to prevent oid_object_info_extended() from fetching missing
+ * Set this to 0 to prevent odb_read_object_info_extended() from fetching missing
* blobs. This has a difference only if extensions.partialClone is set.
*
* Its default value is 1.
diff --git a/object-name.c b/object-name.c
index 2b757eb7948..973548d8923 100644
--- a/object-name.c
+++ b/object-name.c
@@ -251,7 +251,7 @@ static int disambiguate_commit_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_COMMIT;
}
@@ -262,7 +262,7 @@ static int disambiguate_committish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -279,7 +279,7 @@ static int disambiguate_tree_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_TREE;
}
@@ -290,7 +290,7 @@ static int disambiguate_treeish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_TREE || kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -307,7 +307,7 @@ static int disambiguate_blob_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_BLOB;
}
@@ -399,7 +399,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
return 0;
hash = repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV);
- type = oid_object_info(ds->repo, oid, NULL);
+ type = odb_read_object_info(ds->repo->objects, oid, NULL);
if (type < 0) {
/*
@@ -514,8 +514,8 @@ static int sort_ambiguous(const void *va, const void *vb, void *ctx)
{
struct repository *sort_ambiguous_repo = ctx;
const struct object_id *a = va, *b = vb;
- int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
- int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
+ int a_type = odb_read_object_info(sort_ambiguous_repo->objects, a, NULL);
+ int b_type = odb_read_object_info(sort_ambiguous_repo->objects, b, NULL);
int a_type_sort;
int b_type_sort;
diff --git a/object.c b/object.c
index 3b15469139d..868d89eed42 100644
--- a/object.c
+++ b/object.c
@@ -214,7 +214,7 @@ enum peel_status peel_object(struct repository *r,
struct object *o = lookup_unknown_object(r, name);
if (o->type == OBJ_NONE) {
- int type = oid_object_info(r, name, NULL);
+ int type = odb_read_object_info(r->objects, name, NULL);
if (type < 0 || !object_as_type(o, type, 0))
return PEEL_INVALID;
}
@@ -315,7 +315,7 @@ struct object *parse_object_with_flags(struct repository *r,
}
if ((!obj || obj->type == OBJ_BLOB) &&
- oid_object_info(r, oid, NULL) == OBJ_BLOB) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
if (!skip_hash && stream_object_signature(r, repl) < 0) {
error(_("hash mismatch %s"), oid_to_hex(oid));
return NULL;
@@ -331,7 +331,7 @@ struct object *parse_object_with_flags(struct repository *r,
*/
if (skip_hash && discard_tree &&
(!obj || obj->type == OBJ_TREE) &&
- oid_object_info(r, oid, NULL) == OBJ_TREE) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_TREE) {
return &lookup_tree(r, oid)->object;
}
diff --git a/odb.c b/odb.c
index c150c01db4a..3d5d4ff8454 100644
--- a/odb.c
+++ b/odb.c
@@ -647,7 +647,7 @@ static int register_all_submodule_alternates(struct object_database *odb)
return ret;
}
-static int do_oid_object_info_extended(struct repository *r,
+static int do_oid_object_info_extended(struct object_database *odb,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
{
@@ -660,7 +660,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
- real = lookup_replace_object(r, oid);
+ real = lookup_replace_object(odb->repo, oid);
if (is_null_oid(real))
return -1;
@@ -668,7 +668,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (!oi)
oi = &blank_oi;
- co = find_cached_object(r->objects, real);
+ co = find_cached_object(odb, real);
if (co) {
if (oi->typep)
*(oi->typep) = co->type;
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, r->hash_algo);
+ oidclr(oi->delta_base_oid, odb->repo->hash_algo);
if (oi->type_name)
strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
@@ -687,17 +687,17 @@ static int do_oid_object_info_extended(struct repository *r,
}
while (1) {
- if (find_pack_entry(r, real, &e))
+ if (find_pack_entry(odb->repo, real, &e))
break;
/* Most likely it's a loose object. */
- if (!loose_object_info(r, real, oi, flags))
+ if (!loose_object_info(odb->repo, real, oi, flags))
return 0;
/* Not a loose object; someone else may have just packed it. */
if (!(flags & OBJECT_INFO_QUICK)) {
- reprepare_packed_git(r);
- if (find_pack_entry(r, real, &e))
+ reprepare_packed_git(odb->repo);
+ if (find_pack_entry(odb->repo, real, &e))
break;
}
@@ -707,15 +707,15 @@ static int do_oid_object_info_extended(struct repository *r,
* `odb_add_submodule_alternate_by_path()` on that submodule's
* ODB). If any such ODBs exist, register them and try again.
*/
- if (register_all_submodule_alternates(r->objects))
+ if (register_all_submodule_alternates(odb))
/* We added some alternates; retry */
continue;
/* Check if it is a missing object */
- if (fetch_if_missing && repo_has_promisor_remote(r) &&
+ if (fetch_if_missing && repo_has_promisor_remote(odb->repo) &&
!already_retried &&
!(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) {
- promisor_remote_get_direct(r, real, 1);
+ promisor_remote_get_direct(odb->repo, real, 1);
already_retried = 1;
continue;
}
@@ -725,7 +725,7 @@ static int do_oid_object_info_extended(struct repository *r,
if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid))
die(_("replacement %s not found for %s"),
oid_to_hex(real), oid_to_hex(oid));
- if ((p = has_packed_and_bad(r, real)))
+ if ((p = has_packed_and_bad(odb->repo, real)))
die(_("packed object %s (stored in %s) is corrupt"),
oid_to_hex(real), p->pack_name);
}
@@ -738,10 +738,10 @@ static int do_oid_object_info_extended(struct repository *r,
* information below, so return early.
*/
return 0;
- rtype = packed_object_info(r, e.p, e.offset, oi);
+ rtype = packed_object_info(odb->repo, e.p, e.offset, oi);
if (rtype < 0) {
mark_bad_packed_object(e.p, real);
- return do_oid_object_info_extended(r, real, oi, 0);
+ return do_oid_object_info_extended(odb, real, oi, 0);
} else if (oi->whence == OI_PACKED) {
oi->u.packed.offset = e.offset;
oi->u.packed.pack = e.p;
@@ -789,7 +789,7 @@ static int oid_object_info_convert(struct repository *r,
oi = &new_oi;
}
- ret = oid_object_info_extended(r, &oid, oi, flags);
+ ret = odb_read_object_info_extended(r->objects, &oid, oi, flags);
if (ret)
return -1;
if (oi == input_oi)
@@ -839,33 +839,35 @@ static int oid_object_info_convert(struct repository *r,
return ret;
}
-int oid_object_info_extended(struct repository *r, const struct object_id *oid,
- struct object_info *oi, unsigned flags)
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
{
int ret;
- if (oid->algo && (hash_algo_by_ptr(r->hash_algo) != oid->algo))
- return oid_object_info_convert(r, oid, oi, flags);
+ if (oid->algo && (hash_algo_by_ptr(odb->repo->hash_algo) != oid->algo))
+ return oid_object_info_convert(odb->repo, oid, oi, flags);
obj_read_lock();
- ret = do_oid_object_info_extended(r, oid, oi, flags);
+ ret = do_oid_object_info_extended(odb, oid, oi, flags);
obj_read_unlock();
return ret;
}
/* returns enum object_type or negative */
-int oid_object_info(struct repository *r,
- const struct object_id *oid,
- unsigned long *sizep)
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep)
{
enum object_type type;
struct object_info oi = OBJECT_INFO_INIT;
oi.typep = &type;
oi.sizep = sizep;
- if (oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(odb, oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE) < 0)
return -1;
return type;
}
@@ -896,7 +898,7 @@ int pretend_object_file(struct repository *repo,
/*
* This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call oid_object_info_extended() and give
+ * deal with them should arrange to call odb_read_object_info_extended() and give
* error messages themselves.
*/
void *repo_read_object_file(struct repository *r,
@@ -911,7 +913,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (oid_object_info_extended(r, oid, &oi, flags))
+ if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
return NULL;
return data;
@@ -977,13 +979,13 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(odb->repo, oid, NULL);
+ enum object_type type = odb_read_object_info(odb, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index ef8a8a544b2..d75a5f9d44b 100644
--- a/odb.h
+++ b/odb.h
@@ -254,9 +254,6 @@ void *repo_read_object_file(struct repository *r,
enum object_type *type,
unsigned long *size);
-/* Read and unpack an object file into memory, write memory to an object file */
-int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
-
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -328,9 +325,24 @@ struct object_info {
/* Die if object corruption (not just an object being missing) was detected. */
#define OBJECT_INFO_DIE_IF_CORRUPT 32
-int oid_object_info_extended(struct repository *r,
- const struct object_id *,
- struct object_info *, unsigned flags);
+/*
+ * Read object info from the object database and populate the `object_info`
+ * structure. Returns 0 on success, a negative error code otherwise.
+ */
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags);
+
+/*
+ * Read a subset of object info for the given object ID. Returns an `enum
+ * object_type` on success, a negative error code otherwise. If successful and
+ * `sizep` is non-NULL, then the size of the object will be written to the
+ * pointer.
+ */
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep);
enum {
/* Retry packed storage after checking packed and loose storage */
@@ -352,7 +364,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: repo_read_object_file(),
- * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
+ * read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -360,7 +372,7 @@ void odb_assert_oid_type(struct object_database *odb,
* reading functions. However, beware that in these cases zlib inflation won't
* be performed in parallel, losing performance.
*
- * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
+ * TODO: odb_read_object_info_extended()'s call stack has a recursive behavior. If
* any of its callees end up calling it, this recursive call won't benefit from
* parallel inflation.
*/
@@ -408,4 +420,22 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
+/* Compatibility wrappers, to be removed once Git 2.50 has been released. */
+#include "repository.h"
+
+static inline int oid_object_info_extended(struct repository *r,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
+{
+ return odb_read_object_info_extended(r->objects, oid, oi, flags);
+}
+
+static inline int oid_object_info(struct repository *r,
+ const struct object_id *oid,
+ unsigned long *sizep)
+{
+ return odb_read_object_info(r->objects, oid, sizep);
+}
+
#endif /* ODB_H */
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index c847369eaaa..c5183b619c1 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -144,8 +144,8 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
break;
default:
- real_type = oid_object_info(writer->to_pack->repo,
- &entry->idx.oid, NULL);
+ real_type = odb_read_object_info(writer->to_pack->repo->objects,
+ &entry->idx.oid, NULL);
break;
}
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 467a3e91035..0bd6f1c282f 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1868,8 +1868,8 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
size_t eindex_pos = pos - bitmap_num_objects_total(bitmap_git);
struct eindex *eindex = &bitmap_git->ext_index;
struct object *obj = eindex->objects[eindex_pos];
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects, &obj->oid,
+ &oi, 0) < 0)
die(_("unable to get size of %s"), oid_to_hex(&obj->oid));
}
@@ -3220,8 +3220,8 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)
i)))
continue;
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of '%s'"),
oid_to_hex(&obj->oid));
diff --git a/packfile.c b/packfile.c
index ab9628eb3d4..2f022265a5b 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1310,7 +1310,7 @@ static int retry_bad_packed_offset(struct repository *r,
return OBJ_BAD;
nth_packed_object_id(&oid, p, pack_pos_to_index(p, pos));
mark_bad_packed_object(p, &oid);
- type = oid_object_info(r, &oid, NULL);
+ type = odb_read_object_info(r->objects, &oid, NULL);
if (type <= OBJ_NONE)
return OBJ_BAD;
return type;
@@ -1843,7 +1843,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
oi.typep = &type;
oi.sizep = &base_size;
oi.contentp = &base;
- if (oid_object_info_extended(r, &base_oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(r->objects, &base_oid,
+ &oi, 0) < 0)
base = NULL;
external_base = base;
diff --git a/promisor-remote.c b/promisor-remote.c
index 2baa286bfd0..be6f82d12f8 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -245,8 +245,8 @@ static int remove_fetched_oids(struct repository *repo,
struct object_id *new_oids;
for (i = 0; i < oid_nr; i++)
- if (oid_object_info_extended(repo, &old_oids[i], NULL,
- OBJECT_INFO_SKIP_FETCH_OBJECT)) {
+ if (odb_read_object_info_extended(repo->objects, &old_oids[i], NULL,
+ OBJECT_INFO_SKIP_FETCH_OBJECT)) {
remaining[i] = 1;
remaining_nr++;
}
diff --git a/protocol-caps.c b/protocol-caps.c
index 3022f69a1bd..ecdd0dc58d5 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -64,7 +64,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
strbuf_addstr(&send_buffer, oid_str);
if (info->size) {
- if (oid_object_info(r, &oid, &object_size) < 0) {
+ if (odb_read_object_info(r->objects, &oid, &object_size) < 0) {
strbuf_addstr(&send_buffer, " ");
} else {
strbuf_addf(&send_buffer, " %lu", object_size);
diff --git a/reachable.c b/reachable.c
index 9dc748f0b9a..e984b68a0c4 100644
--- a/reachable.c
+++ b/reachable.c
@@ -211,7 +211,7 @@ static void add_recent_object(const struct object_id *oid,
* later processing, and the revision machinery expects
* commits and tags to have been parsed.
*/
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0)
die("unable to get object info for %s", oid_to_hex(oid));
diff --git a/read-cache.c b/read-cache.c
index dce1056ec7c..be664f857b4 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3758,9 +3758,9 @@ void prefetch_cache_entries(const struct index_state *istate,
if (S_ISGITLINK(ce->ce_mode) || !must_prefetch(ce))
continue;
- if (!oid_object_info_extended(the_repository, &ce->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &ce->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &ce->oid);
}
diff --git a/ref-filter.c b/ref-filter.c
index 4ce45440ad1..f9f2c512a8c 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2302,8 +2302,8 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
oi->info.sizep = &oi->size;
oi->info.typep = &oi->type;
}
- if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(the_repository->objects, &oi->oid, &oi->info,
+ OBJECT_INFO_LOOKUP_REPLACE))
return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
oid_to_hex(&oi->oid), ref->refname);
if (oi->info.disk_sizep && oi->disk_size < 0)
diff --git a/remote.c b/remote.c
index 17a842f5684..72c36239d31 100644
--- a/remote.c
+++ b/remote.c
@@ -1182,7 +1182,7 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
BUG("'%s' is not a valid object, "
"match_explicit_lhs() should catch this!",
matched_src_name);
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type == OBJ_COMMIT) {
advise(_("The <src> part of the refspec is a commit object.\n"
"Did you mean to create a new branch by pushing to\n"
@@ -1412,7 +1412,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
continue; /* not a tag */
if (string_list_has_string(&dst_tag, ref->name))
continue; /* they already have it */
- if (oid_object_info(the_repository, &ref->new_oid, NULL) != OBJ_TAG)
+ if (odb_read_object_info(the_repository->objects,
+ &ref->new_oid, NULL) != OBJ_TAG)
continue; /* be conservative */
item = string_list_append(&src_tag, ref->name);
item->util = ref;
diff --git a/sequencer.c b/sequencer.c
index 35f4e68d59f..bb012a4bfd9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5502,9 +5502,8 @@ int sequencer_pick_revisions(struct repository *r,
if (!repo_get_oid(r, name, &oid)) {
if (!lookup_commit_reference_gently(r, &oid, 1)) {
- enum object_type type = oid_object_info(r,
- &oid,
- NULL);
+ enum object_type type = odb_read_object_info(r->objects,
+ &oid, NULL);
res = error(_("%s: can't cherry-pick a %s"),
name, type_name(type));
goto out;
diff --git a/streaming.c b/streaming.c
index 29cc877f22a..032f134dc10 100644
--- a/streaming.c
+++ b/streaming.c
@@ -44,7 +44,7 @@ struct git_istream {
union {
struct {
- char *buf; /* from oid_object_info_extended() */
+ char *buf; /* from odb_read_object_info_extended() */
unsigned long read_ptr;
} incore;
@@ -403,8 +403,8 @@ static int open_istream_incore(struct git_istream *st, struct repository *r,
oi.typep = type;
oi.sizep = &st->size;
oi.contentp = (void **)&st->u.incore.buf;
- return oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_DIE_IF_CORRUPT);
+ return odb_read_object_info_extended(r->objects, oid, &oi,
+ OBJECT_INFO_DIE_IF_CORRUPT);
}
/*****************************************************************************
@@ -422,7 +422,7 @@ static int istream_source(struct git_istream *st,
oi.typep = type;
oi.sizep = &size;
- status = oid_object_info_extended(r, oid, &oi, 0);
+ status = odb_read_object_info_extended(r->objects, oid, &oi, 0);
if (status < 0)
return status;
diff --git a/submodule.c b/submodule.c
index 788c9e55ed3..f8373a9ea7d 100644
--- a/submodule.c
+++ b/submodule.c
@@ -968,7 +968,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
return 0;
}
- type = oid_object_info(&subrepo, oid, NULL);
+ type = odb_read_object_info(subrepo.objects, oid, NULL);
switch (type) {
case OBJ_COMMIT:
@@ -1752,8 +1752,7 @@ static int fetch_start_failure(struct strbuf *err UNUSED,
static int commit_missing_in_sub(const struct object_id *oid, void *data)
{
struct repository *subrepo = data;
-
- enum object_type type = oid_object_info(subrepo, oid, NULL);
+ enum object_type type = odb_read_object_info(subrepo->objects, oid, NULL);
return type != OBJ_COMMIT;
}
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index dba227259a2..d8488007493 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -23,7 +23,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
die("could not init repo");
if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
die("could not parse oid");
- if (oid_object_info_extended(&r, &oid, &oi, 0))
+ if (odb_read_object_info_extended(r.objects, &oid, &oi, 0))
die("could not obtain object info");
printf("%d\n", (int) size);
diff --git a/tag.c b/tag.c
index 5f6868bf7b1..144048fd5e0 100644
--- a/tag.c
+++ b/tag.c
@@ -52,7 +52,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
unsigned long size;
int ret;
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type != OBJ_TAG)
return error("%s: cannot verify a non-tag object of type %s.",
name_to_report ?
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 14/17] odb: rename `repo_read_object_file()`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (12 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 15/17] odb: rename `has_object()` Patrick Steinhardt
` (3 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
Rename `repo_read_object_file()` to `odb_read_object()` to match other
functions related to the object database and our modern coding
guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 10 +++++-----
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 6 +++---
blame.c | 13 ++++++-------
builtin/cat-file.c | 26 +++++++++++---------------
builtin/difftool.c | 2 +-
builtin/fast-export.c | 6 +++---
builtin/fast-import.c | 8 ++++----
builtin/grep.c | 8 ++++----
builtin/index-pack.c | 8 ++++----
builtin/log.c | 2 +-
builtin/merge-tree.c | 12 ++++++------
builtin/mktag.c | 4 ++--
builtin/notes.c | 6 +++---
builtin/pack-objects.c | 30 +++++++++++++++---------------
builtin/tag.c | 4 ++--
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 4 ++--
bundle.c | 2 +-
combine-diff.c | 2 +-
commit.c | 6 +++---
config.c | 2 +-
dir.c | 2 +-
entry.c | 4 ++--
fmt-merge-msg.c | 4 ++--
fsck.c | 2 +-
grep.c | 4 ++--
http-push.c | 4 ++--
mailmap.c | 2 +-
match-trees.c | 4 ++--
merge-blobs.c | 8 ++++----
merge-ort.c | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 13 +++++++------
object.c | 2 +-
odb.c | 19 +++++++------------
odb.h | 29 +++++++++++++++++++++++------
read-cache.c | 6 +++---
reflog.c | 4 ++--
rerere.c | 5 ++---
submodule-config.c | 4 ++--
tag.c | 6 +++---
tree-walk.c | 6 +++---
tree.c | 4 ++--
xdiff-interface.c | 2 +-
47 files changed, 157 insertions(+), 150 deletions(-)
diff --git a/apply.c b/apply.c
index 879f04df31e..56cd0540350 100644
--- a/apply.c
+++ b/apply.c
@@ -3210,8 +3210,8 @@ static int apply_binary(struct apply_state *state,
unsigned long size;
char *result;
- result = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ result = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!result)
return error(_("the necessary postimage %s for "
"'%s' cannot be read"),
@@ -3273,8 +3273,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
unsigned long sz;
char *result;
- result = repo_read_object_file(the_repository, oid, &type,
- &sz);
+ result = odb_read_object(the_repository->objects, oid,
+ &type, &sz);
if (!result)
return -1;
/* XXX read_sha1_file NUL-terminates */
@@ -3503,7 +3503,7 @@ static int resolve_to(struct image *image, const struct object_id *result_id)
image_clear(image);
- data = repo_read_object_file(the_repository, result_id, &type, &size);
+ data = odb_read_object(the_repository->objects, result_id, &type, &size);
if (!data || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(result_id));
strbuf_attach(&image->buf, data, size, size + 1);
diff --git a/archive.c b/archive.c
index f2511d530d5..f5a9d45c8d3 100644
--- a/archive.c
+++ b/archive.c
@@ -98,7 +98,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
(args->tree ? &args->tree->object.oid : NULL), oid);
path += args->baselen;
- buffer = repo_read_object_file(the_repository, oid, type, sizep);
+ buffer = odb_read_object(the_repository->objects, oid, type, sizep);
if (buffer && S_ISREG(mode)) {
struct strbuf buf = STRBUF_INIT;
size_t size = 0;
diff --git a/attr.c b/attr.c
index e5680db7f65..d1daeb0b4d9 100644
--- a/attr.c
+++ b/attr.c
@@ -779,7 +779,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
if (get_tree_entry(istate->repo, tree_oid, path, &oid, &mode))
return NULL;
- buf = repo_read_object_file(istate->repo, &oid, &type, &sz);
+ buf = odb_read_object(istate->repo->objects, &oid, &type, &sz);
if (!buf || type != OBJ_BLOB) {
free(buf);
return NULL;
diff --git a/bisect.c b/bisect.c
index a7939216d00..f24474542ec 100644
--- a/bisect.c
+++ b/bisect.c
@@ -155,9 +155,9 @@ static void show_list(const char *debug, int counted, int nr,
unsigned commit_flags = commit->object.flags;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository,
- &commit->object.oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects,
+ &commit->object.oid, &type,
+ &size);
const char *subject_start;
int subject_len;
diff --git a/blame.c b/blame.c
index 97db3355af4..858d2d74df9 100644
--- a/blame.c
+++ b/blame.c
@@ -1041,9 +1041,9 @@ static void fill_origin_blob(struct diff_options *opt,
&o->blob_oid, 1, &file->ptr, &file_size))
;
else
- file->ptr = repo_read_object_file(the_repository,
- &o->blob_oid, &type,
- &file_size);
+ file->ptr = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &file_size);
file->size = file_size;
if (!file->ptr)
@@ -2869,10 +2869,9 @@ void setup_scoreboard(struct blame_scoreboard *sb,
&sb->final_buf_size))
;
else
- sb->final_buf = repo_read_object_file(the_repository,
- &o->blob_oid,
- &type,
- &sb->final_buf_size);
+ sb->final_buf = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &sb->final_buf_size);
if (!sb->final_buf)
die(_("cannot read blob %s for path %s"),
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index da172155c85..d6b9afca06e 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -74,7 +74,7 @@ static int filter_object(const char *path, unsigned mode,
{
enum object_type type;
- *buf = repo_read_object_file(the_repository, oid, &type, size);
+ *buf = odb_read_object(the_repository->objects, oid, &type, size);
if (!*buf)
return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path);
@@ -206,8 +206,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
ret = stream_blob(&oid);
goto cleanup;
}
- buf = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!buf)
die("Cannot read object %s", obj_name);
@@ -228,10 +228,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
struct object_id blob_oid;
if (odb_read_object_info(the_repository->objects,
&oid, NULL) == OBJ_TAG) {
- char *buffer = repo_read_object_file(the_repository,
- &oid,
- &type,
- &size);
+ char *buffer = odb_read_object(the_repository->objects,
+ &oid, &type, &size);
const char *target;
if (!buffer)
@@ -412,10 +410,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
if (!textconv_object(the_repository,
data->rest, 0100644, oid,
1, &contents, &size))
- contents = repo_read_object_file(the_repository,
- oid,
- &type,
- &size);
+ contents = odb_read_object(the_repository->objects,
+ oid, &type, &size);
if (!contents)
die("could not convert '%s' %s",
oid_to_hex(oid), data->rest);
@@ -432,8 +428,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
unsigned long size;
void *contents;
- contents = repo_read_object_file(the_repository, oid, &type,
- &size);
+ contents = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!contents)
die("object %s disappeared", oid_to_hex(oid));
@@ -542,8 +538,8 @@ static void batch_object_write(const char *obj_name,
size_t s = data->size;
char *buf = NULL;
- buf = repo_read_object_file(the_repository, &data->oid, &data->type,
- &data->size);
+ buf = odb_read_object(the_repository->objects, &data->oid,
+ &data->type, &data->size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&data->oid));
buf = replace_idents_using_mailmap(buf, &s);
diff --git a/builtin/difftool.c b/builtin/difftool.c
index fac613e3bc3..e4bc1f83169 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -320,7 +320,7 @@ static char *get_symlink(struct repository *repo,
} else {
enum object_type type;
unsigned long size;
- data = repo_read_object_file(repo, oid, &type, &size);
+ data = odb_read_object(repo->objects, oid, &type, &size);
if (!data)
die(_("could not read object %s for symlink %s"),
oid_to_hex(oid), path);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 6c93cf0a8aa..33f304dd0ad 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -323,7 +323,7 @@ static void export_blob(const struct object_id *oid)
object = (struct object *)lookup_blob(the_repository, oid);
eaten = 0;
} else {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
die("could not read blob %s", oid_to_hex(oid));
if (check_object_signature(the_repository, oid, buf, size,
@@ -869,8 +869,8 @@ static void handle_tag(const char *name, struct tag *tag)
return;
}
- buf = repo_read_object_file(the_repository, &tag->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &tag->object.oid,
+ &type, &size);
if (!buf)
die("could not read tag %s", oid_to_hex(&tag->object.oid));
message = memmem(buf, size, "\n\n", 2);
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 2718376f2c9..1973c504e25 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1265,7 +1265,7 @@ static void load_tree(struct tree_entry *root)
die("Can't load tree %s", oid_to_hex(oid));
} else {
enum object_type type;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_TREE)
die("Can't load tree %s", oid_to_hex(oid));
}
@@ -3002,7 +3002,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
char *buf;
if (!oe || oe->pack_id == MAX_PACK_ID) {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
} else {
type = oe->type;
buf = gfi_unpack_entry(oe, &size);
@@ -3110,8 +3110,8 @@ static struct object_entry *dereference(struct object_entry *oe,
buf = gfi_unpack_entry(oe, &size);
} else {
enum object_type unused;
- buf = repo_read_object_file(the_repository, oid, &unused,
- &size);
+ buf = odb_read_object(the_repository->objects, oid,
+ &unused, &size);
}
if (!buf)
die("Can't load object %s", oid_to_hex(oid));
diff --git a/builtin/grep.c b/builtin/grep.c
index 311c940aa9e..f84298af0f6 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -573,8 +573,8 @@ static int grep_cache(struct grep_opt *opt,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository, &ce->oid,
- &type, &size);
+ data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &size);
if (!data)
die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
init_tree_desc(&tree, &ce->oid, data, size);
@@ -666,8 +666,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository,
- &entry.oid, &type, &size);
+ data = odb_read_object(the_repository->objects,
+ &entry.oid, &type, &size);
if (!data)
die(_("unable to read tree (%s)"),
oid_to_hex(&entry.oid));
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 82cf80b89d1..d33392cab65 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -914,8 +914,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
- has_data = repo_read_object_file(the_repository, oid,
- &has_type, &has_size);
+ has_data = odb_read_object(the_repository->objects, oid,
+ &has_type, &has_size);
read_unlock();
if (!data)
data = new_data = get_data_from_pack(obj_entry);
@@ -1515,8 +1515,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue;
- data = repo_read_object_file(the_repository, &d->oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &d->oid,
+ &type, &size);
if (!data)
continue;
diff --git a/builtin/log.c b/builtin/log.c
index fe9cc5ebecb..f2040b18159 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -714,7 +714,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
unsigned long offset = 0;
if (!buf)
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 709ae3966a6..21fb0b2df1d 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -75,9 +75,9 @@ static void *result(struct merge_list *entry, unsigned long *size)
const char *path = entry->path;
if (!entry->stage)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid, &type,
- size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid, &type,
+ size);
base = NULL;
if (entry->stage == 1) {
base = entry->blob;
@@ -100,9 +100,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)
enum object_type type;
while (entry) {
if (entry->stage == 2)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid,
+ &type, size);
entry = entry->link;
}
return NULL;
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 1809b38f937..1b391119de8 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -54,8 +54,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
void *buffer;
const struct object_id *repl;
- buffer = repo_read_object_file(the_repository, tagged_oid, &type,
- &size);
+ buffer = odb_read_object(the_repository->objects, tagged_oid,
+ &type, &size);
if (!buffer)
die(_("could not read tagged object '%s'"),
oid_to_hex(tagged_oid));
diff --git a/builtin/notes.c b/builtin/notes.c
index 783d4932ca6..a9529b1696a 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -152,7 +152,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (buf) {
if (size)
write_or_die(fd, buf, size);
@@ -319,7 +319,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
strbuf_init(&msg->buf, 0);
if (repo_get_oid(the_repository, arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
- if (!(value = repo_read_object_file(the_repository, &object, &type, &len)))
+ if (!(value = odb_read_object(the_repository->objects, &object, &type, &len)))
die(_("failed to read object '%s'."), arg);
if (type != OBJ_BLOB) {
strbuf_release(&msg->buf);
@@ -722,7 +722,7 @@ static int append_edit(int argc, const char **argv, const char *prefix,
unsigned long size;
enum object_type type;
struct strbuf buf = STRBUF_INIT;
- char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
+ char *prev_buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!prev_buf)
die(_("unable to read %s"), oid_to_hex(note));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index da35d684081..580a5c1996b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -337,13 +337,13 @@ static void *get_delta(struct object_entry *entry)
void *buf, *base_buf, *delta_buf;
enum object_type type;
- buf = repo_read_object_file(the_repository, &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &entry->idx.oid,
+ &type, &size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
- base_buf = repo_read_object_file(the_repository,
- &DELTA(entry)->idx.oid, &type,
- &base_size);
+ base_buf = odb_read_object(the_repository->objects,
+ &DELTA(entry)->idx.oid, &type,
+ &base_size);
if (!base_buf)
die("unable to read %s",
oid_to_hex(&DELTA(entry)->idx.oid));
@@ -506,9 +506,9 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
&size, NULL)) != NULL)
buf = NULL;
else {
- buf = repo_read_object_file(the_repository,
- &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects,
+ &entry->idx.oid, &type,
+ &size);
if (!buf)
die(_("unable to read %s"),
oid_to_hex(&entry->idx.oid));
@@ -1895,7 +1895,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
/* Did not find one. Either we got a bogus request or
* we need to read and perhaps cache.
*/
- data = repo_read_object_file(the_repository, oid, &type, &size);
+ data = odb_read_object(the_repository->objects, oid, &type, &size);
if (!data)
return NULL;
if (type != OBJ_TREE) {
@@ -2762,9 +2762,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
/* Load data if not already done */
if (!trg->data) {
packing_data_lock(&to_pack);
- trg->data = repo_read_object_file(the_repository,
- &trg_entry->idx.oid, &type,
- &sz);
+ trg->data = odb_read_object(the_repository->objects,
+ &trg_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!trg->data)
die(_("object %s cannot be read"),
@@ -2777,9 +2777,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
}
if (!src->data) {
packing_data_lock(&to_pack);
- src->data = repo_read_object_file(the_repository,
- &src_entry->idx.oid, &type,
- &sz);
+ src->data = odb_read_object(the_repository->objects,
+ &src_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!src->data) {
if (src_entry->preferred_base) {
diff --git a/builtin/tag.c b/builtin/tag.c
index e0b27396c6b..46cbf892e34 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -244,7 +244,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
struct strbuf payload = STRBUF_INIT;
struct strbuf signature = STRBUF_INIT;
- orig = buf = repo_read_object_file(the_repository, oid, &type, &size);
+ orig = buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return;
if (parse_signature(buf, size, &payload, &signature)) {
@@ -407,7 +407,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
strbuf_addstr(sb, "object of unknown type");
break;
case OBJ_COMMIT:
- if ((buf = repo_read_object_file(the_repository, oid, &type, &size))) {
+ if ((buf = odb_read_object(the_repository->objects, oid, &type, &size))) {
subject_len = find_commit_subject(buf, &subject_start);
strbuf_insert(sb, sb->len, subject_start, subject_len);
} else {
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index b92fd4710a9..4360872ae07 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -14,7 +14,7 @@ static char *create_temp_file(struct object_id *oid)
unsigned long size;
int fd;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 405e78bc592..4bc6575a574 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -516,8 +516,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
return;
- base = repo_read_object_file(the_repository, &base_oid, &type,
- &base_size);
+ base = odb_read_object(the_repository->objects, &base_oid,
+ &type, &base_size);
if (!base) {
error("failed to read delta-pack base object %s",
oid_to_hex(&base_oid));
diff --git a/bundle.c b/bundle.c
index c67f85126da..66d0e8eaf0e 100644
--- a/bundle.c
+++ b/bundle.c
@@ -305,7 +305,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
if (revs->max_age == -1 && revs->min_age == -1)
goto out;
- buf = repo_read_object_file(the_repository, &tag->oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &tag->oid, &type, &size);
if (!buf)
goto out;
line = memmem(buf, size, "\ntagger ", 8);
diff --git a/combine-diff.c b/combine-diff.c
index cf23a753407..4ea2dc93c4f 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -325,7 +325,7 @@ static char *grab_blob(struct repository *r,
*size = fill_textconv(r, textconv, df, &blob);
free_filespec(df);
} else {
- blob = repo_read_object_file(r, oid, &type, size);
+ blob = odb_read_object(r->objects, oid, &type, size);
if (!blob)
die(_("unable to read %s"), oid_to_hex(oid));
if (type != OBJ_BLOB)
diff --git a/commit.c b/commit.c
index d4aa9c7a5f8..28ee6b73ae6 100644
--- a/commit.c
+++ b/commit.c
@@ -374,7 +374,7 @@ const void *repo_get_commit_buffer(struct repository *r,
if (!ret) {
enum object_type type;
unsigned long size;
- ret = repo_read_object_file(r, &commit->object.oid, &type, &size);
+ ret = odb_read_object(r->objects, &commit->object.oid, &type, &size);
if (!ret)
die("cannot read commit object %s",
oid_to_hex(&commit->object.oid));
@@ -1275,8 +1275,8 @@ static void handle_signed_tag(const struct commit *parent, struct commit_extra_h
desc = merge_remote_util(parent);
if (!desc || !desc->obj)
return;
- buf = repo_read_object_file(the_repository, &desc->obj->oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &desc->obj->oid,
+ &type, &size);
if (!buf || type != OBJ_TAG)
goto free_return;
if (!parse_signature(buf, size, &payload, &signature))
diff --git a/config.c b/config.c
index 883dd066827..142c37215a8 100644
--- a/config.c
+++ b/config.c
@@ -1942,7 +1942,7 @@ int git_config_from_blob_oid(config_fn_t fn,
unsigned long size;
int ret;
- buf = repo_read_object_file(repo, oid, &type, &size);
+ buf = odb_read_object(repo->objects, oid, &type, &size);
if (!buf)
return error(_("unable to load config blob object '%s'"), name);
if (type != OBJ_BLOB) {
diff --git a/dir.c b/dir.c
index e11342e1366..251dedf1f5e 100644
--- a/dir.c
+++ b/dir.c
@@ -302,7 +302,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
*size_out = 0;
*data_out = NULL;
- data = repo_read_object_file(the_repository, oid, &type, &sz);
+ data = odb_read_object(the_repository->objects, oid, &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return -1;
diff --git a/entry.c b/entry.c
index 75d55038d7c..cae02eb5039 100644
--- a/entry.c
+++ b/entry.c
@@ -93,8 +93,8 @@ void *read_blob_entry(const struct cache_entry *ce, size_t *size)
{
enum object_type type;
unsigned long ul;
- void *blob_data = repo_read_object_file(the_repository, &ce->oid,
- &type, &ul);
+ void *blob_data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &ul);
*size = ul;
if (blob_data) {
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 1a8c972adf3..40174efa3de 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -526,8 +526,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
struct object_id *oid = origins.items[i].util;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository, oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects, oid,
+ &type, &size);
char *origbuf = buf;
unsigned long len = size;
struct signature_check sigc = { NULL };
diff --git a/fsck.c b/fsck.c
index e69baab3af7..23965e1880f 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1293,7 +1293,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
if (oidset_contains(blobs_done, oid))
continue;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
if (is_promisor_object(the_repository, oid))
continue;
diff --git a/grep.c b/grep.c
index dc77e6c4631..932647e4a65 100644
--- a/grep.c
+++ b/grep.c
@@ -1931,8 +1931,8 @@ static int grep_source_load_oid(struct grep_source *gs)
{
enum object_type type;
- gs->buf = repo_read_object_file(gs->repo, gs->identifier, &type,
- &gs->size);
+ gs->buf = odb_read_object(gs->repo->objects, gs->identifier,
+ &type, &gs->size);
if (!gs->buf)
return error(_("'%s': unable to read %s"),
gs->name,
diff --git a/http-push.c b/http-push.c
index d1b1bb23711..9481825abfb 100644
--- a/http-push.c
+++ b/http-push.c
@@ -369,8 +369,8 @@ static void start_put(struct transfer_request *request)
ssize_t size;
git_zstream stream;
- unpacked = repo_read_object_file(the_repository, &request->obj->oid,
- &type, &len);
+ unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
+ &type, &len);
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
/* Set it up */
diff --git a/mailmap.c b/mailmap.c
index b18e74c2110..56c72102d9e 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -196,7 +196,7 @@ int read_mailmap_blob(struct string_list *map, const char *name)
if (repo_get_oid(the_repository, name, &oid) < 0)
return 0;
- buf = repo_read_object_file(the_repository, &oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &oid, &type, &size);
if (!buf)
return error("unable to read mailmap object at %s", name);
if (type != OBJ_BLOB) {
diff --git a/match-trees.c b/match-trees.c
index 4704f95c340..5a8a5c39b04 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -63,7 +63,7 @@ static void *fill_tree_desc_strict(struct repository *r,
enum object_type type;
unsigned long size;
- buffer = repo_read_object_file(r, hash, &type, &size);
+ buffer = odb_read_object(r->objects, hash, &type, &size);
if (!buffer)
die("unable to read tree (%s)", oid_to_hex(hash));
if (type != OBJ_TREE)
@@ -199,7 +199,7 @@ static int splice_tree(struct repository *r,
if (*subpath)
subpath++;
- buf = repo_read_object_file(r, oid1, &type, &sz);
+ buf = odb_read_object(r->objects, oid1, &type, &sz);
if (!buf)
die("cannot read tree %s", oid_to_hex(oid1));
init_tree_desc(&desc, oid1, buf, sz);
diff --git a/merge-blobs.c b/merge-blobs.c
index ba8a3fdfd82..6fc27994171 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -12,8 +12,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
unsigned long size;
enum object_type type;
- buf = repo_read_object_file(the_repository, &obj->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &obj->object.oid,
+ &type, &size);
if (!buf)
return -1;
if (type != OBJ_BLOB) {
@@ -79,8 +79,8 @@ void *merge_blobs(struct index_state *istate, const char *path,
return NULL;
if (!our)
our = their;
- return repo_read_object_file(the_repository, &our->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects, &our->object.oid,
+ &type, size);
}
if (fill_mmfile_blob(&f1, our) < 0)
diff --git a/merge-ort.c b/merge-ort.c
index 5d4501085e9..53417d399c7 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -3624,7 +3624,7 @@ static int read_oid_strbuf(struct merge_options *opt,
void *buf;
enum object_type type;
unsigned long size;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
path, NULL, NULL, NULL,
diff --git a/notes-cache.c b/notes-cache.c
index 344f67762b8..dd56feed6e8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -87,7 +87,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
value_oid = get_note(&c->tree, key_oid);
if (!value_oid)
return NULL;
- value = repo_read_object_file(the_repository, value_oid, &type, &size);
+ value = odb_read_object(the_repository->objects, value_oid, &type, &size);
*outsize = size;
return value;
diff --git a/notes-merge.c b/notes-merge.c
index de6a52e2e7f..586939939f2 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -340,7 +340,7 @@ static void write_note_to_worktree(const struct object_id *obj,
{
enum object_type type;
unsigned long size;
- void *buf = repo_read_object_file(the_repository, note, &type, &size);
+ void *buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!buf)
die("cannot read note %s for object %s",
diff --git a/notes.c b/notes.c
index fc000e501d2..73eb5f00cf5 100644
--- a/notes.c
+++ b/notes.c
@@ -816,15 +816,15 @@ int combine_notes_concatenate(struct object_id *cur_oid,
/* read in both note blob objects */
if (!is_null_oid(new_oid))
- new_msg = repo_read_object_file(the_repository, new_oid,
- &new_type, &new_len);
+ new_msg = odb_read_object(the_repository->objects, new_oid,
+ &new_type, &new_len);
if (!new_msg || !new_len || new_type != OBJ_BLOB) {
free(new_msg);
return 0;
}
if (!is_null_oid(cur_oid))
- cur_msg = repo_read_object_file(the_repository, cur_oid,
- &cur_type, &cur_len);
+ cur_msg = odb_read_object(the_repository->objects, cur_oid,
+ &cur_type, &cur_len);
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
free(cur_msg);
free(new_msg);
@@ -880,7 +880,7 @@ static int string_list_add_note_lines(struct string_list *list,
return 0;
/* read_sha1_file NUL-terminates */
- data = repo_read_object_file(the_repository, oid, &t, &len);
+ data = odb_read_object(the_repository->objects, oid, &t, &len);
if (t != OBJ_BLOB || !data || !len) {
free(data);
return t != OBJ_BLOB || !data;
@@ -1290,7 +1290,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!oid)
return;
- if (!(msg = repo_read_object_file(the_repository, oid, &type, &msglen)) || type != OBJ_BLOB) {
+ if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
+ type != OBJ_BLOB) {
free(msg);
return;
}
diff --git a/object.c b/object.c
index 868d89eed42..c1553ee4330 100644
--- a/object.c
+++ b/object.c
@@ -335,7 +335,7 @@ struct object *parse_object_with_flags(struct repository *r,
return &lookup_tree(r, oid)->object;
}
- buffer = repo_read_object_file(r, oid, &type, &size);
+ buffer = odb_read_object(r->objects, oid, &type, &size);
if (buffer) {
if (!skip_hash &&
check_object_signature(r, repl, buffer, size, type) < 0) {
diff --git a/odb.c b/odb.c
index 3d5d4ff8454..5202f107af2 100644
--- a/odb.c
+++ b/odb.c
@@ -30,7 +30,7 @@ KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -896,15 +896,10 @@ int pretend_object_file(struct repository *repo,
return 0;
}
-/*
- * This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call odb_read_object_info_extended() and give
- * error messages themselves.
- */
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size)
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
{
struct object_info oi = OBJECT_INFO_INIT;
unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT | OBJECT_INFO_LOOKUP_REPLACE;
@@ -913,7 +908,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
+ if (odb_read_object_info_extended(odb, oid, &oi, flags))
return NULL;
return data;
@@ -935,7 +930,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = repo_read_object_file(r, &actual_oid, &type, &isize);
+ buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
diff --git a/odb.h b/odb.h
index d75a5f9d44b..e4a3763914a 100644
--- a/odb.h
+++ b/odb.h
@@ -130,7 +130,7 @@ struct object_database {
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -249,10 +249,19 @@ void odb_add_to_alternates_file(struct object_database *odb,
void odb_add_to_alternates_memory(struct object_database *odb,
const char *dir);
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size);
+/*
+ * Read an object from the database. Returns the object data and assigns object
+ * type and size to the `type` and `size` pointers, if these pointers are
+ * non-NULL. Returns a `NULL` pointer in case the object does not exist.
+ *
+ * This function dies on corrupt objects; the callers who want to deal with
+ * them should arrange to call odb_read_object_info_extended() and give error
+ * messages themselves.
+ */
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size);
/*
* Add an object file to the in-memory object store, without writing it
@@ -363,7 +372,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
- * following functions in parallel: repo_read_object_file(),
+ * following functions in parallel: odb_read_object(),
* read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
@@ -438,4 +447,12 @@ static inline int oid_object_info(struct repository *r,
return odb_read_object_info(r->objects, oid, sizep);
}
+static inline void *repo_read_object_file(struct repository *r,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
+{
+ return odb_read_object(r->objects, oid, type, size);
+}
+
#endif /* ODB_H */
diff --git a/read-cache.c b/read-cache.c
index be664f857b4..46986798a38 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -254,7 +254,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
if (strbuf_readlink(&sb, ce->name, expected_size))
return -1;
- buffer = repo_read_object_file(the_repository, &ce->oid, &type, &size);
+ buffer = odb_read_object(the_repository->objects, &ce->oid, &type, &size);
if (buffer) {
if (size == sb.len)
match = memcmp(buffer, sb.buf, size);
@@ -3514,8 +3514,8 @@ void *read_blob_data_from_index(struct index_state *istate,
}
if (pos < 0)
return NULL;
- data = repo_read_object_file(the_repository, &istate->cache[pos]->oid,
- &type, &sz);
+ data = odb_read_object(the_repository->objects, &istate->cache[pos]->oid,
+ &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return NULL;
diff --git a/reflog.c b/reflog.c
index 4f8a3b717cd..747b82eada8 100644
--- a/reflog.c
+++ b/reflog.c
@@ -140,8 +140,8 @@ static int tree_is_complete(const struct object_id *oid)
if (!tree->buffer) {
enum object_type type;
unsigned long size;
- void *data = repo_read_object_file(the_repository, oid, &type,
- &size);
+ void *data = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!data) {
tree->object.flags |= INCOMPLETE;
return 0;
diff --git a/rerere.c b/rerere.c
index 951e4bf8b41..8bb97c98229 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1000,9 +1000,8 @@ static int handle_cache(struct index_state *istate,
break;
i = ce_stage(ce) - 1;
if (!mmfile[i].ptr) {
- mmfile[i].ptr = repo_read_object_file(the_repository,
- &ce->oid, &type,
- &size);
+ mmfile[i].ptr = odb_read_object(the_repository->objects,
+ &ce->oid, &type, &size);
if (!mmfile[i].ptr)
die(_("unable to read %s"),
oid_to_hex(&ce->oid));
diff --git a/submodule-config.c b/submodule-config.c
index 0f775f93259..2730a47fad1 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -743,8 +743,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
if (submodule)
goto out;
- config = repo_read_object_file(the_repository, &oid, &type,
- &config_size);
+ config = odb_read_object(the_repository->objects, &oid,
+ &type, &config_size);
if (!config || type != OBJ_BLOB)
goto out;
diff --git a/tag.c b/tag.c
index 144048fd5e0..1d52686ee10 100644
--- a/tag.c
+++ b/tag.c
@@ -60,7 +60,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV),
type_name(type));
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return error("%s: unable to read file.",
name_to_report ?
@@ -222,8 +222,8 @@ int parse_tag(struct tag *item)
if (item->object.parsed)
return 0;
- data = repo_read_object_file(the_repository, &item->object.oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!data)
return error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/tree-walk.c b/tree-walk.c
index 34b0fff4873..766af99f466 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -795,9 +795,9 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
*/
retval = DANGLING_SYMLINK;
- contents = repo_read_object_file(r,
- ¤t_tree_oid, &type,
- &link_len);
+ contents = odb_read_object(r->objects,
+ ¤t_tree_oid, &type,
+ &link_len);
if (!contents)
goto done;
diff --git a/tree.c b/tree.c
index 341b7c2ff3f..1ef743d90f4 100644
--- a/tree.c
+++ b/tree.c
@@ -193,8 +193,8 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
if (item->object.parsed)
return 0;
- buffer = repo_read_object_file(the_repository, &item->object.oid,
- &type, &size);
+ buffer = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!buffer)
return quiet_on_missing ? -1 :
error("Could not read %s",
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 01e6e378ea6..0e5d38c9600 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -187,7 +187,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
return;
}
- ptr->ptr = repo_read_object_file(the_repository, oid, &type, &size);
+ ptr->ptr = odb_read_object(the_repository->objects, oid, &type, &size);
if (!ptr->ptr || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
ptr->size = size;
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 15/17] odb: rename `has_object()`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (13 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
` (2 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
Rename `has_object()` to `odb_has_object()` to match other functions
related to the object database and our modern coding guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 2 +-
builtin/backfill.c | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/clone.c | 2 +-
builtin/fetch.c | 17 +++++++++--------
builtin/fsck.c | 2 +-
builtin/index-pack.c | 4 ++--
builtin/pack-objects.c | 4 ++--
builtin/receive-pack.c | 4 ++--
builtin/remote.c | 4 ++--
builtin/show-ref.c | 4 ++--
builtin/unpack-objects.c | 4 ++--
bulk-checkin.c | 4 ++--
cache-tree.c | 15 ++++++++-------
commit-graph.c | 2 +-
commit.c | 2 +-
fetch-pack.c | 8 ++++----
http-push.c | 14 ++++++++------
http-walker.c | 8 ++++----
list-objects.c | 4 ++--
notes.c | 4 ++--
odb.c | 6 +++---
odb.h | 12 ++++++++++--
reflog.c | 2 +-
refs.c | 3 ++-
remote.c | 2 +-
send-pack.c | 2 +-
shallow.c | 12 ++++++------
upload-pack.c | 2 +-
walker.c | 4 ++--
30 files changed, 87 insertions(+), 74 deletions(-)
diff --git a/apply.c b/apply.c
index 56cd0540350..7fb56517649 100644
--- a/apply.c
+++ b/apply.c
@@ -3204,7 +3204,7 @@ static int apply_binary(struct apply_state *state,
return 0; /* deletion patch */
}
- if (has_object(the_repository, &oid, 0)) {
+ if (odb_has_object(the_repository->objects, &oid, 0)) {
/* We already have the postimage */
enum object_type type;
unsigned long size;
diff --git a/builtin/backfill.c b/builtin/backfill.c
index 0b49baa39fa..80056abe473 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -67,8 +67,8 @@ static int fill_missing_blobs(const char *path UNUSED,
return 0;
for (size_t i = 0; i < list->nr; i++) {
- if (!has_object(ctx->repo, &list->oid[i],
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_has_object(ctx->repo->objects, &list->oid[i],
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&ctx->current_batch, &list->oid[i]);
}
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index d6b9afca06e..571b5cc2ad5 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -169,8 +169,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
goto cleanup;
case 'e':
- ret = !has_object(the_repository, &oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
+ ret = !odb_has_object(the_repository->objects, &oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
goto cleanup;
case 'w':
diff --git a/builtin/clone.c b/builtin/clone.c
index 3aabdf6570b..6d08abed37c 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -506,7 +506,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
continue;
if (ends_with(ref->name, "^{}"))
continue;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
refs_update_ref(get_main_ref_store(the_repository), msg,
ref->name, &ref->old_oid, NULL, 0,
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 82e9603ccab..2000299bcc5 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -366,9 +366,9 @@ static void find_non_local_tags(const struct ref *refs,
*/
if (ends_with(ref->name, "^{}")) {
if (item &&
- !has_object(the_repository, &ref->old_oid, 0) &&
+ !odb_has_object(the_repository->objects, &ref->old_oid, 0) &&
!oidset_contains(&fetch_oids, &ref->old_oid) &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
item = NULL;
@@ -382,7 +382,7 @@ static void find_non_local_tags(const struct ref *refs,
* fetch.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -403,7 +403,7 @@ static void find_non_local_tags(const struct ref *refs,
* checked to see if it needs fetching.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -910,8 +910,8 @@ static int update_local_ref(struct ref *ref,
struct commit *current = NULL, *updated;
int fast_forward = 0;
- if (!has_object(the_repository, &ref->new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &ref->new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
if (oideq(&ref->old_oid, &ref->new_oid)) {
@@ -1330,7 +1330,8 @@ static int check_exist_and_connected(struct ref *ref_map)
* we need all direct targets to exist.
*/
for (r = rm; r; r = r->next) {
- if (!has_object(the_repository, &r->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ if (!odb_has_object(the_repository->objects, &r->old_oid,
+ HAS_OBJECT_RECHECK_PACKED))
return -1;
}
@@ -1485,7 +1486,7 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
struct object_id oid;
if (repo_get_oid(the_repository, s, &oid))
die(_("%s is not a valid object"), s);
- if (!has_object(the_repository, &oid, 0))
+ if (!odb_has_object(the_repository->objects, &oid, 0))
die(_("the object %s does not exist"), s);
oid_array_append(oids, &oid);
continue;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 08a79fe044d..74bfa182597 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -161,7 +161,7 @@ static int mark_object(struct object *obj, enum object_type type,
return 0;
if (!(obj->flags & HAS_OBJ)) {
- if (parent && !has_object(the_repository, &obj->oid, 1)) {
+ if (parent && !odb_has_object(the_repository->objects, &obj->oid, 1)) {
printf_ln(_("broken link from %7s %s\n"
" to %7s %s"),
printable_type(&parent->oid, parent->type),
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index d33392cab65..0aa2f099cbe 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -893,8 +893,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (startup_info->have_repository) {
read_lock();
- collision_test_needed = has_object(the_repository, oid,
- HAS_OBJECT_FETCH_PROMISOR);
+ collision_test_needed = odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_FETCH_PROMISOR);
read_unlock();
}
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 580a5c1996b..06bdeb4223b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3968,7 +3968,7 @@ static void show_object__ma_allow_any(struct object *obj, const char *name, void
* Quietly ignore ALL missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0))
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0))
return;
show_object(obj, name, data);
@@ -3982,7 +3982,7 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
* Quietly ignore EXPECTED missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0) &&
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0) &&
is_promisor_object(to_pack.repo, &obj->oid))
return;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 8c157ea7d1b..27684dce3a4 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1508,8 +1508,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
}
if (!is_null_oid(new_oid) &&
- !has_object(the_repository, new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error("unpack should have generated %s, "
"but I can't find it!", oid_to_hex(new_oid));
ret = "bad pack";
diff --git a/builtin/remote.c b/builtin/remote.c
index ac5b8d2a1a6..7cbda285ebe 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -454,8 +454,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
info->status = PUSH_STATUS_UPTODATE;
else if (is_null_oid(&ref->old_oid))
info->status = PUSH_STATUS_CREATE;
- else if (has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ else if (odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
ref_newer(&ref->new_oid, &ref->old_oid))
info->status = PUSH_STATUS_FASTFORWARD;
else
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 90ec1de78f9..117709cb076 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -35,8 +35,8 @@ static void show_one(const struct show_one_options *opts,
const char *hex;
struct object_id peeled;
- if (!has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die("git show-ref: bad ref %s (%s)", refname,
oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 4bc6575a574..a69d59eb50c 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -449,8 +449,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
delta_data = get_data(delta_size);
if (!delta_data)
return;
- if (has_object(the_repository, &base_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &base_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
; /* Ok we have this one */
else if (resolve_against_held(nr, &base_oid,
delta_data, delta_size))
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 55406a539e7..16df86c0ba8 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -130,8 +130,8 @@ static void flush_batch_fsync(void)
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
{
/* The object may already exist in the repository */
- if (has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 1;
/* Might want to keep the list sorted */
diff --git a/cache-tree.c b/cache-tree.c
index 9786b32b3a1..a4bc14ad15c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -239,8 +239,8 @@ int cache_tree_fully_valid(struct cache_tree *it)
if (!it)
return 0;
if (it->entry_count < 0 ||
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
for (i = 0; i < it->subtree_nr; i++) {
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -292,8 +292,8 @@ static int update_one(struct cache_tree *it,
}
if (0 <= it->entry_count &&
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return it->entry_count;
/*
@@ -399,8 +399,9 @@ static int update_one(struct cache_tree *it,
ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
!must_check_existence(ce);
if (is_null_oid(oid) ||
- (!ce_missing_ok && !has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
+ (!ce_missing_ok &&
+ !odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
strbuf_release(&buffer);
if (expected_missing)
return -1;
@@ -448,7 +449,7 @@ static int update_one(struct cache_tree *it,
struct object_id oid;
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
OBJ_TREE, &oid);
- if (has_object(the_repository, &oid, HAS_OBJECT_RECHECK_PACKED))
+ if (odb_has_object(the_repository->objects, &oid, HAS_OBJECT_RECHECK_PACKED))
oidcpy(&it->oid, &oid);
else
to_invalidate = 1;
diff --git a/commit-graph.c b/commit-graph.c
index 84cfaf87639..cb81a5ce228 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1040,7 +1040,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
return NULL;
if (!search_commit_pos_in_graph(id, repo->objects->commit_graph, &pos))
return NULL;
- if (commit_graph_paranoia && !has_object(repo, id, 0))
+ if (commit_graph_paranoia && !odb_has_object(repo->objects, id, 0))
return NULL;
commit = lookup_commit(repo, id);
diff --git a/commit.c b/commit.c
index 28ee6b73ae6..15115125c36 100644
--- a/commit.c
+++ b/commit.c
@@ -575,7 +575,7 @@ int repo_parse_commit_internal(struct repository *r,
if (commit_graph_paranoia == -1)
commit_graph_paranoia = git_env_bool(GIT_COMMIT_GRAPH_PARANOIA, 0);
- if (commit_graph_paranoia && !has_object(r, &item->object.oid, 0)) {
+ if (commit_graph_paranoia && !odb_has_object(r->objects, &item->object.oid, 0)) {
unparse_commit(r, &item->object.oid);
return quiet_on_missing ? -1 :
error(_("commit %s exists in commit-graph but not in the object database"),
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f5de1c94d1..5e74235fc06 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -142,7 +142,7 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
commit = lookup_commit_in_graph(the_repository, oid);
if (commit) {
if (mark_tags_complete_and_check_obj_db) {
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
die_in_commit_graph_only(oid);
}
return commit;
@@ -770,7 +770,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
if (!commit) {
struct object *o;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
o = parse_object(the_repository, &ref->old_oid);
if (!o || o->type != OBJ_COMMIT)
@@ -1984,8 +1984,8 @@ static void update_shallow(struct fetch_pack_args *args,
struct oid_array extra = OID_ARRAY_INIT;
struct object_id *oid = si->shallow->oid;
for (i = 0; i < si->shallow->nr; i++)
- if (has_object(the_repository, &oid[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &oid[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
oid_array_append(&extra, &oid[i]);
if (extra.nr) {
setup_alternate_shallow(&shallow_lock,
diff --git a/http-push.c b/http-push.c
index 9481825abfb..beb41732fb6 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1447,8 +1447,8 @@ static void one_remote_ref(const char *refname)
* may be required for updating server info later.
*/
if (repo->can_update_info_refs &&
- !has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
obj = lookup_unknown_object(the_repository, &ref->old_oid);
fprintf(stderr, " fetch %s for %s\n",
oid_to_hex(&ref->old_oid), refname);
@@ -1653,14 +1653,16 @@ static int delete_remote_branch(const char *pattern, int force)
return error("Remote HEAD symrefs too deep");
if (is_null_oid(&head_oid))
return error("Unable to resolve remote HEAD");
- if (!has_object(the_repository, &head_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &head_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", oid_to_hex(&head_oid));
/* Remote branch must resolve to a known object */
if (is_null_oid(&remote_ref->old_oid))
return error("Unable to resolve remote branch %s",
remote_ref->name);
- if (!has_object(the_repository, &remote_ref->old_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &remote_ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, oid_to_hex(&remote_ref->old_oid));
/* Remote branch must be an ancestor of remote HEAD */
@@ -1881,8 +1883,8 @@ int cmd_main(int argc, const char **argv)
if (!force_all &&
!is_null_oid(&ref->old_oid) &&
!ref->force) {
- if (!has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
+ if (!odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
!ref_newer(&ref->peer_ref->new_oid,
&ref->old_oid)) {
/*
diff --git a/http-walker.c b/http-walker.c
index 4b1cdd25a80..4e7024ebc5f 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -138,8 +138,8 @@ static int fill_active_slot(void *data UNUSED)
list_for_each_safe(pos, tmp, head) {
obj_req = list_entry(pos, struct object_request, node);
if (obj_req->state == WAITING) {
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
obj_req->state = COMPLETE;
else {
start_object_request(obj_req);
@@ -497,8 +497,8 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
if (!obj_req)
return error("Couldn't find request for %s in the queue", hex);
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
if (obj_req->req)
abort_http_object_request(&obj_req->req);
abort_object_request(obj_req);
diff --git a/list-objects.c b/list-objects.c
index c50b9578584..42c17d95739 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -74,8 +74,8 @@ static void process_blob(struct traversal_context *ctx,
* of missing objects.
*/
if (ctx->revs->exclude_promisor_objects &&
- !has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ !odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
is_promisor_object(ctx->revs->repo, &obj->oid))
return;
diff --git a/notes.c b/notes.c
index 73eb5f00cf5..97b995f3f2d 100644
--- a/notes.c
+++ b/notes.c
@@ -794,8 +794,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
struct note_delete_list **l = (struct note_delete_list **) cb_data;
struct note_delete_list *n;
- if (has_object(the_repository, object_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, object_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0; /* nothing to do for this note */
/* failed to find object => prune this note */
diff --git a/odb.c b/odb.c
index 5202f107af2..787611c8f60 100644
--- a/odb.c
+++ b/odb.c
@@ -880,7 +880,7 @@ int pretend_object_file(struct repository *repo,
char *co_buf;
hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (has_object(repo, oid, 0) ||
+ if (odb_has_object(repo->objects, oid, 0) ||
find_cached_object(repo->objects, oid))
return 0;
@@ -962,7 +962,7 @@ void *read_object_with_reference(struct repository *r,
}
}
-int has_object(struct repository *r, const struct object_id *oid,
+int odb_has_object(struct object_database *odb, const struct object_id *oid,
unsigned flags)
{
unsigned object_info_flags = 0;
@@ -974,7 +974,7 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(odb, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
diff --git a/odb.h b/odb.h
index e4a3763914a..3d38f1ebe60 100644
--- a/odb.h
+++ b/odb.h
@@ -364,8 +364,9 @@ enum {
* Returns 1 if the object exists. This function will not lazily fetch objects
* in a partial clone by default.
*/
-int has_object(struct repository *r, const struct object_id *oid,
- unsigned flags);
+int odb_has_object(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned flags);
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect);
@@ -455,4 +456,11 @@ static inline void *repo_read_object_file(struct repository *r,
return odb_read_object(r->objects, oid, type, size);
}
+static inline int has_object(struct repository *r,
+ const struct object_id *oid,
+ unsigned flags)
+{
+ return odb_has_object(r->objects, oid, flags);
+}
+
#endif /* ODB_H */
diff --git a/reflog.c b/reflog.c
index 747b82eada8..39c205fd26e 100644
--- a/reflog.c
+++ b/reflog.c
@@ -152,7 +152,7 @@ static int tree_is_complete(const struct object_id *oid)
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
complete = 1;
while (tree_entry(&desc, &entry)) {
- if (!has_object(the_repository, &entry.oid,
+ if (!odb_has_object(the_repository->objects, &entry.oid,
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
(S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) {
tree->object.flags |= INCOMPLETE;
diff --git a/refs.c b/refs.c
index 82a70b502f8..d6475d5e745 100644
--- a/refs.c
+++ b/refs.c
@@ -376,7 +376,8 @@ int ref_resolves_to_object(const char *refname,
{
if (flags & REF_ISBROKEN)
return 0;
- if (!has_object(repo, oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (!odb_has_object(repo->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error(_("%s does not point to a valid object!"), refname);
return 0;
}
diff --git a/remote.c b/remote.c
index 72c36239d31..5edf2a9f4b2 100644
--- a/remote.c
+++ b/remote.c
@@ -1703,7 +1703,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
if (starts_with(ref->name, "refs/tags/"))
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
- else if (!has_object(the_repository, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ else if (!odb_has_object(the_repository->objects, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||
!lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))
diff --git a/send-pack.c b/send-pack.c
index abca2dd38a7..d029f748232 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -45,7 +45,7 @@ int option_parse_push_signed(const struct option *opt,
static void feed_object(struct repository *r,
const struct object_id *oid, FILE *fh, int negative)
{
- if (negative && !has_object(r, oid, 0))
+ if (negative && !odb_has_object(r->objects, oid, 0))
return;
if (negative)
diff --git a/shallow.c b/shallow.c
index d379756e39a..ef3adb635fd 100644
--- a/shallow.c
+++ b/shallow.c
@@ -310,8 +310,8 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
if (graft->nr_parent != -1)
return 0;
if (data->flags & QUICK) {
- if (!has_object(the_repository, &graft->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &graft->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
} else if (data->flags & SEEN_ONLY) {
struct commit *c = lookup_commit(the_repository, &graft->oid);
@@ -477,8 +477,8 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
ALLOC_ARRAY(info->ours, sa->nr);
ALLOC_ARRAY(info->theirs, sa->nr);
for (size_t i = 0; i < sa->nr; i++) {
- if (has_object(the_repository, sa->oid + i,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, sa->oid + i,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
struct commit_graft *graft;
graft = lookup_commit_graft(the_repository,
&sa->oid[i]);
@@ -515,8 +515,8 @@ void remove_nonexistent_theirs_shallow(struct shallow_info *info)
for (i = dst = 0; i < info->nr_theirs; i++) {
if (i != dst)
info->theirs[dst] = info->theirs[i];
- if (has_object(the_repository, oid + info->theirs[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid + info->theirs[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
dst++;
}
info->nr_theirs = dst;
diff --git a/upload-pack.c b/upload-pack.c
index cec12cb478a..98cda156434 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -509,7 +509,7 @@ static int got_oid(struct upload_pack_data *data,
{
if (get_oid_hex(hex, oid))
die("git upload-pack: expected SHA1 object, got '%s'", hex);
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
return -1;
return do_got_oid(data, oid);
}
diff --git a/walker.c b/walker.c
index a8abe8a2e78..d131af04c7b 100644
--- a/walker.c
+++ b/walker.c
@@ -150,8 +150,8 @@ static int process(struct walker *walker, struct object *obj)
return 0;
obj->flags |= SEEN;
- if (has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
/* We already have it, so we should scan it now. */
obj->flags |= TO_SCAN;
}
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 16/17] odb: rename `pretend_object_file()`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (14 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 15/17] odb: rename `has_object()` Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 14:12 ` [PATCH v2 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
2025-05-09 21:43 ` [PATCH v2 00/17] object-store: carve out the object database subsystem Junio C Hamano
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
Rename `pretend_object_file()` to `odb_pretend_object()` to match other
functions related to the object database and our modern coding
guidelines.
No compatibility wrapper is introduces as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
blame.c | 3 ++-
odb.c | 18 +++++++++---------
odb.h | 6 +++---
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/blame.c b/blame.c
index 858d2d74df9..dce5c8d855c 100644
--- a/blame.c
+++ b/blame.c
@@ -277,7 +277,8 @@ static struct commit *fake_working_tree_commit(struct repository *r,
convert_to_git(r->index, path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
- pretend_object_file(the_repository, buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
+ odb_pretend_object(the_repository->objects, buf.buf, buf.len,
+ OBJ_BLOB, &origin->blob_oid);
/*
* Read the current index, replace the path entry with
diff --git a/odb.c b/odb.c
index 787611c8f60..dfebeb4c8c0 100644
--- a/odb.c
+++ b/odb.c
@@ -872,21 +872,21 @@ int odb_read_object_info(struct object_database *odb,
return type;
}
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid)
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid)
{
struct cached_object_entry *co;
char *co_buf;
- hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (odb_has_object(repo->objects, oid, 0) ||
- find_cached_object(repo->objects, oid))
+ hash_object_file(odb->repo->hash_algo, buf, len, type, oid);
+ if (odb_has_object(odb, oid, 0) ||
+ find_cached_object(odb, oid))
return 0;
- ALLOC_GROW(repo->objects->cached_objects,
- repo->objects->cached_object_nr + 1, repo->objects->cached_object_alloc);
- co = &repo->objects->cached_objects[repo->objects->cached_object_nr++];
+ ALLOC_GROW(odb->cached_objects,
+ odb->cached_object_nr + 1, odb->cached_object_alloc);
+ co = &odb->cached_objects[odb->cached_object_nr++];
co->value.size = len;
co->value.type = type;
co_buf = xmalloc(len);
diff --git a/odb.h b/odb.h
index 3d38f1ebe60..911448f4d42 100644
--- a/odb.h
+++ b/odb.h
@@ -271,9 +271,9 @@ void *odb_read_object(struct object_database *odb,
* object in persistent storage before writing any other new objects
* that reference it.
*/
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid);
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid);
struct object_info {
/* Request */
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v2 17/17] odb: rename `read_object_with_reference()`
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (15 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
@ 2025-05-09 14:12 ` Patrick Steinhardt
2025-05-09 21:43 ` [PATCH v2 00/17] object-store: carve out the object database subsystem Junio C Hamano
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-09 14:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano
Rename `read_object_with_reference()` to `odb_read_object_peeled()` to
match other functions related to the object database and our modern
coding guidelines. Furthermore though, the old name didn't really
describe very well what this function actually does, which is to walk
down any commit and tag objects until an object of the required type has
been found. This is generally referred to as "peeling", so the new name
should be way more descriptive.
No compatibility wrapper is introduces as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Documentation/user-manual.adoc | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/fast-import.c | 19 ++++++++-----------
builtin/grep.c | 9 +++------
builtin/pack-objects.c | 4 ++--
odb.c | 17 +++++++++--------
odb.h | 15 +++++++--------
tree-walk.c | 10 ++++------
8 files changed, 37 insertions(+), 45 deletions(-)
diff --git a/Documentation/user-manual.adoc b/Documentation/user-manual.adoc
index d2b478ad232..e86b2ad9f8a 100644
--- a/Documentation/user-manual.adoc
+++ b/Documentation/user-manual.adoc
@@ -4301,11 +4301,11 @@ Now, for the meat:
-----------------------------------------------------------------------------
case 0:
- buf = read_object_with_reference(sha1, argv[1], &size, NULL);
+ buf = odb_read_object_peeled(r->objects, sha1, argv[1], &size, NULL);
-----------------------------------------------------------------------------
This is how you read a blob (actually, not only a blob, but any type of
-object). To know how the function `read_object_with_reference()` actually
+object). To know how the function `odb_read_object_peeled()` actually
works, find the source code for it (something like `git grep
read_object_with | grep ":[a-z]"` in the Git repository), and read
the source.
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 571b5cc2ad5..ed0fce9b490 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -255,8 +255,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
* fall-back to the usual case.
*/
}
- buf = read_object_with_reference(the_repository, &oid,
- exp_type_id, &size, NULL);
+ buf = odb_read_object_peeled(the_repository->objects, &oid,
+ exp_type_id, &size, NULL);
if (use_mailmap) {
size_t s = size;
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 1973c504e25..b1389c59211 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2535,10 +2535,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
oidcpy(&commit_oid, &commit_oe->idx.oid);
} else if (!repo_get_oid(the_repository, p, &commit_oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &commit_oid,
- OBJ_COMMIT, &size,
- &commit_oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &commit_oid, OBJ_COMMIT, &size,
+ &commit_oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", p);
free(buf);
@@ -2604,9 +2603,8 @@ static void parse_from_existing(struct branch *b)
unsigned long size;
char *buf;
- buf = read_object_with_reference(the_repository,
- &b->oid, OBJ_COMMIT, &size,
- &b->oid);
+ buf = odb_read_object_peeled(the_repository->objects, &b->oid,
+ OBJ_COMMIT, &size, &b->oid);
parse_from_commit(b, buf, size);
free(buf);
}
@@ -2699,10 +2697,9 @@ static struct hash_list *parse_merge(unsigned int *count)
oidcpy(&n->oid, &oe->idx.oid);
} else if (!repo_get_oid(the_repository, from, &n->oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &n->oid,
- OBJ_COMMIT,
- &size, &n->oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &n->oid, OBJ_COMMIT,
+ &size, &n->oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", from);
free(buf);
diff --git a/builtin/grep.c b/builtin/grep.c
index f84298af0f6..7619479ddad 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -522,9 +522,7 @@ static int grep_submodule(struct grep_opt *opt,
obj_read_lock();
object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
- data = read_object_with_reference(subrepo,
- oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(subrepo->objects, oid, OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
@@ -705,9 +703,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
struct strbuf base;
int hit, len;
- data = read_object_with_reference(opt->repo,
- &obj->oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(opt->repo->objects, &obj->oid,
+ OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 06bdeb4223b..e88a13dbb9f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2055,8 +2055,8 @@ static void add_preferred_base(struct object_id *oid)
if (window <= num_preferred_base++)
return;
- data = read_object_with_reference(the_repository, oid,
- OBJ_TREE, &size, &tree_oid);
+ data = odb_read_object_peeled(the_repository->objects, oid,
+ OBJ_TREE, &size, &tree_oid);
if (!data)
return;
diff --git a/odb.c b/odb.c
index dfebeb4c8c0..fd7fe398d2d 100644
--- a/odb.c
+++ b/odb.c
@@ -914,11 +914,11 @@ void *odb_read_object(struct object_database *odb,
return data;
}
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *actual_oid_return)
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *actual_oid_return)
{
enum object_type type;
void *buffer;
@@ -930,7 +930,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
+ buffer = odb_read_object(odb, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
@@ -950,9 +950,10 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + r->hash_algo->hexsz > isize ||
+ if (ref_length + odb->repo->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid,
+ odb->repo->hash_algo)) {
free(buffer);
return NULL;
}
diff --git a/odb.h b/odb.h
index 911448f4d42..0f26ee3216c 100644
--- a/odb.h
+++ b/odb.h
@@ -263,6 +263,12 @@ void *odb_read_object(struct object_database *odb,
enum object_type *type,
unsigned long *size);
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *oid_ret);
+
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -374,7 +380,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: odb_read_object(),
- * read_object_with_reference(), odb_read_object_info() and odb().
+ * odb_read_object_peeled(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -423,13 +429,6 @@ enum for_each_object_flags {
FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
};
-
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *oid_ret);
-
/* Compatibility wrappers, to be removed once Git 2.50 has been released. */
#include "repository.h"
diff --git a/tree-walk.c b/tree-walk.c
index 766af99f466..e449a1320e5 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -90,7 +90,7 @@ void *fill_tree_descriptor(struct repository *r,
void *buf = NULL;
if (oid) {
- buf = read_object_with_reference(r, oid, OBJ_TREE, &size, NULL);
+ buf = odb_read_object_peeled(r->objects, oid, OBJ_TREE, &size, NULL);
if (!buf)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
}
@@ -611,7 +611,7 @@ int get_tree_entry(struct repository *r,
unsigned long size;
struct object_id root;
- tree = read_object_with_reference(r, tree_oid, OBJ_TREE, &size, &root);
+ tree = odb_read_object_peeled(r->objects, tree_oid, OBJ_TREE, &size, &root);
if (!tree)
return -1;
@@ -681,10 +681,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
void *tree;
struct object_id root;
unsigned long size;
- tree = read_object_with_reference(r,
- ¤t_tree_oid,
- OBJ_TREE, &size,
- &root);
+ tree = odb_read_object_peeled(r->objects, ¤t_tree_oid,
+ OBJ_TREE, &size, &root);
if (!tree)
goto done;
--
2.49.0.1077.gc0e912fd4c.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v2 00/17] object-store: carve out the object database subsystem
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
` (16 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
@ 2025-05-09 21:43 ` Junio C Hamano
2025-05-12 18:33 ` Derrick Stolee
17 siblings, 1 reply; 166+ messages in thread
From: Junio C Hamano @ 2025-05-09 21:43 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Derrick Stolee
Patrick Steinhardt <ps@pks.im> writes:
> Changes in v2:
> - Fix for a copy-and-pasted commit message.
> - Rename `struct odb_backend` to `struct odb_alternate`. I'm happy to
> revert to the previous name if we ultimately think it's the better
> suited one.
Diff between the previous iteration is quite noisy due to this; I do
not have strong opinion for or against either name myself.
> - A couple of fixes to move changes into the correct commit. `git
> rebase -x 'meson compile -C build'` is now clean.
Good to see that we care about bisectability.
> - I _didn't_ back out the rename to "odb.{c,h}". Junio has already
> fixed the fallout, so it's probably more work for him to kick it out
> again than to just leave it in.
You do not have to make me an excuse, if popular demand is not to
rename; I can cope with either one fine.
Will replace, thanks.
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v2 00/17] object-store: carve out the object database subsystem
2025-05-09 21:43 ` [PATCH v2 00/17] object-store: carve out the object database subsystem Junio C Hamano
@ 2025-05-12 18:33 ` Derrick Stolee
0 siblings, 0 replies; 166+ messages in thread
From: Derrick Stolee @ 2025-05-12 18:33 UTC (permalink / raw)
To: Junio C Hamano, Patrick Steinhardt; +Cc: git
On 5/9/2025 5:43 PM, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
>
>> Changes in v2:
>> - Fix for a copy-and-pasted commit message.
>> - Rename `struct odb_backend` to `struct odb_alternate`. I'm happy to
>> revert to the previous name if we ultimately think it's the better
>> suited one.
>
> Diff between the previous iteration is quite noisy due to this; I do
> not have strong opinion for or against either name myself.
I agree the range-diff is noisy, so I had to reread the patches.
Thankfully, the patch organization was already pretty good, so
it was quick to validate that my earlier concerns were handled.
>> - A couple of fixes to move changes into the correct commit. `git
>> rebase -x 'meson compile -C build'` is now clean.
>
> Good to see that we care about bisectability.
>
>> - I _didn't_ back out the rename to "odb.{c,h}". Junio has already
>> fixed the fallout, so it's probably more work for him to kick it out
>> again than to just leave it in.
>
> You do not have to make me an excuse, if popular demand is not to
> rename; I can cope with either one fine.
I'm happy that you considered my advice as necessary.
Since the rename doesn't appear to have huge implications for
ongoing series, I won't voice any further objections to this
rename.
v2 LGTM.
Thanks,
-Stolee
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v3 00/17] object-store: carve out the object database subsystem
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (19 preceding siblings ...)
2025-05-09 14:12 ` [PATCH v2 " Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
` (17 more replies)
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (2 subsequent siblings)
23 siblings, 18 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
Hi,
this patch series refactors the object store subsystem to become more
self-contained by getting rid of `the_repository`. Instead of passing in
the repository explicitly, we start to pass in the object store itself,
which is in contrast to many other refactorings we did, but in line with
what we did for the ref store, as well.
This series also starts to properly scope functions to the carved out
object database subsystem, which requires a bit of shuffling. This
allows us to have a short-and-sweet `odb_` prefix for functions and
prepares us for a future with pluggable object backends.
The series is structured as follows:
- Patches 1 to 3 rename `struct object_store` and `struct
object_directory` as well as the code files.
- Patches 4 to 12 refactor "odb.c" to get rid of `the_repository`.
- Patches 13 to 17 adjust the name of remaining functions so that they
can be clearly attributed to the ODB. I'm happy to kick these
patches out of this series and resend them at a later point in case
they create too much turmoil.
This series is built on top of 6f84262c44a (The eleventh batch,
2025-05-05) with ps/object-store-cleanup at 8a9e27be821 (object-store:
drop `repo_has_object_file()`, 2025-04-29) merged into it. There are a
couple of trivial conflicts when merged with "seen", I have appended the
merge conflict resolution as a patch at the end of this mail.
Changes in v2:
- Fix for a copy-and-pasted commit message.
- Rename `struct odb_backend` to `struct odb_alternate`. I'm happy to
revert to the previous name if we ultimately think it's the better
suited one.
- A couple of fixes to move changes into the correct commit. `git
rebase -x 'meson compile -C build'` is now clean.
- I _didn't_ back out the rename to "odb.{c,h}". Junio has already
fixed the fallout, so it's probably more work for him to kick it out
again than to just leave it in.
- Link to v1: https://lore.kernel.org/r/20250506-pks-object-store-wo-the-repository-v1-0-c05b82e7b126@pks.im
Changes in v3:
- Polishing for some comments and commit messages.
- Link to v2: https://lore.kernel.org/r/20250509-pks-object-store-wo-the-repository-v2-0-103f59bf8e28@pks.im
Thanks!
Patrick
---
Patrick Steinhardt (17):
object-store: rename `raw_object_store` to `object_database`
object-store: rename `object_directory` to `odb_alternate`
object-store: rename files to "odb.{c,h}"
odb: introduce parent pointers
odb: get rid of `the_repository` in `find_odb()`
odb: get rid of `the_repository` in `assert_oid_type()`
odb: get rid of `the_repository` in `odb_mkstemp()`
odb: get rid of `the_repository` when handling alternates
odb: get rid of `the_repository` in `for_each()` functions
odb: get rid of `the_repository` when handling the primary alternate
odb: get rid of `the_repository` when handling submodule alternates
odb: trivial refactorings to get rid of `the_repository`
odb: rename `oid_object_info()`
odb: rename `repo_read_object_file()`
odb: rename `has_object()`
odb: rename `pretend_object_file()`
odb: rename `read_object_with_reference()`
Documentation/user-manual.adoc | 4 +-
Makefile | 2 +-
apply.c | 14 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 6 +-
attr.c | 4 +-
bisect.c | 8 +-
blame.c | 22 +-
builtin/backfill.c | 6 +-
builtin/blame.c | 6 +-
builtin/cat-file.c | 62 +++--
builtin/checkout.c | 2 +-
builtin/clone.c | 14 +-
builtin/commit-graph.c | 20 +-
builtin/commit-tree.c | 4 +-
builtin/count-objects.c | 6 +-
builtin/describe.c | 5 +-
builtin/difftool.c | 4 +-
builtin/fast-export.c | 10 +-
builtin/fast-import.c | 49 ++--
builtin/fetch.c | 21 +-
builtin/fsck.c | 31 +--
builtin/gc.c | 16 +-
builtin/grep.c | 26 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 29 +--
builtin/log.c | 4 +-
builtin/ls-files.c | 4 +-
builtin/ls-tree.c | 6 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 14 +-
builtin/mktag.c | 6 +-
builtin/mktree.c | 10 +-
builtin/multi-pack-index.c | 6 +-
builtin/notes.c | 8 +-
builtin/pack-objects.c | 70 +++---
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 6 +-
builtin/receive-pack.c | 9 +-
builtin/remote.c | 6 +-
builtin/repack.c | 7 +-
builtin/replace.c | 12 +-
builtin/rev-list.c | 8 +-
builtin/show-ref.c | 6 +-
builtin/submodule--helper.c | 11 +-
builtin/tag.c | 10 +-
builtin/unpack-file.c | 4 +-
builtin/unpack-objects.c | 12 +-
bulk-checkin.c | 6 +-
bundle-uri.c | 5 +-
bundle.c | 6 +-
cache-tree.c | 17 +-
combine-diff.c | 4 +-
commit-graph.c | 106 ++++----
commit-graph.h | 20 +-
commit.c | 15 +-
config.c | 4 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 12 +-
diff.c | 20 +-
dir.c | 2 +-
entry.c | 6 +-
fetch-pack.c | 17 +-
fmt-merge-msg.c | 6 +-
fsck.c | 4 +-
grep.c | 6 +-
http-backend.c | 2 +-
http-push.c | 20 +-
http-walker.c | 12 +-
http.c | 6 +-
list-objects-filter.c | 4 +-
list-objects.c | 6 +-
log-tree.c | 2 +-
loose.c | 46 ++--
mailmap.c | 4 +-
match-trees.c | 6 +-
merge-blobs.c | 10 +-
merge-ort.c | 8 +-
meson.build | 2 +-
midx-write.c | 2 +-
midx.c | 6 +-
notes-cache.c | 4 +-
notes-merge.c | 4 +-
notes.c | 19 +-
object-file.c | 94 ++++----
object-file.h | 12 +-
object-name.c | 24 +-
object.c | 8 +-
object-store.c => odb.c | 413 +++++++++++++++++---------------
object-store.h => odb.h | 272 +++++++++++++++------
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 9 +-
pack-bitmap.c | 10 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
pack-write.c | 10 +-
packfile.c | 29 +--
packfile.h | 8 +-
path.c | 4 +-
promisor-remote.c | 6 +-
protocol-caps.c | 4 +-
reachable.c | 2 +-
read-cache.c | 14 +-
ref-filter.c | 6 +-
reflog.c | 8 +-
refs.c | 7 +-
remote.c | 9 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 21 +-
repository.h | 4 +-
rerere.c | 7 +-
revision.c | 5 +-
send-pack.c | 4 +-
sequencer.c | 7 +-
server-info.c | 2 +-
shallow.c | 14 +-
streaming.c | 10 +-
submodule-config.c | 9 +-
submodule.c | 32 +--
submodule.h | 9 -
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 4 +-
t/helper/test-read-graph.c | 8 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 4 +-
tag.c | 10 +-
tmp-objdir.c | 30 +--
tree-walk.c | 18 +-
tree.c | 6 +-
unpack-trees.c | 2 +-
upload-pack.c | 4 +-
walker.c | 6 +-
xdiff-interface.c | 4 +-
139 files changed, 1180 insertions(+), 1032 deletions(-)
Range-diff versus v2:
1: c113f51cc1a ! 1: 40051831e0e object-store: rename `raw_object_store` to `object_database`
@@ Commit message
This conversion can be done by simply passing in an explicit pointer to
a repository and then using its `->objects` pointer. But there is a
second effort underway, which is to make the object subsystem more
- selfcontained so that we can eventually have pluggale object backends.
+ selfcontained so that we can eventually have pluggable object backends.
As such, passing in a repository wouldn't make a ton of sense, and the
goal is to convert the object store interfaces such that we always pass
in a reference to the `raw_object_store` instead.
2: 05a6fb88bf3 ! 2: 39f178ace57 object-store: rename `object_directory` to `odb_alternate`
@@ Commit message
Let's preempt this by renaming the structure to `odb_alternate` now
already. This name is agnostic of how exactly objects are stored while
still specifically pinpointing that this is about an alternate object
- database. In the future, it allows us to easily introduce e.g. a
- `odb_files_alternate` and other specific implementations over time.
+ database. Furthermore, it is already used in Git to represent this
+ context -- the only stretch is that the primary object directory is now
+ the primary alternate.
+
+ In the future, this change allows us to easily introduce for example a
+ `odb_files_alternate` and other format-specific implementations.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
@@ object-store.h: struct oidtree;
-struct object_directory {
- struct object_directory *next;
+/*
-+ * An alternate part of an object database that stores the actual objects.
++ * The alternate is the part of the object database that stores the actual
++ * objects. It thus encapsulates the logic to read and write the specific
++ * on-disk format. An object database can have multiple alternates, and
++ * exactly one primary alternate that is used when writing new objects.
+ */
+struct odb_alternate {
+ struct odb_alternate *next;
3: bcc552e554c = 3: 7d79268aa73 object-store: rename files to "odb.{c,h}"
4: 908e399cde6 = 4: 25777175ade odb: introduce parent pointers
5: 939961a4eb3 = 5: c8daaa9bd03 odb: get rid of `the_repository` in `find_odb()`
6: 74dc4d61e37 = 6: 23cf77f4e83 odb: get rid of `the_repository` in `assert_oid_type()`
7: 61f1302201f = 7: 58975fe2c7f odb: get rid of `the_repository` in `odb_mkstemp()`
8: 81926adbd98 ! 8: 27959349ffe odb: get rid of `the_repository` when handling alternates
@@ odb.h: struct oidtree;
+char *compute_alternate_path(const char *path, struct strbuf *err);
+
/*
- * An alternate part of an object database that stores the actual objects.
- */
+ * The alternate is the part of the object database that stores the actual
+ * objects. It thus encapsulates the logic to read and write the specific
@@ odb.h: struct odb_alternate {
char *path;
};
9: 60693ef4805 = 9: 3bb54296615 odb: get rid of `the_repository` in `for_each()` functions
10: 387e0311264 = 10: b39a3d934a5 odb: get rid of `the_repository` when handling the primary alternate
11: 64503d9eeb8 = 11: 489c6b4c33f odb: get rid of `the_repository` when handling submodule alternates
12: fd793aef552 = 12: a3068a0ad76 odb: trivial refactorings to get rid of `the_repository`
13: efcd16f5d14 = 13: eb614efd08b odb: rename `oid_object_info()`
14: 1f020271cc5 = 14: 6c7c24739d1 odb: rename `repo_read_object_file()`
15: 8a51662e84d = 15: 07c2b387ace odb: rename `has_object()`
16: 3bd6d7e2ae4 = 16: f1e8c7f10ab odb: rename `pretend_object_file()`
17: 7d63407a1b4 = 17: d612f806675 odb: rename `read_object_with_reference()`
---
base-commit: 046efb6f2b050efd580e1c1750b77328a1790c0e
change-id: 20250505-pks-object-store-wo-the-repository-9c6cbdf8d4b1
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v3 01/17] object-store: rename `raw_object_store` to `object_database`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-22 21:59 ` Justin Tobler
2025-05-14 5:12 ` [PATCH v3 02/17] object-store: rename `object_directory` to `odb_alternate` Patrick Steinhardt
` (16 subsequent siblings)
17 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
The `raw_object_store` structure is the central entry point for reading
and writing objects in a repository. The main purpose of this structure
is to manage object directories and provide an interface to access and
write objects in those object directories.
Right now, many of the functions associated with the raw object store
implicitly rely on `the_repository` to get access to its `objects`
pointer, which is the `raw_object_store`. As we want to generally get
rid of using `the_repository` across our codebase we will have to
convert this implicit dependency on this global variable into an
explicit parameter.
This conversion can be done by simply passing in an explicit pointer to
a repository and then using its `->objects` pointer. But there is a
second effort underway, which is to make the object subsystem more
selfcontained so that we can eventually have pluggable object backends.
As such, passing in a repository wouldn't make a ton of sense, and the
goal is to convert the object store interfaces such that we always pass
in a reference to the `raw_object_store` instead.
This will expose the `raw_object_store` type to a lot more callers
though, which surfaces that this type is named somewhat awkwardly. The
"raw_" prefix makes readers wonder whether there is a non-raw variant of
the object store, but there isn't. Furthermore, we nowadays want to name
functions in a way that they can be clearly attributed to a specific
subsystem, but calling them e.g. `raw_object_store_has_object()` is just
too unwieldy, even when dropping the "raw_" prefix.
Instead, rename the structure to `object_database`. This term is already
used a lot throughout our codebase, and it cannot easily be mistaken for
"object directories", either. Furthermore, its acronym ODB is already
well-known and works well as part of a function's name, like for example
`odb_has_object()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
commit-graph.c | 2 +-
commit-graph.h | 4 ++--
object-store.c | 12 ++++++------
object-store.h | 11 ++++++++---
packfile.c | 2 +-
packfile.h | 4 ++--
repository.c | 4 ++--
repository.h | 4 ++--
8 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index 6394752b0b0..1b66486b9c9 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -829,7 +829,7 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
return NULL;
}
-void close_commit_graph(struct raw_object_store *o)
+void close_commit_graph(struct object_database *o)
{
if (!o->commit_graph)
return;
diff --git a/commit-graph.h b/commit-graph.h
index 13f662827d4..20d38c100ce 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -26,7 +26,7 @@ void git_test_write_commit_graph_or_die(void);
struct commit;
struct bloom_filter_settings;
struct repository;
-struct raw_object_store;
+struct object_database;
struct string_list;
char *get_commit_graph_filename(struct object_directory *odb);
@@ -186,7 +186,7 @@ int write_commit_graph(struct object_directory *odb,
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
-void close_commit_graph(struct raw_object_store *);
+void close_commit_graph(struct object_database *);
void free_commit_graph(struct commit_graph *);
/*
diff --git a/object-store.c b/object-store.c
index 2f51d0e3b03..1effcb12273 100644
--- a/object-store.c
+++ b/object-store.c
@@ -44,7 +44,7 @@ struct cached_object_entry {
} value;
};
-static const struct cached_object *find_cached_object(struct raw_object_store *object_store,
+static const struct cached_object *find_cached_object(struct object_database *object_store,
const struct object_id *oid)
{
static const struct cached_object empty_tree = {
@@ -86,7 +86,7 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
/*
* Return non-zero iff the path is usable as an alternate object database.
*/
-static int alt_odb_usable(struct raw_object_store *o,
+static int alt_odb_usable(struct object_database *o,
struct strbuf *path,
const char *normalized_objdir, khiter_t *pos)
{
@@ -959,9 +959,9 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct raw_object_store *raw_object_store_new(void)
+struct object_database *odb_new(void)
{
- struct raw_object_store *o = xmalloc(sizeof(*o));
+ struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
INIT_LIST_HEAD(&o->packed_git_mru);
@@ -970,7 +970,7 @@ struct raw_object_store *raw_object_store_new(void)
return o;
}
-static void free_object_directories(struct raw_object_store *o)
+static void free_object_directories(struct object_database *o)
{
while (o->odb) {
struct object_directory *next;
@@ -983,7 +983,7 @@ static void free_object_directories(struct raw_object_store *o)
o->odb_by_path = NULL;
}
-void raw_object_store_clear(struct raw_object_store *o)
+void odb_clear(struct object_database *o)
{
FREE_AND_NULL(o->alternate_db);
diff --git a/object-store.h b/object-store.h
index c2fe5a19605..34b8efbbb83 100644
--- a/object-store.h
+++ b/object-store.h
@@ -86,7 +86,12 @@ struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
-struct raw_object_store {
+/*
+ * The object database encapsulates access to objects in a repository. It
+ * manages one or more backends that store the actual objects which are
+ * configured via alternates.
+ */
+struct object_database {
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -168,8 +173,8 @@ struct raw_object_store {
unsigned packed_git_initialized : 1;
};
-struct raw_object_store *raw_object_store_new(void);
-void raw_object_store_clear(struct raw_object_store *o);
+struct object_database *odb_new(void);
+void odb_clear(struct object_database *o);
/*
* Create a temporary file rooted in the object database directory, or
diff --git a/packfile.c b/packfile.c
index d91016f1c7f..8f51665266d 100644
--- a/packfile.c
+++ b/packfile.c
@@ -359,7 +359,7 @@ void close_pack(struct packed_git *p)
oidset_clear(&p->bad_objects);
}
-void close_object_store(struct raw_object_store *o)
+void close_object_store(struct object_database *o)
{
struct packed_git *p;
diff --git a/packfile.h b/packfile.h
index 3a3c77cf05a..826eb7f475f 100644
--- a/packfile.h
+++ b/packfile.h
@@ -183,12 +183,12 @@ int close_pack_fd(struct packed_git *p);
uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
-struct raw_object_store;
+struct object_database;
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
void close_pack_windows(struct packed_git *);
void close_pack(struct packed_git *);
-void close_object_store(struct raw_object_store *o);
+void close_object_store(struct object_database *o);
void unuse_pack(struct pack_window **);
void clear_delta_base_cache(void);
struct packed_git *add_packed_git(struct repository *r, const char *path,
diff --git a/repository.c b/repository.c
index 9b3d6665fc6..07757e6e0c9 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = raw_object_store_new();
+ repo->objects = odb_new();
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -374,7 +374,7 @@ void repo_clear(struct repository *repo)
FREE_AND_NULL(repo->worktree);
FREE_AND_NULL(repo->submodule_prefix);
- raw_object_store_clear(repo->objects);
+ odb_clear(repo->objects);
FREE_AND_NULL(repo->objects);
parsed_object_pool_clear(repo->parsed_objects);
diff --git a/repository.h b/repository.h
index c4c92b2ab9c..3a5ef9c781e 100644
--- a/repository.h
+++ b/repository.h
@@ -9,7 +9,7 @@ struct git_hash_algo;
struct index_state;
struct lock_file;
struct pathspec;
-struct raw_object_store;
+struct object_database;
struct submodule_cache;
struct promisor_remote_config;
struct remote_state;
@@ -47,7 +47,7 @@ struct repository {
/*
* Holds any information related to accessing the raw object content.
*/
- struct raw_object_store *objects;
+ struct object_database *objects;
/*
* All objects in this repository that have been parsed. This structure
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v3 01/17] object-store: rename `raw_object_store` to `object_database`
2025-05-14 5:12 ` [PATCH v3 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
@ 2025-05-22 21:59 ` Justin Tobler
0 siblings, 0 replies; 166+ messages in thread
From: Justin Tobler @ 2025-05-22 21:59 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On 25/05/14 07:12AM, Patrick Steinhardt wrote:
> The `raw_object_store` structure is the central entry point for reading
> and writing objects in a repository. The main purpose of this structure
> is to manage object directories and provide an interface to access and
> write objects in those object directories.
>
> Right now, many of the functions associated with the raw object store
> implicitly rely on `the_repository` to get access to its `objects`
> pointer, which is the `raw_object_store`. As we want to generally get
> rid of using `the_repository` across our codebase we will have to
> convert this implicit dependency on this global variable into an
> explicit parameter.
>
> This conversion can be done by simply passing in an explicit pointer to
> a repository and then using its `->objects` pointer. But there is a
> second effort underway, which is to make the object subsystem more
> selfcontained so that we can eventually have pluggable object backends.
> As such, passing in a repository wouldn't make a ton of sense, and the
> goal is to convert the object store interfaces such that we always pass
> in a reference to the `raw_object_store` instead.
>
> This will expose the `raw_object_store` type to a lot more callers
> though, which surfaces that this type is named somewhat awkwardly. The
> "raw_" prefix makes readers wonder whether there is a non-raw variant of
> the object store, but there isn't. Furthermore, we nowadays want to name
> functions in a way that they can be clearly attributed to a specific
> subsystem, but calling them e.g. `raw_object_store_has_object()` is just
> too unwieldy, even when dropping the "raw_" prefix.
>
> Instead, rename the structure to `object_database`. This term is already
> used a lot throughout our codebase, and it cannot easily be mistaken for
> "object directories", either. Furthermore, its acronym ODB is already
> well-known and works well as part of a function's name, like for example
> `odb_has_object()`.
Renaming to `struct object_database` is a good change here. One oddity
is that it still contains the `struct object_directory` field named
"odb", but that gets cleared up in the next patch. So no issue there.
The patch itself just a bunch renames to adapt users of `struct
object_database` and some function renames to use the new prefix. This
patch looks good to me.
-Justin
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v3 02/17] object-store: rename `object_directory` to `odb_alternate`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-22 22:13 ` Justin Tobler
2025-05-14 5:12 ` [PATCH v3 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
` (15 subsequent siblings)
17 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
The `object_directory` structure is used as an access point for a single
object directory like ".git/objects". While the structure isn't yet
fully self-contained, the intent is for it to eventually contain all
information required to access objects in one specific location.
While the name "object directory" is a good fit for now, this will
change over time as we continue with the agenda to make pluggable object
databases a thing. Eventually, objects may not be accessed via any kind
of directory at all anymore, but they could instead be backed by any
kind of durable storage mechanism. While it seems quite far-fetched for
now, it is thinkable that eventually this might even be some form of a
database, for example.
As such, the current name of this structure will become worse over time
as we evolve into the direction of pluggable ODBs. Immediate next steps
will start to carve out proper self-contained object directories, which
requires us to pass in these object directories as parameters. Based on
our modern naming schema this means that those functions should then be
named after their subsystem, which means that we would start to bake the
current name into the codebase more and more.
Let's preempt this by renaming the structure to `odb_alternate` now
already. This name is agnostic of how exactly objects are stored while
still specifically pinpointing that this is about an alternate object
database. Furthermore, it is already used in Git to represent this
context -- the only stretch is that the primary object directory is now
the primary alternate.
In the future, this change allows us to easily introduce for example a
`odb_files_alternate` and other format-specific implementations.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 18 +++----
builtin/count-objects.c | 4 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 14 ++---
builtin/gc.c | 14 ++---
builtin/grep.c | 2 +-
builtin/multi-pack-index.c | 4 +-
builtin/submodule--helper.c | 6 +--
bundle.c | 2 +-
commit-graph.c | 94 +++++++++++++++++-----------------
commit-graph.h | 14 ++---
diagnose.c | 8 +--
http-walker.c | 2 +-
http.c | 4 +-
loose.c | 42 +++++++--------
midx.c | 6 +--
object-file.c | 80 ++++++++++++++---------------
object-file.h | 8 +--
object-name.c | 6 +--
object-store.c | 122 ++++++++++++++++++++++----------------------
object-store.h | 28 ++++++----
packfile.c | 16 +++---
path.c | 2 +-
refs.c | 2 +-
repository.c | 14 ++---
submodule-config.c | 2 +-
t/helper/test-read-graph.c | 6 +--
tmp-objdir.c | 24 ++++-----
28 files changed, 276 insertions(+), 270 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index a783a86e797..628d3a1e92e 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb = NULL;
+ struct odb_alternate *alternate = NULL;
char *graph_name;
char *chain_name;
enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE;
@@ -101,9 +101,9 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- odb = find_odb(the_repository, opts.obj_dir);
- graph_name = get_commit_graph_filename(odb);
- chain_name = get_commit_graph_chain_filename(odb);
+ alternate = find_odb(the_repository, opts.obj_dir);
+ graph_name = get_commit_graph_filename(alternate);
+ chain_name = get_commit_graph_chain_filename(alternate);
if (open_commit_graph(graph_name, &fd, &st))
opened = OPENED_GRAPH;
else if (errno != ENOENT)
@@ -120,7 +120,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opened == OPENED_NONE)
return 0;
else if (opened == OPENED_GRAPH)
- graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb);
+ graph = load_commit_graph_one_fd_st(the_repository, fd, &st, alternate);
else
graph = load_commit_graph_chain_fd_st(the_repository, fd, &st,
&incomplete_chain);
@@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
struct string_list pack_indexes = STRING_LIST_INIT_DUP;
struct strbuf buf = STRBUF_INIT;
struct oidset commits = OIDSET_INIT;
- struct object_directory *odb = NULL;
+ struct odb_alternate *alternate = NULL;
int result = 0;
enum commit_graph_write_flags flags = 0;
struct progress *progress = NULL;
@@ -289,10 +289,10 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- odb = find_odb(the_repository, opts.obj_dir);
+ alternate = find_odb(the_repository, opts.obj_dir);
if (opts.reachable) {
- if (write_commit_graph_reachable(odb, flags, &write_opts))
+ if (write_commit_graph_reachable(alternate, flags, &write_opts))
result = 1;
goto cleanup;
}
@@ -318,7 +318,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
stop_progress(&progress);
}
- if (write_commit_graph(odb,
+ if (write_commit_graph(alternate,
opts.stdin_packs ? &pack_indexes : NULL,
opts.stdin_commits ? &commits : NULL,
flags,
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index a88c0c9c09a..da830fcee57 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -80,10 +80,10 @@ static int count_cruft(const char *basename UNUSED, const char *path,
return 0;
}
-static int print_alternate(struct object_directory *odb, void *data UNUSED)
+static int print_alternate(struct odb_alternate *alternate, void *data UNUSED)
{
printf("alternate: ");
- quote_c_style(odb->path, NULL, stdout, 0);
+ quote_c_style(alternate->path, NULL, stdout, 0);
putchar('\n');
return 0;
}
diff --git a/builtin/fetch.c b/builtin/fetch.c
index cda6eaf1fd6..4de6d3206d4 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2652,7 +2652,7 @@ int cmd_fetch(int argc,
commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
trace2_region_enter("fetch", "write-commit-graph", the_repository);
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->alternates,
commit_graph_flags,
NULL);
trace2_region_leave("fetch", "write-commit-graph", the_repository);
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6cac28356ce..9c54286540c 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -965,7 +965,7 @@ int cmd_fsck(int argc,
struct repository *repo UNUSED)
{
int i;
- struct object_directory *odb;
+ struct odb_alternate *alternate;
/* fsck knows how to handle missing promisor objects */
fetch_if_missing = 0;
@@ -1007,8 +1007,8 @@ int cmd_fsck(int argc,
mark_packed_for_connectivity, NULL, 0);
} else {
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next)
- fsck_object_dir(odb->path);
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next)
+ fsck_object_dir(alternate->path);
if (check_full) {
struct packed_git *p;
@@ -1118,11 +1118,11 @@ int cmd_fsck(int argc,
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
strvec_pushl(&commit_graph_verify.args, "commit-graph",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", alternate->path, NULL);
if (show_progress)
strvec_push(&commit_graph_verify.args, "--progress");
else
@@ -1136,11 +1136,11 @@ int cmd_fsck(int argc,
struct child_process midx_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", alternate->path, NULL);
if (show_progress)
strvec_push(&midx_verify.args, "--progress");
else
diff --git a/builtin/gc.c b/builtin/gc.c
index 78a2751aa8a..9e9d31c1f39 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -944,7 +944,7 @@ struct repository *repo UNUSED)
}
if (the_repository->settings.gc_write_commit_graph == 1)
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->alternates,
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
NULL);
@@ -1197,7 +1197,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
if (loose_object_auto_limit < 0)
return 1;
- return for_each_loose_file_in_objdir(the_repository->objects->odb->path,
+ return for_each_loose_file_in_objdir(the_repository->objects->alternates->path,
loose_object_count,
NULL, NULL, &count);
}
@@ -1232,7 +1232,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
* Do not start pack-objects process
* if there are no loose objects.
*/
- if (!for_each_loose_file_in_objdir(r->objects->odb->path,
+ if (!for_each_loose_file_in_objdir(r->objects->alternates->path,
bail_on_loose,
NULL, NULL, NULL))
return 0;
@@ -1244,7 +1244,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
strvec_push(&pack_proc.args, "--quiet");
else
strvec_push(&pack_proc.args, "--no-quiet");
- strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
+ strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->alternates->path);
pack_proc.in = -1;
@@ -1272,7 +1272,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
else if (data.batch_size > 0)
data.batch_size--; /* Decrease for equality on limit. */
- for_each_loose_file_in_objdir(r->objects->odb->path,
+ for_each_loose_file_in_objdir(r->objects->alternates->path,
write_loose_object_to_stdin,
NULL,
NULL,
@@ -1525,7 +1525,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
int result = 0;
struct lock_file lk;
struct repository *r = the_repository;
- char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path);
+ char *lock_path = xstrfmt("%s/maintenance", r->objects->alternates->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
/*
@@ -2997,7 +2997,7 @@ static int update_background_schedule(const struct maintenance_start_opts *opts,
unsigned int i;
int result = 0;
struct lock_file lk;
- char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path);
+ char *lock_path = xstrfmt("%s/schedule", the_repository->objects->alternates->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
if (errno == EEXIST)
diff --git a/builtin/grep.c b/builtin/grep.c
index 3ce574a605b..3c51a39c10d 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,7 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->odb->path);
+ add_submodule_odb_by_path(subrepo->objects->alternates->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 69a97507324..a77ae465d48 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -294,8 +294,8 @@ int cmd_multi_pack_index(int argc,
if (the_repository &&
the_repository->objects &&
- the_repository->objects->odb)
- opts.object_dir = xstrdup(the_repository->objects->odb->path);
+ the_repository->objects->alternates)
+ opts.object_dir = xstrdup(the_repository->objects->alternates->path);
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 53da2116ddf..cd7db11d825 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1582,7 +1582,7 @@ static const char alternate_error_advice[] = N_(
);
static int add_possible_reference_from_superproject(
- struct object_directory *odb, void *sas_cb)
+ struct odb_alternate *alt_odb, void *sas_cb)
{
struct submodule_alternate_setup *sas = sas_cb;
size_t len;
@@ -1591,12 +1591,12 @@ static int add_possible_reference_from_superproject(
* If the alternate object store is another repository, try the
* standard layout with .git/(modules/<name>)+/objects
*/
- if (strip_suffix(odb->path, "/objects", &len)) {
+ if (strip_suffix(alt_odb->path, "/objects", &len)) {
struct repository alternate;
char *sm_alternate;
struct strbuf sb = STRBUF_INIT;
struct strbuf err = STRBUF_INIT;
- strbuf_add(&sb, odb->path, len);
+ strbuf_add(&sb, alt_odb->path, len);
if (repo_init(&alternate, sb.buf, NULL) < 0)
die(_("could not get a repository handle for gitdir '%s'"),
diff --git a/bundle.c b/bundle.c
index b0a3fee2efa..0c7cd15bb12 100644
--- a/bundle.c
+++ b/bundle.c
@@ -233,7 +233,7 @@ int verify_bundle(struct repository *r,
.quiet = 1,
};
- if (!r || !r->objects || !r->objects->odb)
+ if (!r || !r->objects || !r->objects->alternates)
return error(_("need a repository to verify a bundle"));
for (i = 0; i < p->nr; i++) {
diff --git a/commit-graph.c b/commit-graph.c
index 1b66486b9c9..58d1eeedb1a 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -37,7 +37,7 @@ void git_test_write_commit_graph_or_die(void)
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- if (write_commit_graph_reachable(the_repository->objects->odb,
+ if (write_commit_graph_reachable(the_repository->objects->alternates,
flags, NULL))
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
}
@@ -191,21 +191,21 @@ static int commit_gen_cmp(const void *va, const void *vb)
return 0;
}
-char *get_commit_graph_filename(struct object_directory *obj_dir)
+char *get_commit_graph_filename(struct odb_alternate *alternate)
{
- return xstrfmt("%s/info/commit-graph", obj_dir->path);
+ return xstrfmt("%s/info/commit-graph", alternate->path);
}
-static char *get_split_graph_filename(struct object_directory *odb,
+static char *get_split_graph_filename(struct odb_alternate *alternate,
const char *oid_hex)
{
- return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb->path,
+ return xstrfmt("%s/info/commit-graphs/graph-%s.graph", alternate->path,
oid_hex);
}
-char *get_commit_graph_chain_filename(struct object_directory *odb)
+char *get_commit_graph_chain_filename(struct odb_alternate *alternate)
{
- return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
+ return xstrfmt("%s/info/commit-graphs/commit-graph-chain", alternate->path);
}
static struct commit_graph *alloc_commit_graph(void)
@@ -250,7 +250,7 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
void *graph_map;
size_t graph_size;
@@ -269,7 +269,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
ret = parse_commit_graph(&r->settings, graph_map, graph_size);
if (ret)
- ret->odb = odb;
+ ret->alternate = alternate;
else
munmap(graph_map, graph_size);
@@ -487,7 +487,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
static struct commit_graph *load_commit_graph_one(struct repository *r,
const char *graph_file,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
struct stat st;
@@ -498,7 +498,7 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
if (!open_ok)
return NULL;
- g = load_commit_graph_one_fd_st(r, fd, &st, odb);
+ g = load_commit_graph_one_fd_st(r, fd, &st, alternate);
if (g)
g->filename = xstrdup(graph_file);
@@ -507,10 +507,10 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
}
static struct commit_graph *load_commit_graph_v1(struct repository *r,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
- char *graph_name = get_commit_graph_filename(odb);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ char *graph_name = get_commit_graph_filename(alternate);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, alternate);
free(graph_name);
return g;
@@ -652,7 +652,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
prepare_alt_odb(r);
for (i = 0; i < count; i++) {
- struct object_directory *odb;
+ struct odb_alternate *alternate;
if (strbuf_getline_lf(&line, fp) == EOF)
break;
@@ -665,9 +665,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
valid = 0;
- for (odb = r->objects->odb; odb; odb = odb->next) {
- char *graph_name = get_split_graph_filename(odb, line.buf);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ char *graph_name = get_split_graph_filename(alternate, line.buf);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, alternate);
free(graph_name);
@@ -701,9 +701,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
static struct commit_graph *load_commit_graph_chain(struct repository *r,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
- char *chain_file = get_commit_graph_chain_filename(odb);
+ char *chain_file = get_commit_graph_chain_filename(alternate);
struct stat st;
int fd;
struct commit_graph *g = NULL;
@@ -719,24 +719,24 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
}
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
- struct commit_graph *g = load_commit_graph_v1(r, odb);
+ struct commit_graph *g = load_commit_graph_v1(r, alternate);
if (!g)
- g = load_commit_graph_chain(r, odb);
+ g = load_commit_graph_chain(r, alternate);
return g;
}
static void prepare_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_alternate *alternate)
{
if (r->objects->commit_graph)
return;
- r->objects->commit_graph = read_commit_graph_one(r, odb);
+ r->objects->commit_graph = read_commit_graph_one(r, alternate);
}
/*
@@ -747,7 +747,7 @@ static void prepare_commit_graph_one(struct repository *r,
*/
static int prepare_commit_graph(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
/*
* Early return if there is no git dir or if the commit graph is
@@ -779,10 +779,10 @@ static int prepare_commit_graph(struct repository *r)
return 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb;
- !r->objects->commit_graph && odb;
- odb = odb->next)
- prepare_commit_graph_one(r, odb);
+ for (alternate = r->objects->alternates;
+ !r->objects->commit_graph && alternate;
+ alternate = alternate->next)
+ prepare_commit_graph_one(r, alternate);
return !!r->objects->commit_graph;
}
@@ -1137,7 +1137,7 @@ struct packed_commit_list {
struct write_commit_graph_context {
struct repository *r;
- struct object_directory *odb;
+ struct odb_alternate *alternate;
char *graph_name;
struct oid_array oids;
struct packed_commit_list commits;
@@ -1870,7 +1870,7 @@ static int add_ref_to_set(const char *refname UNUSED,
return 0;
}
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_alternate *alternate,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts)
{
@@ -1890,7 +1890,7 @@ int write_commit_graph_reachable(struct object_directory *odb,
stop_progress(&data.progress);
- result = write_commit_graph(odb, NULL, &commits,
+ result = write_commit_graph(alternate, NULL, &commits,
flags, opts);
oidset_clear(&commits);
@@ -1906,7 +1906,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
int dirlen;
int ret = 0;
- strbuf_addf(&packname, "%s/pack/", ctx->odb->path);
+ strbuf_addf(&packname, "%s/pack/", ctx->alternate->path);
dirlen = packname.len;
if (ctx->report_progress) {
strbuf_addf(&progress_title,
@@ -2058,10 +2058,10 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
strbuf_addf(&tmp_file,
"%s/info/commit-graphs/tmp_graph_XXXXXX",
- ctx->odb->path);
+ ctx->alternate->path);
ctx->graph_name = strbuf_detach(&tmp_file, NULL);
} else {
- ctx->graph_name = get_commit_graph_filename(ctx->odb);
+ ctx->graph_name = get_commit_graph_filename(ctx->alternate);
}
if (safe_create_leading_directories(the_repository, ctx->graph_name)) {
@@ -2071,7 +2071,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
if (ctx->split) {
- char *lock_name = get_commit_graph_chain_filename(ctx->odb);
+ char *lock_name = get_commit_graph_chain_filename(ctx->alternate);
hold_lock_file_for_update_mode(&lk, lock_name,
LOCK_DIE_ON_ERROR, 0444);
@@ -2159,7 +2159,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
char *new_base_hash = xstrdup(oid_to_hex(&ctx->new_base_graph->oid));
- char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb, new_base_hash);
+ char *new_base_name = get_split_graph_filename(ctx->new_base_graph->alternate, new_base_hash);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 2]);
@@ -2199,14 +2199,14 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
}
} else {
- char *graph_name = get_commit_graph_filename(ctx->odb);
+ char *graph_name = get_commit_graph_filename(ctx->alternate);
unlink(graph_name);
free(graph_name);
}
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(hash_to_hex(file_hash));
- final_graph_name = get_split_graph_filename(ctx->odb,
+ final_graph_name = get_split_graph_filename(ctx->alternate,
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1] = final_graph_name;
@@ -2257,7 +2257,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
flags != COMMIT_GRAPH_SPLIT_REPLACE) {
while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
(max_commits && num_commits > max_commits))) {
- if (g->odb != ctx->odb)
+ if (g->alternate != ctx->alternate)
break;
if (unsigned_add_overflows(num_commits, g->num_commits))
@@ -2279,10 +2279,10 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
"should be 1 with --split=replace");
if (ctx->num_commit_graphs_after == 2) {
- char *old_graph_name = get_commit_graph_filename(g->odb);
+ char *old_graph_name = get_commit_graph_filename(g->alternate);
if (!strcmp(g->filename, old_graph_name) &&
- g->odb != ctx->odb) {
+ g->alternate != ctx->alternate) {
ctx->num_commit_graphs_after = 1;
ctx->new_base_graph = NULL;
}
@@ -2454,13 +2454,13 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
if (ctx->opts && ctx->opts->expire_time)
expire_time = ctx->opts->expire_time;
if (!ctx->split) {
- char *chain_file_name = get_commit_graph_chain_filename(ctx->odb);
+ char *chain_file_name = get_commit_graph_chain_filename(ctx->alternate);
unlink(chain_file_name);
free(chain_file_name);
ctx->num_commit_graphs_after = 0;
}
- strbuf_addstr(&path, ctx->odb->path);
+ strbuf_addstr(&path, ctx->alternate->path);
strbuf_addstr(&path, "/info/commit-graphs");
dir = opendir(path.buf);
@@ -2502,7 +2502,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
strbuf_release(&path);
}
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_alternate *alternate,
const struct string_list *const pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
@@ -2533,7 +2533,7 @@ int write_commit_graph(struct object_directory *odb,
CALLOC_ARRAY(ctx, 1);
ctx->r = r;
- ctx->odb = odb;
+ ctx->alternate = alternate;
ctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;
ctx->report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0;
ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
diff --git a/commit-graph.h b/commit-graph.h
index 20d38c100ce..19d95ade6ea 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -29,8 +29,8 @@ struct repository;
struct object_database;
struct string_list;
-char *get_commit_graph_filename(struct object_directory *odb);
-char *get_commit_graph_chain_filename(struct object_directory *odb);
+char *get_commit_graph_filename(struct odb_alternate *alternate);
+char *get_commit_graph_chain_filename(struct odb_alternate *alternate);
int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st);
@@ -89,7 +89,7 @@ struct commit_graph {
uint32_t num_commits;
struct object_id oid;
char *filename;
- struct object_directory *odb;
+ struct odb_alternate *alternate;
uint32_t num_commits_in_base;
unsigned int read_generation_data;
@@ -115,12 +115,12 @@ struct commit_graph {
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb);
+ struct odb_alternate *alternate);
struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
int fd, struct stat *st,
int *incomplete_chain);
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb);
+ struct odb_alternate *alternate);
struct repo_settings;
@@ -173,10 +173,10 @@ struct commit_graph_opts {
* is not compatible with the commit-graph feature, then the
* methods will return 0 without writing a commit-graph.
*/
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_alternate *alternate,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts);
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_alternate *alternate,
const struct string_list *pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
diff --git a/diagnose.c b/diagnose.c
index b1be74be983..50129cf4be3 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -59,13 +59,13 @@ static void dir_file_stats_objects(const char *full_path,
(uintmax_t)st.st_size);
}
-static int dir_file_stats(struct object_directory *object_dir, void *data)
+static int dir_file_stats(struct odb_alternate *alternate, void *data)
{
struct strbuf *buf = data;
- strbuf_addf(buf, "Contents of %s:\n", object_dir->path);
+ strbuf_addf(buf, "Contents of %s:\n", alternate->path);
- for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects,
+ for_each_file_in_pack_dir(alternate->path, dir_file_stats_objects,
data);
return 0;
@@ -228,7 +228,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(r->objects->odb, &buf);
+ dir_file_stats(r->objects->alternates, &buf);
foreach_alt_odb(dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
diff --git a/http-walker.c b/http-walker.c
index 463f7b119ad..9e7bc37f02e 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
ret = error("File %s has bad hash", hex);
} else if (req->rename < 0) {
struct strbuf buf = STRBUF_INIT;
- odb_loose_path(the_repository->objects->odb, &buf, &req->oid);
+ odb_loose_path(the_repository->objects->alternates, &buf, &req->oid);
ret = error("unable to write sha1 filename %s", buf.buf);
strbuf_release(&buf);
}
diff --git a/http.c b/http.c
index 3c029cf8947..8ce2ec73947 100644
--- a/http.c
+++ b/http.c
@@ -2662,7 +2662,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
oidcpy(&freq->oid, oid);
freq->localfile = -1;
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->alternates, &filename, oid);
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2814,7 +2814,7 @@ int finish_http_object_request(struct http_object_request *freq)
unlink_or_warn(freq->tmpfile.buf);
return -1;
}
- odb_loose_path(the_repository->objects->odb, &filename, &freq->oid);
+ odb_loose_path(the_repository->objects->alternates, &filename, &freq->oid);
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
strbuf_release(&filename);
diff --git a/loose.c b/loose.c
index bb602aaa366..bce4e1c3ee7 100644
--- a/loose.c
+++ b/loose.c
@@ -44,36 +44,36 @@ static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *key, const
return 1;
}
-static int insert_loose_map(struct object_directory *odb,
+static int insert_loose_map(struct odb_alternate *alternate,
const struct object_id *oid,
const struct object_id *compat_oid)
{
- struct loose_object_map *map = odb->loose_map;
+ struct loose_object_map *map = alternate->loose_map;
int inserted = 0;
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
if (inserted)
- oidtree_insert(odb->loose_objects_cache, compat_oid);
+ oidtree_insert(alternate->loose_objects_cache, compat_oid);
return inserted;
}
-static int load_one_loose_object_map(struct repository *repo, struct object_directory *dir)
+static int load_one_loose_object_map(struct repository *repo, struct odb_alternate *alternate)
{
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
FILE *fp;
- if (!dir->loose_map)
- loose_object_map_init(&dir->loose_map);
- if (!dir->loose_objects_cache) {
- ALLOC_ARRAY(dir->loose_objects_cache, 1);
- oidtree_init(dir->loose_objects_cache);
+ if (!alternate->loose_map)
+ loose_object_map_init(&alternate->loose_map);
+ if (!alternate->loose_objects_cache) {
+ ALLOC_ARRAY(alternate->loose_objects_cache, 1);
+ oidtree_init(alternate->loose_objects_cache);
}
- insert_loose_map(dir, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
- insert_loose_map(dir, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
- insert_loose_map(dir, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
+ insert_loose_map(alternate, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
+ insert_loose_map(alternate, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
+ insert_loose_map(alternate, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
repo_common_path_replace(repo, &path, "objects/loose-object-idx");
fp = fopen(path.buf, "rb");
@@ -93,7 +93,7 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
parse_oid_hex_algop(p, &compat_oid, &p, repo->compat_hash_algo) ||
p != buf.buf + buf.len)
goto err;
- insert_loose_map(dir, &oid, &compat_oid);
+ insert_loose_map(alternate, &oid, &compat_oid);
}
strbuf_release(&buf);
@@ -107,15 +107,15 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
int repo_read_loose_object_map(struct repository *repo)
{
- struct object_directory *dir;
+ struct odb_alternate *alternate;
if (!should_use_loose_object_map(repo))
return 0;
prepare_alt_odb(repo);
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- if (load_one_loose_object_map(repo, dir) < 0) {
+ for (alternate = repo->objects->alternates; alternate; alternate = alternate->next) {
+ if (load_one_loose_object_map(repo, alternate) < 0) {
return -1;
}
}
@@ -124,7 +124,7 @@ int repo_read_loose_object_map(struct repository *repo)
int repo_write_loose_object_map(struct repository *repo)
{
- kh_oid_map_t *map = repo->objects->odb->loose_map->to_compat;
+ kh_oid_map_t *map = repo->objects->alternates->loose_map->to_compat;
struct lock_file lock;
int fd;
khiter_t iter;
@@ -212,7 +212,7 @@ int repo_add_loose_object_map(struct repository *repo, const struct object_id *o
if (!should_use_loose_object_map(repo))
return 0;
- inserted = insert_loose_map(repo->objects->odb, oid, compat_oid);
+ inserted = insert_loose_map(repo->objects->alternates, oid, compat_oid);
if (inserted)
return write_one_object(repo, oid, compat_oid);
return 0;
@@ -223,12 +223,12 @@ int repo_loose_object_map_oid(struct repository *repo,
const struct git_hash_algo *to,
struct object_id *dest)
{
- struct object_directory *dir;
+ struct odb_alternate *alternate;
kh_oid_map_t *map;
khiter_t pos;
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- struct loose_object_map *loose_map = dir->loose_map;
+ for (alternate = repo->objects->alternates; alternate; alternate = alternate->next) {
+ struct loose_object_map *loose_map = alternate->loose_map;
if (!loose_map)
continue;
map = (to == repo->compat_hash_algo) ?
diff --git a/midx.c b/midx.c
index 3d0015f7828..c1adff4404e 100644
--- a/midx.c
+++ b/midx.c
@@ -824,7 +824,7 @@ void clear_midx_file(struct repository *r)
{
struct strbuf midx = STRBUF_INIT;
- get_midx_filename(r->hash_algo, &midx, r->objects->odb->path);
+ get_midx_filename(r->hash_algo, &midx, r->objects->alternates->path);
if (r->objects && r->objects->multi_pack_index) {
close_midx(r->objects->multi_pack_index);
@@ -834,8 +834,8 @@ void clear_midx_file(struct repository *r)
if (remove_path(midx.buf))
die(_("failed to clear multi-pack-index at %s"), midx.buf);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_BITMAP, NULL);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_REV, NULL);
+ clear_midx_files_ext(r->objects->alternates->path, MIDX_EXT_BITMAP, NULL);
+ clear_midx_files_ext(r->objects->alternates->path, MIDX_EXT_REV, NULL);
strbuf_release(&midx);
}
diff --git a/object-file.c b/object-file.c
index dc56a4766df..e48d968c0e0 100644
--- a/object-file.c
+++ b/object-file.c
@@ -55,12 +55,12 @@ static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
}
}
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_alternate *alternate,
struct strbuf *buf,
const struct object_id *oid)
{
strbuf_reset(buf);
- strbuf_addstr(buf, odb->path);
+ strbuf_addstr(buf, alternate->path);
strbuf_addch(buf, '/');
fill_loose_path(buf, oid);
return buf->buf;
@@ -88,27 +88,27 @@ int check_and_freshen_file(const char *fn, int freshen)
return 1;
}
-static int check_and_freshen_odb(struct object_directory *odb,
+static int check_and_freshen_odb(struct odb_alternate *alternate,
const struct object_id *oid,
int freshen)
{
static struct strbuf path = STRBUF_INIT;
- odb_loose_path(odb, &path, oid);
+ odb_loose_path(alternate, &path, oid);
return check_and_freshen_file(path.buf, freshen);
}
static int check_and_freshen_local(const struct object_id *oid, int freshen)
{
- return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
+ return check_and_freshen_odb(the_repository->objects->alternates, oid, freshen);
}
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
- if (check_and_freshen_odb(odb, oid, freshen))
+ for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
+ if (check_and_freshen_odb(alternate, oid, freshen))
return 1;
}
return 0;
@@ -208,12 +208,12 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct stat *st, const char **path)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ *path = odb_loose_path(alternate, &buf, oid);
if (!lstat(*path, st))
return 0;
}
@@ -229,13 +229,13 @@ static int open_loose_object(struct repository *r,
const struct object_id *oid, const char **path)
{
int fd;
- struct object_directory *odb;
+ struct odb_alternate *alternate;
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ *path = odb_loose_path(alternate, &buf, oid);
fd = git_open(*path);
if (fd >= 0)
return fd;
@@ -250,11 +250,11 @@ static int open_loose_object(struct repository *r,
static int quick_has_loose(struct repository *r,
const struct object_id *oid)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- if (oidtree_contains(odb_loose_cache(odb, oid), oid))
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ if (oidtree_contains(odb_loose_cache(alternate, oid), oid))
return 1;
}
return 0;
@@ -750,7 +750,7 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
/* Finalize a file on disk, and close it. */
static void close_loose_object(int fd, const char *filename)
{
- if (the_repository->objects->odb->will_destroy)
+ if (the_repository->objects->alternates->will_destroy)
goto out;
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
@@ -932,7 +932,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
prepare_loose_object_bulk_checkin();
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->alternates, &filename, oid);
fd = start_loose_object_common(&tmp_file, filename.buf, flags,
&stream, compressed, sizeof(compressed),
@@ -1079,7 +1079,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
goto cleanup;
}
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->alternates, &filename, oid);
/* We finally know the object path, and create the missing dir. */
dirlen = directory_size(filename.buf);
@@ -1540,11 +1540,11 @@ int for_each_loose_file_in_objdir(const char *path,
int for_each_loose_object(each_loose_object_fn cb, void *data,
enum for_each_object_flags flags)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
- int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
+ int r = for_each_loose_file_in_objdir(alternate->path, cb, NULL,
NULL, data);
if (r)
return r;
@@ -1564,43 +1564,43 @@ static int append_loose_object(const struct object_id *oid,
return 0;
}
-struct oidtree *odb_loose_cache(struct object_directory *odb,
- const struct object_id *oid)
+struct oidtree *odb_loose_cache(struct odb_alternate *alternate,
+ const struct object_id *oid)
{
int subdir_nr = oid->hash[0];
struct strbuf buf = STRBUF_INIT;
- size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
+ size_t word_bits = bitsizeof(alternate->loose_objects_subdir_seen[0]);
size_t word_index = subdir_nr / word_bits;
size_t mask = (size_t)1u << (subdir_nr % word_bits);
uint32_t *bitmap;
if (subdir_nr < 0 ||
- subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
+ subdir_nr >= bitsizeof(alternate->loose_objects_subdir_seen))
BUG("subdir_nr out of range");
- bitmap = &odb->loose_objects_subdir_seen[word_index];
+ bitmap = &alternate->loose_objects_subdir_seen[word_index];
if (*bitmap & mask)
- return odb->loose_objects_cache;
- if (!odb->loose_objects_cache) {
- ALLOC_ARRAY(odb->loose_objects_cache, 1);
- oidtree_init(odb->loose_objects_cache);
+ return alternate->loose_objects_cache;
+ if (!alternate->loose_objects_cache) {
+ ALLOC_ARRAY(alternate->loose_objects_cache, 1);
+ oidtree_init(alternate->loose_objects_cache);
}
- strbuf_addstr(&buf, odb->path);
+ strbuf_addstr(&buf, alternate->path);
for_each_file_in_obj_subdir(subdir_nr, &buf,
append_loose_object,
NULL, NULL,
- odb->loose_objects_cache);
+ alternate->loose_objects_cache);
*bitmap |= mask;
strbuf_release(&buf);
- return odb->loose_objects_cache;
+ return alternate->loose_objects_cache;
}
-void odb_clear_loose_cache(struct object_directory *odb)
+void odb_clear_loose_cache(struct odb_alternate *alternate)
{
- oidtree_clear(odb->loose_objects_cache);
- FREE_AND_NULL(odb->loose_objects_cache);
- memset(&odb->loose_objects_subdir_seen, 0,
- sizeof(odb->loose_objects_subdir_seen));
+ oidtree_clear(alternate->loose_objects_cache);
+ FREE_AND_NULL(alternate->loose_objects_cache);
+ memset(&alternate->loose_objects_subdir_seen, 0,
+ sizeof(alternate->loose_objects_subdir_seen));
}
static int check_stream_oid(git_zstream *stream,
diff --git a/object-file.h b/object-file.h
index a85b2e5b494..f1601200938 100644
--- a/object-file.h
+++ b/object-file.h
@@ -24,23 +24,23 @@ enum {
int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
-struct object_directory;
+struct odb_alternate;
/*
* Populate and return the loose object cache array corresponding to the
* given object ID.
*/
-struct oidtree *odb_loose_cache(struct object_directory *odb,
+struct oidtree *odb_loose_cache(struct odb_alternate *alternate,
const struct object_id *oid);
/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
+void odb_clear_loose_cache(struct odb_alternate *alternate);
/*
* Put in `buf` the name of the file in the local object database that
* would be used to store a loose object with the specified oid.
*/
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_alternate *alternate,
struct strbuf *buf,
const struct object_id *oid);
diff --git a/object-name.c b/object-name.c
index 9288b2dd245..b83ba882b9e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -112,10 +112,10 @@ static enum cb_next match_prefix(const struct object_id *oid, void *arg)
static void find_short_object_filename(struct disambiguate_state *ds)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
- for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next)
- oidtree_each(odb_loose_cache(odb, &ds->bin_pfx),
+ for (alternate = ds->repo->objects->alternates; alternate && !ds->ambiguous; alternate = alternate->next)
+ oidtree_each(odb_loose_cache(alternate, &ds->bin_pfx),
&ds->bin_pfx, ds->len, match_prefix, ds);
}
diff --git a/object-store.c b/object-store.c
index 1effcb12273..673a9c6006b 100644
--- a/object-store.c
+++ b/object-store.c
@@ -27,7 +27,7 @@
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
- struct object_directory *, 1, fspathhash, fspatheq)
+ struct odb_alternate *, 1, fspathhash, fspatheq)
/*
* This is meant to hold a *small* number of objects that you would
@@ -104,18 +104,18 @@ static int alt_odb_usable(struct object_database *o,
* Prevent the common mistake of listing the same
* thing twice, or object directory itself.
*/
- if (!o->odb_by_path) {
+ if (!o->alternate_by_path) {
khiter_t p;
- o->odb_by_path = kh_init_odb_path_map();
- assert(!o->odb->next);
- p = kh_put_odb_path_map(o->odb_by_path, o->odb->path, &r);
+ o->alternate_by_path = kh_init_odb_path_map();
+ assert(!o->alternates->next);
+ p = kh_put_odb_path_map(o->alternate_by_path, o->alternates->path, &r);
assert(r == 1); /* never used */
- kh_value(o->odb_by_path, p) = o->odb;
+ kh_value(o->alternate_by_path, p) = o->alternates;
}
if (fspatheq(path->buf, normalized_objdir))
return 0;
- *pos = kh_put_odb_path_map(o->odb_by_path, path->buf, &r);
+ *pos = kh_put_odb_path_map(o->alternate_by_path, path->buf, &r);
/* r: 0 = exists, 1 = never used, 2 = deleted */
return r == 0 ? 0 : 1;
}
@@ -124,7 +124,7 @@ static int alt_odb_usable(struct object_database *o,
* Prepare alternate object database registry.
*
* The variable alt_odb_list points at the list of struct
- * object_directory. The elements on this list come from
+ * odb_alternate. The elements on this list come from
* non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
* environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
* whose contents is similar to that environment variable but can be
@@ -141,7 +141,7 @@ static void read_info_alternates(struct repository *r,
static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
const char *relative_base, int depth, const char *normalized_objdir)
{
- struct object_directory *ent;
+ struct odb_alternate *alternate;
struct strbuf pathbuf = STRBUF_INIT;
struct strbuf tmp = STRBUF_INIT;
khiter_t pos;
@@ -170,19 +170,19 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
goto error;
- CALLOC_ARRAY(ent, 1);
- /* pathbuf.buf is already in r->objects->odb_by_path */
- ent->path = strbuf_detach(&pathbuf, NULL);
+ CALLOC_ARRAY(alternate, 1);
+ /* pathbuf.buf is already in r->objects->alternate_by_path */
+ alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->odb_tail = ent;
- r->objects->odb_tail = &(ent->next);
- ent->next = NULL;
- assert(r->objects->odb_by_path);
- kh_value(r->objects->odb_by_path, pos) = ent;
+ *r->objects->alternates_tail = alternate;
+ r->objects->alternates_tail = &(alternate->next);
+ alternate->next = NULL;
+ assert(r->objects->alternate_by_path);
+ kh_value(r->objects->alternate_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, ent->path, depth + 1);
+ read_info_alternates(r, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -234,7 +234,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->odb->path, 1);
+ strbuf_realpath(&objdirbuf, r->objects->alternates->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
@@ -321,9 +321,9 @@ void add_to_alternates_memory(const char *reference)
'\n', NULL, 0);
}
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy)
{
- struct object_directory *new_odb;
+ struct odb_alternate *alternate;
/*
* Make sure alternates are initialized, or else our entry may be
@@ -335,41 +335,41 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
- new_odb = xcalloc(1, sizeof(*new_odb));
- new_odb->path = xstrdup(dir);
+ alternate = xcalloc(1, sizeof(*alternate));
+ alternate->path = xstrdup(dir);
/*
* Disable ref updates while a temporary odb is active, since
* the objects in the database may roll back.
*/
- new_odb->disable_ref_updates = 1;
- new_odb->will_destroy = will_destroy;
- new_odb->next = the_repository->objects->odb;
- the_repository->objects->odb = new_odb;
- return new_odb->next;
+ alternate->disable_ref_updates = 1;
+ alternate->will_destroy = will_destroy;
+ alternate->next = the_repository->objects->alternates;
+ the_repository->objects->alternates = alternate;
+ return alternate->next;
}
-static void free_object_directory(struct object_directory *odb)
+static void free_object_directory(struct odb_alternate *alternate)
{
- free(odb->path);
- odb_clear_loose_cache(odb);
- loose_object_map_clear(&odb->loose_map);
- free(odb);
+ free(alternate->path);
+ odb_clear_loose_cache(alternate);
+ loose_object_map_clear(&alternate->loose_map);
+ free(alternate);
}
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
+void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path)
{
- struct object_directory *cur_odb = the_repository->objects->odb;
+ struct odb_alternate *cur_alt = the_repository->objects->alternates;
- if (strcmp(old_path, cur_odb->path))
+ if (strcmp(old_path, cur_alt->path))
BUG("expected %s as primary object store; found %s",
- old_path, cur_odb->path);
+ old_path, cur_alt->path);
- if (cur_odb->next != restore_odb)
+ if (cur_alt->next != restore_alt)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->odb = restore_odb;
- free_object_directory(cur_odb);
+ the_repository->objects->alternates = restore_alt;
+ free_object_directory(cur_alt);
}
/*
@@ -442,15 +442,15 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct object_directory *find_odb(struct repository *r, const char *obj_dir)
+struct odb_alternate *find_odb(struct repository *r, const char *obj_dir)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- strbuf_realpath(&odb_path_real, odb->path, 1);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ strbuf_realpath(&odb_path_real, alternate->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
}
@@ -458,9 +458,9 @@ struct object_directory *find_odb(struct repository *r, const char *obj_dir)
free(obj_dir_real);
strbuf_release(&odb_path_real);
- if (!odb)
+ if (!alternate)
die(_("could not find object directory matching %s"), obj_dir);
- return odb;
+ return alternate;
}
static void fill_alternate_refs_command(struct child_process *cmd,
@@ -527,14 +527,14 @@ struct alternate_refs_data {
void *data;
};
-static int refs_from_alternate_cb(struct object_directory *e,
+static int refs_from_alternate_cb(struct odb_alternate *alternate,
void *data)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
struct alternate_refs_data *cb = data;
- if (!strbuf_realpath(&path, e->path, 0))
+ if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
if (!strbuf_strip_suffix(&path, "/objects"))
goto out;
@@ -563,12 +563,12 @@ void for_each_alternate_ref(alternate_ref_fn fn, void *data)
int foreach_alt_odb(alt_odb_fn fn, void *cb)
{
- struct object_directory *ent;
+ struct odb_alternate *alternate;
int r = 0;
prepare_alt_odb(the_repository);
- for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {
- r = fn(ent, cb);
+ for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
+ r = fn(alternate, cb);
if (r)
break;
}
@@ -582,14 +582,14 @@ void prepare_alt_odb(struct repository *r)
link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->odb->path, 0);
+ read_info_alternates(r, r->objects->alternates->path, 0);
r->objects->loaded_alternates = 1;
}
int has_alt_odb(struct repository *r)
{
prepare_alt_odb(r);
- return !!r->objects->odb->next;
+ return !!r->objects->alternates->next;
}
int obj_read_use_lock = 0;
@@ -972,15 +972,15 @@ struct object_database *odb_new(void)
static void free_object_directories(struct object_database *o)
{
- while (o->odb) {
- struct object_directory *next;
+ while (o->alternates) {
+ struct odb_alternate *next;
- next = o->odb->next;
- free_object_directory(o->odb);
- o->odb = next;
+ next = o->alternates->next;
+ free_object_directory(o->alternates);
+ o->alternates = next;
}
- kh_destroy_odb_path_map(o->odb_by_path);
- o->odb_by_path = NULL;
+ kh_destroy_odb_path_map(o->alternate_by_path);
+ o->alternate_by_path = NULL;
}
void odb_clear(struct object_database *o)
@@ -996,7 +996,7 @@ void odb_clear(struct object_database *o)
o->commit_graph_attempted = 0;
free_object_directories(o);
- o->odb_tail = NULL;
+ o->alternates_tail = NULL;
o->loaded_alternates = 0;
for (size_t i = 0; i < o->cached_object_nr; i++)
diff --git a/object-store.h b/object-store.h
index 34b8efbbb83..6dc39376141 100644
--- a/object-store.h
+++ b/object-store.h
@@ -12,8 +12,14 @@ struct oidtree;
struct strbuf;
struct repository;
-struct object_directory {
- struct object_directory *next;
+/*
+ * The alternate is the part of the object database that stores the actual
+ * objects. It thus encapsulates the logic to read and write the specific
+ * on-disk format. An object database can have multiple alternates, and
+ * exactly one primary alternate that is used when writing new objects.
+ */
+struct odb_alternate {
+ struct odb_alternate *next;
/*
* Used to store the results of readdir(3) calls when we are OK
@@ -52,8 +58,8 @@ struct object_directory {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
+struct odb_alternate *find_odb(struct repository *r, const char *obj_dir);
+typedef int alt_odb_fn(struct odb_alternate *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
@@ -75,12 +81,12 @@ void add_to_alternates_memory(const char *dir);
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
*/
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy);
/*
* Restore a previous ODB replaced by set_temporary_main_odb.
*/
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+void restore_primary_odb(struct odb_alternate *restore_alternate, const char *old_path);
struct packed_git;
struct multi_pack_index;
@@ -88,7 +94,7 @@ struct cached_object_entry;
/*
* The object database encapsulates access to objects in a repository. It
- * manages one or more backends that store the actual objects which are
+ * manages one or more alternates that store the actual objects which are
* configured via alternates.
*/
struct object_database {
@@ -97,16 +103,16 @@ struct object_database {
* cannot be NULL after initialization). Subsequent directories are
* alternates.
*/
- struct object_directory *odb;
- struct object_directory **odb_tail;
- struct kh_odb_path_map *odb_by_path;
+ struct odb_alternate *alternates;
+ struct odb_alternate **alternates_tail;
+ struct kh_odb_path_map *alternate_by_path;
int loaded_alternates;
/*
* 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.
+ * populate the "alternates" list when prepare_alt_odb() is run.
*/
char *alternate_db;
diff --git a/packfile.c b/packfile.c
index 8f51665266d..e31e55f0c02 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1018,16 +1018,16 @@ static void prepare_packed_git_mru(struct repository *r)
static void prepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
if (r->objects->packed_git_initialized)
return;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- int local = (odb == r->objects->odb);
- prepare_multi_pack_index_one(r, odb->path, local);
- prepare_packed_git_one(r, odb->path, local);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ int local = (alternate == r->objects->alternates);
+ prepare_multi_pack_index_one(r, alternate->path, local);
+ prepare_packed_git_one(r, alternate->path, local);
}
rearrange_packed_git(r);
@@ -1037,7 +1037,7 @@ static void prepare_packed_git(struct repository *r)
void reprepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_alternate *alternate;
obj_read_lock();
@@ -1050,8 +1050,8 @@ void reprepare_packed_git(struct repository *r)
r->objects->loaded_alternates = 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next)
- odb_clear_loose_cache(odb);
+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next)
+ odb_clear_loose_cache(alternate);
r->objects->approximate_object_count_valid = 0;
r->objects->packed_git_initialized = 0;
diff --git a/path.c b/path.c
index 3b598b2847f..7be0e0214df 100644
--- a/path.c
+++ b/path.c
@@ -397,7 +397,7 @@ static void adjust_git_path(struct repository *repo,
strbuf_splice(buf, 0, buf->len,
repo->index_file, strlen(repo->index_file));
else if (dir_prefix(base, "objects"))
- replace_dir(buf, git_dir_len + 7, repo->objects->odb->path);
+ replace_dir(buf, git_dir_len + 7, repo->objects->alternates->path);
else if (repo_settings_get_hooks_path(repo) && dir_prefix(base, "hooks"))
replace_dir(buf, git_dir_len + 5, repo_settings_get_hooks_path(repo));
else if (repo->different_commondir)
diff --git a/refs.c b/refs.c
index dce5c49ca2b..27325d2f3c6 100644
--- a/refs.c
+++ b/refs.c
@@ -2477,7 +2477,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
break;
}
- if (refs->repo->objects->odb->disable_ref_updates) {
+ if (refs->repo->objects->alternates->disable_ref_updates) {
strbuf_addstr(err,
_("ref updates forbidden inside quarantine environment"));
return -1;
diff --git a/repository.c b/repository.c
index 07757e6e0c9..dcc03fd9e0a 100644
--- a/repository.c
+++ b/repository.c
@@ -107,9 +107,9 @@ const char *repo_get_common_dir(struct repository *repo)
const char *repo_get_object_directory(struct repository *repo)
{
- if (!repo->objects->odb)
+ if (!repo->objects->alternates)
BUG("repository hasn't been set up");
- return repo->objects->odb->path;
+ return repo->objects->alternates->path;
}
const char *repo_get_index_file(struct repository *repo)
@@ -165,14 +165,14 @@ void repo_set_gitdir(struct repository *repo,
repo_set_commondir(repo, o->commondir);
- if (!repo->objects->odb) {
- CALLOC_ARRAY(repo->objects->odb, 1);
- repo->objects->odb_tail = &repo->objects->odb->next;
+ if (!repo->objects->alternates) {
+ CALLOC_ARRAY(repo->objects->alternates, 1);
+ repo->objects->alternates_tail = &repo->objects->alternates->next;
}
- expand_base_dir(&repo->objects->odb->path, o->object_dir,
+ expand_base_dir(&repo->objects->alternates->path, o->object_dir,
repo->commondir, "objects");
- repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
+ repo->objects->alternates->disable_ref_updates = o->disable_ref_updates;
free(repo->objects->alternate_db);
repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
diff --git a/submodule-config.c b/submodule-config.c
index 8630e27947d..0ee0a2884ef 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->odb->path);
+ add_submodule_odb_by_path(repo->objects->alternates->path);
} else {
goto out;
}
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 8b413b644be..cd8ba0c54e7 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -73,15 +73,15 @@ static void dump_graph_bloom_filters(struct commit_graph *graph)
int cmd__read_graph(int argc, const char **argv)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb;
+ struct odb_alternate *alternate;
int ret = 0;
setup_git_directory();
- odb = the_repository->objects->odb;
+ alternate = the_repository->objects->alternates;
prepare_repo_settings(the_repository);
- graph = read_commit_graph_one(the_repository, odb);
+ graph = read_commit_graph_one(the_repository, alternate);
if (!graph) {
ret = 1;
goto done;
diff --git a/tmp-objdir.c b/tmp-objdir.c
index c38fbeb5e8a..b8fe0fdd7d4 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -17,7 +17,7 @@ struct tmp_objdir {
struct repository *repo;
struct strbuf path;
struct strvec env;
- struct object_directory *prev_odb;
+ struct odb_alternate *prev_alt;
int will_destroy;
};
@@ -46,8 +46,8 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
if (t == the_tmp_objdir)
the_tmp_objdir = NULL;
- if (t->prev_odb)
- restore_primary_odb(t->prev_odb, t->path.buf);
+ if (t->prev_alt)
+ restore_primary_odb(t->prev_alt, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -276,11 +276,11 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (!t)
return 0;
- if (t->prev_odb) {
- if (t->repo->objects->odb->will_destroy)
+ if (t->prev_alt) {
+ if (t->repo->objects->alternates->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_odb, t->path.buf);
- t->prev_odb = NULL;
+ restore_primary_odb(t->prev_alt, t->path.buf);
+ t->prev_alt = NULL;
}
strbuf_addbuf(&src, &t->path);
@@ -309,19 +309,19 @@ void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
- if (t->prev_odb)
+ if (t->prev_alt)
BUG("the primary object database is already replaced");
- t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_alt = set_temporary_primary_odb(t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
{
- if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
+ if (!the_tmp_objdir || !the_tmp_objdir->prev_alt)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
- the_tmp_objdir->prev_odb = NULL;
+ restore_primary_odb(the_tmp_objdir->prev_alt, the_tmp_objdir->path.buf);
+ the_tmp_objdir->prev_alt = NULL;
return the_tmp_objdir;
}
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v3 02/17] object-store: rename `object_directory` to `odb_alternate`
2025-05-14 5:12 ` [PATCH v3 02/17] object-store: rename `object_directory` to `odb_alternate` Patrick Steinhardt
@ 2025-05-22 22:13 ` Justin Tobler
2025-05-26 5:45 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Justin Tobler @ 2025-05-22 22:13 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On 25/05/14 07:12AM, Patrick Steinhardt wrote:
> The `object_directory` structure is used as an access point for a single
> object directory like ".git/objects". While the structure isn't yet
> fully self-contained, the intent is for it to eventually contain all
> information required to access objects in one specific location.
>
> While the name "object directory" is a good fit for now, this will
> change over time as we continue with the agenda to make pluggable object
> databases a thing. Eventually, objects may not be accessed via any kind
> of directory at all anymore, but they could instead be backed by any
> kind of durable storage mechanism. While it seems quite far-fetched for
> now, it is thinkable that eventually this might even be some form of a
> database, for example.
>
> As such, the current name of this structure will become worse over time
> as we evolve into the direction of pluggable ODBs. Immediate next steps
> will start to carve out proper self-contained object directories, which
> requires us to pass in these object directories as parameters. Based on
> our modern naming schema this means that those functions should then be
> named after their subsystem, which means that we would start to bake the
> current name into the codebase more and more.
>
> Let's preempt this by renaming the structure to `odb_alternate` now
> already. This name is agnostic of how exactly objects are stored while
> still specifically pinpointing that this is about an alternate object
> database. Furthermore, it is already used in Git to represent this
> context -- the only stretch is that the primary object directory is now
> the primary alternate.
I know the naming here has been discussed in other threads, but
`odb_alternate` doesn't feel quite right to me. When I think of an
object database alternate, I think of the additional object sources that
may be configured for a repository.
From my understanding, the `odb_alternate` here applies to any object
source, even the main one. Using "alternate" makes me think there is
another object database somewhere which may be confusing in scenarios
where there would only be one.
Ultimately I don't want to bikeshed too much on names, but wanted to
voice my thoughts. As an alternative to "alternate", maybe we could do
`object_source`? :)
> In the future, this change allows us to easily introduce for example a
> `odb_files_alternate` and other format-specific implementations.
I look forward to seeing this. The patch itself looks good.
-Justin
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v3 02/17] object-store: rename `object_directory` to `odb_alternate`
2025-05-22 22:13 ` Justin Tobler
@ 2025-05-26 5:45 ` Patrick Steinhardt
2025-05-27 16:45 ` Justin Tobler
0 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-26 5:45 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On Thu, May 22, 2025 at 05:13:55PM -0500, Justin Tobler wrote:
> On 25/05/14 07:12AM, Patrick Steinhardt wrote:
> > The `object_directory` structure is used as an access point for a single
> > object directory like ".git/objects". While the structure isn't yet
> > fully self-contained, the intent is for it to eventually contain all
> > information required to access objects in one specific location.
> >
> > While the name "object directory" is a good fit for now, this will
> > change over time as we continue with the agenda to make pluggable object
> > databases a thing. Eventually, objects may not be accessed via any kind
> > of directory at all anymore, but they could instead be backed by any
> > kind of durable storage mechanism. While it seems quite far-fetched for
> > now, it is thinkable that eventually this might even be some form of a
> > database, for example.
> >
> > As such, the current name of this structure will become worse over time
> > as we evolve into the direction of pluggable ODBs. Immediate next steps
> > will start to carve out proper self-contained object directories, which
> > requires us to pass in these object directories as parameters. Based on
> > our modern naming schema this means that those functions should then be
> > named after their subsystem, which means that we would start to bake the
> > current name into the codebase more and more.
> >
> > Let's preempt this by renaming the structure to `odb_alternate` now
> > already. This name is agnostic of how exactly objects are stored while
> > still specifically pinpointing that this is about an alternate object
> > database. Furthermore, it is already used in Git to represent this
> > context -- the only stretch is that the primary object directory is now
> > the primary alternate.
>
> I know the naming here has been discussed in other threads, but
> `odb_alternate` doesn't feel quite right to me. When I think of an
> object database alternate, I think of the additional object sources that
> may be configured for a repository.
>
> From my understanding, the `odb_alternate` here applies to any object
> source, even the main one. Using "alternate" makes me think there is
> another object database somewhere which may be confusing in scenarios
> where there would only be one.
Yeah, I do get that. On the other hand I don't think it's too much of a
stretch: the local object directory of one repository is another repo's
alternate. Furthermore, we already do have the distinction between
"local" and "non-local" objects, which translates quite well into this
new naming schema.
> Ultimately I don't want to bikeshed too much on names, but wanted to
> voice my thoughts. As an alternative to "alternate", maybe we could do
> `object_source`? :)
If we were picking something more "generic" I'd favor `odb_backend` over
`object_source`, to be honest. But we have agreed in the previous
version of this patch series that this isn't the way to go.
So I'm not quite convinced that `object_source` is better, and if we
were to go this way I'd also rather call it `odb_source`. If others
agree that `odb_source` is better than `odb_alternate` I'm happy to
adapt. But until then I'd rather leave things as-is.
Thanks!
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v3 02/17] object-store: rename `object_directory` to `odb_alternate`
2025-05-26 5:45 ` Patrick Steinhardt
@ 2025-05-27 16:45 ` Justin Tobler
2025-05-28 13:18 ` Toon Claes
2025-05-30 9:39 ` Patrick Steinhardt
0 siblings, 2 replies; 166+ messages in thread
From: Justin Tobler @ 2025-05-27 16:45 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On 25/05/26 07:45AM, Patrick Steinhardt wrote:
> On Thu, May 22, 2025 at 05:13:55PM -0500, Justin Tobler wrote:
> > On 25/05/14 07:12AM, Patrick Steinhardt wrote:
> > > The `object_directory` structure is used as an access point for a single
> > > object directory like ".git/objects". While the structure isn't yet
> > > fully self-contained, the intent is for it to eventually contain all
> > > information required to access objects in one specific location.
> > >
> > > While the name "object directory" is a good fit for now, this will
> > > change over time as we continue with the agenda to make pluggable object
> > > databases a thing. Eventually, objects may not be accessed via any kind
> > > of directory at all anymore, but they could instead be backed by any
> > > kind of durable storage mechanism. While it seems quite far-fetched for
> > > now, it is thinkable that eventually this might even be some form of a
> > > database, for example.
> > >
> > > As such, the current name of this structure will become worse over time
> > > as we evolve into the direction of pluggable ODBs. Immediate next steps
> > > will start to carve out proper self-contained object directories, which
> > > requires us to pass in these object directories as parameters. Based on
> > > our modern naming schema this means that those functions should then be
> > > named after their subsystem, which means that we would start to bake the
> > > current name into the codebase more and more.
> > >
> > > Let's preempt this by renaming the structure to `odb_alternate` now
> > > already. This name is agnostic of how exactly objects are stored while
> > > still specifically pinpointing that this is about an alternate object
> > > database. Furthermore, it is already used in Git to represent this
> > > context -- the only stretch is that the primary object directory is now
> > > the primary alternate.
> >
> > I know the naming here has been discussed in other threads, but
> > `odb_alternate` doesn't feel quite right to me. When I think of an
> > object database alternate, I think of the additional object sources that
> > may be configured for a repository.
> >
> > From my understanding, the `odb_alternate` here applies to any object
> > source, even the main one. Using "alternate" makes me think there is
> > another object database somewhere which may be confusing in scenarios
> > where there would only be one.
>
> Yeah, I do get that. On the other hand I don't think it's too much of a
> stretch: the local object directory of one repository is another repo's
> alternate.
Ok, I was only thinking about this from the perspective of the
repository we would be operating in. But I can sort of see how any odb
can be an alternate from the perspective of a different repository.
> Furthermore, we already do have the distinction between
> "local" and "non-local" objects, which translates quite well into this
> new naming schema.
Just to clarify, are you referring to how we differentiate between local
and alternate odbs? I'm not quite sure I fully understand.
>
> > Ultimately I don't want to bikeshed too much on names, but wanted to
> > voice my thoughts. As an alternative to "alternate", maybe we could do
> > `object_source`? :)
>
> If we were picking something more "generic" I'd favor `odb_backend` over
> `object_source`, to be honest. But we have agreed in the previous
> version of this patch series that this isn't the way to go.
>
> So I'm not quite convinced that `object_source` is better, and if we
> were to go this way I'd also rather call it `odb_source`. If others
> agree that `odb_source` is better than `odb_alternate` I'm happy to
> adapt. But until then I'd rather leave things as-is.
That's fair. Between `odb_backend` and `odb_alternate`, I would probably
still prefer the former, but ultimately I'll acclimate to whatever is
choosen. :)
-Justin
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v3 02/17] object-store: rename `object_directory` to `odb_alternate`
2025-05-27 16:45 ` Justin Tobler
@ 2025-05-28 13:18 ` Toon Claes
2025-05-30 9:39 ` Patrick Steinhardt
2025-05-30 9:39 ` Patrick Steinhardt
1 sibling, 1 reply; 166+ messages in thread
From: Toon Claes @ 2025-05-28 13:18 UTC (permalink / raw)
To: Justin Tobler, Patrick Steinhardt; +Cc: git, Derrick Stolee, Junio C Hamano
Justin Tobler <jltobler@gmail.com> writes:
> That's fair. Between `odb_backend` and `odb_alternate`, I would probably
> still prefer the former, but ultimately I'll acclimate to whatever is
> choosen. :)
>
> -Justin
I feel you. But speaking as a non-native English-speaking person, I can
settle for "alternate" because I can still wire my brain to give it the
meaning we're using here.
But if you like another name, I want to steer away from "backend" as
well. As mentioned elsewhere, a "backend" sounds like an implementation
of an object database, not the instance of an odb. But I'm open to other
suggestions. I've been browsing thesaurus for a bit, unfortunately I
didn't find anything better.
--
Cheers,
Toon
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v3 02/17] object-store: rename `object_directory` to `odb_alternate`
2025-05-28 13:18 ` Toon Claes
@ 2025-05-30 9:39 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-30 9:39 UTC (permalink / raw)
To: Toon Claes; +Cc: Justin Tobler, git, Derrick Stolee, Junio C Hamano
On Wed, May 28, 2025 at 03:18:22PM +0200, Toon Claes wrote:
> Justin Tobler <jltobler@gmail.com> writes:
>
> > That's fair. Between `odb_backend` and `odb_alternate`, I would probably
> > still prefer the former, but ultimately I'll acclimate to whatever is
> > choosen. :)
> >
> > -Justin
>
> I feel you. But speaking as a non-native English-speaking person, I can
> settle for "alternate" because I can still wire my brain to give it the
> meaning we're using here.
>
> But if you like another name, I want to steer away from "backend" as
> well. As mentioned elsewhere, a "backend" sounds like an implementation
> of an object database, not the instance of an odb. But I'm open to other
> suggestions. I've been browsing thesaurus for a bit, unfortunately I
> didn't find anything better.
This ultimately _will_ host the backend implementations -- every
alternate is backed by one specific backend. The problem why we still
wanted to steer away from "backend" is that `odb_backend` rather sounds
as if the complete object database has one backend that can be switched.
That's why we settled on "alternate" instead, to clarify that there is
not a 1:1 relationship between the object database and the respective
backends.
`odb_source` does not have the same problem as `odb_backend`, so I
definitely think it's a way better name. But the reason why I think that
"alternate" is the better name is that I think it will get quite
confusing if we have both the terms "alternate" and "source". It would
make some of the interfaces quite awkward because it wouldn't always be
clear what exactly we are handling at any point in time.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v3 02/17] object-store: rename `object_directory` to `odb_alternate`
2025-05-27 16:45 ` Justin Tobler
2025-05-28 13:18 ` Toon Claes
@ 2025-05-30 9:39 ` Patrick Steinhardt
1 sibling, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-30 9:39 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On Tue, May 27, 2025 at 11:45:14AM -0500, Justin Tobler wrote:
> On 25/05/26 07:45AM, Patrick Steinhardt wrote:
> > Furthermore, we already do have the distinction between
> > "local" and "non-local" objects, which translates quite well into this
> > new naming schema.
>
> Just to clarify, are you referring to how we differentiate between local
> and alternate odbs? I'm not quite sure I fully understand.
Yeah. Non-local objects come from an alternate object directory, whereas
local objects come from the primary object directory.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v3 03/17] object-store: rename files to "odb.{c,h}"
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 02/17] object-store: rename `object_directory` to `odb_alternate` Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 04/17] odb: introduce parent pointers Patrick Steinhardt
` (14 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
In the preceding commits we have renamed the structures contained in
"object-store.h" to `struct object_database` and `struct odb_backend`.
As such, the code files "object-store.{c,h}" are confusingly named now.
Rename them to "odb.{c,h}" accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Makefile | 2 +-
apply.c | 2 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 2 +-
blame.c | 2 +-
builtin/backfill.c | 2 +-
builtin/blame.c | 2 +-
builtin/cat-file.c | 2 +-
builtin/checkout.c | 2 +-
builtin/clone.c | 2 +-
builtin/commit-graph.c | 2 +-
builtin/commit-tree.c | 2 +-
builtin/describe.c | 2 +-
builtin/difftool.c | 2 +-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 2 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 2 +-
builtin/grep.c | 2 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 2 +-
builtin/log.c | 2 +-
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 2 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 2 +-
builtin/mktag.c | 2 +-
builtin/mktree.c | 2 +-
builtin/multi-pack-index.c | 2 +-
builtin/notes.c | 2 +-
builtin/pack-objects.c | 2 +-
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 2 +-
builtin/receive-pack.c | 2 +-
builtin/remote.c | 2 +-
builtin/repack.c | 2 +-
builtin/replace.c | 2 +-
builtin/rev-list.c | 2 +-
builtin/show-ref.c | 2 +-
builtin/submodule--helper.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 2 +-
bulk-checkin.c | 2 +-
bundle-uri.c | 2 +-
bundle.c | 2 +-
cache-tree.c | 2 +-
combine-diff.c | 2 +-
commit-graph.c | 2 +-
commit-graph.h | 2 +-
commit.c | 2 +-
config.c | 2 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 2 +-
diff.c | 2 +-
entry.c | 2 +-
fetch-pack.c | 2 +-
fmt-merge-msg.c | 2 +-
fsck.c | 2 +-
grep.c | 2 +-
http-backend.c | 2 +-
http-push.c | 2 +-
http-walker.c | 2 +-
http.c | 2 +-
list-objects-filter.c | 2 +-
list-objects.c | 2 +-
loose.c | 2 +-
mailmap.c | 2 +-
match-trees.c | 2 +-
merge-blobs.c | 2 +-
merge-ort.c | 2 +-
meson.build | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 2 +-
object-file.c | 2 +-
object-file.h | 2 +-
object-store.c => odb.c | 2 +-
object-store.h => odb.h | 6 +++---
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 2 +-
pack-bitmap.c | 2 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
packfile.c | 2 +-
packfile.h | 4 ++--
path.c | 2 +-
promisor-remote.c | 2 +-
protocol-caps.c | 2 +-
read-cache.c | 2 +-
ref-filter.c | 2 +-
reflog.c | 2 +-
refs.c | 2 +-
remote.c | 2 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 2 +-
rerere.c | 2 +-
revision.c | 2 +-
send-pack.c | 2 +-
sequencer.c | 2 +-
server-info.c | 2 +-
shallow.c | 2 +-
streaming.c | 2 +-
submodule-config.c | 2 +-
submodule.c | 2 +-
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 2 +-
t/helper/test-read-graph.c | 2 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 2 +-
tag.c | 2 +-
tmp-objdir.c | 2 +-
tree-walk.c | 2 +-
tree.c | 2 +-
unpack-trees.c | 2 +-
upload-pack.c | 2 +-
walker.c | 2 +-
xdiff-interface.c | 2 +-
126 files changed, 129 insertions(+), 129 deletions(-)
diff --git a/Makefile b/Makefile
index 8a7f1c76543..d2d65f30907 100644
--- a/Makefile
+++ b/Makefile
@@ -1083,8 +1083,8 @@ LIB_OBJS += notes.o
LIB_OBJS += object-file-convert.o
LIB_OBJS += object-file.o
LIB_OBJS += object-name.o
-LIB_OBJS += object-store.o
LIB_OBJS += object.o
+LIB_OBJS += odb.o
LIB_OBJS += oid-array.o
LIB_OBJS += oidmap.o
LIB_OBJS += oidset.o
diff --git a/apply.c b/apply.c
index 381d2e3652f..879f04df31e 100644
--- a/apply.c
+++ b/apply.c
@@ -14,7 +14,7 @@
#include "abspath.h"
#include "base85.h"
#include "config.h"
-#include "object-store.h"
+#include "odb.h"
#include "delta.h"
#include "diff.h"
#include "dir.h"
diff --git a/archive-tar.c b/archive-tar.c
index 282b48196f9..249164ea77d 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -11,7 +11,7 @@
#include "hex.h"
#include "tar.h"
#include "archive.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "streaming.h"
#include "run-command.h"
diff --git a/archive-zip.c b/archive-zip.c
index 405da6f3d83..df8866d5bae 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -12,7 +12,7 @@
#include "hex.h"
#include "streaming.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "userdiff.h"
#include "write-or-die.h"
diff --git a/archive.c b/archive.c
index 8309ea213e6..7fa2cc2596a 100644
--- a/archive.c
+++ b/archive.c
@@ -14,7 +14,7 @@
#include "pretty.h"
#include "setup.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 86b6109fc4e..e5680db7f65 100644
--- a/attr.c
+++ b/attr.c
@@ -22,7 +22,7 @@
#include "read-cache-ll.h"
#include "refs.h"
#include "revision.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/bisect.c b/bisect.c
index a327468c75b..a7939216d00 100644
--- a/bisect.c
+++ b/bisect.c
@@ -20,7 +20,7 @@
#include "commit-slab.h"
#include "commit-reach.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "dir.h"
diff --git a/blame.c b/blame.c
index 57daa45e899..0ceea080a80 100644
--- a/blame.c
+++ b/blame.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "cache-tree.h"
#include "mergesort.h"
#include "commit.h"
diff --git a/builtin/backfill.c b/builtin/backfill.c
index fa82ad2f6ff..0b49baa39fa 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -13,7 +13,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "promisor-remote.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 944952e30eb..15eda60af90 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -28,7 +28,7 @@
#include "line-log.h"
#include "progress.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "blame.h"
#include "refs.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 3914a2a3f61..2fa5e3f43bd 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -24,7 +24,7 @@
#include "pack-bitmap.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "mailmap.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d185982f3a6..e7dd66173dd 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,7 +20,7 @@
#include "merge-ort-wrappers.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "path.h"
#include "preload-index.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 91b9cd0d164..1eafeefb48d 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -25,7 +25,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "tree-walk.h"
#include "unpack-trees.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 628d3a1e92e..ae8ac52a975 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -6,7 +6,7 @@
#include "hex.h"
#include "parse-options.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "progress.h"
#include "replace-object.h"
#include "strbuf.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index ad6b2c93209..546069f8682 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -9,7 +9,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "parse-options.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 2d50883b729..96cb68e5e5d 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -19,7 +19,7 @@
#include "setup.h"
#include "strvec.h"
#include "run-command.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects.h"
#include "commit-slab.h"
#include "wildmatch.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index a3b64ce6942..fac613e3bc3 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -30,7 +30,7 @@
#include "strbuf.h"
#include "lockfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "entry.h"
#include "setup.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 37c01d6c6fe..0505f289a94 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "object.h"
#include "tag.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index b2839c5f439..52c792488e1 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -24,7 +24,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "mem-pool.h"
#include "commit-reach.h"
#include "khash.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4de6d3206d4..82e9603ccab 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "oid-array.h"
#include "commit.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 9c54286540c..6a5181393a2 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "read-cache-ll.h"
#include "replace-object.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 3c51a39c10d..3858df2a82e 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -26,7 +26,7 @@
#include "submodule-config.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pager.h"
#include "path.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index cd53fa3bde8..9ce0b87c30b 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -11,7 +11,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 147e9b8b479..8ce446064e8 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -21,7 +21,7 @@
#include "packfile.h"
#include "pack-revindex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "path.h"
diff --git a/builtin/log.c b/builtin/log.c
index b450cd3bde8..fe9cc5ebecb 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -15,7 +15,7 @@
#include "hex.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "color.h"
#include "commit.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index be74f0a03b2..821339b07d4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -25,7 +25,7 @@
#include "setup.h"
#include "sparse-index.h"
#include "submodule.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 8aafc30ca48..62b6fd58c16 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -10,7 +10,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "path.h"
#include "quote.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 2b16b10d2ca..9464f275629 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -7,7 +7,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "gettext.h"
#include "setup.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 4aafa73c615..709ae3966a6 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -10,7 +10,7 @@
#include "commit-reach.h"
#include "merge-ort.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "blob.h"
#include "merge-blobs.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 7ac11c46d53..1809b38f937 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -6,7 +6,7 @@
#include "strbuf.h"
#include "replace-object.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "fsck.h"
#include "config.h"
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 4b478034675..016b0e5b224 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -12,7 +12,7 @@
#include "tree.h"
#include "parse-options.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static struct treeent {
unsigned mode;
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index a77ae465d48..01c4c8e62e3 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -7,7 +7,7 @@
#include "midx.h"
#include "strbuf.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index a3f433ca4c0..783d4932ca6 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -16,7 +16,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "pretty.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 8b33edc2ff5..99b63cb0980 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -32,7 +32,7 @@
#include "list.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "dir.h"
#include "midx.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 5d1fc781761..3134cb8c689 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -13,7 +13,7 @@
#include "hex.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#define BLKSIZE 512
diff --git a/builtin/prune.c b/builtin/prune.c
index e930caa0c0a..7bbfb14c2be 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -17,7 +17,7 @@
#include "replace-object.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "shallow.h"
static const char * const prune_usage[] = {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index c92e57ba188..cb5fd55a8e4 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -33,7 +33,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "protocol.h"
#include "commit-reach.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 0d6755bcb71..ac5b8d2a1a6 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -14,7 +14,7 @@
#include "rebase.h"
#include "refs.h"
#include "refspec.h"
-#include "object-store.h"
+#include "odb.h"
#include "strvec.h"
#include "commit-reach.h"
#include "progress.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 59214dbdfdf..16782320058 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -17,7 +17,7 @@
#include "midx.h"
#include "packfile.h"
#include "prune-packed.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "shallow.h"
#include "pack.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 48c7c6a2d56..11c7e2d4c0c 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "tag.h"
#include "wildmatch.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index c4cd4ed5c81..ee25d61c802 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -14,7 +14,7 @@
#include "object.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "parse-options.h"
#include "log-tree.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 623a52a45f8..90ec1de78f9 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "refs/refs-internal.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "string-list.h"
#include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index cd7db11d825..a6c936fb2bd 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -28,7 +28,7 @@
#include "diff.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "advice.h"
#include "branch.h"
#include "list-objects-filter-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 4742b27d16e..cf2ea4b4993 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -19,7 +19,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "tag.h"
#include "parse-options.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index e33acfc4ee4..b92fd4710a9 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
static char *create_temp_file(struct object_id *oid)
{
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index e905d5f4e19..7bf395eec84 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -9,7 +9,7 @@
#include "git-zlib.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "delta.h"
#include "pack.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 678e2ecc2c2..55406a539e7 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -17,7 +17,7 @@
#include "tmp-objdir.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static int odb_transaction_nesting;
diff --git a/bundle-uri.c b/bundle-uri.c
index 96d2ba726d9..993ac62c271 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -14,7 +14,7 @@
#include "fetch-pack.h"
#include "remote.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
static struct {
enum bundle_list_heuristic heuristic;
diff --git a/bundle.c b/bundle.c
index 0c7cd15bb12..c67f85126da 100644
--- a/bundle.c
+++ b/bundle.c
@@ -7,7 +7,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "object.h"
#include "commit.h"
diff --git a/cache-tree.c b/cache-tree.c
index fa3858e2829..9786b32b3a1 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -10,7 +10,7 @@
#include "cache-tree.h"
#include "bulk-checkin.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "read-cache-ll.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/combine-diff.c b/combine-diff.c
index dfae9f7995d..cf23a753407 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -2,7 +2,7 @@
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "convert.h"
#include "diff.h"
diff --git a/commit-graph.c b/commit-graph.c
index 58d1eeedb1a..4848198d7bf 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -13,7 +13,7 @@
#include "refs.h"
#include "hash-lookup.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "alloc.h"
diff --git a/commit-graph.h b/commit-graph.h
index 19d95ade6ea..0be594e2638 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -1,7 +1,7 @@
#ifndef COMMIT_GRAPH_H
#define COMMIT_GRAPH_H
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
diff --git a/commit.c b/commit.c
index e915b2b9a12..1d30f8ce15a 100644
--- a/commit.c
+++ b/commit.c
@@ -9,7 +9,7 @@
#include "hex.h"
#include "repository.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "diff.h"
#include "revision.h"
diff --git a/config.c b/config.c
index b18b5617fcd..883dd066827 100644
--- a/config.c
+++ b/config.c
@@ -31,7 +31,7 @@
#include "hashmap.h"
#include "string-list.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "path.h"
#include "utf8.h"
diff --git a/connected.c b/connected.c
index 4415388beba..18c13245d8e 100644
--- a/connected.c
+++ b/connected.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "run-command.h"
#include "sigchain.h"
#include "connected.h"
diff --git a/contrib/coccinelle/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
index 765ad689678..ea7fe1c8db7 100644
--- a/contrib/coccinelle/the_repository.cocci
+++ b/contrib/coccinelle/the_repository.cocci
@@ -77,7 +77,7 @@
|
- diff_setup
+ repo_diff_setup
-// object-store.h
+// odb.h
|
- read_object_file
+ repo_read_object_file
diff --git a/diagnose.c b/diagnose.c
index 50129cf4be3..d407c98d094 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -7,7 +7,7 @@
#include "gettext.h"
#include "hex.h"
#include "strvec.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "repository.h"
diff --git a/diff.c b/diff.c
index 63e9ecb30c6..193da8bee68 100644
--- a/diff.c
+++ b/diff.c
@@ -23,7 +23,7 @@
#include "color.h"
#include "run-command.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "userdiff.h"
#include "submodule.h"
#include "hashmap.h"
diff --git a/entry.c b/entry.c
index f36ec5ad242..75d55038d7c 100644
--- a/entry.c
+++ b/entry.c
@@ -1,7 +1,7 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index fa4231fee74..cf157f5d7e5 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -24,7 +24,7 @@
#include "oid-array.h"
#include "oidset.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "connected.h"
#include "fetch-negotiator.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 501b5acdd44..1a8c972adf3 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -6,7 +6,7 @@
#include "environment.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "diff.h"
#include "diff-merges.h"
#include "hex.h"
diff --git a/fsck.c b/fsck.c
index 8dc8472ceb3..e69baab3af7 100644
--- a/fsck.c
+++ b/fsck.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "dir.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "object.h"
diff --git a/grep.c b/grep.c
index f8d535182c3..dc77e6c4631 100644
--- a/grep.c
+++ b/grep.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "grep.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "userdiff.h"
#include "xdiff-interface.h"
diff --git a/http-backend.c b/http-backend.c
index 0c575aa88aa..ad8c4037493 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -18,7 +18,7 @@
#include "url.h"
#include "strvec.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "protocol.h"
#include "date.h"
#include "write-or-die.h"
diff --git a/http-push.c b/http-push.c
index f9e67cabd4b..d1b1bb23711 100644
--- a/http-push.c
+++ b/http-push.c
@@ -20,7 +20,7 @@
#include "url.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#ifdef EXPAT_NEEDS_XMLPARSE_H
diff --git a/http-walker.c b/http-walker.c
index 9e7bc37f02e..4b1cdd25a80 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -10,7 +10,7 @@
#include "transport.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct alt_base {
char *base;
diff --git a/http.c b/http.c
index 8ce2ec73947..e639d9fafef 100644
--- a/http.c
+++ b/http.c
@@ -19,7 +19,7 @@
#include "packfile.h"
#include "string-list.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tempfile.h"
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 7765761b3c6..cb9c16734b1 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -12,7 +12,7 @@
#include "oidmap.h"
#include "oidset.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
/* Remember to update object flag allocation in object.h */
/*
diff --git a/list-objects.c b/list-objects.c
index 597114281f6..c50b9578584 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -14,7 +14,7 @@
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace.h"
#include "environment.h"
diff --git a/loose.c b/loose.c
index bce4e1c3ee7..9febd1f3e9a 100644
--- a/loose.c
+++ b/loose.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
#include "repository.h"
#include "wrapper.h"
diff --git a/mailmap.c b/mailmap.c
index 9e2642a043b..b18e74c2110 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -6,7 +6,7 @@
#include "string-list.h"
#include "mailmap.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
char *git_mailmap_file;
diff --git a/match-trees.c b/match-trees.c
index 72922d5d64e..4704f95c340 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -7,7 +7,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
static int score_missing(unsigned mode)
diff --git a/merge-blobs.c b/merge-blobs.c
index 53f36dbc175..ba8a3fdfd82 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -4,7 +4,7 @@
#include "merge-ll.h"
#include "blob.h"
#include "merge-blobs.h"
-#include "object-store.h"
+#include "odb.h"
static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
{
diff --git a/merge-ort.c b/merge-ort.c
index 77310a4a52c..f86c84635f0 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -39,7 +39,7 @@
#include "mem-pool.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/meson.build b/meson.build
index 270ce933d0f..a3c917b1345 100644
--- a/meson.build
+++ b/meson.build
@@ -394,8 +394,8 @@ libgit_sources = [
'object-file-convert.c',
'object-file.c',
'object-name.c',
- 'object-store.c',
'object.c',
+ 'odb.c',
'oid-array.c',
'oidmap.c',
'oidset.c',
diff --git a/notes-cache.c b/notes-cache.c
index 150241b15e0..344f67762b8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "notes-cache.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "repository.h"
#include "commit.h"
diff --git a/notes-merge.c b/notes-merge.c
index dae8e6a281a..de6a52e2e7f 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -8,7 +8,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "diff.h"
diff --git a/notes.c b/notes.c
index 0a128f1de98..fc000e501d2 100644
--- a/notes.c
+++ b/notes.c
@@ -8,7 +8,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "strbuf.h"
#include "tree-walk.h"
diff --git a/object-file.c b/object-file.c
index e48d968c0e0..dabc238447a 100644
--- a/object-file.c
+++ b/object-file.c
@@ -21,7 +21,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidtree.h"
#include "pack.h"
#include "packfile.h"
diff --git a/object-file.h b/object-file.h
index f1601200938..e4810eee449 100644
--- a/object-file.h
+++ b/object-file.h
@@ -3,7 +3,7 @@
#include "git-zlib.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
struct index_state;
diff --git a/object-store.c b/odb.c
similarity index 99%
rename from object-store.c
rename to odb.c
index 673a9c6006b..81281db7e0a 100644
--- a/object-store.c
+++ b/odb.c
@@ -13,7 +13,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/object-store.h b/odb.h
similarity index 99%
rename from object-store.h
rename to odb.h
index 6dc39376141..070dd28e394 100644
--- a/object-store.h
+++ b/odb.h
@@ -1,5 +1,5 @@
-#ifndef OBJECT_STORE_H
-#define OBJECT_STORE_H
+#ifndef ODB_H
+#define ODB_H
#include "hashmap.h"
#include "object.h"
@@ -348,4 +348,4 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
-#endif /* OBJECT_STORE_H */
+#endif /* ODB_H */
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 609a343ee3e..d2a92f34d98 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 7f400ee0121..37648b57125 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -4,7 +4,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index b9f1d866046..467a3e91035 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "repository.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects-filter-options.h"
#include "midx.h"
#include "config.h"
diff --git a/pack-check.c b/pack-check.c
index 874897d6cba..67cb2cf72f2 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -8,7 +8,7 @@
#include "progress.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct idx_entry {
off_t offset;
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 20900ca88d3..8e1f2dec0ef 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-mtimes.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
diff --git a/pack-objects.h b/pack-objects.h
index 475a2d67ce3..1ac8644201b 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -1,7 +1,7 @@
#ifndef PACK_OBJECTS_H
#define PACK_OBJECTS_H
-#include "object-store.h"
+#include "odb.h"
#include "thread-utils.h"
#include "pack.h"
#include "packfile.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index ffcde48870d..0cc422a1e67 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-revindex.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
#include "trace2.h"
diff --git a/packfile.c b/packfile.c
index e31e55f0c02..8133948b58f 100644
--- a/packfile.c
+++ b/packfile.c
@@ -19,7 +19,7 @@
#include "tree-walk.h"
#include "tree.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "midx.h"
#include "commit-graph.h"
#include "pack-revindex.h"
diff --git a/packfile.h b/packfile.h
index 826eb7f475f..53c3b7d3b43 100644
--- a/packfile.h
+++ b/packfile.h
@@ -3,10 +3,10 @@
#include "list.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
-/* in object-store.h */
+/* in odb.h */
struct object_info;
struct packed_git {
diff --git a/path.c b/path.c
index 7be0e0214df..36ddfb24701 100644
--- a/path.c
+++ b/path.c
@@ -15,7 +15,7 @@
#include "submodule-config.h"
#include "path.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "lockfile.h"
#include "exec-cmd.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 9d058586dfa..2baa286bfd0 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "config.h"
#include "trace2.h"
diff --git a/protocol-caps.c b/protocol-caps.c
index 9b8db37a210..3022f69a1bd 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -6,7 +6,7 @@
#include "hash.h"
#include "hex.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "string-list.h"
#include "strbuf.h"
diff --git a/read-cache.c b/read-cache.c
index 73f83a7e7a1..dce1056ec7c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -20,7 +20,7 @@
#include "refs.h"
#include "dir.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "tree.h"
#include "commit.h"
diff --git a/ref-filter.c b/ref-filter.c
index 7a274633cfc..4ce45440ad1 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "wildmatch.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "repo-settings.h"
#include "repository.h"
diff --git a/reflog.c b/reflog.c
index 15d81ebea97..4f8a3b717cd 100644
--- a/reflog.c
+++ b/reflog.c
@@ -5,7 +5,7 @@
#include "config.h"
#include "gettext.h"
#include "parse-options.h"
-#include "object-store.h"
+#include "odb.h"
#include "reflog.h"
#include "refs.h"
#include "revision.h"
diff --git a/refs.c b/refs.c
index 27325d2f3c6..82a70b502f8 100644
--- a/refs.c
+++ b/refs.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "hook.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "path.h"
#include "submodule.h"
diff --git a/remote.c b/remote.c
index 4099183cacd..17a842f5684 100644
--- a/remote.c
+++ b/remote.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "commit.h"
#include "diff.h"
diff --git a/replace-object.c b/replace-object.c
index 7b8a09b5cb4..65b3c108629 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -2,7 +2,7 @@
#include "gettext.h"
#include "hex.h"
#include "oidmap.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "refs.h"
#include "repository.h"
diff --git a/replace-object.h b/replace-object.h
index ba478eb30c4..b1b059ed2fe 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -3,7 +3,7 @@
#include "oidmap.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
struct replace_object {
struct oidmap_entry original;
diff --git a/repository.c b/repository.c
index dcc03fd9e0a..dbc7fa8685f 100644
--- a/repository.c
+++ b/repository.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "object.h"
#include "lockfile.h"
diff --git a/rerere.c b/rerere.c
index 3cd37c5f0ae..951e4bf8b41 100644
--- a/rerere.c
+++ b/rerere.c
@@ -18,7 +18,7 @@
#include "path.h"
#include "pathspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "strmap.h"
#define RESOLVED 0
diff --git a/revision.c b/revision.c
index 2c36a9c179e..cdefe7d6e48 100644
--- a/revision.c
+++ b/revision.c
@@ -8,7 +8,7 @@
#include "hex.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "tag.h"
#include "blob.h"
diff --git a/send-pack.c b/send-pack.c
index 86592ce526d..abca2dd38a7 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pkt-line.h"
#include "sideband.h"
#include "run-command.h"
diff --git a/sequencer.c b/sequencer.c
index b5c4043757e..35f4e68d59f 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -13,7 +13,7 @@
#include "dir.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "pager.h"
#include "commit.h"
diff --git a/server-info.c b/server-info.c
index d6cd20a39d7..9bb30d9ab71 100644
--- a/server-info.c
+++ b/server-info.c
@@ -11,7 +11,7 @@
#include "packfile.h"
#include "path.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "server-info.h"
#include "strbuf.h"
#include "tempfile.h"
diff --git a/shallow.c b/shallow.c
index faeeeb45f98..d379756e39a 100644
--- a/shallow.c
+++ b/shallow.c
@@ -5,7 +5,7 @@
#include "repository.h"
#include "tempfile.h"
#include "lockfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tag.h"
#include "pkt-line.h"
diff --git a/streaming.c b/streaming.c
index 127d6b5d6ac..29cc877f22a 100644
--- a/streaming.c
+++ b/streaming.c
@@ -10,7 +10,7 @@
#include "streaming.h"
#include "repository.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "packfile.h"
diff --git a/submodule-config.c b/submodule-config.c
index 0ee0a2884ef..09034a587f1 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -13,7 +13,7 @@
#include "submodule.h"
#include "strbuf.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/submodule.c b/submodule.c
index ead3fb5dadc..9b1018877df 100644
--- a/submodule.c
+++ b/submodule.c
@@ -27,7 +27,7 @@
#include "parse-options.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index 76c2f4eba85..611a13a3261 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -2,7 +2,7 @@
#include "test-tool.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "setup.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index fdf1b13437b..d51aaa3dc40 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pack-mtimes.h"
#include "setup.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 34f1aee5581..dba227259a2 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "hex.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
/*
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index cd8ba0c54e7..bc37c00a3bd 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "bloom.h"
#include "setup.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index ac81390899a..da2aa036b57 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "midx.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "packfile.h"
#include "setup.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 4cfc7c90b59..2920ca59d72 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -5,7 +5,7 @@
#include "refs.h"
#include "setup.h"
#include "worktree.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "strbuf.h"
diff --git a/tag.c b/tag.c
index 05be39067cf..5f6868bf7b1 100644
--- a/tag.c
+++ b/tag.c
@@ -5,7 +5,7 @@
#include "environment.h"
#include "tag.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "blob.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index b8fe0fdd7d4..9e05fcbddd0 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -10,7 +10,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "quote.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
struct tmp_objdir {
diff --git a/tree-walk.c b/tree-walk.c
index 90655d52378..34b0fff4873 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -6,7 +6,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace2.h"
#include "tree.h"
#include "pathspec.h"
diff --git a/tree.c b/tree.c
index b85f56267fb..341b7c2ff3f 100644
--- a/tree.c
+++ b/tree.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "tree.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "alloc.h"
#include "tree-walk.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 471837f0329..f38c761ab98 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -26,7 +26,7 @@
#include "symlinks.h"
#include "trace2.h"
#include "fsmonitor.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "entry.h"
#include "parallel-checkout.h"
diff --git a/upload-pack.c b/upload-pack.c
index 956da5b061a..cec12cb478a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -10,7 +10,7 @@
#include "pkt-line.h"
#include "sideband.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "object.h"
#include "commit.h"
diff --git a/walker.c b/walker.c
index b470d43e54d..a8abe8a2e78 100644
--- a/walker.c
+++ b/walker.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "walker.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "strbuf.h"
#include "tree.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 1edcd319e6e..01e6e378ea6 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "config.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "xdiff-interface.h"
#include "xdiff/xtypes.h"
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 04/17] odb: introduce parent pointers
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (2 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
` (13 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
In subsequent commits we'll get rid of our use of `the_repository` in
"odb.c" in favor of explicitly passing in a `struct object_database` or
a `struct odb_alternate`. In some cases though we'll need access to the
repository, for example to read a config value from it, but we don't
have a way to access the repository owning a specific object database.
Introduce parent pointers for `struct object_database` to its owning
repository as well as for `struct odb_alternate` to its owning object
database, which will allow us to adapt those use cases.
Note that this change requires us to pass through the object database to
`link_alt_odb_entry()` so that we can set up the parent pointers for any
alternate there. The callchain is adapted to pass through the object
database accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 45 ++++++++++++++++++++++++++-------------------
odb.h | 8 +++++++-
repository.c | 3 ++-
3 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/odb.c b/odb.c
index 81281db7e0a..2b36735087e 100644
--- a/odb.c
+++ b/odb.c
@@ -135,11 +135,15 @@ static int alt_odb_usable(struct object_database *o,
* of the object ID, an extra slash for the first level indirection, and
* the terminating NUL.
*/
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth);
-static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
- const char *relative_base, int depth, const char *normalized_objdir)
+
+static int link_alt_odb_entry(struct object_database *odb,
+ const struct strbuf *entry,
+ const char *relative_base,
+ int depth,
+ const char *normalized_objdir)
{
struct odb_alternate *alternate;
struct strbuf pathbuf = STRBUF_INIT;
@@ -167,22 +171,23 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
strbuf_setlen(&pathbuf, pathbuf.len - 1);
- if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
+ if (!alt_odb_usable(odb, &pathbuf, normalized_objdir, &pos))
goto error;
CALLOC_ARRAY(alternate, 1);
+ alternate->odb = odb;
/* pathbuf.buf is already in r->objects->alternate_by_path */
alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->alternates_tail = alternate;
- r->objects->alternates_tail = &(alternate->next);
+ *odb->alternates_tail = alternate;
+ odb->alternates_tail = &(alternate->next);
alternate->next = NULL;
- assert(r->objects->alternate_by_path);
- kh_value(r->objects->alternate_by_path, pos) = alternate;
+ assert(odb->alternate_by_path);
+ kh_value(odb->alternate_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, alternate->path, depth + 1);
+ read_info_alternates(odb, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -219,7 +224,7 @@ static const char *parse_alt_odb_entry(const char *string,
return end;
}
-static void link_alt_odb_entries(struct repository *r, const char *alt,
+static void link_alt_odb_entries(struct object_database *odb, const char *alt,
int sep, const char *relative_base, int depth)
{
struct strbuf objdirbuf = STRBUF_INIT;
@@ -234,20 +239,20 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->alternates->path, 1);
+ strbuf_realpath(&objdirbuf, odb->alternates->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
if (!entry.len)
continue;
- link_alt_odb_entry(r, &entry,
+ link_alt_odb_entry(odb, &entry,
relative_base, depth, objdirbuf.buf);
}
strbuf_release(&entry);
strbuf_release(&objdirbuf);
}
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth)
{
@@ -261,7 +266,7 @@ static void read_info_alternates(struct repository *r,
return;
}
- link_alt_odb_entries(r, buf.buf, '\n', relative_base, depth);
+ link_alt_odb_entries(odb, buf.buf, '\n', relative_base, depth);
strbuf_release(&buf);
free(path);
}
@@ -303,7 +308,7 @@ void add_to_alternates_file(const char *reference)
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
free(alts);
@@ -317,7 +322,7 @@ void add_to_alternates_memory(const char *reference)
*/
prepare_alt_odb(the_repository);
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
@@ -336,6 +341,7 @@ struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
* alternate
*/
alternate = xcalloc(1, sizeof(*alternate));
+ alternate->odb = the_repository->objects;
alternate->path = xstrdup(dir);
/*
@@ -580,9 +586,9 @@ void prepare_alt_odb(struct repository *r)
if (r->objects->loaded_alternates)
return;
- link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->alternates->path, 0);
+ read_info_alternates(r->objects, r->objects->alternates->path, 0);
r->objects->loaded_alternates = 1;
}
@@ -959,11 +965,12 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct object_database *odb_new(void)
+struct object_database *odb_new(struct repository *repo)
{
struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
+ o->repo = repo;
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
diff --git a/odb.h b/odb.h
index 070dd28e394..1d1ab8e8bf2 100644
--- a/odb.h
+++ b/odb.h
@@ -21,6 +21,9 @@ struct repository;
struct odb_alternate {
struct odb_alternate *next;
+ /* Object database that owns this alternate. */
+ struct object_database *odb;
+
/*
* Used to store the results of readdir(3) calls when we are OK
* sacrificing accuracy due to races for speed. That includes
@@ -98,6 +101,9 @@ struct cached_object_entry;
* configured via alternates.
*/
struct object_database {
+ /* Repository that owns this database. */
+ struct repository *repo;
+
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -179,7 +185,7 @@ struct object_database {
unsigned packed_git_initialized : 1;
};
-struct object_database *odb_new(void);
+struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
/*
diff --git a/repository.c b/repository.c
index dbc7fa8685f..36c508f7cb2 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = odb_new();
+ repo->objects = odb_new(repo);
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -167,6 +167,7 @@ void repo_set_gitdir(struct repository *repo,
if (!repo->objects->alternates) {
CALLOC_ARRAY(repo->objects->alternates, 1);
+ repo->objects->alternates->odb = repo->objects;
repo->objects->alternates_tail = &repo->objects->alternates->next;
}
expand_base_dir(&repo->objects->alternates->path, o->object_dir,
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 05/17] odb: get rid of `the_repository` in `find_odb()`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (3 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 04/17] odb: introduce parent pointers Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
` (12 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
Get rid of our dependency on `the_repository` in `find_odb()` by passing
in the object database in which we want to search for the alternate and
adjusting all callers.
Rename the function to `odb_find_alternate()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 4 ++--
midx-write.c | 2 +-
odb.c | 6 +++---
odb.h | 7 ++++++-
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index ae8ac52a975..90c767797e2 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -101,7 +101,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- alternate = find_odb(the_repository, opts.obj_dir);
+ alternate = odb_find_alternate(the_repository->objects, opts.obj_dir);
graph_name = get_commit_graph_filename(alternate);
chain_name = get_commit_graph_chain_filename(alternate);
if (open_commit_graph(graph_name, &fd, &st))
@@ -289,7 +289,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- alternate = find_odb(the_repository, opts.obj_dir);
+ alternate = odb_find_alternate(the_repository->objects, opts.obj_dir);
if (opts.reachable) {
if (write_commit_graph_reachable(alternate, flags, &write_opts))
diff --git a/midx-write.c b/midx-write.c
index dd3b3070e55..dd65800e8b3 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -922,7 +922,7 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
struct strbuf cur_path_real = STRBUF_INIT;
/* Ensure the given object_dir is local, or a known alternate. */
- find_odb(r, obj_dir_real);
+ odb_find_alternate(r->objects, obj_dir_real);
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
strbuf_realpath(&cur_path_real, cur->object_dir, 1);
diff --git a/odb.c b/odb.c
index 2b36735087e..621a16b35ea 100644
--- a/odb.c
+++ b/odb.c
@@ -448,14 +448,14 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct odb_alternate *find_odb(struct repository *r, const char *obj_dir)
+struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir)
{
struct odb_alternate *alternate;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(r);
- for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
+ prepare_alt_odb(odb->repo);
+ for (alternate = odb->alternates; alternate; alternate = alternate->next) {
strbuf_realpath(&odb_path_real, alternate->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
diff --git a/odb.h b/odb.h
index 1d1ab8e8bf2..5c5ce4653eb 100644
--- a/odb.h
+++ b/odb.h
@@ -61,7 +61,6 @@ struct odb_alternate {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct odb_alternate *find_odb(struct repository *r, const char *obj_dir);
typedef int alt_odb_fn(struct odb_alternate *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
@@ -188,6 +187,12 @@ struct object_database {
struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
+/*
+ * Find backend by its object directory path. Dies in case the object directory
+ * couldn't be found.
+ */
+struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
+
/*
* Create a temporary file rooted in the object database directory, or
* die on failure. The filename is taken from "pattern", which should have the
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 06/17] odb: get rid of `the_repository` in `assert_oid_type()`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (4 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 07/17] odb: get rid of `the_repository` in `odb_mkstemp()` Patrick Steinhardt
` (11 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
Get rid of our dependency on `the_repository` in `assert_oid_type()` by
passing in the object database as a parameter and adjusting all callers.
Rename the function to `odb_assert_oid_type()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-tree.c | 2 +-
commit.c | 2 +-
odb.c | 5 +++--
odb.h | 3 ++-
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 546069f8682..31cfd9bd15d 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -48,7 +48,7 @@ static int parse_parent_arg_callback(const struct option *opt,
if (repo_get_oid_commit(the_repository, arg, &oid))
die(_("not a valid object name %s"), arg);
- assert_oid_type(&oid, OBJ_COMMIT);
+ odb_assert_oid_type(the_repository->objects, &oid, OBJ_COMMIT);
new_parent(lookup_commit(the_repository, &oid), parents);
return 0;
}
diff --git a/commit.c b/commit.c
index 1d30f8ce15a..aa65183d8b6 100644
--- a/commit.c
+++ b/commit.c
@@ -1706,7 +1706,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
/* Not having i18n.commitencoding is the same as having utf-8 */
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
- assert_oid_type(tree, OBJ_TREE);
+ odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);
if (memchr(msg, '\0', msg_len))
return error("a NUL byte in commit log message not allowed.");
diff --git a/odb.c b/odb.c
index 621a16b35ea..d09b8bf00cc 100644
--- a/odb.c
+++ b/odb.c
@@ -955,9 +955,10 @@ int has_object(struct repository *r, const struct object_id *oid,
return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
}
-void assert_oid_type(const struct object_id *oid, enum object_type expect)
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = oid_object_info(odb->repo, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index 5c5ce4653eb..e38a46a05c9 100644
--- a/odb.h
+++ b/odb.h
@@ -298,7 +298,8 @@ enum {
int has_object(struct repository *r, const struct object_id *oid,
unsigned flags);
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect);
/*
* Enabling the object read lock allows multiple threads to safely call the
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 07/17] odb: get rid of `the_repository` in `odb_mkstemp()`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (5 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
` (10 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
Get rid of our dependency on `the_repository` in `odb_mkstemp()` by
passing in the object database as a parameter and adjusting all callers.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 3 ++-
builtin/index-pack.c | 2 +-
bundle-uri.c | 3 ++-
odb.c | 9 +++++----
odb.h | 7 ++++---
pack-bitmap-write.c | 3 ++-
pack-write.c | 10 ++++++----
7 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 52c792488e1..413304db9b5 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -763,7 +763,8 @@ static void start_packfile(void)
struct packed_git *p;
int pack_fd;
- pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX");
+ pack_fd = odb_mkstemp(the_repository->objects, &tmp_file,
+ "pack/tmp_pack_XXXXXX");
FLEX_ALLOC_STR(p, pack_name, tmp_file.buf);
strbuf_release(&tmp_file);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 8ce446064e8..8e5acefde40 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -362,7 +362,7 @@ static const char *open_pack_file(const char *pack_name)
input_fd = 0;
if (!pack_name) {
struct strbuf tmp_file = STRBUF_INIT;
- output_fd = odb_mkstemp(&tmp_file,
+ output_fd = odb_mkstemp(the_repository->objects, &tmp_file,
"pack/tmp_pack_XXXXXX");
pack_name = strbuf_detach(&tmp_file, NULL);
} else {
diff --git a/bundle-uri.c b/bundle-uri.c
index 993ac62c271..87a5ba50945 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -278,7 +278,8 @@ static char *find_temp_filename(void)
* Find a temporary filename that is available. This is briefly
* racy, but unlikely to collide.
*/
- fd = odb_mkstemp(&name, "bundles/tmp_uri_XXXXXX");
+ fd = odb_mkstemp(the_repository->objects, &name,
+ "bundles/tmp_uri_XXXXXX");
if (fd < 0) {
warning(_("failed to create temporary file"));
return NULL;
diff --git a/odb.c b/odb.c
index d09b8bf00cc..7ff614fb0c7 100644
--- a/odb.c
+++ b/odb.c
@@ -63,7 +63,8 @@ static const struct cached_object *find_cached_object(struct object_database *ob
return NULL;
}
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern)
{
int fd;
/*
@@ -71,15 +72,15 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
* restrictive except to remove write permission.
*/
int mode = 0444;
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
fd = git_mkstemp_mode(temp_filename->buf, mode);
if (0 <= fd)
return fd;
/* slow path */
/* some mkstemp implementations erase temp_filename on failure */
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
- safe_create_leading_directories(the_repository, temp_filename->buf);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
+ safe_create_leading_directories(odb->repo, temp_filename->buf);
return xmkstemp_mode(temp_filename->buf, mode);
}
diff --git a/odb.h b/odb.h
index e38a46a05c9..eb46eb60edd 100644
--- a/odb.h
+++ b/odb.h
@@ -194,12 +194,13 @@ void odb_clear(struct object_database *o);
struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
/*
- * Create a temporary file rooted in the object database directory, or
- * die on failure. The filename is taken from "pattern", which should have the
+ * Create a temporary file rooted in the primary alternate's directory, or die
+ * on failure. The filename is taken from "pattern", which should have the
* usual "XXXXXX" trailer, and the resulting filename is written into the
* "template" buffer. Returns the open descriptor.
*/
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern);
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 37648b57125..c847369eaaa 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1052,7 +1052,8 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
struct bitmap_disk_header header;
- int fd = odb_mkstemp(&tmp_file, "pack/tmp_bitmap_XXXXXX");
+ int fd = odb_mkstemp(writer->repo->objects, &tmp_file,
+ "pack/tmp_bitmap_XXXXXX");
if (writer->pseudo_merges_nr)
options |= BITMAP_OPT_PSEUDO_MERGES;
diff --git a/pack-write.c b/pack-write.c
index 6b06315f80a..eccdc798e36 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -84,7 +84,8 @@ const char *write_idx_file(struct repository *repo,
} else {
if (!index_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_idx_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_idx_XXXXXX");
index_name = strbuf_detach(&tmp_file, NULL);
} else {
unlink(index_name);
@@ -259,7 +260,8 @@ char *write_rev_file_order(struct repository *repo,
if (flags & WRITE_REV) {
if (!rev_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_rev_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_rev_XXXXXX");
path = strbuf_detach(&tmp_file, NULL);
} else {
unlink(rev_name);
@@ -342,7 +344,7 @@ static char *write_mtimes_file(struct repository *repo,
if (!to_pack)
BUG("cannot call write_mtimes_file with NULL packing_data");
- fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file, "pack/tmp_mtimes_XXXXXX");
mtimes_name = strbuf_detach(&tmp_file, NULL);
f = hashfd(repo->hash_algo, fd, mtimes_name);
@@ -531,7 +533,7 @@ struct hashfile *create_tmp_packfile(struct repository *repo,
struct strbuf tmpname = STRBUF_INIT;
int fd;
- fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmpname, "pack/tmp_pack_XXXXXX");
*pack_tmp_name = strbuf_detach(&tmpname, NULL);
return hashfd(repo->hash_algo, fd, *pack_tmp_name);
}
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 08/17] odb: get rid of `the_repository` when handling alternates
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (6 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 07/17] odb: get rid of `the_repository` in `odb_mkstemp()` Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
` (9 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
The functions to manage alternates all depend on `the_repository`.
Refactor them to accept an object database as parameter and adjusting
all callers. The functions are renamed accordingly.
Note that right now the situation is still somewhat weird because we end
up using the path provided by the object store's repository anyway. This
will be adapted over time though so that we instead store the path to
the primary object directory in the object database itself.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/clone.c | 10 +++++----
builtin/fsck.c | 6 +++---
builtin/grep.c | 2 +-
builtin/repack.c | 3 ++-
commit-graph.c | 4 ++--
loose.c | 2 +-
object-file.c | 10 ++++-----
object-name.c | 2 +-
odb.c | 44 ++++++++++++++++++---------------------
odb.h | 53 ++++++++++++++++++++++++++++++++---------------
packfile.c | 4 ++--
submodule.c | 3 ++-
t/helper/test-ref-store.c | 2 +-
tmp-objdir.c | 2 +-
14 files changed, 83 insertions(+), 64 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 1eafeefb48d..3aabdf6570b 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -171,7 +171,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
} else {
struct strbuf sb = STRBUF_INIT;
strbuf_addf(&sb, "%s/objects", ref_git);
- add_to_alternates_file(sb.buf);
+ odb_add_to_alternates_file(the_repository->objects, sb.buf);
strbuf_release(&sb);
}
@@ -212,12 +212,14 @@ static void copy_alternates(struct strbuf *src, const char *src_repo)
if (!line.len || line.buf[0] == '#')
continue;
if (is_absolute_path(line.buf)) {
- add_to_alternates_file(line.buf);
+ odb_add_to_alternates_file(the_repository->objects,
+ line.buf);
continue;
}
abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
if (!normalize_path_copy(abs_path, abs_path))
- add_to_alternates_file(abs_path);
+ odb_add_to_alternates_file(the_repository->objects,
+ abs_path);
else
warning("skipping invalid relative alternate: %s/%s",
src_repo, line.buf);
@@ -352,7 +354,7 @@ static void clone_local(const char *src_repo, const char *dest_repo)
struct strbuf alt = STRBUF_INIT;
get_common_dir(&alt, src_repo);
strbuf_addstr(&alt, "/objects");
- add_to_alternates_file(alt.buf);
+ odb_add_to_alternates_file(the_repository->objects, alt.buf);
strbuf_release(&alt);
} else {
struct strbuf src = STRBUF_INIT;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6a5181393a2..b961c2caa22 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1006,7 +1006,7 @@ int cmd_fsck(int argc,
for_each_packed_object(the_repository,
mark_packed_for_connectivity, NULL, 0);
} else {
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next)
fsck_object_dir(alternate->path);
@@ -1117,7 +1117,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_commit_graph) {
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
@@ -1135,7 +1135,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_multi_pack_index) {
struct child_process midx_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
diff --git a/builtin/grep.c b/builtin/grep.c
index 3858df2a82e..b19fee20425 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -462,7 +462,7 @@ static int grep_submodule(struct grep_opt *opt,
/*
* NEEDSWORK: repo_read_gitmodules() might call
- * add_to_alternates_memory() via config_from_gitmodules(). This
+ * odb_add_to_alternates_memory() via config_from_gitmodules(). This
* operation causes a race condition with concurrent object readings
* performed by the worker threads. That's why we need obj_read_lock()
* here. It should be removed once it's no longer necessary to add the
diff --git a/builtin/repack.c b/builtin/repack.c
index 16782320058..8145474cf8d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1256,7 +1256,8 @@ int cmd_repack(int argc,
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
die(_(incremental_bitmap_conflict_error));
- if (write_bitmaps && po_args.local && has_alt_odb(the_repository)) {
+ if (write_bitmaps && po_args.local &&
+ odb_has_alternates(the_repository->objects)) {
/*
* When asked to do a local repack, but we have
* packfiles that are inherited from an alternate, then
diff --git a/commit-graph.c b/commit-graph.c
index 4848198d7bf..cd34b71d270 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -649,7 +649,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
count = st->st_size / (the_hash_algo->hexsz + 1);
CALLOC_ARRAY(oids, count);
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (i = 0; i < count; i++) {
struct odb_alternate *alternate;
@@ -778,7 +778,7 @@ static int prepare_commit_graph(struct repository *r)
if (!commit_graph_compatible(r))
return 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates;
!r->objects->commit_graph && alternate;
alternate = alternate->next)
diff --git a/loose.c b/loose.c
index 9febd1f3e9a..9fbf2336822 100644
--- a/loose.c
+++ b/loose.c
@@ -112,7 +112,7 @@ int repo_read_loose_object_map(struct repository *repo)
if (!should_use_loose_object_map(repo))
return 0;
- prepare_alt_odb(repo);
+ odb_prepare_alternates(repo->objects);
for (alternate = repo->objects->alternates; alternate; alternate = alternate->next) {
if (load_one_loose_object_map(repo, alternate) < 0) {
diff --git a/object-file.c b/object-file.c
index dabc238447a..9e8649135ce 100644
--- a/object-file.c
+++ b/object-file.c
@@ -106,7 +106,7 @@ static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
struct odb_alternate *alternate;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
if (check_and_freshen_odb(alternate, oid, freshen))
return 1;
@@ -211,7 +211,7 @@ static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct odb_alternate *alternate;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
*path = odb_loose_path(alternate, &buf, oid);
if (!lstat(*path, st))
@@ -233,7 +233,7 @@ static int open_loose_object(struct repository *r,
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
*path = odb_loose_path(alternate, &buf, oid);
fd = git_open(*path);
@@ -252,7 +252,7 @@ static int quick_has_loose(struct repository *r,
{
struct odb_alternate *alternate;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
if (oidtree_contains(odb_loose_cache(alternate, oid), oid))
return 1;
@@ -1542,7 +1542,7 @@ int for_each_loose_object(each_loose_object_fn cb, void *data,
{
struct odb_alternate *alternate;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
int r = for_each_loose_file_in_objdir(alternate->path, cb, NULL,
NULL, data);
diff --git a/object-name.c b/object-name.c
index b83ba882b9e..2b757eb7948 100644
--- a/object-name.c
+++ b/object-name.c
@@ -376,7 +376,7 @@ static int init_object_disambiguation(struct repository *r,
ds->hex_pfx[len] = '\0';
ds->repo = r;
ds->bin_pfx.algo = algo ? hash_algo_by_ptr(algo) : GIT_HASH_UNKNOWN;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
return 0;
}
diff --git a/odb.c b/odb.c
index 7ff614fb0c7..bd601471cd7 100644
--- a/odb.c
+++ b/odb.c
@@ -272,10 +272,11 @@ static void read_info_alternates(struct object_database *odb,
free(path);
}
-void add_to_alternates_file(const char *reference)
+void odb_add_to_alternates_file(struct object_database *odb,
+ const char *reference)
{
struct lock_file lock = LOCK_INIT;
- char *alts = repo_git_path(the_repository, "objects/info/alternates");
+ char *alts = repo_git_path(odb->repo, "objects/info/alternates");
FILE *in, *out;
int found = 0;
@@ -308,22 +309,23 @@ void add_to_alternates_file(const char *reference)
fprintf_or_die(out, "%s\n", reference);
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
- if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository->objects, reference,
+ if (odb->loaded_alternates)
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
free(alts);
}
-void add_to_alternates_memory(const char *reference)
+void odb_add_to_alternates_memory(struct object_database *odb,
+ const char *reference)
{
/*
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(odb);
- link_alt_odb_entries(the_repository->objects, reference,
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
@@ -335,7 +337,7 @@ struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
/*
* Make a new primary odb and link the old primary ODB in as an
@@ -379,12 +381,6 @@ void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path
free_object_directory(cur_alt);
}
-/*
- * Compute the exact path an alternate is at and returns it. In case of
- * error NULL is returned and the human readable error is added to `err`
- * `path` may be relative and should point to $GIT_DIR.
- * `err` must not be null.
- */
char *compute_alternate_path(const char *path, struct strbuf *err)
{
char *ref_git = NULL;
@@ -455,7 +451,7 @@ struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(odb->repo);
+ odb_prepare_alternates(odb);
for (alternate = odb->alternates; alternate; alternate = alternate->next) {
strbuf_realpath(&odb_path_real, alternate->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
@@ -573,7 +569,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
struct odb_alternate *alternate;
int r = 0;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
r = fn(alternate, cb);
if (r)
@@ -582,21 +578,21 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
return r;
}
-void prepare_alt_odb(struct repository *r)
+void odb_prepare_alternates(struct object_database *odb)
{
- if (r->objects->loaded_alternates)
+ if (odb->loaded_alternates)
return;
- link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(odb, odb->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r->objects, r->objects->alternates->path, 0);
- r->objects->loaded_alternates = 1;
+ read_info_alternates(odb, odb->alternates->path, 0);
+ odb->loaded_alternates = 1;
}
-int has_alt_odb(struct repository *r)
+int odb_has_alternates(struct object_database *odb)
{
- prepare_alt_odb(r);
- return !!r->objects->alternates->next;
+ odb_prepare_alternates(odb);
+ return !!odb->alternates->next;
}
int obj_read_use_lock = 0;
diff --git a/odb.h b/odb.h
index eb46eb60edd..7ff3e54c061 100644
--- a/odb.h
+++ b/odb.h
@@ -12,6 +12,14 @@ struct oidtree;
struct strbuf;
struct repository;
+/*
+ * Compute the exact path an alternate is at and returns it. In case of
+ * error NULL is returned and the human readable error is added to `err`
+ * `path` may be relative and should point to $GIT_DIR.
+ * `err` must not be null.
+ */
+char *compute_alternate_path(const char *path, struct strbuf *err);
+
/*
* The alternate is the part of the object database that stores the actual
* objects. It thus encapsulates the logic to read and write the specific
@@ -58,27 +66,11 @@ struct odb_alternate {
char *path;
};
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
typedef int alt_odb_fn(struct odb_alternate *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
-/*
- * 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);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -117,7 +109,7 @@ struct object_database {
/*
* A list of alternate object directories loaded from the environment;
* this should not generally need to be accessed directly, but will
- * populate the "alternates" list when prepare_alt_odb() is run.
+ * populate the "alternates" list when odb_prepare_alternates() is run.
*/
char *alternate_db;
@@ -202,6 +194,33 @@ struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
int odb_mkstemp(struct object_database *odb,
struct strbuf *temp_filename, const char *pattern);
+/*
+ * Prepare alternate object backends for the given database by reading
+ * "objects/info/alternates" and opening the respective alternates.
+ */
+void odb_prepare_alternates(struct object_database *odb);
+
+/*
+ * Check whether the object database has any alternates. The primary object
+ * backend does not count as alternate.
+ */
+int odb_has_alternates(struct object_database *odb);
+
+/*
+ * Add the directory to the on-disk alternates file; the new entry will also
+ * take effect in the current process.
+ */
+void odb_add_to_alternates_file(struct object_database *odb,
+ 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 odb_add_to_alternates_memory(struct object_database *odb,
+ const char *dir);
+
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,
diff --git a/packfile.c b/packfile.c
index 8133948b58f..ab9628eb3d4 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1023,7 +1023,7 @@ static void prepare_packed_git(struct repository *r)
if (r->objects->packed_git_initialized)
return;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
int local = (alternate == r->objects->alternates);
prepare_multi_pack_index_one(r, alternate->path, local);
@@ -1048,7 +1048,7 @@ void reprepare_packed_git(struct repository *r)
* the lifetime of the process.
*/
r->objects->loaded_alternates = 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (alternate = r->objects->alternates; alternate; alternate = alternate->next)
odb_clear_loose_cache(alternate);
diff --git a/submodule.c b/submodule.c
index 9b1018877df..386be234230 100644
--- a/submodule.c
+++ b/submodule.c
@@ -189,7 +189,8 @@ int register_all_submodule_odb_as_alternates(void)
int ret = added_submodule_odb_paths.nr;
for (i = 0; i < added_submodule_odb_paths.nr; i++)
- add_to_alternates_memory(added_submodule_odb_paths.items[i].string);
+ odb_add_to_alternates_memory(the_repository->objects,
+ added_submodule_odb_paths.items[i].string);
if (ret) {
string_list_clear(&added_submodule_odb_paths, 0);
trace2_data_intmax("submodule", the_repository,
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 2920ca59d72..8d9a271845c 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -79,7 +79,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)
if (!repo_submodule_path_append(the_repository,
&sb, gitdir, "objects/"))
die("computing submodule path failed");
- add_to_alternates_memory(sb.buf);
+ odb_add_to_alternates_memory(the_repository->objects, sb.buf);
strbuf_release(&sb);
*refs = repo_get_submodule_ref_store(the_repository, gitdir);
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 9e05fcbddd0..cbb50438d16 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -304,7 +304,7 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)
void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
{
- add_to_alternates_memory(t->path.buf);
+ odb_add_to_alternates_memory(t->repo->objects, t->path.buf);
}
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 09/17] odb: get rid of `the_repository` in `for_each()` functions
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (7 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 10/17] odb: get rid of `the_repository` when handling the primary alternate Patrick Steinhardt
` (8 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
There are a couple of iterator-style functions that execute a callback
for each instance of a given set, all of which currently depend on
`the_repository`. Refactor them to instead take an object database as
parameter so that we can get rid of this dependency.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/count-objects.c | 2 +-
builtin/receive-pack.c | 3 ++-
builtin/submodule--helper.c | 3 ++-
diagnose.c | 2 +-
fetch-pack.c | 3 ++-
odb.c | 36 +++++++++++++++++++-----------------
odb.h | 23 ++++++++++++++++++-----
revision.c | 3 ++-
8 files changed, 47 insertions(+), 28 deletions(-)
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index da830fcee57..2752a9b02f4 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -159,7 +159,7 @@ int cmd_count_objects(int argc,
printf("prune-packable: %lu\n", packed_loose);
printf("garbage: %lu\n", garbage);
printf("size-garbage: %s\n", garbage_buf.buf);
- foreach_alt_odb(print_alternate, NULL);
+ odb_for_each_alternate(the_repository->objects, print_alternate, NULL);
strbuf_release(&loose_buf);
strbuf_release(&pack_buf);
strbuf_release(&garbage_buf);
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index cb5fd55a8e4..8c157ea7d1b 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -358,7 +358,8 @@ static void write_head_info(void)
refs_for_each_fullref_in(get_main_ref_store(the_repository), "",
exclude_patterns, show_ref_cb, &seen);
- for_each_alternate_ref(show_one_alternate_ref, &seen);
+ odb_for_each_alternate_ref(the_repository->objects,
+ show_one_alternate_ref, &seen);
oidset_clear(&seen);
strvec_clear(&excludes_vector);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a6c936fb2bd..88bbd97820a 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1668,7 +1668,8 @@ static void prepare_possible_alternates(const char *sm_name,
die(_("Value '%s' for submodule.alternateErrorStrategy is not recognized"), error_strategy);
if (!strcmp(sm_alternate, "superproject"))
- foreach_alt_odb(add_possible_reference_from_superproject, &sas);
+ odb_for_each_alternate(the_repository->objects,
+ add_possible_reference_from_superproject, &sas);
else if (!strcmp(sm_alternate, "no"))
; /* do nothing */
else
diff --git a/diagnose.c b/diagnose.c
index d407c98d094..0405368f178 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -229,7 +229,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
dir_file_stats(r->objects->alternates, &buf);
- foreach_alt_odb(dir_file_stats, &buf);
+ odb_for_each_alternate(r->objects, dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
strbuf_reset(&buf);
diff --git a/fetch-pack.c b/fetch-pack.c
index cf157f5d7e5..47fa7fa4c49 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -115,7 +115,8 @@ static void for_each_cached_alternate(struct fetch_negotiator *negotiator,
size_t i;
if (!initialized) {
- for_each_alternate_ref(cache_one_alternate, &cache);
+ odb_for_each_alternate_ref(the_repository->objects,
+ cache_one_alternate, &cache);
initialized = 1;
}
diff --git a/odb.c b/odb.c
index bd601471cd7..feca14d9683 100644
--- a/odb.c
+++ b/odb.c
@@ -494,8 +494,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
}
static void read_alternate_refs(const char *path,
- alternate_ref_fn *cb,
- void *data)
+ odb_for_each_alternate_ref_fn *cb,
+ void *payload)
{
struct child_process cmd = CHILD_PROCESS_INIT;
struct strbuf line = STRBUF_INIT;
@@ -517,7 +517,7 @@ static void read_alternate_refs(const char *path,
break;
}
- cb(&oid, data);
+ cb(&oid, payload);
}
fclose(fh);
@@ -526,16 +526,16 @@ static void read_alternate_refs(const char *path,
}
struct alternate_refs_data {
- alternate_ref_fn *fn;
- void *data;
+ odb_for_each_alternate_ref_fn *fn;
+ void *payload;
};
static int refs_from_alternate_cb(struct odb_alternate *alternate,
- void *data)
+ void *payload)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
- struct alternate_refs_data *cb = data;
+ struct alternate_refs_data *cb = payload;
if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
@@ -549,29 +549,31 @@ static int refs_from_alternate_cb(struct odb_alternate *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->data);
+ read_alternate_refs(path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
return 0;
}
-void for_each_alternate_ref(alternate_ref_fn fn, void *data)
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload)
{
- struct alternate_refs_data cb;
- cb.fn = fn;
- cb.data = data;
- foreach_alt_odb(refs_from_alternate_cb, &cb);
+ struct alternate_refs_data data;
+ data.fn = cb;
+ data.payload = payload;
+ odb_for_each_alternate(odb, refs_from_alternate_cb, &data);
}
-int foreach_alt_odb(alt_odb_fn fn, void *cb)
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload)
{
struct odb_alternate *alternate;
int r = 0;
- odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
- r = fn(alternate, cb);
+ odb_prepare_alternates(odb);
+ for (alternate = odb->alternates->next; alternate; alternate = alternate->next) {
+ r = cb(alternate, payload);
if (r)
break;
}
diff --git a/odb.h b/odb.h
index 7ff3e54c061..dcc3b0bc1f0 100644
--- a/odb.h
+++ b/odb.h
@@ -66,11 +66,6 @@ struct odb_alternate {
char *path;
};
-typedef int alt_odb_fn(struct odb_alternate *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -185,6 +180,24 @@ void odb_clear(struct object_database *o);
*/
struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
+/*
+ * Iterate through all alternates of the database and execute the provided
+ * callback function for each of them. Stop iterating once the callback
+ * function returns a non-zero value, in which case the value is bubbled up
+ * from the callback.
+ */
+typedef int odb_for_each_alternate_fn(struct odb_alternate *, void *);
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload);
+
+/*
+ * Iterate through all alternates of the database and yield their respective
+ * references.
+ */
+typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload);
+
/*
* Create a temporary file rooted in the primary alternate's directory, or die
* on failure. The filename is taken from "pattern", which should have the
diff --git a/revision.c b/revision.c
index cdefe7d6e48..b0364f556ee 100644
--- a/revision.c
+++ b/revision.c
@@ -1907,7 +1907,8 @@ static void add_alternate_refs_to_pending(struct rev_info *revs,
struct add_alternate_refs_data data;
data.revs = revs;
data.flags = flags;
- for_each_alternate_ref(add_one_alternate_ref, &data);
+ odb_for_each_alternate_ref(the_repository->objects,
+ add_one_alternate_ref, &data);
}
static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 10/17] odb: get rid of `the_repository` when handling the primary alternate
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (8 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 11/17] odb: get rid of `the_repository` when handling submodule alternates Patrick Steinhardt
` (7 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
The functions `set_temporary_primary_odb()` and `restore_primary_odb()`
are responsible for managing a temporary primary alternate for the
database. Both of these functions implicitly rely on `the_repository`.
Refactor them to instead take an explicit object database parameter as
argument and adjust callers. Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 19 +++++++++++--------
odb.h | 25 ++++++++++++++-----------
tmp-objdir.c | 10 ++++++----
3 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/odb.c b/odb.c
index feca14d9683..100dd39cbe8 100644
--- a/odb.c
+++ b/odb.c
@@ -329,7 +329,8 @@ void odb_add_to_alternates_memory(struct object_database *odb,
'\n', NULL, 0);
}
-struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_alternate *odb_set_temporary_primary_alternate(struct object_database *odb,
+ const char *dir, int will_destroy)
{
struct odb_alternate *alternate;
@@ -337,14 +338,14 @@ struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- odb_prepare_alternates(the_repository->objects);
+ odb_prepare_alternates(odb);
/*
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
alternate = xcalloc(1, sizeof(*alternate));
- alternate->odb = the_repository->objects;
+ alternate->odb = odb;
alternate->path = xstrdup(dir);
/*
@@ -353,8 +354,8 @@ struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
*/
alternate->disable_ref_updates = 1;
alternate->will_destroy = will_destroy;
- alternate->next = the_repository->objects->alternates;
- the_repository->objects->alternates = alternate;
+ alternate->next = odb->alternates;
+ odb->alternates = alternate;
return alternate->next;
}
@@ -366,9 +367,11 @@ static void free_object_directory(struct odb_alternate *alternate)
free(alternate);
}
-void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path)
+void odb_restore_primary_alternate(struct object_database *odb,
+ struct odb_alternate *restore_alt,
+ const char *old_path)
{
- struct odb_alternate *cur_alt = the_repository->objects->alternates;
+ struct odb_alternate *cur_alt = odb->alternates;
if (strcmp(old_path, cur_alt->path))
BUG("expected %s as primary object store; found %s",
@@ -377,7 +380,7 @@ void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path
if (cur_alt->next != restore_alt)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->alternates = restore_alt;
+ odb->alternates = restore_alt;
free_object_directory(cur_alt);
}
diff --git a/odb.h b/odb.h
index dcc3b0bc1f0..0db4de38529 100644
--- a/odb.h
+++ b/odb.h
@@ -66,17 +66,6 @@ struct odb_alternate {
char *path;
};
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy);
-
-/*
- * Restore a previous ODB replaced by set_temporary_main_odb.
- */
-void restore_primary_odb(struct odb_alternate *restore_alternate, const char *old_path);
-
struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
@@ -180,6 +169,20 @@ void odb_clear(struct object_database *o);
*/
struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary alternate.
+ */
+struct odb_alternate *odb_set_temporary_primary_alternate(struct object_database *odb,
+ const char *dir, int will_destroy);
+
+/*
+ * Restore a previous bakcend replaced by `odb_set_temporary_primary_alternate()`.
+ */
+void odb_restore_primary_alternate(struct object_database *odb,
+ struct odb_alternate *restore_alt,
+ const char *old_path);
+
/*
* Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/tmp-objdir.c b/tmp-objdir.c
index cbb50438d16..c2e58c4be5c 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -47,7 +47,7 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
the_tmp_objdir = NULL;
if (t->prev_alt)
- restore_primary_odb(t->prev_alt, t->path.buf);
+ odb_restore_primary_alternate(t->repo->objects, t->prev_alt, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -279,7 +279,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (t->prev_alt) {
if (t->repo->objects->alternates->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_alt, t->path.buf);
+ odb_restore_primary_alternate(t->repo->objects, t->prev_alt, t->path.buf);
t->prev_alt = NULL;
}
@@ -311,7 +311,8 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
if (t->prev_alt)
BUG("the primary object database is already replaced");
- t->prev_alt = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_alt = odb_set_temporary_primary_alternate(t->repo->objects,
+ t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
@@ -320,7 +321,8 @@ struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
if (!the_tmp_objdir || !the_tmp_objdir->prev_alt)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_alt, the_tmp_objdir->path.buf);
+ odb_restore_primary_alternate(the_tmp_objdir->repo->objects,
+ the_tmp_objdir->prev_alt, the_tmp_objdir->path.buf);
the_tmp_objdir->prev_alt = NULL;
return the_tmp_objdir;
}
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 11/17] odb: get rid of `the_repository` when handling submodule alternates
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (9 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 10/17] odb: get rid of `the_repository` when handling the primary alternate Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
` (6 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
The "--recursive" flag for git-grep(1) allows users to grep for a string
across submodule boundaries. To make this work we add each submodule's
object alternate to our own object database so that the objects can be
accessed directly.
The infrastructure for this depends on a global string list of submodule
paths. The caller is expected to call `add_submodule_odb_by_path()` for
each alternate and the object database will then eventually register all
submodule alternates via `do_oid_object_info_extended()` in case it
isn't able to look up a specific object.
This reliance on global state is of course suboptimal with regards to
our libification efforts.
Refactor the logic so that the list of submodule alternates is instead
tracked in the object database itself. This allows us to lose the
condition of `r == the_repository` before registering submodule
alternates as we only ever add submodule alternates to `the_repository`
anyway. As such, behaviour before and after this refactoring should
always be the same.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/grep.c | 3 ++-
odb.c | 37 +++++++++++++++++++++++++++++++------
odb.h | 15 +++++++++++++++
submodule-config.c | 3 ++-
submodule.c | 26 --------------------------
submodule.h | 9 ---------
6 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index b19fee20425..277bc121e4e 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,8 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->alternates->path);
+ odb_add_submodule_alternate_by_path(the_repository->objects,
+ subrepo->objects->alternates->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/odb.c b/odb.c
index 100dd39cbe8..72ff1ab5a7d 100644
--- a/odb.c
+++ b/odb.c
@@ -24,6 +24,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "submodule.h"
+#include "trace2.h"
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
@@ -469,6 +470,12 @@ struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
return alternate;
}
+void odb_add_submodule_alternate_by_path(struct object_database *odb,
+ const char *path)
+{
+ string_list_insert(&odb->submodule_alternate_paths, path);
+}
+
static void fill_alternate_refs_command(struct child_process *cmd,
const char *repo_path)
{
@@ -623,6 +630,23 @@ void disable_obj_read_lock(void)
int fetch_if_missing = 1;
+static int register_all_submodule_alternates(struct object_database *odb)
+{
+ int ret = odb->submodule_alternate_paths.nr;
+
+ for (size_t i = 0; i < odb->submodule_alternate_paths.nr; i++)
+ odb_add_to_alternates_memory(odb,
+ odb->submodule_alternate_paths.items[i].string);
+ if (ret) {
+ string_list_clear(&odb->submodule_alternate_paths, 0);
+ trace2_data_intmax("submodule", odb->repo,
+ "register_all_submodule_alternates/registered", ret);
+ if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
+ BUG("register_all_submodule_alternates() called");
+ }
+ return ret;
+}
+
static int do_oid_object_info_extended(struct repository *r,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
@@ -678,13 +702,12 @@ static int do_oid_object_info_extended(struct repository *r,
}
/*
- * If r is the_repository, this might be an attempt at
- * accessing a submodule object as if it were in the_repository
- * (having called add_submodule_odb() on that submodule's ODB).
- * If any such ODBs exist, register them and try again.
+ * This might be an attempt at accessing a submodule object as
+ * if it were in main object store (having called
+ * `odb_add_submodule_alternate_by_path()` on that submodule's
+ * ODB). If any such ODBs exist, register them and try again.
*/
- if (r == the_repository &&
- register_all_submodule_odb_as_alternates())
+ if (register_all_submodule_alternates(r->objects))
/* We added some alternates; retry */
continue;
@@ -977,6 +1000,7 @@ struct object_database *odb_new(struct repository *repo)
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
+ string_list_init_dup(&o->submodule_alternate_paths);
return o;
}
@@ -1027,4 +1051,5 @@ void odb_clear(struct object_database *o)
o->packed_git = NULL;
hashmap_clear(&o->pack_map);
+ string_list_clear(&o->submodule_alternate_paths, 0);
}
diff --git a/odb.h b/odb.h
index 0db4de38529..44326cb698d 100644
--- a/odb.h
+++ b/odb.h
@@ -5,6 +5,7 @@
#include "object.h"
#include "list.h"
#include "oidset.h"
+#include "string-list.h"
#include "thread-utils.h"
struct oidmap;
@@ -158,6 +159,12 @@ struct object_database {
* packs.
*/
unsigned packed_git_initialized : 1;
+
+ /*
+ * Submodule alternate paths that will be added as alternatives to
+ * allow lookup of submodule objects via the main object database.
+ */
+ struct string_list submodule_alternate_paths;
};
struct object_database *odb_new(struct repository *repo);
@@ -183,6 +190,14 @@ void odb_restore_primary_alternate(struct object_database *odb,
struct odb_alternate *restore_alt,
const char *old_path);
+/*
+ * Call odb_add_submodule_alternate_by_path() to add the submodule at the given
+ * path to a list. The object stores of all submodules in that list will be
+ * added as alternates in the object store when looking up objects.
+ */
+void odb_add_submodule_alternate_by_path(struct object_database *odb,
+ const char *path);
+
/*
* Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/submodule-config.c b/submodule-config.c
index 09034a587f1..0f775f93259 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,8 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->alternates->path);
+ odb_add_submodule_alternate_by_path(the_repository->objects,
+ repo->objects->alternates->path);
} else {
goto out;
}
diff --git a/submodule.c b/submodule.c
index 386be234230..788c9e55ed3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -31,7 +31,6 @@
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
-#include "trace2.h"
static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
static int initialized_fetch_ref_tips;
@@ -176,31 +175,6 @@ void stage_updated_gitmodules(struct index_state *istate)
die(_("staging updated .gitmodules failed"));
}
-static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_DUP;
-
-void add_submodule_odb_by_path(const char *path)
-{
- string_list_insert(&added_submodule_odb_paths, path);
-}
-
-int register_all_submodule_odb_as_alternates(void)
-{
- int i;
- int ret = added_submodule_odb_paths.nr;
-
- for (i = 0; i < added_submodule_odb_paths.nr; i++)
- odb_add_to_alternates_memory(the_repository->objects,
- added_submodule_odb_paths.items[i].string);
- if (ret) {
- string_list_clear(&added_submodule_odb_paths, 0);
- trace2_data_intmax("submodule", the_repository,
- "register_all_submodule_odb_as_alternates/registered", ret);
- if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
- BUG("register_all_submodule_odb_as_alternates() called");
- }
- return ret;
-}
-
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
const char *path)
{
diff --git a/submodule.h b/submodule.h
index db980c1d083..b10e16e6c06 100644
--- a/submodule.h
+++ b/submodule.h
@@ -104,15 +104,6 @@ int submodule_uses_gitfile(const char *path);
#define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
int bad_to_remove_submodule(const char *path, unsigned flags);
-/*
- * Call add_submodule_odb_by_path() to add the submodule at the given
- * path to a list. When register_all_submodule_odb_as_alternates() is
- * called, the object stores of all submodules in that list will be
- * added as alternates in the_repository.
- */
-void add_submodule_odb_by_path(const char *path);
-int register_all_submodule_odb_as_alternates(void);
-
/*
* Checks if there are submodule changes in a..b. If a is the null OID,
* checks b and all its ancestors instead.
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 12/17] odb: trivial refactorings to get rid of `the_repository`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (10 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 11/17] odb: get rid of `the_repository` when handling submodule alternates Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
` (5 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
All of the external functions provided by the object database subsystem
don't depend on `the_repository` anymore, but some internal functions
still do. Refactor those cases by plumbing through the repository that
owns the object database.
This change allows us to get rid of the `USE_THE_REPOSITORY_VARIABLE`
preprocessor define.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/odb.c b/odb.c
index 72ff1ab5a7d..c150c01db4a 100644
--- a/odb.c
+++ b/odb.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "abspath.h"
#include "commit-graph.h"
@@ -476,12 +474,13 @@ void odb_add_submodule_alternate_by_path(struct object_database *odb,
string_list_insert(&odb->submodule_alternate_paths, path);
}
-static void fill_alternate_refs_command(struct child_process *cmd,
+static void fill_alternate_refs_command(struct repository *repo,
+ struct child_process *cmd,
const char *repo_path)
{
const char *value;
- if (!git_config_get_value("core.alternateRefsCommand", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsCommand", &value)) {
cmd->use_shell = 1;
strvec_push(&cmd->args, value);
@@ -493,7 +492,7 @@ static void fill_alternate_refs_command(struct child_process *cmd,
strvec_push(&cmd->args, "for-each-ref");
strvec_push(&cmd->args, "--format=%(objectname)");
- if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsPrefixes", &value)) {
strvec_push(&cmd->args, "--");
strvec_split(&cmd->args, value);
}
@@ -503,7 +502,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
cmd->out = -1;
}
-static void read_alternate_refs(const char *path,
+static void read_alternate_refs(struct repository *repo,
+ const char *path,
odb_for_each_alternate_ref_fn *cb,
void *payload)
{
@@ -511,7 +511,7 @@ static void read_alternate_refs(const char *path,
struct strbuf line = STRBUF_INIT;
FILE *fh;
- fill_alternate_refs_command(&cmd, path);
+ fill_alternate_refs_command(repo, &cmd, path);
if (start_command(&cmd))
return;
@@ -521,7 +521,7 @@ static void read_alternate_refs(const char *path,
struct object_id oid;
const char *p;
- if (parse_oid_hex(line.buf, &oid, &p) || *p) {
+ if (parse_oid_hex_algop(line.buf, &oid, &p, repo->hash_algo) || *p) {
warning(_("invalid line while parsing alternate refs: %s"),
line.buf);
break;
@@ -559,7 +559,7 @@ static int refs_from_alternate_cb(struct odb_alternate *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->payload);
+ read_alternate_refs(alternate->odb->repo, path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, the_repository->hash_algo);
+ oidclr(oi->delta_base_oid, r->hash_algo);
if (oi->type_name)
strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
@@ -765,10 +765,10 @@ static int oid_object_info_convert(struct repository *r,
void *content;
int ret;
- if (repo_oid_to_algop(r, input_oid, the_hash_algo, &oid)) {
+ if (repo_oid_to_algop(r, input_oid, r->hash_algo, &oid)) {
if (do_die)
die(_("missing mapping of %s to %s"),
- oid_to_hex(input_oid), the_hash_algo->name);
+ oid_to_hex(input_oid), r->hash_algo->name);
return -1;
}
@@ -804,8 +804,8 @@ static int oid_object_info_convert(struct repository *r,
if (type == -1)
return -1;
if (type != OBJ_BLOB) {
- ret = convert_object_file(the_repository, &outbuf,
- the_hash_algo, input_algo,
+ ret = convert_object_file(r, &outbuf,
+ r->hash_algo, input_algo,
content, size, type, !do_die);
free(content);
if (ret == -1)
@@ -953,9 +953,9 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + the_hash_algo->hexsz > isize ||
+ if (ref_length + r->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
free(buffer);
return NULL;
}
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 13/17] odb: rename `oid_object_info()`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (11 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
` (4 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
Rename `oid_object_info()` to `odb_read_object_info()` as well as their
`_extended()` variant to match other functions related to the object
database and our modern coding guidelines.
Introduce compatibility wrappers so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
archive.c | 2 +-
blame.c | 4 +--
builtin/blame.c | 4 +--
builtin/cat-file.c | 26 ++++++++++---------
builtin/describe.c | 3 ++-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 17 ++++++------
builtin/fsck.c | 7 ++---
builtin/gc.c | 2 +-
builtin/grep.c | 2 +-
builtin/index-pack.c | 13 +++++-----
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 4 +--
builtin/mktree.c | 8 +++---
builtin/pack-objects.c | 30 ++++++++++++----------
builtin/prune.c | 4 +--
builtin/repack.c | 2 +-
builtin/replace.c | 10 ++++----
builtin/rev-list.c | 6 +++--
builtin/tag.c | 4 +--
builtin/unpack-objects.c | 2 +-
commit-graph.c | 2 +-
commit.c | 3 ++-
diff.c | 18 ++++++-------
fetch-pack.c | 4 +--
list-objects-filter.c | 2 +-
log-tree.c | 2 +-
merge-ort.c | 4 +--
object-file.c | 2 +-
object-file.h | 2 +-
object-name.c | 16 ++++++------
object.c | 6 ++---
odb.c | 60 ++++++++++++++++++++++---------------------
odb.h | 46 +++++++++++++++++++++++++++------
pack-bitmap-write.c | 4 +--
pack-bitmap.c | 8 +++---
packfile.c | 5 ++--
promisor-remote.c | 4 +--
protocol-caps.c | 2 +-
reachable.c | 2 +-
read-cache.c | 6 ++---
ref-filter.c | 4 +--
remote.c | 5 ++--
sequencer.c | 5 ++--
streaming.c | 8 +++---
submodule.c | 5 ++--
t/helper/test-partial-clone.c | 2 +-
tag.c | 2 +-
48 files changed, 213 insertions(+), 170 deletions(-)
diff --git a/archive.c b/archive.c
index 7fa2cc2596a..f2511d530d5 100644
--- a/archive.c
+++ b/archive.c
@@ -215,7 +215,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
/* Stream it? */
if (S_ISREG(mode) && !args->convert &&
- oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
+ odb_read_object_info(args->repo->objects, oid, &size) == OBJ_BLOB &&
size > repo_settings_get_big_file_threshold(the_repository))
return write_entry(args, oid, path.buf, path.len, mode, NULL, size);
diff --git a/blame.c b/blame.c
index 0ceea080a80..97db3355af4 100644
--- a/blame.c
+++ b/blame.c
@@ -116,7 +116,7 @@ static void verify_working_tree_path(struct repository *r,
unsigned short mode;
if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
- oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
+ odb_read_object_info(r->objects, &blob_oid, NULL) == OBJ_BLOB)
return;
}
@@ -1245,7 +1245,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
return 0;
if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
goto error_out;
- if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
+ if (odb_read_object_info(r->objects, &origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out;
return 0;
error_out:
diff --git a/builtin/blame.c b/builtin/blame.c
index 15eda60af90..91586e6852b 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -837,7 +837,7 @@ static int is_a_rev(const char *name)
if (repo_get_oid(the_repository, name, &oid))
return 0;
- return OBJ_NONE < oid_object_info(the_repository, &oid, NULL);
+ return OBJ_NONE < odb_read_object_info(the_repository->objects, &oid, NULL);
}
static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
@@ -848,7 +848,7 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
oidcpy(&oid, oid_ret);
while (1) {
struct object *obj;
- int kind = oid_object_info(r, &oid, NULL);
+ int kind = odb_read_object_info(r->objects, &oid, NULL);
if (kind == OBJ_COMMIT) {
oidcpy(oid_ret, &oid);
return 0;
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 2fa5e3f43bd..da172155c85 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -137,7 +137,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
switch (opt) {
case 't':
oi.type_name = &sb;
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (sb.len) {
printf("%s\n", sb.buf);
@@ -155,7 +155,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
oi.contentp = (void**)&buf;
}
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
@@ -189,7 +189,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
/* else fallthrough */
case 'p':
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("Not a valid object name %s", obj_name);
@@ -226,7 +226,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
if (exp_type_id == OBJ_BLOB) {
struct object_id blob_oid;
- if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
+ if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_TAG) {
char *buffer = repo_read_object_file(the_repository,
&oid,
&type,
@@ -244,7 +245,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
} else
oidcpy(&blob_oid, &oid);
- if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB) {
+ if (odb_read_object_info(the_repository->objects,
+ &blob_oid, NULL) == OBJ_BLOB) {
ret = stream_blob(&blob_oid);
goto cleanup;
}
@@ -303,7 +305,7 @@ struct expand_data {
/*
* After a mark_query run, this object_info is set up to be
- * passed to oid_object_info_extended. It will point to the data
+ * passed to odb_read_object_info_extended. It will point to the data
* elements above, so you can retrieve the response from there.
*/
struct object_info info;
@@ -493,12 +495,12 @@ static void batch_object_write(const char *obj_name,
data->info.sizep = &data->size;
if (pack)
- ret = packed_object_info(the_repository, pack, offset,
- &data->info);
+ ret = packed_object_info(the_repository, pack,
+ offset, &data->info);
else
- ret = oid_object_info_extended(the_repository,
- &data->oid, &data->info,
- OBJECT_INFO_LOOKUP_REPLACE);
+ ret = odb_read_object_info_extended(the_repository->objects,
+ &data->oid, &data->info,
+ OBJECT_INFO_LOOKUP_REPLACE);
if (ret < 0) {
report_object_status(opt, obj_name, &data->oid, "missing");
return;
@@ -881,7 +883,7 @@ static int batch_objects(struct batch_options *opt)
/*
* Expand once with our special mark_query flag, which will prime the
- * object_info to be handed to oid_object_info_extended for each
+ * object_info to be handed to odb_read_object_info_extended for each
* object.
*/
memset(&data, 0, sizeof(data));
diff --git a/builtin/describe.c b/builtin/describe.c
index 96cb68e5e5d..fbf305d7624 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -552,7 +552,8 @@ static void describe(const char *arg, int last_one)
if (cmit)
describe_commit(&oid, &sb);
- else if (oid_object_info(the_repository, &oid, NULL) == OBJ_BLOB)
+ else if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_BLOB)
describe_blob(oid, &sb);
else
die(_("%s is neither a commit nor blob"), arg);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 0505f289a94..6c93cf0a8aa 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -1200,7 +1200,7 @@ static void import_marks(char *input_file, int check_exists)
if (last_idnum < mark)
last_idnum = mark;
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(&oid));
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 413304db9b5..2718376f2c9 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1756,8 +1756,8 @@ static void insert_object_entry(struct mark_set **s, struct object_id *oid, uint
struct object_entry *e;
e = find_object(oid);
if (!e) {
- enum object_type type = oid_object_info(the_repository,
- oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
e = insert_object(oid);
@@ -2416,8 +2416,8 @@ static void file_change_m(const char *p, struct branch *b)
enum object_type expected = S_ISDIR(mode) ?
OBJ_TREE: OBJ_BLOB;
enum object_type type = oe ? oe->type :
- oid_object_info(the_repository, &oid,
- NULL);
+ odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("%s not found: %s",
S_ISDIR(mode) ? "Tree" : "Blob",
@@ -2553,7 +2553,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
die("Not a blob (actually a %s): %s",
type_name(oe->type), command_buf.buf);
} else if (!is_null_oid(&oid)) {
- enum object_type type = oid_object_info(the_repository, &oid,
+ enum object_type type = odb_read_object_info(the_repository->objects, &oid,
NULL);
if (type < 0)
die("Blob not found: %s", command_buf.buf);
@@ -2895,7 +2895,8 @@ static void parse_new_tag(const char *arg)
} else if (!repo_get_oid(the_repository, from, &oid)) {
struct object_entry *oe = find_object(&oid);
if (!oe) {
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("Not a valid object: %s", from);
} else
@@ -3085,8 +3086,8 @@ static struct object_entry *dereference(struct object_entry *oe,
const unsigned hexsz = the_hash_algo->hexsz;
if (!oe) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
/* cache it! */
diff --git a/builtin/fsck.c b/builtin/fsck.c
index b961c2caa22..08a79fe044d 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -71,7 +71,8 @@ static const char *printable_type(const struct object_id *oid,
const char *ret;
if (type == OBJ_NONE)
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
ret = type_name(type);
if (!ret)
@@ -232,8 +233,8 @@ static void mark_unreachable_referents(const struct object_id *oid)
* (and we want to avoid parsing blobs).
*/
if (obj->type == OBJ_NONE) {
- enum object_type type = oid_object_info(the_repository,
- &obj->oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ &obj->oid, NULL);
if (type > 0)
object_as_type(obj, type, 0);
}
diff --git a/builtin/gc.c b/builtin/gc.c
index 9e9d31c1f39..40bd2259c6a 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1006,7 +1006,7 @@ static int dfs_on_ref(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
commit = lookup_commit(the_repository, oid);
diff --git a/builtin/grep.c b/builtin/grep.c
index 277bc121e4e..311c940aa9e 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -520,7 +520,7 @@ static int grep_submodule(struct grep_opt *opt,
struct strbuf base = STRBUF_INIT;
obj_read_lock();
- object_type = oid_object_info(subrepo, oid, NULL);
+ object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
data = read_object_with_reference(subrepo,
oid, OBJ_TREE,
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 8e5acefde40..82cf80b89d1 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -260,7 +260,8 @@ static unsigned check_object(struct object *obj)
if (!(obj->flags & FLAG_CHECKED)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects,
+ &obj->oid, &size);
if (type <= 0)
die(_("did not receive expected object %s"),
oid_to_hex(&obj->oid));
@@ -908,7 +909,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
enum object_type has_type;
unsigned long has_size;
read_lock();
- has_type = oid_object_info(the_repository, oid, &has_size);
+ has_type = odb_read_object_info(the_repository->objects, oid, &has_size);
if (has_type < 0)
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
@@ -1495,9 +1496,9 @@ static void fix_unresolved_deltas(struct hashfile *f)
struct oid_array to_fetch = OID_ARRAY_INIT;
for (i = 0; i < nr_ref_deltas; i++) {
struct ref_delta_entry *d = sorted_by_pos[i];
- if (!oid_object_info_extended(the_repository, &d->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &d->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &d->oid);
}
@@ -1823,7 +1824,7 @@ static void repack_local_links(void)
oidset_iter_init(&outgoing_links, &iter);
while ((oid = oidset_iter_next(&iter))) {
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info, 0))
/* Missing; assume it is a promisor object */
continue;
if (info.whence == OI_PACKED && info.u.packed.pack->pack_promisor)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 821339b07d4..ff975e7be06 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -251,7 +251,7 @@ static void expand_objectsize(struct repository *repo, struct strbuf *line,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(repo, oid, &size) < 0)
+ if (odb_read_object_info(repo->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 62b6fd58c16..4d616dd5282 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -27,7 +27,7 @@ static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
@@ -217,7 +217,7 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base,
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
+ if (odb_read_object_info(the_repository->objects, oid, &size) == OBJ_BAD)
xsnprintf(size_text, sizeof(size_text), "BAD");
else
xsnprintf(size_text, sizeof(size_text),
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 016b0e5b224..81df7f6099f 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -124,10 +124,10 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
/* Check the type of object identified by oid without fetching objects */
oi.typep = &obj_type;
- if (oid_object_info_extended(the_repository, &oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_QUICK |
- OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_QUICK |
+ OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
obj_type = -1;
if (obj_type < 0) {
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 99b63cb0980..da35d684081 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2154,10 +2154,10 @@ static void prefetch_to_pack(uint32_t object_index_start) {
for (i = object_index_start; i < to_pack.nr_objects; i++) {
struct object_entry *entry = to_pack.objects + i;
- if (!oid_object_info_extended(the_repository,
- &entry->idx.oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &entry->idx.oid,
+ NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &entry->idx.oid);
}
@@ -2298,19 +2298,19 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
/*
* No choice but to fall back to the recursive delta walk
- * with oid_object_info() to find about the object type
+ * with odb_read_object_info() to find about the object type
* at this point...
*/
give_up:
unuse_pack(&w_curs);
}
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
if (repo_has_promisor_remote(the_repository)) {
prefetch_to_pack(object_index);
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
type = -1;
} else {
type = -1;
@@ -2384,12 +2384,13 @@ static void drop_reused_delta(struct object_entry *entry)
if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
/*
* We failed to get the info from this pack for some reason;
- * fall back to oid_object_info, which may find another copy.
+ * fall back to odb_read_object_info, which may find another copy.
* And if that fails, the error will be recorded in oe_type(entry)
* and dealt with in prepare_pack().
*/
oe_set_type(entry,
- oid_object_info(the_repository, &entry->idx.oid, &size));
+ odb_read_object_info(the_repository->objects,
+ &entry->idx.oid, &size));
} else {
oe_set_type(entry, type);
}
@@ -2677,7 +2678,8 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
packing_data_lock(&to_pack);
- if (oid_object_info(the_repository, &e->idx.oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects,
+ &e->idx.oid, &size) < 0)
die(_("unable to get size of %s"),
oid_to_hex(&e->idx.oid));
packing_data_unlock(&to_pack);
@@ -4063,7 +4065,7 @@ static void add_objects_in_unpacked_packs(void)
static int add_loose_object(const struct object_id *oid, const char *path,
void *data UNUSED)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0) {
warning(_("loose object at %s could not be examined"), path);
@@ -4449,7 +4451,7 @@ static int option_parse_cruft_expiration(const struct option *opt UNUSED,
static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED)
{
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, &obj->oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0))
BUG("should_include_obj should only be called on existing objects");
return info.whence != OI_PACKED || !info.u.packed.pack->pack_promisor;
}
diff --git a/builtin/prune.c b/builtin/prune.c
index 7bbfb14c2be..339017c7ccf 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -99,8 +99,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
if (st.st_mtime > expire)
return 0;
if (show_only || verbose) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? type_name(type) : "unknown");
}
diff --git a/builtin/repack.c b/builtin/repack.c
index 8145474cf8d..a89c2b704fb 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -707,7 +707,7 @@ static int midx_snapshot_ref_one(const char *refname UNUSED,
if (oidset_insert(&data->seen, oid))
return 0; /* already seen */
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
fprintf(data->f->fp, "%s%s\n", data->preferred ? "+" : "",
diff --git a/builtin/replace.c b/builtin/replace.c
index 11c7e2d4c0c..5ff2ab723cb 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -65,8 +65,8 @@ static int show_reference(const char *refname,
if (repo_get_oid(data->repo, refname, &object))
return error(_("failed to resolve '%s' as a valid ref"), refname);
- obj_type = oid_object_info(data->repo, &object, NULL);
- repl_type = oid_object_info(data->repo, oid, NULL);
+ obj_type = odb_read_object_info(data->repo->objects, &object, NULL);
+ repl_type = odb_read_object_info(data->repo->objects, oid, NULL);
printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
oid_to_hex(oid), type_name(repl_type));
@@ -185,8 +185,8 @@ static int replace_object_oid(const char *object_ref,
struct strbuf err = STRBUF_INIT;
int res = 0;
- obj_type = oid_object_info(the_repository, object, NULL);
- repl_type = oid_object_info(the_repository, repl, NULL);
+ obj_type = odb_read_object_info(the_repository->objects, object, NULL);
+ repl_type = odb_read_object_info(the_repository->objects, repl, NULL);
if (!force && obj_type != repl_type)
return error(_("Objects must be of the same type.\n"
"'%s' points to a replaced object of type '%s'\n"
@@ -334,7 +334,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
if (repo_get_oid(the_repository, object_ref, &old_oid) < 0)
return error(_("not a valid object name: '%s'"), object_ref);
- type = oid_object_info(the_repository, &old_oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &old_oid, NULL);
if (type < 0)
return error(_("unable to get object type for %s"),
oid_to_hex(&old_oid));
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index ee25d61c802..eed73f5fc0b 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -110,7 +110,8 @@ static off_t get_object_disk_usage(struct object *obj)
off_t size;
struct object_info oi = OBJECT_INFO_INIT;
oi.disk_sizep = &size;
- if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid));
return size;
}
@@ -346,7 +347,8 @@ static void show_commit(struct commit *commit, void *data)
static int finish_object(struct object *obj, const char *name, void *cb_data)
{
struct rev_list_info *info = cb_data;
- if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, NULL, 0) < 0) {
finish_object__ma(obj, name);
return 1;
}
diff --git a/builtin/tag.c b/builtin/tag.c
index cf2ea4b4993..e0b27396c6b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -304,7 +304,7 @@ static void create_tag(const struct object_id *object, const char *object_ref,
struct strbuf header = STRBUF_INIT;
int should_edit;
- type = oid_object_info(the_repository, object, NULL);
+ type = odb_read_object_info(the_repository->objects, object, NULL);
if (type <= OBJ_NONE)
die(_("bad object type."));
@@ -401,7 +401,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
}
strbuf_addstr(sb, " (");
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
switch (type) {
default:
strbuf_addstr(sb, "object of unknown type");
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 7bf395eec84..405e78bc592 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -232,7 +232,7 @@ static int check_object(struct object *obj, enum object_type type,
if (!(obj->flags & FLAG_OPEN)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects, &obj->oid, &size);
if (type != obj->type || type <= 0)
die("object of unexpected type");
obj->flags |= FLAG_WRITTEN;
diff --git a/commit-graph.c b/commit-graph.c
index cd34b71d270..84cfaf87639 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1862,7 +1862,7 @@ static int add_ref_to_set(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) == OBJ_COMMIT)
oidset_insert(data->commits, oid);
display_progress(data->progress, oidset_size(data->commits));
diff --git a/commit.c b/commit.c
index aa65183d8b6..d4aa9c7a5f8 100644
--- a/commit.c
+++ b/commit.c
@@ -585,7 +585,8 @@ int repo_parse_commit_internal(struct repository *r,
return 0;
}
- if (oid_object_info_extended(r, &item->object.oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(r->objects, &item->object.oid,
+ &oi, flags) < 0)
return quiet_on_missing ? -1 :
error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/diff.c b/diff.c
index 193da8bee68..75cfedf18a5 100644
--- a/diff.c
+++ b/diff.c
@@ -4230,14 +4230,14 @@ int diff_populate_filespec(struct repository *r,
info.contentp = &s->data;
if (options && options->missing_object_cb) {
- if (!oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_SKIP_FETCH_OBJECT))
+ if (!odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_SKIP_FETCH_OBJECT))
goto object_read;
options->missing_object_cb(options->missing_object_data);
}
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
object_read:
@@ -4252,8 +4252,8 @@ int diff_populate_filespec(struct repository *r,
}
if (!info.contentp) {
info.contentp = &s->data;
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
}
s->should_free = 1;
@@ -7019,8 +7019,8 @@ void diff_add_if_missing(struct repository *r,
{
if (filespec && filespec->oid_valid &&
!S_ISGITLINK(filespec->mode) &&
- oid_object_info_extended(r, &filespec->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(r->objects, &filespec->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(to_fetch, &filespec->oid);
}
diff --git a/fetch-pack.c b/fetch-pack.c
index 47fa7fa4c49..0f5de1c94d1 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -149,8 +149,8 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
}
while (1) {
- if (oid_object_info_extended(the_repository, oid, &info,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
return NULL;
if (type == OBJ_TAG) {
struct tag *tag = (struct tag *)
diff --git a/list-objects-filter.c b/list-objects-filter.c
index cb9c16734b1..ec7aebaffd0 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -310,7 +310,7 @@ static enum list_objects_filter_result filter_blobs_limit(
assert(obj->type == OBJ_BLOB);
assert((obj->flags & SEEN) == 0);
- t = oid_object_info(r, &obj->oid, &object_length);
+ t = odb_read_object_info(r->objects, &obj->oid, &object_length);
if (t != OBJ_BLOB) { /* probably OBJ_NONE */
/*
* We DO NOT have the blob locally, so we cannot
diff --git a/log-tree.c b/log-tree.c
index 1d05dc1c701..233bf9f227c 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -176,7 +176,7 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
return 0;
}
- objtype = oid_object_info(the_repository, oid, NULL);
+ objtype = odb_read_object_info(the_repository->objects, oid, NULL);
if (objtype < 0)
return 0;
obj = lookup_object_by_type(the_repository, oid, objtype);
diff --git a/merge-ort.c b/merge-ort.c
index f86c84635f0..5d4501085e9 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -4374,8 +4374,8 @@ static void prefetch_for_content_merges(struct merge_options *opt,
if ((ci->filemask & side_mask) &&
S_ISREG(vi->mode) &&
- oid_object_info_extended(opt->repo, &vi->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(opt->repo->objects, &vi->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&to_fetch, &vi->oid);
}
}
diff --git a/object-file.c b/object-file.c
index 9e8649135ce..d5f41cb73a2 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1211,7 +1211,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
oi.typep = &type;
oi.sizep = &len;
oi.contentp = &buf;
- if (oid_object_info_extended(the_repository, oid, &oi, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &oi, 0))
return error(_("cannot read object for %s"), oid_to_hex(oid));
if (compat) {
if (repo_oid_to_algop(repo, oid, compat, &compat_oid))
diff --git a/object-file.h b/object-file.h
index e4810eee449..86920bd4bb8 100644
--- a/object-file.h
+++ b/object-file.h
@@ -8,7 +8,7 @@
struct index_state;
/*
- * Set this to 0 to prevent oid_object_info_extended() from fetching missing
+ * Set this to 0 to prevent odb_read_object_info_extended() from fetching missing
* blobs. This has a difference only if extensions.partialClone is set.
*
* Its default value is 1.
diff --git a/object-name.c b/object-name.c
index 2b757eb7948..973548d8923 100644
--- a/object-name.c
+++ b/object-name.c
@@ -251,7 +251,7 @@ static int disambiguate_commit_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_COMMIT;
}
@@ -262,7 +262,7 @@ static int disambiguate_committish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -279,7 +279,7 @@ static int disambiguate_tree_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_TREE;
}
@@ -290,7 +290,7 @@ static int disambiguate_treeish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_TREE || kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -307,7 +307,7 @@ static int disambiguate_blob_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_BLOB;
}
@@ -399,7 +399,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
return 0;
hash = repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV);
- type = oid_object_info(ds->repo, oid, NULL);
+ type = odb_read_object_info(ds->repo->objects, oid, NULL);
if (type < 0) {
/*
@@ -514,8 +514,8 @@ static int sort_ambiguous(const void *va, const void *vb, void *ctx)
{
struct repository *sort_ambiguous_repo = ctx;
const struct object_id *a = va, *b = vb;
- int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
- int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
+ int a_type = odb_read_object_info(sort_ambiguous_repo->objects, a, NULL);
+ int b_type = odb_read_object_info(sort_ambiguous_repo->objects, b, NULL);
int a_type_sort;
int b_type_sort;
diff --git a/object.c b/object.c
index 3b15469139d..868d89eed42 100644
--- a/object.c
+++ b/object.c
@@ -214,7 +214,7 @@ enum peel_status peel_object(struct repository *r,
struct object *o = lookup_unknown_object(r, name);
if (o->type == OBJ_NONE) {
- int type = oid_object_info(r, name, NULL);
+ int type = odb_read_object_info(r->objects, name, NULL);
if (type < 0 || !object_as_type(o, type, 0))
return PEEL_INVALID;
}
@@ -315,7 +315,7 @@ struct object *parse_object_with_flags(struct repository *r,
}
if ((!obj || obj->type == OBJ_BLOB) &&
- oid_object_info(r, oid, NULL) == OBJ_BLOB) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
if (!skip_hash && stream_object_signature(r, repl) < 0) {
error(_("hash mismatch %s"), oid_to_hex(oid));
return NULL;
@@ -331,7 +331,7 @@ struct object *parse_object_with_flags(struct repository *r,
*/
if (skip_hash && discard_tree &&
(!obj || obj->type == OBJ_TREE) &&
- oid_object_info(r, oid, NULL) == OBJ_TREE) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_TREE) {
return &lookup_tree(r, oid)->object;
}
diff --git a/odb.c b/odb.c
index c150c01db4a..3d5d4ff8454 100644
--- a/odb.c
+++ b/odb.c
@@ -647,7 +647,7 @@ static int register_all_submodule_alternates(struct object_database *odb)
return ret;
}
-static int do_oid_object_info_extended(struct repository *r,
+static int do_oid_object_info_extended(struct object_database *odb,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
{
@@ -660,7 +660,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
- real = lookup_replace_object(r, oid);
+ real = lookup_replace_object(odb->repo, oid);
if (is_null_oid(real))
return -1;
@@ -668,7 +668,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (!oi)
oi = &blank_oi;
- co = find_cached_object(r->objects, real);
+ co = find_cached_object(odb, real);
if (co) {
if (oi->typep)
*(oi->typep) = co->type;
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, r->hash_algo);
+ oidclr(oi->delta_base_oid, odb->repo->hash_algo);
if (oi->type_name)
strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
@@ -687,17 +687,17 @@ static int do_oid_object_info_extended(struct repository *r,
}
while (1) {
- if (find_pack_entry(r, real, &e))
+ if (find_pack_entry(odb->repo, real, &e))
break;
/* Most likely it's a loose object. */
- if (!loose_object_info(r, real, oi, flags))
+ if (!loose_object_info(odb->repo, real, oi, flags))
return 0;
/* Not a loose object; someone else may have just packed it. */
if (!(flags & OBJECT_INFO_QUICK)) {
- reprepare_packed_git(r);
- if (find_pack_entry(r, real, &e))
+ reprepare_packed_git(odb->repo);
+ if (find_pack_entry(odb->repo, real, &e))
break;
}
@@ -707,15 +707,15 @@ static int do_oid_object_info_extended(struct repository *r,
* `odb_add_submodule_alternate_by_path()` on that submodule's
* ODB). If any such ODBs exist, register them and try again.
*/
- if (register_all_submodule_alternates(r->objects))
+ if (register_all_submodule_alternates(odb))
/* We added some alternates; retry */
continue;
/* Check if it is a missing object */
- if (fetch_if_missing && repo_has_promisor_remote(r) &&
+ if (fetch_if_missing && repo_has_promisor_remote(odb->repo) &&
!already_retried &&
!(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) {
- promisor_remote_get_direct(r, real, 1);
+ promisor_remote_get_direct(odb->repo, real, 1);
already_retried = 1;
continue;
}
@@ -725,7 +725,7 @@ static int do_oid_object_info_extended(struct repository *r,
if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid))
die(_("replacement %s not found for %s"),
oid_to_hex(real), oid_to_hex(oid));
- if ((p = has_packed_and_bad(r, real)))
+ if ((p = has_packed_and_bad(odb->repo, real)))
die(_("packed object %s (stored in %s) is corrupt"),
oid_to_hex(real), p->pack_name);
}
@@ -738,10 +738,10 @@ static int do_oid_object_info_extended(struct repository *r,
* information below, so return early.
*/
return 0;
- rtype = packed_object_info(r, e.p, e.offset, oi);
+ rtype = packed_object_info(odb->repo, e.p, e.offset, oi);
if (rtype < 0) {
mark_bad_packed_object(e.p, real);
- return do_oid_object_info_extended(r, real, oi, 0);
+ return do_oid_object_info_extended(odb, real, oi, 0);
} else if (oi->whence == OI_PACKED) {
oi->u.packed.offset = e.offset;
oi->u.packed.pack = e.p;
@@ -789,7 +789,7 @@ static int oid_object_info_convert(struct repository *r,
oi = &new_oi;
}
- ret = oid_object_info_extended(r, &oid, oi, flags);
+ ret = odb_read_object_info_extended(r->objects, &oid, oi, flags);
if (ret)
return -1;
if (oi == input_oi)
@@ -839,33 +839,35 @@ static int oid_object_info_convert(struct repository *r,
return ret;
}
-int oid_object_info_extended(struct repository *r, const struct object_id *oid,
- struct object_info *oi, unsigned flags)
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
{
int ret;
- if (oid->algo && (hash_algo_by_ptr(r->hash_algo) != oid->algo))
- return oid_object_info_convert(r, oid, oi, flags);
+ if (oid->algo && (hash_algo_by_ptr(odb->repo->hash_algo) != oid->algo))
+ return oid_object_info_convert(odb->repo, oid, oi, flags);
obj_read_lock();
- ret = do_oid_object_info_extended(r, oid, oi, flags);
+ ret = do_oid_object_info_extended(odb, oid, oi, flags);
obj_read_unlock();
return ret;
}
/* returns enum object_type or negative */
-int oid_object_info(struct repository *r,
- const struct object_id *oid,
- unsigned long *sizep)
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep)
{
enum object_type type;
struct object_info oi = OBJECT_INFO_INIT;
oi.typep = &type;
oi.sizep = sizep;
- if (oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(odb, oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE) < 0)
return -1;
return type;
}
@@ -896,7 +898,7 @@ int pretend_object_file(struct repository *repo,
/*
* This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call oid_object_info_extended() and give
+ * deal with them should arrange to call odb_read_object_info_extended() and give
* error messages themselves.
*/
void *repo_read_object_file(struct repository *r,
@@ -911,7 +913,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (oid_object_info_extended(r, oid, &oi, flags))
+ if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
return NULL;
return data;
@@ -977,13 +979,13 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(odb->repo, oid, NULL);
+ enum object_type type = odb_read_object_info(odb, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index 44326cb698d..e521a608237 100644
--- a/odb.h
+++ b/odb.h
@@ -257,9 +257,6 @@ void *repo_read_object_file(struct repository *r,
enum object_type *type,
unsigned long *size);
-/* Read and unpack an object file into memory, write memory to an object file */
-int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
-
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -331,9 +328,24 @@ struct object_info {
/* Die if object corruption (not just an object being missing) was detected. */
#define OBJECT_INFO_DIE_IF_CORRUPT 32
-int oid_object_info_extended(struct repository *r,
- const struct object_id *,
- struct object_info *, unsigned flags);
+/*
+ * Read object info from the object database and populate the `object_info`
+ * structure. Returns 0 on success, a negative error code otherwise.
+ */
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags);
+
+/*
+ * Read a subset of object info for the given object ID. Returns an `enum
+ * object_type` on success, a negative error code otherwise. If successful and
+ * `sizep` is non-NULL, then the size of the object will be written to the
+ * pointer.
+ */
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep);
enum {
/* Retry packed storage after checking packed and loose storage */
@@ -355,7 +367,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: repo_read_object_file(),
- * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
+ * read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -363,7 +375,7 @@ void odb_assert_oid_type(struct object_database *odb,
* reading functions. However, beware that in these cases zlib inflation won't
* be performed in parallel, losing performance.
*
- * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
+ * TODO: odb_read_object_info_extended()'s call stack has a recursive behavior. If
* any of its callees end up calling it, this recursive call won't benefit from
* parallel inflation.
*/
@@ -411,4 +423,22 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
+/* Compatibility wrappers, to be removed once Git 2.50 has been released. */
+#include "repository.h"
+
+static inline int oid_object_info_extended(struct repository *r,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
+{
+ return odb_read_object_info_extended(r->objects, oid, oi, flags);
+}
+
+static inline int oid_object_info(struct repository *r,
+ const struct object_id *oid,
+ unsigned long *sizep)
+{
+ return odb_read_object_info(r->objects, oid, sizep);
+}
+
#endif /* ODB_H */
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index c847369eaaa..c5183b619c1 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -144,8 +144,8 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
break;
default:
- real_type = oid_object_info(writer->to_pack->repo,
- &entry->idx.oid, NULL);
+ real_type = odb_read_object_info(writer->to_pack->repo->objects,
+ &entry->idx.oid, NULL);
break;
}
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 467a3e91035..0bd6f1c282f 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1868,8 +1868,8 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
size_t eindex_pos = pos - bitmap_num_objects_total(bitmap_git);
struct eindex *eindex = &bitmap_git->ext_index;
struct object *obj = eindex->objects[eindex_pos];
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects, &obj->oid,
+ &oi, 0) < 0)
die(_("unable to get size of %s"), oid_to_hex(&obj->oid));
}
@@ -3220,8 +3220,8 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)
i)))
continue;
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of '%s'"),
oid_to_hex(&obj->oid));
diff --git a/packfile.c b/packfile.c
index ab9628eb3d4..2f022265a5b 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1310,7 +1310,7 @@ static int retry_bad_packed_offset(struct repository *r,
return OBJ_BAD;
nth_packed_object_id(&oid, p, pack_pos_to_index(p, pos));
mark_bad_packed_object(p, &oid);
- type = oid_object_info(r, &oid, NULL);
+ type = odb_read_object_info(r->objects, &oid, NULL);
if (type <= OBJ_NONE)
return OBJ_BAD;
return type;
@@ -1843,7 +1843,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
oi.typep = &type;
oi.sizep = &base_size;
oi.contentp = &base;
- if (oid_object_info_extended(r, &base_oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(r->objects, &base_oid,
+ &oi, 0) < 0)
base = NULL;
external_base = base;
diff --git a/promisor-remote.c b/promisor-remote.c
index 2baa286bfd0..be6f82d12f8 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -245,8 +245,8 @@ static int remove_fetched_oids(struct repository *repo,
struct object_id *new_oids;
for (i = 0; i < oid_nr; i++)
- if (oid_object_info_extended(repo, &old_oids[i], NULL,
- OBJECT_INFO_SKIP_FETCH_OBJECT)) {
+ if (odb_read_object_info_extended(repo->objects, &old_oids[i], NULL,
+ OBJECT_INFO_SKIP_FETCH_OBJECT)) {
remaining[i] = 1;
remaining_nr++;
}
diff --git a/protocol-caps.c b/protocol-caps.c
index 3022f69a1bd..ecdd0dc58d5 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -64,7 +64,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
strbuf_addstr(&send_buffer, oid_str);
if (info->size) {
- if (oid_object_info(r, &oid, &object_size) < 0) {
+ if (odb_read_object_info(r->objects, &oid, &object_size) < 0) {
strbuf_addstr(&send_buffer, " ");
} else {
strbuf_addf(&send_buffer, " %lu", object_size);
diff --git a/reachable.c b/reachable.c
index 9dc748f0b9a..e984b68a0c4 100644
--- a/reachable.c
+++ b/reachable.c
@@ -211,7 +211,7 @@ static void add_recent_object(const struct object_id *oid,
* later processing, and the revision machinery expects
* commits and tags to have been parsed.
*/
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0)
die("unable to get object info for %s", oid_to_hex(oid));
diff --git a/read-cache.c b/read-cache.c
index dce1056ec7c..be664f857b4 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3758,9 +3758,9 @@ void prefetch_cache_entries(const struct index_state *istate,
if (S_ISGITLINK(ce->ce_mode) || !must_prefetch(ce))
continue;
- if (!oid_object_info_extended(the_repository, &ce->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &ce->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &ce->oid);
}
diff --git a/ref-filter.c b/ref-filter.c
index 4ce45440ad1..f9f2c512a8c 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2302,8 +2302,8 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
oi->info.sizep = &oi->size;
oi->info.typep = &oi->type;
}
- if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(the_repository->objects, &oi->oid, &oi->info,
+ OBJECT_INFO_LOOKUP_REPLACE))
return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
oid_to_hex(&oi->oid), ref->refname);
if (oi->info.disk_sizep && oi->disk_size < 0)
diff --git a/remote.c b/remote.c
index 17a842f5684..72c36239d31 100644
--- a/remote.c
+++ b/remote.c
@@ -1182,7 +1182,7 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
BUG("'%s' is not a valid object, "
"match_explicit_lhs() should catch this!",
matched_src_name);
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type == OBJ_COMMIT) {
advise(_("The <src> part of the refspec is a commit object.\n"
"Did you mean to create a new branch by pushing to\n"
@@ -1412,7 +1412,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
continue; /* not a tag */
if (string_list_has_string(&dst_tag, ref->name))
continue; /* they already have it */
- if (oid_object_info(the_repository, &ref->new_oid, NULL) != OBJ_TAG)
+ if (odb_read_object_info(the_repository->objects,
+ &ref->new_oid, NULL) != OBJ_TAG)
continue; /* be conservative */
item = string_list_append(&src_tag, ref->name);
item->util = ref;
diff --git a/sequencer.c b/sequencer.c
index 35f4e68d59f..bb012a4bfd9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5502,9 +5502,8 @@ int sequencer_pick_revisions(struct repository *r,
if (!repo_get_oid(r, name, &oid)) {
if (!lookup_commit_reference_gently(r, &oid, 1)) {
- enum object_type type = oid_object_info(r,
- &oid,
- NULL);
+ enum object_type type = odb_read_object_info(r->objects,
+ &oid, NULL);
res = error(_("%s: can't cherry-pick a %s"),
name, type_name(type));
goto out;
diff --git a/streaming.c b/streaming.c
index 29cc877f22a..032f134dc10 100644
--- a/streaming.c
+++ b/streaming.c
@@ -44,7 +44,7 @@ struct git_istream {
union {
struct {
- char *buf; /* from oid_object_info_extended() */
+ char *buf; /* from odb_read_object_info_extended() */
unsigned long read_ptr;
} incore;
@@ -403,8 +403,8 @@ static int open_istream_incore(struct git_istream *st, struct repository *r,
oi.typep = type;
oi.sizep = &st->size;
oi.contentp = (void **)&st->u.incore.buf;
- return oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_DIE_IF_CORRUPT);
+ return odb_read_object_info_extended(r->objects, oid, &oi,
+ OBJECT_INFO_DIE_IF_CORRUPT);
}
/*****************************************************************************
@@ -422,7 +422,7 @@ static int istream_source(struct git_istream *st,
oi.typep = type;
oi.sizep = &size;
- status = oid_object_info_extended(r, oid, &oi, 0);
+ status = odb_read_object_info_extended(r->objects, oid, &oi, 0);
if (status < 0)
return status;
diff --git a/submodule.c b/submodule.c
index 788c9e55ed3..f8373a9ea7d 100644
--- a/submodule.c
+++ b/submodule.c
@@ -968,7 +968,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
return 0;
}
- type = oid_object_info(&subrepo, oid, NULL);
+ type = odb_read_object_info(subrepo.objects, oid, NULL);
switch (type) {
case OBJ_COMMIT:
@@ -1752,8 +1752,7 @@ static int fetch_start_failure(struct strbuf *err UNUSED,
static int commit_missing_in_sub(const struct object_id *oid, void *data)
{
struct repository *subrepo = data;
-
- enum object_type type = oid_object_info(subrepo, oid, NULL);
+ enum object_type type = odb_read_object_info(subrepo->objects, oid, NULL);
return type != OBJ_COMMIT;
}
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index dba227259a2..d8488007493 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -23,7 +23,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
die("could not init repo");
if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
die("could not parse oid");
- if (oid_object_info_extended(&r, &oid, &oi, 0))
+ if (odb_read_object_info_extended(r.objects, &oid, &oi, 0))
die("could not obtain object info");
printf("%d\n", (int) size);
diff --git a/tag.c b/tag.c
index 5f6868bf7b1..144048fd5e0 100644
--- a/tag.c
+++ b/tag.c
@@ -52,7 +52,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
unsigned long size;
int ret;
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type != OBJ_TAG)
return error("%s: cannot verify a non-tag object of type %s.",
name_to_report ?
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 14/17] odb: rename `repo_read_object_file()`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (12 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 15/17] odb: rename `has_object()` Patrick Steinhardt
` (3 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
Rename `repo_read_object_file()` to `odb_read_object()` to match other
functions related to the object database and our modern coding
guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 10 +++++-----
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 6 +++---
blame.c | 13 ++++++-------
builtin/cat-file.c | 26 +++++++++++---------------
builtin/difftool.c | 2 +-
builtin/fast-export.c | 6 +++---
builtin/fast-import.c | 8 ++++----
builtin/grep.c | 8 ++++----
builtin/index-pack.c | 8 ++++----
builtin/log.c | 2 +-
builtin/merge-tree.c | 12 ++++++------
builtin/mktag.c | 4 ++--
builtin/notes.c | 6 +++---
builtin/pack-objects.c | 30 +++++++++++++++---------------
builtin/tag.c | 4 ++--
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 4 ++--
bundle.c | 2 +-
combine-diff.c | 2 +-
commit.c | 6 +++---
config.c | 2 +-
dir.c | 2 +-
entry.c | 4 ++--
fmt-merge-msg.c | 4 ++--
fsck.c | 2 +-
grep.c | 4 ++--
http-push.c | 4 ++--
mailmap.c | 2 +-
match-trees.c | 4 ++--
merge-blobs.c | 8 ++++----
merge-ort.c | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 13 +++++++------
object.c | 2 +-
odb.c | 19 +++++++------------
odb.h | 29 +++++++++++++++++++++++------
read-cache.c | 6 +++---
reflog.c | 4 ++--
rerere.c | 5 ++---
submodule-config.c | 4 ++--
tag.c | 6 +++---
tree-walk.c | 6 +++---
tree.c | 4 ++--
xdiff-interface.c | 2 +-
47 files changed, 157 insertions(+), 150 deletions(-)
diff --git a/apply.c b/apply.c
index 879f04df31e..56cd0540350 100644
--- a/apply.c
+++ b/apply.c
@@ -3210,8 +3210,8 @@ static int apply_binary(struct apply_state *state,
unsigned long size;
char *result;
- result = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ result = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!result)
return error(_("the necessary postimage %s for "
"'%s' cannot be read"),
@@ -3273,8 +3273,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
unsigned long sz;
char *result;
- result = repo_read_object_file(the_repository, oid, &type,
- &sz);
+ result = odb_read_object(the_repository->objects, oid,
+ &type, &sz);
if (!result)
return -1;
/* XXX read_sha1_file NUL-terminates */
@@ -3503,7 +3503,7 @@ static int resolve_to(struct image *image, const struct object_id *result_id)
image_clear(image);
- data = repo_read_object_file(the_repository, result_id, &type, &size);
+ data = odb_read_object(the_repository->objects, result_id, &type, &size);
if (!data || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(result_id));
strbuf_attach(&image->buf, data, size, size + 1);
diff --git a/archive.c b/archive.c
index f2511d530d5..f5a9d45c8d3 100644
--- a/archive.c
+++ b/archive.c
@@ -98,7 +98,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
(args->tree ? &args->tree->object.oid : NULL), oid);
path += args->baselen;
- buffer = repo_read_object_file(the_repository, oid, type, sizep);
+ buffer = odb_read_object(the_repository->objects, oid, type, sizep);
if (buffer && S_ISREG(mode)) {
struct strbuf buf = STRBUF_INIT;
size_t size = 0;
diff --git a/attr.c b/attr.c
index e5680db7f65..d1daeb0b4d9 100644
--- a/attr.c
+++ b/attr.c
@@ -779,7 +779,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
if (get_tree_entry(istate->repo, tree_oid, path, &oid, &mode))
return NULL;
- buf = repo_read_object_file(istate->repo, &oid, &type, &sz);
+ buf = odb_read_object(istate->repo->objects, &oid, &type, &sz);
if (!buf || type != OBJ_BLOB) {
free(buf);
return NULL;
diff --git a/bisect.c b/bisect.c
index a7939216d00..f24474542ec 100644
--- a/bisect.c
+++ b/bisect.c
@@ -155,9 +155,9 @@ static void show_list(const char *debug, int counted, int nr,
unsigned commit_flags = commit->object.flags;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository,
- &commit->object.oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects,
+ &commit->object.oid, &type,
+ &size);
const char *subject_start;
int subject_len;
diff --git a/blame.c b/blame.c
index 97db3355af4..858d2d74df9 100644
--- a/blame.c
+++ b/blame.c
@@ -1041,9 +1041,9 @@ static void fill_origin_blob(struct diff_options *opt,
&o->blob_oid, 1, &file->ptr, &file_size))
;
else
- file->ptr = repo_read_object_file(the_repository,
- &o->blob_oid, &type,
- &file_size);
+ file->ptr = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &file_size);
file->size = file_size;
if (!file->ptr)
@@ -2869,10 +2869,9 @@ void setup_scoreboard(struct blame_scoreboard *sb,
&sb->final_buf_size))
;
else
- sb->final_buf = repo_read_object_file(the_repository,
- &o->blob_oid,
- &type,
- &sb->final_buf_size);
+ sb->final_buf = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &sb->final_buf_size);
if (!sb->final_buf)
die(_("cannot read blob %s for path %s"),
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index da172155c85..d6b9afca06e 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -74,7 +74,7 @@ static int filter_object(const char *path, unsigned mode,
{
enum object_type type;
- *buf = repo_read_object_file(the_repository, oid, &type, size);
+ *buf = odb_read_object(the_repository->objects, oid, &type, size);
if (!*buf)
return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path);
@@ -206,8 +206,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
ret = stream_blob(&oid);
goto cleanup;
}
- buf = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!buf)
die("Cannot read object %s", obj_name);
@@ -228,10 +228,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
struct object_id blob_oid;
if (odb_read_object_info(the_repository->objects,
&oid, NULL) == OBJ_TAG) {
- char *buffer = repo_read_object_file(the_repository,
- &oid,
- &type,
- &size);
+ char *buffer = odb_read_object(the_repository->objects,
+ &oid, &type, &size);
const char *target;
if (!buffer)
@@ -412,10 +410,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
if (!textconv_object(the_repository,
data->rest, 0100644, oid,
1, &contents, &size))
- contents = repo_read_object_file(the_repository,
- oid,
- &type,
- &size);
+ contents = odb_read_object(the_repository->objects,
+ oid, &type, &size);
if (!contents)
die("could not convert '%s' %s",
oid_to_hex(oid), data->rest);
@@ -432,8 +428,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
unsigned long size;
void *contents;
- contents = repo_read_object_file(the_repository, oid, &type,
- &size);
+ contents = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!contents)
die("object %s disappeared", oid_to_hex(oid));
@@ -542,8 +538,8 @@ static void batch_object_write(const char *obj_name,
size_t s = data->size;
char *buf = NULL;
- buf = repo_read_object_file(the_repository, &data->oid, &data->type,
- &data->size);
+ buf = odb_read_object(the_repository->objects, &data->oid,
+ &data->type, &data->size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&data->oid));
buf = replace_idents_using_mailmap(buf, &s);
diff --git a/builtin/difftool.c b/builtin/difftool.c
index fac613e3bc3..e4bc1f83169 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -320,7 +320,7 @@ static char *get_symlink(struct repository *repo,
} else {
enum object_type type;
unsigned long size;
- data = repo_read_object_file(repo, oid, &type, &size);
+ data = odb_read_object(repo->objects, oid, &type, &size);
if (!data)
die(_("could not read object %s for symlink %s"),
oid_to_hex(oid), path);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 6c93cf0a8aa..33f304dd0ad 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -323,7 +323,7 @@ static void export_blob(const struct object_id *oid)
object = (struct object *)lookup_blob(the_repository, oid);
eaten = 0;
} else {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
die("could not read blob %s", oid_to_hex(oid));
if (check_object_signature(the_repository, oid, buf, size,
@@ -869,8 +869,8 @@ static void handle_tag(const char *name, struct tag *tag)
return;
}
- buf = repo_read_object_file(the_repository, &tag->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &tag->object.oid,
+ &type, &size);
if (!buf)
die("could not read tag %s", oid_to_hex(&tag->object.oid));
message = memmem(buf, size, "\n\n", 2);
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 2718376f2c9..1973c504e25 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1265,7 +1265,7 @@ static void load_tree(struct tree_entry *root)
die("Can't load tree %s", oid_to_hex(oid));
} else {
enum object_type type;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_TREE)
die("Can't load tree %s", oid_to_hex(oid));
}
@@ -3002,7 +3002,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
char *buf;
if (!oe || oe->pack_id == MAX_PACK_ID) {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
} else {
type = oe->type;
buf = gfi_unpack_entry(oe, &size);
@@ -3110,8 +3110,8 @@ static struct object_entry *dereference(struct object_entry *oe,
buf = gfi_unpack_entry(oe, &size);
} else {
enum object_type unused;
- buf = repo_read_object_file(the_repository, oid, &unused,
- &size);
+ buf = odb_read_object(the_repository->objects, oid,
+ &unused, &size);
}
if (!buf)
die("Can't load object %s", oid_to_hex(oid));
diff --git a/builtin/grep.c b/builtin/grep.c
index 311c940aa9e..f84298af0f6 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -573,8 +573,8 @@ static int grep_cache(struct grep_opt *opt,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository, &ce->oid,
- &type, &size);
+ data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &size);
if (!data)
die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
init_tree_desc(&tree, &ce->oid, data, size);
@@ -666,8 +666,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository,
- &entry.oid, &type, &size);
+ data = odb_read_object(the_repository->objects,
+ &entry.oid, &type, &size);
if (!data)
die(_("unable to read tree (%s)"),
oid_to_hex(&entry.oid));
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 82cf80b89d1..d33392cab65 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -914,8 +914,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
- has_data = repo_read_object_file(the_repository, oid,
- &has_type, &has_size);
+ has_data = odb_read_object(the_repository->objects, oid,
+ &has_type, &has_size);
read_unlock();
if (!data)
data = new_data = get_data_from_pack(obj_entry);
@@ -1515,8 +1515,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue;
- data = repo_read_object_file(the_repository, &d->oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &d->oid,
+ &type, &size);
if (!data)
continue;
diff --git a/builtin/log.c b/builtin/log.c
index fe9cc5ebecb..f2040b18159 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -714,7 +714,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
unsigned long offset = 0;
if (!buf)
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 709ae3966a6..21fb0b2df1d 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -75,9 +75,9 @@ static void *result(struct merge_list *entry, unsigned long *size)
const char *path = entry->path;
if (!entry->stage)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid, &type,
- size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid, &type,
+ size);
base = NULL;
if (entry->stage == 1) {
base = entry->blob;
@@ -100,9 +100,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)
enum object_type type;
while (entry) {
if (entry->stage == 2)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid,
+ &type, size);
entry = entry->link;
}
return NULL;
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 1809b38f937..1b391119de8 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -54,8 +54,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
void *buffer;
const struct object_id *repl;
- buffer = repo_read_object_file(the_repository, tagged_oid, &type,
- &size);
+ buffer = odb_read_object(the_repository->objects, tagged_oid,
+ &type, &size);
if (!buffer)
die(_("could not read tagged object '%s'"),
oid_to_hex(tagged_oid));
diff --git a/builtin/notes.c b/builtin/notes.c
index 783d4932ca6..a9529b1696a 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -152,7 +152,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (buf) {
if (size)
write_or_die(fd, buf, size);
@@ -319,7 +319,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
strbuf_init(&msg->buf, 0);
if (repo_get_oid(the_repository, arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
- if (!(value = repo_read_object_file(the_repository, &object, &type, &len)))
+ if (!(value = odb_read_object(the_repository->objects, &object, &type, &len)))
die(_("failed to read object '%s'."), arg);
if (type != OBJ_BLOB) {
strbuf_release(&msg->buf);
@@ -722,7 +722,7 @@ static int append_edit(int argc, const char **argv, const char *prefix,
unsigned long size;
enum object_type type;
struct strbuf buf = STRBUF_INIT;
- char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
+ char *prev_buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!prev_buf)
die(_("unable to read %s"), oid_to_hex(note));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index da35d684081..580a5c1996b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -337,13 +337,13 @@ static void *get_delta(struct object_entry *entry)
void *buf, *base_buf, *delta_buf;
enum object_type type;
- buf = repo_read_object_file(the_repository, &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &entry->idx.oid,
+ &type, &size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
- base_buf = repo_read_object_file(the_repository,
- &DELTA(entry)->idx.oid, &type,
- &base_size);
+ base_buf = odb_read_object(the_repository->objects,
+ &DELTA(entry)->idx.oid, &type,
+ &base_size);
if (!base_buf)
die("unable to read %s",
oid_to_hex(&DELTA(entry)->idx.oid));
@@ -506,9 +506,9 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
&size, NULL)) != NULL)
buf = NULL;
else {
- buf = repo_read_object_file(the_repository,
- &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects,
+ &entry->idx.oid, &type,
+ &size);
if (!buf)
die(_("unable to read %s"),
oid_to_hex(&entry->idx.oid));
@@ -1895,7 +1895,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
/* Did not find one. Either we got a bogus request or
* we need to read and perhaps cache.
*/
- data = repo_read_object_file(the_repository, oid, &type, &size);
+ data = odb_read_object(the_repository->objects, oid, &type, &size);
if (!data)
return NULL;
if (type != OBJ_TREE) {
@@ -2762,9 +2762,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
/* Load data if not already done */
if (!trg->data) {
packing_data_lock(&to_pack);
- trg->data = repo_read_object_file(the_repository,
- &trg_entry->idx.oid, &type,
- &sz);
+ trg->data = odb_read_object(the_repository->objects,
+ &trg_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!trg->data)
die(_("object %s cannot be read"),
@@ -2777,9 +2777,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
}
if (!src->data) {
packing_data_lock(&to_pack);
- src->data = repo_read_object_file(the_repository,
- &src_entry->idx.oid, &type,
- &sz);
+ src->data = odb_read_object(the_repository->objects,
+ &src_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!src->data) {
if (src_entry->preferred_base) {
diff --git a/builtin/tag.c b/builtin/tag.c
index e0b27396c6b..46cbf892e34 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -244,7 +244,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
struct strbuf payload = STRBUF_INIT;
struct strbuf signature = STRBUF_INIT;
- orig = buf = repo_read_object_file(the_repository, oid, &type, &size);
+ orig = buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return;
if (parse_signature(buf, size, &payload, &signature)) {
@@ -407,7 +407,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
strbuf_addstr(sb, "object of unknown type");
break;
case OBJ_COMMIT:
- if ((buf = repo_read_object_file(the_repository, oid, &type, &size))) {
+ if ((buf = odb_read_object(the_repository->objects, oid, &type, &size))) {
subject_len = find_commit_subject(buf, &subject_start);
strbuf_insert(sb, sb->len, subject_start, subject_len);
} else {
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index b92fd4710a9..4360872ae07 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -14,7 +14,7 @@ static char *create_temp_file(struct object_id *oid)
unsigned long size;
int fd;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 405e78bc592..4bc6575a574 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -516,8 +516,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
return;
- base = repo_read_object_file(the_repository, &base_oid, &type,
- &base_size);
+ base = odb_read_object(the_repository->objects, &base_oid,
+ &type, &base_size);
if (!base) {
error("failed to read delta-pack base object %s",
oid_to_hex(&base_oid));
diff --git a/bundle.c b/bundle.c
index c67f85126da..66d0e8eaf0e 100644
--- a/bundle.c
+++ b/bundle.c
@@ -305,7 +305,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
if (revs->max_age == -1 && revs->min_age == -1)
goto out;
- buf = repo_read_object_file(the_repository, &tag->oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &tag->oid, &type, &size);
if (!buf)
goto out;
line = memmem(buf, size, "\ntagger ", 8);
diff --git a/combine-diff.c b/combine-diff.c
index cf23a753407..4ea2dc93c4f 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -325,7 +325,7 @@ static char *grab_blob(struct repository *r,
*size = fill_textconv(r, textconv, df, &blob);
free_filespec(df);
} else {
- blob = repo_read_object_file(r, oid, &type, size);
+ blob = odb_read_object(r->objects, oid, &type, size);
if (!blob)
die(_("unable to read %s"), oid_to_hex(oid));
if (type != OBJ_BLOB)
diff --git a/commit.c b/commit.c
index d4aa9c7a5f8..28ee6b73ae6 100644
--- a/commit.c
+++ b/commit.c
@@ -374,7 +374,7 @@ const void *repo_get_commit_buffer(struct repository *r,
if (!ret) {
enum object_type type;
unsigned long size;
- ret = repo_read_object_file(r, &commit->object.oid, &type, &size);
+ ret = odb_read_object(r->objects, &commit->object.oid, &type, &size);
if (!ret)
die("cannot read commit object %s",
oid_to_hex(&commit->object.oid));
@@ -1275,8 +1275,8 @@ static void handle_signed_tag(const struct commit *parent, struct commit_extra_h
desc = merge_remote_util(parent);
if (!desc || !desc->obj)
return;
- buf = repo_read_object_file(the_repository, &desc->obj->oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &desc->obj->oid,
+ &type, &size);
if (!buf || type != OBJ_TAG)
goto free_return;
if (!parse_signature(buf, size, &payload, &signature))
diff --git a/config.c b/config.c
index 883dd066827..142c37215a8 100644
--- a/config.c
+++ b/config.c
@@ -1942,7 +1942,7 @@ int git_config_from_blob_oid(config_fn_t fn,
unsigned long size;
int ret;
- buf = repo_read_object_file(repo, oid, &type, &size);
+ buf = odb_read_object(repo->objects, oid, &type, &size);
if (!buf)
return error(_("unable to load config blob object '%s'"), name);
if (type != OBJ_BLOB) {
diff --git a/dir.c b/dir.c
index e11342e1366..251dedf1f5e 100644
--- a/dir.c
+++ b/dir.c
@@ -302,7 +302,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
*size_out = 0;
*data_out = NULL;
- data = repo_read_object_file(the_repository, oid, &type, &sz);
+ data = odb_read_object(the_repository->objects, oid, &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return -1;
diff --git a/entry.c b/entry.c
index 75d55038d7c..cae02eb5039 100644
--- a/entry.c
+++ b/entry.c
@@ -93,8 +93,8 @@ void *read_blob_entry(const struct cache_entry *ce, size_t *size)
{
enum object_type type;
unsigned long ul;
- void *blob_data = repo_read_object_file(the_repository, &ce->oid,
- &type, &ul);
+ void *blob_data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &ul);
*size = ul;
if (blob_data) {
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 1a8c972adf3..40174efa3de 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -526,8 +526,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
struct object_id *oid = origins.items[i].util;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository, oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects, oid,
+ &type, &size);
char *origbuf = buf;
unsigned long len = size;
struct signature_check sigc = { NULL };
diff --git a/fsck.c b/fsck.c
index e69baab3af7..23965e1880f 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1293,7 +1293,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
if (oidset_contains(blobs_done, oid))
continue;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
if (is_promisor_object(the_repository, oid))
continue;
diff --git a/grep.c b/grep.c
index dc77e6c4631..932647e4a65 100644
--- a/grep.c
+++ b/grep.c
@@ -1931,8 +1931,8 @@ static int grep_source_load_oid(struct grep_source *gs)
{
enum object_type type;
- gs->buf = repo_read_object_file(gs->repo, gs->identifier, &type,
- &gs->size);
+ gs->buf = odb_read_object(gs->repo->objects, gs->identifier,
+ &type, &gs->size);
if (!gs->buf)
return error(_("'%s': unable to read %s"),
gs->name,
diff --git a/http-push.c b/http-push.c
index d1b1bb23711..9481825abfb 100644
--- a/http-push.c
+++ b/http-push.c
@@ -369,8 +369,8 @@ static void start_put(struct transfer_request *request)
ssize_t size;
git_zstream stream;
- unpacked = repo_read_object_file(the_repository, &request->obj->oid,
- &type, &len);
+ unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
+ &type, &len);
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
/* Set it up */
diff --git a/mailmap.c b/mailmap.c
index b18e74c2110..56c72102d9e 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -196,7 +196,7 @@ int read_mailmap_blob(struct string_list *map, const char *name)
if (repo_get_oid(the_repository, name, &oid) < 0)
return 0;
- buf = repo_read_object_file(the_repository, &oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &oid, &type, &size);
if (!buf)
return error("unable to read mailmap object at %s", name);
if (type != OBJ_BLOB) {
diff --git a/match-trees.c b/match-trees.c
index 4704f95c340..5a8a5c39b04 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -63,7 +63,7 @@ static void *fill_tree_desc_strict(struct repository *r,
enum object_type type;
unsigned long size;
- buffer = repo_read_object_file(r, hash, &type, &size);
+ buffer = odb_read_object(r->objects, hash, &type, &size);
if (!buffer)
die("unable to read tree (%s)", oid_to_hex(hash));
if (type != OBJ_TREE)
@@ -199,7 +199,7 @@ static int splice_tree(struct repository *r,
if (*subpath)
subpath++;
- buf = repo_read_object_file(r, oid1, &type, &sz);
+ buf = odb_read_object(r->objects, oid1, &type, &sz);
if (!buf)
die("cannot read tree %s", oid_to_hex(oid1));
init_tree_desc(&desc, oid1, buf, sz);
diff --git a/merge-blobs.c b/merge-blobs.c
index ba8a3fdfd82..6fc27994171 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -12,8 +12,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
unsigned long size;
enum object_type type;
- buf = repo_read_object_file(the_repository, &obj->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &obj->object.oid,
+ &type, &size);
if (!buf)
return -1;
if (type != OBJ_BLOB) {
@@ -79,8 +79,8 @@ void *merge_blobs(struct index_state *istate, const char *path,
return NULL;
if (!our)
our = their;
- return repo_read_object_file(the_repository, &our->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects, &our->object.oid,
+ &type, size);
}
if (fill_mmfile_blob(&f1, our) < 0)
diff --git a/merge-ort.c b/merge-ort.c
index 5d4501085e9..53417d399c7 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -3624,7 +3624,7 @@ static int read_oid_strbuf(struct merge_options *opt,
void *buf;
enum object_type type;
unsigned long size;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
path, NULL, NULL, NULL,
diff --git a/notes-cache.c b/notes-cache.c
index 344f67762b8..dd56feed6e8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -87,7 +87,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
value_oid = get_note(&c->tree, key_oid);
if (!value_oid)
return NULL;
- value = repo_read_object_file(the_repository, value_oid, &type, &size);
+ value = odb_read_object(the_repository->objects, value_oid, &type, &size);
*outsize = size;
return value;
diff --git a/notes-merge.c b/notes-merge.c
index de6a52e2e7f..586939939f2 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -340,7 +340,7 @@ static void write_note_to_worktree(const struct object_id *obj,
{
enum object_type type;
unsigned long size;
- void *buf = repo_read_object_file(the_repository, note, &type, &size);
+ void *buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!buf)
die("cannot read note %s for object %s",
diff --git a/notes.c b/notes.c
index fc000e501d2..73eb5f00cf5 100644
--- a/notes.c
+++ b/notes.c
@@ -816,15 +816,15 @@ int combine_notes_concatenate(struct object_id *cur_oid,
/* read in both note blob objects */
if (!is_null_oid(new_oid))
- new_msg = repo_read_object_file(the_repository, new_oid,
- &new_type, &new_len);
+ new_msg = odb_read_object(the_repository->objects, new_oid,
+ &new_type, &new_len);
if (!new_msg || !new_len || new_type != OBJ_BLOB) {
free(new_msg);
return 0;
}
if (!is_null_oid(cur_oid))
- cur_msg = repo_read_object_file(the_repository, cur_oid,
- &cur_type, &cur_len);
+ cur_msg = odb_read_object(the_repository->objects, cur_oid,
+ &cur_type, &cur_len);
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
free(cur_msg);
free(new_msg);
@@ -880,7 +880,7 @@ static int string_list_add_note_lines(struct string_list *list,
return 0;
/* read_sha1_file NUL-terminates */
- data = repo_read_object_file(the_repository, oid, &t, &len);
+ data = odb_read_object(the_repository->objects, oid, &t, &len);
if (t != OBJ_BLOB || !data || !len) {
free(data);
return t != OBJ_BLOB || !data;
@@ -1290,7 +1290,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!oid)
return;
- if (!(msg = repo_read_object_file(the_repository, oid, &type, &msglen)) || type != OBJ_BLOB) {
+ if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
+ type != OBJ_BLOB) {
free(msg);
return;
}
diff --git a/object.c b/object.c
index 868d89eed42..c1553ee4330 100644
--- a/object.c
+++ b/object.c
@@ -335,7 +335,7 @@ struct object *parse_object_with_flags(struct repository *r,
return &lookup_tree(r, oid)->object;
}
- buffer = repo_read_object_file(r, oid, &type, &size);
+ buffer = odb_read_object(r->objects, oid, &type, &size);
if (buffer) {
if (!skip_hash &&
check_object_signature(r, repl, buffer, size, type) < 0) {
diff --git a/odb.c b/odb.c
index 3d5d4ff8454..5202f107af2 100644
--- a/odb.c
+++ b/odb.c
@@ -30,7 +30,7 @@ KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -896,15 +896,10 @@ int pretend_object_file(struct repository *repo,
return 0;
}
-/*
- * This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call odb_read_object_info_extended() and give
- * error messages themselves.
- */
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size)
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
{
struct object_info oi = OBJECT_INFO_INIT;
unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT | OBJECT_INFO_LOOKUP_REPLACE;
@@ -913,7 +908,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
+ if (odb_read_object_info_extended(odb, oid, &oi, flags))
return NULL;
return data;
@@ -935,7 +930,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = repo_read_object_file(r, &actual_oid, &type, &isize);
+ buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
diff --git a/odb.h b/odb.h
index e521a608237..fb56cc9e1fe 100644
--- a/odb.h
+++ b/odb.h
@@ -133,7 +133,7 @@ struct object_database {
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -252,10 +252,19 @@ void odb_add_to_alternates_file(struct object_database *odb,
void odb_add_to_alternates_memory(struct object_database *odb,
const char *dir);
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size);
+/*
+ * Read an object from the database. Returns the object data and assigns object
+ * type and size to the `type` and `size` pointers, if these pointers are
+ * non-NULL. Returns a `NULL` pointer in case the object does not exist.
+ *
+ * This function dies on corrupt objects; the callers who want to deal with
+ * them should arrange to call odb_read_object_info_extended() and give error
+ * messages themselves.
+ */
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size);
/*
* Add an object file to the in-memory object store, without writing it
@@ -366,7 +375,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
- * following functions in parallel: repo_read_object_file(),
+ * following functions in parallel: odb_read_object(),
* read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
@@ -441,4 +450,12 @@ static inline int oid_object_info(struct repository *r,
return odb_read_object_info(r->objects, oid, sizep);
}
+static inline void *repo_read_object_file(struct repository *r,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
+{
+ return odb_read_object(r->objects, oid, type, size);
+}
+
#endif /* ODB_H */
diff --git a/read-cache.c b/read-cache.c
index be664f857b4..46986798a38 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -254,7 +254,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
if (strbuf_readlink(&sb, ce->name, expected_size))
return -1;
- buffer = repo_read_object_file(the_repository, &ce->oid, &type, &size);
+ buffer = odb_read_object(the_repository->objects, &ce->oid, &type, &size);
if (buffer) {
if (size == sb.len)
match = memcmp(buffer, sb.buf, size);
@@ -3514,8 +3514,8 @@ void *read_blob_data_from_index(struct index_state *istate,
}
if (pos < 0)
return NULL;
- data = repo_read_object_file(the_repository, &istate->cache[pos]->oid,
- &type, &sz);
+ data = odb_read_object(the_repository->objects, &istate->cache[pos]->oid,
+ &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return NULL;
diff --git a/reflog.c b/reflog.c
index 4f8a3b717cd..747b82eada8 100644
--- a/reflog.c
+++ b/reflog.c
@@ -140,8 +140,8 @@ static int tree_is_complete(const struct object_id *oid)
if (!tree->buffer) {
enum object_type type;
unsigned long size;
- void *data = repo_read_object_file(the_repository, oid, &type,
- &size);
+ void *data = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!data) {
tree->object.flags |= INCOMPLETE;
return 0;
diff --git a/rerere.c b/rerere.c
index 951e4bf8b41..8bb97c98229 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1000,9 +1000,8 @@ static int handle_cache(struct index_state *istate,
break;
i = ce_stage(ce) - 1;
if (!mmfile[i].ptr) {
- mmfile[i].ptr = repo_read_object_file(the_repository,
- &ce->oid, &type,
- &size);
+ mmfile[i].ptr = odb_read_object(the_repository->objects,
+ &ce->oid, &type, &size);
if (!mmfile[i].ptr)
die(_("unable to read %s"),
oid_to_hex(&ce->oid));
diff --git a/submodule-config.c b/submodule-config.c
index 0f775f93259..2730a47fad1 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -743,8 +743,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
if (submodule)
goto out;
- config = repo_read_object_file(the_repository, &oid, &type,
- &config_size);
+ config = odb_read_object(the_repository->objects, &oid,
+ &type, &config_size);
if (!config || type != OBJ_BLOB)
goto out;
diff --git a/tag.c b/tag.c
index 144048fd5e0..1d52686ee10 100644
--- a/tag.c
+++ b/tag.c
@@ -60,7 +60,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV),
type_name(type));
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return error("%s: unable to read file.",
name_to_report ?
@@ -222,8 +222,8 @@ int parse_tag(struct tag *item)
if (item->object.parsed)
return 0;
- data = repo_read_object_file(the_repository, &item->object.oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!data)
return error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/tree-walk.c b/tree-walk.c
index 34b0fff4873..766af99f466 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -795,9 +795,9 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
*/
retval = DANGLING_SYMLINK;
- contents = repo_read_object_file(r,
- ¤t_tree_oid, &type,
- &link_len);
+ contents = odb_read_object(r->objects,
+ ¤t_tree_oid, &type,
+ &link_len);
if (!contents)
goto done;
diff --git a/tree.c b/tree.c
index 341b7c2ff3f..1ef743d90f4 100644
--- a/tree.c
+++ b/tree.c
@@ -193,8 +193,8 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
if (item->object.parsed)
return 0;
- buffer = repo_read_object_file(the_repository, &item->object.oid,
- &type, &size);
+ buffer = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!buffer)
return quiet_on_missing ? -1 :
error("Could not read %s",
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 01e6e378ea6..0e5d38c9600 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -187,7 +187,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
return;
}
- ptr->ptr = repo_read_object_file(the_repository, oid, &type, &size);
+ ptr->ptr = odb_read_object(the_repository->objects, oid, &type, &size);
if (!ptr->ptr || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
ptr->size = size;
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 15/17] odb: rename `has_object()`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (13 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
` (2 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
Rename `has_object()` to `odb_has_object()` to match other functions
related to the object database and our modern coding guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 2 +-
builtin/backfill.c | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/clone.c | 2 +-
builtin/fetch.c | 17 +++++++++--------
builtin/fsck.c | 2 +-
builtin/index-pack.c | 4 ++--
builtin/pack-objects.c | 4 ++--
builtin/receive-pack.c | 4 ++--
builtin/remote.c | 4 ++--
builtin/show-ref.c | 4 ++--
builtin/unpack-objects.c | 4 ++--
bulk-checkin.c | 4 ++--
cache-tree.c | 15 ++++++++-------
commit-graph.c | 2 +-
commit.c | 2 +-
fetch-pack.c | 8 ++++----
http-push.c | 14 ++++++++------
http-walker.c | 8 ++++----
list-objects.c | 4 ++--
notes.c | 4 ++--
odb.c | 6 +++---
odb.h | 12 ++++++++++--
reflog.c | 2 +-
refs.c | 3 ++-
remote.c | 2 +-
send-pack.c | 2 +-
shallow.c | 12 ++++++------
upload-pack.c | 2 +-
walker.c | 4 ++--
30 files changed, 87 insertions(+), 74 deletions(-)
diff --git a/apply.c b/apply.c
index 56cd0540350..7fb56517649 100644
--- a/apply.c
+++ b/apply.c
@@ -3204,7 +3204,7 @@ static int apply_binary(struct apply_state *state,
return 0; /* deletion patch */
}
- if (has_object(the_repository, &oid, 0)) {
+ if (odb_has_object(the_repository->objects, &oid, 0)) {
/* We already have the postimage */
enum object_type type;
unsigned long size;
diff --git a/builtin/backfill.c b/builtin/backfill.c
index 0b49baa39fa..80056abe473 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -67,8 +67,8 @@ static int fill_missing_blobs(const char *path UNUSED,
return 0;
for (size_t i = 0; i < list->nr; i++) {
- if (!has_object(ctx->repo, &list->oid[i],
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_has_object(ctx->repo->objects, &list->oid[i],
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&ctx->current_batch, &list->oid[i]);
}
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index d6b9afca06e..571b5cc2ad5 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -169,8 +169,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
goto cleanup;
case 'e':
- ret = !has_object(the_repository, &oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
+ ret = !odb_has_object(the_repository->objects, &oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
goto cleanup;
case 'w':
diff --git a/builtin/clone.c b/builtin/clone.c
index 3aabdf6570b..6d08abed37c 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -506,7 +506,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
continue;
if (ends_with(ref->name, "^{}"))
continue;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
refs_update_ref(get_main_ref_store(the_repository), msg,
ref->name, &ref->old_oid, NULL, 0,
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 82e9603ccab..2000299bcc5 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -366,9 +366,9 @@ static void find_non_local_tags(const struct ref *refs,
*/
if (ends_with(ref->name, "^{}")) {
if (item &&
- !has_object(the_repository, &ref->old_oid, 0) &&
+ !odb_has_object(the_repository->objects, &ref->old_oid, 0) &&
!oidset_contains(&fetch_oids, &ref->old_oid) &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
item = NULL;
@@ -382,7 +382,7 @@ static void find_non_local_tags(const struct ref *refs,
* fetch.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -403,7 +403,7 @@ static void find_non_local_tags(const struct ref *refs,
* checked to see if it needs fetching.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -910,8 +910,8 @@ static int update_local_ref(struct ref *ref,
struct commit *current = NULL, *updated;
int fast_forward = 0;
- if (!has_object(the_repository, &ref->new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &ref->new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
if (oideq(&ref->old_oid, &ref->new_oid)) {
@@ -1330,7 +1330,8 @@ static int check_exist_and_connected(struct ref *ref_map)
* we need all direct targets to exist.
*/
for (r = rm; r; r = r->next) {
- if (!has_object(the_repository, &r->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ if (!odb_has_object(the_repository->objects, &r->old_oid,
+ HAS_OBJECT_RECHECK_PACKED))
return -1;
}
@@ -1485,7 +1486,7 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
struct object_id oid;
if (repo_get_oid(the_repository, s, &oid))
die(_("%s is not a valid object"), s);
- if (!has_object(the_repository, &oid, 0))
+ if (!odb_has_object(the_repository->objects, &oid, 0))
die(_("the object %s does not exist"), s);
oid_array_append(oids, &oid);
continue;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 08a79fe044d..74bfa182597 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -161,7 +161,7 @@ static int mark_object(struct object *obj, enum object_type type,
return 0;
if (!(obj->flags & HAS_OBJ)) {
- if (parent && !has_object(the_repository, &obj->oid, 1)) {
+ if (parent && !odb_has_object(the_repository->objects, &obj->oid, 1)) {
printf_ln(_("broken link from %7s %s\n"
" to %7s %s"),
printable_type(&parent->oid, parent->type),
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index d33392cab65..0aa2f099cbe 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -893,8 +893,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (startup_info->have_repository) {
read_lock();
- collision_test_needed = has_object(the_repository, oid,
- HAS_OBJECT_FETCH_PROMISOR);
+ collision_test_needed = odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_FETCH_PROMISOR);
read_unlock();
}
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 580a5c1996b..06bdeb4223b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3968,7 +3968,7 @@ static void show_object__ma_allow_any(struct object *obj, const char *name, void
* Quietly ignore ALL missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0))
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0))
return;
show_object(obj, name, data);
@@ -3982,7 +3982,7 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
* Quietly ignore EXPECTED missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0) &&
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0) &&
is_promisor_object(to_pack.repo, &obj->oid))
return;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 8c157ea7d1b..27684dce3a4 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1508,8 +1508,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
}
if (!is_null_oid(new_oid) &&
- !has_object(the_repository, new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error("unpack should have generated %s, "
"but I can't find it!", oid_to_hex(new_oid));
ret = "bad pack";
diff --git a/builtin/remote.c b/builtin/remote.c
index ac5b8d2a1a6..7cbda285ebe 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -454,8 +454,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
info->status = PUSH_STATUS_UPTODATE;
else if (is_null_oid(&ref->old_oid))
info->status = PUSH_STATUS_CREATE;
- else if (has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ else if (odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
ref_newer(&ref->new_oid, &ref->old_oid))
info->status = PUSH_STATUS_FASTFORWARD;
else
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 90ec1de78f9..117709cb076 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -35,8 +35,8 @@ static void show_one(const struct show_one_options *opts,
const char *hex;
struct object_id peeled;
- if (!has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die("git show-ref: bad ref %s (%s)", refname,
oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 4bc6575a574..a69d59eb50c 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -449,8 +449,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
delta_data = get_data(delta_size);
if (!delta_data)
return;
- if (has_object(the_repository, &base_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &base_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
; /* Ok we have this one */
else if (resolve_against_held(nr, &base_oid,
delta_data, delta_size))
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 55406a539e7..16df86c0ba8 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -130,8 +130,8 @@ static void flush_batch_fsync(void)
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
{
/* The object may already exist in the repository */
- if (has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 1;
/* Might want to keep the list sorted */
diff --git a/cache-tree.c b/cache-tree.c
index 9786b32b3a1..a4bc14ad15c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -239,8 +239,8 @@ int cache_tree_fully_valid(struct cache_tree *it)
if (!it)
return 0;
if (it->entry_count < 0 ||
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
for (i = 0; i < it->subtree_nr; i++) {
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -292,8 +292,8 @@ static int update_one(struct cache_tree *it,
}
if (0 <= it->entry_count &&
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return it->entry_count;
/*
@@ -399,8 +399,9 @@ static int update_one(struct cache_tree *it,
ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
!must_check_existence(ce);
if (is_null_oid(oid) ||
- (!ce_missing_ok && !has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
+ (!ce_missing_ok &&
+ !odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
strbuf_release(&buffer);
if (expected_missing)
return -1;
@@ -448,7 +449,7 @@ static int update_one(struct cache_tree *it,
struct object_id oid;
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
OBJ_TREE, &oid);
- if (has_object(the_repository, &oid, HAS_OBJECT_RECHECK_PACKED))
+ if (odb_has_object(the_repository->objects, &oid, HAS_OBJECT_RECHECK_PACKED))
oidcpy(&it->oid, &oid);
else
to_invalidate = 1;
diff --git a/commit-graph.c b/commit-graph.c
index 84cfaf87639..cb81a5ce228 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1040,7 +1040,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
return NULL;
if (!search_commit_pos_in_graph(id, repo->objects->commit_graph, &pos))
return NULL;
- if (commit_graph_paranoia && !has_object(repo, id, 0))
+ if (commit_graph_paranoia && !odb_has_object(repo->objects, id, 0))
return NULL;
commit = lookup_commit(repo, id);
diff --git a/commit.c b/commit.c
index 28ee6b73ae6..15115125c36 100644
--- a/commit.c
+++ b/commit.c
@@ -575,7 +575,7 @@ int repo_parse_commit_internal(struct repository *r,
if (commit_graph_paranoia == -1)
commit_graph_paranoia = git_env_bool(GIT_COMMIT_GRAPH_PARANOIA, 0);
- if (commit_graph_paranoia && !has_object(r, &item->object.oid, 0)) {
+ if (commit_graph_paranoia && !odb_has_object(r->objects, &item->object.oid, 0)) {
unparse_commit(r, &item->object.oid);
return quiet_on_missing ? -1 :
error(_("commit %s exists in commit-graph but not in the object database"),
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f5de1c94d1..5e74235fc06 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -142,7 +142,7 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
commit = lookup_commit_in_graph(the_repository, oid);
if (commit) {
if (mark_tags_complete_and_check_obj_db) {
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
die_in_commit_graph_only(oid);
}
return commit;
@@ -770,7 +770,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
if (!commit) {
struct object *o;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
o = parse_object(the_repository, &ref->old_oid);
if (!o || o->type != OBJ_COMMIT)
@@ -1984,8 +1984,8 @@ static void update_shallow(struct fetch_pack_args *args,
struct oid_array extra = OID_ARRAY_INIT;
struct object_id *oid = si->shallow->oid;
for (i = 0; i < si->shallow->nr; i++)
- if (has_object(the_repository, &oid[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &oid[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
oid_array_append(&extra, &oid[i]);
if (extra.nr) {
setup_alternate_shallow(&shallow_lock,
diff --git a/http-push.c b/http-push.c
index 9481825abfb..beb41732fb6 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1447,8 +1447,8 @@ static void one_remote_ref(const char *refname)
* may be required for updating server info later.
*/
if (repo->can_update_info_refs &&
- !has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
obj = lookup_unknown_object(the_repository, &ref->old_oid);
fprintf(stderr, " fetch %s for %s\n",
oid_to_hex(&ref->old_oid), refname);
@@ -1653,14 +1653,16 @@ static int delete_remote_branch(const char *pattern, int force)
return error("Remote HEAD symrefs too deep");
if (is_null_oid(&head_oid))
return error("Unable to resolve remote HEAD");
- if (!has_object(the_repository, &head_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &head_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", oid_to_hex(&head_oid));
/* Remote branch must resolve to a known object */
if (is_null_oid(&remote_ref->old_oid))
return error("Unable to resolve remote branch %s",
remote_ref->name);
- if (!has_object(the_repository, &remote_ref->old_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &remote_ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, oid_to_hex(&remote_ref->old_oid));
/* Remote branch must be an ancestor of remote HEAD */
@@ -1881,8 +1883,8 @@ int cmd_main(int argc, const char **argv)
if (!force_all &&
!is_null_oid(&ref->old_oid) &&
!ref->force) {
- if (!has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
+ if (!odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
!ref_newer(&ref->peer_ref->new_oid,
&ref->old_oid)) {
/*
diff --git a/http-walker.c b/http-walker.c
index 4b1cdd25a80..4e7024ebc5f 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -138,8 +138,8 @@ static int fill_active_slot(void *data UNUSED)
list_for_each_safe(pos, tmp, head) {
obj_req = list_entry(pos, struct object_request, node);
if (obj_req->state == WAITING) {
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
obj_req->state = COMPLETE;
else {
start_object_request(obj_req);
@@ -497,8 +497,8 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
if (!obj_req)
return error("Couldn't find request for %s in the queue", hex);
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
if (obj_req->req)
abort_http_object_request(&obj_req->req);
abort_object_request(obj_req);
diff --git a/list-objects.c b/list-objects.c
index c50b9578584..42c17d95739 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -74,8 +74,8 @@ static void process_blob(struct traversal_context *ctx,
* of missing objects.
*/
if (ctx->revs->exclude_promisor_objects &&
- !has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ !odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
is_promisor_object(ctx->revs->repo, &obj->oid))
return;
diff --git a/notes.c b/notes.c
index 73eb5f00cf5..97b995f3f2d 100644
--- a/notes.c
+++ b/notes.c
@@ -794,8 +794,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
struct note_delete_list **l = (struct note_delete_list **) cb_data;
struct note_delete_list *n;
- if (has_object(the_repository, object_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, object_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0; /* nothing to do for this note */
/* failed to find object => prune this note */
diff --git a/odb.c b/odb.c
index 5202f107af2..787611c8f60 100644
--- a/odb.c
+++ b/odb.c
@@ -880,7 +880,7 @@ int pretend_object_file(struct repository *repo,
char *co_buf;
hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (has_object(repo, oid, 0) ||
+ if (odb_has_object(repo->objects, oid, 0) ||
find_cached_object(repo->objects, oid))
return 0;
@@ -962,7 +962,7 @@ void *read_object_with_reference(struct repository *r,
}
}
-int has_object(struct repository *r, const struct object_id *oid,
+int odb_has_object(struct object_database *odb, const struct object_id *oid,
unsigned flags)
{
unsigned object_info_flags = 0;
@@ -974,7 +974,7 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(odb, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
diff --git a/odb.h b/odb.h
index fb56cc9e1fe..3a96de56bd6 100644
--- a/odb.h
+++ b/odb.h
@@ -367,8 +367,9 @@ enum {
* Returns 1 if the object exists. This function will not lazily fetch objects
* in a partial clone by default.
*/
-int has_object(struct repository *r, const struct object_id *oid,
- unsigned flags);
+int odb_has_object(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned flags);
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect);
@@ -458,4 +459,11 @@ static inline void *repo_read_object_file(struct repository *r,
return odb_read_object(r->objects, oid, type, size);
}
+static inline int has_object(struct repository *r,
+ const struct object_id *oid,
+ unsigned flags)
+{
+ return odb_has_object(r->objects, oid, flags);
+}
+
#endif /* ODB_H */
diff --git a/reflog.c b/reflog.c
index 747b82eada8..39c205fd26e 100644
--- a/reflog.c
+++ b/reflog.c
@@ -152,7 +152,7 @@ static int tree_is_complete(const struct object_id *oid)
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
complete = 1;
while (tree_entry(&desc, &entry)) {
- if (!has_object(the_repository, &entry.oid,
+ if (!odb_has_object(the_repository->objects, &entry.oid,
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
(S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) {
tree->object.flags |= INCOMPLETE;
diff --git a/refs.c b/refs.c
index 82a70b502f8..d6475d5e745 100644
--- a/refs.c
+++ b/refs.c
@@ -376,7 +376,8 @@ int ref_resolves_to_object(const char *refname,
{
if (flags & REF_ISBROKEN)
return 0;
- if (!has_object(repo, oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (!odb_has_object(repo->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error(_("%s does not point to a valid object!"), refname);
return 0;
}
diff --git a/remote.c b/remote.c
index 72c36239d31..5edf2a9f4b2 100644
--- a/remote.c
+++ b/remote.c
@@ -1703,7 +1703,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
if (starts_with(ref->name, "refs/tags/"))
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
- else if (!has_object(the_repository, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ else if (!odb_has_object(the_repository->objects, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||
!lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))
diff --git a/send-pack.c b/send-pack.c
index abca2dd38a7..d029f748232 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -45,7 +45,7 @@ int option_parse_push_signed(const struct option *opt,
static void feed_object(struct repository *r,
const struct object_id *oid, FILE *fh, int negative)
{
- if (negative && !has_object(r, oid, 0))
+ if (negative && !odb_has_object(r->objects, oid, 0))
return;
if (negative)
diff --git a/shallow.c b/shallow.c
index d379756e39a..ef3adb635fd 100644
--- a/shallow.c
+++ b/shallow.c
@@ -310,8 +310,8 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
if (graft->nr_parent != -1)
return 0;
if (data->flags & QUICK) {
- if (!has_object(the_repository, &graft->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &graft->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
} else if (data->flags & SEEN_ONLY) {
struct commit *c = lookup_commit(the_repository, &graft->oid);
@@ -477,8 +477,8 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
ALLOC_ARRAY(info->ours, sa->nr);
ALLOC_ARRAY(info->theirs, sa->nr);
for (size_t i = 0; i < sa->nr; i++) {
- if (has_object(the_repository, sa->oid + i,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, sa->oid + i,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
struct commit_graft *graft;
graft = lookup_commit_graft(the_repository,
&sa->oid[i]);
@@ -515,8 +515,8 @@ void remove_nonexistent_theirs_shallow(struct shallow_info *info)
for (i = dst = 0; i < info->nr_theirs; i++) {
if (i != dst)
info->theirs[dst] = info->theirs[i];
- if (has_object(the_repository, oid + info->theirs[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid + info->theirs[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
dst++;
}
info->nr_theirs = dst;
diff --git a/upload-pack.c b/upload-pack.c
index cec12cb478a..98cda156434 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -509,7 +509,7 @@ static int got_oid(struct upload_pack_data *data,
{
if (get_oid_hex(hex, oid))
die("git upload-pack: expected SHA1 object, got '%s'", hex);
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
return -1;
return do_got_oid(data, oid);
}
diff --git a/walker.c b/walker.c
index a8abe8a2e78..d131af04c7b 100644
--- a/walker.c
+++ b/walker.c
@@ -150,8 +150,8 @@ static int process(struct walker *walker, struct object *obj)
return 0;
obj->flags |= SEEN;
- if (has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
/* We already have it, so we should scan it now. */
obj->flags |= TO_SCAN;
}
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 16/17] odb: rename `pretend_object_file()`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (14 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 15/17] odb: rename `has_object()` Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 5:12 ` [PATCH v3 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
2025-05-14 14:48 ` [PATCH v3 00/17] object-store: carve out the object database subsystem Toon Claes
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
Rename `pretend_object_file()` to `odb_pretend_object()` to match other
functions related to the object database and our modern coding
guidelines.
No compatibility wrapper is introduces as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
blame.c | 3 ++-
odb.c | 18 +++++++++---------
odb.h | 6 +++---
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/blame.c b/blame.c
index 858d2d74df9..dce5c8d855c 100644
--- a/blame.c
+++ b/blame.c
@@ -277,7 +277,8 @@ static struct commit *fake_working_tree_commit(struct repository *r,
convert_to_git(r->index, path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
- pretend_object_file(the_repository, buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
+ odb_pretend_object(the_repository->objects, buf.buf, buf.len,
+ OBJ_BLOB, &origin->blob_oid);
/*
* Read the current index, replace the path entry with
diff --git a/odb.c b/odb.c
index 787611c8f60..dfebeb4c8c0 100644
--- a/odb.c
+++ b/odb.c
@@ -872,21 +872,21 @@ int odb_read_object_info(struct object_database *odb,
return type;
}
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid)
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid)
{
struct cached_object_entry *co;
char *co_buf;
- hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (odb_has_object(repo->objects, oid, 0) ||
- find_cached_object(repo->objects, oid))
+ hash_object_file(odb->repo->hash_algo, buf, len, type, oid);
+ if (odb_has_object(odb, oid, 0) ||
+ find_cached_object(odb, oid))
return 0;
- ALLOC_GROW(repo->objects->cached_objects,
- repo->objects->cached_object_nr + 1, repo->objects->cached_object_alloc);
- co = &repo->objects->cached_objects[repo->objects->cached_object_nr++];
+ ALLOC_GROW(odb->cached_objects,
+ odb->cached_object_nr + 1, odb->cached_object_alloc);
+ co = &odb->cached_objects[odb->cached_object_nr++];
co->value.size = len;
co->value.type = type;
co_buf = xmalloc(len);
diff --git a/odb.h b/odb.h
index 3a96de56bd6..18de1f3f57c 100644
--- a/odb.h
+++ b/odb.h
@@ -274,9 +274,9 @@ void *odb_read_object(struct object_database *odb,
* object in persistent storage before writing any other new objects
* that reference it.
*/
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid);
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid);
struct object_info {
/* Request */
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v3 17/17] odb: rename `read_object_with_reference()`
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (15 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
@ 2025-05-14 5:12 ` Patrick Steinhardt
2025-05-14 14:48 ` [PATCH v3 00/17] object-store: carve out the object database subsystem Toon Claes
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-14 5:12 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes
Rename `read_object_with_reference()` to `odb_read_object_peeled()` to
match other functions related to the object database and our modern
coding guidelines. Furthermore though, the old name didn't really
describe very well what this function actually does, which is to walk
down any commit and tag objects until an object of the required type has
been found. This is generally referred to as "peeling", so the new name
should be way more descriptive.
No compatibility wrapper is introduces as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Documentation/user-manual.adoc | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/fast-import.c | 19 ++++++++-----------
builtin/grep.c | 9 +++------
builtin/pack-objects.c | 4 ++--
odb.c | 17 +++++++++--------
odb.h | 15 +++++++--------
tree-walk.c | 10 ++++------
8 files changed, 37 insertions(+), 45 deletions(-)
diff --git a/Documentation/user-manual.adoc b/Documentation/user-manual.adoc
index d2b478ad232..e86b2ad9f8a 100644
--- a/Documentation/user-manual.adoc
+++ b/Documentation/user-manual.adoc
@@ -4301,11 +4301,11 @@ Now, for the meat:
-----------------------------------------------------------------------------
case 0:
- buf = read_object_with_reference(sha1, argv[1], &size, NULL);
+ buf = odb_read_object_peeled(r->objects, sha1, argv[1], &size, NULL);
-----------------------------------------------------------------------------
This is how you read a blob (actually, not only a blob, but any type of
-object). To know how the function `read_object_with_reference()` actually
+object). To know how the function `odb_read_object_peeled()` actually
works, find the source code for it (something like `git grep
read_object_with | grep ":[a-z]"` in the Git repository), and read
the source.
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 571b5cc2ad5..ed0fce9b490 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -255,8 +255,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
* fall-back to the usual case.
*/
}
- buf = read_object_with_reference(the_repository, &oid,
- exp_type_id, &size, NULL);
+ buf = odb_read_object_peeled(the_repository->objects, &oid,
+ exp_type_id, &size, NULL);
if (use_mailmap) {
size_t s = size;
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 1973c504e25..b1389c59211 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2535,10 +2535,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
oidcpy(&commit_oid, &commit_oe->idx.oid);
} else if (!repo_get_oid(the_repository, p, &commit_oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &commit_oid,
- OBJ_COMMIT, &size,
- &commit_oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &commit_oid, OBJ_COMMIT, &size,
+ &commit_oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", p);
free(buf);
@@ -2604,9 +2603,8 @@ static void parse_from_existing(struct branch *b)
unsigned long size;
char *buf;
- buf = read_object_with_reference(the_repository,
- &b->oid, OBJ_COMMIT, &size,
- &b->oid);
+ buf = odb_read_object_peeled(the_repository->objects, &b->oid,
+ OBJ_COMMIT, &size, &b->oid);
parse_from_commit(b, buf, size);
free(buf);
}
@@ -2699,10 +2697,9 @@ static struct hash_list *parse_merge(unsigned int *count)
oidcpy(&n->oid, &oe->idx.oid);
} else if (!repo_get_oid(the_repository, from, &n->oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &n->oid,
- OBJ_COMMIT,
- &size, &n->oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &n->oid, OBJ_COMMIT,
+ &size, &n->oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", from);
free(buf);
diff --git a/builtin/grep.c b/builtin/grep.c
index f84298af0f6..7619479ddad 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -522,9 +522,7 @@ static int grep_submodule(struct grep_opt *opt,
obj_read_lock();
object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
- data = read_object_with_reference(subrepo,
- oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(subrepo->objects, oid, OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
@@ -705,9 +703,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
struct strbuf base;
int hit, len;
- data = read_object_with_reference(opt->repo,
- &obj->oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(opt->repo->objects, &obj->oid,
+ OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 06bdeb4223b..e88a13dbb9f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2055,8 +2055,8 @@ static void add_preferred_base(struct object_id *oid)
if (window <= num_preferred_base++)
return;
- data = read_object_with_reference(the_repository, oid,
- OBJ_TREE, &size, &tree_oid);
+ data = odb_read_object_peeled(the_repository->objects, oid,
+ OBJ_TREE, &size, &tree_oid);
if (!data)
return;
diff --git a/odb.c b/odb.c
index dfebeb4c8c0..fd7fe398d2d 100644
--- a/odb.c
+++ b/odb.c
@@ -914,11 +914,11 @@ void *odb_read_object(struct object_database *odb,
return data;
}
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *actual_oid_return)
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *actual_oid_return)
{
enum object_type type;
void *buffer;
@@ -930,7 +930,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
+ buffer = odb_read_object(odb, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
@@ -950,9 +950,10 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + r->hash_algo->hexsz > isize ||
+ if (ref_length + odb->repo->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid,
+ odb->repo->hash_algo)) {
free(buffer);
return NULL;
}
diff --git a/odb.h b/odb.h
index 18de1f3f57c..a9945d302fb 100644
--- a/odb.h
+++ b/odb.h
@@ -266,6 +266,12 @@ void *odb_read_object(struct object_database *odb,
enum object_type *type,
unsigned long *size);
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *oid_ret);
+
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -377,7 +383,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: odb_read_object(),
- * read_object_with_reference(), odb_read_object_info() and odb().
+ * odb_read_object_peeled(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -426,13 +432,6 @@ enum for_each_object_flags {
FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
};
-
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *oid_ret);
-
/* Compatibility wrappers, to be removed once Git 2.50 has been released. */
#include "repository.h"
diff --git a/tree-walk.c b/tree-walk.c
index 766af99f466..e449a1320e5 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -90,7 +90,7 @@ void *fill_tree_descriptor(struct repository *r,
void *buf = NULL;
if (oid) {
- buf = read_object_with_reference(r, oid, OBJ_TREE, &size, NULL);
+ buf = odb_read_object_peeled(r->objects, oid, OBJ_TREE, &size, NULL);
if (!buf)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
}
@@ -611,7 +611,7 @@ int get_tree_entry(struct repository *r,
unsigned long size;
struct object_id root;
- tree = read_object_with_reference(r, tree_oid, OBJ_TREE, &size, &root);
+ tree = odb_read_object_peeled(r->objects, tree_oid, OBJ_TREE, &size, &root);
if (!tree)
return -1;
@@ -681,10 +681,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
void *tree;
struct object_id root;
unsigned long size;
- tree = read_object_with_reference(r,
- ¤t_tree_oid,
- OBJ_TREE, &size,
- &root);
+ tree = odb_read_object_peeled(r->objects, ¤t_tree_oid,
+ OBJ_TREE, &size, &root);
if (!tree)
goto done;
--
2.49.0.1141.g47af616452.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v3 00/17] object-store: carve out the object database subsystem
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
` (16 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
@ 2025-05-14 14:48 ` Toon Claes
2025-05-15 8:22 ` Patrick Steinhardt
17 siblings, 1 reply; 166+ messages in thread
From: Toon Claes @ 2025-05-14 14:48 UTC (permalink / raw)
To: Patrick Steinhardt, git; +Cc: Derrick Stolee, Junio C Hamano
Patrick Steinhardt <ps@pks.im> writes:
> Hi,
>
> this patch series refactors the object store subsystem to become more
> self-contained by getting rid of `the_repository`. Instead of passing in
> the repository explicitly, we start to pass in the object store itself,
> which is in contrast to many other refactorings we did, but in line with
> what we did for the ref store, as well.
>
> This series also starts to properly scope functions to the carved out
> object database subsystem, which requires a bit of shuffling. This
> allows us to have a short-and-sweet `odb_` prefix for functions and
> prepares us for a future with pluggable object backends.
>
> The series is structured as follows:
>
> - Patches 1 to 3 rename `struct object_store` and `struct
> object_directory` as well as the code files.
>
> - Patches 4 to 12 refactor "odb.c" to get rid of `the_repository`.
>
> - Patches 13 to 17 adjust the name of remaining functions so that they
> can be clearly attributed to the ODB. I'm happy to kick these
> patches out of this series and resend them at a later point in case
> they create too much turmoil.
>
> This series is built on top of 6f84262c44a (The eleventh batch,
> 2025-05-05) with ps/object-store-cleanup at 8a9e27be821 (object-store:
> drop `repo_has_object_file()`, 2025-04-29) merged into it. There are a
> couple of trivial conflicts when merged with "seen", I have appended the
> merge conflict resolution as a patch at the end of this mail.
>
> Changes in v2:
> - Fix for a copy-and-pasted commit message.
> - Rename `struct odb_backend` to `struct odb_alternate`. I'm happy to
> revert to the previous name if we ultimately think it's the better
> suited one.
> - A couple of fixes to move changes into the correct commit. `git
> rebase -x 'meson compile -C build'` is now clean.
> - I _didn't_ back out the rename to "odb.{c,h}". Junio has already
> fixed the fallout, so it's probably more work for him to kick it out
> again than to just leave it in.
> - Link to v1: https://lore.kernel.org/r/20250506-pks-object-store-wo-the-repository-v1-0-c05b82e7b126@pks.im
>
> Changes in v3:
> - Polishing for some comments and commit messages.
> - Link to v2: https://lore.kernel.org/r/20250509-pks-object-store-wo-the-repository-v2-0-103f59bf8e28@pks.im
>
> Thanks!
>
> Patrick
The range-diff looks good, and I've got no further comments.
Only one small question though, what's the point of the compatibility
layer in the last 5(-ish) commits? I mean if we add temp wrappers for
other topics in flight, then when/how do we convert that new code to
stop using the wrappers? Won't we remain having issues because there's
always something in flight?
Cheers,
-- Toon
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v3 00/17] object-store: carve out the object database subsystem
2025-05-14 14:48 ` [PATCH v3 00/17] object-store: carve out the object database subsystem Toon Claes
@ 2025-05-15 8:22 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-05-15 8:22 UTC (permalink / raw)
To: Toon Claes; +Cc: git, Derrick Stolee, Junio C Hamano
On Wed, May 14, 2025 at 04:48:47PM +0200, Toon Claes wrote:
> Only one small question though, what's the point of the compatibility
> layer in the last 5(-ish) commits? I mean if we add temp wrappers for
> other topics in flight, then when/how do we convert that new code to
> stop using the wrappers? Won't we remain having issues because there's
> always something in flight?
As mentioned in the comment for those wrappers the expectation is that
those will be removed once Git 2.50 is out. This is a common approach we
have used in the past, as well: for global changes to functions with a
lot of users we introduce wrappers that remain for the current release
cycle.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v4 00/17] object-store: carve out the object database subsystem
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (20 preceding siblings ...)
2025-05-14 5:12 ` [PATCH v3 " Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
` (17 more replies)
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
23 siblings, 18 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Hi,
this patch series refactors the object store subsystem to become more
self-contained by getting rid of `the_repository`. Instead of passing in
the repository explicitly, we start to pass in the object store itself,
which is in contrast to many other refactorings we did, but in line with
what we did for the ref store, as well.
This series also starts to properly scope functions to the carved out
object database subsystem, which requires a bit of shuffling. This
allows us to have a short-and-sweet `odb_` prefix for functions and
prepares us for a future with pluggable object backends.
The series is structured as follows:
- Patches 1 to 3 rename `struct object_store` and `struct
object_directory` as well as the code files.
- Patches 4 to 12 refactor "odb.c" to get rid of `the_repository`.
- Patches 13 to 17 adjust the name of remaining functions so that they
can be clearly attributed to the ODB. I'm happy to kick these
patches out of this series and resend them at a later point in case
they create too much turmoil.
This series is built on top of 6f84262c44a (The eleventh batch,
2025-05-05) with ps/object-store-cleanup at 8a9e27be821 (object-store:
drop `repo_has_object_file()`, 2025-04-29) merged into it. There are a
couple of trivial conflicts when merged with "seen", I have appended the
merge conflict resolution as a patch at the end of this mail.
Changes in v2:
- Fix for a copy-and-pasted commit message.
- Rename `struct odb_backend` to `struct odb_alternate`. I'm happy to
revert to the previous name if we ultimately think it's the better
suited one.
- A couple of fixes to move changes into the correct commit. `git
rebase -x 'meson compile -C build'` is now clean.
- I _didn't_ back out the rename to "odb.{c,h}". Junio has already
fixed the fallout, so it's probably more work for him to kick it out
again than to just leave it in.
- Link to v1: https://lore.kernel.org/r/20250506-pks-object-store-wo-the-repository-v1-0-c05b82e7b126@pks.im
Changes in v3:
- Polishing for some comments and commit messages.
- Link to v2: https://lore.kernel.org/r/20250509-pks-object-store-wo-the-repository-v2-0-103f59bf8e28@pks.im
Changes in v4:
- Rebased the patch series on top of 7014b55638d (A bit more topics
for -rc1, 2025-05-30). This fixes a couple of merge conflicts, most
importantly with jk/no-funny-object-types.
- Rename `struct odb_alternate` to `odb_source`.
- Link to v3: https://lore.kernel.org/r/20250514-pks-object-store-wo-the-repository-v3-0-47df1d4ead22@pks.im
Thanks!
Patrick
---
Patrick Steinhardt (17):
object-store: rename `raw_object_store` to `object_database`
object-store: rename `object_directory` to `odb_source`
object-store: rename files to "odb.{c,h}"
odb: introduce parent pointers
odb: get rid of `the_repository` in `find_odb()`
odb: get rid of `the_repository` in `assert_oid_type()`
odb: get rid of `the_repository` in `odb_mkstemp()`
odb: get rid of `the_repository` when handling alternates
odb: get rid of `the_repository` in `for_each()` functions
odb: get rid of `the_repository` when handling the primary source
odb: get rid of `the_repository` when handling submodule sources
odb: trivial refactorings to get rid of `the_repository`
odb: rename `oid_object_info()`
odb: rename `repo_read_object_file()`
odb: rename `has_object()`
odb: rename `pretend_object_file()`
odb: rename `read_object_with_reference()`
Documentation/user-manual.adoc | 4 +-
Makefile | 2 +-
apply.c | 14 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 6 +-
attr.c | 4 +-
bisect.c | 8 +-
blame.c | 22 +-
builtin/backfill.c | 6 +-
builtin/blame.c | 6 +-
builtin/cat-file.c | 62 ++---
builtin/checkout.c | 2 +-
builtin/clone.c | 14 +-
builtin/commit-graph.c | 20 +-
builtin/commit-tree.c | 4 +-
builtin/count-objects.c | 6 +-
builtin/describe.c | 5 +-
builtin/difftool.c | 4 +-
builtin/fast-export.c | 10 +-
builtin/fast-import.c | 49 ++--
builtin/fetch.c | 21 +-
builtin/fsck.c | 31 ++-
builtin/gc.c | 16 +-
builtin/grep.c | 26 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 29 +-
builtin/log.c | 4 +-
builtin/ls-files.c | 4 +-
builtin/ls-tree.c | 6 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 14 +-
builtin/mktag.c | 6 +-
builtin/mktree.c | 10 +-
builtin/multi-pack-index.c | 6 +-
builtin/notes.c | 8 +-
builtin/pack-objects.c | 70 ++---
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 6 +-
builtin/receive-pack.c | 9 +-
builtin/remote.c | 6 +-
builtin/repack.c | 7 +-
builtin/replace.c | 12 +-
builtin/rev-list.c | 8 +-
builtin/show-ref.c | 6 +-
builtin/submodule--helper.c | 11 +-
builtin/tag.c | 10 +-
builtin/unpack-file.c | 4 +-
builtin/unpack-objects.c | 12 +-
bulk-checkin.c | 6 +-
bundle-uri.c | 5 +-
bundle.c | 6 +-
cache-tree.c | 17 +-
combine-diff.c | 4 +-
commit-graph.c | 106 +++----
commit-graph.h | 20 +-
commit.c | 15 +-
config.c | 4 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 12 +-
diff.c | 20 +-
dir.c | 2 +-
entry.c | 6 +-
fetch-pack.c | 17 +-
fmt-merge-msg.c | 6 +-
fsck.c | 4 +-
grep.c | 6 +-
http-backend.c | 2 +-
http-push.c | 20 +-
http-walker.c | 12 +-
http.c | 6 +-
list-objects-filter.c | 4 +-
list-objects.c | 6 +-
log-tree.c | 2 +-
loose.c | 46 ++--
mailmap.c | 4 +-
match-trees.c | 6 +-
merge-blobs.c | 10 +-
merge-ort.c | 8 +-
meson.build | 2 +-
midx-write.c | 2 +-
midx.c | 6 +-
notes-cache.c | 4 +-
notes-merge.c | 4 +-
notes.c | 19 +-
object-file.c | 94 +++----
object-file.h | 12 +-
object-name.c | 24 +-
object-store.h | 338 -----------------------
object.c | 8 +-
object-store.c => odb.c | 413 +++++++++++++++-------------
odb.h | 472 ++++++++++++++++++++++++++++++++
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 9 +-
pack-bitmap.c | 10 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
pack-write.c | 10 +-
packfile.c | 29 +-
packfile.h | 8 +-
path.c | 4 +-
promisor-remote.c | 6 +-
protocol-caps.c | 4 +-
reachable.c | 2 +-
read-cache.c | 14 +-
ref-filter.c | 6 +-
reflog.c | 8 +-
refs.c | 7 +-
remote.c | 9 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 21 +-
repository.h | 4 +-
rerere.c | 7 +-
revision.c | 5 +-
send-pack.c | 4 +-
sequencer.c | 7 +-
server-info.c | 2 +-
shallow.c | 14 +-
streaming.c | 10 +-
submodule-config.c | 9 +-
submodule.c | 32 +--
submodule.h | 9 -
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 4 +-
t/helper/test-read-graph.c | 8 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 4 +-
tag.c | 10 +-
tmp-objdir.c | 30 +-
tree-walk.c | 18 +-
tree.c | 6 +-
unpack-trees.c | 2 +-
upload-pack.c | 4 +-
walker.c | 6 +-
xdiff-interface.c | 4 +-
140 files changed, 1452 insertions(+), 1298 deletions(-)
Range-diff versus v3:
1: 043ce74ca7c = 1: 159c8dbbe70 object-store: rename `raw_object_store` to `object_database`
2: 9a723eebf54 ! 2: 6b9fea59a10 object-store: rename `object_directory` to `odb_alternate`
@@ Metadata
Author: Patrick Steinhardt <ps@pks.im>
## Commit message ##
- object-store: rename `object_directory` to `odb_alternate`
+ object-store: rename `object_directory` to `odb_source`
The `object_directory` structure is used as an access point for a single
object directory like ".git/objects". While the structure isn't yet
@@ Commit message
named after their subsystem, which means that we would start to bake the
current name into the codebase more and more.
- Let's preempt this by renaming the structure to `odb_alternate` now
- already. This name is agnostic of how exactly objects are stored while
- still specifically pinpointing that this is about an alternate object
- database. Furthermore, it is already used in Git to represent this
- context -- the only stretch is that the primary object directory is now
- the primary alternate.
+ Let's preempt this by renaming the structure. There have been a couple
+ alternatives that were discussed:
+
+ - `odb_backend` was discarded because it led to the association that
+ one object database has a single backend, but the model is that one
+ alternate has one backend. Furthermore, "backend" is more about the
+ actual backing implementation and less about the high-level concept.
+
+ - `odb_alternate` was discarded because it is a bit of a stretch to
+ also call the main object directory an "alternate".
+
+ Instead, pick `odb_source` as the new name. It makes it sufficiently
+ clear that there can be multiple sources and does not cause confusion
+ when mixed with the already-existing "alternate" terminology.
In the future, this change allows us to easily introduce for example a
- `odb_files_alternate` and other format-specific implementations.
+ `odb_files_source` and other format-specific implementations.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
@@ builtin/commit-graph.c: static int graph_verify(int argc, const char **argv, con
{
struct commit_graph *graph = NULL;
- struct object_directory *odb = NULL;
-+ struct odb_alternate *alternate = NULL;
++ struct odb_source *source = NULL;
char *graph_name;
char *chain_name;
enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE;
@@ builtin/commit-graph.c: static int graph_verify(int argc, const char **argv, con
- odb = find_odb(the_repository, opts.obj_dir);
- graph_name = get_commit_graph_filename(odb);
- chain_name = get_commit_graph_chain_filename(odb);
-+ alternate = find_odb(the_repository, opts.obj_dir);
-+ graph_name = get_commit_graph_filename(alternate);
-+ chain_name = get_commit_graph_chain_filename(alternate);
++ source = find_odb(the_repository, opts.obj_dir);
++ graph_name = get_commit_graph_filename(source);
++ chain_name = get_commit_graph_chain_filename(source);
if (open_commit_graph(graph_name, &fd, &st))
opened = OPENED_GRAPH;
else if (errno != ENOENT)
@@ builtin/commit-graph.c: static int graph_verify(int argc, const char **argv, con
return 0;
else if (opened == OPENED_GRAPH)
- graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb);
-+ graph = load_commit_graph_one_fd_st(the_repository, fd, &st, alternate);
++ graph = load_commit_graph_one_fd_st(the_repository, fd, &st, source);
else
graph = load_commit_graph_chain_fd_st(the_repository, fd, &st,
&incomplete_chain);
@@ builtin/commit-graph.c: static int graph_write(int argc, const char **argv, cons
struct strbuf buf = STRBUF_INIT;
struct oidset commits = OIDSET_INIT;
- struct object_directory *odb = NULL;
-+ struct odb_alternate *alternate = NULL;
++ struct odb_source *source = NULL;
int result = 0;
enum commit_graph_write_flags flags = 0;
struct progress *progress = NULL;
@@ builtin/commit-graph.c: static int graph_write(int argc, const char **argv, cons
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- odb = find_odb(the_repository, opts.obj_dir);
-+ alternate = find_odb(the_repository, opts.obj_dir);
++ source = find_odb(the_repository, opts.obj_dir);
if (opts.reachable) {
- if (write_commit_graph_reachable(odb, flags, &write_opts))
-+ if (write_commit_graph_reachable(alternate, flags, &write_opts))
++ if (write_commit_graph_reachable(source, flags, &write_opts))
result = 1;
goto cleanup;
}
@@ builtin/commit-graph.c: static int graph_write(int argc, const char **argv, cons
}
- if (write_commit_graph(odb,
-+ if (write_commit_graph(alternate,
++ if (write_commit_graph(source,
opts.stdin_packs ? &pack_indexes : NULL,
opts.stdin_commits ? &commits : NULL,
flags,
@@ builtin/count-objects.c: static int count_cruft(const char *basename UNUSED, con
}
-static int print_alternate(struct object_directory *odb, void *data UNUSED)
-+static int print_alternate(struct odb_alternate *alternate, void *data UNUSED)
++static int print_alternate(struct odb_source *alternate, void *data UNUSED)
{
printf("alternate: ");
- quote_c_style(odb->path, NULL, stdout, 0);
@@ builtin/fetch.c: int cmd_fetch(int argc,
trace2_region_enter("fetch", "write-commit-graph", the_repository);
- write_commit_graph_reachable(the_repository->objects->odb,
-+ write_commit_graph_reachable(the_repository->objects->alternates,
++ write_commit_graph_reachable(the_repository->objects->sources,
commit_graph_flags,
NULL);
trace2_region_leave("fetch", "write-commit-graph", the_repository);
@@ builtin/fsck.c: int cmd_fsck(int argc,
{
int i;
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
/* fsck knows how to handle missing promisor objects */
fetch_if_missing = 0;
@@ builtin/fsck.c: int cmd_fsck(int argc,
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next)
- fsck_object_dir(odb->path);
-+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next)
-+ fsck_object_dir(alternate->path);
++ for (source = the_repository->objects->sources; source; source = source->next)
++ fsck_object_dir(source->path);
if (check_full) {
struct packed_git *p;
@@ builtin/fsck.c: int cmd_fsck(int argc,
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
-+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
++ for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
strvec_pushl(&commit_graph_verify.args, "commit-graph",
- "verify", "--object-dir", odb->path, NULL);
-+ "verify", "--object-dir", alternate->path, NULL);
++ "verify", "--object-dir", source->path, NULL);
if (show_progress)
strvec_push(&commit_graph_verify.args, "--progress");
else
@@ builtin/fsck.c: int cmd_fsck(int argc,
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
-+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
++ for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
- "verify", "--object-dir", odb->path, NULL);
-+ "verify", "--object-dir", alternate->path, NULL);
++ "verify", "--object-dir", source->path, NULL);
if (show_progress)
strvec_push(&midx_verify.args, "--progress");
else
## builtin/gc.c ##
-@@ builtin/gc.c: struct repository *repo UNUSED)
+@@ builtin/gc.c: int cmd_gc(int argc,
}
if (the_repository->settings.gc_write_commit_graph == 1)
- write_commit_graph_reachable(the_repository->objects->odb,
-+ write_commit_graph_reachable(the_repository->objects->alternates,
++ write_commit_graph_reachable(the_repository->objects->sources,
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
NULL);
@@ builtin/gc.c: static int loose_object_auto_condition(struct gc_config *cfg UNUSE
return 1;
- return for_each_loose_file_in_objdir(the_repository->objects->odb->path,
-+ return for_each_loose_file_in_objdir(the_repository->objects->alternates->path,
++ return for_each_loose_file_in_objdir(the_repository->objects->sources->path,
loose_object_count,
NULL, NULL, &count);
}
@@ builtin/gc.c: static int pack_loose(struct maintenance_run_opts *opts)
* if there are no loose objects.
*/
- if (!for_each_loose_file_in_objdir(r->objects->odb->path,
-+ if (!for_each_loose_file_in_objdir(r->objects->alternates->path,
++ if (!for_each_loose_file_in_objdir(r->objects->sources->path,
bail_on_loose,
NULL, NULL, NULL))
return 0;
@@ builtin/gc.c: static int pack_loose(struct maintenance_run_opts *opts)
else
strvec_push(&pack_proc.args, "--no-quiet");
- strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
-+ strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->alternates->path);
++ strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->sources->path);
pack_proc.in = -1;
@@ builtin/gc.c: static int pack_loose(struct maintenance_run_opts *opts)
data.batch_size--; /* Decrease for equality on limit. */
- for_each_loose_file_in_objdir(r->objects->odb->path,
-+ for_each_loose_file_in_objdir(r->objects->alternates->path,
++ for_each_loose_file_in_objdir(r->objects->sources->path,
write_loose_object_to_stdin,
NULL,
NULL,
@@ builtin/gc.c: static int maintenance_run_tasks(struct maintenance_run_opts *opts
struct lock_file lk;
struct repository *r = the_repository;
- char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path);
-+ char *lock_path = xstrfmt("%s/maintenance", r->objects->alternates->path);
++ char *lock_path = xstrfmt("%s/maintenance", r->objects->sources->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
/*
@@ builtin/gc.c: static int update_background_schedule(const struct maintenance_sta
int result = 0;
struct lock_file lk;
- char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path);
-+ char *lock_path = xstrfmt("%s/schedule", the_repository->objects->alternates->path);
++ char *lock_path = xstrfmt("%s/schedule", the_repository->objects->sources->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
if (errno == EEXIST)
@@ builtin/grep.c: static int grep_submodule(struct grep_opt *opt,
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->odb->path);
-+ add_submodule_odb_by_path(subrepo->objects->alternates->path);
++ add_submodule_odb_by_path(subrepo->objects->sources->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
@@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc,
the_repository->objects &&
- the_repository->objects->odb)
- opts.object_dir = xstrdup(the_repository->objects->odb->path);
-+ the_repository->objects->alternates)
-+ opts.object_dir = xstrdup(the_repository->objects->alternates->path);
++ the_repository->objects->sources)
++ opts.object_dir = xstrdup(the_repository->objects->sources->path);
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
@@ builtin/submodule--helper.c: static const char alternate_error_advice[] = N_(
static int add_possible_reference_from_superproject(
- struct object_directory *odb, void *sas_cb)
-+ struct odb_alternate *alt_odb, void *sas_cb)
++ struct odb_source *alt_odb, void *sas_cb)
{
struct submodule_alternate_setup *sas = sas_cb;
size_t len;
@@ bundle.c: int verify_bundle(struct repository *r,
};
- if (!r || !r->objects || !r->objects->odb)
-+ if (!r || !r->objects || !r->objects->alternates)
++ if (!r || !r->objects || !r->objects->sources)
return error(_("need a repository to verify a bundle"));
for (i = 0; i < p->nr; i++) {
@@ commit-graph.c: void git_test_write_commit_graph_or_die(void)
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- if (write_commit_graph_reachable(the_repository->objects->odb,
-+ if (write_commit_graph_reachable(the_repository->objects->alternates,
++ if (write_commit_graph_reachable(the_repository->objects->sources,
flags, NULL))
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
}
@@ commit-graph.c: static int commit_gen_cmp(const void *va, const void *vb)
}
-char *get_commit_graph_filename(struct object_directory *obj_dir)
-+char *get_commit_graph_filename(struct odb_alternate *alternate)
++char *get_commit_graph_filename(struct odb_source *source)
{
- return xstrfmt("%s/info/commit-graph", obj_dir->path);
-+ return xstrfmt("%s/info/commit-graph", alternate->path);
++ return xstrfmt("%s/info/commit-graph", source->path);
}
-static char *get_split_graph_filename(struct object_directory *odb,
-+static char *get_split_graph_filename(struct odb_alternate *alternate,
++static char *get_split_graph_filename(struct odb_source *source,
const char *oid_hex)
{
- return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb->path,
-+ return xstrfmt("%s/info/commit-graphs/graph-%s.graph", alternate->path,
++ return xstrfmt("%s/info/commit-graphs/graph-%s.graph", source->path,
oid_hex);
}
-char *get_commit_graph_chain_filename(struct object_directory *odb)
-+char *get_commit_graph_chain_filename(struct odb_alternate *alternate)
++char *get_commit_graph_chain_filename(struct odb_source *source)
{
- return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
-+ return xstrfmt("%s/info/commit-graphs/commit-graph-chain", alternate->path);
++ return xstrfmt("%s/info/commit-graphs/commit-graph-chain", source->path);
}
static struct commit_graph *alloc_commit_graph(void)
@@ commit-graph.c: int open_commit_graph(const char *graph_file, int *fd, struct st
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb)
-+ struct odb_alternate *alternate)
++ struct odb_source *source)
{
void *graph_map;
size_t graph_size;
@@ commit-graph.c: struct commit_graph *load_commit_graph_one_fd_st(struct reposito
if (ret)
- ret->odb = odb;
-+ ret->alternate = alternate;
++ ret->odb_source = source;
else
munmap(graph_map, graph_size);
@@ commit-graph.c: struct commit_graph *parse_commit_graph(struct repo_settings *s,
static struct commit_graph *load_commit_graph_one(struct repository *r,
const char *graph_file,
- struct object_directory *odb)
-+ struct odb_alternate *alternate)
++ struct odb_source *source)
{
struct stat st;
@@ commit-graph.c: static struct commit_graph *load_commit_graph_one(struct reposit
return NULL;
- g = load_commit_graph_one_fd_st(r, fd, &st, odb);
-+ g = load_commit_graph_one_fd_st(r, fd, &st, alternate);
++ g = load_commit_graph_one_fd_st(r, fd, &st, source);
if (g)
g->filename = xstrdup(graph_file);
@@ commit-graph.c: static struct commit_graph *load_commit_graph_one(struct reposit
static struct commit_graph *load_commit_graph_v1(struct repository *r,
- struct object_directory *odb)
-+ struct odb_alternate *alternate)
++ struct odb_source *source)
{
- char *graph_name = get_commit_graph_filename(odb);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
-+ char *graph_name = get_commit_graph_filename(alternate);
-+ struct commit_graph *g = load_commit_graph_one(r, graph_name, alternate);
++ char *graph_name = get_commit_graph_filename(source);
++ struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
free(graph_name);
return g;
@@ commit-graph.c: struct commit_graph *load_commit_graph_chain_fd_st(struct reposi
for (i = 0; i < count; i++) {
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
if (strbuf_getline_lf(&line, fp) == EOF)
break;
@@ commit-graph.c: struct commit_graph *load_commit_graph_chain_fd_st(struct reposi
- for (odb = r->objects->odb; odb; odb = odb->next) {
- char *graph_name = get_split_graph_filename(odb, line.buf);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
-+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
-+ char *graph_name = get_split_graph_filename(alternate, line.buf);
-+ struct commit_graph *g = load_commit_graph_one(r, graph_name, alternate);
++ for (source = r->objects->sources; source; source = source->next) {
++ char *graph_name = get_split_graph_filename(source, line.buf);
++ struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
free(graph_name);
@@ commit-graph.c: struct commit_graph *load_commit_graph_chain_fd_st(struct reposi
static struct commit_graph *load_commit_graph_chain(struct repository *r,
- struct object_directory *odb)
-+ struct odb_alternate *alternate)
++ struct odb_source *source)
{
- char *chain_file = get_commit_graph_chain_filename(odb);
-+ char *chain_file = get_commit_graph_chain_filename(alternate);
++ char *chain_file = get_commit_graph_chain_filename(source);
struct stat st;
int fd;
struct commit_graph *g = NULL;
@@ commit-graph.c: static struct commit_graph *load_commit_graph_chain(struct repos
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb)
-+ struct odb_alternate *alternate)
++ struct odb_source *source)
{
- struct commit_graph *g = load_commit_graph_v1(r, odb);
-+ struct commit_graph *g = load_commit_graph_v1(r, alternate);
++ struct commit_graph *g = load_commit_graph_v1(r, source);
if (!g)
- g = load_commit_graph_chain(r, odb);
-+ g = load_commit_graph_chain(r, alternate);
++ g = load_commit_graph_chain(r, source);
return g;
}
static void prepare_commit_graph_one(struct repository *r,
- struct object_directory *odb)
-+ struct odb_alternate *alternate)
++ struct odb_source *source)
{
if (r->objects->commit_graph)
return;
- r->objects->commit_graph = read_commit_graph_one(r, odb);
-+ r->objects->commit_graph = read_commit_graph_one(r, alternate);
++ r->objects->commit_graph = read_commit_graph_one(r, source);
}
/*
@@ commit-graph.c: static void prepare_commit_graph_one(struct repository *r,
static int prepare_commit_graph(struct repository *r)
{
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
/*
* Early return if there is no git dir or if the commit graph is
@@ commit-graph.c: static int prepare_commit_graph(struct repository *r)
- !r->objects->commit_graph && odb;
- odb = odb->next)
- prepare_commit_graph_one(r, odb);
-+ for (alternate = r->objects->alternates;
-+ !r->objects->commit_graph && alternate;
-+ alternate = alternate->next)
-+ prepare_commit_graph_one(r, alternate);
++ for (source = r->objects->sources;
++ !r->objects->commit_graph && source;
++ source = source->next)
++ prepare_commit_graph_one(r, source);
return !!r->objects->commit_graph;
}
@@ commit-graph.c: struct packed_commit_list {
struct write_commit_graph_context {
struct repository *r;
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *odb_source;
char *graph_name;
struct oid_array oids;
struct packed_commit_list commits;
@@ commit-graph.c: static int add_ref_to_set(const char *refname UNUSED,
}
-int write_commit_graph_reachable(struct object_directory *odb,
-+int write_commit_graph_reachable(struct odb_alternate *alternate,
++int write_commit_graph_reachable(struct odb_source *source,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts)
{
@@ commit-graph.c: int write_commit_graph_reachable(struct object_directory *odb,
stop_progress(&data.progress);
- result = write_commit_graph(odb, NULL, &commits,
-+ result = write_commit_graph(alternate, NULL, &commits,
++ result = write_commit_graph(source, NULL, &commits,
flags, opts);
oidset_clear(&commits);
@@ commit-graph.c: static int fill_oids_from_packs(struct write_commit_graph_contex
int ret = 0;
- strbuf_addf(&packname, "%s/pack/", ctx->odb->path);
-+ strbuf_addf(&packname, "%s/pack/", ctx->alternate->path);
++ strbuf_addf(&packname, "%s/pack/", ctx->odb_source->path);
dirlen = packname.len;
if (ctx->report_progress) {
strbuf_addf(&progress_title,
@@ commit-graph.c: static int write_commit_graph_file(struct write_commit_graph_con
strbuf_addf(&tmp_file,
"%s/info/commit-graphs/tmp_graph_XXXXXX",
- ctx->odb->path);
-+ ctx->alternate->path);
++ ctx->odb_source->path);
ctx->graph_name = strbuf_detach(&tmp_file, NULL);
} else {
- ctx->graph_name = get_commit_graph_filename(ctx->odb);
-+ ctx->graph_name = get_commit_graph_filename(ctx->alternate);
++ ctx->graph_name = get_commit_graph_filename(ctx->odb_source);
}
if (safe_create_leading_directories(the_repository, ctx->graph_name)) {
@@ commit-graph.c: static int write_commit_graph_file(struct write_commit_graph_con
if (ctx->split) {
- char *lock_name = get_commit_graph_chain_filename(ctx->odb);
-+ char *lock_name = get_commit_graph_chain_filename(ctx->alternate);
++ char *lock_name = get_commit_graph_chain_filename(ctx->odb_source);
hold_lock_file_for_update_mode(&lk, lock_name,
LOCK_DIE_ON_ERROR, 0444);
@@ commit-graph.c: static int write_commit_graph_file(struct write_commit_graph_con
if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
char *new_base_hash = xstrdup(oid_to_hex(&ctx->new_base_graph->oid));
- char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb, new_base_hash);
-+ char *new_base_name = get_split_graph_filename(ctx->new_base_graph->alternate, new_base_hash);
++ char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb_source, new_base_hash);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 2]);
@@ commit-graph.c: static int write_commit_graph_file(struct write_commit_graph_con
}
} else {
- char *graph_name = get_commit_graph_filename(ctx->odb);
-+ char *graph_name = get_commit_graph_filename(ctx->alternate);
++ char *graph_name = get_commit_graph_filename(ctx->odb_source);
unlink(graph_name);
free(graph_name);
}
@@ commit-graph.c: static int write_commit_graph_file(struct write_commit_graph_con
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(hash_to_hex(file_hash));
- final_graph_name = get_split_graph_filename(ctx->odb,
-+ final_graph_name = get_split_graph_filename(ctx->alternate,
++ final_graph_name = get_split_graph_filename(ctx->odb_source,
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1] = final_graph_name;
@@ commit-graph.c: static void split_graph_merge_strategy(struct write_commit_graph
while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
(max_commits && num_commits > max_commits))) {
- if (g->odb != ctx->odb)
-+ if (g->alternate != ctx->alternate)
++ if (g->odb_source != ctx->odb_source)
break;
if (unsigned_add_overflows(num_commits, g->num_commits))
@@ commit-graph.c: static void split_graph_merge_strategy(struct write_commit_graph
if (ctx->num_commit_graphs_after == 2) {
- char *old_graph_name = get_commit_graph_filename(g->odb);
-+ char *old_graph_name = get_commit_graph_filename(g->alternate);
++ char *old_graph_name = get_commit_graph_filename(g->odb_source);
if (!strcmp(g->filename, old_graph_name) &&
- g->odb != ctx->odb) {
-+ g->alternate != ctx->alternate) {
++ g->odb_source != ctx->odb_source) {
ctx->num_commit_graphs_after = 1;
ctx->new_base_graph = NULL;
}
@@ commit-graph.c: static void expire_commit_graphs(struct write_commit_graph_conte
expire_time = ctx->opts->expire_time;
if (!ctx->split) {
- char *chain_file_name = get_commit_graph_chain_filename(ctx->odb);
-+ char *chain_file_name = get_commit_graph_chain_filename(ctx->alternate);
++ char *chain_file_name = get_commit_graph_chain_filename(ctx->odb_source);
unlink(chain_file_name);
free(chain_file_name);
ctx->num_commit_graphs_after = 0;
}
- strbuf_addstr(&path, ctx->odb->path);
-+ strbuf_addstr(&path, ctx->alternate->path);
++ strbuf_addstr(&path, ctx->odb_source->path);
strbuf_addstr(&path, "/info/commit-graphs");
dir = opendir(path.buf);
@@ commit-graph.c: static void expire_commit_graphs(struct write_commit_graph_conte
}
-int write_commit_graph(struct object_directory *odb,
-+int write_commit_graph(struct odb_alternate *alternate,
++int write_commit_graph(struct odb_source *source,
const struct string_list *const pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
@@ commit-graph.c: int write_commit_graph(struct object_directory *odb,
-
- CALLOC_ARRAY(ctx, 1);
- ctx->r = r;
-- ctx->odb = odb;
-+ ctx->alternate = alternate;
- ctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;
- ctx->report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0;
- ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
+ struct repository *r = the_repository;
+ struct write_commit_graph_context ctx = {
+ .r = r,
+- .odb = odb,
++ .odb_source = source,
+ .append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0,
+ .report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0,
+ .split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0,
## commit-graph.h ##
@@ commit-graph.h: struct repository;
@@ commit-graph.h: struct repository;
-char *get_commit_graph_filename(struct object_directory *odb);
-char *get_commit_graph_chain_filename(struct object_directory *odb);
-+char *get_commit_graph_filename(struct odb_alternate *alternate);
-+char *get_commit_graph_chain_filename(struct odb_alternate *alternate);
++char *get_commit_graph_filename(struct odb_source *source);
++char *get_commit_graph_chain_filename(struct odb_source *source);
int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st);
@@ commit-graph.h: struct commit_graph {
struct object_id oid;
char *filename;
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *odb_source;
uint32_t num_commits_in_base;
unsigned int read_generation_data;
@@ commit-graph.h: struct commit_graph {
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb);
-+ struct odb_alternate *alternate);
++ struct odb_source *source);
struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
int fd, struct stat *st,
int *incomplete_chain);
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb);
-+ struct odb_alternate *alternate);
++ struct odb_source *source);
struct repo_settings;
@@ commit-graph.h: struct commit_graph_opts {
* methods will return 0 without writing a commit-graph.
*/
-int write_commit_graph_reachable(struct object_directory *odb,
-+int write_commit_graph_reachable(struct odb_alternate *alternate,
++int write_commit_graph_reachable(struct odb_source *source,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts);
-int write_commit_graph(struct object_directory *odb,
-+int write_commit_graph(struct odb_alternate *alternate,
++int write_commit_graph(struct odb_source *source,
const struct string_list *pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
@@ diagnose.c: static void dir_file_stats_objects(const char *full_path,
}
-static int dir_file_stats(struct object_directory *object_dir, void *data)
-+static int dir_file_stats(struct odb_alternate *alternate, void *data)
++static int dir_file_stats(struct odb_source *source, void *data)
{
struct strbuf *buf = data;
- strbuf_addf(buf, "Contents of %s:\n", object_dir->path);
-+ strbuf_addf(buf, "Contents of %s:\n", alternate->path);
++ strbuf_addf(buf, "Contents of %s:\n", source->path);
- for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects,
-+ for_each_file_in_pack_dir(alternate->path, dir_file_stats_objects,
++ for_each_file_in_pack_dir(source->path, dir_file_stats_objects,
data);
return 0;
@@ diagnose.c: int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(r->objects->odb, &buf);
-+ dir_file_stats(r->objects->alternates, &buf);
++ dir_file_stats(r->objects->sources, &buf);
foreach_alt_odb(dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
@@ http-walker.c: static int fetch_object(struct walker *walker, const struct objec
} else if (req->rename < 0) {
struct strbuf buf = STRBUF_INIT;
- odb_loose_path(the_repository->objects->odb, &buf, &req->oid);
-+ odb_loose_path(the_repository->objects->alternates, &buf, &req->oid);
++ odb_loose_path(the_repository->objects->sources, &buf, &req->oid);
ret = error("unable to write sha1 filename %s", buf.buf);
strbuf_release(&buf);
}
@@ http.c: struct http_object_request *new_http_object_request(const char *base_url
freq->localfile = -1;
- odb_loose_path(the_repository->objects->odb, &filename, oid);
-+ odb_loose_path(the_repository->objects->alternates, &filename, oid);
++ odb_loose_path(the_repository->objects->sources, &filename, oid);
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ http.c: int finish_http_object_request(struct http_object_request *freq)
return -1;
}
- odb_loose_path(the_repository->objects->odb, &filename, &freq->oid);
-+ odb_loose_path(the_repository->objects->alternates, &filename, &freq->oid);
++ odb_loose_path(the_repository->objects->sources, &filename, &freq->oid);
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
strbuf_release(&filename);
@@ loose.c: static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *k
}
-static int insert_loose_map(struct object_directory *odb,
-+static int insert_loose_map(struct odb_alternate *alternate,
++static int insert_loose_map(struct odb_source *source,
const struct object_id *oid,
const struct object_id *compat_oid)
{
- struct loose_object_map *map = odb->loose_map;
-+ struct loose_object_map *map = alternate->loose_map;
++ struct loose_object_map *map = source->loose_map;
int inserted = 0;
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
if (inserted)
- oidtree_insert(odb->loose_objects_cache, compat_oid);
-+ oidtree_insert(alternate->loose_objects_cache, compat_oid);
++ oidtree_insert(source->loose_objects_cache, compat_oid);
return inserted;
}
-static int load_one_loose_object_map(struct repository *repo, struct object_directory *dir)
-+static int load_one_loose_object_map(struct repository *repo, struct odb_alternate *alternate)
++static int load_one_loose_object_map(struct repository *repo, struct odb_source *source)
{
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
FILE *fp;
@@ loose.c: static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *k
- if (!dir->loose_objects_cache) {
- ALLOC_ARRAY(dir->loose_objects_cache, 1);
- oidtree_init(dir->loose_objects_cache);
-+ if (!alternate->loose_map)
-+ loose_object_map_init(&alternate->loose_map);
-+ if (!alternate->loose_objects_cache) {
-+ ALLOC_ARRAY(alternate->loose_objects_cache, 1);
-+ oidtree_init(alternate->loose_objects_cache);
++ if (!source->loose_map)
++ loose_object_map_init(&source->loose_map);
++ if (!source->loose_objects_cache) {
++ ALLOC_ARRAY(source->loose_objects_cache, 1);
++ oidtree_init(source->loose_objects_cache);
}
- insert_loose_map(dir, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
- insert_loose_map(dir, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
- insert_loose_map(dir, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
-+ insert_loose_map(alternate, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
-+ insert_loose_map(alternate, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
-+ insert_loose_map(alternate, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
++ insert_loose_map(source, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
++ insert_loose_map(source, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
++ insert_loose_map(source, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
repo_common_path_replace(repo, &path, "objects/loose-object-idx");
fp = fopen(path.buf, "rb");
@@ loose.c: static int load_one_loose_object_map(struct repository *repo, struct ob
p != buf.buf + buf.len)
goto err;
- insert_loose_map(dir, &oid, &compat_oid);
-+ insert_loose_map(alternate, &oid, &compat_oid);
++ insert_loose_map(source, &oid, &compat_oid);
}
strbuf_release(&buf);
@@ loose.c: static int load_one_loose_object_map(struct repository *repo, struct ob
int repo_read_loose_object_map(struct repository *repo)
{
- struct object_directory *dir;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
if (!should_use_loose_object_map(repo))
return 0;
@@ loose.c: static int load_one_loose_object_map(struct repository *repo, struct ob
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- if (load_one_loose_object_map(repo, dir) < 0) {
-+ for (alternate = repo->objects->alternates; alternate; alternate = alternate->next) {
-+ if (load_one_loose_object_map(repo, alternate) < 0) {
++ for (source = repo->objects->sources; source; source = source->next) {
++ if (load_one_loose_object_map(repo, source) < 0) {
return -1;
}
}
@@ loose.c: int repo_read_loose_object_map(struct repository *repo)
int repo_write_loose_object_map(struct repository *repo)
{
- kh_oid_map_t *map = repo->objects->odb->loose_map->to_compat;
-+ kh_oid_map_t *map = repo->objects->alternates->loose_map->to_compat;
++ kh_oid_map_t *map = repo->objects->sources->loose_map->to_compat;
struct lock_file lock;
int fd;
khiter_t iter;
@@ loose.c: int repo_add_loose_object_map(struct repository *repo, const struct obj
return 0;
- inserted = insert_loose_map(repo->objects->odb, oid, compat_oid);
-+ inserted = insert_loose_map(repo->objects->alternates, oid, compat_oid);
++ inserted = insert_loose_map(repo->objects->sources, oid, compat_oid);
if (inserted)
return write_one_object(repo, oid, compat_oid);
return 0;
@@ loose.c: int repo_loose_object_map_oid(struct repository *repo,
struct object_id *dest)
{
- struct object_directory *dir;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
kh_oid_map_t *map;
khiter_t pos;
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- struct loose_object_map *loose_map = dir->loose_map;
-+ for (alternate = repo->objects->alternates; alternate; alternate = alternate->next) {
-+ struct loose_object_map *loose_map = alternate->loose_map;
++ for (source = repo->objects->sources; source; source = source->next) {
++ struct loose_object_map *loose_map = source->loose_map;
if (!loose_map)
continue;
map = (to == repo->compat_hash_algo) ?
@@ midx.c: void clear_midx_file(struct repository *r)
struct strbuf midx = STRBUF_INIT;
- get_midx_filename(r->hash_algo, &midx, r->objects->odb->path);
-+ get_midx_filename(r->hash_algo, &midx, r->objects->alternates->path);
++ get_midx_filename(r->hash_algo, &midx, r->objects->sources->path);
if (r->objects && r->objects->multi_pack_index) {
close_midx(r->objects->multi_pack_index);
@@ midx.c: void clear_midx_file(struct repository *r)
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_BITMAP, NULL);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_REV, NULL);
-+ clear_midx_files_ext(r->objects->alternates->path, MIDX_EXT_BITMAP, NULL);
-+ clear_midx_files_ext(r->objects->alternates->path, MIDX_EXT_REV, NULL);
++ clear_midx_files_ext(r->objects->sources->path, MIDX_EXT_BITMAP, NULL);
++ clear_midx_files_ext(r->objects->sources->path, MIDX_EXT_REV, NULL);
strbuf_release(&midx);
}
@@ object-file.c: static void fill_loose_path(struct strbuf *buf, const struct obje
}
-const char *odb_loose_path(struct object_directory *odb,
-+const char *odb_loose_path(struct odb_alternate *alternate,
++const char *odb_loose_path(struct odb_source *source,
struct strbuf *buf,
const struct object_id *oid)
{
strbuf_reset(buf);
- strbuf_addstr(buf, odb->path);
-+ strbuf_addstr(buf, alternate->path);
++ strbuf_addstr(buf, source->path);
strbuf_addch(buf, '/');
fill_loose_path(buf, oid);
return buf->buf;
@@ object-file.c: int check_and_freshen_file(const char *fn, int freshen)
}
-static int check_and_freshen_odb(struct object_directory *odb,
-+static int check_and_freshen_odb(struct odb_alternate *alternate,
++static int check_and_freshen_odb(struct odb_source *source,
const struct object_id *oid,
int freshen)
{
static struct strbuf path = STRBUF_INIT;
- odb_loose_path(odb, &path, oid);
-+ odb_loose_path(alternate, &path, oid);
++ odb_loose_path(source, &path, oid);
return check_and_freshen_file(path.buf, freshen);
}
static int check_and_freshen_local(const struct object_id *oid, int freshen)
{
- return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
-+ return check_and_freshen_odb(the_repository->objects->alternates, oid, freshen);
++ return check_and_freshen_odb(the_repository->objects->sources, oid, freshen);
}
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
- if (check_and_freshen_odb(odb, oid, freshen))
-+ for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
-+ if (check_and_freshen_odb(alternate, oid, freshen))
++ for (source = the_repository->objects->sources->next; source; source = source->next) {
++ if (check_and_freshen_odb(source, oid, freshen))
return 1;
}
return 0;
@@ object-file.c: int stream_object_signature(struct repository *r, const struct ob
struct stat *st, const char **path)
{
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
-+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
-+ *path = odb_loose_path(alternate, &buf, oid);
++ for (source = r->objects->sources; source; source = source->next) {
++ *path = odb_loose_path(source, &buf, oid);
if (!lstat(*path, st))
return 0;
}
@@ object-file.c: static int open_loose_object(struct repository *r,
{
int fd;
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
-+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
-+ *path = odb_loose_path(alternate, &buf, oid);
++ for (source = r->objects->sources; source; source = source->next) {
++ *path = odb_loose_path(source, &buf, oid);
fd = git_open(*path);
if (fd >= 0)
return fd;
@@ object-file.c: static int open_loose_object(struct repository *r,
const struct object_id *oid)
{
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- if (oidtree_contains(odb_loose_cache(odb, oid), oid))
-+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
-+ if (oidtree_contains(odb_loose_cache(alternate, oid), oid))
++ for (source = r->objects->sources; source; source = source->next) {
++ if (oidtree_contains(odb_loose_cache(source, oid), oid))
return 1;
}
return 0;
@@ object-file.c: void hash_object_file(const struct git_hash_algo *algo, const voi
static void close_loose_object(int fd, const char *filename)
{
- if (the_repository->objects->odb->will_destroy)
-+ if (the_repository->objects->alternates->will_destroy)
++ if (the_repository->objects->sources->will_destroy)
goto out;
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
@@ object-file.c: static int write_loose_object(const struct object_id *oid, char *
prepare_loose_object_bulk_checkin();
- odb_loose_path(the_repository->objects->odb, &filename, oid);
-+ odb_loose_path(the_repository->objects->alternates, &filename, oid);
++ odb_loose_path(the_repository->objects->sources, &filename, oid);
fd = start_loose_object_common(&tmp_file, filename.buf, flags,
&stream, compressed, sizeof(compressed),
@@ object-file.c: int stream_loose_object(struct input_stream *in_stream, size_t le
}
- odb_loose_path(the_repository->objects->odb, &filename, oid);
-+ odb_loose_path(the_repository->objects->alternates, &filename, oid);
++ odb_loose_path(the_repository->objects->sources, &filename, oid);
/* We finally know the object path, and create the missing dir. */
dirlen = directory_size(filename.buf);
@@ object-file.c: int for_each_loose_file_in_objdir(const char *path,
enum for_each_object_flags flags)
{
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
- int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
-+ for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
-+ int r = for_each_loose_file_in_objdir(alternate->path, cb, NULL,
++ for (source = the_repository->objects->sources; source; source = source->next) {
++ int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
NULL, data);
if (r)
return r;
@@ object-file.c: static int append_loose_object(const struct object_id *oid,
-struct oidtree *odb_loose_cache(struct object_directory *odb,
- const struct object_id *oid)
-+struct oidtree *odb_loose_cache(struct odb_alternate *alternate,
++struct oidtree *odb_loose_cache(struct odb_source *source,
+ const struct object_id *oid)
{
int subdir_nr = oid->hash[0];
struct strbuf buf = STRBUF_INIT;
- size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
-+ size_t word_bits = bitsizeof(alternate->loose_objects_subdir_seen[0]);
++ size_t word_bits = bitsizeof(source->loose_objects_subdir_seen[0]);
size_t word_index = subdir_nr / word_bits;
size_t mask = (size_t)1u << (subdir_nr % word_bits);
uint32_t *bitmap;
if (subdir_nr < 0 ||
- subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
-+ subdir_nr >= bitsizeof(alternate->loose_objects_subdir_seen))
++ subdir_nr >= bitsizeof(source->loose_objects_subdir_seen))
BUG("subdir_nr out of range");
- bitmap = &odb->loose_objects_subdir_seen[word_index];
-+ bitmap = &alternate->loose_objects_subdir_seen[word_index];
++ bitmap = &source->loose_objects_subdir_seen[word_index];
if (*bitmap & mask)
- return odb->loose_objects_cache;
- if (!odb->loose_objects_cache) {
- ALLOC_ARRAY(odb->loose_objects_cache, 1);
- oidtree_init(odb->loose_objects_cache);
-+ return alternate->loose_objects_cache;
-+ if (!alternate->loose_objects_cache) {
-+ ALLOC_ARRAY(alternate->loose_objects_cache, 1);
-+ oidtree_init(alternate->loose_objects_cache);
++ return source->loose_objects_cache;
++ if (!source->loose_objects_cache) {
++ ALLOC_ARRAY(source->loose_objects_cache, 1);
++ oidtree_init(source->loose_objects_cache);
}
- strbuf_addstr(&buf, odb->path);
-+ strbuf_addstr(&buf, alternate->path);
++ strbuf_addstr(&buf, source->path);
for_each_file_in_obj_subdir(subdir_nr, &buf,
append_loose_object,
NULL, NULL,
- odb->loose_objects_cache);
-+ alternate->loose_objects_cache);
++ source->loose_objects_cache);
*bitmap |= mask;
strbuf_release(&buf);
- return odb->loose_objects_cache;
-+ return alternate->loose_objects_cache;
++ return source->loose_objects_cache;
}
-void odb_clear_loose_cache(struct object_directory *odb)
-+void odb_clear_loose_cache(struct odb_alternate *alternate)
++void odb_clear_loose_cache(struct odb_source *source)
{
- oidtree_clear(odb->loose_objects_cache);
- FREE_AND_NULL(odb->loose_objects_cache);
- memset(&odb->loose_objects_subdir_seen, 0,
- sizeof(odb->loose_objects_subdir_seen));
-+ oidtree_clear(alternate->loose_objects_cache);
-+ FREE_AND_NULL(alternate->loose_objects_cache);
-+ memset(&alternate->loose_objects_subdir_seen, 0,
-+ sizeof(alternate->loose_objects_subdir_seen));
++ oidtree_clear(source->loose_objects_cache);
++ FREE_AND_NULL(source->loose_objects_cache);
++ memset(&source->loose_objects_subdir_seen, 0,
++ sizeof(source->loose_objects_subdir_seen));
}
static int check_stream_oid(git_zstream *stream,
@@ object-file.h: enum {
int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
-struct object_directory;
-+struct odb_alternate;
++struct odb_source;
/*
* Populate and return the loose object cache array corresponding to the
* given object ID.
*/
-struct oidtree *odb_loose_cache(struct object_directory *odb,
-+struct oidtree *odb_loose_cache(struct odb_alternate *alternate,
++struct oidtree *odb_loose_cache(struct odb_source *source,
const struct object_id *oid);
/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
-+void odb_clear_loose_cache(struct odb_alternate *alternate);
++void odb_clear_loose_cache(struct odb_source *source);
/*
* Put in `buf` the name of the file in the local object database that
* would be used to store a loose object with the specified oid.
*/
-const char *odb_loose_path(struct object_directory *odb,
-+const char *odb_loose_path(struct odb_alternate *alternate,
++const char *odb_loose_path(struct odb_source *source,
struct strbuf *buf,
const struct object_id *oid);
@@ object-name.c: static enum cb_next match_prefix(const struct object_id *oid, voi
static void find_short_object_filename(struct disambiguate_state *ds)
{
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
- for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next)
- oidtree_each(odb_loose_cache(odb, &ds->bin_pfx),
-+ for (alternate = ds->repo->objects->alternates; alternate && !ds->ambiguous; alternate = alternate->next)
-+ oidtree_each(odb_loose_cache(alternate, &ds->bin_pfx),
++ for (source = ds->repo->objects->sources; source && !ds->ambiguous; source = source->next)
++ oidtree_each(odb_loose_cache(source, &ds->bin_pfx),
&ds->bin_pfx, ds->len, match_prefix, ds);
}
@@ object-store.c
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
- struct object_directory *, 1, fspathhash, fspatheq)
-+ struct odb_alternate *, 1, fspathhash, fspatheq)
++ struct odb_source *, 1, fspathhash, fspatheq)
/*
* This is meant to hold a *small* number of objects that you would
@@ object-store.c: static int alt_odb_usable(struct object_database *o,
* thing twice, or object directory itself.
*/
- if (!o->odb_by_path) {
-+ if (!o->alternate_by_path) {
++ if (!o->source_by_path) {
khiter_t p;
- o->odb_by_path = kh_init_odb_path_map();
- assert(!o->odb->next);
- p = kh_put_odb_path_map(o->odb_by_path, o->odb->path, &r);
-+ o->alternate_by_path = kh_init_odb_path_map();
-+ assert(!o->alternates->next);
-+ p = kh_put_odb_path_map(o->alternate_by_path, o->alternates->path, &r);
++ o->source_by_path = kh_init_odb_path_map();
++ assert(!o->sources->next);
++ p = kh_put_odb_path_map(o->source_by_path, o->sources->path, &r);
assert(r == 1); /* never used */
- kh_value(o->odb_by_path, p) = o->odb;
-+ kh_value(o->alternate_by_path, p) = o->alternates;
++ kh_value(o->source_by_path, p) = o->sources;
}
if (fspatheq(path->buf, normalized_objdir))
return 0;
- *pos = kh_put_odb_path_map(o->odb_by_path, path->buf, &r);
-+ *pos = kh_put_odb_path_map(o->alternate_by_path, path->buf, &r);
++ *pos = kh_put_odb_path_map(o->source_by_path, path->buf, &r);
/* r: 0 = exists, 1 = never used, 2 = deleted */
return r == 0 ? 0 : 1;
}
@@ object-store.c: static int alt_odb_usable(struct object_database *o,
*
* The variable alt_odb_list points at the list of struct
- * object_directory. The elements on this list come from
-+ * odb_alternate. The elements on this list come from
++ * odb_source. The elements on this list come from
* non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
* environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
* whose contents is similar to that environment variable but can be
@@ object-store.c: static void read_info_alternates(struct repository *r,
const char *relative_base, int depth, const char *normalized_objdir)
{
- struct object_directory *ent;
-+ struct odb_alternate *alternate;
++ struct odb_source *alternate;
struct strbuf pathbuf = STRBUF_INIT;
struct strbuf tmp = STRBUF_INIT;
khiter_t pos;
@@ object-store.c: static int link_alt_odb_entry(struct repository *r, const struct
- /* pathbuf.buf is already in r->objects->odb_by_path */
- ent->path = strbuf_detach(&pathbuf, NULL);
+ CALLOC_ARRAY(alternate, 1);
-+ /* pathbuf.buf is already in r->objects->alternate_by_path */
++ /* pathbuf.buf is already in r->objects->source_by_path */
+ alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
@@ object-store.c: static int link_alt_odb_entry(struct repository *r, const struct
- ent->next = NULL;
- assert(r->objects->odb_by_path);
- kh_value(r->objects->odb_by_path, pos) = ent;
-+ *r->objects->alternates_tail = alternate;
-+ r->objects->alternates_tail = &(alternate->next);
++ *r->objects->sources_tail = alternate;
++ r->objects->sources_tail = &(alternate->next);
+ alternate->next = NULL;
-+ assert(r->objects->alternate_by_path);
-+ kh_value(r->objects->alternate_by_path, pos) = alternate;
++ assert(r->objects->source_by_path);
++ kh_value(r->objects->source_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, ent->path, depth + 1);
@@ object-store.c: static void link_alt_odb_entries(struct repository *r, const cha
}
- strbuf_realpath(&objdirbuf, r->objects->odb->path, 1);
-+ strbuf_realpath(&objdirbuf, r->objects->alternates->path, 1);
++ strbuf_realpath(&objdirbuf, r->objects->sources->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
@@ object-store.c: void add_to_alternates_memory(const char *reference)
}
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy)
-+struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy)
++struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
{
- struct object_directory *new_odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
/*
* Make sure alternates are initialized, or else our entry may be
@@ object-store.c: struct object_directory *set_temporary_primary_odb(const char *d
*/
- new_odb = xcalloc(1, sizeof(*new_odb));
- new_odb->path = xstrdup(dir);
-+ alternate = xcalloc(1, sizeof(*alternate));
-+ alternate->path = xstrdup(dir);
++ source = xcalloc(1, sizeof(*source));
++ source->path = xstrdup(dir);
/*
* Disable ref updates while a temporary odb is active, since
@@ object-store.c: struct object_directory *set_temporary_primary_odb(const char *d
- new_odb->next = the_repository->objects->odb;
- the_repository->objects->odb = new_odb;
- return new_odb->next;
-+ alternate->disable_ref_updates = 1;
-+ alternate->will_destroy = will_destroy;
-+ alternate->next = the_repository->objects->alternates;
-+ the_repository->objects->alternates = alternate;
-+ return alternate->next;
++ source->disable_ref_updates = 1;
++ source->will_destroy = will_destroy;
++ source->next = the_repository->objects->sources;
++ the_repository->objects->sources = source;
++ return source->next;
}
-static void free_object_directory(struct object_directory *odb)
-+static void free_object_directory(struct odb_alternate *alternate)
++static void free_object_directory(struct odb_source *source)
{
- free(odb->path);
- odb_clear_loose_cache(odb);
- loose_object_map_clear(&odb->loose_map);
- free(odb);
-+ free(alternate->path);
-+ odb_clear_loose_cache(alternate);
-+ loose_object_map_clear(&alternate->loose_map);
-+ free(alternate);
++ free(source->path);
++ odb_clear_loose_cache(source);
++ loose_object_map_clear(&source->loose_map);
++ free(source);
}
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
-+void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path)
++void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
{
- struct object_directory *cur_odb = the_repository->objects->odb;
-+ struct odb_alternate *cur_alt = the_repository->objects->alternates;
++ struct odb_source *cur_alt = the_repository->objects->sources;
- if (strcmp(old_path, cur_odb->path))
+ if (strcmp(old_path, cur_alt->path))
@@ object-store.c: struct object_directory *set_temporary_primary_odb(const char *d
- the_repository->objects->odb = restore_odb;
- free_object_directory(cur_odb);
-+ the_repository->objects->alternates = restore_alt;
++ the_repository->objects->sources = restore_alt;
+ free_object_directory(cur_alt);
}
@@ object-store.c: char *compute_alternate_path(const char *path, struct strbuf *er
}
-struct object_directory *find_odb(struct repository *r, const char *obj_dir)
-+struct odb_alternate *find_odb(struct repository *r, const char *obj_dir)
++struct odb_source *find_odb(struct repository *r, const char *obj_dir)
{
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- strbuf_realpath(&odb_path_real, odb->path, 1);
-+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
-+ strbuf_realpath(&odb_path_real, alternate->path, 1);
++ for (source = r->objects->sources; source; source = source->next) {
++ strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
}
@@ object-store.c: struct object_directory *find_odb(struct repository *r, const ch
strbuf_release(&odb_path_real);
- if (!odb)
-+ if (!alternate)
++ if (!source)
die(_("could not find object directory matching %s"), obj_dir);
- return odb;
-+ return alternate;
++ return source;
}
static void fill_alternate_refs_command(struct child_process *cmd,
@@ object-store.c: struct alternate_refs_data {
};
-static int refs_from_alternate_cb(struct object_directory *e,
-+static int refs_from_alternate_cb(struct odb_alternate *alternate,
++static int refs_from_alternate_cb(struct odb_source *alternate,
void *data)
{
struct strbuf path = STRBUF_INIT;
@@ object-store.c: void for_each_alternate_ref(alternate_ref_fn fn, void *data)
int foreach_alt_odb(alt_odb_fn fn, void *cb)
{
- struct object_directory *ent;
-+ struct odb_alternate *alternate;
++ struct odb_source *alternate;
int r = 0;
prepare_alt_odb(the_repository);
- for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {
- r = fn(ent, cb);
-+ for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
++ for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
+ r = fn(alternate, cb);
if (r)
break;
@@ object-store.c: void prepare_alt_odb(struct repository *r)
link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->odb->path, 0);
-+ read_info_alternates(r, r->objects->alternates->path, 0);
++ read_info_alternates(r, r->objects->sources->path, 0);
r->objects->loaded_alternates = 1;
}
@@ object-store.c: void prepare_alt_odb(struct repository *r)
{
prepare_alt_odb(r);
- return !!r->objects->odb->next;
-+ return !!r->objects->alternates->next;
++ return !!r->objects->sources->next;
}
int obj_read_use_lock = 0;
@@ object-store.c: struct object_database *odb_new(void)
{
- while (o->odb) {
- struct object_directory *next;
-+ while (o->alternates) {
-+ struct odb_alternate *next;
++ while (o->sources) {
++ struct odb_source *next;
- next = o->odb->next;
- free_object_directory(o->odb);
- o->odb = next;
-+ next = o->alternates->next;
-+ free_object_directory(o->alternates);
-+ o->alternates = next;
++ next = o->sources->next;
++ free_object_directory(o->sources);
++ o->sources = next;
}
- kh_destroy_odb_path_map(o->odb_by_path);
- o->odb_by_path = NULL;
-+ kh_destroy_odb_path_map(o->alternate_by_path);
-+ o->alternate_by_path = NULL;
++ kh_destroy_odb_path_map(o->source_by_path);
++ o->source_by_path = NULL;
}
void odb_clear(struct object_database *o)
@@ object-store.c: void odb_clear(struct object_database *o)
free_object_directories(o);
- o->odb_tail = NULL;
-+ o->alternates_tail = NULL;
++ o->sources_tail = NULL;
o->loaded_alternates = 0;
for (size_t i = 0; i < o->cached_object_nr; i++)
@@ object-store.h: struct oidtree;
-struct object_directory {
- struct object_directory *next;
+/*
-+ * The alternate is the part of the object database that stores the actual
++ * The source is the part of the object database that stores the actual
+ * objects. It thus encapsulates the logic to read and write the specific
-+ * on-disk format. An object database can have multiple alternates, and
-+ * exactly one primary alternate that is used when writing new objects.
++ * on-disk format. An object database can have multiple sources:
++ *
++ * - The primary source, which is typically located in "$GIT_DIR/objects".
++ * This is where new objects are usually written to.
++ *
++ * - Alternate sources, which are configured via "objects/info/alternates" or
++ * via the GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable. These
++ * alternate sources are only used to read objects.
+ */
-+struct odb_alternate {
-+ struct odb_alternate *next;
++struct odb_source {
++ struct odb_source *next;
/*
* Used to store the results of readdir(3) calls when we are OK
+@@ object-store.h: struct object_directory {
+ int will_destroy;
+
+ /*
+- * Path to the alternative object store. If this is a relative path,
+- * it is relative to the current working directory.
++ * Path to the source. If this is a relative path, it is relative to
++ * the current working directory.
+ */
+ char *path;
+ };
@@ object-store.h: struct object_directory {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
-+struct odb_alternate *find_odb(struct repository *r, const char *obj_dir);
-+typedef int alt_odb_fn(struct odb_alternate *, void *);
++struct odb_source *find_odb(struct repository *r, const char *obj_dir);
++typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
@@ object-store.h: void add_to_alternates_memory(const char *dir);
* object directory; returns the former primary object directory.
*/
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
-+struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destroy);
++struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy);
/*
* Restore a previous ODB replaced by set_temporary_main_odb.
*/
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
-+void restore_primary_odb(struct odb_alternate *restore_alternate, const char *old_path);
++void restore_primary_odb(struct odb_source *restore_alternate, const char *old_path);
struct packed_git;
struct multi_pack_index;
@@ object-store.h: struct object_database {
- struct object_directory *odb;
- struct object_directory **odb_tail;
- struct kh_odb_path_map *odb_by_path;
-+ struct odb_alternate *alternates;
-+ struct odb_alternate **alternates_tail;
-+ struct kh_odb_path_map *alternate_by_path;
++ struct odb_source *sources;
++ struct odb_source **sources_tail;
++ struct kh_odb_path_map *source_by_path;
int loaded_alternates;
@@ object-store.h: struct object_database {
* 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.
-+ * populate the "alternates" list when prepare_alt_odb() is run.
++ * populate the "sources" list when prepare_alt_odb() is run.
*/
char *alternate_db;
@@ packfile.c: static void prepare_packed_git_mru(struct repository *r)
static void prepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
if (r->objects->packed_git_initialized)
return;
@@ packfile.c: static void prepare_packed_git_mru(struct repository *r)
- int local = (odb == r->objects->odb);
- prepare_multi_pack_index_one(r, odb->path, local);
- prepare_packed_git_one(r, odb->path, local);
-+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
-+ int local = (alternate == r->objects->alternates);
-+ prepare_multi_pack_index_one(r, alternate->path, local);
-+ prepare_packed_git_one(r, alternate->path, local);
++ for (source = r->objects->sources; source; source = source->next) {
++ int local = (source == r->objects->sources);
++ prepare_multi_pack_index_one(r, source->path, local);
++ prepare_packed_git_one(r, source->path, local);
}
rearrange_packed_git(r);
@@ packfile.c: static void prepare_packed_git(struct repository *r)
void reprepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
obj_read_lock();
@@ packfile.c: void reprepare_packed_git(struct repository *r)
- for (odb = r->objects->odb; odb; odb = odb->next)
- odb_clear_loose_cache(odb);
-+ for (alternate = r->objects->alternates; alternate; alternate = alternate->next)
-+ odb_clear_loose_cache(alternate);
++ for (source = r->objects->sources; source; source = source->next)
++ odb_clear_loose_cache(source);
r->objects->approximate_object_count_valid = 0;
r->objects->packed_git_initialized = 0;
@@ path.c: static void adjust_git_path(struct repository *repo,
repo->index_file, strlen(repo->index_file));
else if (dir_prefix(base, "objects"))
- replace_dir(buf, git_dir_len + 7, repo->objects->odb->path);
-+ replace_dir(buf, git_dir_len + 7, repo->objects->alternates->path);
++ replace_dir(buf, git_dir_len + 7, repo->objects->sources->path);
else if (repo_settings_get_hooks_path(repo) && dir_prefix(base, "hooks"))
replace_dir(buf, git_dir_len + 5, repo_settings_get_hooks_path(repo));
else if (repo->different_commondir)
@@ refs.c: int ref_transaction_prepare(struct ref_transaction *transaction,
}
- if (refs->repo->objects->odb->disable_ref_updates) {
-+ if (refs->repo->objects->alternates->disable_ref_updates) {
++ if (refs->repo->objects->sources->disable_ref_updates) {
strbuf_addstr(err,
_("ref updates forbidden inside quarantine environment"));
return -1;
@@ repository.c: const char *repo_get_common_dir(struct repository *repo)
const char *repo_get_object_directory(struct repository *repo)
{
- if (!repo->objects->odb)
-+ if (!repo->objects->alternates)
++ if (!repo->objects->sources)
BUG("repository hasn't been set up");
- return repo->objects->odb->path;
-+ return repo->objects->alternates->path;
++ return repo->objects->sources->path;
}
const char *repo_get_index_file(struct repository *repo)
@@ repository.c: void repo_set_gitdir(struct repository *repo,
- if (!repo->objects->odb) {
- CALLOC_ARRAY(repo->objects->odb, 1);
- repo->objects->odb_tail = &repo->objects->odb->next;
-+ if (!repo->objects->alternates) {
-+ CALLOC_ARRAY(repo->objects->alternates, 1);
-+ repo->objects->alternates_tail = &repo->objects->alternates->next;
++ if (!repo->objects->sources) {
++ CALLOC_ARRAY(repo->objects->sources, 1);
++ repo->objects->sources_tail = &repo->objects->sources->next;
}
- expand_base_dir(&repo->objects->odb->path, o->object_dir,
-+ expand_base_dir(&repo->objects->alternates->path, o->object_dir,
++ expand_base_dir(&repo->objects->sources->path, o->object_dir,
repo->commondir, "objects");
- repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
-+ repo->objects->alternates->disable_ref_updates = o->disable_ref_updates;
++ repo->objects->sources->disable_ref_updates = o->disable_ref_updates;
free(repo->objects->alternate_db);
repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
@@ submodule-config.c: static void config_from_gitmodules(config_fn_t fn, struct re
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->odb->path);
-+ add_submodule_odb_by_path(repo->objects->alternates->path);
++ add_submodule_odb_by_path(repo->objects->sources->path);
} else {
goto out;
}
@@ t/helper/test-read-graph.c: static void dump_graph_bloom_filters(struct commit_g
{
struct commit_graph *graph = NULL;
- struct object_directory *odb;
-+ struct odb_alternate *alternate;
++ struct odb_source *source;
int ret = 0;
setup_git_directory();
- odb = the_repository->objects->odb;
-+ alternate = the_repository->objects->alternates;
++ source = the_repository->objects->sources;
prepare_repo_settings(the_repository);
- graph = read_commit_graph_one(the_repository, odb);
-+ graph = read_commit_graph_one(the_repository, alternate);
++ graph = read_commit_graph_one(the_repository, source);
if (!graph) {
ret = 1;
goto done;
@@ tmp-objdir.c: struct tmp_objdir {
struct strbuf path;
struct strvec env;
- struct object_directory *prev_odb;
-+ struct odb_alternate *prev_alt;
++ struct odb_source *prev_source;
int will_destroy;
};
@@ tmp-objdir.c: int tmp_objdir_destroy(struct tmp_objdir *t)
- if (t->prev_odb)
- restore_primary_odb(t->prev_odb, t->path.buf);
-+ if (t->prev_alt)
-+ restore_primary_odb(t->prev_alt, t->path.buf);
++ if (t->prev_source)
++ restore_primary_odb(t->prev_source, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ tmp-objdir.c: int tmp_objdir_migrate(struct tmp_objdir *t)
- if (t->prev_odb) {
- if (t->repo->objects->odb->will_destroy)
-+ if (t->prev_alt) {
-+ if (t->repo->objects->alternates->will_destroy)
++ if (t->prev_source) {
++ if (t->repo->objects->sources->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_odb, t->path.buf);
- t->prev_odb = NULL;
-+ restore_primary_odb(t->prev_alt, t->path.buf);
-+ t->prev_alt = NULL;
++ restore_primary_odb(t->prev_source, t->path.buf);
++ t->prev_source = NULL;
}
strbuf_addbuf(&src, &t->path);
@@ tmp-objdir.c: void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
- if (t->prev_odb)
-+ if (t->prev_alt)
++ if (t->prev_source)
BUG("the primary object database is already replaced");
- t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
-+ t->prev_alt = set_temporary_primary_odb(t->path.buf, will_destroy);
++ t->prev_source = set_temporary_primary_odb(t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
{
- if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
-+ if (!the_tmp_objdir || !the_tmp_objdir->prev_alt)
++ if (!the_tmp_objdir || !the_tmp_objdir->prev_source)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
- the_tmp_objdir->prev_odb = NULL;
-+ restore_primary_odb(the_tmp_objdir->prev_alt, the_tmp_objdir->path.buf);
-+ the_tmp_objdir->prev_alt = NULL;
++ restore_primary_odb(the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
++ the_tmp_objdir->prev_source = NULL;
return the_tmp_objdir;
}
3: c9fe7a702f2 = 3: f294d140f35 object-store: rename files to "odb.{c,h}"
4: 2d35bc630b1 ! 4: b9cd65d68e3 odb: introduce parent pointers
@@ Commit message
In subsequent commits we'll get rid of our use of `the_repository` in
"odb.c" in favor of explicitly passing in a `struct object_database` or
- a `struct odb_alternate`. In some cases though we'll need access to the
+ a `struct odb_source`. In some cases though we'll need access to the
repository, for example to read a config value from it, but we don't
have a way to access the repository owning a specific object database.
Introduce parent pointers for `struct object_database` to its owning
- repository as well as for `struct odb_alternate` to its owning object
+ repository as well as for `struct odb_source` to its owning object
database, which will allow us to adapt those use cases.
Note that this change requires us to pass through the object database to
`link_alt_odb_entry()` so that we can set up the parent pointers for any
- alternate there. The callchain is adapted to pass through the object
+ source there. The callchain is adapted to pass through the object
database accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
@@ odb.c: static int alt_odb_usable(struct object_database *o,
+ int depth,
+ const char *normalized_objdir)
{
- struct odb_alternate *alternate;
+ struct odb_source *alternate;
struct strbuf pathbuf = STRBUF_INIT;
@@ odb.c: static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
@@ odb.c: static int link_alt_odb_entry(struct repository *r, const struct strbuf *
goto error;
CALLOC_ARRAY(alternate, 1);
+- /* pathbuf.buf is already in r->objects->source_by_path */
+ alternate->odb = odb;
- /* pathbuf.buf is already in r->objects->alternate_by_path */
++ /* pathbuf.buf is already in r->objects->alternate_by_path */
alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
-- *r->objects->alternates_tail = alternate;
-- r->objects->alternates_tail = &(alternate->next);
-+ *odb->alternates_tail = alternate;
-+ odb->alternates_tail = &(alternate->next);
+- *r->objects->sources_tail = alternate;
+- r->objects->sources_tail = &(alternate->next);
++ *odb->sources_tail = alternate;
++ odb->sources_tail = &(alternate->next);
alternate->next = NULL;
-- assert(r->objects->alternate_by_path);
-- kh_value(r->objects->alternate_by_path, pos) = alternate;
-+ assert(odb->alternate_by_path);
-+ kh_value(odb->alternate_by_path, pos) = alternate;
+- assert(r->objects->source_by_path);
+- kh_value(r->objects->source_by_path, pos) = alternate;
++ assert(odb->source_by_path);
++ kh_value(odb->source_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, alternate->path, depth + 1);
@@ odb.c: static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
-- strbuf_realpath(&objdirbuf, r->objects->alternates->path, 1);
-+ strbuf_realpath(&objdirbuf, odb->alternates->path, 1);
+- strbuf_realpath(&objdirbuf, r->objects->sources->path, 1);
++ strbuf_realpath(&objdirbuf, odb->sources->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
@@ odb.c: void add_to_alternates_memory(const char *reference)
'\n', NULL, 0);
}
-@@ odb.c: struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
+@@ odb.c: struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* alternate
*/
- alternate = xcalloc(1, sizeof(*alternate));
-+ alternate->odb = the_repository->objects;
- alternate->path = xstrdup(dir);
+ source = xcalloc(1, sizeof(*source));
++ source->odb = the_repository->objects;
+ source->path = xstrdup(dir);
/*
@@ odb.c: void prepare_alt_odb(struct repository *r)
@@ odb.c: void prepare_alt_odb(struct repository *r)
- link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
-- read_info_alternates(r, r->objects->alternates->path, 0);
-+ read_info_alternates(r->objects, r->objects->alternates->path, 0);
+- read_info_alternates(r, r->objects->sources->path, 0);
++ read_info_alternates(r->objects, r->objects->sources->path, 0);
r->objects->loaded_alternates = 1;
}
@@ odb.c: void assert_oid_type(const struct object_id *oid, enum object_type expect
## odb.h ##
@@ odb.h: struct repository;
- struct odb_alternate {
- struct odb_alternate *next;
+ struct odb_source {
+ struct odb_source *next;
-+ /* Object database that owns this alternate. */
++ /* Object database that owns this object source. */
+ struct object_database *odb;
+
/*
@@ repository.c: static void set_default_hash_algo(struct repository *repo)
ALLOC_ARRAY(repo->index, 1);
@@ repository.c: void repo_set_gitdir(struct repository *repo,
- if (!repo->objects->alternates) {
- CALLOC_ARRAY(repo->objects->alternates, 1);
-+ repo->objects->alternates->odb = repo->objects;
- repo->objects->alternates_tail = &repo->objects->alternates->next;
+ if (!repo->objects->sources) {
+ CALLOC_ARRAY(repo->objects->sources, 1);
++ repo->objects->sources->odb = repo->objects;
+ repo->objects->sources_tail = &repo->objects->sources->next;
}
- expand_base_dir(&repo->objects->alternates->path, o->object_dir,
+ expand_base_dir(&repo->objects->sources->path, o->object_dir,
5: 7ed8aaa8e94 < -: ----------- odb: get rid of `the_repository` in `find_odb()`
-: ----------- > 5: ca3b9e62e03 odb: get rid of `the_repository` in `find_odb()`
6: 3cad18408a7 = 6: 36c9802f66c odb: get rid of `the_repository` in `assert_oid_type()`
7: 2b69ee1249b ! 7: 7dcf630c701 odb: get rid of `the_repository` in `odb_mkstemp()`
@@ odb.c: int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
## odb.h ##
@@ odb.h: void odb_clear(struct object_database *o);
- struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
+ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
/*
- * Create a temporary file rooted in the object database directory, or
8: cd36a4906a9 ! 8: 2d3a4a958d7 odb: get rid of `the_repository` when handling alternates
@@ builtin/fsck.c: int cmd_fsck(int argc,
} else {
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next)
- fsck_object_dir(alternate->path);
+ for (source = the_repository->objects->sources; source; source = source->next)
+ fsck_object_dir(source->path);
@@ builtin/fsck.c: int cmd_fsck(int argc,
if (the_repository->settings.core_commit_graph) {
@@ builtin/fsck.c: int cmd_fsck(int argc,
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
+ for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
@@ builtin/fsck.c: int cmd_fsck(int argc,
@@ builtin/fsck.c: int cmd_fsck(int argc,
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
+ for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
@@ commit-graph.c: struct commit_graph *load_commit_graph_chain_fd_st(struct reposi
+ odb_prepare_alternates(r->objects);
for (i = 0; i < count; i++) {
- struct odb_alternate *alternate;
+ struct odb_source *source;
@@ commit-graph.c: static int prepare_commit_graph(struct repository *r)
if (!commit_graph_compatible(r))
return 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (alternate = r->objects->alternates;
- !r->objects->commit_graph && alternate;
- alternate = alternate->next)
+ for (source = r->objects->sources;
+ !r->objects->commit_graph && source;
+ source = source->next)
## loose.c ##
@@ loose.c: int repo_read_loose_object_map(struct repository *repo)
@@ loose.c: int repo_read_loose_object_map(struct repository *repo)
- prepare_alt_odb(repo);
+ odb_prepare_alternates(repo->objects);
- for (alternate = repo->objects->alternates; alternate; alternate = alternate->next) {
- if (load_one_loose_object_map(repo, alternate) < 0) {
+ for (source = repo->objects->sources; source; source = source->next) {
+ if (load_one_loose_object_map(repo, source) < 0) {
## object-file.c ##
@@ object-file.c: static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
- struct odb_alternate *alternate;
+ struct odb_source *source;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
- if (check_and_freshen_odb(alternate, oid, freshen))
+ for (source = the_repository->objects->sources->next; source; source = source->next) {
+ if (check_and_freshen_odb(source, oid, freshen))
return 1;
@@ object-file.c: static int stat_loose_object(struct repository *r, const struct object_id *oid,
- struct odb_alternate *alternate;
+ struct odb_source *source;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
- *path = odb_loose_path(alternate, &buf, oid);
+ for (source = r->objects->sources; source; source = source->next) {
+ *path = odb_loose_path(source, &buf, oid);
if (!lstat(*path, st))
@@ object-file.c: static int open_loose_object(struct repository *r,
int most_interesting_errno = ENOENT;
@@ object-file.c: static int open_loose_object(struct repository *r,
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
- *path = odb_loose_path(alternate, &buf, oid);
+ for (source = r->objects->sources; source; source = source->next) {
+ *path = odb_loose_path(source, &buf, oid);
fd = git_open(*path);
@@ object-file.c: static int quick_has_loose(struct repository *r,
{
- struct odb_alternate *alternate;
+ struct odb_source *source;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
- if (oidtree_contains(odb_loose_cache(alternate, oid), oid))
+ for (source = r->objects->sources; source; source = source->next) {
+ if (oidtree_contains(odb_loose_cache(source, oid), oid))
return 1;
@@ object-file.c: int for_each_loose_object(each_loose_object_fn cb, void *data,
{
- struct odb_alternate *alternate;
+ struct odb_source *source;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->alternates; alternate; alternate = alternate->next) {
- int r = for_each_loose_file_in_objdir(alternate->path, cb, NULL,
+ for (source = the_repository->objects->sources; source; source = source->next) {
+ int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
NULL, data);
## object-name.c ##
@@ odb.c: void add_to_alternates_file(const char *reference)
'\n', NULL, 0);
}
-@@ odb.c: struct odb_alternate *set_temporary_primary_odb(const char *dir, int will_destro
+@@ odb.c: struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
@@ odb.c: struct odb_alternate *set_temporary_primary_odb(const char *dir, int will
/*
* Make a new primary odb and link the old primary ODB in as an
-@@ odb.c: void restore_primary_odb(struct odb_alternate *restore_alt, const char *old_path
+@@ odb.c: void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
free_object_directory(cur_alt);
}
@@ odb.c: void restore_primary_odb(struct odb_alternate *restore_alt, const char *o
char *compute_alternate_path(const char *path, struct strbuf *err)
{
char *ref_git = NULL;
-@@ odb.c: struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
+@@ odb.c: struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(odb->repo);
+ odb_prepare_alternates(odb);
- for (alternate = odb->alternates; alternate; alternate = alternate->next) {
- strbuf_realpath(&odb_path_real, alternate->path, 1);
+ for (source = odb->sources; source; source = source->next) {
+ strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
@@ odb.c: int foreach_alt_odb(alt_odb_fn fn, void *cb)
- struct odb_alternate *alternate;
+ struct odb_source *alternate;
int r = 0;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
+ for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
r = fn(alternate, cb);
if (r)
@@ odb.c: int foreach_alt_odb(alt_odb_fn fn, void *cb)
@@ odb.c: int foreach_alt_odb(alt_odb_fn fn, void *cb)
- link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(odb, odb->alternate_db, PATH_SEP, NULL, 0);
-- read_info_alternates(r->objects, r->objects->alternates->path, 0);
+- read_info_alternates(r->objects, r->objects->sources->path, 0);
- r->objects->loaded_alternates = 1;
-+ read_info_alternates(odb, odb->alternates->path, 0);
++ read_info_alternates(odb, odb->sources->path, 0);
+ odb->loaded_alternates = 1;
}
@@ odb.c: int foreach_alt_odb(alt_odb_fn fn, void *cb)
+int odb_has_alternates(struct object_database *odb)
{
- prepare_alt_odb(r);
-- return !!r->objects->alternates->next;
+- return !!r->objects->sources->next;
+ odb_prepare_alternates(odb);
-+ return !!odb->alternates->next;
++ return !!odb->sources->next;
}
int obj_read_use_lock = 0;
@@ odb.h: struct oidtree;
+char *compute_alternate_path(const char *path, struct strbuf *err);
+
/*
- * The alternate is the part of the object database that stores the actual
+ * The source is the part of the object database that stores the actual
* objects. It thus encapsulates the logic to read and write the specific
-@@ odb.h: struct odb_alternate {
+@@ odb.h: struct odb_source {
char *path;
};
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
- typedef int alt_odb_fn(struct odb_alternate *, void *);
+ typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
@@ odb.h: struct object_database {
/*
* A list of alternate object directories loaded from the environment;
* this should not generally need to be accessed directly, but will
-- * populate the "alternates" list when prepare_alt_odb() is run.
-+ * populate the "alternates" list when odb_prepare_alternates() is run.
+- * populate the "sources" list when prepare_alt_odb() is run.
++ * populate the "sources" list when odb_prepare_alternates() is run.
*/
char *alternate_db;
-@@ odb.h: struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
+@@ odb.h: struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
int odb_mkstemp(struct object_database *odb,
struct strbuf *temp_filename, const char *pattern);
+/*
-+ * Prepare alternate object backends for the given database by reading
-+ * "objects/info/alternates" and opening the respective alternates.
++ * Prepare alternate object sources for the given database by reading
++ * "objects/info/alternates" and opening the respective sources.
+ */
+void odb_prepare_alternates(struct object_database *odb);
+
+/*
+ * Check whether the object database has any alternates. The primary object
-+ * backend does not count as alternate.
++ * source does not count as alternate.
+ */
+int odb_has_alternates(struct object_database *odb);
+
@@ odb.h: struct odb_alternate *odb_find_alternate(struct object_database *odb, con
+ const char *dir);
+
+/*
-+ * Add the directory to the in-memory list of alternates (along with any
++ * Add the directory to the in-memory list of alternate sources (along with any
+ * recursive alternates it points to), but do not modify the on-disk alternates
+ * file.
+ */
@@ packfile.c: static void prepare_packed_git(struct repository *r)
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (alternate = r->objects->alternates; alternate; alternate = alternate->next) {
- int local = (alternate == r->objects->alternates);
- prepare_multi_pack_index_one(r, alternate->path, local);
+ for (source = r->objects->sources; source; source = source->next) {
+ int local = (source == r->objects->sources);
+ prepare_multi_pack_index_one(r, source->path, local);
@@ packfile.c: void reprepare_packed_git(struct repository *r)
* the lifetime of the process.
*/
@@ packfile.c: void reprepare_packed_git(struct repository *r)
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
- for (alternate = r->objects->alternates; alternate; alternate = alternate->next)
- odb_clear_loose_cache(alternate);
+ for (source = r->objects->sources; source; source = source->next)
+ odb_clear_loose_cache(source);
## submodule.c ##
@@ submodule.c: int register_all_submodule_odb_as_alternates(void)
9: e69ccfe7434 ! 9: 320f73f70e0 odb: get rid of `the_repository` in `for_each()` functions
@@ diagnose.c
@@ diagnose.c: int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(r->objects->alternates, &buf);
+ dir_file_stats(r->objects->sources, &buf);
- foreach_alt_odb(dir_file_stats, &buf);
+ odb_for_each_alternate(r->objects, dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
@@ odb.c: static void read_alternate_refs(const char *path,
+ void *payload;
};
- static int refs_from_alternate_cb(struct odb_alternate *alternate,
+ static int refs_from_alternate_cb(struct odb_source *alternate,
- void *data)
+ void *payload)
{
@@ odb.c: static void read_alternate_refs(const char *path,
if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
-@@ odb.c: static int refs_from_alternate_cb(struct odb_alternate *alternate,
+@@ odb.c: static int refs_from_alternate_cb(struct odb_source *alternate,
goto out;
strbuf_setlen(&path, base_len);
@@ odb.c: static int refs_from_alternate_cb(struct odb_alternate *alternate,
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload)
{
- struct odb_alternate *alternate;
+ struct odb_source *alternate;
int r = 0;
- odb_prepare_alternates(the_repository->objects);
-- for (alternate = the_repository->objects->alternates->next; alternate; alternate = alternate->next) {
+- for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
- r = fn(alternate, cb);
+ odb_prepare_alternates(odb);
-+ for (alternate = odb->alternates->next; alternate; alternate = alternate->next) {
++ for (alternate = odb->sources->next; alternate; alternate = alternate->next) {
+ r = cb(alternate, payload);
if (r)
break;
}
## odb.h ##
-@@ odb.h: struct odb_alternate {
+@@ odb.h: struct odb_source {
char *path;
};
--typedef int alt_odb_fn(struct odb_alternate *, void *);
+-typedef int alt_odb_fn(struct odb_source *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
@@ odb.h: struct odb_alternate {
* object directory; returns the former primary object directory.
@@ odb.h: void odb_clear(struct object_database *o);
*/
- struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir);
+ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+/*
+ * Iterate through all alternates of the database and execute the provided
@@ odb.h: void odb_clear(struct object_database *o);
+ * function returns a non-zero value, in which case the value is bubbled up
+ * from the callback.
+ */
-+typedef int odb_for_each_alternate_fn(struct odb_alternate *, void *);
++typedef int odb_for_each_alternate_fn(struct odb_source *, void *);
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload);
+
10: 271ab001cd6 < -: ----------- odb: get rid of `the_repository` when handling the primary alternate
-: ----------- > 10: 6a5991f3c90 odb: get rid of `the_repository` when handling the primary source
11: cfa2d832fd6 ! 11: aa502131265 odb: get rid of `the_repository` when handling submodule alternates
@@ Metadata
Author: Patrick Steinhardt <ps@pks.im>
## Commit message ##
- odb: get rid of `the_repository` when handling submodule alternates
+ odb: get rid of `the_repository` when handling submodule sources
The "--recursive" flag for git-grep(1) allows users to grep for a string
across submodule boundaries. To make this work we add each submodule's
- object alternate to our own object database so that the objects can be
+ object sources to our own object database so that the objects can be
accessed directly.
The infrastructure for this depends on a global string list of submodule
paths. The caller is expected to call `add_submodule_odb_by_path()` for
- each alternate and the object database will then eventually register all
- submodule alternates via `do_oid_object_info_extended()` in case it
- isn't able to look up a specific object.
+ each source and the object database will then eventually register all
+ submodule sources via `do_oid_object_info_extended()` in case it isn't
+ able to look up a specific object.
This reliance on global state is of course suboptimal with regards to
our libification efforts.
- Refactor the logic so that the list of submodule alternates is instead
+ Refactor the logic so that the list of submodule sources is instead
tracked in the object database itself. This allows us to lose the
- condition of `r == the_repository` before registering submodule
- alternates as we only ever add submodule alternates to `the_repository`
- anyway. As such, behaviour before and after this refactoring should
- always be the same.
+ condition of `r == the_repository` before registering submodule sources
+ as we only ever add submodule sources to `the_repository` anyway. As
+ such, behaviour before and after this refactoring should always be the
+ same.
Rename the functions accordingly.
@@ builtin/grep.c: static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
-- add_submodule_odb_by_path(subrepo->objects->alternates->path);
-+ odb_add_submodule_alternate_by_path(the_repository->objects,
-+ subrepo->objects->alternates->path);
+- add_submodule_odb_by_path(subrepo->objects->sources->path);
++ odb_add_submodule_source_by_path(the_repository->objects,
++ subrepo->objects->sources->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
@@ odb.c
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
-@@ odb.c: struct odb_alternate *odb_find_alternate(struct object_database *odb, const char
- return alternate;
+@@ odb.c: struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
+ return source;
}
-+void odb_add_submodule_alternate_by_path(struct object_database *odb,
-+ const char *path)
++void odb_add_submodule_source_by_path(struct object_database *odb,
++ const char *path)
+{
-+ string_list_insert(&odb->submodule_alternate_paths, path);
++ string_list_insert(&odb->submodule_source_paths, path);
+}
+
static void fill_alternate_refs_command(struct child_process *cmd,
@@ odb.c: void disable_obj_read_lock(void)
+static int register_all_submodule_alternates(struct object_database *odb)
+{
-+ int ret = odb->submodule_alternate_paths.nr;
++ int ret = odb->submodule_source_paths.nr;
+
-+ for (size_t i = 0; i < odb->submodule_alternate_paths.nr; i++)
++ for (size_t i = 0; i < odb->submodule_source_paths.nr; i++)
+ odb_add_to_alternates_memory(odb,
-+ odb->submodule_alternate_paths.items[i].string);
++ odb->submodule_source_paths.items[i].string);
+ if (ret) {
-+ string_list_clear(&odb->submodule_alternate_paths, 0);
++ string_list_clear(&odb->submodule_source_paths, 0);
+ trace2_data_intmax("submodule", odb->repo,
+ "register_all_submodule_alternates/registered", ret);
+ if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
- * If any such ODBs exist, register them and try again.
+ * This might be an attempt at accessing a submodule object as
+ * if it were in main object store (having called
-+ * `odb_add_submodule_alternate_by_path()` on that submodule's
++ * `odb_add_submodule_source_by_path()` on that submodule's
+ * ODB). If any such ODBs exist, register them and try again.
*/
- if (r == the_repository &&
@@ odb.c: struct object_database *odb_new(struct repository *repo)
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
-+ string_list_init_dup(&o->submodule_alternate_paths);
++ string_list_init_dup(&o->submodule_source_paths);
return o;
}
@@ odb.c: void odb_clear(struct object_database *o)
o->packed_git = NULL;
hashmap_clear(&o->pack_map);
-+ string_list_clear(&o->submodule_alternate_paths, 0);
++ string_list_clear(&o->submodule_source_paths, 0);
}
## odb.h ##
@@
- #include "object.h"
#include "list.h"
#include "oidset.h"
+ #include "oidmap.h"
+#include "string-list.h"
#include "thread-utils.h"
@@ odb.h: struct object_database {
unsigned packed_git_initialized : 1;
+
+ /*
-+ * Submodule alternate paths that will be added as alternatives to
++ * Submodule source paths that will be added as additional sources to
+ * allow lookup of submodule objects via the main object database.
+ */
-+ struct string_list submodule_alternate_paths;
++ struct string_list submodule_source_paths;
};
struct object_database *odb_new(struct repository *repo);
-@@ odb.h: void odb_restore_primary_alternate(struct object_database *odb,
- struct odb_alternate *restore_alt,
- const char *old_path);
+@@ odb.h: void odb_restore_primary_source(struct object_database *odb,
+ struct odb_source *restore_source,
+ const char *old_path);
+/*
-+ * Call odb_add_submodule_alternate_by_path() to add the submodule at the given
++ * Call odb_add_submodule_source_by_path() to add the submodule at the given
+ * path to a list. The object stores of all submodules in that list will be
-+ * added as alternates in the object store when looking up objects.
++ * added as additional sources in the object store when looking up objects.
+ */
-+void odb_add_submodule_alternate_by_path(struct object_database *odb,
-+ const char *path);
++void odb_add_submodule_source_by_path(struct object_database *odb,
++ const char *path);
+
/*
* Iterate through all alternates of the database and execute the provided
@@ submodule-config.c: static void config_from_gitmodules(config_fn_t fn, struct re
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
-- add_submodule_odb_by_path(repo->objects->alternates->path);
-+ odb_add_submodule_alternate_by_path(the_repository->objects,
-+ repo->objects->alternates->path);
+- add_submodule_odb_by_path(repo->objects->sources->path);
++ odb_add_submodule_source_by_path(the_repository->objects,
++ repo->objects->sources->path);
} else {
goto out;
}
12: 9541cc16ed7 ! 12: a9fdf3fbb8b odb: trivial refactorings to get rid of `the_repository`
@@ odb.c
#include "git-compat-util.h"
#include "abspath.h"
#include "commit-graph.h"
-@@ odb.c: void odb_add_submodule_alternate_by_path(struct object_database *odb,
- string_list_insert(&odb->submodule_alternate_paths, path);
+@@ odb.c: void odb_add_submodule_source_by_path(struct object_database *odb,
+ string_list_insert(&odb->submodule_source_paths, path);
}
-static void fill_alternate_refs_command(struct child_process *cmd,
@@ odb.c: static void read_alternate_refs(const char *path,
warning(_("invalid line while parsing alternate refs: %s"),
line.buf);
break;
-@@ odb.c: static int refs_from_alternate_cb(struct odb_alternate *alternate,
+@@ odb.c: static int refs_from_alternate_cb(struct odb_source *alternate,
goto out;
strbuf_setlen(&path, base_len);
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, the_repository->hash_algo);
+ oidclr(oi->delta_base_oid, r->hash_algo);
- if (oi->type_name)
- strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
+ *oi->contentp = xmemdupz(co->buf, co->size);
+ oi->whence = OI_CACHED;
@@ odb.c: static int oid_object_info_convert(struct repository *r,
void *content;
int ret;
@@ odb.c: static int oid_object_info_convert(struct repository *r,
}
@@ odb.c: static int oid_object_info_convert(struct repository *r,
- if (type == -1)
- return -1;
+ struct strbuf outbuf = STRBUF_INIT;
+
if (type != OBJ_BLOB) {
- ret = convert_object_file(the_repository, &outbuf,
- the_hash_algo, input_algo,
13: c4b1c12476e ! 13: 3f0bdecc039 odb: rename `oid_object_info()`
@@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *
return 0;
## builtin/cat-file.c ##
-@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
+@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
switch (opt) {
case 't':
- oi.type_name = &sb;
+ oi.typep = &type;
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
- if (sb.len) {
- printf("%s\n", sb.buf);
-@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
+ printf("%s\n", type_name(type));
+ ret = 0;
+@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
oi.contentp = (void**)&buf;
}
@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const
die("git cat-file: could not get object info");
if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
-@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
+@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
/* else fallthrough */
case 'p':
@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const
if (type < 0)
die("Not a valid object name %s", obj_name);
-@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
+@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
if (exp_type_id == OBJ_BLOB) {
struct object_id blob_oid;
@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const
char *buffer = repo_read_object_file(the_repository,
&oid,
&type,
-@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
+@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
} else
oidcpy(&blob_oid, &oid);
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, r->hash_algo);
+ oidclr(oi->delta_base_oid, odb->repo->hash_algo);
- if (oi->type_name)
- strbuf_addstr(oi->type_name, type_name(co->type));
if (oi->contentp)
+ *oi->contentp = xmemdupz(co->buf, co->size);
+ oi->whence = OI_CACHED;
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
}
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
}
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
- * `odb_add_submodule_alternate_by_path()` on that submodule's
+ * `odb_add_submodule_source_by_path()` on that submodule's
* ODB). If any such ODBs exist, register them and try again.
*/
- if (register_all_submodule_alternates(r->objects))
@@ odb.h: void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
-+/* Compatibility wrappers, to be removed once Git 2.50 has been released. */
++/* Compatibility wrappers, to be removed once Git 2.51 has been released. */
+#include "repository.h"
+
+static inline int oid_object_info_extended(struct repository *r,
14: eeb31a420b0 ! 14: 644cd847670 odb: rename `repo_read_object_file()`
@@ builtin/cat-file.c: static int filter_object(const char *path, unsigned mode,
if (!*buf)
return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path);
-@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
+@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
ret = stream_blob(&oid);
goto cleanup;
}
@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const
if (!buf)
die("Cannot read object %s", obj_name);
-@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
+@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
struct object_id blob_oid;
if (odb_read_object_info(the_repository->objects,
&oid, NULL) == OBJ_TAG) {
15: ab652070bc6 ! 15: 53812350b40 odb: rename `has_object()`
@@ builtin/backfill.c: static int fill_missing_blobs(const char *path UNUSED,
## builtin/cat-file.c ##
-@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
+@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
goto cleanup;
case 'e':
16: 580bfe7bc24 = 16: bcbfd390398 odb: rename `pretend_object_file()`
17: b23d48d216a ! 17: 77f7e41f83f odb: rename `read_object_with_reference()`
@@ Documentation/user-manual.adoc: Now, for the meat:
the source.
## builtin/cat-file.c ##
-@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
+@@ builtin/cat-file.c: static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
* fall-back to the usual case.
*/
}
@@ odb.h: enum for_each_object_flags {
- unsigned long *size,
- struct object_id *oid_ret);
-
- /* Compatibility wrappers, to be removed once Git 2.50 has been released. */
+ /* Compatibility wrappers, to be removed once Git 2.51 has been released. */
#include "repository.h"
---
base-commit: 7014b55638da979331baf8dc31c4e1d697cf2d67
change-id: 20250505-pks-object-store-wo-the-repository-9c6cbdf8d4b1
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v4 01/17] object-store: rename `raw_object_store` to `object_database`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-04 8:55 ` Toon Claes
2025-06-02 10:27 ` [PATCH v4 02/17] object-store: rename `object_directory` to `odb_source` Patrick Steinhardt
` (16 subsequent siblings)
17 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The `raw_object_store` structure is the central entry point for reading
and writing objects in a repository. The main purpose of this structure
is to manage object directories and provide an interface to access and
write objects in those object directories.
Right now, many of the functions associated with the raw object store
implicitly rely on `the_repository` to get access to its `objects`
pointer, which is the `raw_object_store`. As we want to generally get
rid of using `the_repository` across our codebase we will have to
convert this implicit dependency on this global variable into an
explicit parameter.
This conversion can be done by simply passing in an explicit pointer to
a repository and then using its `->objects` pointer. But there is a
second effort underway, which is to make the object subsystem more
selfcontained so that we can eventually have pluggable object backends.
As such, passing in a repository wouldn't make a ton of sense, and the
goal is to convert the object store interfaces such that we always pass
in a reference to the `raw_object_store` instead.
This will expose the `raw_object_store` type to a lot more callers
though, which surfaces that this type is named somewhat awkwardly. The
"raw_" prefix makes readers wonder whether there is a non-raw variant of
the object store, but there isn't. Furthermore, we nowadays want to name
functions in a way that they can be clearly attributed to a specific
subsystem, but calling them e.g. `raw_object_store_has_object()` is just
too unwieldy, even when dropping the "raw_" prefix.
Instead, rename the structure to `object_database`. This term is already
used a lot throughout our codebase, and it cannot easily be mistaken for
"object directories", either. Furthermore, its acronym ODB is already
well-known and works well as part of a function's name, like for example
`odb_has_object()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
commit-graph.c | 2 +-
commit-graph.h | 4 ++--
object-store.c | 12 ++++++------
object-store.h | 11 ++++++++---
packfile.c | 2 +-
packfile.h | 4 ++--
repository.c | 4 ++--
repository.h | 4 ++--
8 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index ad3943b6906..905fcbdf0e8 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -829,7 +829,7 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
return NULL;
}
-void close_commit_graph(struct raw_object_store *o)
+void close_commit_graph(struct object_database *o)
{
if (!o->commit_graph)
return;
diff --git a/commit-graph.h b/commit-graph.h
index 13f662827d4..20d38c100ce 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -26,7 +26,7 @@ void git_test_write_commit_graph_or_die(void);
struct commit;
struct bloom_filter_settings;
struct repository;
-struct raw_object_store;
+struct object_database;
struct string_list;
char *get_commit_graph_filename(struct object_directory *odb);
@@ -186,7 +186,7 @@ int write_commit_graph(struct object_directory *odb,
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
-void close_commit_graph(struct raw_object_store *);
+void close_commit_graph(struct object_database *);
void free_commit_graph(struct commit_graph *);
/*
diff --git a/object-store.c b/object-store.c
index 58cde0313a5..f4e8f99d90f 100644
--- a/object-store.c
+++ b/object-store.c
@@ -44,7 +44,7 @@ struct cached_object_entry {
} value;
};
-static const struct cached_object *find_cached_object(struct raw_object_store *object_store,
+static const struct cached_object *find_cached_object(struct object_database *object_store,
const struct object_id *oid)
{
static const struct cached_object empty_tree = {
@@ -86,7 +86,7 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
/*
* Return non-zero iff the path is usable as an alternate object database.
*/
-static int alt_odb_usable(struct raw_object_store *o,
+static int alt_odb_usable(struct object_database *o,
struct strbuf *path,
const char *normalized_objdir, khiter_t *pos)
{
@@ -950,9 +950,9 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct raw_object_store *raw_object_store_new(void)
+struct object_database *odb_new(void)
{
- struct raw_object_store *o = xmalloc(sizeof(*o));
+ struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
INIT_LIST_HEAD(&o->packed_git_mru);
@@ -961,7 +961,7 @@ struct raw_object_store *raw_object_store_new(void)
return o;
}
-static void free_object_directories(struct raw_object_store *o)
+static void free_object_directories(struct object_database *o)
{
while (o->odb) {
struct object_directory *next;
@@ -974,7 +974,7 @@ static void free_object_directories(struct raw_object_store *o)
o->odb_by_path = NULL;
}
-void raw_object_store_clear(struct raw_object_store *o)
+void odb_clear(struct object_database *o)
{
FREE_AND_NULL(o->alternate_db);
diff --git a/object-store.h b/object-store.h
index c5890085352..a3be27d1171 100644
--- a/object-store.h
+++ b/object-store.h
@@ -87,7 +87,12 @@ struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
-struct raw_object_store {
+/*
+ * The object database encapsulates access to objects in a repository. It
+ * manages one or more backends that store the actual objects which are
+ * configured via alternates.
+ */
+struct object_database {
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -169,8 +174,8 @@ struct raw_object_store {
unsigned packed_git_initialized : 1;
};
-struct raw_object_store *raw_object_store_new(void);
-void raw_object_store_clear(struct raw_object_store *o);
+struct object_database *odb_new(void);
+void odb_clear(struct object_database *o);
/*
* Create a temporary file rooted in the object database directory, or
diff --git a/packfile.c b/packfile.c
index 70c7208f027..c735b4d0135 100644
--- a/packfile.c
+++ b/packfile.c
@@ -359,7 +359,7 @@ void close_pack(struct packed_git *p)
oidset_clear(&p->bad_objects);
}
-void close_object_store(struct raw_object_store *o)
+void close_object_store(struct object_database *o)
{
struct packed_git *p;
diff --git a/packfile.h b/packfile.h
index 3a3c77cf05a..826eb7f475f 100644
--- a/packfile.h
+++ b/packfile.h
@@ -183,12 +183,12 @@ int close_pack_fd(struct packed_git *p);
uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
-struct raw_object_store;
+struct object_database;
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
void close_pack_windows(struct packed_git *);
void close_pack(struct packed_git *);
-void close_object_store(struct raw_object_store *o);
+void close_object_store(struct object_database *o);
void unuse_pack(struct pack_window **);
void clear_delta_base_cache(void);
struct packed_git *add_packed_git(struct repository *r, const char *path,
diff --git a/repository.c b/repository.c
index 9b3d6665fc6..07757e6e0c9 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = raw_object_store_new();
+ repo->objects = odb_new();
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -374,7 +374,7 @@ void repo_clear(struct repository *repo)
FREE_AND_NULL(repo->worktree);
FREE_AND_NULL(repo->submodule_prefix);
- raw_object_store_clear(repo->objects);
+ odb_clear(repo->objects);
FREE_AND_NULL(repo->objects);
parsed_object_pool_clear(repo->parsed_objects);
diff --git a/repository.h b/repository.h
index c4c92b2ab9c..3a5ef9c781e 100644
--- a/repository.h
+++ b/repository.h
@@ -9,7 +9,7 @@ struct git_hash_algo;
struct index_state;
struct lock_file;
struct pathspec;
-struct raw_object_store;
+struct object_database;
struct submodule_cache;
struct promisor_remote_config;
struct remote_state;
@@ -47,7 +47,7 @@ struct repository {
/*
* Holds any information related to accessing the raw object content.
*/
- struct raw_object_store *objects;
+ struct object_database *objects;
/*
* All objects in this repository that have been parsed. This structure
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v4 01/17] object-store: rename `raw_object_store` to `object_database`
2025-06-02 10:27 ` [PATCH v4 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
@ 2025-06-04 8:55 ` Toon Claes
2025-06-04 11:52 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Toon Claes @ 2025-06-04 8:55 UTC (permalink / raw)
To: Patrick Steinhardt, git; +Cc: Derrick Stolee, Junio C Hamano, Justin Tobler
Patrick Steinhardt <ps@pks.im> writes:
> The `raw_object_store` structure is the central entry point for reading
> and writing objects in a repository. The main purpose of this structure
> is to manage object directories and provide an interface to access and
> write objects in those object directories.
>
> Right now, many of the functions associated with the raw object store
> implicitly rely on `the_repository` to get access to its `objects`
> pointer, which is the `raw_object_store`. As we want to generally get
> rid of using `the_repository` across our codebase we will have to
> convert this implicit dependency on this global variable into an
> explicit parameter.
>
> This conversion can be done by simply passing in an explicit pointer to
> a repository and then using its `->objects` pointer. But there is a
> second effort underway, which is to make the object subsystem more
> selfcontained so that we can eventually have pluggable object backends.
> As such, passing in a repository wouldn't make a ton of sense, and the
> goal is to convert the object store interfaces such that we always pass
> in a reference to the `raw_object_store` instead.
>
> This will expose the `raw_object_store` type to a lot more callers
> though, which surfaces that this type is named somewhat awkwardly. The
> "raw_" prefix makes readers wonder whether there is a non-raw variant of
> the object store, but there isn't. Furthermore, we nowadays want to name
> functions in a way that they can be clearly attributed to a specific
> subsystem, but calling them e.g. `raw_object_store_has_object()` is just
> too unwieldy, even when dropping the "raw_" prefix.
>
> Instead, rename the structure to `object_database`. This term is already
> used a lot throughout our codebase, and it cannot easily be mistaken for
> "object directories", either. Furthermore, its acronym ODB is already
> well-known and works well as part of a function's name, like for example
> `odb_has_object()`.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> commit-graph.c | 2 +-
> commit-graph.h | 4 ++--
> object-store.c | 12 ++++++------
> object-store.h | 11 ++++++++---
> packfile.c | 2 +-
> packfile.h | 4 ++--
> repository.c | 4 ++--
> repository.h | 4 ++--
> 8 files changed, 24 insertions(+), 19 deletions(-)
>
> diff --git a/commit-graph.c b/commit-graph.c
> index ad3943b6906..905fcbdf0e8 100644
> --- a/commit-graph.c
> +++ b/commit-graph.c
> @@ -829,7 +829,7 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
> return NULL;
> }
>
> -void close_commit_graph(struct raw_object_store *o)
> +void close_commit_graph(struct object_database *o)
> {
> if (!o->commit_graph)
> return;
> diff --git a/commit-graph.h b/commit-graph.h
> index 13f662827d4..20d38c100ce 100644
> --- a/commit-graph.h
> +++ b/commit-graph.h
> @@ -26,7 +26,7 @@ void git_test_write_commit_graph_or_die(void);
> struct commit;
> struct bloom_filter_settings;
> struct repository;
> -struct raw_object_store;
> +struct object_database;
> struct string_list;
>
> char *get_commit_graph_filename(struct object_directory *odb);
> @@ -186,7 +186,7 @@ int write_commit_graph(struct object_directory *odb,
>
> int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
>
> -void close_commit_graph(struct raw_object_store *);
> +void close_commit_graph(struct object_database *);
> void free_commit_graph(struct commit_graph *);
>
> /*
> diff --git a/object-store.c b/object-store.c
> index 58cde0313a5..f4e8f99d90f 100644
> --- a/object-store.c
> +++ b/object-store.c
> @@ -44,7 +44,7 @@ struct cached_object_entry {
> } value;
> };
>
> -static const struct cached_object *find_cached_object(struct raw_object_store *object_store,
> +static const struct cached_object *find_cached_object(struct object_database *object_store,
> const struct object_id *oid)
> {
> static const struct cached_object empty_tree = {
> @@ -86,7 +86,7 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
> /*
> * Return non-zero iff the path is usable as an alternate object database.
> */
> -static int alt_odb_usable(struct raw_object_store *o,
> +static int alt_odb_usable(struct object_database *o,
> struct strbuf *path,
> const char *normalized_objdir, khiter_t *pos)
> {
> @@ -950,9 +950,9 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
> type_name(expect));
> }
>
> -struct raw_object_store *raw_object_store_new(void)
> +struct object_database *odb_new(void)
> {
> - struct raw_object_store *o = xmalloc(sizeof(*o));
> + struct object_database *o = xmalloc(sizeof(*o));
>
> memset(o, 0, sizeof(*o));
> INIT_LIST_HEAD(&o->packed_git_mru);
> @@ -961,7 +961,7 @@ struct raw_object_store *raw_object_store_new(void)
> return o;
> }
>
> -static void free_object_directories(struct raw_object_store *o)
> +static void free_object_directories(struct object_database *o)
> {
> while (o->odb) {
> struct object_directory *next;
> @@ -974,7 +974,7 @@ static void free_object_directories(struct raw_object_store *o)
> o->odb_by_path = NULL;
> }
>
> -void raw_object_store_clear(struct raw_object_store *o)
> +void odb_clear(struct object_database *o)
> {
> FREE_AND_NULL(o->alternate_db);
>
> diff --git a/object-store.h b/object-store.h
> index c5890085352..a3be27d1171 100644
> --- a/object-store.h
> +++ b/object-store.h
> @@ -87,7 +87,12 @@ struct packed_git;
> struct multi_pack_index;
> struct cached_object_entry;
>
> -struct raw_object_store {
> +/*
> + * The object database encapsulates access to objects in a repository. It
> + * manages one or more backends that store the actual objects which are
> + * configured via alternates.
This still uses /old/ terminology. I think the "backend" should be
called "source", and we can keep the "alternates"?
--
Cheers,
Toon
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v4 01/17] object-store: rename `raw_object_store` to `object_database`
2025-06-04 8:55 ` Toon Claes
@ 2025-06-04 11:52 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-04 11:52 UTC (permalink / raw)
To: Toon Claes; +Cc: git, Derrick Stolee, Junio C Hamano, Justin Tobler
On Wed, Jun 04, 2025 at 10:55:40AM +0200, Toon Claes wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/object-store.h b/object-store.h
> > index c5890085352..a3be27d1171 100644
> > --- a/object-store.h
> > +++ b/object-store.h
> > @@ -87,7 +87,12 @@ struct packed_git;
> > struct multi_pack_index;
> > struct cached_object_entry;
> >
> > -struct raw_object_store {
> > +/*
> > + * The object database encapsulates access to objects in a repository. It
> > + * manages one or more backends that store the actual objects which are
> > + * configured via alternates.
>
> This still uses /old/ terminology. I think the "backend" should be
> called "source", and we can keep the "alternates"?
The term "source" doesn't yet exist in this commit. The next commit
touches the comment, but _that_ commit still uses the old "alternate"
term to talk about the sources. It's correct to say that those are
configured via alternates, but the alternates do configure sources in
the ODB indeed.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v4 02/17] object-store: rename `object_directory` to `odb_source`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-04 13:24 ` Toon Claes
2025-06-02 10:27 ` [PATCH v4 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
` (15 subsequent siblings)
17 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The `object_directory` structure is used as an access point for a single
object directory like ".git/objects". While the structure isn't yet
fully self-contained, the intent is for it to eventually contain all
information required to access objects in one specific location.
While the name "object directory" is a good fit for now, this will
change over time as we continue with the agenda to make pluggable object
databases a thing. Eventually, objects may not be accessed via any kind
of directory at all anymore, but they could instead be backed by any
kind of durable storage mechanism. While it seems quite far-fetched for
now, it is thinkable that eventually this might even be some form of a
database, for example.
As such, the current name of this structure will become worse over time
as we evolve into the direction of pluggable ODBs. Immediate next steps
will start to carve out proper self-contained object directories, which
requires us to pass in these object directories as parameters. Based on
our modern naming schema this means that those functions should then be
named after their subsystem, which means that we would start to bake the
current name into the codebase more and more.
Let's preempt this by renaming the structure. There have been a couple
alternatives that were discussed:
- `odb_backend` was discarded because it led to the association that
one object database has a single backend, but the model is that one
alternate has one backend. Furthermore, "backend" is more about the
actual backing implementation and less about the high-level concept.
- `odb_alternate` was discarded because it is a bit of a stretch to
also call the main object directory an "alternate".
Instead, pick `odb_source` as the new name. It makes it sufficiently
clear that there can be multiple sources and does not cause confusion
when mixed with the already-existing "alternate" terminology.
In the future, this change allows us to easily introduce for example a
`odb_files_source` and other format-specific implementations.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 18 +++----
builtin/count-objects.c | 4 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 14 ++---
builtin/gc.c | 14 ++---
builtin/grep.c | 2 +-
builtin/multi-pack-index.c | 4 +-
builtin/submodule--helper.c | 6 +--
bundle.c | 2 +-
commit-graph.c | 94 +++++++++++++++++-----------------
commit-graph.h | 14 ++---
diagnose.c | 8 +--
http-walker.c | 2 +-
http.c | 4 +-
loose.c | 42 +++++++--------
midx.c | 6 +--
object-file.c | 80 ++++++++++++++---------------
object-file.h | 8 +--
object-name.c | 6 +--
object-store.c | 122 ++++++++++++++++++++++----------------------
object-store.h | 38 +++++++++-----
packfile.c | 16 +++---
path.c | 2 +-
refs.c | 2 +-
repository.c | 14 ++---
submodule-config.c | 2 +-
t/helper/test-read-graph.c | 6 +--
tmp-objdir.c | 24 ++++-----
28 files changed, 284 insertions(+), 272 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index a783a86e797..98a84315342 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb = NULL;
+ struct odb_source *source = NULL;
char *graph_name;
char *chain_name;
enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE;
@@ -101,9 +101,9 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- odb = find_odb(the_repository, opts.obj_dir);
- graph_name = get_commit_graph_filename(odb);
- chain_name = get_commit_graph_chain_filename(odb);
+ source = find_odb(the_repository, opts.obj_dir);
+ graph_name = get_commit_graph_filename(source);
+ chain_name = get_commit_graph_chain_filename(source);
if (open_commit_graph(graph_name, &fd, &st))
opened = OPENED_GRAPH;
else if (errno != ENOENT)
@@ -120,7 +120,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opened == OPENED_NONE)
return 0;
else if (opened == OPENED_GRAPH)
- graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb);
+ graph = load_commit_graph_one_fd_st(the_repository, fd, &st, source);
else
graph = load_commit_graph_chain_fd_st(the_repository, fd, &st,
&incomplete_chain);
@@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
struct string_list pack_indexes = STRING_LIST_INIT_DUP;
struct strbuf buf = STRBUF_INIT;
struct oidset commits = OIDSET_INIT;
- struct object_directory *odb = NULL;
+ struct odb_source *source = NULL;
int result = 0;
enum commit_graph_write_flags flags = 0;
struct progress *progress = NULL;
@@ -289,10 +289,10 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- odb = find_odb(the_repository, opts.obj_dir);
+ source = find_odb(the_repository, opts.obj_dir);
if (opts.reachable) {
- if (write_commit_graph_reachable(odb, flags, &write_opts))
+ if (write_commit_graph_reachable(source, flags, &write_opts))
result = 1;
goto cleanup;
}
@@ -318,7 +318,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
stop_progress(&progress);
}
- if (write_commit_graph(odb,
+ if (write_commit_graph(source,
opts.stdin_packs ? &pack_indexes : NULL,
opts.stdin_commits ? &commits : NULL,
flags,
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index a88c0c9c09a..58e0af433d1 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -80,10 +80,10 @@ static int count_cruft(const char *basename UNUSED, const char *path,
return 0;
}
-static int print_alternate(struct object_directory *odb, void *data UNUSED)
+static int print_alternate(struct odb_source *alternate, void *data UNUSED)
{
printf("alternate: ");
- quote_c_style(odb->path, NULL, stdout, 0);
+ quote_c_style(alternate->path, NULL, stdout, 0);
putchar('\n');
return 0;
}
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 40a0e8d2443..a890e2864d1 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2653,7 +2653,7 @@ int cmd_fetch(int argc,
commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
trace2_region_enter("fetch", "write-commit-graph", the_repository);
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->sources,
commit_graph_flags,
NULL);
trace2_region_leave("fetch", "write-commit-graph", the_repository);
diff --git a/builtin/fsck.c b/builtin/fsck.c
index e7d96a9c8ea..6e1474f63d5 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -956,7 +956,7 @@ int cmd_fsck(int argc,
struct repository *repo UNUSED)
{
int i;
- struct object_directory *odb;
+ struct odb_source *source;
/* fsck knows how to handle missing promisor objects */
fetch_if_missing = 0;
@@ -998,8 +998,8 @@ int cmd_fsck(int argc,
mark_packed_for_connectivity, NULL, 0);
} else {
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next)
- fsck_object_dir(odb->path);
+ for (source = the_repository->objects->sources; source; source = source->next)
+ fsck_object_dir(source->path);
if (check_full) {
struct packed_git *p;
@@ -1109,11 +1109,11 @@ int cmd_fsck(int argc,
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
strvec_pushl(&commit_graph_verify.args, "commit-graph",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", source->path, NULL);
if (show_progress)
strvec_push(&commit_graph_verify.args, "--progress");
else
@@ -1127,11 +1127,11 @@ int cmd_fsck(int argc,
struct child_process midx_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", source->path, NULL);
if (show_progress)
strvec_push(&midx_verify.args, "--progress");
else
diff --git a/builtin/gc.c b/builtin/gc.c
index e33ba946e43..50a09eb07e3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1018,7 +1018,7 @@ int cmd_gc(int argc,
}
if (the_repository->settings.gc_write_commit_graph == 1)
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->sources,
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
NULL);
@@ -1271,7 +1271,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
if (loose_object_auto_limit < 0)
return 1;
- return for_each_loose_file_in_objdir(the_repository->objects->odb->path,
+ return for_each_loose_file_in_objdir(the_repository->objects->sources->path,
loose_object_count,
NULL, NULL, &count);
}
@@ -1306,7 +1306,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
* Do not start pack-objects process
* if there are no loose objects.
*/
- if (!for_each_loose_file_in_objdir(r->objects->odb->path,
+ if (!for_each_loose_file_in_objdir(r->objects->sources->path,
bail_on_loose,
NULL, NULL, NULL))
return 0;
@@ -1318,7 +1318,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
strvec_push(&pack_proc.args, "--quiet");
else
strvec_push(&pack_proc.args, "--no-quiet");
- strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
+ strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->sources->path);
pack_proc.in = -1;
@@ -1346,7 +1346,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
else if (data.batch_size > 0)
data.batch_size--; /* Decrease for equality on limit. */
- for_each_loose_file_in_objdir(r->objects->odb->path,
+ for_each_loose_file_in_objdir(r->objects->sources->path,
write_loose_object_to_stdin,
NULL,
NULL,
@@ -1611,7 +1611,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
int result = 0;
struct lock_file lk;
struct repository *r = the_repository;
- char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path);
+ char *lock_path = xstrfmt("%s/maintenance", r->objects->sources->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
/*
@@ -3083,7 +3083,7 @@ static int update_background_schedule(const struct maintenance_start_opts *opts,
unsigned int i;
int result = 0;
struct lock_file lk;
- char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path);
+ char *lock_path = xstrfmt("%s/schedule", the_repository->objects->sources->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
if (errno == EEXIST)
diff --git a/builtin/grep.c b/builtin/grep.c
index 3ce574a605b..76b1938bba5 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,7 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->odb->path);
+ add_submodule_odb_by_path(subrepo->objects->sources->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 69a97507324..f55bf53da83 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -294,8 +294,8 @@ int cmd_multi_pack_index(int argc,
if (the_repository &&
the_repository->objects &&
- the_repository->objects->odb)
- opts.object_dir = xstrdup(the_repository->objects->odb->path);
+ the_repository->objects->sources)
+ opts.object_dir = xstrdup(the_repository->objects->sources->path);
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 53da2116ddf..758bc6d0f24 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1582,7 +1582,7 @@ static const char alternate_error_advice[] = N_(
);
static int add_possible_reference_from_superproject(
- struct object_directory *odb, void *sas_cb)
+ struct odb_source *alt_odb, void *sas_cb)
{
struct submodule_alternate_setup *sas = sas_cb;
size_t len;
@@ -1591,12 +1591,12 @@ static int add_possible_reference_from_superproject(
* If the alternate object store is another repository, try the
* standard layout with .git/(modules/<name>)+/objects
*/
- if (strip_suffix(odb->path, "/objects", &len)) {
+ if (strip_suffix(alt_odb->path, "/objects", &len)) {
struct repository alternate;
char *sm_alternate;
struct strbuf sb = STRBUF_INIT;
struct strbuf err = STRBUF_INIT;
- strbuf_add(&sb, odb->path, len);
+ strbuf_add(&sb, alt_odb->path, len);
if (repo_init(&alternate, sb.buf, NULL) < 0)
die(_("could not get a repository handle for gitdir '%s'"),
diff --git a/bundle.c b/bundle.c
index b0a3fee2efa..2ce7525f90d 100644
--- a/bundle.c
+++ b/bundle.c
@@ -233,7 +233,7 @@ int verify_bundle(struct repository *r,
.quiet = 1,
};
- if (!r || !r->objects || !r->objects->odb)
+ if (!r || !r->objects || !r->objects->sources)
return error(_("need a repository to verify a bundle"));
for (i = 0; i < p->nr; i++) {
diff --git a/commit-graph.c b/commit-graph.c
index 905fcbdf0e8..12d32cdad1d 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -37,7 +37,7 @@ void git_test_write_commit_graph_or_die(void)
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- if (write_commit_graph_reachable(the_repository->objects->odb,
+ if (write_commit_graph_reachable(the_repository->objects->sources,
flags, NULL))
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
}
@@ -191,21 +191,21 @@ static int commit_gen_cmp(const void *va, const void *vb)
return 0;
}
-char *get_commit_graph_filename(struct object_directory *obj_dir)
+char *get_commit_graph_filename(struct odb_source *source)
{
- return xstrfmt("%s/info/commit-graph", obj_dir->path);
+ return xstrfmt("%s/info/commit-graph", source->path);
}
-static char *get_split_graph_filename(struct object_directory *odb,
+static char *get_split_graph_filename(struct odb_source *source,
const char *oid_hex)
{
- return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb->path,
+ return xstrfmt("%s/info/commit-graphs/graph-%s.graph", source->path,
oid_hex);
}
-char *get_commit_graph_chain_filename(struct object_directory *odb)
+char *get_commit_graph_chain_filename(struct odb_source *source)
{
- return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
+ return xstrfmt("%s/info/commit-graphs/commit-graph-chain", source->path);
}
static struct commit_graph *alloc_commit_graph(void)
@@ -250,7 +250,7 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb)
+ struct odb_source *source)
{
void *graph_map;
size_t graph_size;
@@ -269,7 +269,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
ret = parse_commit_graph(&r->settings, graph_map, graph_size);
if (ret)
- ret->odb = odb;
+ ret->odb_source = source;
else
munmap(graph_map, graph_size);
@@ -487,7 +487,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
static struct commit_graph *load_commit_graph_one(struct repository *r,
const char *graph_file,
- struct object_directory *odb)
+ struct odb_source *source)
{
struct stat st;
@@ -498,7 +498,7 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
if (!open_ok)
return NULL;
- g = load_commit_graph_one_fd_st(r, fd, &st, odb);
+ g = load_commit_graph_one_fd_st(r, fd, &st, source);
if (g)
g->filename = xstrdup(graph_file);
@@ -507,10 +507,10 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
}
static struct commit_graph *load_commit_graph_v1(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- char *graph_name = get_commit_graph_filename(odb);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ char *graph_name = get_commit_graph_filename(source);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
free(graph_name);
return g;
@@ -652,7 +652,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
prepare_alt_odb(r);
for (i = 0; i < count; i++) {
- struct object_directory *odb;
+ struct odb_source *source;
if (strbuf_getline_lf(&line, fp) == EOF)
break;
@@ -665,9 +665,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
valid = 0;
- for (odb = r->objects->odb; odb; odb = odb->next) {
- char *graph_name = get_split_graph_filename(odb, line.buf);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ for (source = r->objects->sources; source; source = source->next) {
+ char *graph_name = get_split_graph_filename(source, line.buf);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
free(graph_name);
@@ -701,9 +701,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
static struct commit_graph *load_commit_graph_chain(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- char *chain_file = get_commit_graph_chain_filename(odb);
+ char *chain_file = get_commit_graph_chain_filename(source);
struct stat st;
int fd;
struct commit_graph *g = NULL;
@@ -719,24 +719,24 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
}
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- struct commit_graph *g = load_commit_graph_v1(r, odb);
+ struct commit_graph *g = load_commit_graph_v1(r, source);
if (!g)
- g = load_commit_graph_chain(r, odb);
+ g = load_commit_graph_chain(r, source);
return g;
}
static void prepare_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
if (r->objects->commit_graph)
return;
- r->objects->commit_graph = read_commit_graph_one(r, odb);
+ r->objects->commit_graph = read_commit_graph_one(r, source);
}
/*
@@ -747,7 +747,7 @@ static void prepare_commit_graph_one(struct repository *r,
*/
static int prepare_commit_graph(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_source *source;
/*
* Early return if there is no git dir or if the commit graph is
@@ -779,10 +779,10 @@ static int prepare_commit_graph(struct repository *r)
return 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb;
- !r->objects->commit_graph && odb;
- odb = odb->next)
- prepare_commit_graph_one(r, odb);
+ for (source = r->objects->sources;
+ !r->objects->commit_graph && source;
+ source = source->next)
+ prepare_commit_graph_one(r, source);
return !!r->objects->commit_graph;
}
@@ -1137,7 +1137,7 @@ struct packed_commit_list {
struct write_commit_graph_context {
struct repository *r;
- struct object_directory *odb;
+ struct odb_source *odb_source;
char *graph_name;
struct oid_array oids;
struct packed_commit_list commits;
@@ -1870,7 +1870,7 @@ static int add_ref_to_set(const char *refname UNUSED,
return 0;
}
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_source *source,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts)
{
@@ -1890,7 +1890,7 @@ int write_commit_graph_reachable(struct object_directory *odb,
stop_progress(&data.progress);
- result = write_commit_graph(odb, NULL, &commits,
+ result = write_commit_graph(source, NULL, &commits,
flags, opts);
oidset_clear(&commits);
@@ -1906,7 +1906,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
int dirlen;
int ret = 0;
- strbuf_addf(&packname, "%s/pack/", ctx->odb->path);
+ strbuf_addf(&packname, "%s/pack/", ctx->odb_source->path);
dirlen = packname.len;
if (ctx->report_progress) {
strbuf_addf(&progress_title,
@@ -2060,10 +2060,10 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
strbuf_addf(&tmp_file,
"%s/info/commit-graphs/tmp_graph_XXXXXX",
- ctx->odb->path);
+ ctx->odb_source->path);
ctx->graph_name = strbuf_detach(&tmp_file, NULL);
} else {
- ctx->graph_name = get_commit_graph_filename(ctx->odb);
+ ctx->graph_name = get_commit_graph_filename(ctx->odb_source);
}
if (safe_create_leading_directories(the_repository, ctx->graph_name)) {
@@ -2073,7 +2073,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
if (ctx->split) {
- char *lock_name = get_commit_graph_chain_filename(ctx->odb);
+ char *lock_name = get_commit_graph_chain_filename(ctx->odb_source);
hold_lock_file_for_update_mode(&lk, lock_name,
LOCK_DIE_ON_ERROR, 0444);
@@ -2161,7 +2161,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
char *new_base_hash = xstrdup(oid_to_hex(&ctx->new_base_graph->oid));
- char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb, new_base_hash);
+ char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb_source, new_base_hash);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 2]);
@@ -2201,14 +2201,14 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
}
} else {
- char *graph_name = get_commit_graph_filename(ctx->odb);
+ char *graph_name = get_commit_graph_filename(ctx->odb_source);
unlink(graph_name);
free(graph_name);
}
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(hash_to_hex(file_hash));
- final_graph_name = get_split_graph_filename(ctx->odb,
+ final_graph_name = get_split_graph_filename(ctx->odb_source,
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1] = final_graph_name;
@@ -2259,7 +2259,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
flags != COMMIT_GRAPH_SPLIT_REPLACE) {
while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
(max_commits && num_commits > max_commits))) {
- if (g->odb != ctx->odb)
+ if (g->odb_source != ctx->odb_source)
break;
if (unsigned_add_overflows(num_commits, g->num_commits))
@@ -2281,10 +2281,10 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
"should be 1 with --split=replace");
if (ctx->num_commit_graphs_after == 2) {
- char *old_graph_name = get_commit_graph_filename(g->odb);
+ char *old_graph_name = get_commit_graph_filename(g->odb_source);
if (!strcmp(g->filename, old_graph_name) &&
- g->odb != ctx->odb) {
+ g->odb_source != ctx->odb_source) {
ctx->num_commit_graphs_after = 1;
ctx->new_base_graph = NULL;
}
@@ -2456,13 +2456,13 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
if (ctx->opts && ctx->opts->expire_time)
expire_time = ctx->opts->expire_time;
if (!ctx->split) {
- char *chain_file_name = get_commit_graph_chain_filename(ctx->odb);
+ char *chain_file_name = get_commit_graph_chain_filename(ctx->odb_source);
unlink(chain_file_name);
free(chain_file_name);
ctx->num_commit_graphs_after = 0;
}
- strbuf_addstr(&path, ctx->odb->path);
+ strbuf_addstr(&path, ctx->odb_source->path);
strbuf_addstr(&path, "/info/commit-graphs");
dir = opendir(path.buf);
@@ -2504,7 +2504,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
strbuf_release(&path);
}
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_source *source,
const struct string_list *const pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
@@ -2513,7 +2513,7 @@ int write_commit_graph(struct object_directory *odb,
struct repository *r = the_repository;
struct write_commit_graph_context ctx = {
.r = r,
- .odb = odb,
+ .odb_source = source,
.append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0,
.report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0,
.split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0,
diff --git a/commit-graph.h b/commit-graph.h
index 20d38c100ce..0e661db1b54 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -29,8 +29,8 @@ struct repository;
struct object_database;
struct string_list;
-char *get_commit_graph_filename(struct object_directory *odb);
-char *get_commit_graph_chain_filename(struct object_directory *odb);
+char *get_commit_graph_filename(struct odb_source *source);
+char *get_commit_graph_chain_filename(struct odb_source *source);
int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st);
@@ -89,7 +89,7 @@ struct commit_graph {
uint32_t num_commits;
struct object_id oid;
char *filename;
- struct object_directory *odb;
+ struct odb_source *odb_source;
uint32_t num_commits_in_base;
unsigned int read_generation_data;
@@ -115,12 +115,12 @@ struct commit_graph {
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb);
+ struct odb_source *source);
struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
int fd, struct stat *st,
int *incomplete_chain);
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb);
+ struct odb_source *source);
struct repo_settings;
@@ -173,10 +173,10 @@ struct commit_graph_opts {
* is not compatible with the commit-graph feature, then the
* methods will return 0 without writing a commit-graph.
*/
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_source *source,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts);
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_source *source,
const struct string_list *pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
diff --git a/diagnose.c b/diagnose.c
index b1be74be983..d08d5643aac 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -59,13 +59,13 @@ static void dir_file_stats_objects(const char *full_path,
(uintmax_t)st.st_size);
}
-static int dir_file_stats(struct object_directory *object_dir, void *data)
+static int dir_file_stats(struct odb_source *source, void *data)
{
struct strbuf *buf = data;
- strbuf_addf(buf, "Contents of %s:\n", object_dir->path);
+ strbuf_addf(buf, "Contents of %s:\n", source->path);
- for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects,
+ for_each_file_in_pack_dir(source->path, dir_file_stats_objects,
data);
return 0;
@@ -228,7 +228,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(r->objects->odb, &buf);
+ dir_file_stats(r->objects->sources, &buf);
foreach_alt_odb(dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
diff --git a/http-walker.c b/http-walker.c
index 463f7b119ad..c374e6b2056 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
ret = error("File %s has bad hash", hex);
} else if (req->rename < 0) {
struct strbuf buf = STRBUF_INIT;
- odb_loose_path(the_repository->objects->odb, &buf, &req->oid);
+ odb_loose_path(the_repository->objects->sources, &buf, &req->oid);
ret = error("unable to write sha1 filename %s", buf.buf);
strbuf_release(&buf);
}
diff --git a/http.c b/http.c
index 3c029cf8947..5e15bbab3f1 100644
--- a/http.c
+++ b/http.c
@@ -2662,7 +2662,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
oidcpy(&freq->oid, oid);
freq->localfile = -1;
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2814,7 +2814,7 @@ int finish_http_object_request(struct http_object_request *freq)
unlink_or_warn(freq->tmpfile.buf);
return -1;
}
- odb_loose_path(the_repository->objects->odb, &filename, &freq->oid);
+ odb_loose_path(the_repository->objects->sources, &filename, &freq->oid);
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
strbuf_release(&filename);
diff --git a/loose.c b/loose.c
index bb602aaa366..fe65d5b9b0f 100644
--- a/loose.c
+++ b/loose.c
@@ -44,36 +44,36 @@ static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *key, const
return 1;
}
-static int insert_loose_map(struct object_directory *odb,
+static int insert_loose_map(struct odb_source *source,
const struct object_id *oid,
const struct object_id *compat_oid)
{
- struct loose_object_map *map = odb->loose_map;
+ struct loose_object_map *map = source->loose_map;
int inserted = 0;
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
if (inserted)
- oidtree_insert(odb->loose_objects_cache, compat_oid);
+ oidtree_insert(source->loose_objects_cache, compat_oid);
return inserted;
}
-static int load_one_loose_object_map(struct repository *repo, struct object_directory *dir)
+static int load_one_loose_object_map(struct repository *repo, struct odb_source *source)
{
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
FILE *fp;
- if (!dir->loose_map)
- loose_object_map_init(&dir->loose_map);
- if (!dir->loose_objects_cache) {
- ALLOC_ARRAY(dir->loose_objects_cache, 1);
- oidtree_init(dir->loose_objects_cache);
+ if (!source->loose_map)
+ loose_object_map_init(&source->loose_map);
+ if (!source->loose_objects_cache) {
+ ALLOC_ARRAY(source->loose_objects_cache, 1);
+ oidtree_init(source->loose_objects_cache);
}
- insert_loose_map(dir, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
- insert_loose_map(dir, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
- insert_loose_map(dir, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
+ insert_loose_map(source, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
+ insert_loose_map(source, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
+ insert_loose_map(source, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
repo_common_path_replace(repo, &path, "objects/loose-object-idx");
fp = fopen(path.buf, "rb");
@@ -93,7 +93,7 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
parse_oid_hex_algop(p, &compat_oid, &p, repo->compat_hash_algo) ||
p != buf.buf + buf.len)
goto err;
- insert_loose_map(dir, &oid, &compat_oid);
+ insert_loose_map(source, &oid, &compat_oid);
}
strbuf_release(&buf);
@@ -107,15 +107,15 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
int repo_read_loose_object_map(struct repository *repo)
{
- struct object_directory *dir;
+ struct odb_source *source;
if (!should_use_loose_object_map(repo))
return 0;
prepare_alt_odb(repo);
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- if (load_one_loose_object_map(repo, dir) < 0) {
+ for (source = repo->objects->sources; source; source = source->next) {
+ if (load_one_loose_object_map(repo, source) < 0) {
return -1;
}
}
@@ -124,7 +124,7 @@ int repo_read_loose_object_map(struct repository *repo)
int repo_write_loose_object_map(struct repository *repo)
{
- kh_oid_map_t *map = repo->objects->odb->loose_map->to_compat;
+ kh_oid_map_t *map = repo->objects->sources->loose_map->to_compat;
struct lock_file lock;
int fd;
khiter_t iter;
@@ -212,7 +212,7 @@ int repo_add_loose_object_map(struct repository *repo, const struct object_id *o
if (!should_use_loose_object_map(repo))
return 0;
- inserted = insert_loose_map(repo->objects->odb, oid, compat_oid);
+ inserted = insert_loose_map(repo->objects->sources, oid, compat_oid);
if (inserted)
return write_one_object(repo, oid, compat_oid);
return 0;
@@ -223,12 +223,12 @@ int repo_loose_object_map_oid(struct repository *repo,
const struct git_hash_algo *to,
struct object_id *dest)
{
- struct object_directory *dir;
+ struct odb_source *source;
kh_oid_map_t *map;
khiter_t pos;
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- struct loose_object_map *loose_map = dir->loose_map;
+ for (source = repo->objects->sources; source; source = source->next) {
+ struct loose_object_map *loose_map = source->loose_map;
if (!loose_map)
continue;
map = (to == repo->compat_hash_algo) ?
diff --git a/midx.c b/midx.c
index cd6e766ce2b..3c5bc821730 100644
--- a/midx.c
+++ b/midx.c
@@ -832,7 +832,7 @@ void clear_midx_file(struct repository *r)
{
struct strbuf midx = STRBUF_INIT;
- get_midx_filename(r->hash_algo, &midx, r->objects->odb->path);
+ get_midx_filename(r->hash_algo, &midx, r->objects->sources->path);
if (r->objects && r->objects->multi_pack_index) {
close_midx(r->objects->multi_pack_index);
@@ -842,8 +842,8 @@ void clear_midx_file(struct repository *r)
if (remove_path(midx.buf))
die(_("failed to clear multi-pack-index at %s"), midx.buf);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_BITMAP, NULL);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_REV, NULL);
+ clear_midx_files_ext(r->objects->sources->path, MIDX_EXT_BITMAP, NULL);
+ clear_midx_files_ext(r->objects->sources->path, MIDX_EXT_REV, NULL);
strbuf_release(&midx);
}
diff --git a/object-file.c b/object-file.c
index 1ac04c28916..6bad1d3dd1c 100644
--- a/object-file.c
+++ b/object-file.c
@@ -55,12 +55,12 @@ static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
}
}
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_source *source,
struct strbuf *buf,
const struct object_id *oid)
{
strbuf_reset(buf);
- strbuf_addstr(buf, odb->path);
+ strbuf_addstr(buf, source->path);
strbuf_addch(buf, '/');
fill_loose_path(buf, oid);
return buf->buf;
@@ -88,27 +88,27 @@ int check_and_freshen_file(const char *fn, int freshen)
return 1;
}
-static int check_and_freshen_odb(struct object_directory *odb,
+static int check_and_freshen_odb(struct odb_source *source,
const struct object_id *oid,
int freshen)
{
static struct strbuf path = STRBUF_INIT;
- odb_loose_path(odb, &path, oid);
+ odb_loose_path(source, &path, oid);
return check_and_freshen_file(path.buf, freshen);
}
static int check_and_freshen_local(const struct object_id *oid, int freshen)
{
- return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
+ return check_and_freshen_odb(the_repository->objects->sources, oid, freshen);
}
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
- if (check_and_freshen_odb(odb, oid, freshen))
+ for (source = the_repository->objects->sources->next; source; source = source->next) {
+ if (check_and_freshen_odb(source, oid, freshen))
return 1;
}
return 0;
@@ -202,12 +202,12 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct stat *st, const char **path)
{
- struct object_directory *odb;
+ struct odb_source *source;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (source = r->objects->sources; source; source = source->next) {
+ *path = odb_loose_path(source, &buf, oid);
if (!lstat(*path, st))
return 0;
}
@@ -223,13 +223,13 @@ static int open_loose_object(struct repository *r,
const struct object_id *oid, const char **path)
{
int fd;
- struct object_directory *odb;
+ struct odb_source *source;
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (source = r->objects->sources; source; source = source->next) {
+ *path = odb_loose_path(source, &buf, oid);
fd = git_open(*path);
if (fd >= 0)
return fd;
@@ -244,11 +244,11 @@ static int open_loose_object(struct repository *r,
static int quick_has_loose(struct repository *r,
const struct object_id *oid)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- if (oidtree_contains(odb_loose_cache(odb, oid), oid))
+ for (source = r->objects->sources; source; source = source->next) {
+ if (oidtree_contains(odb_loose_cache(source, oid), oid))
return 1;
}
return 0;
@@ -694,7 +694,7 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
/* Finalize a file on disk, and close it. */
static void close_loose_object(int fd, const char *filename)
{
- if (the_repository->objects->odb->will_destroy)
+ if (the_repository->objects->sources->will_destroy)
goto out;
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
@@ -876,7 +876,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
prepare_loose_object_bulk_checkin();
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
fd = start_loose_object_common(&tmp_file, filename.buf, flags,
&stream, compressed, sizeof(compressed),
@@ -1023,7 +1023,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
goto cleanup;
}
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
/* We finally know the object path, and create the missing dir. */
dirlen = directory_size(filename.buf);
@@ -1437,11 +1437,11 @@ int for_each_loose_file_in_objdir(const char *path,
int for_each_loose_object(each_loose_object_fn cb, void *data,
enum for_each_object_flags flags)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
- int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
+ for (source = the_repository->objects->sources; source; source = source->next) {
+ int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
NULL, data);
if (r)
return r;
@@ -1461,43 +1461,43 @@ static int append_loose_object(const struct object_id *oid,
return 0;
}
-struct oidtree *odb_loose_cache(struct object_directory *odb,
- const struct object_id *oid)
+struct oidtree *odb_loose_cache(struct odb_source *source,
+ const struct object_id *oid)
{
int subdir_nr = oid->hash[0];
struct strbuf buf = STRBUF_INIT;
- size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
+ size_t word_bits = bitsizeof(source->loose_objects_subdir_seen[0]);
size_t word_index = subdir_nr / word_bits;
size_t mask = (size_t)1u << (subdir_nr % word_bits);
uint32_t *bitmap;
if (subdir_nr < 0 ||
- subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
+ subdir_nr >= bitsizeof(source->loose_objects_subdir_seen))
BUG("subdir_nr out of range");
- bitmap = &odb->loose_objects_subdir_seen[word_index];
+ bitmap = &source->loose_objects_subdir_seen[word_index];
if (*bitmap & mask)
- return odb->loose_objects_cache;
- if (!odb->loose_objects_cache) {
- ALLOC_ARRAY(odb->loose_objects_cache, 1);
- oidtree_init(odb->loose_objects_cache);
+ return source->loose_objects_cache;
+ if (!source->loose_objects_cache) {
+ ALLOC_ARRAY(source->loose_objects_cache, 1);
+ oidtree_init(source->loose_objects_cache);
}
- strbuf_addstr(&buf, odb->path);
+ strbuf_addstr(&buf, source->path);
for_each_file_in_obj_subdir(subdir_nr, &buf,
append_loose_object,
NULL, NULL,
- odb->loose_objects_cache);
+ source->loose_objects_cache);
*bitmap |= mask;
strbuf_release(&buf);
- return odb->loose_objects_cache;
+ return source->loose_objects_cache;
}
-void odb_clear_loose_cache(struct object_directory *odb)
+void odb_clear_loose_cache(struct odb_source *source)
{
- oidtree_clear(odb->loose_objects_cache);
- FREE_AND_NULL(odb->loose_objects_cache);
- memset(&odb->loose_objects_subdir_seen, 0,
- sizeof(odb->loose_objects_subdir_seen));
+ oidtree_clear(source->loose_objects_cache);
+ FREE_AND_NULL(source->loose_objects_cache);
+ memset(&source->loose_objects_subdir_seen, 0,
+ sizeof(source->loose_objects_subdir_seen));
}
static int check_stream_oid(git_zstream *stream,
diff --git a/object-file.h b/object-file.h
index 6f411424523..9a18859b2e0 100644
--- a/object-file.h
+++ b/object-file.h
@@ -24,23 +24,23 @@ enum {
int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
-struct object_directory;
+struct odb_source;
/*
* Populate and return the loose object cache array corresponding to the
* given object ID.
*/
-struct oidtree *odb_loose_cache(struct object_directory *odb,
+struct oidtree *odb_loose_cache(struct odb_source *source,
const struct object_id *oid);
/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
+void odb_clear_loose_cache(struct odb_source *source);
/*
* Put in `buf` the name of the file in the local object database that
* would be used to store a loose object with the specified oid.
*/
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_source *source,
struct strbuf *buf,
const struct object_id *oid);
diff --git a/object-name.c b/object-name.c
index 9288b2dd245..544634d0f40 100644
--- a/object-name.c
+++ b/object-name.c
@@ -112,10 +112,10 @@ static enum cb_next match_prefix(const struct object_id *oid, void *arg)
static void find_short_object_filename(struct disambiguate_state *ds)
{
- struct object_directory *odb;
+ struct odb_source *source;
- for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next)
- oidtree_each(odb_loose_cache(odb, &ds->bin_pfx),
+ for (source = ds->repo->objects->sources; source && !ds->ambiguous; source = source->next)
+ oidtree_each(odb_loose_cache(source, &ds->bin_pfx),
&ds->bin_pfx, ds->len, match_prefix, ds);
}
diff --git a/object-store.c b/object-store.c
index f4e8f99d90f..5c04a1018f7 100644
--- a/object-store.c
+++ b/object-store.c
@@ -27,7 +27,7 @@
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
- struct object_directory *, 1, fspathhash, fspatheq)
+ struct odb_source *, 1, fspathhash, fspatheq)
/*
* This is meant to hold a *small* number of objects that you would
@@ -104,18 +104,18 @@ static int alt_odb_usable(struct object_database *o,
* Prevent the common mistake of listing the same
* thing twice, or object directory itself.
*/
- if (!o->odb_by_path) {
+ if (!o->source_by_path) {
khiter_t p;
- o->odb_by_path = kh_init_odb_path_map();
- assert(!o->odb->next);
- p = kh_put_odb_path_map(o->odb_by_path, o->odb->path, &r);
+ o->source_by_path = kh_init_odb_path_map();
+ assert(!o->sources->next);
+ p = kh_put_odb_path_map(o->source_by_path, o->sources->path, &r);
assert(r == 1); /* never used */
- kh_value(o->odb_by_path, p) = o->odb;
+ kh_value(o->source_by_path, p) = o->sources;
}
if (fspatheq(path->buf, normalized_objdir))
return 0;
- *pos = kh_put_odb_path_map(o->odb_by_path, path->buf, &r);
+ *pos = kh_put_odb_path_map(o->source_by_path, path->buf, &r);
/* r: 0 = exists, 1 = never used, 2 = deleted */
return r == 0 ? 0 : 1;
}
@@ -124,7 +124,7 @@ static int alt_odb_usable(struct object_database *o,
* Prepare alternate object database registry.
*
* The variable alt_odb_list points at the list of struct
- * object_directory. The elements on this list come from
+ * odb_source. The elements on this list come from
* non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
* environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
* whose contents is similar to that environment variable but can be
@@ -141,7 +141,7 @@ static void read_info_alternates(struct repository *r,
static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
const char *relative_base, int depth, const char *normalized_objdir)
{
- struct object_directory *ent;
+ struct odb_source *alternate;
struct strbuf pathbuf = STRBUF_INIT;
struct strbuf tmp = STRBUF_INIT;
khiter_t pos;
@@ -170,19 +170,19 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
goto error;
- CALLOC_ARRAY(ent, 1);
- /* pathbuf.buf is already in r->objects->odb_by_path */
- ent->path = strbuf_detach(&pathbuf, NULL);
+ CALLOC_ARRAY(alternate, 1);
+ /* pathbuf.buf is already in r->objects->source_by_path */
+ alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->odb_tail = ent;
- r->objects->odb_tail = &(ent->next);
- ent->next = NULL;
- assert(r->objects->odb_by_path);
- kh_value(r->objects->odb_by_path, pos) = ent;
+ *r->objects->sources_tail = alternate;
+ r->objects->sources_tail = &(alternate->next);
+ alternate->next = NULL;
+ assert(r->objects->source_by_path);
+ kh_value(r->objects->source_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, ent->path, depth + 1);
+ read_info_alternates(r, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -234,7 +234,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->odb->path, 1);
+ strbuf_realpath(&objdirbuf, r->objects->sources->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
@@ -321,9 +321,9 @@ void add_to_alternates_memory(const char *reference)
'\n', NULL, 0);
}
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
{
- struct object_directory *new_odb;
+ struct odb_source *source;
/*
* Make sure alternates are initialized, or else our entry may be
@@ -335,41 +335,41 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
- new_odb = xcalloc(1, sizeof(*new_odb));
- new_odb->path = xstrdup(dir);
+ source = xcalloc(1, sizeof(*source));
+ source->path = xstrdup(dir);
/*
* Disable ref updates while a temporary odb is active, since
* the objects in the database may roll back.
*/
- new_odb->disable_ref_updates = 1;
- new_odb->will_destroy = will_destroy;
- new_odb->next = the_repository->objects->odb;
- the_repository->objects->odb = new_odb;
- return new_odb->next;
+ source->disable_ref_updates = 1;
+ source->will_destroy = will_destroy;
+ source->next = the_repository->objects->sources;
+ the_repository->objects->sources = source;
+ return source->next;
}
-static void free_object_directory(struct object_directory *odb)
+static void free_object_directory(struct odb_source *source)
{
- free(odb->path);
- odb_clear_loose_cache(odb);
- loose_object_map_clear(&odb->loose_map);
- free(odb);
+ free(source->path);
+ odb_clear_loose_cache(source);
+ loose_object_map_clear(&source->loose_map);
+ free(source);
}
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
+void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
{
- struct object_directory *cur_odb = the_repository->objects->odb;
+ struct odb_source *cur_alt = the_repository->objects->sources;
- if (strcmp(old_path, cur_odb->path))
+ if (strcmp(old_path, cur_alt->path))
BUG("expected %s as primary object store; found %s",
- old_path, cur_odb->path);
+ old_path, cur_alt->path);
- if (cur_odb->next != restore_odb)
+ if (cur_alt->next != restore_alt)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->odb = restore_odb;
- free_object_directory(cur_odb);
+ the_repository->objects->sources = restore_alt;
+ free_object_directory(cur_alt);
}
/*
@@ -442,15 +442,15 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct object_directory *find_odb(struct repository *r, const char *obj_dir)
+struct odb_source *find_odb(struct repository *r, const char *obj_dir)
{
- struct object_directory *odb;
+ struct odb_source *source;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- strbuf_realpath(&odb_path_real, odb->path, 1);
+ for (source = r->objects->sources; source; source = source->next) {
+ strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
}
@@ -458,9 +458,9 @@ struct object_directory *find_odb(struct repository *r, const char *obj_dir)
free(obj_dir_real);
strbuf_release(&odb_path_real);
- if (!odb)
+ if (!source)
die(_("could not find object directory matching %s"), obj_dir);
- return odb;
+ return source;
}
static void fill_alternate_refs_command(struct child_process *cmd,
@@ -527,14 +527,14 @@ struct alternate_refs_data {
void *data;
};
-static int refs_from_alternate_cb(struct object_directory *e,
+static int refs_from_alternate_cb(struct odb_source *alternate,
void *data)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
struct alternate_refs_data *cb = data;
- if (!strbuf_realpath(&path, e->path, 0))
+ if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
if (!strbuf_strip_suffix(&path, "/objects"))
goto out;
@@ -563,12 +563,12 @@ void for_each_alternate_ref(alternate_ref_fn fn, void *data)
int foreach_alt_odb(alt_odb_fn fn, void *cb)
{
- struct object_directory *ent;
+ struct odb_source *alternate;
int r = 0;
prepare_alt_odb(the_repository);
- for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {
- r = fn(ent, cb);
+ for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
+ r = fn(alternate, cb);
if (r)
break;
}
@@ -582,14 +582,14 @@ void prepare_alt_odb(struct repository *r)
link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->odb->path, 0);
+ read_info_alternates(r, r->objects->sources->path, 0);
r->objects->loaded_alternates = 1;
}
int has_alt_odb(struct repository *r)
{
prepare_alt_odb(r);
- return !!r->objects->odb->next;
+ return !!r->objects->sources->next;
}
int obj_read_use_lock = 0;
@@ -963,15 +963,15 @@ struct object_database *odb_new(void)
static void free_object_directories(struct object_database *o)
{
- while (o->odb) {
- struct object_directory *next;
+ while (o->sources) {
+ struct odb_source *next;
- next = o->odb->next;
- free_object_directory(o->odb);
- o->odb = next;
+ next = o->sources->next;
+ free_object_directory(o->sources);
+ o->sources = next;
}
- kh_destroy_odb_path_map(o->odb_by_path);
- o->odb_by_path = NULL;
+ kh_destroy_odb_path_map(o->source_by_path);
+ o->source_by_path = NULL;
}
void odb_clear(struct object_database *o)
@@ -986,7 +986,7 @@ void odb_clear(struct object_database *o)
o->commit_graph_attempted = 0;
free_object_directories(o);
- o->odb_tail = NULL;
+ o->sources_tail = NULL;
o->loaded_alternates = 0;
for (size_t i = 0; i < o->cached_object_nr; i++)
diff --git a/object-store.h b/object-store.h
index a3be27d1171..a034a8f39e2 100644
--- a/object-store.h
+++ b/object-store.h
@@ -13,8 +13,20 @@ struct oidtree;
struct strbuf;
struct repository;
-struct object_directory {
- struct object_directory *next;
+/*
+ * The source is the part of the object database that stores the actual
+ * objects. It thus encapsulates the logic to read and write the specific
+ * on-disk format. An object database can have multiple sources:
+ *
+ * - The primary source, which is typically located in "$GIT_DIR/objects".
+ * This is where new objects are usually written to.
+ *
+ * - Alternate sources, which are configured via "objects/info/alternates" or
+ * via the GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable. These
+ * alternate sources are only used to read objects.
+ */
+struct odb_source {
+ struct odb_source *next;
/*
* Used to store the results of readdir(3) calls when we are OK
@@ -44,8 +56,8 @@ struct object_directory {
int will_destroy;
/*
- * Path to the alternative object store. If this is a relative path,
- * it is relative to the current working directory.
+ * Path to the source. If this is a relative path, it is relative to
+ * the current working directory.
*/
char *path;
};
@@ -53,8 +65,8 @@ struct object_directory {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
+struct odb_source *find_odb(struct repository *r, const char *obj_dir);
+typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
@@ -76,12 +88,12 @@ void add_to_alternates_memory(const char *dir);
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
*/
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy);
/*
* Restore a previous ODB replaced by set_temporary_main_odb.
*/
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+void restore_primary_odb(struct odb_source *restore_alternate, const char *old_path);
struct packed_git;
struct multi_pack_index;
@@ -89,7 +101,7 @@ struct cached_object_entry;
/*
* The object database encapsulates access to objects in a repository. It
- * manages one or more backends that store the actual objects which are
+ * manages one or more alternates that store the actual objects which are
* configured via alternates.
*/
struct object_database {
@@ -98,16 +110,16 @@ struct object_database {
* cannot be NULL after initialization). Subsequent directories are
* alternates.
*/
- struct object_directory *odb;
- struct object_directory **odb_tail;
- struct kh_odb_path_map *odb_by_path;
+ struct odb_source *sources;
+ struct odb_source **sources_tail;
+ struct kh_odb_path_map *source_by_path;
int loaded_alternates;
/*
* 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.
+ * populate the "sources" list when prepare_alt_odb() is run.
*/
char *alternate_db;
diff --git a/packfile.c b/packfile.c
index c735b4d0135..60661ad0095 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1029,16 +1029,16 @@ static void prepare_packed_git_mru(struct repository *r)
static void prepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_source *source;
if (r->objects->packed_git_initialized)
return;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- int local = (odb == r->objects->odb);
- prepare_multi_pack_index_one(r, odb->path, local);
- prepare_packed_git_one(r, odb->path, local);
+ for (source = r->objects->sources; source; source = source->next) {
+ int local = (source == r->objects->sources);
+ prepare_multi_pack_index_one(r, source->path, local);
+ prepare_packed_git_one(r, source->path, local);
}
rearrange_packed_git(r);
@@ -1048,7 +1048,7 @@ static void prepare_packed_git(struct repository *r)
void reprepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_source *source;
obj_read_lock();
@@ -1061,8 +1061,8 @@ void reprepare_packed_git(struct repository *r)
r->objects->loaded_alternates = 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next)
- odb_clear_loose_cache(odb);
+ for (source = r->objects->sources; source; source = source->next)
+ odb_clear_loose_cache(source);
r->objects->approximate_object_count_valid = 0;
r->objects->packed_git_initialized = 0;
diff --git a/path.c b/path.c
index 3b598b2847f..c347829aa66 100644
--- a/path.c
+++ b/path.c
@@ -397,7 +397,7 @@ static void adjust_git_path(struct repository *repo,
strbuf_splice(buf, 0, buf->len,
repo->index_file, strlen(repo->index_file));
else if (dir_prefix(base, "objects"))
- replace_dir(buf, git_dir_len + 7, repo->objects->odb->path);
+ replace_dir(buf, git_dir_len + 7, repo->objects->sources->path);
else if (repo_settings_get_hooks_path(repo) && dir_prefix(base, "hooks"))
replace_dir(buf, git_dir_len + 5, repo_settings_get_hooks_path(repo));
else if (repo->different_commondir)
diff --git a/refs.c b/refs.c
index dce5c49ca2b..5f6a386cc93 100644
--- a/refs.c
+++ b/refs.c
@@ -2477,7 +2477,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
break;
}
- if (refs->repo->objects->odb->disable_ref_updates) {
+ if (refs->repo->objects->sources->disable_ref_updates) {
strbuf_addstr(err,
_("ref updates forbidden inside quarantine environment"));
return -1;
diff --git a/repository.c b/repository.c
index 07757e6e0c9..7528beccddf 100644
--- a/repository.c
+++ b/repository.c
@@ -107,9 +107,9 @@ const char *repo_get_common_dir(struct repository *repo)
const char *repo_get_object_directory(struct repository *repo)
{
- if (!repo->objects->odb)
+ if (!repo->objects->sources)
BUG("repository hasn't been set up");
- return repo->objects->odb->path;
+ return repo->objects->sources->path;
}
const char *repo_get_index_file(struct repository *repo)
@@ -165,14 +165,14 @@ void repo_set_gitdir(struct repository *repo,
repo_set_commondir(repo, o->commondir);
- if (!repo->objects->odb) {
- CALLOC_ARRAY(repo->objects->odb, 1);
- repo->objects->odb_tail = &repo->objects->odb->next;
+ if (!repo->objects->sources) {
+ CALLOC_ARRAY(repo->objects->sources, 1);
+ repo->objects->sources_tail = &repo->objects->sources->next;
}
- expand_base_dir(&repo->objects->odb->path, o->object_dir,
+ expand_base_dir(&repo->objects->sources->path, o->object_dir,
repo->commondir, "objects");
- repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
+ repo->objects->sources->disable_ref_updates = o->disable_ref_updates;
free(repo->objects->alternate_db);
repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
diff --git a/submodule-config.c b/submodule-config.c
index 8630e27947d..b30d9365fbd 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->odb->path);
+ add_submodule_odb_by_path(repo->objects->sources->path);
} else {
goto out;
}
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 8b413b644be..53b633e2ba6 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -73,15 +73,15 @@ static void dump_graph_bloom_filters(struct commit_graph *graph)
int cmd__read_graph(int argc, const char **argv)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb;
+ struct odb_source *source;
int ret = 0;
setup_git_directory();
- odb = the_repository->objects->odb;
+ source = the_repository->objects->sources;
prepare_repo_settings(the_repository);
- graph = read_commit_graph_one(the_repository, odb);
+ graph = read_commit_graph_one(the_repository, source);
if (!graph) {
ret = 1;
goto done;
diff --git a/tmp-objdir.c b/tmp-objdir.c
index c38fbeb5e8a..056484404be 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -17,7 +17,7 @@ struct tmp_objdir {
struct repository *repo;
struct strbuf path;
struct strvec env;
- struct object_directory *prev_odb;
+ struct odb_source *prev_source;
int will_destroy;
};
@@ -46,8 +46,8 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
if (t == the_tmp_objdir)
the_tmp_objdir = NULL;
- if (t->prev_odb)
- restore_primary_odb(t->prev_odb, t->path.buf);
+ if (t->prev_source)
+ restore_primary_odb(t->prev_source, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -276,11 +276,11 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (!t)
return 0;
- if (t->prev_odb) {
- if (t->repo->objects->odb->will_destroy)
+ if (t->prev_source) {
+ if (t->repo->objects->sources->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_odb, t->path.buf);
- t->prev_odb = NULL;
+ restore_primary_odb(t->prev_source, t->path.buf);
+ t->prev_source = NULL;
}
strbuf_addbuf(&src, &t->path);
@@ -309,19 +309,19 @@ void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
- if (t->prev_odb)
+ if (t->prev_source)
BUG("the primary object database is already replaced");
- t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_source = set_temporary_primary_odb(t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
{
- if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
+ if (!the_tmp_objdir || !the_tmp_objdir->prev_source)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
- the_tmp_objdir->prev_odb = NULL;
+ restore_primary_odb(the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
+ the_tmp_objdir->prev_source = NULL;
return the_tmp_objdir;
}
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v4 02/17] object-store: rename `object_directory` to `odb_source`
2025-06-02 10:27 ` [PATCH v4 02/17] object-store: rename `object_directory` to `odb_source` Patrick Steinhardt
@ 2025-06-04 13:24 ` Toon Claes
2025-06-04 13:55 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Toon Claes @ 2025-06-04 13:24 UTC (permalink / raw)
To: Patrick Steinhardt, git; +Cc: Derrick Stolee, Junio C Hamano, Justin Tobler
Patrick Steinhardt <ps@pks.im> writes:
> The `object_directory` structure is used as an access point for a single
> object directory like ".git/objects". While the structure isn't yet
> fully self-contained, the intent is for it to eventually contain all
> information required to access objects in one specific location.
>
> While the name "object directory" is a good fit for now, this will
> change over time as we continue with the agenda to make pluggable object
> databases a thing. Eventually, objects may not be accessed via any kind
> of directory at all anymore, but they could instead be backed by any
> kind of durable storage mechanism. While it seems quite far-fetched for
> now, it is thinkable that eventually this might even be some form of a
> database, for example.
>
> As such, the current name of this structure will become worse over time
> as we evolve into the direction of pluggable ODBs. Immediate next steps
> will start to carve out proper self-contained object directories, which
> requires us to pass in these object directories as parameters. Based on
> our modern naming schema this means that those functions should then be
> named after their subsystem, which means that we would start to bake the
> current name into the codebase more and more.
>
> Let's preempt this by renaming the structure. There have been a couple
> alternatives that were discussed:
>
> - `odb_backend` was discarded because it led to the association that
> one object database has a single backend, but the model is that one
> alternate has one backend. Furthermore, "backend" is more about the
> actual backing implementation and less about the high-level concept.
>
> - `odb_alternate` was discarded because it is a bit of a stretch to
> also call the main object directory an "alternate".
>
> Instead, pick `odb_source` as the new name. It makes it sufficiently
> clear that there can be multiple sources and does not cause confusion
> when mixed with the already-existing "alternate" terminology.
>
> In the future, this change allows us to easily introduce for example a
> `odb_files_source` and other format-specific implementations.
Sorry for being pedantic (but I guess this series is all about naming
anyway, so better get it right), but wouldn't this be
`odb_files_backend`?
--
Cheers,
Toon
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v4 02/17] object-store: rename `object_directory` to `odb_source`
2025-06-04 13:24 ` Toon Claes
@ 2025-06-04 13:55 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-04 13:55 UTC (permalink / raw)
To: Toon Claes; +Cc: git, Derrick Stolee, Junio C Hamano, Justin Tobler
On Wed, Jun 04, 2025 at 03:24:43PM +0200, Toon Claes wrote:
> Patrick Steinhardt <ps@pks.im> writes:
>
> > The `object_directory` structure is used as an access point for a single
> > object directory like ".git/objects". While the structure isn't yet
> > fully self-contained, the intent is for it to eventually contain all
> > information required to access objects in one specific location.
> >
> > While the name "object directory" is a good fit for now, this will
> > change over time as we continue with the agenda to make pluggable object
> > databases a thing. Eventually, objects may not be accessed via any kind
> > of directory at all anymore, but they could instead be backed by any
> > kind of durable storage mechanism. While it seems quite far-fetched for
> > now, it is thinkable that eventually this might even be some form of a
> > database, for example.
> >
> > As such, the current name of this structure will become worse over time
> > as we evolve into the direction of pluggable ODBs. Immediate next steps
> > will start to carve out proper self-contained object directories, which
> > requires us to pass in these object directories as parameters. Based on
> > our modern naming schema this means that those functions should then be
> > named after their subsystem, which means that we would start to bake the
> > current name into the codebase more and more.
> >
> > Let's preempt this by renaming the structure. There have been a couple
> > alternatives that were discussed:
> >
> > - `odb_backend` was discarded because it led to the association that
> > one object database has a single backend, but the model is that one
> > alternate has one backend. Furthermore, "backend" is more about the
> > actual backing implementation and less about the high-level concept.
> >
> > - `odb_alternate` was discarded because it is a bit of a stretch to
> > also call the main object directory an "alternate".
> >
> > Instead, pick `odb_source` as the new name. It makes it sufficiently
> > clear that there can be multiple sources and does not cause confusion
> > when mixed with the already-existing "alternate" terminology.
> >
> > In the future, this change allows us to easily introduce for example a
> > `odb_files_source` and other format-specific implementations.
>
> Sorry for being pedantic (but I guess this series is all about naming
> anyway, so better get it right), but wouldn't this be
> `odb_files_backend`?
Maybe, maybe not. In any case, we can still decide that at a later point
in time -- it's only part of the commit message, so this part is not set
in stone and can be discussed once we introduce such backends.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v4 03/17] object-store: rename files to "odb.{c,h}"
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 02/17] object-store: rename `object_directory` to `odb_source` Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 04/17] odb: introduce parent pointers Patrick Steinhardt
` (14 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
In the preceding commits we have renamed the structures contained in
"object-store.h" to `struct object_database` and `struct odb_backend`.
As such, the code files "object-store.{c,h}" are confusingly named now.
Rename them to "odb.{c,h}" accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Makefile | 2 +-
apply.c | 2 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 2 +-
blame.c | 2 +-
builtin/backfill.c | 2 +-
builtin/blame.c | 2 +-
builtin/cat-file.c | 2 +-
builtin/checkout.c | 2 +-
builtin/clone.c | 2 +-
builtin/commit-graph.c | 2 +-
builtin/commit-tree.c | 2 +-
builtin/describe.c | 2 +-
builtin/difftool.c | 2 +-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 2 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 2 +-
builtin/grep.c | 2 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 2 +-
builtin/log.c | 2 +-
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 2 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 2 +-
builtin/mktag.c | 2 +-
builtin/mktree.c | 2 +-
builtin/multi-pack-index.c | 2 +-
builtin/notes.c | 2 +-
builtin/pack-objects.c | 2 +-
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 2 +-
builtin/receive-pack.c | 2 +-
builtin/remote.c | 2 +-
builtin/repack.c | 2 +-
builtin/replace.c | 2 +-
builtin/rev-list.c | 2 +-
builtin/show-ref.c | 2 +-
builtin/submodule--helper.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 2 +-
bulk-checkin.c | 2 +-
bundle-uri.c | 2 +-
bundle.c | 2 +-
cache-tree.c | 2 +-
combine-diff.c | 2 +-
commit-graph.c | 2 +-
commit-graph.h | 2 +-
commit.c | 2 +-
config.c | 2 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 2 +-
diff.c | 2 +-
entry.c | 2 +-
fetch-pack.c | 2 +-
fmt-merge-msg.c | 2 +-
fsck.c | 2 +-
grep.c | 2 +-
http-backend.c | 2 +-
http-push.c | 2 +-
http-walker.c | 2 +-
http.c | 2 +-
list-objects-filter.c | 2 +-
list-objects.c | 2 +-
loose.c | 2 +-
mailmap.c | 2 +-
match-trees.c | 2 +-
merge-blobs.c | 2 +-
merge-ort.c | 2 +-
meson.build | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 2 +-
object-file.c | 2 +-
object-file.h | 2 +-
object-store.c => odb.c | 2 +-
object-store.h => odb.h | 6 +++---
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 2 +-
pack-bitmap.c | 2 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
packfile.c | 2 +-
packfile.h | 4 ++--
path.c | 2 +-
promisor-remote.c | 2 +-
protocol-caps.c | 2 +-
read-cache.c | 2 +-
ref-filter.c | 2 +-
reflog.c | 2 +-
refs.c | 2 +-
remote.c | 2 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 2 +-
rerere.c | 2 +-
revision.c | 2 +-
send-pack.c | 2 +-
sequencer.c | 2 +-
server-info.c | 2 +-
shallow.c | 2 +-
streaming.c | 2 +-
submodule-config.c | 2 +-
submodule.c | 2 +-
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 2 +-
t/helper/test-read-graph.c | 2 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 2 +-
tag.c | 2 +-
tmp-objdir.c | 2 +-
tree-walk.c | 2 +-
tree.c | 2 +-
unpack-trees.c | 2 +-
upload-pack.c | 2 +-
walker.c | 2 +-
xdiff-interface.c | 2 +-
126 files changed, 129 insertions(+), 129 deletions(-)
diff --git a/Makefile b/Makefile
index 70d1543b6b8..4b1bf897791 100644
--- a/Makefile
+++ b/Makefile
@@ -1085,8 +1085,8 @@ LIB_OBJS += notes.o
LIB_OBJS += object-file-convert.o
LIB_OBJS += object-file.o
LIB_OBJS += object-name.o
-LIB_OBJS += object-store.o
LIB_OBJS += object.o
+LIB_OBJS += odb.o
LIB_OBJS += oid-array.o
LIB_OBJS += oidmap.o
LIB_OBJS += oidset.o
diff --git a/apply.c b/apply.c
index 8bbe6ed2240..e778b4e911d 100644
--- a/apply.c
+++ b/apply.c
@@ -14,7 +14,7 @@
#include "abspath.h"
#include "base85.h"
#include "config.h"
-#include "object-store.h"
+#include "odb.h"
#include "delta.h"
#include "diff.h"
#include "dir.h"
diff --git a/archive-tar.c b/archive-tar.c
index 282b48196f9..249164ea77d 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -11,7 +11,7 @@
#include "hex.h"
#include "tar.h"
#include "archive.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "streaming.h"
#include "run-command.h"
diff --git a/archive-zip.c b/archive-zip.c
index 405da6f3d83..df8866d5bae 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -12,7 +12,7 @@
#include "hex.h"
#include "streaming.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "userdiff.h"
#include "write-or-die.h"
diff --git a/archive.c b/archive.c
index 8309ea213e6..7fa2cc2596a 100644
--- a/archive.c
+++ b/archive.c
@@ -14,7 +14,7 @@
#include "pretty.h"
#include "setup.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 86b6109fc4e..e5680db7f65 100644
--- a/attr.c
+++ b/attr.c
@@ -22,7 +22,7 @@
#include "read-cache-ll.h"
#include "refs.h"
#include "revision.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/bisect.c b/bisect.c
index a327468c75b..a7939216d00 100644
--- a/bisect.c
+++ b/bisect.c
@@ -20,7 +20,7 @@
#include "commit-slab.h"
#include "commit-reach.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "dir.h"
diff --git a/blame.c b/blame.c
index 57daa45e899..0ceea080a80 100644
--- a/blame.c
+++ b/blame.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "cache-tree.h"
#include "mergesort.h"
#include "commit.h"
diff --git a/builtin/backfill.c b/builtin/backfill.c
index fa82ad2f6ff..0b49baa39fa 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -13,7 +13,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "promisor-remote.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 944952e30eb..15eda60af90 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -28,7 +28,7 @@
#include "line-log.h"
#include "progress.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "blame.h"
#include "refs.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 67a5ff2b9eb..f3a925a8183 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -24,7 +24,7 @@
#include "pack-bitmap.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "mailmap.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d185982f3a6..e7dd66173dd 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,7 +20,7 @@
#include "merge-ort-wrappers.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "path.h"
#include "preload-index.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 91b9cd0d164..1eafeefb48d 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -25,7 +25,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "tree-walk.h"
#include "unpack-trees.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 98a84315342..f04eaba5259 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -6,7 +6,7 @@
#include "hex.h"
#include "parse-options.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "progress.h"
#include "replace-object.h"
#include "strbuf.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index ad6b2c93209..546069f8682 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -9,7 +9,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "parse-options.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 2d50883b729..96cb68e5e5d 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -19,7 +19,7 @@
#include "setup.h"
#include "strvec.h"
#include "run-command.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects.h"
#include "commit-slab.h"
#include "wildmatch.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index a3b64ce6942..fac613e3bc3 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -30,7 +30,7 @@
#include "strbuf.h"
#include "lockfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "entry.h"
#include "setup.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 37c01d6c6fe..0505f289a94 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "object.h"
#include "tag.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index b2839c5f439..52c792488e1 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -24,7 +24,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "mem-pool.h"
#include "commit-reach.h"
#include "khash.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index a890e2864d1..b842bc9c51b 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "oid-array.h"
#include "commit.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6e1474f63d5..9abd7b25580 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "read-cache-ll.h"
#include "replace-object.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 76b1938bba5..a1d7ee7af39 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -26,7 +26,7 @@
#include "submodule-config.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pager.h"
#include "path.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index 6a99ec250d0..e28f000221f 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -11,7 +11,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bb7925bd29f..1aabe6b8ee2 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -21,7 +21,7 @@
#include "packfile.h"
#include "pack-revindex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "path.h"
diff --git a/builtin/log.c b/builtin/log.c
index b450cd3bde8..fe9cc5ebecb 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -15,7 +15,7 @@
#include "hex.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "color.h"
#include "commit.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index be74f0a03b2..821339b07d4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -25,7 +25,7 @@
#include "setup.h"
#include "sparse-index.h"
#include "submodule.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 8aafc30ca48..62b6fd58c16 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -10,7 +10,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "path.h"
#include "quote.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 2b16b10d2ca..9464f275629 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -7,7 +7,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "gettext.h"
#include "setup.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 7f41665dfd7..b1a17787bcf 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -10,7 +10,7 @@
#include "commit-reach.h"
#include "merge-ort.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "blob.h"
#include "merge-blobs.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 7ac11c46d53..1809b38f937 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -6,7 +6,7 @@
#include "strbuf.h"
#include "replace-object.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "fsck.h"
#include "config.h"
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 4b478034675..016b0e5b224 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -12,7 +12,7 @@
#include "tree.h"
#include "parse-options.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static struct treeent {
unsigned mode;
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index f55bf53da83..aa25b06f9d0 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -7,7 +7,7 @@
#include "midx.h"
#include "strbuf.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index a3f433ca4c0..783d4932ca6 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -16,7 +16,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "pretty.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 8b33edc2ff5..99b63cb0980 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -32,7 +32,7 @@
#include "list.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "dir.h"
#include "midx.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 5d1fc781761..3134cb8c689 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -13,7 +13,7 @@
#include "hex.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#define BLKSIZE 512
diff --git a/builtin/prune.c b/builtin/prune.c
index e930caa0c0a..7bbfb14c2be 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -17,7 +17,7 @@
#include "replace-object.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "shallow.h"
static const char * const prune_usage[] = {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index a317d6c278d..0f5958c4a66 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -33,7 +33,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "protocol.h"
#include "commit-reach.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 0d6755bcb71..ac5b8d2a1a6 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -14,7 +14,7 @@
#include "rebase.h"
#include "refs.h"
#include "refspec.h"
-#include "object-store.h"
+#include "odb.h"
#include "strvec.h"
#include "commit-reach.h"
#include "progress.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 59214dbdfdf..16782320058 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -17,7 +17,7 @@
#include "midx.h"
#include "packfile.h"
#include "prune-packed.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "shallow.h"
#include "pack.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 48c7c6a2d56..11c7e2d4c0c 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "tag.h"
#include "wildmatch.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 0984b607bf0..0ee37a32cb2 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -14,7 +14,7 @@
#include "object.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "parse-options.h"
#include "log-tree.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 623a52a45f8..90ec1de78f9 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "refs/refs-internal.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "string-list.h"
#include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 758bc6d0f24..84f7fa53424 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -28,7 +28,7 @@
#include "diff.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "advice.h"
#include "branch.h"
#include "list-objects-filter-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 4742b27d16e..cf2ea4b4993 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -19,7 +19,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "tag.h"
#include "parse-options.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index e33acfc4ee4..b92fd4710a9 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
static char *create_temp_file(struct object_id *oid)
{
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index e905d5f4e19..7bf395eec84 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -9,7 +9,7 @@
#include "git-zlib.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "delta.h"
#include "pack.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 678e2ecc2c2..55406a539e7 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -17,7 +17,7 @@
#include "tmp-objdir.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static int odb_transaction_nesting;
diff --git a/bundle-uri.c b/bundle-uri.c
index 9accf157b44..2e623f8627a 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -14,7 +14,7 @@
#include "fetch-pack.h"
#include "remote.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
static struct {
enum bundle_list_heuristic heuristic;
diff --git a/bundle.c b/bundle.c
index 2ce7525f90d..e09e3c2f58c 100644
--- a/bundle.c
+++ b/bundle.c
@@ -7,7 +7,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "object.h"
#include "commit.h"
diff --git a/cache-tree.c b/cache-tree.c
index fa3858e2829..9786b32b3a1 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -10,7 +10,7 @@
#include "cache-tree.h"
#include "bulk-checkin.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "read-cache-ll.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/combine-diff.c b/combine-diff.c
index dfae9f7995d..cf23a753407 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -2,7 +2,7 @@
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "convert.h"
#include "diff.h"
diff --git a/commit-graph.c b/commit-graph.c
index 12d32cdad1d..6ced5b366e7 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -13,7 +13,7 @@
#include "refs.h"
#include "hash-lookup.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "alloc.h"
diff --git a/commit-graph.h b/commit-graph.h
index 0e661db1b54..78ab7b875b2 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -1,7 +1,7 @@
#ifndef COMMIT_GRAPH_H
#define COMMIT_GRAPH_H
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
diff --git a/commit.c b/commit.c
index e915b2b9a12..1d30f8ce15a 100644
--- a/commit.c
+++ b/commit.c
@@ -9,7 +9,7 @@
#include "hex.h"
#include "repository.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "diff.h"
#include "revision.h"
diff --git a/config.c b/config.c
index b18b5617fcd..883dd066827 100644
--- a/config.c
+++ b/config.c
@@ -31,7 +31,7 @@
#include "hashmap.h"
#include "string-list.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "path.h"
#include "utf8.h"
diff --git a/connected.c b/connected.c
index 4415388beba..18c13245d8e 100644
--- a/connected.c
+++ b/connected.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "run-command.h"
#include "sigchain.h"
#include "connected.h"
diff --git a/contrib/coccinelle/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
index 765ad689678..ea7fe1c8db7 100644
--- a/contrib/coccinelle/the_repository.cocci
+++ b/contrib/coccinelle/the_repository.cocci
@@ -77,7 +77,7 @@
|
- diff_setup
+ repo_diff_setup
-// object-store.h
+// odb.h
|
- read_object_file
+ repo_read_object_file
diff --git a/diagnose.c b/diagnose.c
index d08d5643aac..ad0d5c12465 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -7,7 +7,7 @@
#include "gettext.h"
#include "hex.h"
#include "strvec.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "repository.h"
diff --git a/diff.c b/diff.c
index 90e8003dd11..3af108115b3 100644
--- a/diff.c
+++ b/diff.c
@@ -23,7 +23,7 @@
#include "color.h"
#include "run-command.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "userdiff.h"
#include "submodule.h"
#include "hashmap.h"
diff --git a/entry.c b/entry.c
index f36ec5ad242..75d55038d7c 100644
--- a/entry.c
+++ b/entry.c
@@ -1,7 +1,7 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index fa4231fee74..cf157f5d7e5 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -24,7 +24,7 @@
#include "oid-array.h"
#include "oidset.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "connected.h"
#include "fetch-negotiator.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 501b5acdd44..1a8c972adf3 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -6,7 +6,7 @@
#include "environment.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "diff.h"
#include "diff-merges.h"
#include "hex.h"
diff --git a/fsck.c b/fsck.c
index 8dc8472ceb3..e69baab3af7 100644
--- a/fsck.c
+++ b/fsck.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "dir.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "object.h"
diff --git a/grep.c b/grep.c
index f8d535182c3..dc77e6c4631 100644
--- a/grep.c
+++ b/grep.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "grep.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "userdiff.h"
#include "xdiff-interface.h"
diff --git a/http-backend.c b/http-backend.c
index 0c575aa88aa..ad8c4037493 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -18,7 +18,7 @@
#include "url.h"
#include "strvec.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "protocol.h"
#include "date.h"
#include "write-or-die.h"
diff --git a/http-push.c b/http-push.c
index f9e67cabd4b..d1b1bb23711 100644
--- a/http-push.c
+++ b/http-push.c
@@ -20,7 +20,7 @@
#include "url.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#ifdef EXPAT_NEEDS_XMLPARSE_H
diff --git a/http-walker.c b/http-walker.c
index c374e6b2056..05fb9ce714a 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -10,7 +10,7 @@
#include "transport.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct alt_base {
char *base;
diff --git a/http.c b/http.c
index 5e15bbab3f1..8f4f701a818 100644
--- a/http.c
+++ b/http.c
@@ -19,7 +19,7 @@
#include "packfile.h"
#include "string-list.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tempfile.h"
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 78b397bc194..80fe48a52c8 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -12,7 +12,7 @@
#include "oidmap.h"
#include "oidset.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
/* Remember to update object flag allocation in object.h */
/*
diff --git a/list-objects.c b/list-objects.c
index 597114281f6..c50b9578584 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -14,7 +14,7 @@
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace.h"
#include "environment.h"
diff --git a/loose.c b/loose.c
index fe65d5b9b0f..fab4041c03d 100644
--- a/loose.c
+++ b/loose.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
#include "repository.h"
#include "wrapper.h"
diff --git a/mailmap.c b/mailmap.c
index 9e2642a043b..b18e74c2110 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -6,7 +6,7 @@
#include "string-list.h"
#include "mailmap.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
char *git_mailmap_file;
diff --git a/match-trees.c b/match-trees.c
index 72922d5d64e..4704f95c340 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -7,7 +7,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
static int score_missing(unsigned mode)
diff --git a/merge-blobs.c b/merge-blobs.c
index 53f36dbc175..ba8a3fdfd82 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -4,7 +4,7 @@
#include "merge-ll.h"
#include "blob.h"
#include "merge-blobs.h"
-#include "object-store.h"
+#include "odb.h"
static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
{
diff --git a/merge-ort.c b/merge-ort.c
index 47b3d1730ec..9f693ab1d36 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -39,7 +39,7 @@
#include "mem-pool.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/meson.build b/meson.build
index 596f5ac7110..3fad0e39987 100644
--- a/meson.build
+++ b/meson.build
@@ -396,8 +396,8 @@ libgit_sources = [
'object-file-convert.c',
'object-file.c',
'object-name.c',
- 'object-store.c',
'object.c',
+ 'odb.c',
'oid-array.c',
'oidmap.c',
'oidset.c',
diff --git a/notes-cache.c b/notes-cache.c
index 150241b15e0..344f67762b8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "notes-cache.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "repository.h"
#include "commit.h"
diff --git a/notes-merge.c b/notes-merge.c
index dae8e6a281a..de6a52e2e7f 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -8,7 +8,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "diff.h"
diff --git a/notes.c b/notes.c
index 0a128f1de98..fc000e501d2 100644
--- a/notes.c
+++ b/notes.c
@@ -8,7 +8,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "strbuf.h"
#include "tree-walk.h"
diff --git a/object-file.c b/object-file.c
index 6bad1d3dd1c..2d3af8a77c0 100644
--- a/object-file.c
+++ b/object-file.c
@@ -21,7 +21,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidtree.h"
#include "pack.h"
#include "packfile.h"
diff --git a/object-file.h b/object-file.h
index 9a18859b2e0..5066638f8ec 100644
--- a/object-file.h
+++ b/object-file.h
@@ -3,7 +3,7 @@
#include "git-zlib.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
struct index_state;
diff --git a/object-store.c b/odb.c
similarity index 99%
rename from object-store.c
rename to odb.c
index 5c04a1018f7..d1025ac182d 100644
--- a/object-store.c
+++ b/odb.c
@@ -13,7 +13,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/object-store.h b/odb.h
similarity index 99%
rename from object-store.h
rename to odb.h
index a034a8f39e2..111584a0a09 100644
--- a/object-store.h
+++ b/odb.h
@@ -1,5 +1,5 @@
-#ifndef OBJECT_STORE_H
-#define OBJECT_STORE_H
+#ifndef ODB_H
+#define ODB_H
#include "hashmap.h"
#include "object.h"
@@ -352,4 +352,4 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
-#endif /* OBJECT_STORE_H */
+#endif /* ODB_H */
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 609a343ee3e..d2a92f34d98 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 7f400ee0121..37648b57125 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -4,7 +4,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index ac6d62b980c..a695a794e9b 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "repository.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects-filter-options.h"
#include "midx.h"
#include "config.h"
diff --git a/pack-check.c b/pack-check.c
index 874897d6cba..67cb2cf72f2 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -8,7 +8,7 @@
#include "progress.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct idx_entry {
off_t offset;
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 20900ca88d3..8e1f2dec0ef 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-mtimes.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
diff --git a/pack-objects.h b/pack-objects.h
index 475a2d67ce3..1ac8644201b 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -1,7 +1,7 @@
#ifndef PACK_OBJECTS_H
#define PACK_OBJECTS_H
-#include "object-store.h"
+#include "odb.h"
#include "thread-utils.h"
#include "pack.h"
#include "packfile.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index ffcde48870d..0cc422a1e67 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-revindex.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
#include "trace2.h"
diff --git a/packfile.c b/packfile.c
index 60661ad0095..346c2f9ce90 100644
--- a/packfile.c
+++ b/packfile.c
@@ -19,7 +19,7 @@
#include "tree-walk.h"
#include "tree.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "midx.h"
#include "commit-graph.h"
#include "pack-revindex.h"
diff --git a/packfile.h b/packfile.h
index 826eb7f475f..53c3b7d3b43 100644
--- a/packfile.h
+++ b/packfile.h
@@ -3,10 +3,10 @@
#include "list.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
-/* in object-store.h */
+/* in odb.h */
struct object_info;
struct packed_git {
diff --git a/path.c b/path.c
index c347829aa66..7f56eaf9930 100644
--- a/path.c
+++ b/path.c
@@ -15,7 +15,7 @@
#include "submodule-config.h"
#include "path.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "lockfile.h"
#include "exec-cmd.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 9d058586dfa..2baa286bfd0 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "config.h"
#include "trace2.h"
diff --git a/protocol-caps.c b/protocol-caps.c
index 9b8db37a210..3022f69a1bd 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -6,7 +6,7 @@
#include "hash.h"
#include "hex.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "string-list.h"
#include "strbuf.h"
diff --git a/read-cache.c b/read-cache.c
index c0bb760ad47..c3fa9686766 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -20,7 +20,7 @@
#include "refs.h"
#include "dir.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "tree.h"
#include "commit.h"
diff --git a/ref-filter.c b/ref-filter.c
index 7a274633cfc..4ce45440ad1 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "wildmatch.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "repo-settings.h"
#include "repository.h"
diff --git a/reflog.c b/reflog.c
index 15d81ebea97..4f8a3b717cd 100644
--- a/reflog.c
+++ b/reflog.c
@@ -5,7 +5,7 @@
#include "config.h"
#include "gettext.h"
#include "parse-options.h"
-#include "object-store.h"
+#include "odb.h"
#include "reflog.h"
#include "refs.h"
#include "revision.h"
diff --git a/refs.c b/refs.c
index 5f6a386cc93..0ff0e582a6b 100644
--- a/refs.c
+++ b/refs.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "hook.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "path.h"
#include "submodule.h"
diff --git a/remote.c b/remote.c
index 4099183cacd..17a842f5684 100644
--- a/remote.c
+++ b/remote.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "commit.h"
#include "diff.h"
diff --git a/replace-object.c b/replace-object.c
index f8c5f68837f..3eae0510745 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -2,7 +2,7 @@
#include "gettext.h"
#include "hex.h"
#include "oidmap.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "refs.h"
#include "repository.h"
diff --git a/replace-object.h b/replace-object.h
index 3052e96a620..4c9f2a2383d 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -3,7 +3,7 @@
#include "oidmap.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
struct replace_object {
struct oidmap_entry original;
diff --git a/repository.c b/repository.c
index 7528beccddf..13426db0f2b 100644
--- a/repository.c
+++ b/repository.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "object.h"
#include "lockfile.h"
diff --git a/rerere.c b/rerere.c
index 3cd37c5f0ae..951e4bf8b41 100644
--- a/rerere.c
+++ b/rerere.c
@@ -18,7 +18,7 @@
#include "path.h"
#include "pathspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "strmap.h"
#define RESOLVED 0
diff --git a/revision.c b/revision.c
index 2c36a9c179e..cdefe7d6e48 100644
--- a/revision.c
+++ b/revision.c
@@ -8,7 +8,7 @@
#include "hex.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "tag.h"
#include "blob.h"
diff --git a/send-pack.c b/send-pack.c
index 86592ce526d..abca2dd38a7 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pkt-line.h"
#include "sideband.h"
#include "run-command.h"
diff --git a/sequencer.c b/sequencer.c
index 1ee0abbd451..2432d0a39ec 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -13,7 +13,7 @@
#include "dir.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "pager.h"
#include "commit.h"
diff --git a/server-info.c b/server-info.c
index d6cd20a39d7..9bb30d9ab71 100644
--- a/server-info.c
+++ b/server-info.c
@@ -11,7 +11,7 @@
#include "packfile.h"
#include "path.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "server-info.h"
#include "strbuf.h"
#include "tempfile.h"
diff --git a/shallow.c b/shallow.c
index faeeeb45f98..d379756e39a 100644
--- a/shallow.c
+++ b/shallow.c
@@ -5,7 +5,7 @@
#include "repository.h"
#include "tempfile.h"
#include "lockfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tag.h"
#include "pkt-line.h"
diff --git a/streaming.c b/streaming.c
index 6d6512e2e0d..81c42673a23 100644
--- a/streaming.c
+++ b/streaming.c
@@ -10,7 +10,7 @@
#include "streaming.h"
#include "repository.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "packfile.h"
diff --git a/submodule-config.c b/submodule-config.c
index b30d9365fbd..9c80f9f7b66 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -13,7 +13,7 @@
#include "submodule.h"
#include "strbuf.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/submodule.c b/submodule.c
index ead3fb5dadc..9b1018877df 100644
--- a/submodule.c
+++ b/submodule.c
@@ -27,7 +27,7 @@
#include "parse-options.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index 76c2f4eba85..611a13a3261 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -2,7 +2,7 @@
#include "test-tool.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "setup.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index fdf1b13437b..d51aaa3dc40 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pack-mtimes.h"
#include "setup.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 34f1aee5581..dba227259a2 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "hex.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
/*
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 53b633e2ba6..ef5339bbee9 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "bloom.h"
#include "setup.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index ac81390899a..da2aa036b57 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "midx.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "packfile.h"
#include "setup.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 4cfc7c90b59..2920ca59d72 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -5,7 +5,7 @@
#include "refs.h"
#include "setup.h"
#include "worktree.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "strbuf.h"
diff --git a/tag.c b/tag.c
index 05be39067cf..5f6868bf7b1 100644
--- a/tag.c
+++ b/tag.c
@@ -5,7 +5,7 @@
#include "environment.h"
#include "tag.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "blob.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 056484404be..bef2f917cd2 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -10,7 +10,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "quote.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
struct tmp_objdir {
diff --git a/tree-walk.c b/tree-walk.c
index 90655d52378..34b0fff4873 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -6,7 +6,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace2.h"
#include "tree.h"
#include "pathspec.h"
diff --git a/tree.c b/tree.c
index b85f56267fb..341b7c2ff3f 100644
--- a/tree.c
+++ b/tree.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "tree.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "alloc.h"
#include "tree-walk.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 471837f0329..f38c761ab98 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -26,7 +26,7 @@
#include "symlinks.h"
#include "trace2.h"
#include "fsmonitor.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "entry.h"
#include "parallel-checkout.h"
diff --git a/upload-pack.c b/upload-pack.c
index 26f29b85b55..e994d6a901b 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -10,7 +10,7 @@
#include "pkt-line.h"
#include "sideband.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "object.h"
#include "commit.h"
diff --git a/walker.c b/walker.c
index b470d43e54d..a8abe8a2e78 100644
--- a/walker.c
+++ b/walker.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "walker.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "strbuf.h"
#include "tree.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 1edcd319e6e..01e6e378ea6 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "config.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "xdiff-interface.h"
#include "xdiff/xtypes.h"
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 04/17] odb: introduce parent pointers
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (2 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
` (13 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
In subsequent commits we'll get rid of our use of `the_repository` in
"odb.c" in favor of explicitly passing in a `struct object_database` or
a `struct odb_source`. In some cases though we'll need access to the
repository, for example to read a config value from it, but we don't
have a way to access the repository owning a specific object database.
Introduce parent pointers for `struct object_database` to its owning
repository as well as for `struct odb_source` to its owning object
database, which will allow us to adapt those use cases.
Note that this change requires us to pass through the object database to
`link_alt_odb_entry()` so that we can set up the parent pointers for any
source there. The callchain is adapted to pass through the object
database accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 47 +++++++++++++++++++++++++++--------------------
odb.h | 8 +++++++-
repository.c | 3 ++-
3 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/odb.c b/odb.c
index d1025ac182d..afb16f4c693 100644
--- a/odb.c
+++ b/odb.c
@@ -135,11 +135,15 @@ static int alt_odb_usable(struct object_database *o,
* of the object ID, an extra slash for the first level indirection, and
* the terminating NUL.
*/
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth);
-static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
- const char *relative_base, int depth, const char *normalized_objdir)
+
+static int link_alt_odb_entry(struct object_database *odb,
+ const struct strbuf *entry,
+ const char *relative_base,
+ int depth,
+ const char *normalized_objdir)
{
struct odb_source *alternate;
struct strbuf pathbuf = STRBUF_INIT;
@@ -167,22 +171,23 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
strbuf_setlen(&pathbuf, pathbuf.len - 1);
- if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
+ if (!alt_odb_usable(odb, &pathbuf, normalized_objdir, &pos))
goto error;
CALLOC_ARRAY(alternate, 1);
- /* pathbuf.buf is already in r->objects->source_by_path */
+ alternate->odb = odb;
+ /* pathbuf.buf is already in r->objects->alternate_by_path */
alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->sources_tail = alternate;
- r->objects->sources_tail = &(alternate->next);
+ *odb->sources_tail = alternate;
+ odb->sources_tail = &(alternate->next);
alternate->next = NULL;
- assert(r->objects->source_by_path);
- kh_value(r->objects->source_by_path, pos) = alternate;
+ assert(odb->source_by_path);
+ kh_value(odb->source_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, alternate->path, depth + 1);
+ read_info_alternates(odb, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -219,7 +224,7 @@ static const char *parse_alt_odb_entry(const char *string,
return end;
}
-static void link_alt_odb_entries(struct repository *r, const char *alt,
+static void link_alt_odb_entries(struct object_database *odb, const char *alt,
int sep, const char *relative_base, int depth)
{
struct strbuf objdirbuf = STRBUF_INIT;
@@ -234,20 +239,20 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->sources->path, 1);
+ strbuf_realpath(&objdirbuf, odb->sources->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
if (!entry.len)
continue;
- link_alt_odb_entry(r, &entry,
+ link_alt_odb_entry(odb, &entry,
relative_base, depth, objdirbuf.buf);
}
strbuf_release(&entry);
strbuf_release(&objdirbuf);
}
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth)
{
@@ -261,7 +266,7 @@ static void read_info_alternates(struct repository *r,
return;
}
- link_alt_odb_entries(r, buf.buf, '\n', relative_base, depth);
+ link_alt_odb_entries(odb, buf.buf, '\n', relative_base, depth);
strbuf_release(&buf);
free(path);
}
@@ -303,7 +308,7 @@ void add_to_alternates_file(const char *reference)
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
free(alts);
@@ -317,7 +322,7 @@ void add_to_alternates_memory(const char *reference)
*/
prepare_alt_odb(the_repository);
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
@@ -336,6 +341,7 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* alternate
*/
source = xcalloc(1, sizeof(*source));
+ source->odb = the_repository->objects;
source->path = xstrdup(dir);
/*
@@ -580,9 +586,9 @@ void prepare_alt_odb(struct repository *r)
if (r->objects->loaded_alternates)
return;
- link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->sources->path, 0);
+ read_info_alternates(r->objects, r->objects->sources->path, 0);
r->objects->loaded_alternates = 1;
}
@@ -950,11 +956,12 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct object_database *odb_new(void)
+struct object_database *odb_new(struct repository *repo)
{
struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
+ o->repo = repo;
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
diff --git a/odb.h b/odb.h
index 111584a0a09..f1c903d103c 100644
--- a/odb.h
+++ b/odb.h
@@ -28,6 +28,9 @@ struct repository;
struct odb_source {
struct odb_source *next;
+ /* Object database that owns this object source. */
+ struct object_database *odb;
+
/*
* Used to store the results of readdir(3) calls when we are OK
* sacrificing accuracy due to races for speed. That includes
@@ -105,6 +108,9 @@ struct cached_object_entry;
* configured via alternates.
*/
struct object_database {
+ /* Repository that owns this database. */
+ struct repository *repo;
+
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -186,7 +192,7 @@ struct object_database {
unsigned packed_git_initialized : 1;
};
-struct object_database *odb_new(void);
+struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
/*
diff --git a/repository.c b/repository.c
index 13426db0f2b..c606e1153c8 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = odb_new();
+ repo->objects = odb_new(repo);
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -167,6 +167,7 @@ void repo_set_gitdir(struct repository *repo,
if (!repo->objects->sources) {
CALLOC_ARRAY(repo->objects->sources, 1);
+ repo->objects->sources->odb = repo->objects;
repo->objects->sources_tail = &repo->objects->sources->next;
}
expand_base_dir(&repo->objects->sources->path, o->object_dir,
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 05/17] odb: get rid of `the_repository` in `find_odb()`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (3 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 04/17] odb: introduce parent pointers Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
` (12 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Get rid of our dependency on `the_repository` in `find_odb()` by passing
in the object database in which we want to search for the source and
adjusting all callers.
Rename the function to `odb_find_source()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 4 ++--
midx-write.c | 2 +-
odb.c | 6 +++---
odb.h | 7 ++++++-
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index f04eaba5259..77d7e88a98c 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -101,7 +101,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- source = find_odb(the_repository, opts.obj_dir);
+ source = odb_find_source(the_repository->objects, opts.obj_dir);
graph_name = get_commit_graph_filename(source);
chain_name = get_commit_graph_chain_filename(source);
if (open_commit_graph(graph_name, &fd, &st))
@@ -289,7 +289,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- source = find_odb(the_repository, opts.obj_dir);
+ source = odb_find_source(the_repository->objects, opts.obj_dir);
if (opts.reachable) {
if (write_commit_graph_reachable(source, flags, &write_opts))
diff --git a/midx-write.c b/midx-write.c
index ba4a94950a8..f2cfb85476e 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -922,7 +922,7 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
struct strbuf cur_path_real = STRBUF_INIT;
/* Ensure the given object_dir is local, or a known alternate. */
- find_odb(r, obj_dir_real);
+ odb_find_source(r->objects, obj_dir_real);
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
strbuf_realpath(&cur_path_real, cur->object_dir, 1);
diff --git a/odb.c b/odb.c
index afb16f4c693..483b9b38414 100644
--- a/odb.c
+++ b/odb.c
@@ -448,14 +448,14 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct odb_source *find_odb(struct repository *r, const char *obj_dir)
+struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir)
{
struct odb_source *source;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(r);
- for (source = r->objects->sources; source; source = source->next) {
+ prepare_alt_odb(odb->repo);
+ for (source = odb->sources; source; source = source->next) {
strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
diff --git a/odb.h b/odb.h
index f1c903d103c..a9e802f5831 100644
--- a/odb.h
+++ b/odb.h
@@ -68,7 +68,6 @@ struct odb_source {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct odb_source *find_odb(struct repository *r, const char *obj_dir);
typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
@@ -195,6 +194,12 @@ struct object_database {
struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
+/*
+ * Find source by its object directory path. Dies in case the source couldn't
+ * be found.
+ */
+struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+
/*
* Create a temporary file rooted in the object database directory, or
* die on failure. The filename is taken from "pattern", which should have the
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 06/17] odb: get rid of `the_repository` in `assert_oid_type()`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (4 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 07/17] odb: get rid of `the_repository` in `odb_mkstemp()` Patrick Steinhardt
` (11 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Get rid of our dependency on `the_repository` in `assert_oid_type()` by
passing in the object database as a parameter and adjusting all callers.
Rename the function to `odb_assert_oid_type()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-tree.c | 2 +-
commit.c | 2 +-
odb.c | 5 +++--
odb.h | 3 ++-
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 546069f8682..31cfd9bd15d 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -48,7 +48,7 @@ static int parse_parent_arg_callback(const struct option *opt,
if (repo_get_oid_commit(the_repository, arg, &oid))
die(_("not a valid object name %s"), arg);
- assert_oid_type(&oid, OBJ_COMMIT);
+ odb_assert_oid_type(the_repository->objects, &oid, OBJ_COMMIT);
new_parent(lookup_commit(the_repository, &oid), parents);
return 0;
}
diff --git a/commit.c b/commit.c
index 1d30f8ce15a..aa65183d8b6 100644
--- a/commit.c
+++ b/commit.c
@@ -1706,7 +1706,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
/* Not having i18n.commitencoding is the same as having utf-8 */
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
- assert_oid_type(tree, OBJ_TREE);
+ odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);
if (memchr(msg, '\0', msg_len))
return error("a NUL byte in commit log message not allowed.");
diff --git a/odb.c b/odb.c
index 483b9b38414..3a3ceed5508 100644
--- a/odb.c
+++ b/odb.c
@@ -946,9 +946,10 @@ int has_object(struct repository *r, const struct object_id *oid,
return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
}
-void assert_oid_type(const struct object_id *oid, enum object_type expect)
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = oid_object_info(odb->repo, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index a9e802f5831..7b64358d678 100644
--- a/odb.h
+++ b/odb.h
@@ -302,7 +302,8 @@ enum {
int has_object(struct repository *r, const struct object_id *oid,
unsigned flags);
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect);
/*
* Enabling the object read lock allows multiple threads to safely call the
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 07/17] odb: get rid of `the_repository` in `odb_mkstemp()`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (5 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
` (10 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Get rid of our dependency on `the_repository` in `odb_mkstemp()` by
passing in the object database as a parameter and adjusting all callers.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 3 ++-
builtin/index-pack.c | 2 +-
bundle-uri.c | 3 ++-
odb.c | 9 +++++----
odb.h | 7 ++++---
pack-bitmap-write.c | 3 ++-
pack-write.c | 10 ++++++----
7 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 52c792488e1..413304db9b5 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -763,7 +763,8 @@ static void start_packfile(void)
struct packed_git *p;
int pack_fd;
- pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX");
+ pack_fd = odb_mkstemp(the_repository->objects, &tmp_file,
+ "pack/tmp_pack_XXXXXX");
FLEX_ALLOC_STR(p, pack_name, tmp_file.buf);
strbuf_release(&tmp_file);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 1aabe6b8ee2..4d4d989eb1a 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -362,7 +362,7 @@ static const char *open_pack_file(const char *pack_name)
input_fd = 0;
if (!pack_name) {
struct strbuf tmp_file = STRBUF_INIT;
- output_fd = odb_mkstemp(&tmp_file,
+ output_fd = odb_mkstemp(the_repository->objects, &tmp_file,
"pack/tmp_pack_XXXXXX");
pack_name = strbuf_detach(&tmp_file, NULL);
} else {
diff --git a/bundle-uri.c b/bundle-uri.c
index 2e623f8627a..f94e780e967 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -278,7 +278,8 @@ static char *find_temp_filename(void)
* Find a temporary filename that is available. This is briefly
* racy, but unlikely to collide.
*/
- fd = odb_mkstemp(&name, "bundles/tmp_uri_XXXXXX");
+ fd = odb_mkstemp(the_repository->objects, &name,
+ "bundles/tmp_uri_XXXXXX");
if (fd < 0) {
warning(_("failed to create temporary file"));
return NULL;
diff --git a/odb.c b/odb.c
index 3a3ceed5508..73410920a88 100644
--- a/odb.c
+++ b/odb.c
@@ -63,7 +63,8 @@ static const struct cached_object *find_cached_object(struct object_database *ob
return NULL;
}
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern)
{
int fd;
/*
@@ -71,15 +72,15 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
* restrictive except to remove write permission.
*/
int mode = 0444;
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
fd = git_mkstemp_mode(temp_filename->buf, mode);
if (0 <= fd)
return fd;
/* slow path */
/* some mkstemp implementations erase temp_filename on failure */
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
- safe_create_leading_directories(the_repository, temp_filename->buf);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
+ safe_create_leading_directories(odb->repo, temp_filename->buf);
return xmkstemp_mode(temp_filename->buf, mode);
}
diff --git a/odb.h b/odb.h
index 7b64358d678..418a57a5487 100644
--- a/odb.h
+++ b/odb.h
@@ -201,12 +201,13 @@ void odb_clear(struct object_database *o);
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
/*
- * Create a temporary file rooted in the object database directory, or
- * die on failure. The filename is taken from "pattern", which should have the
+ * Create a temporary file rooted in the primary alternate's directory, or die
+ * on failure. The filename is taken from "pattern", which should have the
* usual "XXXXXX" trailer, and the resulting filename is written into the
* "template" buffer. Returns the open descriptor.
*/
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern);
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 37648b57125..c847369eaaa 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1052,7 +1052,8 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
struct bitmap_disk_header header;
- int fd = odb_mkstemp(&tmp_file, "pack/tmp_bitmap_XXXXXX");
+ int fd = odb_mkstemp(writer->repo->objects, &tmp_file,
+ "pack/tmp_bitmap_XXXXXX");
if (writer->pseudo_merges_nr)
options |= BITMAP_OPT_PSEUDO_MERGES;
diff --git a/pack-write.c b/pack-write.c
index 6b06315f80a..eccdc798e36 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -84,7 +84,8 @@ const char *write_idx_file(struct repository *repo,
} else {
if (!index_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_idx_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_idx_XXXXXX");
index_name = strbuf_detach(&tmp_file, NULL);
} else {
unlink(index_name);
@@ -259,7 +260,8 @@ char *write_rev_file_order(struct repository *repo,
if (flags & WRITE_REV) {
if (!rev_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_rev_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_rev_XXXXXX");
path = strbuf_detach(&tmp_file, NULL);
} else {
unlink(rev_name);
@@ -342,7 +344,7 @@ static char *write_mtimes_file(struct repository *repo,
if (!to_pack)
BUG("cannot call write_mtimes_file with NULL packing_data");
- fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file, "pack/tmp_mtimes_XXXXXX");
mtimes_name = strbuf_detach(&tmp_file, NULL);
f = hashfd(repo->hash_algo, fd, mtimes_name);
@@ -531,7 +533,7 @@ struct hashfile *create_tmp_packfile(struct repository *repo,
struct strbuf tmpname = STRBUF_INIT;
int fd;
- fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmpname, "pack/tmp_pack_XXXXXX");
*pack_tmp_name = strbuf_detach(&tmpname, NULL);
return hashfd(repo->hash_algo, fd, *pack_tmp_name);
}
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 08/17] odb: get rid of `the_repository` when handling alternates
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (6 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 07/17] odb: get rid of `the_repository` in `odb_mkstemp()` Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
` (9 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The functions to manage alternates all depend on `the_repository`.
Refactor them to accept an object database as parameter and adjusting
all callers. The functions are renamed accordingly.
Note that right now the situation is still somewhat weird because we end
up using the path provided by the object store's repository anyway. This
will be adapted over time though so that we instead store the path to
the primary object directory in the object database itself.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/clone.c | 10 +++++----
builtin/fsck.c | 6 +++---
builtin/grep.c | 2 +-
builtin/repack.c | 3 ++-
commit-graph.c | 4 ++--
loose.c | 2 +-
object-file.c | 10 ++++-----
object-name.c | 2 +-
odb.c | 44 ++++++++++++++++++---------------------
odb.h | 53 ++++++++++++++++++++++++++++++++---------------
packfile.c | 4 ++--
submodule.c | 3 ++-
t/helper/test-ref-store.c | 2 +-
tmp-objdir.c | 2 +-
14 files changed, 83 insertions(+), 64 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 1eafeefb48d..3aabdf6570b 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -171,7 +171,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
} else {
struct strbuf sb = STRBUF_INIT;
strbuf_addf(&sb, "%s/objects", ref_git);
- add_to_alternates_file(sb.buf);
+ odb_add_to_alternates_file(the_repository->objects, sb.buf);
strbuf_release(&sb);
}
@@ -212,12 +212,14 @@ static void copy_alternates(struct strbuf *src, const char *src_repo)
if (!line.len || line.buf[0] == '#')
continue;
if (is_absolute_path(line.buf)) {
- add_to_alternates_file(line.buf);
+ odb_add_to_alternates_file(the_repository->objects,
+ line.buf);
continue;
}
abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
if (!normalize_path_copy(abs_path, abs_path))
- add_to_alternates_file(abs_path);
+ odb_add_to_alternates_file(the_repository->objects,
+ abs_path);
else
warning("skipping invalid relative alternate: %s/%s",
src_repo, line.buf);
@@ -352,7 +354,7 @@ static void clone_local(const char *src_repo, const char *dest_repo)
struct strbuf alt = STRBUF_INIT;
get_common_dir(&alt, src_repo);
strbuf_addstr(&alt, "/objects");
- add_to_alternates_file(alt.buf);
+ odb_add_to_alternates_file(the_repository->objects, alt.buf);
strbuf_release(&alt);
} else {
struct strbuf src = STRBUF_INIT;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 9abd7b25580..014aa1344e2 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -997,7 +997,7 @@ int cmd_fsck(int argc,
for_each_packed_object(the_repository,
mark_packed_for_connectivity, NULL, 0);
} else {
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next)
fsck_object_dir(source->path);
@@ -1108,7 +1108,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_commit_graph) {
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
@@ -1126,7 +1126,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_multi_pack_index) {
struct child_process midx_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
diff --git a/builtin/grep.c b/builtin/grep.c
index a1d7ee7af39..336cfcab6fb 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -462,7 +462,7 @@ static int grep_submodule(struct grep_opt *opt,
/*
* NEEDSWORK: repo_read_gitmodules() might call
- * add_to_alternates_memory() via config_from_gitmodules(). This
+ * odb_add_to_alternates_memory() via config_from_gitmodules(). This
* operation causes a race condition with concurrent object readings
* performed by the worker threads. That's why we need obj_read_lock()
* here. It should be removed once it's no longer necessary to add the
diff --git a/builtin/repack.c b/builtin/repack.c
index 16782320058..8145474cf8d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1256,7 +1256,8 @@ int cmd_repack(int argc,
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
die(_(incremental_bitmap_conflict_error));
- if (write_bitmaps && po_args.local && has_alt_odb(the_repository)) {
+ if (write_bitmaps && po_args.local &&
+ odb_has_alternates(the_repository->objects)) {
/*
* When asked to do a local repack, but we have
* packfiles that are inherited from an alternate, then
diff --git a/commit-graph.c b/commit-graph.c
index 6ced5b366e7..59265f89385 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -649,7 +649,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
count = st->st_size / (the_hash_algo->hexsz + 1);
CALLOC_ARRAY(oids, count);
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (i = 0; i < count; i++) {
struct odb_source *source;
@@ -778,7 +778,7 @@ static int prepare_commit_graph(struct repository *r)
if (!commit_graph_compatible(r))
return 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources;
!r->objects->commit_graph && source;
source = source->next)
diff --git a/loose.c b/loose.c
index fab4041c03d..519f5db7935 100644
--- a/loose.c
+++ b/loose.c
@@ -112,7 +112,7 @@ int repo_read_loose_object_map(struct repository *repo)
if (!should_use_loose_object_map(repo))
return 0;
- prepare_alt_odb(repo);
+ odb_prepare_alternates(repo->objects);
for (source = repo->objects->sources; source; source = source->next) {
if (load_one_loose_object_map(repo, source) < 0) {
diff --git a/object-file.c b/object-file.c
index 2d3af8a77c0..04da19a1a3b 100644
--- a/object-file.c
+++ b/object-file.c
@@ -106,7 +106,7 @@ static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
struct odb_source *source;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources->next; source; source = source->next) {
if (check_and_freshen_odb(source, oid, freshen))
return 1;
@@ -205,7 +205,7 @@ static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct odb_source *source;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
*path = odb_loose_path(source, &buf, oid);
if (!lstat(*path, st))
@@ -227,7 +227,7 @@ static int open_loose_object(struct repository *r,
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
*path = odb_loose_path(source, &buf, oid);
fd = git_open(*path);
@@ -246,7 +246,7 @@ static int quick_has_loose(struct repository *r,
{
struct odb_source *source;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
if (oidtree_contains(odb_loose_cache(source, oid), oid))
return 1;
@@ -1439,7 +1439,7 @@ int for_each_loose_object(each_loose_object_fn cb, void *data,
{
struct odb_source *source;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next) {
int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
NULL, data);
diff --git a/object-name.c b/object-name.c
index 544634d0f40..381536e900e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -376,7 +376,7 @@ static int init_object_disambiguation(struct repository *r,
ds->hex_pfx[len] = '\0';
ds->repo = r;
ds->bin_pfx.algo = algo ? hash_algo_by_ptr(algo) : GIT_HASH_UNKNOWN;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
return 0;
}
diff --git a/odb.c b/odb.c
index 73410920a88..42862ef7fe7 100644
--- a/odb.c
+++ b/odb.c
@@ -272,10 +272,11 @@ static void read_info_alternates(struct object_database *odb,
free(path);
}
-void add_to_alternates_file(const char *reference)
+void odb_add_to_alternates_file(struct object_database *odb,
+ const char *reference)
{
struct lock_file lock = LOCK_INIT;
- char *alts = repo_git_path(the_repository, "objects/info/alternates");
+ char *alts = repo_git_path(odb->repo, "objects/info/alternates");
FILE *in, *out;
int found = 0;
@@ -308,22 +309,23 @@ void add_to_alternates_file(const char *reference)
fprintf_or_die(out, "%s\n", reference);
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
- if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository->objects, reference,
+ if (odb->loaded_alternates)
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
free(alts);
}
-void add_to_alternates_memory(const char *reference)
+void odb_add_to_alternates_memory(struct object_database *odb,
+ const char *reference)
{
/*
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(odb);
- link_alt_odb_entries(the_repository->objects, reference,
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
@@ -335,7 +337,7 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
/*
* Make a new primary odb and link the old primary ODB in as an
@@ -379,12 +381,6 @@ void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
free_object_directory(cur_alt);
}
-/*
- * Compute the exact path an alternate is at and returns it. In case of
- * error NULL is returned and the human readable error is added to `err`
- * `path` may be relative and should point to $GIT_DIR.
- * `err` must not be null.
- */
char *compute_alternate_path(const char *path, struct strbuf *err)
{
char *ref_git = NULL;
@@ -455,7 +451,7 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(odb->repo);
+ odb_prepare_alternates(odb);
for (source = odb->sources; source; source = source->next) {
strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
@@ -573,7 +569,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
struct odb_source *alternate;
int r = 0;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
r = fn(alternate, cb);
if (r)
@@ -582,21 +578,21 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
return r;
}
-void prepare_alt_odb(struct repository *r)
+void odb_prepare_alternates(struct object_database *odb)
{
- if (r->objects->loaded_alternates)
+ if (odb->loaded_alternates)
return;
- link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(odb, odb->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r->objects, r->objects->sources->path, 0);
- r->objects->loaded_alternates = 1;
+ read_info_alternates(odb, odb->sources->path, 0);
+ odb->loaded_alternates = 1;
}
-int has_alt_odb(struct repository *r)
+int odb_has_alternates(struct object_database *odb)
{
- prepare_alt_odb(r);
- return !!r->objects->sources->next;
+ odb_prepare_alternates(odb);
+ return !!odb->sources->next;
}
int obj_read_use_lock = 0;
diff --git a/odb.h b/odb.h
index 418a57a5487..abe3d2c7a80 100644
--- a/odb.h
+++ b/odb.h
@@ -13,6 +13,14 @@ struct oidtree;
struct strbuf;
struct repository;
+/*
+ * Compute the exact path an alternate is at and returns it. In case of
+ * error NULL is returned and the human readable error is added to `err`
+ * `path` may be relative and should point to $GIT_DIR.
+ * `err` must not be null.
+ */
+char *compute_alternate_path(const char *path, struct strbuf *err);
+
/*
* The source is the part of the object database that stores the actual
* objects. It thus encapsulates the logic to read and write the specific
@@ -65,27 +73,11 @@ struct odb_source {
char *path;
};
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
-/*
- * 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);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -124,7 +116,7 @@ struct object_database {
/*
* A list of alternate object directories loaded from the environment;
* this should not generally need to be accessed directly, but will
- * populate the "sources" list when prepare_alt_odb() is run.
+ * populate the "sources" list when odb_prepare_alternates() is run.
*/
char *alternate_db;
@@ -209,6 +201,33 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
int odb_mkstemp(struct object_database *odb,
struct strbuf *temp_filename, const char *pattern);
+/*
+ * Prepare alternate object sources for the given database by reading
+ * "objects/info/alternates" and opening the respective sources.
+ */
+void odb_prepare_alternates(struct object_database *odb);
+
+/*
+ * Check whether the object database has any alternates. The primary object
+ * source does not count as alternate.
+ */
+int odb_has_alternates(struct object_database *odb);
+
+/*
+ * Add the directory to the on-disk alternates file; the new entry will also
+ * take effect in the current process.
+ */
+void odb_add_to_alternates_file(struct object_database *odb,
+ const char *dir);
+
+/*
+ * Add the directory to the in-memory list of alternate sources (along with any
+ * recursive alternates it points to), but do not modify the on-disk alternates
+ * file.
+ */
+void odb_add_to_alternates_memory(struct object_database *odb,
+ const char *dir);
+
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,
diff --git a/packfile.c b/packfile.c
index 346c2f9ce90..ac0e29e99b9 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1034,7 +1034,7 @@ static void prepare_packed_git(struct repository *r)
if (r->objects->packed_git_initialized)
return;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
int local = (source == r->objects->sources);
prepare_multi_pack_index_one(r, source->path, local);
@@ -1059,7 +1059,7 @@ void reprepare_packed_git(struct repository *r)
* the lifetime of the process.
*/
r->objects->loaded_alternates = 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next)
odb_clear_loose_cache(source);
diff --git a/submodule.c b/submodule.c
index 9b1018877df..386be234230 100644
--- a/submodule.c
+++ b/submodule.c
@@ -189,7 +189,8 @@ int register_all_submodule_odb_as_alternates(void)
int ret = added_submodule_odb_paths.nr;
for (i = 0; i < added_submodule_odb_paths.nr; i++)
- add_to_alternates_memory(added_submodule_odb_paths.items[i].string);
+ odb_add_to_alternates_memory(the_repository->objects,
+ added_submodule_odb_paths.items[i].string);
if (ret) {
string_list_clear(&added_submodule_odb_paths, 0);
trace2_data_intmax("submodule", the_repository,
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 2920ca59d72..8d9a271845c 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -79,7 +79,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)
if (!repo_submodule_path_append(the_repository,
&sb, gitdir, "objects/"))
die("computing submodule path failed");
- add_to_alternates_memory(sb.buf);
+ odb_add_to_alternates_memory(the_repository->objects, sb.buf);
strbuf_release(&sb);
*refs = repo_get_submodule_ref_store(the_repository, gitdir);
diff --git a/tmp-objdir.c b/tmp-objdir.c
index bef2f917cd2..4120badf5ce 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -304,7 +304,7 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)
void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
{
- add_to_alternates_memory(t->path.buf);
+ odb_add_to_alternates_memory(t->repo->objects, t->path.buf);
}
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 09/17] odb: get rid of `the_repository` in `for_each()` functions
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (7 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 10/17] odb: get rid of `the_repository` when handling the primary source Patrick Steinhardt
` (8 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
There are a couple of iterator-style functions that execute a callback
for each instance of a given set, all of which currently depend on
`the_repository`. Refactor them to instead take an object database as
parameter so that we can get rid of this dependency.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/count-objects.c | 2 +-
builtin/receive-pack.c | 3 ++-
builtin/submodule--helper.c | 3 ++-
diagnose.c | 2 +-
fetch-pack.c | 3 ++-
odb.c | 36 +++++++++++++++++++-----------------
odb.h | 23 ++++++++++++++++++-----
revision.c | 3 ++-
8 files changed, 47 insertions(+), 28 deletions(-)
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 58e0af433d1..f687647931e 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -159,7 +159,7 @@ int cmd_count_objects(int argc,
printf("prune-packable: %lu\n", packed_loose);
printf("garbage: %lu\n", garbage);
printf("size-garbage: %s\n", garbage_buf.buf);
- foreach_alt_odb(print_alternate, NULL);
+ odb_for_each_alternate(the_repository->objects, print_alternate, NULL);
strbuf_release(&loose_buf);
strbuf_release(&pack_buf);
strbuf_release(&garbage_buf);
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 0f5958c4a66..7ea273d93e4 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -359,7 +359,8 @@ static void write_head_info(void)
refs_for_each_fullref_in(get_main_ref_store(the_repository), "",
exclude_patterns, show_ref_cb, &seen);
- for_each_alternate_ref(show_one_alternate_ref, &seen);
+ odb_for_each_alternate_ref(the_repository->objects,
+ show_one_alternate_ref, &seen);
oidset_clear(&seen);
strvec_clear(&excludes_vector);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 84f7fa53424..7ca483cab52 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1668,7 +1668,8 @@ static void prepare_possible_alternates(const char *sm_name,
die(_("Value '%s' for submodule.alternateErrorStrategy is not recognized"), error_strategy);
if (!strcmp(sm_alternate, "superproject"))
- foreach_alt_odb(add_possible_reference_from_superproject, &sas);
+ odb_for_each_alternate(the_repository->objects,
+ add_possible_reference_from_superproject, &sas);
else if (!strcmp(sm_alternate, "no"))
; /* do nothing */
else
diff --git a/diagnose.c b/diagnose.c
index ad0d5c12465..5092bf80d35 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -229,7 +229,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
dir_file_stats(r->objects->sources, &buf);
- foreach_alt_odb(dir_file_stats, &buf);
+ odb_for_each_alternate(r->objects, dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
strbuf_reset(&buf);
diff --git a/fetch-pack.c b/fetch-pack.c
index cf157f5d7e5..47fa7fa4c49 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -115,7 +115,8 @@ static void for_each_cached_alternate(struct fetch_negotiator *negotiator,
size_t i;
if (!initialized) {
- for_each_alternate_ref(cache_one_alternate, &cache);
+ odb_for_each_alternate_ref(the_repository->objects,
+ cache_one_alternate, &cache);
initialized = 1;
}
diff --git a/odb.c b/odb.c
index 42862ef7fe7..d83f7416e9e 100644
--- a/odb.c
+++ b/odb.c
@@ -494,8 +494,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
}
static void read_alternate_refs(const char *path,
- alternate_ref_fn *cb,
- void *data)
+ odb_for_each_alternate_ref_fn *cb,
+ void *payload)
{
struct child_process cmd = CHILD_PROCESS_INIT;
struct strbuf line = STRBUF_INIT;
@@ -517,7 +517,7 @@ static void read_alternate_refs(const char *path,
break;
}
- cb(&oid, data);
+ cb(&oid, payload);
}
fclose(fh);
@@ -526,16 +526,16 @@ static void read_alternate_refs(const char *path,
}
struct alternate_refs_data {
- alternate_ref_fn *fn;
- void *data;
+ odb_for_each_alternate_ref_fn *fn;
+ void *payload;
};
static int refs_from_alternate_cb(struct odb_source *alternate,
- void *data)
+ void *payload)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
- struct alternate_refs_data *cb = data;
+ struct alternate_refs_data *cb = payload;
if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
@@ -549,29 +549,31 @@ static int refs_from_alternate_cb(struct odb_source *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->data);
+ read_alternate_refs(path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
return 0;
}
-void for_each_alternate_ref(alternate_ref_fn fn, void *data)
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload)
{
- struct alternate_refs_data cb;
- cb.fn = fn;
- cb.data = data;
- foreach_alt_odb(refs_from_alternate_cb, &cb);
+ struct alternate_refs_data data;
+ data.fn = cb;
+ data.payload = payload;
+ odb_for_each_alternate(odb, refs_from_alternate_cb, &data);
}
-int foreach_alt_odb(alt_odb_fn fn, void *cb)
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload)
{
struct odb_source *alternate;
int r = 0;
- odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
- r = fn(alternate, cb);
+ odb_prepare_alternates(odb);
+ for (alternate = odb->sources->next; alternate; alternate = alternate->next) {
+ r = cb(alternate, payload);
if (r)
break;
}
diff --git a/odb.h b/odb.h
index abe3d2c7a80..82ddbb71e46 100644
--- a/odb.h
+++ b/odb.h
@@ -73,11 +73,6 @@ struct odb_source {
char *path;
};
-typedef int alt_odb_fn(struct odb_source *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -192,6 +187,24 @@ void odb_clear(struct object_database *o);
*/
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+/*
+ * Iterate through all alternates of the database and execute the provided
+ * callback function for each of them. Stop iterating once the callback
+ * function returns a non-zero value, in which case the value is bubbled up
+ * from the callback.
+ */
+typedef int odb_for_each_alternate_fn(struct odb_source *, void *);
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload);
+
+/*
+ * Iterate through all alternates of the database and yield their respective
+ * references.
+ */
+typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload);
+
/*
* Create a temporary file rooted in the primary alternate's directory, or die
* on failure. The filename is taken from "pattern", which should have the
diff --git a/revision.c b/revision.c
index cdefe7d6e48..b0364f556ee 100644
--- a/revision.c
+++ b/revision.c
@@ -1907,7 +1907,8 @@ static void add_alternate_refs_to_pending(struct rev_info *revs,
struct add_alternate_refs_data data;
data.revs = revs;
data.flags = flags;
- for_each_alternate_ref(add_one_alternate_ref, &data);
+ odb_for_each_alternate_ref(the_repository->objects,
+ add_one_alternate_ref, &data);
}
static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 10/17] odb: get rid of `the_repository` when handling the primary source
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (8 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 11/17] odb: get rid of `the_repository` when handling submodule sources Patrick Steinhardt
` (7 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The functions `set_temporary_primary_odb()` and `restore_primary_odb()`
are responsible for managing a temporary primary source for the
database. Both of these functions implicitly rely on `the_repository`.
Refactor them to instead take an explicit object database parameter as
argument and adjust callers. Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 27 +++++++++++++++------------
odb.h | 25 ++++++++++++++-----------
tmp-objdir.c | 10 ++++++----
3 files changed, 35 insertions(+), 27 deletions(-)
diff --git a/odb.c b/odb.c
index d83f7416e9e..b154e91953d 100644
--- a/odb.c
+++ b/odb.c
@@ -329,7 +329,8 @@ void odb_add_to_alternates_memory(struct object_database *odb,
'\n', NULL, 0);
}
-struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
+ const char *dir, int will_destroy)
{
struct odb_source *source;
@@ -337,14 +338,14 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- odb_prepare_alternates(the_repository->objects);
+ odb_prepare_alternates(odb);
/*
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
source = xcalloc(1, sizeof(*source));
- source->odb = the_repository->objects;
+ source->odb = odb;
source->path = xstrdup(dir);
/*
@@ -353,8 +354,8 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
*/
source->disable_ref_updates = 1;
source->will_destroy = will_destroy;
- source->next = the_repository->objects->sources;
- the_repository->objects->sources = source;
+ source->next = odb->sources;
+ odb->sources = source;
return source->next;
}
@@ -366,19 +367,21 @@ static void free_object_directory(struct odb_source *source)
free(source);
}
-void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
+void odb_restore_primary_source(struct object_database *odb,
+ struct odb_source *restore_source,
+ const char *old_path)
{
- struct odb_source *cur_alt = the_repository->objects->sources;
+ struct odb_source *cur_source = odb->sources;
- if (strcmp(old_path, cur_alt->path))
+ if (strcmp(old_path, cur_source->path))
BUG("expected %s as primary object store; found %s",
- old_path, cur_alt->path);
+ old_path, cur_source->path);
- if (cur_alt->next != restore_alt)
+ if (cur_source->next != restore_source)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->sources = restore_alt;
- free_object_directory(cur_alt);
+ odb->sources = restore_source;
+ free_object_directory(cur_source);
}
char *compute_alternate_path(const char *path, struct strbuf *err)
diff --git a/odb.h b/odb.h
index 82ddbb71e46..5acfda88fa7 100644
--- a/odb.h
+++ b/odb.h
@@ -73,17 +73,6 @@ struct odb_source {
char *path;
};
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy);
-
-/*
- * Restore a previous ODB replaced by set_temporary_main_odb.
- */
-void restore_primary_odb(struct odb_source *restore_alternate, const char *old_path);
-
struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
@@ -187,6 +176,20 @@ void odb_clear(struct object_database *o);
*/
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary source.
+ */
+struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
+ const char *dir, int will_destroy);
+
+/*
+ * Restore a previous backend replaced by `odb_set_temporary_primary_source()`.
+ */
+void odb_restore_primary_source(struct object_database *odb,
+ struct odb_source *restore_source,
+ const char *old_path);
+
/*
* Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 4120badf5ce..ae01eae9c41 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -47,7 +47,7 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
the_tmp_objdir = NULL;
if (t->prev_source)
- restore_primary_odb(t->prev_source, t->path.buf);
+ odb_restore_primary_source(t->repo->objects, t->prev_source, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -279,7 +279,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (t->prev_source) {
if (t->repo->objects->sources->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_source, t->path.buf);
+ odb_restore_primary_source(t->repo->objects, t->prev_source, t->path.buf);
t->prev_source = NULL;
}
@@ -311,7 +311,8 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
if (t->prev_source)
BUG("the primary object database is already replaced");
- t->prev_source = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_source = odb_set_temporary_primary_source(t->repo->objects,
+ t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
@@ -320,7 +321,8 @@ struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
if (!the_tmp_objdir || !the_tmp_objdir->prev_source)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
+ odb_restore_primary_source(the_tmp_objdir->repo->objects,
+ the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
the_tmp_objdir->prev_source = NULL;
return the_tmp_objdir;
}
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 11/17] odb: get rid of `the_repository` when handling submodule sources
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (9 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 10/17] odb: get rid of `the_repository` when handling the primary source Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
` (6 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The "--recursive" flag for git-grep(1) allows users to grep for a string
across submodule boundaries. To make this work we add each submodule's
object sources to our own object database so that the objects can be
accessed directly.
The infrastructure for this depends on a global string list of submodule
paths. The caller is expected to call `add_submodule_odb_by_path()` for
each source and the object database will then eventually register all
submodule sources via `do_oid_object_info_extended()` in case it isn't
able to look up a specific object.
This reliance on global state is of course suboptimal with regards to
our libification efforts.
Refactor the logic so that the list of submodule sources is instead
tracked in the object database itself. This allows us to lose the
condition of `r == the_repository` before registering submodule sources
as we only ever add submodule sources to `the_repository` anyway. As
such, behaviour before and after this refactoring should always be the
same.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/grep.c | 3 ++-
odb.c | 37 +++++++++++++++++++++++++++++++------
odb.h | 15 +++++++++++++++
submodule-config.c | 3 ++-
submodule.c | 26 --------------------------
submodule.h | 9 ---------
6 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 336cfcab6fb..cfcf916bce1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,8 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->sources->path);
+ odb_add_submodule_source_by_path(the_repository->objects,
+ subrepo->objects->sources->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/odb.c b/odb.c
index b154e91953d..793903cb046 100644
--- a/odb.c
+++ b/odb.c
@@ -24,6 +24,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "submodule.h"
+#include "trace2.h"
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
@@ -469,6 +470,12 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
return source;
}
+void odb_add_submodule_source_by_path(struct object_database *odb,
+ const char *path)
+{
+ string_list_insert(&odb->submodule_source_paths, path);
+}
+
static void fill_alternate_refs_command(struct child_process *cmd,
const char *repo_path)
{
@@ -623,6 +630,23 @@ void disable_obj_read_lock(void)
int fetch_if_missing = 1;
+static int register_all_submodule_alternates(struct object_database *odb)
+{
+ int ret = odb->submodule_source_paths.nr;
+
+ for (size_t i = 0; i < odb->submodule_source_paths.nr; i++)
+ odb_add_to_alternates_memory(odb,
+ odb->submodule_source_paths.items[i].string);
+ if (ret) {
+ string_list_clear(&odb->submodule_source_paths, 0);
+ trace2_data_intmax("submodule", odb->repo,
+ "register_all_submodule_alternates/registered", ret);
+ if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
+ BUG("register_all_submodule_alternates() called");
+ }
+ return ret;
+}
+
static int do_oid_object_info_extended(struct repository *r,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
@@ -676,13 +700,12 @@ static int do_oid_object_info_extended(struct repository *r,
}
/*
- * If r is the_repository, this might be an attempt at
- * accessing a submodule object as if it were in the_repository
- * (having called add_submodule_odb() on that submodule's ODB).
- * If any such ODBs exist, register them and try again.
+ * This might be an attempt at accessing a submodule object as
+ * if it were in main object store (having called
+ * `odb_add_submodule_source_by_path()` on that submodule's
+ * ODB). If any such ODBs exist, register them and try again.
*/
- if (r == the_repository &&
- register_all_submodule_odb_as_alternates())
+ if (register_all_submodule_alternates(r->objects))
/* We added some alternates; retry */
continue;
@@ -968,6 +991,7 @@ struct object_database *odb_new(struct repository *repo)
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
+ string_list_init_dup(&o->submodule_source_paths);
return o;
}
@@ -1017,4 +1041,5 @@ void odb_clear(struct object_database *o)
o->packed_git = NULL;
hashmap_clear(&o->pack_map);
+ string_list_clear(&o->submodule_source_paths, 0);
}
diff --git a/odb.h b/odb.h
index 5acfda88fa7..4e6029ec542 100644
--- a/odb.h
+++ b/odb.h
@@ -6,6 +6,7 @@
#include "list.h"
#include "oidset.h"
#include "oidmap.h"
+#include "string-list.h"
#include "thread-utils.h"
struct oidmap;
@@ -165,6 +166,12 @@ struct object_database {
* packs.
*/
unsigned packed_git_initialized : 1;
+
+ /*
+ * Submodule source paths that will be added as additional sources to
+ * allow lookup of submodule objects via the main object database.
+ */
+ struct string_list submodule_source_paths;
};
struct object_database *odb_new(struct repository *repo);
@@ -190,6 +197,14 @@ void odb_restore_primary_source(struct object_database *odb,
struct odb_source *restore_source,
const char *old_path);
+/*
+ * Call odb_add_submodule_source_by_path() to add the submodule at the given
+ * path to a list. The object stores of all submodules in that list will be
+ * added as additional sources in the object store when looking up objects.
+ */
+void odb_add_submodule_source_by_path(struct object_database *odb,
+ const char *path);
+
/*
* Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/submodule-config.c b/submodule-config.c
index 9c80f9f7b66..a9f72107888 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,8 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->sources->path);
+ odb_add_submodule_source_by_path(the_repository->objects,
+ repo->objects->sources->path);
} else {
goto out;
}
diff --git a/submodule.c b/submodule.c
index 386be234230..788c9e55ed3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -31,7 +31,6 @@
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
-#include "trace2.h"
static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
static int initialized_fetch_ref_tips;
@@ -176,31 +175,6 @@ void stage_updated_gitmodules(struct index_state *istate)
die(_("staging updated .gitmodules failed"));
}
-static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_DUP;
-
-void add_submodule_odb_by_path(const char *path)
-{
- string_list_insert(&added_submodule_odb_paths, path);
-}
-
-int register_all_submodule_odb_as_alternates(void)
-{
- int i;
- int ret = added_submodule_odb_paths.nr;
-
- for (i = 0; i < added_submodule_odb_paths.nr; i++)
- odb_add_to_alternates_memory(the_repository->objects,
- added_submodule_odb_paths.items[i].string);
- if (ret) {
- string_list_clear(&added_submodule_odb_paths, 0);
- trace2_data_intmax("submodule", the_repository,
- "register_all_submodule_odb_as_alternates/registered", ret);
- if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
- BUG("register_all_submodule_odb_as_alternates() called");
- }
- return ret;
-}
-
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
const char *path)
{
diff --git a/submodule.h b/submodule.h
index db980c1d083..b10e16e6c06 100644
--- a/submodule.h
+++ b/submodule.h
@@ -104,15 +104,6 @@ int submodule_uses_gitfile(const char *path);
#define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
int bad_to_remove_submodule(const char *path, unsigned flags);
-/*
- * Call add_submodule_odb_by_path() to add the submodule at the given
- * path to a list. When register_all_submodule_odb_as_alternates() is
- * called, the object stores of all submodules in that list will be
- * added as alternates in the_repository.
- */
-void add_submodule_odb_by_path(const char *path);
-int register_all_submodule_odb_as_alternates(void);
-
/*
* Checks if there are submodule changes in a..b. If a is the null OID,
* checks b and all its ancestors instead.
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 12/17] odb: trivial refactorings to get rid of `the_repository`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (10 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 11/17] odb: get rid of `the_repository` when handling submodule sources Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
` (5 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
All of the external functions provided by the object database subsystem
don't depend on `the_repository` anymore, but some internal functions
still do. Refactor those cases by plumbing through the repository that
owns the object database.
This change allows us to get rid of the `USE_THE_REPOSITORY_VARIABLE`
preprocessor define.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/odb.c b/odb.c
index 793903cb046..a13b9ecbbc9 100644
--- a/odb.c
+++ b/odb.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "abspath.h"
#include "commit-graph.h"
@@ -476,12 +474,13 @@ void odb_add_submodule_source_by_path(struct object_database *odb,
string_list_insert(&odb->submodule_source_paths, path);
}
-static void fill_alternate_refs_command(struct child_process *cmd,
+static void fill_alternate_refs_command(struct repository *repo,
+ struct child_process *cmd,
const char *repo_path)
{
const char *value;
- if (!git_config_get_value("core.alternateRefsCommand", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsCommand", &value)) {
cmd->use_shell = 1;
strvec_push(&cmd->args, value);
@@ -493,7 +492,7 @@ static void fill_alternate_refs_command(struct child_process *cmd,
strvec_push(&cmd->args, "for-each-ref");
strvec_push(&cmd->args, "--format=%(objectname)");
- if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsPrefixes", &value)) {
strvec_push(&cmd->args, "--");
strvec_split(&cmd->args, value);
}
@@ -503,7 +502,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
cmd->out = -1;
}
-static void read_alternate_refs(const char *path,
+static void read_alternate_refs(struct repository *repo,
+ const char *path,
odb_for_each_alternate_ref_fn *cb,
void *payload)
{
@@ -511,7 +511,7 @@ static void read_alternate_refs(const char *path,
struct strbuf line = STRBUF_INIT;
FILE *fh;
- fill_alternate_refs_command(&cmd, path);
+ fill_alternate_refs_command(repo, &cmd, path);
if (start_command(&cmd))
return;
@@ -521,7 +521,7 @@ static void read_alternate_refs(const char *path,
struct object_id oid;
const char *p;
- if (parse_oid_hex(line.buf, &oid, &p) || *p) {
+ if (parse_oid_hex_algop(line.buf, &oid, &p, repo->hash_algo) || *p) {
warning(_("invalid line while parsing alternate refs: %s"),
line.buf);
break;
@@ -559,7 +559,7 @@ static int refs_from_alternate_cb(struct odb_source *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->payload);
+ read_alternate_refs(alternate->odb->repo, path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, the_repository->hash_algo);
+ oidclr(oi->delta_base_oid, r->hash_algo);
if (oi->contentp)
*oi->contentp = xmemdupz(co->buf, co->size);
oi->whence = OI_CACHED;
@@ -763,10 +763,10 @@ static int oid_object_info_convert(struct repository *r,
void *content;
int ret;
- if (repo_oid_to_algop(r, input_oid, the_hash_algo, &oid)) {
+ if (repo_oid_to_algop(r, input_oid, r->hash_algo, &oid)) {
if (do_die)
die(_("missing mapping of %s to %s"),
- oid_to_hex(input_oid), the_hash_algo->name);
+ oid_to_hex(input_oid), r->hash_algo->name);
return -1;
}
@@ -797,8 +797,8 @@ static int oid_object_info_convert(struct repository *r,
struct strbuf outbuf = STRBUF_INIT;
if (type != OBJ_BLOB) {
- ret = convert_object_file(the_repository, &outbuf,
- the_hash_algo, input_algo,
+ ret = convert_object_file(r, &outbuf,
+ r->hash_algo, input_algo,
content, size, type, !do_die);
free(content);
if (ret == -1)
@@ -944,9 +944,9 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + the_hash_algo->hexsz > isize ||
+ if (ref_length + r->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
free(buffer);
return NULL;
}
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 13/17] odb: rename `oid_object_info()`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (11 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
` (4 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `oid_object_info()` to `odb_read_object_info()` as well as their
`_extended()` variant to match other functions related to the object
database and our modern coding guidelines.
Introduce compatibility wrappers so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
archive.c | 2 +-
blame.c | 4 +--
builtin/blame.c | 4 +--
builtin/cat-file.c | 26 ++++++++++---------
builtin/describe.c | 3 ++-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 17 ++++++------
builtin/fsck.c | 7 ++---
builtin/gc.c | 2 +-
builtin/grep.c | 2 +-
builtin/index-pack.c | 13 +++++-----
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 4 +--
builtin/mktree.c | 8 +++---
builtin/pack-objects.c | 30 ++++++++++++----------
builtin/prune.c | 4 +--
builtin/repack.c | 2 +-
builtin/replace.c | 10 ++++----
builtin/rev-list.c | 6 +++--
builtin/tag.c | 4 +--
builtin/unpack-objects.c | 2 +-
commit-graph.c | 2 +-
commit.c | 3 ++-
diff.c | 18 ++++++-------
fetch-pack.c | 4 +--
list-objects-filter.c | 2 +-
log-tree.c | 2 +-
merge-ort.c | 4 +--
object-file.c | 2 +-
object-file.h | 2 +-
object-name.c | 16 ++++++------
object.c | 6 ++---
odb.c | 60 ++++++++++++++++++++++---------------------
odb.h | 46 +++++++++++++++++++++++++++------
pack-bitmap-write.c | 4 +--
pack-bitmap.c | 8 +++---
packfile.c | 5 ++--
promisor-remote.c | 4 +--
protocol-caps.c | 2 +-
reachable.c | 2 +-
read-cache.c | 6 ++---
ref-filter.c | 4 +--
remote.c | 5 ++--
sequencer.c | 5 ++--
streaming.c | 8 +++---
submodule.c | 5 ++--
t/helper/test-partial-clone.c | 2 +-
tag.c | 2 +-
48 files changed, 213 insertions(+), 170 deletions(-)
diff --git a/archive.c b/archive.c
index 7fa2cc2596a..f2511d530d5 100644
--- a/archive.c
+++ b/archive.c
@@ -215,7 +215,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
/* Stream it? */
if (S_ISREG(mode) && !args->convert &&
- oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
+ odb_read_object_info(args->repo->objects, oid, &size) == OBJ_BLOB &&
size > repo_settings_get_big_file_threshold(the_repository))
return write_entry(args, oid, path.buf, path.len, mode, NULL, size);
diff --git a/blame.c b/blame.c
index 0ceea080a80..97db3355af4 100644
--- a/blame.c
+++ b/blame.c
@@ -116,7 +116,7 @@ static void verify_working_tree_path(struct repository *r,
unsigned short mode;
if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
- oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
+ odb_read_object_info(r->objects, &blob_oid, NULL) == OBJ_BLOB)
return;
}
@@ -1245,7 +1245,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
return 0;
if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
goto error_out;
- if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
+ if (odb_read_object_info(r->objects, &origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out;
return 0;
error_out:
diff --git a/builtin/blame.c b/builtin/blame.c
index 15eda60af90..91586e6852b 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -837,7 +837,7 @@ static int is_a_rev(const char *name)
if (repo_get_oid(the_repository, name, &oid))
return 0;
- return OBJ_NONE < oid_object_info(the_repository, &oid, NULL);
+ return OBJ_NONE < odb_read_object_info(the_repository->objects, &oid, NULL);
}
static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
@@ -848,7 +848,7 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
oidcpy(&oid, oid_ret);
while (1) {
struct object *obj;
- int kind = oid_object_info(r, &oid, NULL);
+ int kind = odb_read_object_info(r->objects, &oid, NULL);
if (kind == OBJ_COMMIT) {
oidcpy(oid_ret, &oid);
return 0;
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index f3a925a8183..f7595fdb04e 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -132,7 +132,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
switch (opt) {
case 't':
oi.typep = &type;
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
printf("%s\n", type_name(type));
ret = 0;
@@ -146,7 +146,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
oi.contentp = (void**)&buf;
}
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
@@ -180,7 +180,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
/* else fallthrough */
case 'p':
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("Not a valid object name %s", obj_name);
@@ -217,7 +217,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
if (exp_type_id == OBJ_BLOB) {
struct object_id blob_oid;
- if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
+ if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_TAG) {
char *buffer = repo_read_object_file(the_repository,
&oid,
&type,
@@ -235,7 +236,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
} else
oidcpy(&blob_oid, &oid);
- if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB) {
+ if (odb_read_object_info(the_repository->objects,
+ &blob_oid, NULL) == OBJ_BLOB) {
ret = stream_blob(&blob_oid);
goto cleanup;
}
@@ -294,7 +296,7 @@ struct expand_data {
/*
* After a mark_query run, this object_info is set up to be
- * passed to oid_object_info_extended. It will point to the data
+ * passed to odb_read_object_info_extended. It will point to the data
* elements above, so you can retrieve the response from there.
*/
struct object_info info;
@@ -484,12 +486,12 @@ static void batch_object_write(const char *obj_name,
data->info.sizep = &data->size;
if (pack)
- ret = packed_object_info(the_repository, pack, offset,
- &data->info);
+ ret = packed_object_info(the_repository, pack,
+ offset, &data->info);
else
- ret = oid_object_info_extended(the_repository,
- &data->oid, &data->info,
- OBJECT_INFO_LOOKUP_REPLACE);
+ ret = odb_read_object_info_extended(the_repository->objects,
+ &data->oid, &data->info,
+ OBJECT_INFO_LOOKUP_REPLACE);
if (ret < 0) {
report_object_status(opt, obj_name, &data->oid, "missing");
return;
@@ -872,7 +874,7 @@ static int batch_objects(struct batch_options *opt)
/*
* Expand once with our special mark_query flag, which will prime the
- * object_info to be handed to oid_object_info_extended for each
+ * object_info to be handed to odb_read_object_info_extended for each
* object.
*/
memset(&data, 0, sizeof(data));
diff --git a/builtin/describe.c b/builtin/describe.c
index 96cb68e5e5d..fbf305d7624 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -552,7 +552,8 @@ static void describe(const char *arg, int last_one)
if (cmit)
describe_commit(&oid, &sb);
- else if (oid_object_info(the_repository, &oid, NULL) == OBJ_BLOB)
+ else if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_BLOB)
describe_blob(oid, &sb);
else
die(_("%s is neither a commit nor blob"), arg);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 0505f289a94..6c93cf0a8aa 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -1200,7 +1200,7 @@ static void import_marks(char *input_file, int check_exists)
if (last_idnum < mark)
last_idnum = mark;
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(&oid));
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 413304db9b5..2718376f2c9 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1756,8 +1756,8 @@ static void insert_object_entry(struct mark_set **s, struct object_id *oid, uint
struct object_entry *e;
e = find_object(oid);
if (!e) {
- enum object_type type = oid_object_info(the_repository,
- oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
e = insert_object(oid);
@@ -2416,8 +2416,8 @@ static void file_change_m(const char *p, struct branch *b)
enum object_type expected = S_ISDIR(mode) ?
OBJ_TREE: OBJ_BLOB;
enum object_type type = oe ? oe->type :
- oid_object_info(the_repository, &oid,
- NULL);
+ odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("%s not found: %s",
S_ISDIR(mode) ? "Tree" : "Blob",
@@ -2553,7 +2553,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
die("Not a blob (actually a %s): %s",
type_name(oe->type), command_buf.buf);
} else if (!is_null_oid(&oid)) {
- enum object_type type = oid_object_info(the_repository, &oid,
+ enum object_type type = odb_read_object_info(the_repository->objects, &oid,
NULL);
if (type < 0)
die("Blob not found: %s", command_buf.buf);
@@ -2895,7 +2895,8 @@ static void parse_new_tag(const char *arg)
} else if (!repo_get_oid(the_repository, from, &oid)) {
struct object_entry *oe = find_object(&oid);
if (!oe) {
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("Not a valid object: %s", from);
} else
@@ -3085,8 +3086,8 @@ static struct object_entry *dereference(struct object_entry *oe,
const unsigned hexsz = the_hash_algo->hexsz;
if (!oe) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
/* cache it! */
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 014aa1344e2..6e3465b0266 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -71,7 +71,8 @@ static const char *printable_type(const struct object_id *oid,
const char *ret;
if (type == OBJ_NONE)
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
ret = type_name(type);
if (!ret)
@@ -232,8 +233,8 @@ static void mark_unreachable_referents(const struct object_id *oid)
* (and we want to avoid parsing blobs).
*/
if (obj->type == OBJ_NONE) {
- enum object_type type = oid_object_info(the_repository,
- &obj->oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ &obj->oid, NULL);
if (type > 0)
object_as_type(obj, type, 0);
}
diff --git a/builtin/gc.c b/builtin/gc.c
index 50a09eb07e3..ff551fab439 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1080,7 +1080,7 @@ static int dfs_on_ref(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
commit = lookup_commit(the_repository, oid);
diff --git a/builtin/grep.c b/builtin/grep.c
index cfcf916bce1..1435d462cd1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -520,7 +520,7 @@ static int grep_submodule(struct grep_opt *opt,
struct strbuf base = STRBUF_INIT;
obj_read_lock();
- object_type = oid_object_info(subrepo, oid, NULL);
+ object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
data = read_object_with_reference(subrepo,
oid, OBJ_TREE,
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 4d4d989eb1a..d0b16908122 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -260,7 +260,8 @@ static unsigned check_object(struct object *obj)
if (!(obj->flags & FLAG_CHECKED)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects,
+ &obj->oid, &size);
if (type <= 0)
die(_("did not receive expected object %s"),
oid_to_hex(&obj->oid));
@@ -908,7 +909,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
enum object_type has_type;
unsigned long has_size;
read_lock();
- has_type = oid_object_info(the_repository, oid, &has_size);
+ has_type = odb_read_object_info(the_repository->objects, oid, &has_size);
if (has_type < 0)
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
@@ -1501,9 +1502,9 @@ static void fix_unresolved_deltas(struct hashfile *f)
struct oid_array to_fetch = OID_ARRAY_INIT;
for (i = 0; i < nr_ref_deltas; i++) {
struct ref_delta_entry *d = sorted_by_pos[i];
- if (!oid_object_info_extended(the_repository, &d->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &d->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &d->oid);
}
@@ -1829,7 +1830,7 @@ static void repack_local_links(void)
oidset_iter_init(&outgoing_links, &iter);
while ((oid = oidset_iter_next(&iter))) {
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info, 0))
/* Missing; assume it is a promisor object */
continue;
if (info.whence == OI_PACKED && info.u.packed.pack->pack_promisor)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 821339b07d4..ff975e7be06 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -251,7 +251,7 @@ static void expand_objectsize(struct repository *repo, struct strbuf *line,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(repo, oid, &size) < 0)
+ if (odb_read_object_info(repo->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 62b6fd58c16..4d616dd5282 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -27,7 +27,7 @@ static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
@@ -217,7 +217,7 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base,
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
+ if (odb_read_object_info(the_repository->objects, oid, &size) == OBJ_BAD)
xsnprintf(size_text, sizeof(size_text), "BAD");
else
xsnprintf(size_text, sizeof(size_text),
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 016b0e5b224..81df7f6099f 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -124,10 +124,10 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
/* Check the type of object identified by oid without fetching objects */
oi.typep = &obj_type;
- if (oid_object_info_extended(the_repository, &oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_QUICK |
- OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_QUICK |
+ OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
obj_type = -1;
if (obj_type < 0) {
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 99b63cb0980..da35d684081 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2154,10 +2154,10 @@ static void prefetch_to_pack(uint32_t object_index_start) {
for (i = object_index_start; i < to_pack.nr_objects; i++) {
struct object_entry *entry = to_pack.objects + i;
- if (!oid_object_info_extended(the_repository,
- &entry->idx.oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &entry->idx.oid,
+ NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &entry->idx.oid);
}
@@ -2298,19 +2298,19 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
/*
* No choice but to fall back to the recursive delta walk
- * with oid_object_info() to find about the object type
+ * with odb_read_object_info() to find about the object type
* at this point...
*/
give_up:
unuse_pack(&w_curs);
}
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
if (repo_has_promisor_remote(the_repository)) {
prefetch_to_pack(object_index);
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
type = -1;
} else {
type = -1;
@@ -2384,12 +2384,13 @@ static void drop_reused_delta(struct object_entry *entry)
if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
/*
* We failed to get the info from this pack for some reason;
- * fall back to oid_object_info, which may find another copy.
+ * fall back to odb_read_object_info, which may find another copy.
* And if that fails, the error will be recorded in oe_type(entry)
* and dealt with in prepare_pack().
*/
oe_set_type(entry,
- oid_object_info(the_repository, &entry->idx.oid, &size));
+ odb_read_object_info(the_repository->objects,
+ &entry->idx.oid, &size));
} else {
oe_set_type(entry, type);
}
@@ -2677,7 +2678,8 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
packing_data_lock(&to_pack);
- if (oid_object_info(the_repository, &e->idx.oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects,
+ &e->idx.oid, &size) < 0)
die(_("unable to get size of %s"),
oid_to_hex(&e->idx.oid));
packing_data_unlock(&to_pack);
@@ -4063,7 +4065,7 @@ static void add_objects_in_unpacked_packs(void)
static int add_loose_object(const struct object_id *oid, const char *path,
void *data UNUSED)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0) {
warning(_("loose object at %s could not be examined"), path);
@@ -4449,7 +4451,7 @@ static int option_parse_cruft_expiration(const struct option *opt UNUSED,
static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED)
{
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, &obj->oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0))
BUG("should_include_obj should only be called on existing objects");
return info.whence != OI_PACKED || !info.u.packed.pack->pack_promisor;
}
diff --git a/builtin/prune.c b/builtin/prune.c
index 7bbfb14c2be..339017c7ccf 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -99,8 +99,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
if (st.st_mtime > expire)
return 0;
if (show_only || verbose) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? type_name(type) : "unknown");
}
diff --git a/builtin/repack.c b/builtin/repack.c
index 8145474cf8d..a89c2b704fb 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -707,7 +707,7 @@ static int midx_snapshot_ref_one(const char *refname UNUSED,
if (oidset_insert(&data->seen, oid))
return 0; /* already seen */
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
fprintf(data->f->fp, "%s%s\n", data->preferred ? "+" : "",
diff --git a/builtin/replace.c b/builtin/replace.c
index 11c7e2d4c0c..5ff2ab723cb 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -65,8 +65,8 @@ static int show_reference(const char *refname,
if (repo_get_oid(data->repo, refname, &object))
return error(_("failed to resolve '%s' as a valid ref"), refname);
- obj_type = oid_object_info(data->repo, &object, NULL);
- repl_type = oid_object_info(data->repo, oid, NULL);
+ obj_type = odb_read_object_info(data->repo->objects, &object, NULL);
+ repl_type = odb_read_object_info(data->repo->objects, oid, NULL);
printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
oid_to_hex(oid), type_name(repl_type));
@@ -185,8 +185,8 @@ static int replace_object_oid(const char *object_ref,
struct strbuf err = STRBUF_INIT;
int res = 0;
- obj_type = oid_object_info(the_repository, object, NULL);
- repl_type = oid_object_info(the_repository, repl, NULL);
+ obj_type = odb_read_object_info(the_repository->objects, object, NULL);
+ repl_type = odb_read_object_info(the_repository->objects, repl, NULL);
if (!force && obj_type != repl_type)
return error(_("Objects must be of the same type.\n"
"'%s' points to a replaced object of type '%s'\n"
@@ -334,7 +334,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
if (repo_get_oid(the_repository, object_ref, &old_oid) < 0)
return error(_("not a valid object name: '%s'"), object_ref);
- type = oid_object_info(the_repository, &old_oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &old_oid, NULL);
if (type < 0)
return error(_("unable to get object type for %s"),
oid_to_hex(&old_oid));
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 0ee37a32cb2..4d0c460f186 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -110,7 +110,8 @@ static off_t get_object_disk_usage(struct object *obj)
off_t size;
struct object_info oi = OBJECT_INFO_INIT;
oi.disk_sizep = &size;
- if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid));
return size;
}
@@ -346,7 +347,8 @@ static void show_commit(struct commit *commit, void *data)
static int finish_object(struct object *obj, const char *name, void *cb_data)
{
struct rev_list_info *info = cb_data;
- if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, NULL, 0) < 0) {
finish_object__ma(obj, name);
return 1;
}
diff --git a/builtin/tag.c b/builtin/tag.c
index cf2ea4b4993..e0b27396c6b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -304,7 +304,7 @@ static void create_tag(const struct object_id *object, const char *object_ref,
struct strbuf header = STRBUF_INIT;
int should_edit;
- type = oid_object_info(the_repository, object, NULL);
+ type = odb_read_object_info(the_repository->objects, object, NULL);
if (type <= OBJ_NONE)
die(_("bad object type."));
@@ -401,7 +401,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
}
strbuf_addstr(sb, " (");
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
switch (type) {
default:
strbuf_addstr(sb, "object of unknown type");
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 7bf395eec84..405e78bc592 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -232,7 +232,7 @@ static int check_object(struct object *obj, enum object_type type,
if (!(obj->flags & FLAG_OPEN)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects, &obj->oid, &size);
if (type != obj->type || type <= 0)
die("object of unexpected type");
obj->flags |= FLAG_WRITTEN;
diff --git a/commit-graph.c b/commit-graph.c
index 59265f89385..5f482d3377f 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1862,7 +1862,7 @@ static int add_ref_to_set(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) == OBJ_COMMIT)
oidset_insert(data->commits, oid);
display_progress(data->progress, oidset_size(data->commits));
diff --git a/commit.c b/commit.c
index aa65183d8b6..d4aa9c7a5f8 100644
--- a/commit.c
+++ b/commit.c
@@ -585,7 +585,8 @@ int repo_parse_commit_internal(struct repository *r,
return 0;
}
- if (oid_object_info_extended(r, &item->object.oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(r->objects, &item->object.oid,
+ &oi, flags) < 0)
return quiet_on_missing ? -1 :
error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/diff.c b/diff.c
index 3af108115b3..dca87e164fb 100644
--- a/diff.c
+++ b/diff.c
@@ -4230,14 +4230,14 @@ int diff_populate_filespec(struct repository *r,
info.contentp = &s->data;
if (options && options->missing_object_cb) {
- if (!oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_SKIP_FETCH_OBJECT))
+ if (!odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_SKIP_FETCH_OBJECT))
goto object_read;
options->missing_object_cb(options->missing_object_data);
}
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
object_read:
@@ -4252,8 +4252,8 @@ int diff_populate_filespec(struct repository *r,
}
if (!info.contentp) {
info.contentp = &s->data;
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
}
s->should_free = 1;
@@ -7019,8 +7019,8 @@ void diff_add_if_missing(struct repository *r,
{
if (filespec && filespec->oid_valid &&
!S_ISGITLINK(filespec->mode) &&
- oid_object_info_extended(r, &filespec->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(r->objects, &filespec->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(to_fetch, &filespec->oid);
}
diff --git a/fetch-pack.c b/fetch-pack.c
index 47fa7fa4c49..0f5de1c94d1 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -149,8 +149,8 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
}
while (1) {
- if (oid_object_info_extended(the_repository, oid, &info,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
return NULL;
if (type == OBJ_TAG) {
struct tag *tag = (struct tag *)
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 80fe48a52c8..7ecd4d9ef50 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -310,7 +310,7 @@ static enum list_objects_filter_result filter_blobs_limit(
assert(obj->type == OBJ_BLOB);
assert((obj->flags & SEEN) == 0);
- t = oid_object_info(r, &obj->oid, &object_length);
+ t = odb_read_object_info(r->objects, &obj->oid, &object_length);
if (t != OBJ_BLOB) { /* probably OBJ_NONE */
/*
* We DO NOT have the blob locally, so we cannot
diff --git a/log-tree.c b/log-tree.c
index 1d05dc1c701..233bf9f227c 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -176,7 +176,7 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
return 0;
}
- objtype = oid_object_info(the_repository, oid, NULL);
+ objtype = odb_read_object_info(the_repository->objects, oid, NULL);
if (objtype < 0)
return 0;
obj = lookup_object_by_type(the_repository, oid, objtype);
diff --git a/merge-ort.c b/merge-ort.c
index 9f693ab1d36..f29417040c1 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -4385,8 +4385,8 @@ static void prefetch_for_content_merges(struct merge_options *opt,
if ((ci->filemask & side_mask) &&
S_ISREG(vi->mode) &&
- oid_object_info_extended(opt->repo, &vi->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(opt->repo->objects, &vi->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&to_fetch, &vi->oid);
}
}
diff --git a/object-file.c b/object-file.c
index 04da19a1a3b..3d674d1093e 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1108,7 +1108,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
oi.typep = &type;
oi.sizep = &len;
oi.contentp = &buf;
- if (oid_object_info_extended(the_repository, oid, &oi, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &oi, 0))
return error(_("cannot read object for %s"), oid_to_hex(oid));
if (compat) {
if (repo_oid_to_algop(repo, oid, compat, &compat_oid))
diff --git a/object-file.h b/object-file.h
index 5066638f8ec..67b4ffc4808 100644
--- a/object-file.h
+++ b/object-file.h
@@ -8,7 +8,7 @@
struct index_state;
/*
- * Set this to 0 to prevent oid_object_info_extended() from fetching missing
+ * Set this to 0 to prevent odb_read_object_info_extended() from fetching missing
* blobs. This has a difference only if extensions.partialClone is set.
*
* Its default value is 1.
diff --git a/object-name.c b/object-name.c
index 381536e900e..e225eb602cf 100644
--- a/object-name.c
+++ b/object-name.c
@@ -251,7 +251,7 @@ static int disambiguate_commit_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_COMMIT;
}
@@ -262,7 +262,7 @@ static int disambiguate_committish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -279,7 +279,7 @@ static int disambiguate_tree_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_TREE;
}
@@ -290,7 +290,7 @@ static int disambiguate_treeish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_TREE || kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -307,7 +307,7 @@ static int disambiguate_blob_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_BLOB;
}
@@ -399,7 +399,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
return 0;
hash = repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV);
- type = oid_object_info(ds->repo, oid, NULL);
+ type = odb_read_object_info(ds->repo->objects, oid, NULL);
if (type < 0) {
/*
@@ -514,8 +514,8 @@ static int sort_ambiguous(const void *va, const void *vb, void *ctx)
{
struct repository *sort_ambiguous_repo = ctx;
const struct object_id *a = va, *b = vb;
- int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
- int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
+ int a_type = odb_read_object_info(sort_ambiguous_repo->objects, a, NULL);
+ int b_type = odb_read_object_info(sort_ambiguous_repo->objects, b, NULL);
int a_type_sort;
int b_type_sort;
diff --git a/object.c b/object.c
index 3b15469139d..868d89eed42 100644
--- a/object.c
+++ b/object.c
@@ -214,7 +214,7 @@ enum peel_status peel_object(struct repository *r,
struct object *o = lookup_unknown_object(r, name);
if (o->type == OBJ_NONE) {
- int type = oid_object_info(r, name, NULL);
+ int type = odb_read_object_info(r->objects, name, NULL);
if (type < 0 || !object_as_type(o, type, 0))
return PEEL_INVALID;
}
@@ -315,7 +315,7 @@ struct object *parse_object_with_flags(struct repository *r,
}
if ((!obj || obj->type == OBJ_BLOB) &&
- oid_object_info(r, oid, NULL) == OBJ_BLOB) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
if (!skip_hash && stream_object_signature(r, repl) < 0) {
error(_("hash mismatch %s"), oid_to_hex(oid));
return NULL;
@@ -331,7 +331,7 @@ struct object *parse_object_with_flags(struct repository *r,
*/
if (skip_hash && discard_tree &&
(!obj || obj->type == OBJ_TREE) &&
- oid_object_info(r, oid, NULL) == OBJ_TREE) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_TREE) {
return &lookup_tree(r, oid)->object;
}
diff --git a/odb.c b/odb.c
index a13b9ecbbc9..cc1cc727346 100644
--- a/odb.c
+++ b/odb.c
@@ -647,7 +647,7 @@ static int register_all_submodule_alternates(struct object_database *odb)
return ret;
}
-static int do_oid_object_info_extended(struct repository *r,
+static int do_oid_object_info_extended(struct object_database *odb,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
{
@@ -660,7 +660,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
- real = lookup_replace_object(r, oid);
+ real = lookup_replace_object(odb->repo, oid);
if (is_null_oid(real))
return -1;
@@ -668,7 +668,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (!oi)
oi = &blank_oi;
- co = find_cached_object(r->objects, real);
+ co = find_cached_object(odb, real);
if (co) {
if (oi->typep)
*(oi->typep) = co->type;
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, r->hash_algo);
+ oidclr(oi->delta_base_oid, odb->repo->hash_algo);
if (oi->contentp)
*oi->contentp = xmemdupz(co->buf, co->size);
oi->whence = OI_CACHED;
@@ -685,17 +685,17 @@ static int do_oid_object_info_extended(struct repository *r,
}
while (1) {
- if (find_pack_entry(r, real, &e))
+ if (find_pack_entry(odb->repo, real, &e))
break;
/* Most likely it's a loose object. */
- if (!loose_object_info(r, real, oi, flags))
+ if (!loose_object_info(odb->repo, real, oi, flags))
return 0;
/* Not a loose object; someone else may have just packed it. */
if (!(flags & OBJECT_INFO_QUICK)) {
- reprepare_packed_git(r);
- if (find_pack_entry(r, real, &e))
+ reprepare_packed_git(odb->repo);
+ if (find_pack_entry(odb->repo, real, &e))
break;
}
@@ -705,15 +705,15 @@ static int do_oid_object_info_extended(struct repository *r,
* `odb_add_submodule_source_by_path()` on that submodule's
* ODB). If any such ODBs exist, register them and try again.
*/
- if (register_all_submodule_alternates(r->objects))
+ if (register_all_submodule_alternates(odb))
/* We added some alternates; retry */
continue;
/* Check if it is a missing object */
- if (fetch_if_missing && repo_has_promisor_remote(r) &&
+ if (fetch_if_missing && repo_has_promisor_remote(odb->repo) &&
!already_retried &&
!(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) {
- promisor_remote_get_direct(r, real, 1);
+ promisor_remote_get_direct(odb->repo, real, 1);
already_retried = 1;
continue;
}
@@ -723,7 +723,7 @@ static int do_oid_object_info_extended(struct repository *r,
if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid))
die(_("replacement %s not found for %s"),
oid_to_hex(real), oid_to_hex(oid));
- if ((p = has_packed_and_bad(r, real)))
+ if ((p = has_packed_and_bad(odb->repo, real)))
die(_("packed object %s (stored in %s) is corrupt"),
oid_to_hex(real), p->pack_name);
}
@@ -736,10 +736,10 @@ static int do_oid_object_info_extended(struct repository *r,
* information below, so return early.
*/
return 0;
- rtype = packed_object_info(r, e.p, e.offset, oi);
+ rtype = packed_object_info(odb->repo, e.p, e.offset, oi);
if (rtype < 0) {
mark_bad_packed_object(e.p, real);
- return do_oid_object_info_extended(r, real, oi, 0);
+ return do_oid_object_info_extended(odb, real, oi, 0);
} else if (oi->whence == OI_PACKED) {
oi->u.packed.offset = e.offset;
oi->u.packed.pack = e.p;
@@ -787,7 +787,7 @@ static int oid_object_info_convert(struct repository *r,
oi = &new_oi;
}
- ret = oid_object_info_extended(r, &oid, oi, flags);
+ ret = odb_read_object_info_extended(r->objects, &oid, oi, flags);
if (ret)
return -1;
if (oi == input_oi)
@@ -830,33 +830,35 @@ static int oid_object_info_convert(struct repository *r,
return ret;
}
-int oid_object_info_extended(struct repository *r, const struct object_id *oid,
- struct object_info *oi, unsigned flags)
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
{
int ret;
- if (oid->algo && (hash_algo_by_ptr(r->hash_algo) != oid->algo))
- return oid_object_info_convert(r, oid, oi, flags);
+ if (oid->algo && (hash_algo_by_ptr(odb->repo->hash_algo) != oid->algo))
+ return oid_object_info_convert(odb->repo, oid, oi, flags);
obj_read_lock();
- ret = do_oid_object_info_extended(r, oid, oi, flags);
+ ret = do_oid_object_info_extended(odb, oid, oi, flags);
obj_read_unlock();
return ret;
}
/* returns enum object_type or negative */
-int oid_object_info(struct repository *r,
- const struct object_id *oid,
- unsigned long *sizep)
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep)
{
enum object_type type;
struct object_info oi = OBJECT_INFO_INIT;
oi.typep = &type;
oi.sizep = sizep;
- if (oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(odb, oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE) < 0)
return -1;
return type;
}
@@ -887,7 +889,7 @@ int pretend_object_file(struct repository *repo,
/*
* This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call oid_object_info_extended() and give
+ * deal with them should arrange to call odb_read_object_info_extended() and give
* error messages themselves.
*/
void *repo_read_object_file(struct repository *r,
@@ -902,7 +904,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (oid_object_info_extended(r, oid, &oi, flags))
+ if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
return NULL;
return data;
@@ -968,13 +970,13 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(odb->repo, oid, NULL);
+ enum object_type type = odb_read_object_info(odb, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index 4e6029ec542..fd99bd593f7 100644
--- a/odb.h
+++ b/odb.h
@@ -264,9 +264,6 @@ void *repo_read_object_file(struct repository *r,
enum object_type *type,
unsigned long *size);
-/* Read and unpack an object file into memory, write memory to an object file */
-int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
-
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -335,9 +332,24 @@ struct object_info {
/* Die if object corruption (not just an object being missing) was detected. */
#define OBJECT_INFO_DIE_IF_CORRUPT 32
-int oid_object_info_extended(struct repository *r,
- const struct object_id *,
- struct object_info *, unsigned flags);
+/*
+ * Read object info from the object database and populate the `object_info`
+ * structure. Returns 0 on success, a negative error code otherwise.
+ */
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags);
+
+/*
+ * Read a subset of object info for the given object ID. Returns an `enum
+ * object_type` on success, a negative error code otherwise. If successful and
+ * `sizep` is non-NULL, then the size of the object will be written to the
+ * pointer.
+ */
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep);
enum {
/* Retry packed storage after checking packed and loose storage */
@@ -359,7 +371,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: repo_read_object_file(),
- * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
+ * read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -367,7 +379,7 @@ void odb_assert_oid_type(struct object_database *odb,
* reading functions. However, beware that in these cases zlib inflation won't
* be performed in parallel, losing performance.
*
- * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
+ * TODO: odb_read_object_info_extended()'s call stack has a recursive behavior. If
* any of its callees end up calling it, this recursive call won't benefit from
* parallel inflation.
*/
@@ -415,4 +427,22 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
+/* Compatibility wrappers, to be removed once Git 2.51 has been released. */
+#include "repository.h"
+
+static inline int oid_object_info_extended(struct repository *r,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
+{
+ return odb_read_object_info_extended(r->objects, oid, oi, flags);
+}
+
+static inline int oid_object_info(struct repository *r,
+ const struct object_id *oid,
+ unsigned long *sizep)
+{
+ return odb_read_object_info(r->objects, oid, sizep);
+}
+
#endif /* ODB_H */
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index c847369eaaa..c5183b619c1 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -144,8 +144,8 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
break;
default:
- real_type = oid_object_info(writer->to_pack->repo,
- &entry->idx.oid, NULL);
+ real_type = odb_read_object_info(writer->to_pack->repo->objects,
+ &entry->idx.oid, NULL);
break;
}
diff --git a/pack-bitmap.c b/pack-bitmap.c
index a695a794e9b..bcbb71f7502 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1868,8 +1868,8 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
size_t eindex_pos = pos - bitmap_num_objects_total(bitmap_git);
struct eindex *eindex = &bitmap_git->ext_index;
struct object *obj = eindex->objects[eindex_pos];
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects, &obj->oid,
+ &oi, 0) < 0)
die(_("unable to get size of %s"), oid_to_hex(&obj->oid));
}
@@ -3220,8 +3220,8 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)
i)))
continue;
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of '%s'"),
oid_to_hex(&obj->oid));
diff --git a/packfile.c b/packfile.c
index ac0e29e99b9..af9ccfdba62 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1321,7 +1321,7 @@ static int retry_bad_packed_offset(struct repository *r,
return OBJ_BAD;
nth_packed_object_id(&oid, p, pack_pos_to_index(p, pos));
mark_bad_packed_object(p, &oid);
- type = oid_object_info(r, &oid, NULL);
+ type = odb_read_object_info(r->objects, &oid, NULL);
if (type <= OBJ_NONE)
return OBJ_BAD;
return type;
@@ -1849,7 +1849,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
oi.typep = &type;
oi.sizep = &base_size;
oi.contentp = &base;
- if (oid_object_info_extended(r, &base_oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(r->objects, &base_oid,
+ &oi, 0) < 0)
base = NULL;
external_base = base;
diff --git a/promisor-remote.c b/promisor-remote.c
index 2baa286bfd0..be6f82d12f8 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -245,8 +245,8 @@ static int remove_fetched_oids(struct repository *repo,
struct object_id *new_oids;
for (i = 0; i < oid_nr; i++)
- if (oid_object_info_extended(repo, &old_oids[i], NULL,
- OBJECT_INFO_SKIP_FETCH_OBJECT)) {
+ if (odb_read_object_info_extended(repo->objects, &old_oids[i], NULL,
+ OBJECT_INFO_SKIP_FETCH_OBJECT)) {
remaining[i] = 1;
remaining_nr++;
}
diff --git a/protocol-caps.c b/protocol-caps.c
index 3022f69a1bd..ecdd0dc58d5 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -64,7 +64,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
strbuf_addstr(&send_buffer, oid_str);
if (info->size) {
- if (oid_object_info(r, &oid, &object_size) < 0) {
+ if (odb_read_object_info(r->objects, &oid, &object_size) < 0) {
strbuf_addstr(&send_buffer, " ");
} else {
strbuf_addf(&send_buffer, " %lu", object_size);
diff --git a/reachable.c b/reachable.c
index 9dc748f0b9a..e984b68a0c4 100644
--- a/reachable.c
+++ b/reachable.c
@@ -211,7 +211,7 @@ static void add_recent_object(const struct object_id *oid,
* later processing, and the revision machinery expects
* commits and tags to have been parsed.
*/
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0)
die("unable to get object info for %s", oid_to_hex(oid));
diff --git a/read-cache.c b/read-cache.c
index c3fa9686766..7d5bccf95dc 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3729,9 +3729,9 @@ void prefetch_cache_entries(const struct index_state *istate,
if (S_ISGITLINK(ce->ce_mode) || !must_prefetch(ce))
continue;
- if (!oid_object_info_extended(the_repository, &ce->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &ce->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &ce->oid);
}
diff --git a/ref-filter.c b/ref-filter.c
index 4ce45440ad1..f9f2c512a8c 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2302,8 +2302,8 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
oi->info.sizep = &oi->size;
oi->info.typep = &oi->type;
}
- if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(the_repository->objects, &oi->oid, &oi->info,
+ OBJECT_INFO_LOOKUP_REPLACE))
return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
oid_to_hex(&oi->oid), ref->refname);
if (oi->info.disk_sizep && oi->disk_size < 0)
diff --git a/remote.c b/remote.c
index 17a842f5684..72c36239d31 100644
--- a/remote.c
+++ b/remote.c
@@ -1182,7 +1182,7 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
BUG("'%s' is not a valid object, "
"match_explicit_lhs() should catch this!",
matched_src_name);
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type == OBJ_COMMIT) {
advise(_("The <src> part of the refspec is a commit object.\n"
"Did you mean to create a new branch by pushing to\n"
@@ -1412,7 +1412,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
continue; /* not a tag */
if (string_list_has_string(&dst_tag, ref->name))
continue; /* they already have it */
- if (oid_object_info(the_repository, &ref->new_oid, NULL) != OBJ_TAG)
+ if (odb_read_object_info(the_repository->objects,
+ &ref->new_oid, NULL) != OBJ_TAG)
continue; /* be conservative */
item = string_list_append(&src_tag, ref->name);
item->util = ref;
diff --git a/sequencer.c b/sequencer.c
index 2432d0a39ec..193459405f8 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5503,9 +5503,8 @@ int sequencer_pick_revisions(struct repository *r,
if (!repo_get_oid(r, name, &oid)) {
if (!lookup_commit_reference_gently(r, &oid, 1)) {
- enum object_type type = oid_object_info(r,
- &oid,
- NULL);
+ enum object_type type = odb_read_object_info(r->objects,
+ &oid, NULL);
res = error(_("%s: can't cherry-pick a %s"),
name, type_name(type));
goto out;
diff --git a/streaming.c b/streaming.c
index 81c42673a23..4b13827668e 100644
--- a/streaming.c
+++ b/streaming.c
@@ -44,7 +44,7 @@ struct git_istream {
union {
struct {
- char *buf; /* from oid_object_info_extended() */
+ char *buf; /* from odb_read_object_info_extended() */
unsigned long read_ptr;
} incore;
@@ -403,8 +403,8 @@ static int open_istream_incore(struct git_istream *st, struct repository *r,
oi.typep = type;
oi.sizep = &st->size;
oi.contentp = (void **)&st->u.incore.buf;
- return oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_DIE_IF_CORRUPT);
+ return odb_read_object_info_extended(r->objects, oid, &oi,
+ OBJECT_INFO_DIE_IF_CORRUPT);
}
/*****************************************************************************
@@ -422,7 +422,7 @@ static int istream_source(struct git_istream *st,
oi.typep = type;
oi.sizep = &size;
- status = oid_object_info_extended(r, oid, &oi, 0);
+ status = odb_read_object_info_extended(r->objects, oid, &oi, 0);
if (status < 0)
return status;
diff --git a/submodule.c b/submodule.c
index 788c9e55ed3..f8373a9ea7d 100644
--- a/submodule.c
+++ b/submodule.c
@@ -968,7 +968,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
return 0;
}
- type = oid_object_info(&subrepo, oid, NULL);
+ type = odb_read_object_info(subrepo.objects, oid, NULL);
switch (type) {
case OBJ_COMMIT:
@@ -1752,8 +1752,7 @@ static int fetch_start_failure(struct strbuf *err UNUSED,
static int commit_missing_in_sub(const struct object_id *oid, void *data)
{
struct repository *subrepo = data;
-
- enum object_type type = oid_object_info(subrepo, oid, NULL);
+ enum object_type type = odb_read_object_info(subrepo->objects, oid, NULL);
return type != OBJ_COMMIT;
}
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index dba227259a2..d8488007493 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -23,7 +23,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
die("could not init repo");
if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
die("could not parse oid");
- if (oid_object_info_extended(&r, &oid, &oi, 0))
+ if (odb_read_object_info_extended(r.objects, &oid, &oi, 0))
die("could not obtain object info");
printf("%d\n", (int) size);
diff --git a/tag.c b/tag.c
index 5f6868bf7b1..144048fd5e0 100644
--- a/tag.c
+++ b/tag.c
@@ -52,7 +52,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
unsigned long size;
int ret;
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type != OBJ_TAG)
return error("%s: cannot verify a non-tag object of type %s.",
name_to_report ?
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 14/17] odb: rename `repo_read_object_file()`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (12 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 15/17] odb: rename `has_object()` Patrick Steinhardt
` (3 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `repo_read_object_file()` to `odb_read_object()` to match other
functions related to the object database and our modern coding
guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 10 +++++-----
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 6 +++---
blame.c | 13 ++++++-------
builtin/cat-file.c | 26 +++++++++++---------------
builtin/difftool.c | 2 +-
builtin/fast-export.c | 6 +++---
builtin/fast-import.c | 8 ++++----
builtin/grep.c | 8 ++++----
builtin/index-pack.c | 8 ++++----
builtin/log.c | 2 +-
builtin/merge-tree.c | 12 ++++++------
builtin/mktag.c | 4 ++--
builtin/notes.c | 6 +++---
builtin/pack-objects.c | 30 +++++++++++++++---------------
builtin/tag.c | 4 ++--
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 4 ++--
bundle.c | 2 +-
combine-diff.c | 2 +-
commit.c | 6 +++---
config.c | 2 +-
dir.c | 2 +-
entry.c | 4 ++--
fmt-merge-msg.c | 4 ++--
fsck.c | 2 +-
grep.c | 4 ++--
http-push.c | 4 ++--
mailmap.c | 2 +-
match-trees.c | 4 ++--
merge-blobs.c | 8 ++++----
merge-ort.c | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 13 +++++++------
object.c | 2 +-
odb.c | 19 +++++++------------
odb.h | 29 +++++++++++++++++++++++------
read-cache.c | 6 +++---
reflog.c | 4 ++--
rerere.c | 5 ++---
submodule-config.c | 4 ++--
tag.c | 6 +++---
tree-walk.c | 6 +++---
tree.c | 4 ++--
xdiff-interface.c | 2 +-
47 files changed, 157 insertions(+), 150 deletions(-)
diff --git a/apply.c b/apply.c
index e778b4e911d..a34ced04625 100644
--- a/apply.c
+++ b/apply.c
@@ -3210,8 +3210,8 @@ static int apply_binary(struct apply_state *state,
unsigned long size;
char *result;
- result = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ result = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!result)
return error(_("the necessary postimage %s for "
"'%s' cannot be read"),
@@ -3273,8 +3273,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
unsigned long sz;
char *result;
- result = repo_read_object_file(the_repository, oid, &type,
- &sz);
+ result = odb_read_object(the_repository->objects, oid,
+ &type, &sz);
if (!result)
return -1;
/* XXX read_sha1_file NUL-terminates */
@@ -3503,7 +3503,7 @@ static int resolve_to(struct image *image, const struct object_id *result_id)
image_clear(image);
- data = repo_read_object_file(the_repository, result_id, &type, &size);
+ data = odb_read_object(the_repository->objects, result_id, &type, &size);
if (!data || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(result_id));
strbuf_attach(&image->buf, data, size, size + 1);
diff --git a/archive.c b/archive.c
index f2511d530d5..f5a9d45c8d3 100644
--- a/archive.c
+++ b/archive.c
@@ -98,7 +98,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
(args->tree ? &args->tree->object.oid : NULL), oid);
path += args->baselen;
- buffer = repo_read_object_file(the_repository, oid, type, sizep);
+ buffer = odb_read_object(the_repository->objects, oid, type, sizep);
if (buffer && S_ISREG(mode)) {
struct strbuf buf = STRBUF_INIT;
size_t size = 0;
diff --git a/attr.c b/attr.c
index e5680db7f65..d1daeb0b4d9 100644
--- a/attr.c
+++ b/attr.c
@@ -779,7 +779,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
if (get_tree_entry(istate->repo, tree_oid, path, &oid, &mode))
return NULL;
- buf = repo_read_object_file(istate->repo, &oid, &type, &sz);
+ buf = odb_read_object(istate->repo->objects, &oid, &type, &sz);
if (!buf || type != OBJ_BLOB) {
free(buf);
return NULL;
diff --git a/bisect.c b/bisect.c
index a7939216d00..f24474542ec 100644
--- a/bisect.c
+++ b/bisect.c
@@ -155,9 +155,9 @@ static void show_list(const char *debug, int counted, int nr,
unsigned commit_flags = commit->object.flags;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository,
- &commit->object.oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects,
+ &commit->object.oid, &type,
+ &size);
const char *subject_start;
int subject_len;
diff --git a/blame.c b/blame.c
index 97db3355af4..858d2d74df9 100644
--- a/blame.c
+++ b/blame.c
@@ -1041,9 +1041,9 @@ static void fill_origin_blob(struct diff_options *opt,
&o->blob_oid, 1, &file->ptr, &file_size))
;
else
- file->ptr = repo_read_object_file(the_repository,
- &o->blob_oid, &type,
- &file_size);
+ file->ptr = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &file_size);
file->size = file_size;
if (!file->ptr)
@@ -2869,10 +2869,9 @@ void setup_scoreboard(struct blame_scoreboard *sb,
&sb->final_buf_size))
;
else
- sb->final_buf = repo_read_object_file(the_repository,
- &o->blob_oid,
- &type,
- &sb->final_buf_size);
+ sb->final_buf = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &sb->final_buf_size);
if (!sb->final_buf)
die(_("cannot read blob %s for path %s"),
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index f7595fdb04e..90a3e159d11 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -74,7 +74,7 @@ static int filter_object(const char *path, unsigned mode,
{
enum object_type type;
- *buf = repo_read_object_file(the_repository, oid, &type, size);
+ *buf = odb_read_object(the_repository->objects, oid, &type, size);
if (!*buf)
return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path);
@@ -197,8 +197,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
ret = stream_blob(&oid);
goto cleanup;
}
- buf = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!buf)
die("Cannot read object %s", obj_name);
@@ -219,10 +219,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
struct object_id blob_oid;
if (odb_read_object_info(the_repository->objects,
&oid, NULL) == OBJ_TAG) {
- char *buffer = repo_read_object_file(the_repository,
- &oid,
- &type,
- &size);
+ char *buffer = odb_read_object(the_repository->objects,
+ &oid, &type, &size);
const char *target;
if (!buffer)
@@ -403,10 +401,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
if (!textconv_object(the_repository,
data->rest, 0100644, oid,
1, &contents, &size))
- contents = repo_read_object_file(the_repository,
- oid,
- &type,
- &size);
+ contents = odb_read_object(the_repository->objects,
+ oid, &type, &size);
if (!contents)
die("could not convert '%s' %s",
oid_to_hex(oid), data->rest);
@@ -423,8 +419,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
unsigned long size;
void *contents;
- contents = repo_read_object_file(the_repository, oid, &type,
- &size);
+ contents = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!contents)
die("object %s disappeared", oid_to_hex(oid));
@@ -533,8 +529,8 @@ static void batch_object_write(const char *obj_name,
size_t s = data->size;
char *buf = NULL;
- buf = repo_read_object_file(the_repository, &data->oid, &data->type,
- &data->size);
+ buf = odb_read_object(the_repository->objects, &data->oid,
+ &data->type, &data->size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&data->oid));
buf = replace_idents_using_mailmap(buf, &s);
diff --git a/builtin/difftool.c b/builtin/difftool.c
index fac613e3bc3..e4bc1f83169 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -320,7 +320,7 @@ static char *get_symlink(struct repository *repo,
} else {
enum object_type type;
unsigned long size;
- data = repo_read_object_file(repo, oid, &type, &size);
+ data = odb_read_object(repo->objects, oid, &type, &size);
if (!data)
die(_("could not read object %s for symlink %s"),
oid_to_hex(oid), path);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 6c93cf0a8aa..33f304dd0ad 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -323,7 +323,7 @@ static void export_blob(const struct object_id *oid)
object = (struct object *)lookup_blob(the_repository, oid);
eaten = 0;
} else {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
die("could not read blob %s", oid_to_hex(oid));
if (check_object_signature(the_repository, oid, buf, size,
@@ -869,8 +869,8 @@ static void handle_tag(const char *name, struct tag *tag)
return;
}
- buf = repo_read_object_file(the_repository, &tag->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &tag->object.oid,
+ &type, &size);
if (!buf)
die("could not read tag %s", oid_to_hex(&tag->object.oid));
message = memmem(buf, size, "\n\n", 2);
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 2718376f2c9..1973c504e25 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1265,7 +1265,7 @@ static void load_tree(struct tree_entry *root)
die("Can't load tree %s", oid_to_hex(oid));
} else {
enum object_type type;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_TREE)
die("Can't load tree %s", oid_to_hex(oid));
}
@@ -3002,7 +3002,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
char *buf;
if (!oe || oe->pack_id == MAX_PACK_ID) {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
} else {
type = oe->type;
buf = gfi_unpack_entry(oe, &size);
@@ -3110,8 +3110,8 @@ static struct object_entry *dereference(struct object_entry *oe,
buf = gfi_unpack_entry(oe, &size);
} else {
enum object_type unused;
- buf = repo_read_object_file(the_repository, oid, &unused,
- &size);
+ buf = odb_read_object(the_repository->objects, oid,
+ &unused, &size);
}
if (!buf)
die("Can't load object %s", oid_to_hex(oid));
diff --git a/builtin/grep.c b/builtin/grep.c
index 1435d462cd1..5de61dfffe8 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -573,8 +573,8 @@ static int grep_cache(struct grep_opt *opt,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository, &ce->oid,
- &type, &size);
+ data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &size);
if (!data)
die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
init_tree_desc(&tree, &ce->oid, data, size);
@@ -666,8 +666,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository,
- &entry.oid, &type, &size);
+ data = odb_read_object(the_repository->objects,
+ &entry.oid, &type, &size);
if (!data)
die(_("unable to read tree (%s)"),
oid_to_hex(&entry.oid));
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index d0b16908122..180d261f6ce 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -914,8 +914,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
- has_data = repo_read_object_file(the_repository, oid,
- &has_type, &has_size);
+ has_data = odb_read_object(the_repository->objects, oid,
+ &has_type, &has_size);
read_unlock();
if (!data)
data = new_data = get_data_from_pack(obj_entry);
@@ -1521,8 +1521,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue;
- data = repo_read_object_file(the_repository, &d->oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &d->oid,
+ &type, &size);
if (!data)
continue;
diff --git a/builtin/log.c b/builtin/log.c
index fe9cc5ebecb..f2040b18159 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -714,7 +714,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
unsigned long offset = 0;
if (!buf)
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index b1a17787bcf..cf8b06cadc7 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -75,9 +75,9 @@ static void *result(struct merge_list *entry, unsigned long *size)
const char *path = entry->path;
if (!entry->stage)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid, &type,
- size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid, &type,
+ size);
base = NULL;
if (entry->stage == 1) {
base = entry->blob;
@@ -100,9 +100,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)
enum object_type type;
while (entry) {
if (entry->stage == 2)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid,
+ &type, size);
entry = entry->link;
}
return NULL;
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 1809b38f937..1b391119de8 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -54,8 +54,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
void *buffer;
const struct object_id *repl;
- buffer = repo_read_object_file(the_repository, tagged_oid, &type,
- &size);
+ buffer = odb_read_object(the_repository->objects, tagged_oid,
+ &type, &size);
if (!buffer)
die(_("could not read tagged object '%s'"),
oid_to_hex(tagged_oid));
diff --git a/builtin/notes.c b/builtin/notes.c
index 783d4932ca6..a9529b1696a 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -152,7 +152,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (buf) {
if (size)
write_or_die(fd, buf, size);
@@ -319,7 +319,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
strbuf_init(&msg->buf, 0);
if (repo_get_oid(the_repository, arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
- if (!(value = repo_read_object_file(the_repository, &object, &type, &len)))
+ if (!(value = odb_read_object(the_repository->objects, &object, &type, &len)))
die(_("failed to read object '%s'."), arg);
if (type != OBJ_BLOB) {
strbuf_release(&msg->buf);
@@ -722,7 +722,7 @@ static int append_edit(int argc, const char **argv, const char *prefix,
unsigned long size;
enum object_type type;
struct strbuf buf = STRBUF_INIT;
- char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
+ char *prev_buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!prev_buf)
die(_("unable to read %s"), oid_to_hex(note));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index da35d684081..580a5c1996b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -337,13 +337,13 @@ static void *get_delta(struct object_entry *entry)
void *buf, *base_buf, *delta_buf;
enum object_type type;
- buf = repo_read_object_file(the_repository, &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &entry->idx.oid,
+ &type, &size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
- base_buf = repo_read_object_file(the_repository,
- &DELTA(entry)->idx.oid, &type,
- &base_size);
+ base_buf = odb_read_object(the_repository->objects,
+ &DELTA(entry)->idx.oid, &type,
+ &base_size);
if (!base_buf)
die("unable to read %s",
oid_to_hex(&DELTA(entry)->idx.oid));
@@ -506,9 +506,9 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
&size, NULL)) != NULL)
buf = NULL;
else {
- buf = repo_read_object_file(the_repository,
- &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects,
+ &entry->idx.oid, &type,
+ &size);
if (!buf)
die(_("unable to read %s"),
oid_to_hex(&entry->idx.oid));
@@ -1895,7 +1895,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
/* Did not find one. Either we got a bogus request or
* we need to read and perhaps cache.
*/
- data = repo_read_object_file(the_repository, oid, &type, &size);
+ data = odb_read_object(the_repository->objects, oid, &type, &size);
if (!data)
return NULL;
if (type != OBJ_TREE) {
@@ -2762,9 +2762,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
/* Load data if not already done */
if (!trg->data) {
packing_data_lock(&to_pack);
- trg->data = repo_read_object_file(the_repository,
- &trg_entry->idx.oid, &type,
- &sz);
+ trg->data = odb_read_object(the_repository->objects,
+ &trg_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!trg->data)
die(_("object %s cannot be read"),
@@ -2777,9 +2777,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
}
if (!src->data) {
packing_data_lock(&to_pack);
- src->data = repo_read_object_file(the_repository,
- &src_entry->idx.oid, &type,
- &sz);
+ src->data = odb_read_object(the_repository->objects,
+ &src_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!src->data) {
if (src_entry->preferred_base) {
diff --git a/builtin/tag.c b/builtin/tag.c
index e0b27396c6b..46cbf892e34 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -244,7 +244,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
struct strbuf payload = STRBUF_INIT;
struct strbuf signature = STRBUF_INIT;
- orig = buf = repo_read_object_file(the_repository, oid, &type, &size);
+ orig = buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return;
if (parse_signature(buf, size, &payload, &signature)) {
@@ -407,7 +407,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
strbuf_addstr(sb, "object of unknown type");
break;
case OBJ_COMMIT:
- if ((buf = repo_read_object_file(the_repository, oid, &type, &size))) {
+ if ((buf = odb_read_object(the_repository->objects, oid, &type, &size))) {
subject_len = find_commit_subject(buf, &subject_start);
strbuf_insert(sb, sb->len, subject_start, subject_len);
} else {
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index b92fd4710a9..4360872ae07 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -14,7 +14,7 @@ static char *create_temp_file(struct object_id *oid)
unsigned long size;
int fd;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 405e78bc592..4bc6575a574 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -516,8 +516,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
return;
- base = repo_read_object_file(the_repository, &base_oid, &type,
- &base_size);
+ base = odb_read_object(the_repository->objects, &base_oid,
+ &type, &base_size);
if (!base) {
error("failed to read delta-pack base object %s",
oid_to_hex(&base_oid));
diff --git a/bundle.c b/bundle.c
index e09e3c2f58c..717f056a454 100644
--- a/bundle.c
+++ b/bundle.c
@@ -305,7 +305,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
if (revs->max_age == -1 && revs->min_age == -1)
goto out;
- buf = repo_read_object_file(the_repository, &tag->oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &tag->oid, &type, &size);
if (!buf)
goto out;
line = memmem(buf, size, "\ntagger ", 8);
diff --git a/combine-diff.c b/combine-diff.c
index cf23a753407..4ea2dc93c4f 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -325,7 +325,7 @@ static char *grab_blob(struct repository *r,
*size = fill_textconv(r, textconv, df, &blob);
free_filespec(df);
} else {
- blob = repo_read_object_file(r, oid, &type, size);
+ blob = odb_read_object(r->objects, oid, &type, size);
if (!blob)
die(_("unable to read %s"), oid_to_hex(oid));
if (type != OBJ_BLOB)
diff --git a/commit.c b/commit.c
index d4aa9c7a5f8..28ee6b73ae6 100644
--- a/commit.c
+++ b/commit.c
@@ -374,7 +374,7 @@ const void *repo_get_commit_buffer(struct repository *r,
if (!ret) {
enum object_type type;
unsigned long size;
- ret = repo_read_object_file(r, &commit->object.oid, &type, &size);
+ ret = odb_read_object(r->objects, &commit->object.oid, &type, &size);
if (!ret)
die("cannot read commit object %s",
oid_to_hex(&commit->object.oid));
@@ -1275,8 +1275,8 @@ static void handle_signed_tag(const struct commit *parent, struct commit_extra_h
desc = merge_remote_util(parent);
if (!desc || !desc->obj)
return;
- buf = repo_read_object_file(the_repository, &desc->obj->oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &desc->obj->oid,
+ &type, &size);
if (!buf || type != OBJ_TAG)
goto free_return;
if (!parse_signature(buf, size, &payload, &signature))
diff --git a/config.c b/config.c
index 883dd066827..142c37215a8 100644
--- a/config.c
+++ b/config.c
@@ -1942,7 +1942,7 @@ int git_config_from_blob_oid(config_fn_t fn,
unsigned long size;
int ret;
- buf = repo_read_object_file(repo, oid, &type, &size);
+ buf = odb_read_object(repo->objects, oid, &type, &size);
if (!buf)
return error(_("unable to load config blob object '%s'"), name);
if (type != OBJ_BLOB) {
diff --git a/dir.c b/dir.c
index a374972b624..cb7bd873b17 100644
--- a/dir.c
+++ b/dir.c
@@ -302,7 +302,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
*size_out = 0;
*data_out = NULL;
- data = repo_read_object_file(the_repository, oid, &type, &sz);
+ data = odb_read_object(the_repository->objects, oid, &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return -1;
diff --git a/entry.c b/entry.c
index 75d55038d7c..cae02eb5039 100644
--- a/entry.c
+++ b/entry.c
@@ -93,8 +93,8 @@ void *read_blob_entry(const struct cache_entry *ce, size_t *size)
{
enum object_type type;
unsigned long ul;
- void *blob_data = repo_read_object_file(the_repository, &ce->oid,
- &type, &ul);
+ void *blob_data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &ul);
*size = ul;
if (blob_data) {
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 1a8c972adf3..40174efa3de 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -526,8 +526,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
struct object_id *oid = origins.items[i].util;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository, oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects, oid,
+ &type, &size);
char *origbuf = buf;
unsigned long len = size;
struct signature_check sigc = { NULL };
diff --git a/fsck.c b/fsck.c
index e69baab3af7..23965e1880f 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1293,7 +1293,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
if (oidset_contains(blobs_done, oid))
continue;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
if (is_promisor_object(the_repository, oid))
continue;
diff --git a/grep.c b/grep.c
index dc77e6c4631..932647e4a65 100644
--- a/grep.c
+++ b/grep.c
@@ -1931,8 +1931,8 @@ static int grep_source_load_oid(struct grep_source *gs)
{
enum object_type type;
- gs->buf = repo_read_object_file(gs->repo, gs->identifier, &type,
- &gs->size);
+ gs->buf = odb_read_object(gs->repo->objects, gs->identifier,
+ &type, &gs->size);
if (!gs->buf)
return error(_("'%s': unable to read %s"),
gs->name,
diff --git a/http-push.c b/http-push.c
index d1b1bb23711..9481825abfb 100644
--- a/http-push.c
+++ b/http-push.c
@@ -369,8 +369,8 @@ static void start_put(struct transfer_request *request)
ssize_t size;
git_zstream stream;
- unpacked = repo_read_object_file(the_repository, &request->obj->oid,
- &type, &len);
+ unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
+ &type, &len);
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
/* Set it up */
diff --git a/mailmap.c b/mailmap.c
index b18e74c2110..56c72102d9e 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -196,7 +196,7 @@ int read_mailmap_blob(struct string_list *map, const char *name)
if (repo_get_oid(the_repository, name, &oid) < 0)
return 0;
- buf = repo_read_object_file(the_repository, &oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &oid, &type, &size);
if (!buf)
return error("unable to read mailmap object at %s", name);
if (type != OBJ_BLOB) {
diff --git a/match-trees.c b/match-trees.c
index 4704f95c340..5a8a5c39b04 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -63,7 +63,7 @@ static void *fill_tree_desc_strict(struct repository *r,
enum object_type type;
unsigned long size;
- buffer = repo_read_object_file(r, hash, &type, &size);
+ buffer = odb_read_object(r->objects, hash, &type, &size);
if (!buffer)
die("unable to read tree (%s)", oid_to_hex(hash));
if (type != OBJ_TREE)
@@ -199,7 +199,7 @@ static int splice_tree(struct repository *r,
if (*subpath)
subpath++;
- buf = repo_read_object_file(r, oid1, &type, &sz);
+ buf = odb_read_object(r->objects, oid1, &type, &sz);
if (!buf)
die("cannot read tree %s", oid_to_hex(oid1));
init_tree_desc(&desc, oid1, buf, sz);
diff --git a/merge-blobs.c b/merge-blobs.c
index ba8a3fdfd82..6fc27994171 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -12,8 +12,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
unsigned long size;
enum object_type type;
- buf = repo_read_object_file(the_repository, &obj->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &obj->object.oid,
+ &type, &size);
if (!buf)
return -1;
if (type != OBJ_BLOB) {
@@ -79,8 +79,8 @@ void *merge_blobs(struct index_state *istate, const char *path,
return NULL;
if (!our)
our = their;
- return repo_read_object_file(the_repository, &our->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects, &our->object.oid,
+ &type, size);
}
if (fill_mmfile_blob(&f1, our) < 0)
diff --git a/merge-ort.c b/merge-ort.c
index f29417040c1..473ff61e36e 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -3629,7 +3629,7 @@ static int read_oid_strbuf(struct merge_options *opt,
void *buf;
enum object_type type;
unsigned long size;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
path, NULL, NULL, NULL,
diff --git a/notes-cache.c b/notes-cache.c
index 344f67762b8..dd56feed6e8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -87,7 +87,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
value_oid = get_note(&c->tree, key_oid);
if (!value_oid)
return NULL;
- value = repo_read_object_file(the_repository, value_oid, &type, &size);
+ value = odb_read_object(the_repository->objects, value_oid, &type, &size);
*outsize = size;
return value;
diff --git a/notes-merge.c b/notes-merge.c
index de6a52e2e7f..586939939f2 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -340,7 +340,7 @@ static void write_note_to_worktree(const struct object_id *obj,
{
enum object_type type;
unsigned long size;
- void *buf = repo_read_object_file(the_repository, note, &type, &size);
+ void *buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!buf)
die("cannot read note %s for object %s",
diff --git a/notes.c b/notes.c
index fc000e501d2..73eb5f00cf5 100644
--- a/notes.c
+++ b/notes.c
@@ -816,15 +816,15 @@ int combine_notes_concatenate(struct object_id *cur_oid,
/* read in both note blob objects */
if (!is_null_oid(new_oid))
- new_msg = repo_read_object_file(the_repository, new_oid,
- &new_type, &new_len);
+ new_msg = odb_read_object(the_repository->objects, new_oid,
+ &new_type, &new_len);
if (!new_msg || !new_len || new_type != OBJ_BLOB) {
free(new_msg);
return 0;
}
if (!is_null_oid(cur_oid))
- cur_msg = repo_read_object_file(the_repository, cur_oid,
- &cur_type, &cur_len);
+ cur_msg = odb_read_object(the_repository->objects, cur_oid,
+ &cur_type, &cur_len);
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
free(cur_msg);
free(new_msg);
@@ -880,7 +880,7 @@ static int string_list_add_note_lines(struct string_list *list,
return 0;
/* read_sha1_file NUL-terminates */
- data = repo_read_object_file(the_repository, oid, &t, &len);
+ data = odb_read_object(the_repository->objects, oid, &t, &len);
if (t != OBJ_BLOB || !data || !len) {
free(data);
return t != OBJ_BLOB || !data;
@@ -1290,7 +1290,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!oid)
return;
- if (!(msg = repo_read_object_file(the_repository, oid, &type, &msglen)) || type != OBJ_BLOB) {
+ if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
+ type != OBJ_BLOB) {
free(msg);
return;
}
diff --git a/object.c b/object.c
index 868d89eed42..c1553ee4330 100644
--- a/object.c
+++ b/object.c
@@ -335,7 +335,7 @@ struct object *parse_object_with_flags(struct repository *r,
return &lookup_tree(r, oid)->object;
}
- buffer = repo_read_object_file(r, oid, &type, &size);
+ buffer = odb_read_object(r->objects, oid, &type, &size);
if (buffer) {
if (!skip_hash &&
check_object_signature(r, repl, buffer, size, type) < 0) {
diff --git a/odb.c b/odb.c
index cc1cc727346..15f81401c9a 100644
--- a/odb.c
+++ b/odb.c
@@ -30,7 +30,7 @@ KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -887,15 +887,10 @@ int pretend_object_file(struct repository *repo,
return 0;
}
-/*
- * This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call odb_read_object_info_extended() and give
- * error messages themselves.
- */
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size)
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
{
struct object_info oi = OBJECT_INFO_INIT;
unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT | OBJECT_INFO_LOOKUP_REPLACE;
@@ -904,7 +899,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
+ if (odb_read_object_info_extended(odb, oid, &oi, flags))
return NULL;
return data;
@@ -926,7 +921,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = repo_read_object_file(r, &actual_oid, &type, &isize);
+ buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
diff --git a/odb.h b/odb.h
index fd99bd593f7..4a5c9eaf0a9 100644
--- a/odb.h
+++ b/odb.h
@@ -140,7 +140,7 @@ struct object_database {
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -259,10 +259,19 @@ void odb_add_to_alternates_file(struct object_database *odb,
void odb_add_to_alternates_memory(struct object_database *odb,
const char *dir);
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size);
+/*
+ * Read an object from the database. Returns the object data and assigns object
+ * type and size to the `type` and `size` pointers, if these pointers are
+ * non-NULL. Returns a `NULL` pointer in case the object does not exist.
+ *
+ * This function dies on corrupt objects; the callers who want to deal with
+ * them should arrange to call odb_read_object_info_extended() and give error
+ * messages themselves.
+ */
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size);
/*
* Add an object file to the in-memory object store, without writing it
@@ -370,7 +379,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
- * following functions in parallel: repo_read_object_file(),
+ * following functions in parallel: odb_read_object(),
* read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
@@ -445,4 +454,12 @@ static inline int oid_object_info(struct repository *r,
return odb_read_object_info(r->objects, oid, sizep);
}
+static inline void *repo_read_object_file(struct repository *r,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
+{
+ return odb_read_object(r->objects, oid, type, size);
+}
+
#endif /* ODB_H */
diff --git a/read-cache.c b/read-cache.c
index 7d5bccf95dc..531d87e7905 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -254,7 +254,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
if (strbuf_readlink(&sb, ce->name, expected_size))
return -1;
- buffer = repo_read_object_file(the_repository, &ce->oid, &type, &size);
+ buffer = odb_read_object(the_repository->objects, &ce->oid, &type, &size);
if (buffer) {
if (size == sb.len)
match = memcmp(buffer, sb.buf, size);
@@ -3485,8 +3485,8 @@ void *read_blob_data_from_index(struct index_state *istate,
}
if (pos < 0)
return NULL;
- data = repo_read_object_file(the_repository, &istate->cache[pos]->oid,
- &type, &sz);
+ data = odb_read_object(the_repository->objects, &istate->cache[pos]->oid,
+ &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return NULL;
diff --git a/reflog.c b/reflog.c
index 4f8a3b717cd..747b82eada8 100644
--- a/reflog.c
+++ b/reflog.c
@@ -140,8 +140,8 @@ static int tree_is_complete(const struct object_id *oid)
if (!tree->buffer) {
enum object_type type;
unsigned long size;
- void *data = repo_read_object_file(the_repository, oid, &type,
- &size);
+ void *data = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!data) {
tree->object.flags |= INCOMPLETE;
return 0;
diff --git a/rerere.c b/rerere.c
index 951e4bf8b41..8bb97c98229 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1000,9 +1000,8 @@ static int handle_cache(struct index_state *istate,
break;
i = ce_stage(ce) - 1;
if (!mmfile[i].ptr) {
- mmfile[i].ptr = repo_read_object_file(the_repository,
- &ce->oid, &type,
- &size);
+ mmfile[i].ptr = odb_read_object(the_repository->objects,
+ &ce->oid, &type, &size);
if (!mmfile[i].ptr)
die(_("unable to read %s"),
oid_to_hex(&ce->oid));
diff --git a/submodule-config.c b/submodule-config.c
index a9f72107888..ea3a087a8bb 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -743,8 +743,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
if (submodule)
goto out;
- config = repo_read_object_file(the_repository, &oid, &type,
- &config_size);
+ config = odb_read_object(the_repository->objects, &oid,
+ &type, &config_size);
if (!config || type != OBJ_BLOB)
goto out;
diff --git a/tag.c b/tag.c
index 144048fd5e0..1d52686ee10 100644
--- a/tag.c
+++ b/tag.c
@@ -60,7 +60,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV),
type_name(type));
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return error("%s: unable to read file.",
name_to_report ?
@@ -222,8 +222,8 @@ int parse_tag(struct tag *item)
if (item->object.parsed)
return 0;
- data = repo_read_object_file(the_repository, &item->object.oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!data)
return error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/tree-walk.c b/tree-walk.c
index 34b0fff4873..766af99f466 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -795,9 +795,9 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
*/
retval = DANGLING_SYMLINK;
- contents = repo_read_object_file(r,
- ¤t_tree_oid, &type,
- &link_len);
+ contents = odb_read_object(r->objects,
+ ¤t_tree_oid, &type,
+ &link_len);
if (!contents)
goto done;
diff --git a/tree.c b/tree.c
index 341b7c2ff3f..1ef743d90f4 100644
--- a/tree.c
+++ b/tree.c
@@ -193,8 +193,8 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
if (item->object.parsed)
return 0;
- buffer = repo_read_object_file(the_repository, &item->object.oid,
- &type, &size);
+ buffer = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!buffer)
return quiet_on_missing ? -1 :
error("Could not read %s",
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 01e6e378ea6..0e5d38c9600 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -187,7 +187,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
return;
}
- ptr->ptr = repo_read_object_file(the_repository, oid, &type, &size);
+ ptr->ptr = odb_read_object(the_repository->objects, oid, &type, &size);
if (!ptr->ptr || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
ptr->size = size;
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 15/17] odb: rename `has_object()`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (13 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
` (2 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `has_object()` to `odb_has_object()` to match other functions
related to the object database and our modern coding guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 2 +-
builtin/backfill.c | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/clone.c | 2 +-
builtin/fetch.c | 17 +++++++++--------
builtin/fsck.c | 2 +-
builtin/index-pack.c | 4 ++--
builtin/pack-objects.c | 4 ++--
builtin/receive-pack.c | 4 ++--
builtin/remote.c | 4 ++--
builtin/show-ref.c | 4 ++--
builtin/unpack-objects.c | 4 ++--
bulk-checkin.c | 4 ++--
cache-tree.c | 15 ++++++++-------
commit-graph.c | 2 +-
commit.c | 2 +-
fetch-pack.c | 8 ++++----
http-push.c | 14 ++++++++------
http-walker.c | 8 ++++----
list-objects.c | 4 ++--
notes.c | 4 ++--
odb.c | 6 +++---
odb.h | 12 ++++++++++--
reflog.c | 2 +-
refs.c | 3 ++-
remote.c | 2 +-
send-pack.c | 2 +-
shallow.c | 12 ++++++------
upload-pack.c | 2 +-
walker.c | 4 ++--
30 files changed, 87 insertions(+), 74 deletions(-)
diff --git a/apply.c b/apply.c
index a34ced04625..a6836692d0c 100644
--- a/apply.c
+++ b/apply.c
@@ -3204,7 +3204,7 @@ static int apply_binary(struct apply_state *state,
return 0; /* deletion patch */
}
- if (has_object(the_repository, &oid, 0)) {
+ if (odb_has_object(the_repository->objects, &oid, 0)) {
/* We already have the postimage */
enum object_type type;
unsigned long size;
diff --git a/builtin/backfill.c b/builtin/backfill.c
index 0b49baa39fa..80056abe473 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -67,8 +67,8 @@ static int fill_missing_blobs(const char *path UNUSED,
return 0;
for (size_t i = 0; i < list->nr; i++) {
- if (!has_object(ctx->repo, &list->oid[i],
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_has_object(ctx->repo->objects, &list->oid[i],
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&ctx->current_batch, &list->oid[i]);
}
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 90a3e159d11..01672ec74bd 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -160,8 +160,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
goto cleanup;
case 'e':
- ret = !has_object(the_repository, &oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
+ ret = !odb_has_object(the_repository->objects, &oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
goto cleanup;
case 'w':
diff --git a/builtin/clone.c b/builtin/clone.c
index 3aabdf6570b..6d08abed37c 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -506,7 +506,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
continue;
if (ends_with(ref->name, "^{}"))
continue;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
refs_update_ref(get_main_ref_store(the_repository), msg,
ref->name, &ref->old_oid, NULL, 0,
diff --git a/builtin/fetch.c b/builtin/fetch.c
index b842bc9c51b..65ea6c84368 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -366,9 +366,9 @@ static void find_non_local_tags(const struct ref *refs,
*/
if (ends_with(ref->name, "^{}")) {
if (item &&
- !has_object(the_repository, &ref->old_oid, 0) &&
+ !odb_has_object(the_repository->objects, &ref->old_oid, 0) &&
!oidset_contains(&fetch_oids, &ref->old_oid) &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
item = NULL;
@@ -382,7 +382,7 @@ static void find_non_local_tags(const struct ref *refs,
* fetch.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -403,7 +403,7 @@ static void find_non_local_tags(const struct ref *refs,
* checked to see if it needs fetching.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -910,8 +910,8 @@ static int update_local_ref(struct ref *ref,
struct commit *current = NULL, *updated;
int fast_forward = 0;
- if (!has_object(the_repository, &ref->new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &ref->new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
if (oideq(&ref->old_oid, &ref->new_oid)) {
@@ -1330,7 +1330,8 @@ static int check_exist_and_connected(struct ref *ref_map)
* we need all direct targets to exist.
*/
for (r = rm; r; r = r->next) {
- if (!has_object(the_repository, &r->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ if (!odb_has_object(the_repository->objects, &r->old_oid,
+ HAS_OBJECT_RECHECK_PACKED))
return -1;
}
@@ -1485,7 +1486,7 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
struct object_id oid;
if (repo_get_oid(the_repository, s, &oid))
die(_("%s is not a valid object"), s);
- if (!has_object(the_repository, &oid, 0))
+ if (!odb_has_object(the_repository->objects, &oid, 0))
die(_("the object %s does not exist"), s);
oid_array_append(oids, &oid);
continue;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6e3465b0266..0084cf7400b 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -161,7 +161,7 @@ static int mark_object(struct object *obj, enum object_type type,
return 0;
if (!(obj->flags & HAS_OBJ)) {
- if (parent && !has_object(the_repository, &obj->oid, 1)) {
+ if (parent && !odb_has_object(the_repository->objects, &obj->oid, 1)) {
printf_ln(_("broken link from %7s %s\n"
" to %7s %s"),
printable_type(&parent->oid, parent->type),
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 180d261f6ce..19c67a85344 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -893,8 +893,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (startup_info->have_repository) {
read_lock();
- collision_test_needed = has_object(the_repository, oid,
- HAS_OBJECT_FETCH_PROMISOR);
+ collision_test_needed = odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_FETCH_PROMISOR);
read_unlock();
}
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 580a5c1996b..06bdeb4223b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3968,7 +3968,7 @@ static void show_object__ma_allow_any(struct object *obj, const char *name, void
* Quietly ignore ALL missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0))
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0))
return;
show_object(obj, name, data);
@@ -3982,7 +3982,7 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
* Quietly ignore EXPECTED missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0) &&
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0) &&
is_promisor_object(to_pack.repo, &obj->oid))
return;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 7ea273d93e4..26e77d70726 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1509,8 +1509,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
}
if (!is_null_oid(new_oid) &&
- !has_object(the_repository, new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error("unpack should have generated %s, "
"but I can't find it!", oid_to_hex(new_oid));
ret = "bad pack";
diff --git a/builtin/remote.c b/builtin/remote.c
index ac5b8d2a1a6..7cbda285ebe 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -454,8 +454,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
info->status = PUSH_STATUS_UPTODATE;
else if (is_null_oid(&ref->old_oid))
info->status = PUSH_STATUS_CREATE;
- else if (has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ else if (odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
ref_newer(&ref->new_oid, &ref->old_oid))
info->status = PUSH_STATUS_FASTFORWARD;
else
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 90ec1de78f9..117709cb076 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -35,8 +35,8 @@ static void show_one(const struct show_one_options *opts,
const char *hex;
struct object_id peeled;
- if (!has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die("git show-ref: bad ref %s (%s)", refname,
oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 4bc6575a574..a69d59eb50c 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -449,8 +449,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
delta_data = get_data(delta_size);
if (!delta_data)
return;
- if (has_object(the_repository, &base_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &base_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
; /* Ok we have this one */
else if (resolve_against_held(nr, &base_oid,
delta_data, delta_size))
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 55406a539e7..16df86c0ba8 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -130,8 +130,8 @@ static void flush_batch_fsync(void)
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
{
/* The object may already exist in the repository */
- if (has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 1;
/* Might want to keep the list sorted */
diff --git a/cache-tree.c b/cache-tree.c
index 9786b32b3a1..a4bc14ad15c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -239,8 +239,8 @@ int cache_tree_fully_valid(struct cache_tree *it)
if (!it)
return 0;
if (it->entry_count < 0 ||
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
for (i = 0; i < it->subtree_nr; i++) {
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -292,8 +292,8 @@ static int update_one(struct cache_tree *it,
}
if (0 <= it->entry_count &&
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return it->entry_count;
/*
@@ -399,8 +399,9 @@ static int update_one(struct cache_tree *it,
ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
!must_check_existence(ce);
if (is_null_oid(oid) ||
- (!ce_missing_ok && !has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
+ (!ce_missing_ok &&
+ !odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
strbuf_release(&buffer);
if (expected_missing)
return -1;
@@ -448,7 +449,7 @@ static int update_one(struct cache_tree *it,
struct object_id oid;
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
OBJ_TREE, &oid);
- if (has_object(the_repository, &oid, HAS_OBJECT_RECHECK_PACKED))
+ if (odb_has_object(the_repository->objects, &oid, HAS_OBJECT_RECHECK_PACKED))
oidcpy(&it->oid, &oid);
else
to_invalidate = 1;
diff --git a/commit-graph.c b/commit-graph.c
index 5f482d3377f..bd7b6f5338b 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1040,7 +1040,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
return NULL;
if (!search_commit_pos_in_graph(id, repo->objects->commit_graph, &pos))
return NULL;
- if (commit_graph_paranoia && !has_object(repo, id, 0))
+ if (commit_graph_paranoia && !odb_has_object(repo->objects, id, 0))
return NULL;
commit = lookup_commit(repo, id);
diff --git a/commit.c b/commit.c
index 28ee6b73ae6..15115125c36 100644
--- a/commit.c
+++ b/commit.c
@@ -575,7 +575,7 @@ int repo_parse_commit_internal(struct repository *r,
if (commit_graph_paranoia == -1)
commit_graph_paranoia = git_env_bool(GIT_COMMIT_GRAPH_PARANOIA, 0);
- if (commit_graph_paranoia && !has_object(r, &item->object.oid, 0)) {
+ if (commit_graph_paranoia && !odb_has_object(r->objects, &item->object.oid, 0)) {
unparse_commit(r, &item->object.oid);
return quiet_on_missing ? -1 :
error(_("commit %s exists in commit-graph but not in the object database"),
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f5de1c94d1..5e74235fc06 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -142,7 +142,7 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
commit = lookup_commit_in_graph(the_repository, oid);
if (commit) {
if (mark_tags_complete_and_check_obj_db) {
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
die_in_commit_graph_only(oid);
}
return commit;
@@ -770,7 +770,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
if (!commit) {
struct object *o;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
o = parse_object(the_repository, &ref->old_oid);
if (!o || o->type != OBJ_COMMIT)
@@ -1984,8 +1984,8 @@ static void update_shallow(struct fetch_pack_args *args,
struct oid_array extra = OID_ARRAY_INIT;
struct object_id *oid = si->shallow->oid;
for (i = 0; i < si->shallow->nr; i++)
- if (has_object(the_repository, &oid[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &oid[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
oid_array_append(&extra, &oid[i]);
if (extra.nr) {
setup_alternate_shallow(&shallow_lock,
diff --git a/http-push.c b/http-push.c
index 9481825abfb..beb41732fb6 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1447,8 +1447,8 @@ static void one_remote_ref(const char *refname)
* may be required for updating server info later.
*/
if (repo->can_update_info_refs &&
- !has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
obj = lookup_unknown_object(the_repository, &ref->old_oid);
fprintf(stderr, " fetch %s for %s\n",
oid_to_hex(&ref->old_oid), refname);
@@ -1653,14 +1653,16 @@ static int delete_remote_branch(const char *pattern, int force)
return error("Remote HEAD symrefs too deep");
if (is_null_oid(&head_oid))
return error("Unable to resolve remote HEAD");
- if (!has_object(the_repository, &head_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &head_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", oid_to_hex(&head_oid));
/* Remote branch must resolve to a known object */
if (is_null_oid(&remote_ref->old_oid))
return error("Unable to resolve remote branch %s",
remote_ref->name);
- if (!has_object(the_repository, &remote_ref->old_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &remote_ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, oid_to_hex(&remote_ref->old_oid));
/* Remote branch must be an ancestor of remote HEAD */
@@ -1881,8 +1883,8 @@ int cmd_main(int argc, const char **argv)
if (!force_all &&
!is_null_oid(&ref->old_oid) &&
!ref->force) {
- if (!has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
+ if (!odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
!ref_newer(&ref->peer_ref->new_oid,
&ref->old_oid)) {
/*
diff --git a/http-walker.c b/http-walker.c
index 05fb9ce714a..0f7ae46d7f1 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -138,8 +138,8 @@ static int fill_active_slot(void *data UNUSED)
list_for_each_safe(pos, tmp, head) {
obj_req = list_entry(pos, struct object_request, node);
if (obj_req->state == WAITING) {
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
obj_req->state = COMPLETE;
else {
start_object_request(obj_req);
@@ -497,8 +497,8 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
if (!obj_req)
return error("Couldn't find request for %s in the queue", hex);
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
if (obj_req->req)
abort_http_object_request(&obj_req->req);
abort_object_request(obj_req);
diff --git a/list-objects.c b/list-objects.c
index c50b9578584..42c17d95739 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -74,8 +74,8 @@ static void process_blob(struct traversal_context *ctx,
* of missing objects.
*/
if (ctx->revs->exclude_promisor_objects &&
- !has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ !odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
is_promisor_object(ctx->revs->repo, &obj->oid))
return;
diff --git a/notes.c b/notes.c
index 73eb5f00cf5..97b995f3f2d 100644
--- a/notes.c
+++ b/notes.c
@@ -794,8 +794,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
struct note_delete_list **l = (struct note_delete_list **) cb_data;
struct note_delete_list *n;
- if (has_object(the_repository, object_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, object_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0; /* nothing to do for this note */
/* failed to find object => prune this note */
diff --git a/odb.c b/odb.c
index 15f81401c9a..ad2a621698c 100644
--- a/odb.c
+++ b/odb.c
@@ -871,7 +871,7 @@ int pretend_object_file(struct repository *repo,
char *co_buf;
hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (has_object(repo, oid, 0) ||
+ if (odb_has_object(repo->objects, oid, 0) ||
find_cached_object(repo->objects, oid))
return 0;
@@ -953,7 +953,7 @@ void *read_object_with_reference(struct repository *r,
}
}
-int has_object(struct repository *r, const struct object_id *oid,
+int odb_has_object(struct object_database *odb, const struct object_id *oid,
unsigned flags)
{
unsigned object_info_flags = 0;
@@ -965,7 +965,7 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(odb, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
diff --git a/odb.h b/odb.h
index 4a5c9eaf0a9..09cfd9e01f9 100644
--- a/odb.h
+++ b/odb.h
@@ -371,8 +371,9 @@ enum {
* Returns 1 if the object exists. This function will not lazily fetch objects
* in a partial clone by default.
*/
-int has_object(struct repository *r, const struct object_id *oid,
- unsigned flags);
+int odb_has_object(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned flags);
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect);
@@ -462,4 +463,11 @@ static inline void *repo_read_object_file(struct repository *r,
return odb_read_object(r->objects, oid, type, size);
}
+static inline int has_object(struct repository *r,
+ const struct object_id *oid,
+ unsigned flags)
+{
+ return odb_has_object(r->objects, oid, flags);
+}
+
#endif /* ODB_H */
diff --git a/reflog.c b/reflog.c
index 747b82eada8..39c205fd26e 100644
--- a/reflog.c
+++ b/reflog.c
@@ -152,7 +152,7 @@ static int tree_is_complete(const struct object_id *oid)
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
complete = 1;
while (tree_entry(&desc, &entry)) {
- if (!has_object(the_repository, &entry.oid,
+ if (!odb_has_object(the_repository->objects, &entry.oid,
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
(S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) {
tree->object.flags |= INCOMPLETE;
diff --git a/refs.c b/refs.c
index 0ff0e582a6b..26e5c2a7d9c 100644
--- a/refs.c
+++ b/refs.c
@@ -376,7 +376,8 @@ int ref_resolves_to_object(const char *refname,
{
if (flags & REF_ISBROKEN)
return 0;
- if (!has_object(repo, oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (!odb_has_object(repo->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error(_("%s does not point to a valid object!"), refname);
return 0;
}
diff --git a/remote.c b/remote.c
index 72c36239d31..5edf2a9f4b2 100644
--- a/remote.c
+++ b/remote.c
@@ -1703,7 +1703,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
if (starts_with(ref->name, "refs/tags/"))
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
- else if (!has_object(the_repository, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ else if (!odb_has_object(the_repository->objects, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||
!lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))
diff --git a/send-pack.c b/send-pack.c
index abca2dd38a7..d029f748232 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -45,7 +45,7 @@ int option_parse_push_signed(const struct option *opt,
static void feed_object(struct repository *r,
const struct object_id *oid, FILE *fh, int negative)
{
- if (negative && !has_object(r, oid, 0))
+ if (negative && !odb_has_object(r->objects, oid, 0))
return;
if (negative)
diff --git a/shallow.c b/shallow.c
index d379756e39a..ef3adb635fd 100644
--- a/shallow.c
+++ b/shallow.c
@@ -310,8 +310,8 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
if (graft->nr_parent != -1)
return 0;
if (data->flags & QUICK) {
- if (!has_object(the_repository, &graft->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &graft->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
} else if (data->flags & SEEN_ONLY) {
struct commit *c = lookup_commit(the_repository, &graft->oid);
@@ -477,8 +477,8 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
ALLOC_ARRAY(info->ours, sa->nr);
ALLOC_ARRAY(info->theirs, sa->nr);
for (size_t i = 0; i < sa->nr; i++) {
- if (has_object(the_repository, sa->oid + i,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, sa->oid + i,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
struct commit_graft *graft;
graft = lookup_commit_graft(the_repository,
&sa->oid[i]);
@@ -515,8 +515,8 @@ void remove_nonexistent_theirs_shallow(struct shallow_info *info)
for (i = dst = 0; i < info->nr_theirs; i++) {
if (i != dst)
info->theirs[dst] = info->theirs[i];
- if (has_object(the_repository, oid + info->theirs[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid + info->theirs[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
dst++;
}
info->nr_theirs = dst;
diff --git a/upload-pack.c b/upload-pack.c
index e994d6a901b..4f26f6afc77 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -509,7 +509,7 @@ static int got_oid(struct upload_pack_data *data,
{
if (get_oid_hex(hex, oid))
die("git upload-pack: expected SHA1 object, got '%s'", hex);
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
return -1;
return do_got_oid(data, oid);
}
diff --git a/walker.c b/walker.c
index a8abe8a2e78..d131af04c7b 100644
--- a/walker.c
+++ b/walker.c
@@ -150,8 +150,8 @@ static int process(struct walker *walker, struct object *obj)
return 0;
obj->flags |= SEEN;
- if (has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
/* We already have it, so we should scan it now. */
obj->flags |= TO_SCAN;
}
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 16/17] odb: rename `pretend_object_file()`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (14 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 15/17] odb: rename `has_object()` Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 10:27 ` [PATCH v4 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
2025-06-02 15:38 ` [PATCH v4 00/17] object-store: carve out the object database subsystem Junio C Hamano
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `pretend_object_file()` to `odb_pretend_object()` to match other
functions related to the object database and our modern coding
guidelines.
No compatibility wrapper is introduces as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
blame.c | 3 ++-
odb.c | 18 +++++++++---------
odb.h | 6 +++---
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/blame.c b/blame.c
index 858d2d74df9..dce5c8d855c 100644
--- a/blame.c
+++ b/blame.c
@@ -277,7 +277,8 @@ static struct commit *fake_working_tree_commit(struct repository *r,
convert_to_git(r->index, path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
- pretend_object_file(the_repository, buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
+ odb_pretend_object(the_repository->objects, buf.buf, buf.len,
+ OBJ_BLOB, &origin->blob_oid);
/*
* Read the current index, replace the path entry with
diff --git a/odb.c b/odb.c
index ad2a621698c..dd6b37eaa92 100644
--- a/odb.c
+++ b/odb.c
@@ -863,21 +863,21 @@ int odb_read_object_info(struct object_database *odb,
return type;
}
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid)
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid)
{
struct cached_object_entry *co;
char *co_buf;
- hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (odb_has_object(repo->objects, oid, 0) ||
- find_cached_object(repo->objects, oid))
+ hash_object_file(odb->repo->hash_algo, buf, len, type, oid);
+ if (odb_has_object(odb, oid, 0) ||
+ find_cached_object(odb, oid))
return 0;
- ALLOC_GROW(repo->objects->cached_objects,
- repo->objects->cached_object_nr + 1, repo->objects->cached_object_alloc);
- co = &repo->objects->cached_objects[repo->objects->cached_object_nr++];
+ ALLOC_GROW(odb->cached_objects,
+ odb->cached_object_nr + 1, odb->cached_object_alloc);
+ co = &odb->cached_objects[odb->cached_object_nr++];
co->value.size = len;
co->value.type = type;
co_buf = xmalloc(len);
diff --git a/odb.h b/odb.h
index 09cfd9e01f9..8eaa4ba7ba9 100644
--- a/odb.h
+++ b/odb.h
@@ -281,9 +281,9 @@ void *odb_read_object(struct object_database *odb,
* object in persistent storage before writing any other new objects
* that reference it.
*/
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid);
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid);
struct object_info {
/* Request */
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v4 17/17] odb: rename `read_object_with_reference()`
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (15 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
@ 2025-06-02 10:27 ` Patrick Steinhardt
2025-06-02 15:38 ` [PATCH v4 00/17] object-store: carve out the object database subsystem Junio C Hamano
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-02 10:27 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `read_object_with_reference()` to `odb_read_object_peeled()` to
match other functions related to the object database and our modern
coding guidelines. Furthermore though, the old name didn't really
describe very well what this function actually does, which is to walk
down any commit and tag objects until an object of the required type has
been found. This is generally referred to as "peeling", so the new name
should be way more descriptive.
No compatibility wrapper is introduces as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Documentation/user-manual.adoc | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/fast-import.c | 19 ++++++++-----------
builtin/grep.c | 9 +++------
builtin/pack-objects.c | 4 ++--
odb.c | 17 +++++++++--------
odb.h | 15 +++++++--------
tree-walk.c | 10 ++++------
8 files changed, 37 insertions(+), 45 deletions(-)
diff --git a/Documentation/user-manual.adoc b/Documentation/user-manual.adoc
index d2b478ad232..e86b2ad9f8a 100644
--- a/Documentation/user-manual.adoc
+++ b/Documentation/user-manual.adoc
@@ -4301,11 +4301,11 @@ Now, for the meat:
-----------------------------------------------------------------------------
case 0:
- buf = read_object_with_reference(sha1, argv[1], &size, NULL);
+ buf = odb_read_object_peeled(r->objects, sha1, argv[1], &size, NULL);
-----------------------------------------------------------------------------
This is how you read a blob (actually, not only a blob, but any type of
-object). To know how the function `read_object_with_reference()` actually
+object). To know how the function `odb_read_object_peeled()` actually
works, find the source code for it (something like `git grep
read_object_with | grep ":[a-z]"` in the Git repository), and read
the source.
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 01672ec74bd..08afecbf57c 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -246,8 +246,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
* fall-back to the usual case.
*/
}
- buf = read_object_with_reference(the_repository, &oid,
- exp_type_id, &size, NULL);
+ buf = odb_read_object_peeled(the_repository->objects, &oid,
+ exp_type_id, &size, NULL);
if (use_mailmap) {
size_t s = size;
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 1973c504e25..b1389c59211 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2535,10 +2535,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
oidcpy(&commit_oid, &commit_oe->idx.oid);
} else if (!repo_get_oid(the_repository, p, &commit_oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &commit_oid,
- OBJ_COMMIT, &size,
- &commit_oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &commit_oid, OBJ_COMMIT, &size,
+ &commit_oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", p);
free(buf);
@@ -2604,9 +2603,8 @@ static void parse_from_existing(struct branch *b)
unsigned long size;
char *buf;
- buf = read_object_with_reference(the_repository,
- &b->oid, OBJ_COMMIT, &size,
- &b->oid);
+ buf = odb_read_object_peeled(the_repository->objects, &b->oid,
+ OBJ_COMMIT, &size, &b->oid);
parse_from_commit(b, buf, size);
free(buf);
}
@@ -2699,10 +2697,9 @@ static struct hash_list *parse_merge(unsigned int *count)
oidcpy(&n->oid, &oe->idx.oid);
} else if (!repo_get_oid(the_repository, from, &n->oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &n->oid,
- OBJ_COMMIT,
- &size, &n->oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &n->oid, OBJ_COMMIT,
+ &size, &n->oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", from);
free(buf);
diff --git a/builtin/grep.c b/builtin/grep.c
index 5de61dfffe8..39273d9c0fd 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -522,9 +522,7 @@ static int grep_submodule(struct grep_opt *opt,
obj_read_lock();
object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
- data = read_object_with_reference(subrepo,
- oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(subrepo->objects, oid, OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
@@ -705,9 +703,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
struct strbuf base;
int hit, len;
- data = read_object_with_reference(opt->repo,
- &obj->oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(opt->repo->objects, &obj->oid,
+ OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 06bdeb4223b..e88a13dbb9f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2055,8 +2055,8 @@ static void add_preferred_base(struct object_id *oid)
if (window <= num_preferred_base++)
return;
- data = read_object_with_reference(the_repository, oid,
- OBJ_TREE, &size, &tree_oid);
+ data = odb_read_object_peeled(the_repository->objects, oid,
+ OBJ_TREE, &size, &tree_oid);
if (!data)
return;
diff --git a/odb.c b/odb.c
index dd6b37eaa92..b6c087c1fe0 100644
--- a/odb.c
+++ b/odb.c
@@ -905,11 +905,11 @@ void *odb_read_object(struct object_database *odb,
return data;
}
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *actual_oid_return)
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *actual_oid_return)
{
enum object_type type;
void *buffer;
@@ -921,7 +921,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
+ buffer = odb_read_object(odb, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
@@ -941,9 +941,10 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + r->hash_algo->hexsz > isize ||
+ if (ref_length + odb->repo->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid,
+ odb->repo->hash_algo)) {
free(buffer);
return NULL;
}
diff --git a/odb.h b/odb.h
index 8eaa4ba7ba9..f629380f79f 100644
--- a/odb.h
+++ b/odb.h
@@ -273,6 +273,12 @@ void *odb_read_object(struct object_database *odb,
enum object_type *type,
unsigned long *size);
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *oid_ret);
+
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -381,7 +387,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: odb_read_object(),
- * read_object_with_reference(), odb_read_object_info() and odb().
+ * odb_read_object_peeled(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -430,13 +436,6 @@ enum for_each_object_flags {
FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
};
-
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *oid_ret);
-
/* Compatibility wrappers, to be removed once Git 2.51 has been released. */
#include "repository.h"
diff --git a/tree-walk.c b/tree-walk.c
index 766af99f466..e449a1320e5 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -90,7 +90,7 @@ void *fill_tree_descriptor(struct repository *r,
void *buf = NULL;
if (oid) {
- buf = read_object_with_reference(r, oid, OBJ_TREE, &size, NULL);
+ buf = odb_read_object_peeled(r->objects, oid, OBJ_TREE, &size, NULL);
if (!buf)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
}
@@ -611,7 +611,7 @@ int get_tree_entry(struct repository *r,
unsigned long size;
struct object_id root;
- tree = read_object_with_reference(r, tree_oid, OBJ_TREE, &size, &root);
+ tree = odb_read_object_peeled(r->objects, tree_oid, OBJ_TREE, &size, &root);
if (!tree)
return -1;
@@ -681,10 +681,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
void *tree;
struct object_id root;
unsigned long size;
- tree = read_object_with_reference(r,
- ¤t_tree_oid,
- OBJ_TREE, &size,
- &root);
+ tree = odb_read_object_peeled(r->objects, ¤t_tree_oid,
+ OBJ_TREE, &size, &root);
if (!tree)
goto done;
--
2.50.0.rc0.629.g846fc57c9e.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v4 00/17] object-store: carve out the object database subsystem
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
` (16 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
@ 2025-06-02 15:38 ` Junio C Hamano
17 siblings, 0 replies; 166+ messages in thread
From: Junio C Hamano @ 2025-06-02 15:38 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Derrick Stolee, Toon Claes, Justin Tobler
Patrick Steinhardt <ps@pks.im> writes:
> This series is built on top of 6f84262c44a (The eleventh batch,
> 2025-05-05) with ps/object-store-cleanup at 8a9e27be821 (object-store:
> drop `repo_has_object_file()`, 2025-04-29) merged into it. There are a
> couple of trivial conflicts when merged with "seen", I have appended the
> merge conflict resolution as a patch at the end of this mail.
> ...
> Changes in v4:
> - Rebased the patch series on top of 7014b55638d (A bit more topics
> for -rc1, 2025-05-30). This fixes a couple of merge conflicts, most
> importantly with jk/no-funny-object-types.
Ah, the original cover letter material that was more prominent is
still left before the changes per iteration lissted here, so I was
scratching my head wondering why the series fails to apply at 02/17.
Will try to read it through before queuing.
Thanks.
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v5 00/17] object-store: carve out the object database subsystem
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (21 preceding siblings ...)
2025-06-02 10:27 ` [PATCH v4 " Patrick Steinhardt
@ 2025-06-05 6:46 ` Patrick Steinhardt
2025-06-05 6:46 ` [PATCH v5 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
` (16 more replies)
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
23 siblings, 17 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:46 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Hi,
this patch series refactors the object store subsystem to become more
self-contained by getting rid of `the_repository`. Instead of passing in
the repository explicitly, we start to pass in the object store itself,
which is in contrast to many other refactorings we did, but in line with
what we did for the ref store, as well.
This series also starts to properly scope functions to the carved out
object database subsystem, which requires a bit of shuffling. This
allows us to have a short-and-sweet `odb_` prefix for functions and
prepares us for a future with pluggable object backends.
The series is structured as follows:
- Patches 1 to 3 rename `struct object_store` and `struct
object_directory` as well as the code files.
- Patches 4 to 12 refactor "odb.c" to get rid of `the_repository`.
- Patches 13 to 17 adjust the name of remaining functions so that they
can be clearly attributed to the ODB. I'm happy to kick these
patches out of this series and resend them at a later point in case
they create too much turmoil.
This series is built on top of 6f84262c44a (The eleventh batch,
2025-05-05) with ps/object-store-cleanup at 8a9e27be821 (object-store:
drop `repo_has_object_file()`, 2025-04-29) merged into it. There are a
couple of trivial conflicts when merged with "seen", I have appended the
merge conflict resolution as a patch at the end of this mail.
Changes in v2:
- Fix for a copy-and-pasted commit message.
- Rename `struct odb_backend` to `struct odb_alternate`. I'm happy to
revert to the previous name if we ultimately think it's the better
suited one.
- A couple of fixes to move changes into the correct commit. `git
rebase -x 'meson compile -C build'` is now clean.
- I _didn't_ back out the rename to "odb.{c,h}". Junio has already
fixed the fallout, so it's probably more work for him to kick it out
again than to just leave it in.
- Link to v1: https://lore.kernel.org/r/20250506-pks-object-store-wo-the-repository-v1-0-c05b82e7b126@pks.im
Changes in v3:
- Polishing for some comments and commit messages.
- Link to v2: https://lore.kernel.org/r/20250509-pks-object-store-wo-the-repository-v2-0-103f59bf8e28@pks.im
Changes in v4:
- Rebased the patch series on top of 7014b55638d (A bit more topics
for -rc1, 2025-05-30). This fixes a couple of merge conflicts, most
importantly with jk/no-funny-object-types.
- Rename `struct odb_alternate` to `odb_source`.
- Link to v3: https://lore.kernel.org/r/20250514-pks-object-store-wo-the-repository-v3-0-47df1d4ead22@pks.im
Changes in v5:
- Some polishing to fix leftover terminology from previous rounds.
- Link to v4: https://lore.kernel.org/r/20250602-pks-object-store-wo-the-repository-v4-0-e986804a7c62@pks.im
Thanks!
Patrick
---
Patrick Steinhardt (17):
object-store: rename `raw_object_store` to `object_database`
object-store: rename `object_directory` to `odb_source`
object-store: rename files to "odb.{c,h}"
odb: introduce parent pointers
odb: get rid of `the_repository` in `find_odb()`
odb: get rid of `the_repository` in `assert_oid_type()`
odb: get rid of `the_repository` in `odb_mkstemp()`
odb: get rid of `the_repository` when handling alternates
odb: get rid of `the_repository` in `for_each()` functions
odb: get rid of `the_repository` when handling the primary source
odb: get rid of `the_repository` when handling submodule sources
odb: trivial refactorings to get rid of `the_repository`
odb: rename `oid_object_info()`
odb: rename `repo_read_object_file()`
odb: rename `has_object()`
odb: rename `pretend_object_file()`
odb: rename `read_object_with_reference()`
Documentation/user-manual.adoc | 4 +-
Makefile | 2 +-
apply.c | 14 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 6 +-
attr.c | 4 +-
bisect.c | 8 +-
blame.c | 22 +-
builtin/backfill.c | 6 +-
builtin/blame.c | 6 +-
builtin/cat-file.c | 62 ++---
builtin/checkout.c | 2 +-
builtin/clone.c | 14 +-
builtin/commit-graph.c | 20 +-
builtin/commit-tree.c | 4 +-
builtin/count-objects.c | 6 +-
builtin/describe.c | 5 +-
builtin/difftool.c | 4 +-
builtin/fast-export.c | 10 +-
builtin/fast-import.c | 49 ++--
builtin/fetch.c | 21 +-
builtin/fsck.c | 31 ++-
builtin/gc.c | 16 +-
builtin/grep.c | 26 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 29 +-
builtin/log.c | 4 +-
builtin/ls-files.c | 4 +-
builtin/ls-tree.c | 6 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 14 +-
builtin/mktag.c | 6 +-
builtin/mktree.c | 10 +-
builtin/multi-pack-index.c | 6 +-
builtin/notes.c | 8 +-
builtin/pack-objects.c | 70 ++---
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 6 +-
builtin/receive-pack.c | 9 +-
builtin/remote.c | 6 +-
builtin/repack.c | 7 +-
builtin/replace.c | 12 +-
builtin/rev-list.c | 8 +-
builtin/show-ref.c | 6 +-
builtin/submodule--helper.c | 11 +-
builtin/tag.c | 10 +-
builtin/unpack-file.c | 4 +-
builtin/unpack-objects.c | 12 +-
bulk-checkin.c | 6 +-
bundle-uri.c | 5 +-
bundle.c | 6 +-
cache-tree.c | 17 +-
combine-diff.c | 4 +-
commit-graph.c | 106 +++----
commit-graph.h | 20 +-
commit.c | 15 +-
config.c | 4 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 12 +-
diff.c | 20 +-
dir.c | 2 +-
entry.c | 6 +-
fetch-pack.c | 17 +-
fmt-merge-msg.c | 6 +-
fsck.c | 4 +-
grep.c | 6 +-
http-backend.c | 2 +-
http-push.c | 20 +-
http-walker.c | 12 +-
http.c | 6 +-
list-objects-filter.c | 4 +-
list-objects.c | 6 +-
log-tree.c | 2 +-
loose.c | 46 ++--
mailmap.c | 4 +-
match-trees.c | 6 +-
merge-blobs.c | 10 +-
merge-ort.c | 8 +-
meson.build | 2 +-
midx-write.c | 2 +-
midx.c | 6 +-
notes-cache.c | 4 +-
notes-merge.c | 4 +-
notes.c | 19 +-
object-file.c | 94 +++----
object-file.h | 12 +-
object-name.c | 24 +-
object-store.h | 338 -----------------------
object.c | 8 +-
object-store.c => odb.c | 413 +++++++++++++++-------------
odb.h | 473 ++++++++++++++++++++++++++++++++
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 9 +-
pack-bitmap.c | 10 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
pack-write.c | 10 +-
packfile.c | 29 +-
packfile.h | 8 +-
path.c | 4 +-
promisor-remote.c | 6 +-
protocol-caps.c | 4 +-
reachable.c | 2 +-
read-cache.c | 14 +-
ref-filter.c | 6 +-
reflog.c | 8 +-
refs.c | 7 +-
remote.c | 9 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 21 +-
repository.h | 4 +-
rerere.c | 7 +-
revision.c | 5 +-
send-pack.c | 4 +-
sequencer.c | 7 +-
server-info.c | 2 +-
shallow.c | 14 +-
streaming.c | 10 +-
submodule-config.c | 9 +-
submodule.c | 32 +--
submodule.h | 9 -
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 4 +-
t/helper/test-read-graph.c | 8 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 4 +-
tag.c | 10 +-
tmp-objdir.c | 30 +-
tree-walk.c | 18 +-
tree.c | 6 +-
unpack-trees.c | 2 +-
upload-pack.c | 4 +-
walker.c | 6 +-
xdiff-interface.c | 4 +-
140 files changed, 1453 insertions(+), 1298 deletions(-)
Range-diff versus v4:
1: cb0cee8ca28 = 1: 50bcf60f256 object-store: rename `raw_object_store` to `object_database`
2: 1886e2d9657 ! 2: 5223817ea6e object-store: rename `object_directory` to `odb_source`
@@ object-store.h: struct cached_object_entry;
/*
* The object database encapsulates access to objects in a repository. It
- * manages one or more backends that store the actual objects which are
-+ * manages one or more alternates that store the actual objects which are
++ * manages one or more sources that store the actual objects which are
* configured via alternates.
*/
struct object_database {
3: 9f879846830 = 3: b6aefd95bda object-store: rename files to "odb.{c,h}"
4: 13535610312 = 4: 4b67ce83a83 odb: introduce parent pointers
5: c8eb92c2112 = 5: 6fe26d9012a odb: get rid of `the_repository` in `find_odb()`
6: a9b75d55df3 = 6: 23b332596e4 odb: get rid of `the_repository` in `assert_oid_type()`
7: 890cabc3c06 = 7: 95b022aef55 odb: get rid of `the_repository` in `odb_mkstemp()`
8: e38e8e2988f = 8: 45f89d7a5b2 odb: get rid of `the_repository` when handling alternates
9: bc140fac83f = 9: 671e1d461db odb: get rid of `the_repository` in `for_each()` functions
10: 94679138925 ! 10: fa2291c77a3 odb: get rid of `the_repository` when handling the primary source
@@ odb.h: void odb_clear(struct object_database *o);
+ const char *dir, int will_destroy);
+
+/*
-+ * Restore a previous backend replaced by `odb_set_temporary_primary_source()`.
++ * Restore the primary source that was previously replaced by
++ * `odb_set_temporary_primary_source()`.
+ */
+void odb_restore_primary_source(struct object_database *odb,
+ struct odb_source *restore_source,
11: 5bb13b32bb0 ! 11: 282b628fd7c odb: get rid of `the_repository` when handling submodule sources
@@ odb.c: void disable_obj_read_lock(void)
int fetch_if_missing = 1;
-+static int register_all_submodule_alternates(struct object_database *odb)
++static int register_all_submodule_sources(struct object_database *odb)
+{
+ int ret = odb->submodule_source_paths.nr;
+
@@ odb.c: void disable_obj_read_lock(void)
+ if (ret) {
+ string_list_clear(&odb->submodule_source_paths, 0);
+ trace2_data_intmax("submodule", odb->repo,
-+ "register_all_submodule_alternates/registered", ret);
++ "register_all_submodule_sources/registered", ret);
+ if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
-+ BUG("register_all_submodule_alternates() called");
++ BUG("register_all_submodule_sources() called");
+ }
+ return ret;
+}
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
*/
- if (r == the_repository &&
- register_all_submodule_odb_as_alternates())
-+ if (register_all_submodule_alternates(r->objects))
++ if (register_all_submodule_sources(r->objects))
/* We added some alternates; retry */
continue;
12: 1cb9d97c582 = 12: 9e7172fdb7f odb: trivial refactorings to get rid of `the_repository`
13: 453435c4000 ! 13: 932bf88ac7a odb: rename `oid_object_info()`
@@ object.c: struct object *parse_object_with_flags(struct repository *r,
## odb.c ##
-@@ odb.c: static int register_all_submodule_alternates(struct object_database *odb)
+@@ odb.c: static int register_all_submodule_sources(struct object_database *odb)
return ret;
}
@@ odb.c: static int do_oid_object_info_extended(struct repository *r,
* `odb_add_submodule_source_by_path()` on that submodule's
* ODB). If any such ODBs exist, register them and try again.
*/
-- if (register_all_submodule_alternates(r->objects))
-+ if (register_all_submodule_alternates(odb))
+- if (register_all_submodule_sources(r->objects))
++ if (register_all_submodule_sources(odb))
/* We added some alternates; retry */
continue;
14: 238207c6646 = 14: 345ee62c5f9 odb: rename `repo_read_object_file()`
15: 949dffee2b8 = 15: 6108150e126 odb: rename `has_object()`
16: aff9d3ae2fa = 16: c7a5955f376 odb: rename `pretend_object_file()`
17: 6dd67f110fd = 17: 033e5e2173e odb: rename `read_object_with_reference()`
---
base-commit: 7014b55638da979331baf8dc31c4e1d697cf2d67
change-id: 20250505-pks-object-store-wo-the-repository-9c6cbdf8d4b1
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v5 01/17] object-store: rename `raw_object_store` to `object_database`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
@ 2025-06-05 6:46 ` Patrick Steinhardt
2025-06-05 6:46 ` [PATCH v5 02/17] object-store: rename `object_directory` to `odb_source` Patrick Steinhardt
` (15 subsequent siblings)
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:46 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The `raw_object_store` structure is the central entry point for reading
and writing objects in a repository. The main purpose of this structure
is to manage object directories and provide an interface to access and
write objects in those object directories.
Right now, many of the functions associated with the raw object store
implicitly rely on `the_repository` to get access to its `objects`
pointer, which is the `raw_object_store`. As we want to generally get
rid of using `the_repository` across our codebase we will have to
convert this implicit dependency on this global variable into an
explicit parameter.
This conversion can be done by simply passing in an explicit pointer to
a repository and then using its `->objects` pointer. But there is a
second effort underway, which is to make the object subsystem more
selfcontained so that we can eventually have pluggable object backends.
As such, passing in a repository wouldn't make a ton of sense, and the
goal is to convert the object store interfaces such that we always pass
in a reference to the `raw_object_store` instead.
This will expose the `raw_object_store` type to a lot more callers
though, which surfaces that this type is named somewhat awkwardly. The
"raw_" prefix makes readers wonder whether there is a non-raw variant of
the object store, but there isn't. Furthermore, we nowadays want to name
functions in a way that they can be clearly attributed to a specific
subsystem, but calling them e.g. `raw_object_store_has_object()` is just
too unwieldy, even when dropping the "raw_" prefix.
Instead, rename the structure to `object_database`. This term is already
used a lot throughout our codebase, and it cannot easily be mistaken for
"object directories", either. Furthermore, its acronym ODB is already
well-known and works well as part of a function's name, like for example
`odb_has_object()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
commit-graph.c | 2 +-
commit-graph.h | 4 ++--
object-store.c | 12 ++++++------
object-store.h | 11 ++++++++---
packfile.c | 2 +-
packfile.h | 4 ++--
repository.c | 4 ++--
repository.h | 4 ++--
8 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index ad3943b6906..905fcbdf0e8 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -829,7 +829,7 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
return NULL;
}
-void close_commit_graph(struct raw_object_store *o)
+void close_commit_graph(struct object_database *o)
{
if (!o->commit_graph)
return;
diff --git a/commit-graph.h b/commit-graph.h
index 13f662827d4..20d38c100ce 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -26,7 +26,7 @@ void git_test_write_commit_graph_or_die(void);
struct commit;
struct bloom_filter_settings;
struct repository;
-struct raw_object_store;
+struct object_database;
struct string_list;
char *get_commit_graph_filename(struct object_directory *odb);
@@ -186,7 +186,7 @@ int write_commit_graph(struct object_directory *odb,
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
-void close_commit_graph(struct raw_object_store *);
+void close_commit_graph(struct object_database *);
void free_commit_graph(struct commit_graph *);
/*
diff --git a/object-store.c b/object-store.c
index 58cde0313a5..f4e8f99d90f 100644
--- a/object-store.c
+++ b/object-store.c
@@ -44,7 +44,7 @@ struct cached_object_entry {
} value;
};
-static const struct cached_object *find_cached_object(struct raw_object_store *object_store,
+static const struct cached_object *find_cached_object(struct object_database *object_store,
const struct object_id *oid)
{
static const struct cached_object empty_tree = {
@@ -86,7 +86,7 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
/*
* Return non-zero iff the path is usable as an alternate object database.
*/
-static int alt_odb_usable(struct raw_object_store *o,
+static int alt_odb_usable(struct object_database *o,
struct strbuf *path,
const char *normalized_objdir, khiter_t *pos)
{
@@ -950,9 +950,9 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct raw_object_store *raw_object_store_new(void)
+struct object_database *odb_new(void)
{
- struct raw_object_store *o = xmalloc(sizeof(*o));
+ struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
INIT_LIST_HEAD(&o->packed_git_mru);
@@ -961,7 +961,7 @@ struct raw_object_store *raw_object_store_new(void)
return o;
}
-static void free_object_directories(struct raw_object_store *o)
+static void free_object_directories(struct object_database *o)
{
while (o->odb) {
struct object_directory *next;
@@ -974,7 +974,7 @@ static void free_object_directories(struct raw_object_store *o)
o->odb_by_path = NULL;
}
-void raw_object_store_clear(struct raw_object_store *o)
+void odb_clear(struct object_database *o)
{
FREE_AND_NULL(o->alternate_db);
diff --git a/object-store.h b/object-store.h
index c5890085352..a3be27d1171 100644
--- a/object-store.h
+++ b/object-store.h
@@ -87,7 +87,12 @@ struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
-struct raw_object_store {
+/*
+ * The object database encapsulates access to objects in a repository. It
+ * manages one or more backends that store the actual objects which are
+ * configured via alternates.
+ */
+struct object_database {
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -169,8 +174,8 @@ struct raw_object_store {
unsigned packed_git_initialized : 1;
};
-struct raw_object_store *raw_object_store_new(void);
-void raw_object_store_clear(struct raw_object_store *o);
+struct object_database *odb_new(void);
+void odb_clear(struct object_database *o);
/*
* Create a temporary file rooted in the object database directory, or
diff --git a/packfile.c b/packfile.c
index 70c7208f027..c735b4d0135 100644
--- a/packfile.c
+++ b/packfile.c
@@ -359,7 +359,7 @@ void close_pack(struct packed_git *p)
oidset_clear(&p->bad_objects);
}
-void close_object_store(struct raw_object_store *o)
+void close_object_store(struct object_database *o)
{
struct packed_git *p;
diff --git a/packfile.h b/packfile.h
index 3a3c77cf05a..826eb7f475f 100644
--- a/packfile.h
+++ b/packfile.h
@@ -183,12 +183,12 @@ int close_pack_fd(struct packed_git *p);
uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
-struct raw_object_store;
+struct object_database;
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
void close_pack_windows(struct packed_git *);
void close_pack(struct packed_git *);
-void close_object_store(struct raw_object_store *o);
+void close_object_store(struct object_database *o);
void unuse_pack(struct pack_window **);
void clear_delta_base_cache(void);
struct packed_git *add_packed_git(struct repository *r, const char *path,
diff --git a/repository.c b/repository.c
index 9b3d6665fc6..07757e6e0c9 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = raw_object_store_new();
+ repo->objects = odb_new();
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -374,7 +374,7 @@ void repo_clear(struct repository *repo)
FREE_AND_NULL(repo->worktree);
FREE_AND_NULL(repo->submodule_prefix);
- raw_object_store_clear(repo->objects);
+ odb_clear(repo->objects);
FREE_AND_NULL(repo->objects);
parsed_object_pool_clear(repo->parsed_objects);
diff --git a/repository.h b/repository.h
index c4c92b2ab9c..3a5ef9c781e 100644
--- a/repository.h
+++ b/repository.h
@@ -9,7 +9,7 @@ struct git_hash_algo;
struct index_state;
struct lock_file;
struct pathspec;
-struct raw_object_store;
+struct object_database;
struct submodule_cache;
struct promisor_remote_config;
struct remote_state;
@@ -47,7 +47,7 @@ struct repository {
/*
* Holds any information related to accessing the raw object content.
*/
- struct raw_object_store *objects;
+ struct object_database *objects;
/*
* All objects in this repository that have been parsed. This structure
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 02/17] object-store: rename `object_directory` to `odb_source`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
2025-06-05 6:46 ` [PATCH v5 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
@ 2025-06-05 6:46 ` Patrick Steinhardt
2025-06-30 2:02 ` Justin Tobler
2025-06-05 6:46 ` [PATCH v5 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
` (14 subsequent siblings)
16 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:46 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The `object_directory` structure is used as an access point for a single
object directory like ".git/objects". While the structure isn't yet
fully self-contained, the intent is for it to eventually contain all
information required to access objects in one specific location.
While the name "object directory" is a good fit for now, this will
change over time as we continue with the agenda to make pluggable object
databases a thing. Eventually, objects may not be accessed via any kind
of directory at all anymore, but they could instead be backed by any
kind of durable storage mechanism. While it seems quite far-fetched for
now, it is thinkable that eventually this might even be some form of a
database, for example.
As such, the current name of this structure will become worse over time
as we evolve into the direction of pluggable ODBs. Immediate next steps
will start to carve out proper self-contained object directories, which
requires us to pass in these object directories as parameters. Based on
our modern naming schema this means that those functions should then be
named after their subsystem, which means that we would start to bake the
current name into the codebase more and more.
Let's preempt this by renaming the structure. There have been a couple
alternatives that were discussed:
- `odb_backend` was discarded because it led to the association that
one object database has a single backend, but the model is that one
alternate has one backend. Furthermore, "backend" is more about the
actual backing implementation and less about the high-level concept.
- `odb_alternate` was discarded because it is a bit of a stretch to
also call the main object directory an "alternate".
Instead, pick `odb_source` as the new name. It makes it sufficiently
clear that there can be multiple sources and does not cause confusion
when mixed with the already-existing "alternate" terminology.
In the future, this change allows us to easily introduce for example a
`odb_files_source` and other format-specific implementations.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 18 +++----
builtin/count-objects.c | 4 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 14 ++---
builtin/gc.c | 14 ++---
builtin/grep.c | 2 +-
builtin/multi-pack-index.c | 4 +-
builtin/submodule--helper.c | 6 +--
bundle.c | 2 +-
commit-graph.c | 94 +++++++++++++++++-----------------
commit-graph.h | 14 ++---
diagnose.c | 8 +--
http-walker.c | 2 +-
http.c | 4 +-
loose.c | 42 +++++++--------
midx.c | 6 +--
object-file.c | 80 ++++++++++++++---------------
object-file.h | 8 +--
object-name.c | 6 +--
object-store.c | 122 ++++++++++++++++++++++----------------------
object-store.h | 38 +++++++++-----
packfile.c | 16 +++---
path.c | 2 +-
refs.c | 2 +-
repository.c | 14 ++---
submodule-config.c | 2 +-
t/helper/test-read-graph.c | 6 +--
tmp-objdir.c | 24 ++++-----
28 files changed, 284 insertions(+), 272 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index a783a86e797..98a84315342 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb = NULL;
+ struct odb_source *source = NULL;
char *graph_name;
char *chain_name;
enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE;
@@ -101,9 +101,9 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- odb = find_odb(the_repository, opts.obj_dir);
- graph_name = get_commit_graph_filename(odb);
- chain_name = get_commit_graph_chain_filename(odb);
+ source = find_odb(the_repository, opts.obj_dir);
+ graph_name = get_commit_graph_filename(source);
+ chain_name = get_commit_graph_chain_filename(source);
if (open_commit_graph(graph_name, &fd, &st))
opened = OPENED_GRAPH;
else if (errno != ENOENT)
@@ -120,7 +120,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opened == OPENED_NONE)
return 0;
else if (opened == OPENED_GRAPH)
- graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb);
+ graph = load_commit_graph_one_fd_st(the_repository, fd, &st, source);
else
graph = load_commit_graph_chain_fd_st(the_repository, fd, &st,
&incomplete_chain);
@@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
struct string_list pack_indexes = STRING_LIST_INIT_DUP;
struct strbuf buf = STRBUF_INIT;
struct oidset commits = OIDSET_INIT;
- struct object_directory *odb = NULL;
+ struct odb_source *source = NULL;
int result = 0;
enum commit_graph_write_flags flags = 0;
struct progress *progress = NULL;
@@ -289,10 +289,10 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- odb = find_odb(the_repository, opts.obj_dir);
+ source = find_odb(the_repository, opts.obj_dir);
if (opts.reachable) {
- if (write_commit_graph_reachable(odb, flags, &write_opts))
+ if (write_commit_graph_reachable(source, flags, &write_opts))
result = 1;
goto cleanup;
}
@@ -318,7 +318,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
stop_progress(&progress);
}
- if (write_commit_graph(odb,
+ if (write_commit_graph(source,
opts.stdin_packs ? &pack_indexes : NULL,
opts.stdin_commits ? &commits : NULL,
flags,
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index a88c0c9c09a..58e0af433d1 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -80,10 +80,10 @@ static int count_cruft(const char *basename UNUSED, const char *path,
return 0;
}
-static int print_alternate(struct object_directory *odb, void *data UNUSED)
+static int print_alternate(struct odb_source *alternate, void *data UNUSED)
{
printf("alternate: ");
- quote_c_style(odb->path, NULL, stdout, 0);
+ quote_c_style(alternate->path, NULL, stdout, 0);
putchar('\n');
return 0;
}
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 40a0e8d2443..a890e2864d1 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2653,7 +2653,7 @@ int cmd_fetch(int argc,
commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
trace2_region_enter("fetch", "write-commit-graph", the_repository);
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->sources,
commit_graph_flags,
NULL);
trace2_region_leave("fetch", "write-commit-graph", the_repository);
diff --git a/builtin/fsck.c b/builtin/fsck.c
index e7d96a9c8ea..6e1474f63d5 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -956,7 +956,7 @@ int cmd_fsck(int argc,
struct repository *repo UNUSED)
{
int i;
- struct object_directory *odb;
+ struct odb_source *source;
/* fsck knows how to handle missing promisor objects */
fetch_if_missing = 0;
@@ -998,8 +998,8 @@ int cmd_fsck(int argc,
mark_packed_for_connectivity, NULL, 0);
} else {
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next)
- fsck_object_dir(odb->path);
+ for (source = the_repository->objects->sources; source; source = source->next)
+ fsck_object_dir(source->path);
if (check_full) {
struct packed_git *p;
@@ -1109,11 +1109,11 @@ int cmd_fsck(int argc,
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
strvec_pushl(&commit_graph_verify.args, "commit-graph",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", source->path, NULL);
if (show_progress)
strvec_push(&commit_graph_verify.args, "--progress");
else
@@ -1127,11 +1127,11 @@ int cmd_fsck(int argc,
struct child_process midx_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", source->path, NULL);
if (show_progress)
strvec_push(&midx_verify.args, "--progress");
else
diff --git a/builtin/gc.c b/builtin/gc.c
index e33ba946e43..50a09eb07e3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1018,7 +1018,7 @@ int cmd_gc(int argc,
}
if (the_repository->settings.gc_write_commit_graph == 1)
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->sources,
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
NULL);
@@ -1271,7 +1271,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
if (loose_object_auto_limit < 0)
return 1;
- return for_each_loose_file_in_objdir(the_repository->objects->odb->path,
+ return for_each_loose_file_in_objdir(the_repository->objects->sources->path,
loose_object_count,
NULL, NULL, &count);
}
@@ -1306,7 +1306,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
* Do not start pack-objects process
* if there are no loose objects.
*/
- if (!for_each_loose_file_in_objdir(r->objects->odb->path,
+ if (!for_each_loose_file_in_objdir(r->objects->sources->path,
bail_on_loose,
NULL, NULL, NULL))
return 0;
@@ -1318,7 +1318,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
strvec_push(&pack_proc.args, "--quiet");
else
strvec_push(&pack_proc.args, "--no-quiet");
- strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
+ strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->sources->path);
pack_proc.in = -1;
@@ -1346,7 +1346,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
else if (data.batch_size > 0)
data.batch_size--; /* Decrease for equality on limit. */
- for_each_loose_file_in_objdir(r->objects->odb->path,
+ for_each_loose_file_in_objdir(r->objects->sources->path,
write_loose_object_to_stdin,
NULL,
NULL,
@@ -1611,7 +1611,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
int result = 0;
struct lock_file lk;
struct repository *r = the_repository;
- char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path);
+ char *lock_path = xstrfmt("%s/maintenance", r->objects->sources->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
/*
@@ -3083,7 +3083,7 @@ static int update_background_schedule(const struct maintenance_start_opts *opts,
unsigned int i;
int result = 0;
struct lock_file lk;
- char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path);
+ char *lock_path = xstrfmt("%s/schedule", the_repository->objects->sources->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
if (errno == EEXIST)
diff --git a/builtin/grep.c b/builtin/grep.c
index 3ce574a605b..76b1938bba5 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,7 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->odb->path);
+ add_submodule_odb_by_path(subrepo->objects->sources->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 69a97507324..f55bf53da83 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -294,8 +294,8 @@ int cmd_multi_pack_index(int argc,
if (the_repository &&
the_repository->objects &&
- the_repository->objects->odb)
- opts.object_dir = xstrdup(the_repository->objects->odb->path);
+ the_repository->objects->sources)
+ opts.object_dir = xstrdup(the_repository->objects->sources->path);
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 53da2116ddf..758bc6d0f24 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1582,7 +1582,7 @@ static const char alternate_error_advice[] = N_(
);
static int add_possible_reference_from_superproject(
- struct object_directory *odb, void *sas_cb)
+ struct odb_source *alt_odb, void *sas_cb)
{
struct submodule_alternate_setup *sas = sas_cb;
size_t len;
@@ -1591,12 +1591,12 @@ static int add_possible_reference_from_superproject(
* If the alternate object store is another repository, try the
* standard layout with .git/(modules/<name>)+/objects
*/
- if (strip_suffix(odb->path, "/objects", &len)) {
+ if (strip_suffix(alt_odb->path, "/objects", &len)) {
struct repository alternate;
char *sm_alternate;
struct strbuf sb = STRBUF_INIT;
struct strbuf err = STRBUF_INIT;
- strbuf_add(&sb, odb->path, len);
+ strbuf_add(&sb, alt_odb->path, len);
if (repo_init(&alternate, sb.buf, NULL) < 0)
die(_("could not get a repository handle for gitdir '%s'"),
diff --git a/bundle.c b/bundle.c
index b0a3fee2efa..2ce7525f90d 100644
--- a/bundle.c
+++ b/bundle.c
@@ -233,7 +233,7 @@ int verify_bundle(struct repository *r,
.quiet = 1,
};
- if (!r || !r->objects || !r->objects->odb)
+ if (!r || !r->objects || !r->objects->sources)
return error(_("need a repository to verify a bundle"));
for (i = 0; i < p->nr; i++) {
diff --git a/commit-graph.c b/commit-graph.c
index 905fcbdf0e8..12d32cdad1d 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -37,7 +37,7 @@ void git_test_write_commit_graph_or_die(void)
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- if (write_commit_graph_reachable(the_repository->objects->odb,
+ if (write_commit_graph_reachable(the_repository->objects->sources,
flags, NULL))
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
}
@@ -191,21 +191,21 @@ static int commit_gen_cmp(const void *va, const void *vb)
return 0;
}
-char *get_commit_graph_filename(struct object_directory *obj_dir)
+char *get_commit_graph_filename(struct odb_source *source)
{
- return xstrfmt("%s/info/commit-graph", obj_dir->path);
+ return xstrfmt("%s/info/commit-graph", source->path);
}
-static char *get_split_graph_filename(struct object_directory *odb,
+static char *get_split_graph_filename(struct odb_source *source,
const char *oid_hex)
{
- return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb->path,
+ return xstrfmt("%s/info/commit-graphs/graph-%s.graph", source->path,
oid_hex);
}
-char *get_commit_graph_chain_filename(struct object_directory *odb)
+char *get_commit_graph_chain_filename(struct odb_source *source)
{
- return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
+ return xstrfmt("%s/info/commit-graphs/commit-graph-chain", source->path);
}
static struct commit_graph *alloc_commit_graph(void)
@@ -250,7 +250,7 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb)
+ struct odb_source *source)
{
void *graph_map;
size_t graph_size;
@@ -269,7 +269,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
ret = parse_commit_graph(&r->settings, graph_map, graph_size);
if (ret)
- ret->odb = odb;
+ ret->odb_source = source;
else
munmap(graph_map, graph_size);
@@ -487,7 +487,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
static struct commit_graph *load_commit_graph_one(struct repository *r,
const char *graph_file,
- struct object_directory *odb)
+ struct odb_source *source)
{
struct stat st;
@@ -498,7 +498,7 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
if (!open_ok)
return NULL;
- g = load_commit_graph_one_fd_st(r, fd, &st, odb);
+ g = load_commit_graph_one_fd_st(r, fd, &st, source);
if (g)
g->filename = xstrdup(graph_file);
@@ -507,10 +507,10 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
}
static struct commit_graph *load_commit_graph_v1(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- char *graph_name = get_commit_graph_filename(odb);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ char *graph_name = get_commit_graph_filename(source);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
free(graph_name);
return g;
@@ -652,7 +652,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
prepare_alt_odb(r);
for (i = 0; i < count; i++) {
- struct object_directory *odb;
+ struct odb_source *source;
if (strbuf_getline_lf(&line, fp) == EOF)
break;
@@ -665,9 +665,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
valid = 0;
- for (odb = r->objects->odb; odb; odb = odb->next) {
- char *graph_name = get_split_graph_filename(odb, line.buf);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ for (source = r->objects->sources; source; source = source->next) {
+ char *graph_name = get_split_graph_filename(source, line.buf);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
free(graph_name);
@@ -701,9 +701,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
static struct commit_graph *load_commit_graph_chain(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- char *chain_file = get_commit_graph_chain_filename(odb);
+ char *chain_file = get_commit_graph_chain_filename(source);
struct stat st;
int fd;
struct commit_graph *g = NULL;
@@ -719,24 +719,24 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
}
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- struct commit_graph *g = load_commit_graph_v1(r, odb);
+ struct commit_graph *g = load_commit_graph_v1(r, source);
if (!g)
- g = load_commit_graph_chain(r, odb);
+ g = load_commit_graph_chain(r, source);
return g;
}
static void prepare_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
if (r->objects->commit_graph)
return;
- r->objects->commit_graph = read_commit_graph_one(r, odb);
+ r->objects->commit_graph = read_commit_graph_one(r, source);
}
/*
@@ -747,7 +747,7 @@ static void prepare_commit_graph_one(struct repository *r,
*/
static int prepare_commit_graph(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_source *source;
/*
* Early return if there is no git dir or if the commit graph is
@@ -779,10 +779,10 @@ static int prepare_commit_graph(struct repository *r)
return 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb;
- !r->objects->commit_graph && odb;
- odb = odb->next)
- prepare_commit_graph_one(r, odb);
+ for (source = r->objects->sources;
+ !r->objects->commit_graph && source;
+ source = source->next)
+ prepare_commit_graph_one(r, source);
return !!r->objects->commit_graph;
}
@@ -1137,7 +1137,7 @@ struct packed_commit_list {
struct write_commit_graph_context {
struct repository *r;
- struct object_directory *odb;
+ struct odb_source *odb_source;
char *graph_name;
struct oid_array oids;
struct packed_commit_list commits;
@@ -1870,7 +1870,7 @@ static int add_ref_to_set(const char *refname UNUSED,
return 0;
}
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_source *source,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts)
{
@@ -1890,7 +1890,7 @@ int write_commit_graph_reachable(struct object_directory *odb,
stop_progress(&data.progress);
- result = write_commit_graph(odb, NULL, &commits,
+ result = write_commit_graph(source, NULL, &commits,
flags, opts);
oidset_clear(&commits);
@@ -1906,7 +1906,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
int dirlen;
int ret = 0;
- strbuf_addf(&packname, "%s/pack/", ctx->odb->path);
+ strbuf_addf(&packname, "%s/pack/", ctx->odb_source->path);
dirlen = packname.len;
if (ctx->report_progress) {
strbuf_addf(&progress_title,
@@ -2060,10 +2060,10 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
strbuf_addf(&tmp_file,
"%s/info/commit-graphs/tmp_graph_XXXXXX",
- ctx->odb->path);
+ ctx->odb_source->path);
ctx->graph_name = strbuf_detach(&tmp_file, NULL);
} else {
- ctx->graph_name = get_commit_graph_filename(ctx->odb);
+ ctx->graph_name = get_commit_graph_filename(ctx->odb_source);
}
if (safe_create_leading_directories(the_repository, ctx->graph_name)) {
@@ -2073,7 +2073,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
if (ctx->split) {
- char *lock_name = get_commit_graph_chain_filename(ctx->odb);
+ char *lock_name = get_commit_graph_chain_filename(ctx->odb_source);
hold_lock_file_for_update_mode(&lk, lock_name,
LOCK_DIE_ON_ERROR, 0444);
@@ -2161,7 +2161,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
char *new_base_hash = xstrdup(oid_to_hex(&ctx->new_base_graph->oid));
- char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb, new_base_hash);
+ char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb_source, new_base_hash);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 2]);
@@ -2201,14 +2201,14 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
}
} else {
- char *graph_name = get_commit_graph_filename(ctx->odb);
+ char *graph_name = get_commit_graph_filename(ctx->odb_source);
unlink(graph_name);
free(graph_name);
}
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(hash_to_hex(file_hash));
- final_graph_name = get_split_graph_filename(ctx->odb,
+ final_graph_name = get_split_graph_filename(ctx->odb_source,
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1] = final_graph_name;
@@ -2259,7 +2259,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
flags != COMMIT_GRAPH_SPLIT_REPLACE) {
while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
(max_commits && num_commits > max_commits))) {
- if (g->odb != ctx->odb)
+ if (g->odb_source != ctx->odb_source)
break;
if (unsigned_add_overflows(num_commits, g->num_commits))
@@ -2281,10 +2281,10 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
"should be 1 with --split=replace");
if (ctx->num_commit_graphs_after == 2) {
- char *old_graph_name = get_commit_graph_filename(g->odb);
+ char *old_graph_name = get_commit_graph_filename(g->odb_source);
if (!strcmp(g->filename, old_graph_name) &&
- g->odb != ctx->odb) {
+ g->odb_source != ctx->odb_source) {
ctx->num_commit_graphs_after = 1;
ctx->new_base_graph = NULL;
}
@@ -2456,13 +2456,13 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
if (ctx->opts && ctx->opts->expire_time)
expire_time = ctx->opts->expire_time;
if (!ctx->split) {
- char *chain_file_name = get_commit_graph_chain_filename(ctx->odb);
+ char *chain_file_name = get_commit_graph_chain_filename(ctx->odb_source);
unlink(chain_file_name);
free(chain_file_name);
ctx->num_commit_graphs_after = 0;
}
- strbuf_addstr(&path, ctx->odb->path);
+ strbuf_addstr(&path, ctx->odb_source->path);
strbuf_addstr(&path, "/info/commit-graphs");
dir = opendir(path.buf);
@@ -2504,7 +2504,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
strbuf_release(&path);
}
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_source *source,
const struct string_list *const pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
@@ -2513,7 +2513,7 @@ int write_commit_graph(struct object_directory *odb,
struct repository *r = the_repository;
struct write_commit_graph_context ctx = {
.r = r,
- .odb = odb,
+ .odb_source = source,
.append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0,
.report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0,
.split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0,
diff --git a/commit-graph.h b/commit-graph.h
index 20d38c100ce..0e661db1b54 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -29,8 +29,8 @@ struct repository;
struct object_database;
struct string_list;
-char *get_commit_graph_filename(struct object_directory *odb);
-char *get_commit_graph_chain_filename(struct object_directory *odb);
+char *get_commit_graph_filename(struct odb_source *source);
+char *get_commit_graph_chain_filename(struct odb_source *source);
int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st);
@@ -89,7 +89,7 @@ struct commit_graph {
uint32_t num_commits;
struct object_id oid;
char *filename;
- struct object_directory *odb;
+ struct odb_source *odb_source;
uint32_t num_commits_in_base;
unsigned int read_generation_data;
@@ -115,12 +115,12 @@ struct commit_graph {
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb);
+ struct odb_source *source);
struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
int fd, struct stat *st,
int *incomplete_chain);
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb);
+ struct odb_source *source);
struct repo_settings;
@@ -173,10 +173,10 @@ struct commit_graph_opts {
* is not compatible with the commit-graph feature, then the
* methods will return 0 without writing a commit-graph.
*/
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_source *source,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts);
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_source *source,
const struct string_list *pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
diff --git a/diagnose.c b/diagnose.c
index b1be74be983..d08d5643aac 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -59,13 +59,13 @@ static void dir_file_stats_objects(const char *full_path,
(uintmax_t)st.st_size);
}
-static int dir_file_stats(struct object_directory *object_dir, void *data)
+static int dir_file_stats(struct odb_source *source, void *data)
{
struct strbuf *buf = data;
- strbuf_addf(buf, "Contents of %s:\n", object_dir->path);
+ strbuf_addf(buf, "Contents of %s:\n", source->path);
- for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects,
+ for_each_file_in_pack_dir(source->path, dir_file_stats_objects,
data);
return 0;
@@ -228,7 +228,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(r->objects->odb, &buf);
+ dir_file_stats(r->objects->sources, &buf);
foreach_alt_odb(dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
diff --git a/http-walker.c b/http-walker.c
index 463f7b119ad..c374e6b2056 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
ret = error("File %s has bad hash", hex);
} else if (req->rename < 0) {
struct strbuf buf = STRBUF_INIT;
- odb_loose_path(the_repository->objects->odb, &buf, &req->oid);
+ odb_loose_path(the_repository->objects->sources, &buf, &req->oid);
ret = error("unable to write sha1 filename %s", buf.buf);
strbuf_release(&buf);
}
diff --git a/http.c b/http.c
index 3c029cf8947..5e15bbab3f1 100644
--- a/http.c
+++ b/http.c
@@ -2662,7 +2662,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
oidcpy(&freq->oid, oid);
freq->localfile = -1;
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2814,7 +2814,7 @@ int finish_http_object_request(struct http_object_request *freq)
unlink_or_warn(freq->tmpfile.buf);
return -1;
}
- odb_loose_path(the_repository->objects->odb, &filename, &freq->oid);
+ odb_loose_path(the_repository->objects->sources, &filename, &freq->oid);
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
strbuf_release(&filename);
diff --git a/loose.c b/loose.c
index bb602aaa366..fe65d5b9b0f 100644
--- a/loose.c
+++ b/loose.c
@@ -44,36 +44,36 @@ static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *key, const
return 1;
}
-static int insert_loose_map(struct object_directory *odb,
+static int insert_loose_map(struct odb_source *source,
const struct object_id *oid,
const struct object_id *compat_oid)
{
- struct loose_object_map *map = odb->loose_map;
+ struct loose_object_map *map = source->loose_map;
int inserted = 0;
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
if (inserted)
- oidtree_insert(odb->loose_objects_cache, compat_oid);
+ oidtree_insert(source->loose_objects_cache, compat_oid);
return inserted;
}
-static int load_one_loose_object_map(struct repository *repo, struct object_directory *dir)
+static int load_one_loose_object_map(struct repository *repo, struct odb_source *source)
{
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
FILE *fp;
- if (!dir->loose_map)
- loose_object_map_init(&dir->loose_map);
- if (!dir->loose_objects_cache) {
- ALLOC_ARRAY(dir->loose_objects_cache, 1);
- oidtree_init(dir->loose_objects_cache);
+ if (!source->loose_map)
+ loose_object_map_init(&source->loose_map);
+ if (!source->loose_objects_cache) {
+ ALLOC_ARRAY(source->loose_objects_cache, 1);
+ oidtree_init(source->loose_objects_cache);
}
- insert_loose_map(dir, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
- insert_loose_map(dir, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
- insert_loose_map(dir, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
+ insert_loose_map(source, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
+ insert_loose_map(source, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
+ insert_loose_map(source, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
repo_common_path_replace(repo, &path, "objects/loose-object-idx");
fp = fopen(path.buf, "rb");
@@ -93,7 +93,7 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
parse_oid_hex_algop(p, &compat_oid, &p, repo->compat_hash_algo) ||
p != buf.buf + buf.len)
goto err;
- insert_loose_map(dir, &oid, &compat_oid);
+ insert_loose_map(source, &oid, &compat_oid);
}
strbuf_release(&buf);
@@ -107,15 +107,15 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
int repo_read_loose_object_map(struct repository *repo)
{
- struct object_directory *dir;
+ struct odb_source *source;
if (!should_use_loose_object_map(repo))
return 0;
prepare_alt_odb(repo);
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- if (load_one_loose_object_map(repo, dir) < 0) {
+ for (source = repo->objects->sources; source; source = source->next) {
+ if (load_one_loose_object_map(repo, source) < 0) {
return -1;
}
}
@@ -124,7 +124,7 @@ int repo_read_loose_object_map(struct repository *repo)
int repo_write_loose_object_map(struct repository *repo)
{
- kh_oid_map_t *map = repo->objects->odb->loose_map->to_compat;
+ kh_oid_map_t *map = repo->objects->sources->loose_map->to_compat;
struct lock_file lock;
int fd;
khiter_t iter;
@@ -212,7 +212,7 @@ int repo_add_loose_object_map(struct repository *repo, const struct object_id *o
if (!should_use_loose_object_map(repo))
return 0;
- inserted = insert_loose_map(repo->objects->odb, oid, compat_oid);
+ inserted = insert_loose_map(repo->objects->sources, oid, compat_oid);
if (inserted)
return write_one_object(repo, oid, compat_oid);
return 0;
@@ -223,12 +223,12 @@ int repo_loose_object_map_oid(struct repository *repo,
const struct git_hash_algo *to,
struct object_id *dest)
{
- struct object_directory *dir;
+ struct odb_source *source;
kh_oid_map_t *map;
khiter_t pos;
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- struct loose_object_map *loose_map = dir->loose_map;
+ for (source = repo->objects->sources; source; source = source->next) {
+ struct loose_object_map *loose_map = source->loose_map;
if (!loose_map)
continue;
map = (to == repo->compat_hash_algo) ?
diff --git a/midx.c b/midx.c
index cd6e766ce2b..3c5bc821730 100644
--- a/midx.c
+++ b/midx.c
@@ -832,7 +832,7 @@ void clear_midx_file(struct repository *r)
{
struct strbuf midx = STRBUF_INIT;
- get_midx_filename(r->hash_algo, &midx, r->objects->odb->path);
+ get_midx_filename(r->hash_algo, &midx, r->objects->sources->path);
if (r->objects && r->objects->multi_pack_index) {
close_midx(r->objects->multi_pack_index);
@@ -842,8 +842,8 @@ void clear_midx_file(struct repository *r)
if (remove_path(midx.buf))
die(_("failed to clear multi-pack-index at %s"), midx.buf);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_BITMAP, NULL);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_REV, NULL);
+ clear_midx_files_ext(r->objects->sources->path, MIDX_EXT_BITMAP, NULL);
+ clear_midx_files_ext(r->objects->sources->path, MIDX_EXT_REV, NULL);
strbuf_release(&midx);
}
diff --git a/object-file.c b/object-file.c
index 1ac04c28916..6bad1d3dd1c 100644
--- a/object-file.c
+++ b/object-file.c
@@ -55,12 +55,12 @@ static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
}
}
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_source *source,
struct strbuf *buf,
const struct object_id *oid)
{
strbuf_reset(buf);
- strbuf_addstr(buf, odb->path);
+ strbuf_addstr(buf, source->path);
strbuf_addch(buf, '/');
fill_loose_path(buf, oid);
return buf->buf;
@@ -88,27 +88,27 @@ int check_and_freshen_file(const char *fn, int freshen)
return 1;
}
-static int check_and_freshen_odb(struct object_directory *odb,
+static int check_and_freshen_odb(struct odb_source *source,
const struct object_id *oid,
int freshen)
{
static struct strbuf path = STRBUF_INIT;
- odb_loose_path(odb, &path, oid);
+ odb_loose_path(source, &path, oid);
return check_and_freshen_file(path.buf, freshen);
}
static int check_and_freshen_local(const struct object_id *oid, int freshen)
{
- return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
+ return check_and_freshen_odb(the_repository->objects->sources, oid, freshen);
}
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
- if (check_and_freshen_odb(odb, oid, freshen))
+ for (source = the_repository->objects->sources->next; source; source = source->next) {
+ if (check_and_freshen_odb(source, oid, freshen))
return 1;
}
return 0;
@@ -202,12 +202,12 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct stat *st, const char **path)
{
- struct object_directory *odb;
+ struct odb_source *source;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (source = r->objects->sources; source; source = source->next) {
+ *path = odb_loose_path(source, &buf, oid);
if (!lstat(*path, st))
return 0;
}
@@ -223,13 +223,13 @@ static int open_loose_object(struct repository *r,
const struct object_id *oid, const char **path)
{
int fd;
- struct object_directory *odb;
+ struct odb_source *source;
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (source = r->objects->sources; source; source = source->next) {
+ *path = odb_loose_path(source, &buf, oid);
fd = git_open(*path);
if (fd >= 0)
return fd;
@@ -244,11 +244,11 @@ static int open_loose_object(struct repository *r,
static int quick_has_loose(struct repository *r,
const struct object_id *oid)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- if (oidtree_contains(odb_loose_cache(odb, oid), oid))
+ for (source = r->objects->sources; source; source = source->next) {
+ if (oidtree_contains(odb_loose_cache(source, oid), oid))
return 1;
}
return 0;
@@ -694,7 +694,7 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
/* Finalize a file on disk, and close it. */
static void close_loose_object(int fd, const char *filename)
{
- if (the_repository->objects->odb->will_destroy)
+ if (the_repository->objects->sources->will_destroy)
goto out;
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
@@ -876,7 +876,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
prepare_loose_object_bulk_checkin();
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
fd = start_loose_object_common(&tmp_file, filename.buf, flags,
&stream, compressed, sizeof(compressed),
@@ -1023,7 +1023,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
goto cleanup;
}
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
/* We finally know the object path, and create the missing dir. */
dirlen = directory_size(filename.buf);
@@ -1437,11 +1437,11 @@ int for_each_loose_file_in_objdir(const char *path,
int for_each_loose_object(each_loose_object_fn cb, void *data,
enum for_each_object_flags flags)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
- int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
+ for (source = the_repository->objects->sources; source; source = source->next) {
+ int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
NULL, data);
if (r)
return r;
@@ -1461,43 +1461,43 @@ static int append_loose_object(const struct object_id *oid,
return 0;
}
-struct oidtree *odb_loose_cache(struct object_directory *odb,
- const struct object_id *oid)
+struct oidtree *odb_loose_cache(struct odb_source *source,
+ const struct object_id *oid)
{
int subdir_nr = oid->hash[0];
struct strbuf buf = STRBUF_INIT;
- size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
+ size_t word_bits = bitsizeof(source->loose_objects_subdir_seen[0]);
size_t word_index = subdir_nr / word_bits;
size_t mask = (size_t)1u << (subdir_nr % word_bits);
uint32_t *bitmap;
if (subdir_nr < 0 ||
- subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
+ subdir_nr >= bitsizeof(source->loose_objects_subdir_seen))
BUG("subdir_nr out of range");
- bitmap = &odb->loose_objects_subdir_seen[word_index];
+ bitmap = &source->loose_objects_subdir_seen[word_index];
if (*bitmap & mask)
- return odb->loose_objects_cache;
- if (!odb->loose_objects_cache) {
- ALLOC_ARRAY(odb->loose_objects_cache, 1);
- oidtree_init(odb->loose_objects_cache);
+ return source->loose_objects_cache;
+ if (!source->loose_objects_cache) {
+ ALLOC_ARRAY(source->loose_objects_cache, 1);
+ oidtree_init(source->loose_objects_cache);
}
- strbuf_addstr(&buf, odb->path);
+ strbuf_addstr(&buf, source->path);
for_each_file_in_obj_subdir(subdir_nr, &buf,
append_loose_object,
NULL, NULL,
- odb->loose_objects_cache);
+ source->loose_objects_cache);
*bitmap |= mask;
strbuf_release(&buf);
- return odb->loose_objects_cache;
+ return source->loose_objects_cache;
}
-void odb_clear_loose_cache(struct object_directory *odb)
+void odb_clear_loose_cache(struct odb_source *source)
{
- oidtree_clear(odb->loose_objects_cache);
- FREE_AND_NULL(odb->loose_objects_cache);
- memset(&odb->loose_objects_subdir_seen, 0,
- sizeof(odb->loose_objects_subdir_seen));
+ oidtree_clear(source->loose_objects_cache);
+ FREE_AND_NULL(source->loose_objects_cache);
+ memset(&source->loose_objects_subdir_seen, 0,
+ sizeof(source->loose_objects_subdir_seen));
}
static int check_stream_oid(git_zstream *stream,
diff --git a/object-file.h b/object-file.h
index 6f411424523..9a18859b2e0 100644
--- a/object-file.h
+++ b/object-file.h
@@ -24,23 +24,23 @@ enum {
int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
-struct object_directory;
+struct odb_source;
/*
* Populate and return the loose object cache array corresponding to the
* given object ID.
*/
-struct oidtree *odb_loose_cache(struct object_directory *odb,
+struct oidtree *odb_loose_cache(struct odb_source *source,
const struct object_id *oid);
/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
+void odb_clear_loose_cache(struct odb_source *source);
/*
* Put in `buf` the name of the file in the local object database that
* would be used to store a loose object with the specified oid.
*/
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_source *source,
struct strbuf *buf,
const struct object_id *oid);
diff --git a/object-name.c b/object-name.c
index 9288b2dd245..544634d0f40 100644
--- a/object-name.c
+++ b/object-name.c
@@ -112,10 +112,10 @@ static enum cb_next match_prefix(const struct object_id *oid, void *arg)
static void find_short_object_filename(struct disambiguate_state *ds)
{
- struct object_directory *odb;
+ struct odb_source *source;
- for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next)
- oidtree_each(odb_loose_cache(odb, &ds->bin_pfx),
+ for (source = ds->repo->objects->sources; source && !ds->ambiguous; source = source->next)
+ oidtree_each(odb_loose_cache(source, &ds->bin_pfx),
&ds->bin_pfx, ds->len, match_prefix, ds);
}
diff --git a/object-store.c b/object-store.c
index f4e8f99d90f..5c04a1018f7 100644
--- a/object-store.c
+++ b/object-store.c
@@ -27,7 +27,7 @@
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
- struct object_directory *, 1, fspathhash, fspatheq)
+ struct odb_source *, 1, fspathhash, fspatheq)
/*
* This is meant to hold a *small* number of objects that you would
@@ -104,18 +104,18 @@ static int alt_odb_usable(struct object_database *o,
* Prevent the common mistake of listing the same
* thing twice, or object directory itself.
*/
- if (!o->odb_by_path) {
+ if (!o->source_by_path) {
khiter_t p;
- o->odb_by_path = kh_init_odb_path_map();
- assert(!o->odb->next);
- p = kh_put_odb_path_map(o->odb_by_path, o->odb->path, &r);
+ o->source_by_path = kh_init_odb_path_map();
+ assert(!o->sources->next);
+ p = kh_put_odb_path_map(o->source_by_path, o->sources->path, &r);
assert(r == 1); /* never used */
- kh_value(o->odb_by_path, p) = o->odb;
+ kh_value(o->source_by_path, p) = o->sources;
}
if (fspatheq(path->buf, normalized_objdir))
return 0;
- *pos = kh_put_odb_path_map(o->odb_by_path, path->buf, &r);
+ *pos = kh_put_odb_path_map(o->source_by_path, path->buf, &r);
/* r: 0 = exists, 1 = never used, 2 = deleted */
return r == 0 ? 0 : 1;
}
@@ -124,7 +124,7 @@ static int alt_odb_usable(struct object_database *o,
* Prepare alternate object database registry.
*
* The variable alt_odb_list points at the list of struct
- * object_directory. The elements on this list come from
+ * odb_source. The elements on this list come from
* non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
* environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
* whose contents is similar to that environment variable but can be
@@ -141,7 +141,7 @@ static void read_info_alternates(struct repository *r,
static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
const char *relative_base, int depth, const char *normalized_objdir)
{
- struct object_directory *ent;
+ struct odb_source *alternate;
struct strbuf pathbuf = STRBUF_INIT;
struct strbuf tmp = STRBUF_INIT;
khiter_t pos;
@@ -170,19 +170,19 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
goto error;
- CALLOC_ARRAY(ent, 1);
- /* pathbuf.buf is already in r->objects->odb_by_path */
- ent->path = strbuf_detach(&pathbuf, NULL);
+ CALLOC_ARRAY(alternate, 1);
+ /* pathbuf.buf is already in r->objects->source_by_path */
+ alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->odb_tail = ent;
- r->objects->odb_tail = &(ent->next);
- ent->next = NULL;
- assert(r->objects->odb_by_path);
- kh_value(r->objects->odb_by_path, pos) = ent;
+ *r->objects->sources_tail = alternate;
+ r->objects->sources_tail = &(alternate->next);
+ alternate->next = NULL;
+ assert(r->objects->source_by_path);
+ kh_value(r->objects->source_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, ent->path, depth + 1);
+ read_info_alternates(r, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -234,7 +234,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->odb->path, 1);
+ strbuf_realpath(&objdirbuf, r->objects->sources->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
@@ -321,9 +321,9 @@ void add_to_alternates_memory(const char *reference)
'\n', NULL, 0);
}
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
{
- struct object_directory *new_odb;
+ struct odb_source *source;
/*
* Make sure alternates are initialized, or else our entry may be
@@ -335,41 +335,41 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
- new_odb = xcalloc(1, sizeof(*new_odb));
- new_odb->path = xstrdup(dir);
+ source = xcalloc(1, sizeof(*source));
+ source->path = xstrdup(dir);
/*
* Disable ref updates while a temporary odb is active, since
* the objects in the database may roll back.
*/
- new_odb->disable_ref_updates = 1;
- new_odb->will_destroy = will_destroy;
- new_odb->next = the_repository->objects->odb;
- the_repository->objects->odb = new_odb;
- return new_odb->next;
+ source->disable_ref_updates = 1;
+ source->will_destroy = will_destroy;
+ source->next = the_repository->objects->sources;
+ the_repository->objects->sources = source;
+ return source->next;
}
-static void free_object_directory(struct object_directory *odb)
+static void free_object_directory(struct odb_source *source)
{
- free(odb->path);
- odb_clear_loose_cache(odb);
- loose_object_map_clear(&odb->loose_map);
- free(odb);
+ free(source->path);
+ odb_clear_loose_cache(source);
+ loose_object_map_clear(&source->loose_map);
+ free(source);
}
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
+void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
{
- struct object_directory *cur_odb = the_repository->objects->odb;
+ struct odb_source *cur_alt = the_repository->objects->sources;
- if (strcmp(old_path, cur_odb->path))
+ if (strcmp(old_path, cur_alt->path))
BUG("expected %s as primary object store; found %s",
- old_path, cur_odb->path);
+ old_path, cur_alt->path);
- if (cur_odb->next != restore_odb)
+ if (cur_alt->next != restore_alt)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->odb = restore_odb;
- free_object_directory(cur_odb);
+ the_repository->objects->sources = restore_alt;
+ free_object_directory(cur_alt);
}
/*
@@ -442,15 +442,15 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct object_directory *find_odb(struct repository *r, const char *obj_dir)
+struct odb_source *find_odb(struct repository *r, const char *obj_dir)
{
- struct object_directory *odb;
+ struct odb_source *source;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- strbuf_realpath(&odb_path_real, odb->path, 1);
+ for (source = r->objects->sources; source; source = source->next) {
+ strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
}
@@ -458,9 +458,9 @@ struct object_directory *find_odb(struct repository *r, const char *obj_dir)
free(obj_dir_real);
strbuf_release(&odb_path_real);
- if (!odb)
+ if (!source)
die(_("could not find object directory matching %s"), obj_dir);
- return odb;
+ return source;
}
static void fill_alternate_refs_command(struct child_process *cmd,
@@ -527,14 +527,14 @@ struct alternate_refs_data {
void *data;
};
-static int refs_from_alternate_cb(struct object_directory *e,
+static int refs_from_alternate_cb(struct odb_source *alternate,
void *data)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
struct alternate_refs_data *cb = data;
- if (!strbuf_realpath(&path, e->path, 0))
+ if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
if (!strbuf_strip_suffix(&path, "/objects"))
goto out;
@@ -563,12 +563,12 @@ void for_each_alternate_ref(alternate_ref_fn fn, void *data)
int foreach_alt_odb(alt_odb_fn fn, void *cb)
{
- struct object_directory *ent;
+ struct odb_source *alternate;
int r = 0;
prepare_alt_odb(the_repository);
- for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {
- r = fn(ent, cb);
+ for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
+ r = fn(alternate, cb);
if (r)
break;
}
@@ -582,14 +582,14 @@ void prepare_alt_odb(struct repository *r)
link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->odb->path, 0);
+ read_info_alternates(r, r->objects->sources->path, 0);
r->objects->loaded_alternates = 1;
}
int has_alt_odb(struct repository *r)
{
prepare_alt_odb(r);
- return !!r->objects->odb->next;
+ return !!r->objects->sources->next;
}
int obj_read_use_lock = 0;
@@ -963,15 +963,15 @@ struct object_database *odb_new(void)
static void free_object_directories(struct object_database *o)
{
- while (o->odb) {
- struct object_directory *next;
+ while (o->sources) {
+ struct odb_source *next;
- next = o->odb->next;
- free_object_directory(o->odb);
- o->odb = next;
+ next = o->sources->next;
+ free_object_directory(o->sources);
+ o->sources = next;
}
- kh_destroy_odb_path_map(o->odb_by_path);
- o->odb_by_path = NULL;
+ kh_destroy_odb_path_map(o->source_by_path);
+ o->source_by_path = NULL;
}
void odb_clear(struct object_database *o)
@@ -986,7 +986,7 @@ void odb_clear(struct object_database *o)
o->commit_graph_attempted = 0;
free_object_directories(o);
- o->odb_tail = NULL;
+ o->sources_tail = NULL;
o->loaded_alternates = 0;
for (size_t i = 0; i < o->cached_object_nr; i++)
diff --git a/object-store.h b/object-store.h
index a3be27d1171..d199d757d76 100644
--- a/object-store.h
+++ b/object-store.h
@@ -13,8 +13,20 @@ struct oidtree;
struct strbuf;
struct repository;
-struct object_directory {
- struct object_directory *next;
+/*
+ * The source is the part of the object database that stores the actual
+ * objects. It thus encapsulates the logic to read and write the specific
+ * on-disk format. An object database can have multiple sources:
+ *
+ * - The primary source, which is typically located in "$GIT_DIR/objects".
+ * This is where new objects are usually written to.
+ *
+ * - Alternate sources, which are configured via "objects/info/alternates" or
+ * via the GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable. These
+ * alternate sources are only used to read objects.
+ */
+struct odb_source {
+ struct odb_source *next;
/*
* Used to store the results of readdir(3) calls when we are OK
@@ -44,8 +56,8 @@ struct object_directory {
int will_destroy;
/*
- * Path to the alternative object store. If this is a relative path,
- * it is relative to the current working directory.
+ * Path to the source. If this is a relative path, it is relative to
+ * the current working directory.
*/
char *path;
};
@@ -53,8 +65,8 @@ struct object_directory {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
+struct odb_source *find_odb(struct repository *r, const char *obj_dir);
+typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
@@ -76,12 +88,12 @@ void add_to_alternates_memory(const char *dir);
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
*/
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy);
/*
* Restore a previous ODB replaced by set_temporary_main_odb.
*/
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+void restore_primary_odb(struct odb_source *restore_alternate, const char *old_path);
struct packed_git;
struct multi_pack_index;
@@ -89,7 +101,7 @@ struct cached_object_entry;
/*
* The object database encapsulates access to objects in a repository. It
- * manages one or more backends that store the actual objects which are
+ * manages one or more sources that store the actual objects which are
* configured via alternates.
*/
struct object_database {
@@ -98,16 +110,16 @@ struct object_database {
* cannot be NULL after initialization). Subsequent directories are
* alternates.
*/
- struct object_directory *odb;
- struct object_directory **odb_tail;
- struct kh_odb_path_map *odb_by_path;
+ struct odb_source *sources;
+ struct odb_source **sources_tail;
+ struct kh_odb_path_map *source_by_path;
int loaded_alternates;
/*
* 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.
+ * populate the "sources" list when prepare_alt_odb() is run.
*/
char *alternate_db;
diff --git a/packfile.c b/packfile.c
index c735b4d0135..60661ad0095 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1029,16 +1029,16 @@ static void prepare_packed_git_mru(struct repository *r)
static void prepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_source *source;
if (r->objects->packed_git_initialized)
return;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- int local = (odb == r->objects->odb);
- prepare_multi_pack_index_one(r, odb->path, local);
- prepare_packed_git_one(r, odb->path, local);
+ for (source = r->objects->sources; source; source = source->next) {
+ int local = (source == r->objects->sources);
+ prepare_multi_pack_index_one(r, source->path, local);
+ prepare_packed_git_one(r, source->path, local);
}
rearrange_packed_git(r);
@@ -1048,7 +1048,7 @@ static void prepare_packed_git(struct repository *r)
void reprepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_source *source;
obj_read_lock();
@@ -1061,8 +1061,8 @@ void reprepare_packed_git(struct repository *r)
r->objects->loaded_alternates = 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next)
- odb_clear_loose_cache(odb);
+ for (source = r->objects->sources; source; source = source->next)
+ odb_clear_loose_cache(source);
r->objects->approximate_object_count_valid = 0;
r->objects->packed_git_initialized = 0;
diff --git a/path.c b/path.c
index 3b598b2847f..c347829aa66 100644
--- a/path.c
+++ b/path.c
@@ -397,7 +397,7 @@ static void adjust_git_path(struct repository *repo,
strbuf_splice(buf, 0, buf->len,
repo->index_file, strlen(repo->index_file));
else if (dir_prefix(base, "objects"))
- replace_dir(buf, git_dir_len + 7, repo->objects->odb->path);
+ replace_dir(buf, git_dir_len + 7, repo->objects->sources->path);
else if (repo_settings_get_hooks_path(repo) && dir_prefix(base, "hooks"))
replace_dir(buf, git_dir_len + 5, repo_settings_get_hooks_path(repo));
else if (repo->different_commondir)
diff --git a/refs.c b/refs.c
index dce5c49ca2b..5f6a386cc93 100644
--- a/refs.c
+++ b/refs.c
@@ -2477,7 +2477,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
break;
}
- if (refs->repo->objects->odb->disable_ref_updates) {
+ if (refs->repo->objects->sources->disable_ref_updates) {
strbuf_addstr(err,
_("ref updates forbidden inside quarantine environment"));
return -1;
diff --git a/repository.c b/repository.c
index 07757e6e0c9..7528beccddf 100644
--- a/repository.c
+++ b/repository.c
@@ -107,9 +107,9 @@ const char *repo_get_common_dir(struct repository *repo)
const char *repo_get_object_directory(struct repository *repo)
{
- if (!repo->objects->odb)
+ if (!repo->objects->sources)
BUG("repository hasn't been set up");
- return repo->objects->odb->path;
+ return repo->objects->sources->path;
}
const char *repo_get_index_file(struct repository *repo)
@@ -165,14 +165,14 @@ void repo_set_gitdir(struct repository *repo,
repo_set_commondir(repo, o->commondir);
- if (!repo->objects->odb) {
- CALLOC_ARRAY(repo->objects->odb, 1);
- repo->objects->odb_tail = &repo->objects->odb->next;
+ if (!repo->objects->sources) {
+ CALLOC_ARRAY(repo->objects->sources, 1);
+ repo->objects->sources_tail = &repo->objects->sources->next;
}
- expand_base_dir(&repo->objects->odb->path, o->object_dir,
+ expand_base_dir(&repo->objects->sources->path, o->object_dir,
repo->commondir, "objects");
- repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
+ repo->objects->sources->disable_ref_updates = o->disable_ref_updates;
free(repo->objects->alternate_db);
repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
diff --git a/submodule-config.c b/submodule-config.c
index 8630e27947d..b30d9365fbd 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->odb->path);
+ add_submodule_odb_by_path(repo->objects->sources->path);
} else {
goto out;
}
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 8b413b644be..53b633e2ba6 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -73,15 +73,15 @@ static void dump_graph_bloom_filters(struct commit_graph *graph)
int cmd__read_graph(int argc, const char **argv)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb;
+ struct odb_source *source;
int ret = 0;
setup_git_directory();
- odb = the_repository->objects->odb;
+ source = the_repository->objects->sources;
prepare_repo_settings(the_repository);
- graph = read_commit_graph_one(the_repository, odb);
+ graph = read_commit_graph_one(the_repository, source);
if (!graph) {
ret = 1;
goto done;
diff --git a/tmp-objdir.c b/tmp-objdir.c
index c38fbeb5e8a..056484404be 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -17,7 +17,7 @@ struct tmp_objdir {
struct repository *repo;
struct strbuf path;
struct strvec env;
- struct object_directory *prev_odb;
+ struct odb_source *prev_source;
int will_destroy;
};
@@ -46,8 +46,8 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
if (t == the_tmp_objdir)
the_tmp_objdir = NULL;
- if (t->prev_odb)
- restore_primary_odb(t->prev_odb, t->path.buf);
+ if (t->prev_source)
+ restore_primary_odb(t->prev_source, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -276,11 +276,11 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (!t)
return 0;
- if (t->prev_odb) {
- if (t->repo->objects->odb->will_destroy)
+ if (t->prev_source) {
+ if (t->repo->objects->sources->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_odb, t->path.buf);
- t->prev_odb = NULL;
+ restore_primary_odb(t->prev_source, t->path.buf);
+ t->prev_source = NULL;
}
strbuf_addbuf(&src, &t->path);
@@ -309,19 +309,19 @@ void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
- if (t->prev_odb)
+ if (t->prev_source)
BUG("the primary object database is already replaced");
- t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_source = set_temporary_primary_odb(t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
{
- if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
+ if (!the_tmp_objdir || !the_tmp_objdir->prev_source)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
- the_tmp_objdir->prev_odb = NULL;
+ restore_primary_odb(the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
+ the_tmp_objdir->prev_source = NULL;
return the_tmp_objdir;
}
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v5 02/17] object-store: rename `object_directory` to `odb_source`
2025-06-05 6:46 ` [PATCH v5 02/17] object-store: rename `object_directory` to `odb_source` Patrick Steinhardt
@ 2025-06-30 2:02 ` Justin Tobler
2025-07-01 12:17 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Justin Tobler @ 2025-06-30 2:02 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On 25/06/05 08:46AM, Patrick Steinhardt wrote:
> The `object_directory` structure is used as an access point for a single
> object directory like ".git/objects". While the structure isn't yet
> fully self-contained, the intent is for it to eventually contain all
> information required to access objects in one specific location.
>
> While the name "object directory" is a good fit for now, this will
> change over time as we continue with the agenda to make pluggable object
> databases a thing. Eventually, objects may not be accessed via any kind
> of directory at all anymore, but they could instead be backed by any
> kind of durable storage mechanism. While it seems quite far-fetched for
> now, it is thinkable that eventually this might even be some form of a
> database, for example.
>
> As such, the current name of this structure will become worse over time
> as we evolve into the direction of pluggable ODBs. Immediate next steps
> will start to carve out proper self-contained object directories, which
> requires us to pass in these object directories as parameters. Based on
> our modern naming schema this means that those functions should then be
> named after their subsystem, which means that we would start to bake the
> current name into the codebase more and more.
>
> Let's preempt this by renaming the structure. There have been a couple
> alternatives that were discussed:
>
> - `odb_backend` was discarded because it led to the association that
> one object database has a single backend, but the model is that one
> alternate has one backend. Furthermore, "backend" is more about the
> actual backing implementation and less about the high-level concept.
>
> - `odb_alternate` was discarded because it is a bit of a stretch to
> also call the main object directory an "alternate".
>
> Instead, pick `odb_source` as the new name. It makes it sufficiently
> clear that there can be multiple sources and does not cause confusion
> when mixed with the already-existing "alternate" terminology.
I'm biased, but I think the new name fits well ;)
>
> In the future, this change allows us to easily introduce for example a
> `odb_files_source` and other format-specific implementations.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
[snip]
> -struct object_directory *find_odb(struct repository *r, const char *obj_dir)
> +struct odb_source *find_odb(struct repository *r, const char *obj_dir)
Since we renamed `object_directory` to `odb_source`, should instead call
this function `find_odb_source`?
Otherwise, the renames in this patch look good to me.
-Justin
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v5 02/17] object-store: rename `object_directory` to `odb_source`
2025-06-30 2:02 ` Justin Tobler
@ 2025-07-01 12:17 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:17 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On Sun, Jun 29, 2025 at 09:02:04PM -0500, Justin Tobler wrote:
> On 25/06/05 08:46AM, Patrick Steinhardt wrote:
> [snip]
> > -struct object_directory *find_odb(struct repository *r, const char *obj_dir)
> > +struct odb_source *find_odb(struct repository *r, const char *obj_dir)
>
> Since we renamed `object_directory` to `odb_source`, should instead call
> this function `find_odb_source`?
>
> Otherwise, the renames in this patch look good to me.
The name gets adjusted to `odb_find_source()` in a later patch.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v5 03/17] object-store: rename files to "odb.{c,h}"
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
2025-06-05 6:46 ` [PATCH v5 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
2025-06-05 6:46 ` [PATCH v5 02/17] object-store: rename `object_directory` to `odb_source` Patrick Steinhardt
@ 2025-06-05 6:46 ` Patrick Steinhardt
2025-06-05 6:46 ` [PATCH v5 04/17] odb: introduce parent pointers Patrick Steinhardt
` (13 subsequent siblings)
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:46 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
In the preceding commits we have renamed the structures contained in
"object-store.h" to `struct object_database` and `struct odb_backend`.
As such, the code files "object-store.{c,h}" are confusingly named now.
Rename them to "odb.{c,h}" accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Makefile | 2 +-
apply.c | 2 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 2 +-
blame.c | 2 +-
builtin/backfill.c | 2 +-
builtin/blame.c | 2 +-
builtin/cat-file.c | 2 +-
builtin/checkout.c | 2 +-
builtin/clone.c | 2 +-
builtin/commit-graph.c | 2 +-
builtin/commit-tree.c | 2 +-
builtin/describe.c | 2 +-
builtin/difftool.c | 2 +-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 2 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 2 +-
builtin/grep.c | 2 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 2 +-
builtin/log.c | 2 +-
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 2 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 2 +-
builtin/mktag.c | 2 +-
builtin/mktree.c | 2 +-
builtin/multi-pack-index.c | 2 +-
builtin/notes.c | 2 +-
builtin/pack-objects.c | 2 +-
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 2 +-
builtin/receive-pack.c | 2 +-
builtin/remote.c | 2 +-
builtin/repack.c | 2 +-
builtin/replace.c | 2 +-
builtin/rev-list.c | 2 +-
builtin/show-ref.c | 2 +-
builtin/submodule--helper.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 2 +-
bulk-checkin.c | 2 +-
bundle-uri.c | 2 +-
bundle.c | 2 +-
cache-tree.c | 2 +-
combine-diff.c | 2 +-
commit-graph.c | 2 +-
commit-graph.h | 2 +-
commit.c | 2 +-
config.c | 2 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 2 +-
diff.c | 2 +-
entry.c | 2 +-
fetch-pack.c | 2 +-
fmt-merge-msg.c | 2 +-
fsck.c | 2 +-
grep.c | 2 +-
http-backend.c | 2 +-
http-push.c | 2 +-
http-walker.c | 2 +-
http.c | 2 +-
list-objects-filter.c | 2 +-
list-objects.c | 2 +-
loose.c | 2 +-
mailmap.c | 2 +-
match-trees.c | 2 +-
merge-blobs.c | 2 +-
merge-ort.c | 2 +-
meson.build | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 2 +-
object-file.c | 2 +-
object-file.h | 2 +-
object-store.c => odb.c | 2 +-
object-store.h => odb.h | 6 +++---
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 2 +-
pack-bitmap.c | 2 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
packfile.c | 2 +-
packfile.h | 4 ++--
path.c | 2 +-
promisor-remote.c | 2 +-
protocol-caps.c | 2 +-
read-cache.c | 2 +-
ref-filter.c | 2 +-
reflog.c | 2 +-
refs.c | 2 +-
remote.c | 2 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 2 +-
rerere.c | 2 +-
revision.c | 2 +-
send-pack.c | 2 +-
sequencer.c | 2 +-
server-info.c | 2 +-
shallow.c | 2 +-
streaming.c | 2 +-
submodule-config.c | 2 +-
submodule.c | 2 +-
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 2 +-
t/helper/test-read-graph.c | 2 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 2 +-
tag.c | 2 +-
tmp-objdir.c | 2 +-
tree-walk.c | 2 +-
tree.c | 2 +-
unpack-trees.c | 2 +-
upload-pack.c | 2 +-
walker.c | 2 +-
xdiff-interface.c | 2 +-
126 files changed, 129 insertions(+), 129 deletions(-)
diff --git a/Makefile b/Makefile
index 70d1543b6b8..4b1bf897791 100644
--- a/Makefile
+++ b/Makefile
@@ -1085,8 +1085,8 @@ LIB_OBJS += notes.o
LIB_OBJS += object-file-convert.o
LIB_OBJS += object-file.o
LIB_OBJS += object-name.o
-LIB_OBJS += object-store.o
LIB_OBJS += object.o
+LIB_OBJS += odb.o
LIB_OBJS += oid-array.o
LIB_OBJS += oidmap.o
LIB_OBJS += oidset.o
diff --git a/apply.c b/apply.c
index 8bbe6ed2240..e778b4e911d 100644
--- a/apply.c
+++ b/apply.c
@@ -14,7 +14,7 @@
#include "abspath.h"
#include "base85.h"
#include "config.h"
-#include "object-store.h"
+#include "odb.h"
#include "delta.h"
#include "diff.h"
#include "dir.h"
diff --git a/archive-tar.c b/archive-tar.c
index 282b48196f9..249164ea77d 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -11,7 +11,7 @@
#include "hex.h"
#include "tar.h"
#include "archive.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "streaming.h"
#include "run-command.h"
diff --git a/archive-zip.c b/archive-zip.c
index 405da6f3d83..df8866d5bae 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -12,7 +12,7 @@
#include "hex.h"
#include "streaming.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "userdiff.h"
#include "write-or-die.h"
diff --git a/archive.c b/archive.c
index 8309ea213e6..7fa2cc2596a 100644
--- a/archive.c
+++ b/archive.c
@@ -14,7 +14,7 @@
#include "pretty.h"
#include "setup.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 86b6109fc4e..e5680db7f65 100644
--- a/attr.c
+++ b/attr.c
@@ -22,7 +22,7 @@
#include "read-cache-ll.h"
#include "refs.h"
#include "revision.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/bisect.c b/bisect.c
index a327468c75b..a7939216d00 100644
--- a/bisect.c
+++ b/bisect.c
@@ -20,7 +20,7 @@
#include "commit-slab.h"
#include "commit-reach.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "dir.h"
diff --git a/blame.c b/blame.c
index 57daa45e899..0ceea080a80 100644
--- a/blame.c
+++ b/blame.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "cache-tree.h"
#include "mergesort.h"
#include "commit.h"
diff --git a/builtin/backfill.c b/builtin/backfill.c
index fa82ad2f6ff..0b49baa39fa 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -13,7 +13,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "promisor-remote.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 944952e30eb..15eda60af90 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -28,7 +28,7 @@
#include "line-log.h"
#include "progress.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "blame.h"
#include "refs.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 67a5ff2b9eb..f3a925a8183 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -24,7 +24,7 @@
#include "pack-bitmap.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "mailmap.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d185982f3a6..e7dd66173dd 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,7 +20,7 @@
#include "merge-ort-wrappers.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "path.h"
#include "preload-index.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 91b9cd0d164..1eafeefb48d 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -25,7 +25,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "tree-walk.h"
#include "unpack-trees.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 98a84315342..f04eaba5259 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -6,7 +6,7 @@
#include "hex.h"
#include "parse-options.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "progress.h"
#include "replace-object.h"
#include "strbuf.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index ad6b2c93209..546069f8682 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -9,7 +9,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "parse-options.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 2d50883b729..96cb68e5e5d 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -19,7 +19,7 @@
#include "setup.h"
#include "strvec.h"
#include "run-command.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects.h"
#include "commit-slab.h"
#include "wildmatch.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index a3b64ce6942..fac613e3bc3 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -30,7 +30,7 @@
#include "strbuf.h"
#include "lockfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "entry.h"
#include "setup.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 37c01d6c6fe..0505f289a94 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "object.h"
#include "tag.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index b2839c5f439..52c792488e1 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -24,7 +24,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "mem-pool.h"
#include "commit-reach.h"
#include "khash.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index a890e2864d1..b842bc9c51b 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "oid-array.h"
#include "commit.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6e1474f63d5..9abd7b25580 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "read-cache-ll.h"
#include "replace-object.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 76b1938bba5..a1d7ee7af39 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -26,7 +26,7 @@
#include "submodule-config.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pager.h"
#include "path.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index 6a99ec250d0..e28f000221f 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -11,7 +11,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bb7925bd29f..1aabe6b8ee2 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -21,7 +21,7 @@
#include "packfile.h"
#include "pack-revindex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "path.h"
diff --git a/builtin/log.c b/builtin/log.c
index b450cd3bde8..fe9cc5ebecb 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -15,7 +15,7 @@
#include "hex.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "color.h"
#include "commit.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index be74f0a03b2..821339b07d4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -25,7 +25,7 @@
#include "setup.h"
#include "sparse-index.h"
#include "submodule.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 8aafc30ca48..62b6fd58c16 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -10,7 +10,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "path.h"
#include "quote.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 2b16b10d2ca..9464f275629 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -7,7 +7,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "gettext.h"
#include "setup.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 7f41665dfd7..b1a17787bcf 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -10,7 +10,7 @@
#include "commit-reach.h"
#include "merge-ort.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "blob.h"
#include "merge-blobs.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 7ac11c46d53..1809b38f937 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -6,7 +6,7 @@
#include "strbuf.h"
#include "replace-object.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "fsck.h"
#include "config.h"
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 4b478034675..016b0e5b224 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -12,7 +12,7 @@
#include "tree.h"
#include "parse-options.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static struct treeent {
unsigned mode;
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index f55bf53da83..aa25b06f9d0 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -7,7 +7,7 @@
#include "midx.h"
#include "strbuf.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index a3f433ca4c0..783d4932ca6 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -16,7 +16,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "pretty.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 8b33edc2ff5..99b63cb0980 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -32,7 +32,7 @@
#include "list.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "dir.h"
#include "midx.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 5d1fc781761..3134cb8c689 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -13,7 +13,7 @@
#include "hex.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#define BLKSIZE 512
diff --git a/builtin/prune.c b/builtin/prune.c
index e930caa0c0a..7bbfb14c2be 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -17,7 +17,7 @@
#include "replace-object.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "shallow.h"
static const char * const prune_usage[] = {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index a317d6c278d..0f5958c4a66 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -33,7 +33,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "protocol.h"
#include "commit-reach.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 0d6755bcb71..ac5b8d2a1a6 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -14,7 +14,7 @@
#include "rebase.h"
#include "refs.h"
#include "refspec.h"
-#include "object-store.h"
+#include "odb.h"
#include "strvec.h"
#include "commit-reach.h"
#include "progress.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 59214dbdfdf..16782320058 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -17,7 +17,7 @@
#include "midx.h"
#include "packfile.h"
#include "prune-packed.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "shallow.h"
#include "pack.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 48c7c6a2d56..11c7e2d4c0c 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "tag.h"
#include "wildmatch.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 0984b607bf0..0ee37a32cb2 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -14,7 +14,7 @@
#include "object.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "parse-options.h"
#include "log-tree.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 623a52a45f8..90ec1de78f9 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "refs/refs-internal.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "string-list.h"
#include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 758bc6d0f24..84f7fa53424 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -28,7 +28,7 @@
#include "diff.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "advice.h"
#include "branch.h"
#include "list-objects-filter-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 4742b27d16e..cf2ea4b4993 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -19,7 +19,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "tag.h"
#include "parse-options.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index e33acfc4ee4..b92fd4710a9 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
static char *create_temp_file(struct object_id *oid)
{
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index e905d5f4e19..7bf395eec84 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -9,7 +9,7 @@
#include "git-zlib.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "delta.h"
#include "pack.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 678e2ecc2c2..55406a539e7 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -17,7 +17,7 @@
#include "tmp-objdir.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static int odb_transaction_nesting;
diff --git a/bundle-uri.c b/bundle-uri.c
index 9accf157b44..2e623f8627a 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -14,7 +14,7 @@
#include "fetch-pack.h"
#include "remote.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
static struct {
enum bundle_list_heuristic heuristic;
diff --git a/bundle.c b/bundle.c
index 2ce7525f90d..e09e3c2f58c 100644
--- a/bundle.c
+++ b/bundle.c
@@ -7,7 +7,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "object.h"
#include "commit.h"
diff --git a/cache-tree.c b/cache-tree.c
index fa3858e2829..9786b32b3a1 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -10,7 +10,7 @@
#include "cache-tree.h"
#include "bulk-checkin.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "read-cache-ll.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/combine-diff.c b/combine-diff.c
index dfae9f7995d..cf23a753407 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -2,7 +2,7 @@
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "convert.h"
#include "diff.h"
diff --git a/commit-graph.c b/commit-graph.c
index 12d32cdad1d..6ced5b366e7 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -13,7 +13,7 @@
#include "refs.h"
#include "hash-lookup.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "alloc.h"
diff --git a/commit-graph.h b/commit-graph.h
index 0e661db1b54..78ab7b875b2 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -1,7 +1,7 @@
#ifndef COMMIT_GRAPH_H
#define COMMIT_GRAPH_H
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
diff --git a/commit.c b/commit.c
index e915b2b9a12..1d30f8ce15a 100644
--- a/commit.c
+++ b/commit.c
@@ -9,7 +9,7 @@
#include "hex.h"
#include "repository.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "diff.h"
#include "revision.h"
diff --git a/config.c b/config.c
index b18b5617fcd..883dd066827 100644
--- a/config.c
+++ b/config.c
@@ -31,7 +31,7 @@
#include "hashmap.h"
#include "string-list.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "path.h"
#include "utf8.h"
diff --git a/connected.c b/connected.c
index 4415388beba..18c13245d8e 100644
--- a/connected.c
+++ b/connected.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "run-command.h"
#include "sigchain.h"
#include "connected.h"
diff --git a/contrib/coccinelle/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
index 765ad689678..ea7fe1c8db7 100644
--- a/contrib/coccinelle/the_repository.cocci
+++ b/contrib/coccinelle/the_repository.cocci
@@ -77,7 +77,7 @@
|
- diff_setup
+ repo_diff_setup
-// object-store.h
+// odb.h
|
- read_object_file
+ repo_read_object_file
diff --git a/diagnose.c b/diagnose.c
index d08d5643aac..ad0d5c12465 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -7,7 +7,7 @@
#include "gettext.h"
#include "hex.h"
#include "strvec.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "repository.h"
diff --git a/diff.c b/diff.c
index 90e8003dd11..3af108115b3 100644
--- a/diff.c
+++ b/diff.c
@@ -23,7 +23,7 @@
#include "color.h"
#include "run-command.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "userdiff.h"
#include "submodule.h"
#include "hashmap.h"
diff --git a/entry.c b/entry.c
index f36ec5ad242..75d55038d7c 100644
--- a/entry.c
+++ b/entry.c
@@ -1,7 +1,7 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index fa4231fee74..cf157f5d7e5 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -24,7 +24,7 @@
#include "oid-array.h"
#include "oidset.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "connected.h"
#include "fetch-negotiator.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 501b5acdd44..1a8c972adf3 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -6,7 +6,7 @@
#include "environment.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "diff.h"
#include "diff-merges.h"
#include "hex.h"
diff --git a/fsck.c b/fsck.c
index 8dc8472ceb3..e69baab3af7 100644
--- a/fsck.c
+++ b/fsck.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "dir.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "object.h"
diff --git a/grep.c b/grep.c
index f8d535182c3..dc77e6c4631 100644
--- a/grep.c
+++ b/grep.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "grep.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "userdiff.h"
#include "xdiff-interface.h"
diff --git a/http-backend.c b/http-backend.c
index 0c575aa88aa..ad8c4037493 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -18,7 +18,7 @@
#include "url.h"
#include "strvec.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "protocol.h"
#include "date.h"
#include "write-or-die.h"
diff --git a/http-push.c b/http-push.c
index f9e67cabd4b..d1b1bb23711 100644
--- a/http-push.c
+++ b/http-push.c
@@ -20,7 +20,7 @@
#include "url.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#ifdef EXPAT_NEEDS_XMLPARSE_H
diff --git a/http-walker.c b/http-walker.c
index c374e6b2056..05fb9ce714a 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -10,7 +10,7 @@
#include "transport.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct alt_base {
char *base;
diff --git a/http.c b/http.c
index 5e15bbab3f1..8f4f701a818 100644
--- a/http.c
+++ b/http.c
@@ -19,7 +19,7 @@
#include "packfile.h"
#include "string-list.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tempfile.h"
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 78b397bc194..80fe48a52c8 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -12,7 +12,7 @@
#include "oidmap.h"
#include "oidset.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
/* Remember to update object flag allocation in object.h */
/*
diff --git a/list-objects.c b/list-objects.c
index 597114281f6..c50b9578584 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -14,7 +14,7 @@
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace.h"
#include "environment.h"
diff --git a/loose.c b/loose.c
index fe65d5b9b0f..fab4041c03d 100644
--- a/loose.c
+++ b/loose.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
#include "repository.h"
#include "wrapper.h"
diff --git a/mailmap.c b/mailmap.c
index 9e2642a043b..b18e74c2110 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -6,7 +6,7 @@
#include "string-list.h"
#include "mailmap.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
char *git_mailmap_file;
diff --git a/match-trees.c b/match-trees.c
index 72922d5d64e..4704f95c340 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -7,7 +7,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
static int score_missing(unsigned mode)
diff --git a/merge-blobs.c b/merge-blobs.c
index 53f36dbc175..ba8a3fdfd82 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -4,7 +4,7 @@
#include "merge-ll.h"
#include "blob.h"
#include "merge-blobs.h"
-#include "object-store.h"
+#include "odb.h"
static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
{
diff --git a/merge-ort.c b/merge-ort.c
index 47b3d1730ec..9f693ab1d36 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -39,7 +39,7 @@
#include "mem-pool.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/meson.build b/meson.build
index 596f5ac7110..3fad0e39987 100644
--- a/meson.build
+++ b/meson.build
@@ -396,8 +396,8 @@ libgit_sources = [
'object-file-convert.c',
'object-file.c',
'object-name.c',
- 'object-store.c',
'object.c',
+ 'odb.c',
'oid-array.c',
'oidmap.c',
'oidset.c',
diff --git a/notes-cache.c b/notes-cache.c
index 150241b15e0..344f67762b8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "notes-cache.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "repository.h"
#include "commit.h"
diff --git a/notes-merge.c b/notes-merge.c
index dae8e6a281a..de6a52e2e7f 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -8,7 +8,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "diff.h"
diff --git a/notes.c b/notes.c
index 0a128f1de98..fc000e501d2 100644
--- a/notes.c
+++ b/notes.c
@@ -8,7 +8,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "strbuf.h"
#include "tree-walk.h"
diff --git a/object-file.c b/object-file.c
index 6bad1d3dd1c..2d3af8a77c0 100644
--- a/object-file.c
+++ b/object-file.c
@@ -21,7 +21,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidtree.h"
#include "pack.h"
#include "packfile.h"
diff --git a/object-file.h b/object-file.h
index 9a18859b2e0..5066638f8ec 100644
--- a/object-file.h
+++ b/object-file.h
@@ -3,7 +3,7 @@
#include "git-zlib.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
struct index_state;
diff --git a/object-store.c b/odb.c
similarity index 99%
rename from object-store.c
rename to odb.c
index 5c04a1018f7..d1025ac182d 100644
--- a/object-store.c
+++ b/odb.c
@@ -13,7 +13,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/object-store.h b/odb.h
similarity index 99%
rename from object-store.h
rename to odb.h
index d199d757d76..6f56b168e46 100644
--- a/object-store.h
+++ b/odb.h
@@ -1,5 +1,5 @@
-#ifndef OBJECT_STORE_H
-#define OBJECT_STORE_H
+#ifndef ODB_H
+#define ODB_H
#include "hashmap.h"
#include "object.h"
@@ -352,4 +352,4 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
-#endif /* OBJECT_STORE_H */
+#endif /* ODB_H */
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 609a343ee3e..d2a92f34d98 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 7f400ee0121..37648b57125 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -4,7 +4,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index ac6d62b980c..a695a794e9b 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "repository.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects-filter-options.h"
#include "midx.h"
#include "config.h"
diff --git a/pack-check.c b/pack-check.c
index 874897d6cba..67cb2cf72f2 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -8,7 +8,7 @@
#include "progress.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct idx_entry {
off_t offset;
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 20900ca88d3..8e1f2dec0ef 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-mtimes.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
diff --git a/pack-objects.h b/pack-objects.h
index 475a2d67ce3..1ac8644201b 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -1,7 +1,7 @@
#ifndef PACK_OBJECTS_H
#define PACK_OBJECTS_H
-#include "object-store.h"
+#include "odb.h"
#include "thread-utils.h"
#include "pack.h"
#include "packfile.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index ffcde48870d..0cc422a1e67 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-revindex.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
#include "trace2.h"
diff --git a/packfile.c b/packfile.c
index 60661ad0095..346c2f9ce90 100644
--- a/packfile.c
+++ b/packfile.c
@@ -19,7 +19,7 @@
#include "tree-walk.h"
#include "tree.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "midx.h"
#include "commit-graph.h"
#include "pack-revindex.h"
diff --git a/packfile.h b/packfile.h
index 826eb7f475f..53c3b7d3b43 100644
--- a/packfile.h
+++ b/packfile.h
@@ -3,10 +3,10 @@
#include "list.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
-/* in object-store.h */
+/* in odb.h */
struct object_info;
struct packed_git {
diff --git a/path.c b/path.c
index c347829aa66..7f56eaf9930 100644
--- a/path.c
+++ b/path.c
@@ -15,7 +15,7 @@
#include "submodule-config.h"
#include "path.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "lockfile.h"
#include "exec-cmd.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 9d058586dfa..2baa286bfd0 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "config.h"
#include "trace2.h"
diff --git a/protocol-caps.c b/protocol-caps.c
index 9b8db37a210..3022f69a1bd 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -6,7 +6,7 @@
#include "hash.h"
#include "hex.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "string-list.h"
#include "strbuf.h"
diff --git a/read-cache.c b/read-cache.c
index c0bb760ad47..c3fa9686766 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -20,7 +20,7 @@
#include "refs.h"
#include "dir.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "tree.h"
#include "commit.h"
diff --git a/ref-filter.c b/ref-filter.c
index 7a274633cfc..4ce45440ad1 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "wildmatch.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "repo-settings.h"
#include "repository.h"
diff --git a/reflog.c b/reflog.c
index 15d81ebea97..4f8a3b717cd 100644
--- a/reflog.c
+++ b/reflog.c
@@ -5,7 +5,7 @@
#include "config.h"
#include "gettext.h"
#include "parse-options.h"
-#include "object-store.h"
+#include "odb.h"
#include "reflog.h"
#include "refs.h"
#include "revision.h"
diff --git a/refs.c b/refs.c
index 5f6a386cc93..0ff0e582a6b 100644
--- a/refs.c
+++ b/refs.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "hook.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "path.h"
#include "submodule.h"
diff --git a/remote.c b/remote.c
index 4099183cacd..17a842f5684 100644
--- a/remote.c
+++ b/remote.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "commit.h"
#include "diff.h"
diff --git a/replace-object.c b/replace-object.c
index f8c5f68837f..3eae0510745 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -2,7 +2,7 @@
#include "gettext.h"
#include "hex.h"
#include "oidmap.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "refs.h"
#include "repository.h"
diff --git a/replace-object.h b/replace-object.h
index 3052e96a620..4c9f2a2383d 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -3,7 +3,7 @@
#include "oidmap.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
struct replace_object {
struct oidmap_entry original;
diff --git a/repository.c b/repository.c
index 7528beccddf..13426db0f2b 100644
--- a/repository.c
+++ b/repository.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "object.h"
#include "lockfile.h"
diff --git a/rerere.c b/rerere.c
index 3cd37c5f0ae..951e4bf8b41 100644
--- a/rerere.c
+++ b/rerere.c
@@ -18,7 +18,7 @@
#include "path.h"
#include "pathspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "strmap.h"
#define RESOLVED 0
diff --git a/revision.c b/revision.c
index 2c36a9c179e..cdefe7d6e48 100644
--- a/revision.c
+++ b/revision.c
@@ -8,7 +8,7 @@
#include "hex.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "tag.h"
#include "blob.h"
diff --git a/send-pack.c b/send-pack.c
index 86592ce526d..abca2dd38a7 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pkt-line.h"
#include "sideband.h"
#include "run-command.h"
diff --git a/sequencer.c b/sequencer.c
index 1ee0abbd451..2432d0a39ec 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -13,7 +13,7 @@
#include "dir.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "pager.h"
#include "commit.h"
diff --git a/server-info.c b/server-info.c
index d6cd20a39d7..9bb30d9ab71 100644
--- a/server-info.c
+++ b/server-info.c
@@ -11,7 +11,7 @@
#include "packfile.h"
#include "path.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "server-info.h"
#include "strbuf.h"
#include "tempfile.h"
diff --git a/shallow.c b/shallow.c
index faeeeb45f98..d379756e39a 100644
--- a/shallow.c
+++ b/shallow.c
@@ -5,7 +5,7 @@
#include "repository.h"
#include "tempfile.h"
#include "lockfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tag.h"
#include "pkt-line.h"
diff --git a/streaming.c b/streaming.c
index 6d6512e2e0d..81c42673a23 100644
--- a/streaming.c
+++ b/streaming.c
@@ -10,7 +10,7 @@
#include "streaming.h"
#include "repository.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "packfile.h"
diff --git a/submodule-config.c b/submodule-config.c
index b30d9365fbd..9c80f9f7b66 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -13,7 +13,7 @@
#include "submodule.h"
#include "strbuf.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/submodule.c b/submodule.c
index ead3fb5dadc..9b1018877df 100644
--- a/submodule.c
+++ b/submodule.c
@@ -27,7 +27,7 @@
#include "parse-options.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index 76c2f4eba85..611a13a3261 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -2,7 +2,7 @@
#include "test-tool.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "setup.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index fdf1b13437b..d51aaa3dc40 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pack-mtimes.h"
#include "setup.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 34f1aee5581..dba227259a2 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "hex.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
/*
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 53b633e2ba6..ef5339bbee9 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "bloom.h"
#include "setup.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index ac81390899a..da2aa036b57 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "midx.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "packfile.h"
#include "setup.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 4cfc7c90b59..2920ca59d72 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -5,7 +5,7 @@
#include "refs.h"
#include "setup.h"
#include "worktree.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "strbuf.h"
diff --git a/tag.c b/tag.c
index 05be39067cf..5f6868bf7b1 100644
--- a/tag.c
+++ b/tag.c
@@ -5,7 +5,7 @@
#include "environment.h"
#include "tag.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "blob.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 056484404be..bef2f917cd2 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -10,7 +10,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "quote.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
struct tmp_objdir {
diff --git a/tree-walk.c b/tree-walk.c
index 90655d52378..34b0fff4873 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -6,7 +6,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace2.h"
#include "tree.h"
#include "pathspec.h"
diff --git a/tree.c b/tree.c
index b85f56267fb..341b7c2ff3f 100644
--- a/tree.c
+++ b/tree.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "tree.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "alloc.h"
#include "tree-walk.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 471837f0329..f38c761ab98 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -26,7 +26,7 @@
#include "symlinks.h"
#include "trace2.h"
#include "fsmonitor.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "entry.h"
#include "parallel-checkout.h"
diff --git a/upload-pack.c b/upload-pack.c
index 26f29b85b55..e994d6a901b 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -10,7 +10,7 @@
#include "pkt-line.h"
#include "sideband.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "object.h"
#include "commit.h"
diff --git a/walker.c b/walker.c
index b470d43e54d..a8abe8a2e78 100644
--- a/walker.c
+++ b/walker.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "walker.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "strbuf.h"
#include "tree.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 1edcd319e6e..01e6e378ea6 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "config.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "xdiff-interface.h"
#include "xdiff/xtypes.h"
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 04/17] odb: introduce parent pointers
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (2 preceding siblings ...)
2025-06-05 6:46 ` [PATCH v5 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
@ 2025-06-05 6:46 ` Patrick Steinhardt
2025-06-30 2:34 ` Justin Tobler
2025-06-05 6:46 ` [PATCH v5 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
` (12 subsequent siblings)
16 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:46 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
In subsequent commits we'll get rid of our use of `the_repository` in
"odb.c" in favor of explicitly passing in a `struct object_database` or
a `struct odb_source`. In some cases though we'll need access to the
repository, for example to read a config value from it, but we don't
have a way to access the repository owning a specific object database.
Introduce parent pointers for `struct object_database` to its owning
repository as well as for `struct odb_source` to its owning object
database, which will allow us to adapt those use cases.
Note that this change requires us to pass through the object database to
`link_alt_odb_entry()` so that we can set up the parent pointers for any
source there. The callchain is adapted to pass through the object
database accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 47 +++++++++++++++++++++++++++--------------------
odb.h | 8 +++++++-
repository.c | 3 ++-
3 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/odb.c b/odb.c
index d1025ac182d..afb16f4c693 100644
--- a/odb.c
+++ b/odb.c
@@ -135,11 +135,15 @@ static int alt_odb_usable(struct object_database *o,
* of the object ID, an extra slash for the first level indirection, and
* the terminating NUL.
*/
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth);
-static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
- const char *relative_base, int depth, const char *normalized_objdir)
+
+static int link_alt_odb_entry(struct object_database *odb,
+ const struct strbuf *entry,
+ const char *relative_base,
+ int depth,
+ const char *normalized_objdir)
{
struct odb_source *alternate;
struct strbuf pathbuf = STRBUF_INIT;
@@ -167,22 +171,23 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
strbuf_setlen(&pathbuf, pathbuf.len - 1);
- if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
+ if (!alt_odb_usable(odb, &pathbuf, normalized_objdir, &pos))
goto error;
CALLOC_ARRAY(alternate, 1);
- /* pathbuf.buf is already in r->objects->source_by_path */
+ alternate->odb = odb;
+ /* pathbuf.buf is already in r->objects->alternate_by_path */
alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->sources_tail = alternate;
- r->objects->sources_tail = &(alternate->next);
+ *odb->sources_tail = alternate;
+ odb->sources_tail = &(alternate->next);
alternate->next = NULL;
- assert(r->objects->source_by_path);
- kh_value(r->objects->source_by_path, pos) = alternate;
+ assert(odb->source_by_path);
+ kh_value(odb->source_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, alternate->path, depth + 1);
+ read_info_alternates(odb, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -219,7 +224,7 @@ static const char *parse_alt_odb_entry(const char *string,
return end;
}
-static void link_alt_odb_entries(struct repository *r, const char *alt,
+static void link_alt_odb_entries(struct object_database *odb, const char *alt,
int sep, const char *relative_base, int depth)
{
struct strbuf objdirbuf = STRBUF_INIT;
@@ -234,20 +239,20 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->sources->path, 1);
+ strbuf_realpath(&objdirbuf, odb->sources->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
if (!entry.len)
continue;
- link_alt_odb_entry(r, &entry,
+ link_alt_odb_entry(odb, &entry,
relative_base, depth, objdirbuf.buf);
}
strbuf_release(&entry);
strbuf_release(&objdirbuf);
}
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth)
{
@@ -261,7 +266,7 @@ static void read_info_alternates(struct repository *r,
return;
}
- link_alt_odb_entries(r, buf.buf, '\n', relative_base, depth);
+ link_alt_odb_entries(odb, buf.buf, '\n', relative_base, depth);
strbuf_release(&buf);
free(path);
}
@@ -303,7 +308,7 @@ void add_to_alternates_file(const char *reference)
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
free(alts);
@@ -317,7 +322,7 @@ void add_to_alternates_memory(const char *reference)
*/
prepare_alt_odb(the_repository);
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
@@ -336,6 +341,7 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* alternate
*/
source = xcalloc(1, sizeof(*source));
+ source->odb = the_repository->objects;
source->path = xstrdup(dir);
/*
@@ -580,9 +586,9 @@ void prepare_alt_odb(struct repository *r)
if (r->objects->loaded_alternates)
return;
- link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->sources->path, 0);
+ read_info_alternates(r->objects, r->objects->sources->path, 0);
r->objects->loaded_alternates = 1;
}
@@ -950,11 +956,12 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct object_database *odb_new(void)
+struct object_database *odb_new(struct repository *repo)
{
struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
+ o->repo = repo;
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
diff --git a/odb.h b/odb.h
index 6f56b168e46..c3851e29668 100644
--- a/odb.h
+++ b/odb.h
@@ -28,6 +28,9 @@ struct repository;
struct odb_source {
struct odb_source *next;
+ /* Object database that owns this object source. */
+ struct object_database *odb;
+
/*
* Used to store the results of readdir(3) calls when we are OK
* sacrificing accuracy due to races for speed. That includes
@@ -105,6 +108,9 @@ struct cached_object_entry;
* configured via alternates.
*/
struct object_database {
+ /* Repository that owns this database. */
+ struct repository *repo;
+
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -186,7 +192,7 @@ struct object_database {
unsigned packed_git_initialized : 1;
};
-struct object_database *odb_new(void);
+struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
/*
diff --git a/repository.c b/repository.c
index 13426db0f2b..c606e1153c8 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = odb_new();
+ repo->objects = odb_new(repo);
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -167,6 +167,7 @@ void repo_set_gitdir(struct repository *repo,
if (!repo->objects->sources) {
CALLOC_ARRAY(repo->objects->sources, 1);
+ repo->objects->sources->odb = repo->objects;
repo->objects->sources_tail = &repo->objects->sources->next;
}
expand_base_dir(&repo->objects->sources->path, o->object_dir,
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v5 04/17] odb: introduce parent pointers
2025-06-05 6:46 ` [PATCH v5 04/17] odb: introduce parent pointers Patrick Steinhardt
@ 2025-06-30 2:34 ` Justin Tobler
2025-07-01 12:17 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Justin Tobler @ 2025-06-30 2:34 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On 25/06/05 08:46AM, Patrick Steinhardt wrote:
> In subsequent commits we'll get rid of our use of `the_repository` in
> "odb.c" in favor of explicitly passing in a `struct object_database` or
> a `struct odb_source`. In some cases though we'll need access to the
> repository, for example to read a config value from it, but we don't
> have a way to access the repository owning a specific object database.
>
> Introduce parent pointers for `struct object_database` to its owning
> repository as well as for `struct odb_source` to its owning object
> database, which will allow us to adapt those use cases.
Ok so in this patch we are introducing the parent pointers and setting
them up, but not actually using them for anything yet.
> Note that this change requires us to pass through the object database to
> `link_alt_odb_entry()` so that we can set up the parent pointers for any
> source there. The callchain is adapted to pass through the object
> database accordingly.
Ok IIUC, for `link_alt_odb_entry()`, the reason we to pass `struct
object_database` instead of `struct odb_source` is because the sources
need to be set up with the pointer to the parent odb. That makes sense.
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> odb.c | 47 +++++++++++++++++++++++++++--------------------
> odb.h | 8 +++++++-
> repository.c | 3 ++-
> 3 files changed, 36 insertions(+), 22 deletions(-)
>
> diff --git a/odb.c b/odb.c
> index d1025ac182d..afb16f4c693 100644
> --- a/odb.c
> +++ b/odb.c
> @@ -135,11 +135,15 @@ static int alt_odb_usable(struct object_database *o,
> * of the object ID, an extra slash for the first level indirection, and
> * the terminating NUL.
> */
> -static void read_info_alternates(struct repository *r,
> +static void read_info_alternates(struct object_database *odb,
> const char *relative_base,
> int depth);
> -static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
> - const char *relative_base, int depth, const char *normalized_objdir)
> +
> +static int link_alt_odb_entry(struct object_database *odb,
> + const struct strbuf *entry,
> + const char *relative_base,
> + int depth,
> + const char *normalized_objdir)
> {
> struct odb_source *alternate;
> struct strbuf pathbuf = STRBUF_INIT;
> @@ -167,22 +171,23 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
> while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
> strbuf_setlen(&pathbuf, pathbuf.len - 1);
>
> - if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
> + if (!alt_odb_usable(odb, &pathbuf, normalized_objdir, &pos))
> goto error;
>
> CALLOC_ARRAY(alternate, 1);
> - /* pathbuf.buf is already in r->objects->source_by_path */
> + alternate->odb = odb;
> + /* pathbuf.buf is already in r->objects->alternate_by_path */
Should this comment instead say "odb->source_by_path"?
The remaining restructuring in this patch looks good.
-Justin
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v5 04/17] odb: introduce parent pointers
2025-06-30 2:34 ` Justin Tobler
@ 2025-07-01 12:17 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:17 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On Sun, Jun 29, 2025 at 09:34:12PM -0500, Justin Tobler wrote:
> > @@ -167,22 +171,23 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
> > while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
> > strbuf_setlen(&pathbuf, pathbuf.len - 1);
> >
> > - if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
> > + if (!alt_odb_usable(odb, &pathbuf, normalized_objdir, &pos))
> > goto error;
> >
> > CALLOC_ARRAY(alternate, 1);
> > - /* pathbuf.buf is already in r->objects->source_by_path */
> > + alternate->odb = odb;
> > + /* pathbuf.buf is already in r->objects->alternate_by_path */
>
> Should this comment instead say "odb->source_by_path"?
>
> The remaining restructuring in this patch looks good.
Ah, good catch. I think I botched conflict resolution here.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v5 05/17] odb: get rid of `the_repository` in `find_odb()`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (3 preceding siblings ...)
2025-06-05 6:46 ` [PATCH v5 04/17] odb: introduce parent pointers Patrick Steinhardt
@ 2025-06-05 6:46 ` Patrick Steinhardt
2025-06-30 2:36 ` Justin Tobler
2025-06-05 6:46 ` [PATCH v5 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
` (11 subsequent siblings)
16 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:46 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Get rid of our dependency on `the_repository` in `find_odb()` by passing
in the object database in which we want to search for the source and
adjusting all callers.
Rename the function to `odb_find_source()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 4 ++--
midx-write.c | 2 +-
odb.c | 6 +++---
odb.h | 7 ++++++-
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index f04eaba5259..77d7e88a98c 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -101,7 +101,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- source = find_odb(the_repository, opts.obj_dir);
+ source = odb_find_source(the_repository->objects, opts.obj_dir);
graph_name = get_commit_graph_filename(source);
chain_name = get_commit_graph_chain_filename(source);
if (open_commit_graph(graph_name, &fd, &st))
@@ -289,7 +289,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- source = find_odb(the_repository, opts.obj_dir);
+ source = odb_find_source(the_repository->objects, opts.obj_dir);
if (opts.reachable) {
if (write_commit_graph_reachable(source, flags, &write_opts))
diff --git a/midx-write.c b/midx-write.c
index ba4a94950a8..f2cfb85476e 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -922,7 +922,7 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
struct strbuf cur_path_real = STRBUF_INIT;
/* Ensure the given object_dir is local, or a known alternate. */
- find_odb(r, obj_dir_real);
+ odb_find_source(r->objects, obj_dir_real);
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
strbuf_realpath(&cur_path_real, cur->object_dir, 1);
diff --git a/odb.c b/odb.c
index afb16f4c693..483b9b38414 100644
--- a/odb.c
+++ b/odb.c
@@ -448,14 +448,14 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct odb_source *find_odb(struct repository *r, const char *obj_dir)
+struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir)
{
struct odb_source *source;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(r);
- for (source = r->objects->sources; source; source = source->next) {
+ prepare_alt_odb(odb->repo);
+ for (source = odb->sources; source; source = source->next) {
strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
diff --git a/odb.h b/odb.h
index c3851e29668..941329c6943 100644
--- a/odb.h
+++ b/odb.h
@@ -68,7 +68,6 @@ struct odb_source {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct odb_source *find_odb(struct repository *r, const char *obj_dir);
typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
@@ -195,6 +194,12 @@ struct object_database {
struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
+/*
+ * Find source by its object directory path. Dies in case the source couldn't
+ * be found.
+ */
+struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+
/*
* Create a temporary file rooted in the object database directory, or
* die on failure. The filename is taken from "pattern", which should have the
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 06/17] odb: get rid of `the_repository` in `assert_oid_type()`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (4 preceding siblings ...)
2025-06-05 6:46 ` [PATCH v5 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
@ 2025-06-05 6:46 ` Patrick Steinhardt
2025-06-05 6:46 ` [PATCH v5 07/17] odb: get rid of `the_repository` in `odb_mkstemp()` Patrick Steinhardt
` (10 subsequent siblings)
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:46 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Get rid of our dependency on `the_repository` in `assert_oid_type()` by
passing in the object database as a parameter and adjusting all callers.
Rename the function to `odb_assert_oid_type()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-tree.c | 2 +-
commit.c | 2 +-
odb.c | 5 +++--
odb.h | 3 ++-
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 546069f8682..31cfd9bd15d 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -48,7 +48,7 @@ static int parse_parent_arg_callback(const struct option *opt,
if (repo_get_oid_commit(the_repository, arg, &oid))
die(_("not a valid object name %s"), arg);
- assert_oid_type(&oid, OBJ_COMMIT);
+ odb_assert_oid_type(the_repository->objects, &oid, OBJ_COMMIT);
new_parent(lookup_commit(the_repository, &oid), parents);
return 0;
}
diff --git a/commit.c b/commit.c
index 1d30f8ce15a..aa65183d8b6 100644
--- a/commit.c
+++ b/commit.c
@@ -1706,7 +1706,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
/* Not having i18n.commitencoding is the same as having utf-8 */
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
- assert_oid_type(tree, OBJ_TREE);
+ odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);
if (memchr(msg, '\0', msg_len))
return error("a NUL byte in commit log message not allowed.");
diff --git a/odb.c b/odb.c
index 483b9b38414..3a3ceed5508 100644
--- a/odb.c
+++ b/odb.c
@@ -946,9 +946,10 @@ int has_object(struct repository *r, const struct object_id *oid,
return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
}
-void assert_oid_type(const struct object_id *oid, enum object_type expect)
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = oid_object_info(odb->repo, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index 941329c6943..13f5da45f54 100644
--- a/odb.h
+++ b/odb.h
@@ -302,7 +302,8 @@ enum {
int has_object(struct repository *r, const struct object_id *oid,
unsigned flags);
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect);
/*
* Enabling the object read lock allows multiple threads to safely call the
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 07/17] odb: get rid of `the_repository` in `odb_mkstemp()`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (5 preceding siblings ...)
2025-06-05 6:46 ` [PATCH v5 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
@ 2025-06-05 6:46 ` Patrick Steinhardt
2025-06-05 6:46 ` [PATCH v5 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
` (9 subsequent siblings)
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:46 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Get rid of our dependency on `the_repository` in `odb_mkstemp()` by
passing in the object database as a parameter and adjusting all callers.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 3 ++-
builtin/index-pack.c | 2 +-
bundle-uri.c | 3 ++-
odb.c | 9 +++++----
odb.h | 7 ++++---
pack-bitmap-write.c | 3 ++-
pack-write.c | 10 ++++++----
7 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 52c792488e1..413304db9b5 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -763,7 +763,8 @@ static void start_packfile(void)
struct packed_git *p;
int pack_fd;
- pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX");
+ pack_fd = odb_mkstemp(the_repository->objects, &tmp_file,
+ "pack/tmp_pack_XXXXXX");
FLEX_ALLOC_STR(p, pack_name, tmp_file.buf);
strbuf_release(&tmp_file);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 1aabe6b8ee2..4d4d989eb1a 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -362,7 +362,7 @@ static const char *open_pack_file(const char *pack_name)
input_fd = 0;
if (!pack_name) {
struct strbuf tmp_file = STRBUF_INIT;
- output_fd = odb_mkstemp(&tmp_file,
+ output_fd = odb_mkstemp(the_repository->objects, &tmp_file,
"pack/tmp_pack_XXXXXX");
pack_name = strbuf_detach(&tmp_file, NULL);
} else {
diff --git a/bundle-uri.c b/bundle-uri.c
index 2e623f8627a..f94e780e967 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -278,7 +278,8 @@ static char *find_temp_filename(void)
* Find a temporary filename that is available. This is briefly
* racy, but unlikely to collide.
*/
- fd = odb_mkstemp(&name, "bundles/tmp_uri_XXXXXX");
+ fd = odb_mkstemp(the_repository->objects, &name,
+ "bundles/tmp_uri_XXXXXX");
if (fd < 0) {
warning(_("failed to create temporary file"));
return NULL;
diff --git a/odb.c b/odb.c
index 3a3ceed5508..73410920a88 100644
--- a/odb.c
+++ b/odb.c
@@ -63,7 +63,8 @@ static const struct cached_object *find_cached_object(struct object_database *ob
return NULL;
}
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern)
{
int fd;
/*
@@ -71,15 +72,15 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
* restrictive except to remove write permission.
*/
int mode = 0444;
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
fd = git_mkstemp_mode(temp_filename->buf, mode);
if (0 <= fd)
return fd;
/* slow path */
/* some mkstemp implementations erase temp_filename on failure */
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
- safe_create_leading_directories(the_repository, temp_filename->buf);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
+ safe_create_leading_directories(odb->repo, temp_filename->buf);
return xmkstemp_mode(temp_filename->buf, mode);
}
diff --git a/odb.h b/odb.h
index 13f5da45f54..5de952608f3 100644
--- a/odb.h
+++ b/odb.h
@@ -201,12 +201,13 @@ void odb_clear(struct object_database *o);
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
/*
- * Create a temporary file rooted in the object database directory, or
- * die on failure. The filename is taken from "pattern", which should have the
+ * Create a temporary file rooted in the primary alternate's directory, or die
+ * on failure. The filename is taken from "pattern", which should have the
* usual "XXXXXX" trailer, and the resulting filename is written into the
* "template" buffer. Returns the open descriptor.
*/
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern);
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 37648b57125..c847369eaaa 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1052,7 +1052,8 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
struct bitmap_disk_header header;
- int fd = odb_mkstemp(&tmp_file, "pack/tmp_bitmap_XXXXXX");
+ int fd = odb_mkstemp(writer->repo->objects, &tmp_file,
+ "pack/tmp_bitmap_XXXXXX");
if (writer->pseudo_merges_nr)
options |= BITMAP_OPT_PSEUDO_MERGES;
diff --git a/pack-write.c b/pack-write.c
index 6b06315f80a..eccdc798e36 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -84,7 +84,8 @@ const char *write_idx_file(struct repository *repo,
} else {
if (!index_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_idx_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_idx_XXXXXX");
index_name = strbuf_detach(&tmp_file, NULL);
} else {
unlink(index_name);
@@ -259,7 +260,8 @@ char *write_rev_file_order(struct repository *repo,
if (flags & WRITE_REV) {
if (!rev_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_rev_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_rev_XXXXXX");
path = strbuf_detach(&tmp_file, NULL);
} else {
unlink(rev_name);
@@ -342,7 +344,7 @@ static char *write_mtimes_file(struct repository *repo,
if (!to_pack)
BUG("cannot call write_mtimes_file with NULL packing_data");
- fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file, "pack/tmp_mtimes_XXXXXX");
mtimes_name = strbuf_detach(&tmp_file, NULL);
f = hashfd(repo->hash_algo, fd, mtimes_name);
@@ -531,7 +533,7 @@ struct hashfile *create_tmp_packfile(struct repository *repo,
struct strbuf tmpname = STRBUF_INIT;
int fd;
- fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmpname, "pack/tmp_pack_XXXXXX");
*pack_tmp_name = strbuf_detach(&tmpname, NULL);
return hashfd(repo->hash_algo, fd, *pack_tmp_name);
}
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 08/17] odb: get rid of `the_repository` when handling alternates
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (6 preceding siblings ...)
2025-06-05 6:46 ` [PATCH v5 07/17] odb: get rid of `the_repository` in `odb_mkstemp()` Patrick Steinhardt
@ 2025-06-05 6:46 ` Patrick Steinhardt
2025-06-30 2:56 ` Justin Tobler
2025-06-05 6:46 ` [PATCH v5 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
` (8 subsequent siblings)
16 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:46 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The functions to manage alternates all depend on `the_repository`.
Refactor them to accept an object database as parameter and adjusting
all callers. The functions are renamed accordingly.
Note that right now the situation is still somewhat weird because we end
up using the path provided by the object store's repository anyway. This
will be adapted over time though so that we instead store the path to
the primary object directory in the object database itself.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/clone.c | 10 +++++----
builtin/fsck.c | 6 +++---
builtin/grep.c | 2 +-
builtin/repack.c | 3 ++-
commit-graph.c | 4 ++--
loose.c | 2 +-
object-file.c | 10 ++++-----
object-name.c | 2 +-
odb.c | 44 ++++++++++++++++++---------------------
odb.h | 53 ++++++++++++++++++++++++++++++++---------------
packfile.c | 4 ++--
submodule.c | 3 ++-
t/helper/test-ref-store.c | 2 +-
tmp-objdir.c | 2 +-
14 files changed, 83 insertions(+), 64 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 1eafeefb48d..3aabdf6570b 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -171,7 +171,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
} else {
struct strbuf sb = STRBUF_INIT;
strbuf_addf(&sb, "%s/objects", ref_git);
- add_to_alternates_file(sb.buf);
+ odb_add_to_alternates_file(the_repository->objects, sb.buf);
strbuf_release(&sb);
}
@@ -212,12 +212,14 @@ static void copy_alternates(struct strbuf *src, const char *src_repo)
if (!line.len || line.buf[0] == '#')
continue;
if (is_absolute_path(line.buf)) {
- add_to_alternates_file(line.buf);
+ odb_add_to_alternates_file(the_repository->objects,
+ line.buf);
continue;
}
abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
if (!normalize_path_copy(abs_path, abs_path))
- add_to_alternates_file(abs_path);
+ odb_add_to_alternates_file(the_repository->objects,
+ abs_path);
else
warning("skipping invalid relative alternate: %s/%s",
src_repo, line.buf);
@@ -352,7 +354,7 @@ static void clone_local(const char *src_repo, const char *dest_repo)
struct strbuf alt = STRBUF_INIT;
get_common_dir(&alt, src_repo);
strbuf_addstr(&alt, "/objects");
- add_to_alternates_file(alt.buf);
+ odb_add_to_alternates_file(the_repository->objects, alt.buf);
strbuf_release(&alt);
} else {
struct strbuf src = STRBUF_INIT;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 9abd7b25580..014aa1344e2 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -997,7 +997,7 @@ int cmd_fsck(int argc,
for_each_packed_object(the_repository,
mark_packed_for_connectivity, NULL, 0);
} else {
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next)
fsck_object_dir(source->path);
@@ -1108,7 +1108,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_commit_graph) {
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
@@ -1126,7 +1126,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_multi_pack_index) {
struct child_process midx_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
diff --git a/builtin/grep.c b/builtin/grep.c
index a1d7ee7af39..336cfcab6fb 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -462,7 +462,7 @@ static int grep_submodule(struct grep_opt *opt,
/*
* NEEDSWORK: repo_read_gitmodules() might call
- * add_to_alternates_memory() via config_from_gitmodules(). This
+ * odb_add_to_alternates_memory() via config_from_gitmodules(). This
* operation causes a race condition with concurrent object readings
* performed by the worker threads. That's why we need obj_read_lock()
* here. It should be removed once it's no longer necessary to add the
diff --git a/builtin/repack.c b/builtin/repack.c
index 16782320058..8145474cf8d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1256,7 +1256,8 @@ int cmd_repack(int argc,
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
die(_(incremental_bitmap_conflict_error));
- if (write_bitmaps && po_args.local && has_alt_odb(the_repository)) {
+ if (write_bitmaps && po_args.local &&
+ odb_has_alternates(the_repository->objects)) {
/*
* When asked to do a local repack, but we have
* packfiles that are inherited from an alternate, then
diff --git a/commit-graph.c b/commit-graph.c
index 6ced5b366e7..59265f89385 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -649,7 +649,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
count = st->st_size / (the_hash_algo->hexsz + 1);
CALLOC_ARRAY(oids, count);
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (i = 0; i < count; i++) {
struct odb_source *source;
@@ -778,7 +778,7 @@ static int prepare_commit_graph(struct repository *r)
if (!commit_graph_compatible(r))
return 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources;
!r->objects->commit_graph && source;
source = source->next)
diff --git a/loose.c b/loose.c
index fab4041c03d..519f5db7935 100644
--- a/loose.c
+++ b/loose.c
@@ -112,7 +112,7 @@ int repo_read_loose_object_map(struct repository *repo)
if (!should_use_loose_object_map(repo))
return 0;
- prepare_alt_odb(repo);
+ odb_prepare_alternates(repo->objects);
for (source = repo->objects->sources; source; source = source->next) {
if (load_one_loose_object_map(repo, source) < 0) {
diff --git a/object-file.c b/object-file.c
index 2d3af8a77c0..04da19a1a3b 100644
--- a/object-file.c
+++ b/object-file.c
@@ -106,7 +106,7 @@ static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
struct odb_source *source;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources->next; source; source = source->next) {
if (check_and_freshen_odb(source, oid, freshen))
return 1;
@@ -205,7 +205,7 @@ static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct odb_source *source;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
*path = odb_loose_path(source, &buf, oid);
if (!lstat(*path, st))
@@ -227,7 +227,7 @@ static int open_loose_object(struct repository *r,
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
*path = odb_loose_path(source, &buf, oid);
fd = git_open(*path);
@@ -246,7 +246,7 @@ static int quick_has_loose(struct repository *r,
{
struct odb_source *source;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
if (oidtree_contains(odb_loose_cache(source, oid), oid))
return 1;
@@ -1439,7 +1439,7 @@ int for_each_loose_object(each_loose_object_fn cb, void *data,
{
struct odb_source *source;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next) {
int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
NULL, data);
diff --git a/object-name.c b/object-name.c
index 544634d0f40..381536e900e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -376,7 +376,7 @@ static int init_object_disambiguation(struct repository *r,
ds->hex_pfx[len] = '\0';
ds->repo = r;
ds->bin_pfx.algo = algo ? hash_algo_by_ptr(algo) : GIT_HASH_UNKNOWN;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
return 0;
}
diff --git a/odb.c b/odb.c
index 73410920a88..42862ef7fe7 100644
--- a/odb.c
+++ b/odb.c
@@ -272,10 +272,11 @@ static void read_info_alternates(struct object_database *odb,
free(path);
}
-void add_to_alternates_file(const char *reference)
+void odb_add_to_alternates_file(struct object_database *odb,
+ const char *reference)
{
struct lock_file lock = LOCK_INIT;
- char *alts = repo_git_path(the_repository, "objects/info/alternates");
+ char *alts = repo_git_path(odb->repo, "objects/info/alternates");
FILE *in, *out;
int found = 0;
@@ -308,22 +309,23 @@ void add_to_alternates_file(const char *reference)
fprintf_or_die(out, "%s\n", reference);
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
- if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository->objects, reference,
+ if (odb->loaded_alternates)
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
free(alts);
}
-void add_to_alternates_memory(const char *reference)
+void odb_add_to_alternates_memory(struct object_database *odb,
+ const char *reference)
{
/*
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(odb);
- link_alt_odb_entries(the_repository->objects, reference,
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
@@ -335,7 +337,7 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
/*
* Make a new primary odb and link the old primary ODB in as an
@@ -379,12 +381,6 @@ void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
free_object_directory(cur_alt);
}
-/*
- * Compute the exact path an alternate is at and returns it. In case of
- * error NULL is returned and the human readable error is added to `err`
- * `path` may be relative and should point to $GIT_DIR.
- * `err` must not be null.
- */
char *compute_alternate_path(const char *path, struct strbuf *err)
{
char *ref_git = NULL;
@@ -455,7 +451,7 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(odb->repo);
+ odb_prepare_alternates(odb);
for (source = odb->sources; source; source = source->next) {
strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
@@ -573,7 +569,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
struct odb_source *alternate;
int r = 0;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
r = fn(alternate, cb);
if (r)
@@ -582,21 +578,21 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
return r;
}
-void prepare_alt_odb(struct repository *r)
+void odb_prepare_alternates(struct object_database *odb)
{
- if (r->objects->loaded_alternates)
+ if (odb->loaded_alternates)
return;
- link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(odb, odb->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r->objects, r->objects->sources->path, 0);
- r->objects->loaded_alternates = 1;
+ read_info_alternates(odb, odb->sources->path, 0);
+ odb->loaded_alternates = 1;
}
-int has_alt_odb(struct repository *r)
+int odb_has_alternates(struct object_database *odb)
{
- prepare_alt_odb(r);
- return !!r->objects->sources->next;
+ odb_prepare_alternates(odb);
+ return !!odb->sources->next;
}
int obj_read_use_lock = 0;
diff --git a/odb.h b/odb.h
index 5de952608f3..eba16929a81 100644
--- a/odb.h
+++ b/odb.h
@@ -13,6 +13,14 @@ struct oidtree;
struct strbuf;
struct repository;
+/*
+ * Compute the exact path an alternate is at and returns it. In case of
+ * error NULL is returned and the human readable error is added to `err`
+ * `path` may be relative and should point to $GIT_DIR.
+ * `err` must not be null.
+ */
+char *compute_alternate_path(const char *path, struct strbuf *err);
+
/*
* The source is the part of the object database that stores the actual
* objects. It thus encapsulates the logic to read and write the specific
@@ -65,27 +73,11 @@ struct odb_source {
char *path;
};
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
-/*
- * 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);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -124,7 +116,7 @@ struct object_database {
/*
* A list of alternate object directories loaded from the environment;
* this should not generally need to be accessed directly, but will
- * populate the "sources" list when prepare_alt_odb() is run.
+ * populate the "sources" list when odb_prepare_alternates() is run.
*/
char *alternate_db;
@@ -209,6 +201,33 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
int odb_mkstemp(struct object_database *odb,
struct strbuf *temp_filename, const char *pattern);
+/*
+ * Prepare alternate object sources for the given database by reading
+ * "objects/info/alternates" and opening the respective sources.
+ */
+void odb_prepare_alternates(struct object_database *odb);
+
+/*
+ * Check whether the object database has any alternates. The primary object
+ * source does not count as alternate.
+ */
+int odb_has_alternates(struct object_database *odb);
+
+/*
+ * Add the directory to the on-disk alternates file; the new entry will also
+ * take effect in the current process.
+ */
+void odb_add_to_alternates_file(struct object_database *odb,
+ const char *dir);
+
+/*
+ * Add the directory to the in-memory list of alternate sources (along with any
+ * recursive alternates it points to), but do not modify the on-disk alternates
+ * file.
+ */
+void odb_add_to_alternates_memory(struct object_database *odb,
+ const char *dir);
+
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,
diff --git a/packfile.c b/packfile.c
index 346c2f9ce90..ac0e29e99b9 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1034,7 +1034,7 @@ static void prepare_packed_git(struct repository *r)
if (r->objects->packed_git_initialized)
return;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
int local = (source == r->objects->sources);
prepare_multi_pack_index_one(r, source->path, local);
@@ -1059,7 +1059,7 @@ void reprepare_packed_git(struct repository *r)
* the lifetime of the process.
*/
r->objects->loaded_alternates = 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next)
odb_clear_loose_cache(source);
diff --git a/submodule.c b/submodule.c
index 9b1018877df..386be234230 100644
--- a/submodule.c
+++ b/submodule.c
@@ -189,7 +189,8 @@ int register_all_submodule_odb_as_alternates(void)
int ret = added_submodule_odb_paths.nr;
for (i = 0; i < added_submodule_odb_paths.nr; i++)
- add_to_alternates_memory(added_submodule_odb_paths.items[i].string);
+ odb_add_to_alternates_memory(the_repository->objects,
+ added_submodule_odb_paths.items[i].string);
if (ret) {
string_list_clear(&added_submodule_odb_paths, 0);
trace2_data_intmax("submodule", the_repository,
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 2920ca59d72..8d9a271845c 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -79,7 +79,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)
if (!repo_submodule_path_append(the_repository,
&sb, gitdir, "objects/"))
die("computing submodule path failed");
- add_to_alternates_memory(sb.buf);
+ odb_add_to_alternates_memory(the_repository->objects, sb.buf);
strbuf_release(&sb);
*refs = repo_get_submodule_ref_store(the_repository, gitdir);
diff --git a/tmp-objdir.c b/tmp-objdir.c
index bef2f917cd2..4120badf5ce 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -304,7 +304,7 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)
void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
{
- add_to_alternates_memory(t->path.buf);
+ odb_add_to_alternates_memory(t->repo->objects, t->path.buf);
}
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v5 08/17] odb: get rid of `the_repository` when handling alternates
2025-06-05 6:46 ` [PATCH v5 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
@ 2025-06-30 2:56 ` Justin Tobler
2025-07-01 12:18 ` Patrick Steinhardt
0 siblings, 1 reply; 166+ messages in thread
From: Justin Tobler @ 2025-06-30 2:56 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On 25/06/05 08:46AM, Patrick Steinhardt wrote:
> The functions to manage alternates all depend on `the_repository`.
> Refactor them to accept an object database as parameter and adjusting
s/parameter and adjusting/a parameter and adjust/
> all callers. The functions are renamed accordingly.
>
> Note that right now the situation is still somewhat weird because we end
> up using the path provided by the object store's repository anyway. This
> will be adapted over time though so that we instead store the path to
> the primary object directory in the object database itself.
Just to clarify, are we walking about the path to the alternate odb? I'm
not quite sure I follow.
The renames and refactors in this patch look good.
-Justin
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
^ permalink raw reply [flat|nested] 166+ messages in thread
* Re: [PATCH v5 08/17] odb: get rid of `the_repository` when handling alternates
2025-06-30 2:56 ` Justin Tobler
@ 2025-07-01 12:18 ` Patrick Steinhardt
0 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:18 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On Sun, Jun 29, 2025 at 09:56:05PM -0500, Justin Tobler wrote:
> On 25/06/05 08:46AM, Patrick Steinhardt wrote:
> > all callers. The functions are renamed accordingly.
> >
> > Note that right now the situation is still somewhat weird because we end
> > up using the path provided by the object store's repository anyway. This
> > will be adapted over time though so that we instead store the path to
> > the primary object directory in the object database itself.
>
> Just to clarify, are we walking about the path to the alternate odb? I'm
> not quite sure I follow.
Yeah, this is phrased a bit weirdly. What I wanted to say is that we
basically end up using `repo_git_path(odb->repo, ...)` anyway, so we
could have just passed in the repository itself.
I'll rephrase the commit message a bit.
Patrick
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v5 09/17] odb: get rid of `the_repository` in `for_each()` functions
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (7 preceding siblings ...)
2025-06-05 6:46 ` [PATCH v5 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
@ 2025-06-05 6:46 ` Patrick Steinhardt
2025-06-05 6:47 ` [PATCH v5 10/17] odb: get rid of `the_repository` when handling the primary source Patrick Steinhardt
` (7 subsequent siblings)
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:46 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
There are a couple of iterator-style functions that execute a callback
for each instance of a given set, all of which currently depend on
`the_repository`. Refactor them to instead take an object database as
parameter so that we can get rid of this dependency.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/count-objects.c | 2 +-
builtin/receive-pack.c | 3 ++-
builtin/submodule--helper.c | 3 ++-
diagnose.c | 2 +-
fetch-pack.c | 3 ++-
odb.c | 36 +++++++++++++++++++-----------------
odb.h | 23 ++++++++++++++++++-----
revision.c | 3 ++-
8 files changed, 47 insertions(+), 28 deletions(-)
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 58e0af433d1..f687647931e 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -159,7 +159,7 @@ int cmd_count_objects(int argc,
printf("prune-packable: %lu\n", packed_loose);
printf("garbage: %lu\n", garbage);
printf("size-garbage: %s\n", garbage_buf.buf);
- foreach_alt_odb(print_alternate, NULL);
+ odb_for_each_alternate(the_repository->objects, print_alternate, NULL);
strbuf_release(&loose_buf);
strbuf_release(&pack_buf);
strbuf_release(&garbage_buf);
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 0f5958c4a66..7ea273d93e4 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -359,7 +359,8 @@ static void write_head_info(void)
refs_for_each_fullref_in(get_main_ref_store(the_repository), "",
exclude_patterns, show_ref_cb, &seen);
- for_each_alternate_ref(show_one_alternate_ref, &seen);
+ odb_for_each_alternate_ref(the_repository->objects,
+ show_one_alternate_ref, &seen);
oidset_clear(&seen);
strvec_clear(&excludes_vector);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 84f7fa53424..7ca483cab52 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1668,7 +1668,8 @@ static void prepare_possible_alternates(const char *sm_name,
die(_("Value '%s' for submodule.alternateErrorStrategy is not recognized"), error_strategy);
if (!strcmp(sm_alternate, "superproject"))
- foreach_alt_odb(add_possible_reference_from_superproject, &sas);
+ odb_for_each_alternate(the_repository->objects,
+ add_possible_reference_from_superproject, &sas);
else if (!strcmp(sm_alternate, "no"))
; /* do nothing */
else
diff --git a/diagnose.c b/diagnose.c
index ad0d5c12465..5092bf80d35 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -229,7 +229,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
dir_file_stats(r->objects->sources, &buf);
- foreach_alt_odb(dir_file_stats, &buf);
+ odb_for_each_alternate(r->objects, dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
strbuf_reset(&buf);
diff --git a/fetch-pack.c b/fetch-pack.c
index cf157f5d7e5..47fa7fa4c49 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -115,7 +115,8 @@ static void for_each_cached_alternate(struct fetch_negotiator *negotiator,
size_t i;
if (!initialized) {
- for_each_alternate_ref(cache_one_alternate, &cache);
+ odb_for_each_alternate_ref(the_repository->objects,
+ cache_one_alternate, &cache);
initialized = 1;
}
diff --git a/odb.c b/odb.c
index 42862ef7fe7..d83f7416e9e 100644
--- a/odb.c
+++ b/odb.c
@@ -494,8 +494,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
}
static void read_alternate_refs(const char *path,
- alternate_ref_fn *cb,
- void *data)
+ odb_for_each_alternate_ref_fn *cb,
+ void *payload)
{
struct child_process cmd = CHILD_PROCESS_INIT;
struct strbuf line = STRBUF_INIT;
@@ -517,7 +517,7 @@ static void read_alternate_refs(const char *path,
break;
}
- cb(&oid, data);
+ cb(&oid, payload);
}
fclose(fh);
@@ -526,16 +526,16 @@ static void read_alternate_refs(const char *path,
}
struct alternate_refs_data {
- alternate_ref_fn *fn;
- void *data;
+ odb_for_each_alternate_ref_fn *fn;
+ void *payload;
};
static int refs_from_alternate_cb(struct odb_source *alternate,
- void *data)
+ void *payload)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
- struct alternate_refs_data *cb = data;
+ struct alternate_refs_data *cb = payload;
if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
@@ -549,29 +549,31 @@ static int refs_from_alternate_cb(struct odb_source *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->data);
+ read_alternate_refs(path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
return 0;
}
-void for_each_alternate_ref(alternate_ref_fn fn, void *data)
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload)
{
- struct alternate_refs_data cb;
- cb.fn = fn;
- cb.data = data;
- foreach_alt_odb(refs_from_alternate_cb, &cb);
+ struct alternate_refs_data data;
+ data.fn = cb;
+ data.payload = payload;
+ odb_for_each_alternate(odb, refs_from_alternate_cb, &data);
}
-int foreach_alt_odb(alt_odb_fn fn, void *cb)
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload)
{
struct odb_source *alternate;
int r = 0;
- odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
- r = fn(alternate, cb);
+ odb_prepare_alternates(odb);
+ for (alternate = odb->sources->next; alternate; alternate = alternate->next) {
+ r = cb(alternate, payload);
if (r)
break;
}
diff --git a/odb.h b/odb.h
index eba16929a81..7e65e9707c1 100644
--- a/odb.h
+++ b/odb.h
@@ -73,11 +73,6 @@ struct odb_source {
char *path;
};
-typedef int alt_odb_fn(struct odb_source *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -192,6 +187,24 @@ void odb_clear(struct object_database *o);
*/
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+/*
+ * Iterate through all alternates of the database and execute the provided
+ * callback function for each of them. Stop iterating once the callback
+ * function returns a non-zero value, in which case the value is bubbled up
+ * from the callback.
+ */
+typedef int odb_for_each_alternate_fn(struct odb_source *, void *);
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload);
+
+/*
+ * Iterate through all alternates of the database and yield their respective
+ * references.
+ */
+typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload);
+
/*
* Create a temporary file rooted in the primary alternate's directory, or die
* on failure. The filename is taken from "pattern", which should have the
diff --git a/revision.c b/revision.c
index cdefe7d6e48..b0364f556ee 100644
--- a/revision.c
+++ b/revision.c
@@ -1907,7 +1907,8 @@ static void add_alternate_refs_to_pending(struct rev_info *revs,
struct add_alternate_refs_data data;
data.revs = revs;
data.flags = flags;
- for_each_alternate_ref(add_one_alternate_ref, &data);
+ odb_for_each_alternate_ref(the_repository->objects,
+ add_one_alternate_ref, &data);
}
static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 10/17] odb: get rid of `the_repository` when handling the primary source
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (8 preceding siblings ...)
2025-06-05 6:46 ` [PATCH v5 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
@ 2025-06-05 6:47 ` Patrick Steinhardt
2025-06-05 6:47 ` [PATCH v5 11/17] odb: get rid of `the_repository` when handling submodule sources Patrick Steinhardt
` (6 subsequent siblings)
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:47 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The functions `set_temporary_primary_odb()` and `restore_primary_odb()`
are responsible for managing a temporary primary source for the
database. Both of these functions implicitly rely on `the_repository`.
Refactor them to instead take an explicit object database parameter as
argument and adjust callers. Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 27 +++++++++++++++------------
odb.h | 26 +++++++++++++++-----------
tmp-objdir.c | 10 ++++++----
3 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/odb.c b/odb.c
index d83f7416e9e..b154e91953d 100644
--- a/odb.c
+++ b/odb.c
@@ -329,7 +329,8 @@ void odb_add_to_alternates_memory(struct object_database *odb,
'\n', NULL, 0);
}
-struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
+ const char *dir, int will_destroy)
{
struct odb_source *source;
@@ -337,14 +338,14 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- odb_prepare_alternates(the_repository->objects);
+ odb_prepare_alternates(odb);
/*
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
source = xcalloc(1, sizeof(*source));
- source->odb = the_repository->objects;
+ source->odb = odb;
source->path = xstrdup(dir);
/*
@@ -353,8 +354,8 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
*/
source->disable_ref_updates = 1;
source->will_destroy = will_destroy;
- source->next = the_repository->objects->sources;
- the_repository->objects->sources = source;
+ source->next = odb->sources;
+ odb->sources = source;
return source->next;
}
@@ -366,19 +367,21 @@ static void free_object_directory(struct odb_source *source)
free(source);
}
-void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
+void odb_restore_primary_source(struct object_database *odb,
+ struct odb_source *restore_source,
+ const char *old_path)
{
- struct odb_source *cur_alt = the_repository->objects->sources;
+ struct odb_source *cur_source = odb->sources;
- if (strcmp(old_path, cur_alt->path))
+ if (strcmp(old_path, cur_source->path))
BUG("expected %s as primary object store; found %s",
- old_path, cur_alt->path);
+ old_path, cur_source->path);
- if (cur_alt->next != restore_alt)
+ if (cur_source->next != restore_source)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->sources = restore_alt;
- free_object_directory(cur_alt);
+ odb->sources = restore_source;
+ free_object_directory(cur_source);
}
char *compute_alternate_path(const char *path, struct strbuf *err)
diff --git a/odb.h b/odb.h
index 7e65e9707c1..4e2d1004f8a 100644
--- a/odb.h
+++ b/odb.h
@@ -73,17 +73,6 @@ struct odb_source {
char *path;
};
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy);
-
-/*
- * Restore a previous ODB replaced by set_temporary_main_odb.
- */
-void restore_primary_odb(struct odb_source *restore_alternate, const char *old_path);
-
struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
@@ -187,6 +176,21 @@ void odb_clear(struct object_database *o);
*/
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary source.
+ */
+struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
+ const char *dir, int will_destroy);
+
+/*
+ * Restore the primary source that was previously replaced by
+ * `odb_set_temporary_primary_source()`.
+ */
+void odb_restore_primary_source(struct object_database *odb,
+ struct odb_source *restore_source,
+ const char *old_path);
+
/*
* Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 4120badf5ce..ae01eae9c41 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -47,7 +47,7 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
the_tmp_objdir = NULL;
if (t->prev_source)
- restore_primary_odb(t->prev_source, t->path.buf);
+ odb_restore_primary_source(t->repo->objects, t->prev_source, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -279,7 +279,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (t->prev_source) {
if (t->repo->objects->sources->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_source, t->path.buf);
+ odb_restore_primary_source(t->repo->objects, t->prev_source, t->path.buf);
t->prev_source = NULL;
}
@@ -311,7 +311,8 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
if (t->prev_source)
BUG("the primary object database is already replaced");
- t->prev_source = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_source = odb_set_temporary_primary_source(t->repo->objects,
+ t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
@@ -320,7 +321,8 @@ struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
if (!the_tmp_objdir || !the_tmp_objdir->prev_source)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
+ odb_restore_primary_source(the_tmp_objdir->repo->objects,
+ the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
the_tmp_objdir->prev_source = NULL;
return the_tmp_objdir;
}
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 11/17] odb: get rid of `the_repository` when handling submodule sources
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (9 preceding siblings ...)
2025-06-05 6:47 ` [PATCH v5 10/17] odb: get rid of `the_repository` when handling the primary source Patrick Steinhardt
@ 2025-06-05 6:47 ` Patrick Steinhardt
2025-06-05 6:47 ` [PATCH v5 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
` (5 subsequent siblings)
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:47 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The "--recursive" flag for git-grep(1) allows users to grep for a string
across submodule boundaries. To make this work we add each submodule's
object sources to our own object database so that the objects can be
accessed directly.
The infrastructure for this depends on a global string list of submodule
paths. The caller is expected to call `add_submodule_odb_by_path()` for
each source and the object database will then eventually register all
submodule sources via `do_oid_object_info_extended()` in case it isn't
able to look up a specific object.
This reliance on global state is of course suboptimal with regards to
our libification efforts.
Refactor the logic so that the list of submodule sources is instead
tracked in the object database itself. This allows us to lose the
condition of `r == the_repository` before registering submodule sources
as we only ever add submodule sources to `the_repository` anyway. As
such, behaviour before and after this refactoring should always be the
same.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/grep.c | 3 ++-
odb.c | 37 +++++++++++++++++++++++++++++++------
odb.h | 15 +++++++++++++++
submodule-config.c | 3 ++-
submodule.c | 26 --------------------------
submodule.h | 9 ---------
6 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 336cfcab6fb..cfcf916bce1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,8 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->sources->path);
+ odb_add_submodule_source_by_path(the_repository->objects,
+ subrepo->objects->sources->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/odb.c b/odb.c
index b154e91953d..decf261dec6 100644
--- a/odb.c
+++ b/odb.c
@@ -24,6 +24,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "submodule.h"
+#include "trace2.h"
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
@@ -469,6 +470,12 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
return source;
}
+void odb_add_submodule_source_by_path(struct object_database *odb,
+ const char *path)
+{
+ string_list_insert(&odb->submodule_source_paths, path);
+}
+
static void fill_alternate_refs_command(struct child_process *cmd,
const char *repo_path)
{
@@ -623,6 +630,23 @@ void disable_obj_read_lock(void)
int fetch_if_missing = 1;
+static int register_all_submodule_sources(struct object_database *odb)
+{
+ int ret = odb->submodule_source_paths.nr;
+
+ for (size_t i = 0; i < odb->submodule_source_paths.nr; i++)
+ odb_add_to_alternates_memory(odb,
+ odb->submodule_source_paths.items[i].string);
+ if (ret) {
+ string_list_clear(&odb->submodule_source_paths, 0);
+ trace2_data_intmax("submodule", odb->repo,
+ "register_all_submodule_sources/registered", ret);
+ if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
+ BUG("register_all_submodule_sources() called");
+ }
+ return ret;
+}
+
static int do_oid_object_info_extended(struct repository *r,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
@@ -676,13 +700,12 @@ static int do_oid_object_info_extended(struct repository *r,
}
/*
- * If r is the_repository, this might be an attempt at
- * accessing a submodule object as if it were in the_repository
- * (having called add_submodule_odb() on that submodule's ODB).
- * If any such ODBs exist, register them and try again.
+ * This might be an attempt at accessing a submodule object as
+ * if it were in main object store (having called
+ * `odb_add_submodule_source_by_path()` on that submodule's
+ * ODB). If any such ODBs exist, register them and try again.
*/
- if (r == the_repository &&
- register_all_submodule_odb_as_alternates())
+ if (register_all_submodule_sources(r->objects))
/* We added some alternates; retry */
continue;
@@ -968,6 +991,7 @@ struct object_database *odb_new(struct repository *repo)
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
+ string_list_init_dup(&o->submodule_source_paths);
return o;
}
@@ -1017,4 +1041,5 @@ void odb_clear(struct object_database *o)
o->packed_git = NULL;
hashmap_clear(&o->pack_map);
+ string_list_clear(&o->submodule_source_paths, 0);
}
diff --git a/odb.h b/odb.h
index 4e2d1004f8a..0ea9d4faa70 100644
--- a/odb.h
+++ b/odb.h
@@ -6,6 +6,7 @@
#include "list.h"
#include "oidset.h"
#include "oidmap.h"
+#include "string-list.h"
#include "thread-utils.h"
struct oidmap;
@@ -165,6 +166,12 @@ struct object_database {
* packs.
*/
unsigned packed_git_initialized : 1;
+
+ /*
+ * Submodule source paths that will be added as additional sources to
+ * allow lookup of submodule objects via the main object database.
+ */
+ struct string_list submodule_source_paths;
};
struct object_database *odb_new(struct repository *repo);
@@ -191,6 +198,14 @@ void odb_restore_primary_source(struct object_database *odb,
struct odb_source *restore_source,
const char *old_path);
+/*
+ * Call odb_add_submodule_source_by_path() to add the submodule at the given
+ * path to a list. The object stores of all submodules in that list will be
+ * added as additional sources in the object store when looking up objects.
+ */
+void odb_add_submodule_source_by_path(struct object_database *odb,
+ const char *path);
+
/*
* Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/submodule-config.c b/submodule-config.c
index 9c80f9f7b66..a9f72107888 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,8 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->sources->path);
+ odb_add_submodule_source_by_path(the_repository->objects,
+ repo->objects->sources->path);
} else {
goto out;
}
diff --git a/submodule.c b/submodule.c
index 386be234230..788c9e55ed3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -31,7 +31,6 @@
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
-#include "trace2.h"
static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
static int initialized_fetch_ref_tips;
@@ -176,31 +175,6 @@ void stage_updated_gitmodules(struct index_state *istate)
die(_("staging updated .gitmodules failed"));
}
-static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_DUP;
-
-void add_submodule_odb_by_path(const char *path)
-{
- string_list_insert(&added_submodule_odb_paths, path);
-}
-
-int register_all_submodule_odb_as_alternates(void)
-{
- int i;
- int ret = added_submodule_odb_paths.nr;
-
- for (i = 0; i < added_submodule_odb_paths.nr; i++)
- odb_add_to_alternates_memory(the_repository->objects,
- added_submodule_odb_paths.items[i].string);
- if (ret) {
- string_list_clear(&added_submodule_odb_paths, 0);
- trace2_data_intmax("submodule", the_repository,
- "register_all_submodule_odb_as_alternates/registered", ret);
- if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
- BUG("register_all_submodule_odb_as_alternates() called");
- }
- return ret;
-}
-
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
const char *path)
{
diff --git a/submodule.h b/submodule.h
index db980c1d083..b10e16e6c06 100644
--- a/submodule.h
+++ b/submodule.h
@@ -104,15 +104,6 @@ int submodule_uses_gitfile(const char *path);
#define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
int bad_to_remove_submodule(const char *path, unsigned flags);
-/*
- * Call add_submodule_odb_by_path() to add the submodule at the given
- * path to a list. When register_all_submodule_odb_as_alternates() is
- * called, the object stores of all submodules in that list will be
- * added as alternates in the_repository.
- */
-void add_submodule_odb_by_path(const char *path);
-int register_all_submodule_odb_as_alternates(void);
-
/*
* Checks if there are submodule changes in a..b. If a is the null OID,
* checks b and all its ancestors instead.
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 12/17] odb: trivial refactorings to get rid of `the_repository`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (10 preceding siblings ...)
2025-06-05 6:47 ` [PATCH v5 11/17] odb: get rid of `the_repository` when handling submodule sources Patrick Steinhardt
@ 2025-06-05 6:47 ` Patrick Steinhardt
2025-06-05 6:47 ` [PATCH v5 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
` (4 subsequent siblings)
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:47 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
All of the external functions provided by the object database subsystem
don't depend on `the_repository` anymore, but some internal functions
still do. Refactor those cases by plumbing through the repository that
owns the object database.
This change allows us to get rid of the `USE_THE_REPOSITORY_VARIABLE`
preprocessor define.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/odb.c b/odb.c
index decf261dec6..d6ca5b92ab8 100644
--- a/odb.c
+++ b/odb.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "abspath.h"
#include "commit-graph.h"
@@ -476,12 +474,13 @@ void odb_add_submodule_source_by_path(struct object_database *odb,
string_list_insert(&odb->submodule_source_paths, path);
}
-static void fill_alternate_refs_command(struct child_process *cmd,
+static void fill_alternate_refs_command(struct repository *repo,
+ struct child_process *cmd,
const char *repo_path)
{
const char *value;
- if (!git_config_get_value("core.alternateRefsCommand", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsCommand", &value)) {
cmd->use_shell = 1;
strvec_push(&cmd->args, value);
@@ -493,7 +492,7 @@ static void fill_alternate_refs_command(struct child_process *cmd,
strvec_push(&cmd->args, "for-each-ref");
strvec_push(&cmd->args, "--format=%(objectname)");
- if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsPrefixes", &value)) {
strvec_push(&cmd->args, "--");
strvec_split(&cmd->args, value);
}
@@ -503,7 +502,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
cmd->out = -1;
}
-static void read_alternate_refs(const char *path,
+static void read_alternate_refs(struct repository *repo,
+ const char *path,
odb_for_each_alternate_ref_fn *cb,
void *payload)
{
@@ -511,7 +511,7 @@ static void read_alternate_refs(const char *path,
struct strbuf line = STRBUF_INIT;
FILE *fh;
- fill_alternate_refs_command(&cmd, path);
+ fill_alternate_refs_command(repo, &cmd, path);
if (start_command(&cmd))
return;
@@ -521,7 +521,7 @@ static void read_alternate_refs(const char *path,
struct object_id oid;
const char *p;
- if (parse_oid_hex(line.buf, &oid, &p) || *p) {
+ if (parse_oid_hex_algop(line.buf, &oid, &p, repo->hash_algo) || *p) {
warning(_("invalid line while parsing alternate refs: %s"),
line.buf);
break;
@@ -559,7 +559,7 @@ static int refs_from_alternate_cb(struct odb_source *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->payload);
+ read_alternate_refs(alternate->odb->repo, path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, the_repository->hash_algo);
+ oidclr(oi->delta_base_oid, r->hash_algo);
if (oi->contentp)
*oi->contentp = xmemdupz(co->buf, co->size);
oi->whence = OI_CACHED;
@@ -763,10 +763,10 @@ static int oid_object_info_convert(struct repository *r,
void *content;
int ret;
- if (repo_oid_to_algop(r, input_oid, the_hash_algo, &oid)) {
+ if (repo_oid_to_algop(r, input_oid, r->hash_algo, &oid)) {
if (do_die)
die(_("missing mapping of %s to %s"),
- oid_to_hex(input_oid), the_hash_algo->name);
+ oid_to_hex(input_oid), r->hash_algo->name);
return -1;
}
@@ -797,8 +797,8 @@ static int oid_object_info_convert(struct repository *r,
struct strbuf outbuf = STRBUF_INIT;
if (type != OBJ_BLOB) {
- ret = convert_object_file(the_repository, &outbuf,
- the_hash_algo, input_algo,
+ ret = convert_object_file(r, &outbuf,
+ r->hash_algo, input_algo,
content, size, type, !do_die);
free(content);
if (ret == -1)
@@ -944,9 +944,9 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + the_hash_algo->hexsz > isize ||
+ if (ref_length + r->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
free(buffer);
return NULL;
}
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 13/17] odb: rename `oid_object_info()`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (11 preceding siblings ...)
2025-06-05 6:47 ` [PATCH v5 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
@ 2025-06-05 6:47 ` Patrick Steinhardt
2025-06-05 6:47 ` [PATCH v5 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
` (3 subsequent siblings)
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:47 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `oid_object_info()` to `odb_read_object_info()` as well as their
`_extended()` variant to match other functions related to the object
database and our modern coding guidelines.
Introduce compatibility wrappers so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
archive.c | 2 +-
blame.c | 4 +--
builtin/blame.c | 4 +--
builtin/cat-file.c | 26 ++++++++++---------
builtin/describe.c | 3 ++-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 17 ++++++------
builtin/fsck.c | 7 ++---
builtin/gc.c | 2 +-
builtin/grep.c | 2 +-
builtin/index-pack.c | 13 +++++-----
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 4 +--
builtin/mktree.c | 8 +++---
builtin/pack-objects.c | 30 ++++++++++++----------
builtin/prune.c | 4 +--
builtin/repack.c | 2 +-
builtin/replace.c | 10 ++++----
builtin/rev-list.c | 6 +++--
builtin/tag.c | 4 +--
builtin/unpack-objects.c | 2 +-
commit-graph.c | 2 +-
commit.c | 3 ++-
diff.c | 18 ++++++-------
fetch-pack.c | 4 +--
list-objects-filter.c | 2 +-
log-tree.c | 2 +-
merge-ort.c | 4 +--
object-file.c | 2 +-
object-file.h | 2 +-
object-name.c | 16 ++++++------
object.c | 6 ++---
odb.c | 60 ++++++++++++++++++++++---------------------
odb.h | 46 +++++++++++++++++++++++++++------
pack-bitmap-write.c | 4 +--
pack-bitmap.c | 8 +++---
packfile.c | 5 ++--
promisor-remote.c | 4 +--
protocol-caps.c | 2 +-
reachable.c | 2 +-
read-cache.c | 6 ++---
ref-filter.c | 4 +--
remote.c | 5 ++--
sequencer.c | 5 ++--
streaming.c | 8 +++---
submodule.c | 5 ++--
t/helper/test-partial-clone.c | 2 +-
tag.c | 2 +-
48 files changed, 213 insertions(+), 170 deletions(-)
diff --git a/archive.c b/archive.c
index 7fa2cc2596a..f2511d530d5 100644
--- a/archive.c
+++ b/archive.c
@@ -215,7 +215,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
/* Stream it? */
if (S_ISREG(mode) && !args->convert &&
- oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
+ odb_read_object_info(args->repo->objects, oid, &size) == OBJ_BLOB &&
size > repo_settings_get_big_file_threshold(the_repository))
return write_entry(args, oid, path.buf, path.len, mode, NULL, size);
diff --git a/blame.c b/blame.c
index 0ceea080a80..97db3355af4 100644
--- a/blame.c
+++ b/blame.c
@@ -116,7 +116,7 @@ static void verify_working_tree_path(struct repository *r,
unsigned short mode;
if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
- oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
+ odb_read_object_info(r->objects, &blob_oid, NULL) == OBJ_BLOB)
return;
}
@@ -1245,7 +1245,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
return 0;
if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
goto error_out;
- if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
+ if (odb_read_object_info(r->objects, &origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out;
return 0;
error_out:
diff --git a/builtin/blame.c b/builtin/blame.c
index 15eda60af90..91586e6852b 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -837,7 +837,7 @@ static int is_a_rev(const char *name)
if (repo_get_oid(the_repository, name, &oid))
return 0;
- return OBJ_NONE < oid_object_info(the_repository, &oid, NULL);
+ return OBJ_NONE < odb_read_object_info(the_repository->objects, &oid, NULL);
}
static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
@@ -848,7 +848,7 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
oidcpy(&oid, oid_ret);
while (1) {
struct object *obj;
- int kind = oid_object_info(r, &oid, NULL);
+ int kind = odb_read_object_info(r->objects, &oid, NULL);
if (kind == OBJ_COMMIT) {
oidcpy(oid_ret, &oid);
return 0;
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index f3a925a8183..f7595fdb04e 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -132,7 +132,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
switch (opt) {
case 't':
oi.typep = &type;
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
printf("%s\n", type_name(type));
ret = 0;
@@ -146,7 +146,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
oi.contentp = (void**)&buf;
}
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
@@ -180,7 +180,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
/* else fallthrough */
case 'p':
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("Not a valid object name %s", obj_name);
@@ -217,7 +217,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
if (exp_type_id == OBJ_BLOB) {
struct object_id blob_oid;
- if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
+ if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_TAG) {
char *buffer = repo_read_object_file(the_repository,
&oid,
&type,
@@ -235,7 +236,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
} else
oidcpy(&blob_oid, &oid);
- if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB) {
+ if (odb_read_object_info(the_repository->objects,
+ &blob_oid, NULL) == OBJ_BLOB) {
ret = stream_blob(&blob_oid);
goto cleanup;
}
@@ -294,7 +296,7 @@ struct expand_data {
/*
* After a mark_query run, this object_info is set up to be
- * passed to oid_object_info_extended. It will point to the data
+ * passed to odb_read_object_info_extended. It will point to the data
* elements above, so you can retrieve the response from there.
*/
struct object_info info;
@@ -484,12 +486,12 @@ static void batch_object_write(const char *obj_name,
data->info.sizep = &data->size;
if (pack)
- ret = packed_object_info(the_repository, pack, offset,
- &data->info);
+ ret = packed_object_info(the_repository, pack,
+ offset, &data->info);
else
- ret = oid_object_info_extended(the_repository,
- &data->oid, &data->info,
- OBJECT_INFO_LOOKUP_REPLACE);
+ ret = odb_read_object_info_extended(the_repository->objects,
+ &data->oid, &data->info,
+ OBJECT_INFO_LOOKUP_REPLACE);
if (ret < 0) {
report_object_status(opt, obj_name, &data->oid, "missing");
return;
@@ -872,7 +874,7 @@ static int batch_objects(struct batch_options *opt)
/*
* Expand once with our special mark_query flag, which will prime the
- * object_info to be handed to oid_object_info_extended for each
+ * object_info to be handed to odb_read_object_info_extended for each
* object.
*/
memset(&data, 0, sizeof(data));
diff --git a/builtin/describe.c b/builtin/describe.c
index 96cb68e5e5d..fbf305d7624 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -552,7 +552,8 @@ static void describe(const char *arg, int last_one)
if (cmit)
describe_commit(&oid, &sb);
- else if (oid_object_info(the_repository, &oid, NULL) == OBJ_BLOB)
+ else if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_BLOB)
describe_blob(oid, &sb);
else
die(_("%s is neither a commit nor blob"), arg);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 0505f289a94..6c93cf0a8aa 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -1200,7 +1200,7 @@ static void import_marks(char *input_file, int check_exists)
if (last_idnum < mark)
last_idnum = mark;
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(&oid));
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 413304db9b5..2718376f2c9 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1756,8 +1756,8 @@ static void insert_object_entry(struct mark_set **s, struct object_id *oid, uint
struct object_entry *e;
e = find_object(oid);
if (!e) {
- enum object_type type = oid_object_info(the_repository,
- oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
e = insert_object(oid);
@@ -2416,8 +2416,8 @@ static void file_change_m(const char *p, struct branch *b)
enum object_type expected = S_ISDIR(mode) ?
OBJ_TREE: OBJ_BLOB;
enum object_type type = oe ? oe->type :
- oid_object_info(the_repository, &oid,
- NULL);
+ odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("%s not found: %s",
S_ISDIR(mode) ? "Tree" : "Blob",
@@ -2553,7 +2553,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
die("Not a blob (actually a %s): %s",
type_name(oe->type), command_buf.buf);
} else if (!is_null_oid(&oid)) {
- enum object_type type = oid_object_info(the_repository, &oid,
+ enum object_type type = odb_read_object_info(the_repository->objects, &oid,
NULL);
if (type < 0)
die("Blob not found: %s", command_buf.buf);
@@ -2895,7 +2895,8 @@ static void parse_new_tag(const char *arg)
} else if (!repo_get_oid(the_repository, from, &oid)) {
struct object_entry *oe = find_object(&oid);
if (!oe) {
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("Not a valid object: %s", from);
} else
@@ -3085,8 +3086,8 @@ static struct object_entry *dereference(struct object_entry *oe,
const unsigned hexsz = the_hash_algo->hexsz;
if (!oe) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
/* cache it! */
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 014aa1344e2..6e3465b0266 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -71,7 +71,8 @@ static const char *printable_type(const struct object_id *oid,
const char *ret;
if (type == OBJ_NONE)
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
ret = type_name(type);
if (!ret)
@@ -232,8 +233,8 @@ static void mark_unreachable_referents(const struct object_id *oid)
* (and we want to avoid parsing blobs).
*/
if (obj->type == OBJ_NONE) {
- enum object_type type = oid_object_info(the_repository,
- &obj->oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ &obj->oid, NULL);
if (type > 0)
object_as_type(obj, type, 0);
}
diff --git a/builtin/gc.c b/builtin/gc.c
index 50a09eb07e3..ff551fab439 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1080,7 +1080,7 @@ static int dfs_on_ref(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
commit = lookup_commit(the_repository, oid);
diff --git a/builtin/grep.c b/builtin/grep.c
index cfcf916bce1..1435d462cd1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -520,7 +520,7 @@ static int grep_submodule(struct grep_opt *opt,
struct strbuf base = STRBUF_INIT;
obj_read_lock();
- object_type = oid_object_info(subrepo, oid, NULL);
+ object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
data = read_object_with_reference(subrepo,
oid, OBJ_TREE,
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 4d4d989eb1a..d0b16908122 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -260,7 +260,8 @@ static unsigned check_object(struct object *obj)
if (!(obj->flags & FLAG_CHECKED)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects,
+ &obj->oid, &size);
if (type <= 0)
die(_("did not receive expected object %s"),
oid_to_hex(&obj->oid));
@@ -908,7 +909,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
enum object_type has_type;
unsigned long has_size;
read_lock();
- has_type = oid_object_info(the_repository, oid, &has_size);
+ has_type = odb_read_object_info(the_repository->objects, oid, &has_size);
if (has_type < 0)
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
@@ -1501,9 +1502,9 @@ static void fix_unresolved_deltas(struct hashfile *f)
struct oid_array to_fetch = OID_ARRAY_INIT;
for (i = 0; i < nr_ref_deltas; i++) {
struct ref_delta_entry *d = sorted_by_pos[i];
- if (!oid_object_info_extended(the_repository, &d->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &d->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &d->oid);
}
@@ -1829,7 +1830,7 @@ static void repack_local_links(void)
oidset_iter_init(&outgoing_links, &iter);
while ((oid = oidset_iter_next(&iter))) {
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info, 0))
/* Missing; assume it is a promisor object */
continue;
if (info.whence == OI_PACKED && info.u.packed.pack->pack_promisor)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 821339b07d4..ff975e7be06 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -251,7 +251,7 @@ static void expand_objectsize(struct repository *repo, struct strbuf *line,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(repo, oid, &size) < 0)
+ if (odb_read_object_info(repo->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 62b6fd58c16..4d616dd5282 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -27,7 +27,7 @@ static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
@@ -217,7 +217,7 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base,
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
+ if (odb_read_object_info(the_repository->objects, oid, &size) == OBJ_BAD)
xsnprintf(size_text, sizeof(size_text), "BAD");
else
xsnprintf(size_text, sizeof(size_text),
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 016b0e5b224..81df7f6099f 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -124,10 +124,10 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
/* Check the type of object identified by oid without fetching objects */
oi.typep = &obj_type;
- if (oid_object_info_extended(the_repository, &oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_QUICK |
- OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_QUICK |
+ OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
obj_type = -1;
if (obj_type < 0) {
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 99b63cb0980..da35d684081 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2154,10 +2154,10 @@ static void prefetch_to_pack(uint32_t object_index_start) {
for (i = object_index_start; i < to_pack.nr_objects; i++) {
struct object_entry *entry = to_pack.objects + i;
- if (!oid_object_info_extended(the_repository,
- &entry->idx.oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &entry->idx.oid,
+ NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &entry->idx.oid);
}
@@ -2298,19 +2298,19 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
/*
* No choice but to fall back to the recursive delta walk
- * with oid_object_info() to find about the object type
+ * with odb_read_object_info() to find about the object type
* at this point...
*/
give_up:
unuse_pack(&w_curs);
}
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
if (repo_has_promisor_remote(the_repository)) {
prefetch_to_pack(object_index);
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
type = -1;
} else {
type = -1;
@@ -2384,12 +2384,13 @@ static void drop_reused_delta(struct object_entry *entry)
if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
/*
* We failed to get the info from this pack for some reason;
- * fall back to oid_object_info, which may find another copy.
+ * fall back to odb_read_object_info, which may find another copy.
* And if that fails, the error will be recorded in oe_type(entry)
* and dealt with in prepare_pack().
*/
oe_set_type(entry,
- oid_object_info(the_repository, &entry->idx.oid, &size));
+ odb_read_object_info(the_repository->objects,
+ &entry->idx.oid, &size));
} else {
oe_set_type(entry, type);
}
@@ -2677,7 +2678,8 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
packing_data_lock(&to_pack);
- if (oid_object_info(the_repository, &e->idx.oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects,
+ &e->idx.oid, &size) < 0)
die(_("unable to get size of %s"),
oid_to_hex(&e->idx.oid));
packing_data_unlock(&to_pack);
@@ -4063,7 +4065,7 @@ static void add_objects_in_unpacked_packs(void)
static int add_loose_object(const struct object_id *oid, const char *path,
void *data UNUSED)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0) {
warning(_("loose object at %s could not be examined"), path);
@@ -4449,7 +4451,7 @@ static int option_parse_cruft_expiration(const struct option *opt UNUSED,
static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED)
{
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, &obj->oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0))
BUG("should_include_obj should only be called on existing objects");
return info.whence != OI_PACKED || !info.u.packed.pack->pack_promisor;
}
diff --git a/builtin/prune.c b/builtin/prune.c
index 7bbfb14c2be..339017c7ccf 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -99,8 +99,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
if (st.st_mtime > expire)
return 0;
if (show_only || verbose) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? type_name(type) : "unknown");
}
diff --git a/builtin/repack.c b/builtin/repack.c
index 8145474cf8d..a89c2b704fb 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -707,7 +707,7 @@ static int midx_snapshot_ref_one(const char *refname UNUSED,
if (oidset_insert(&data->seen, oid))
return 0; /* already seen */
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
fprintf(data->f->fp, "%s%s\n", data->preferred ? "+" : "",
diff --git a/builtin/replace.c b/builtin/replace.c
index 11c7e2d4c0c..5ff2ab723cb 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -65,8 +65,8 @@ static int show_reference(const char *refname,
if (repo_get_oid(data->repo, refname, &object))
return error(_("failed to resolve '%s' as a valid ref"), refname);
- obj_type = oid_object_info(data->repo, &object, NULL);
- repl_type = oid_object_info(data->repo, oid, NULL);
+ obj_type = odb_read_object_info(data->repo->objects, &object, NULL);
+ repl_type = odb_read_object_info(data->repo->objects, oid, NULL);
printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
oid_to_hex(oid), type_name(repl_type));
@@ -185,8 +185,8 @@ static int replace_object_oid(const char *object_ref,
struct strbuf err = STRBUF_INIT;
int res = 0;
- obj_type = oid_object_info(the_repository, object, NULL);
- repl_type = oid_object_info(the_repository, repl, NULL);
+ obj_type = odb_read_object_info(the_repository->objects, object, NULL);
+ repl_type = odb_read_object_info(the_repository->objects, repl, NULL);
if (!force && obj_type != repl_type)
return error(_("Objects must be of the same type.\n"
"'%s' points to a replaced object of type '%s'\n"
@@ -334,7 +334,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
if (repo_get_oid(the_repository, object_ref, &old_oid) < 0)
return error(_("not a valid object name: '%s'"), object_ref);
- type = oid_object_info(the_repository, &old_oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &old_oid, NULL);
if (type < 0)
return error(_("unable to get object type for %s"),
oid_to_hex(&old_oid));
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 0ee37a32cb2..4d0c460f186 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -110,7 +110,8 @@ static off_t get_object_disk_usage(struct object *obj)
off_t size;
struct object_info oi = OBJECT_INFO_INIT;
oi.disk_sizep = &size;
- if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid));
return size;
}
@@ -346,7 +347,8 @@ static void show_commit(struct commit *commit, void *data)
static int finish_object(struct object *obj, const char *name, void *cb_data)
{
struct rev_list_info *info = cb_data;
- if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, NULL, 0) < 0) {
finish_object__ma(obj, name);
return 1;
}
diff --git a/builtin/tag.c b/builtin/tag.c
index cf2ea4b4993..e0b27396c6b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -304,7 +304,7 @@ static void create_tag(const struct object_id *object, const char *object_ref,
struct strbuf header = STRBUF_INIT;
int should_edit;
- type = oid_object_info(the_repository, object, NULL);
+ type = odb_read_object_info(the_repository->objects, object, NULL);
if (type <= OBJ_NONE)
die(_("bad object type."));
@@ -401,7 +401,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
}
strbuf_addstr(sb, " (");
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
switch (type) {
default:
strbuf_addstr(sb, "object of unknown type");
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 7bf395eec84..405e78bc592 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -232,7 +232,7 @@ static int check_object(struct object *obj, enum object_type type,
if (!(obj->flags & FLAG_OPEN)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects, &obj->oid, &size);
if (type != obj->type || type <= 0)
die("object of unexpected type");
obj->flags |= FLAG_WRITTEN;
diff --git a/commit-graph.c b/commit-graph.c
index 59265f89385..5f482d3377f 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1862,7 +1862,7 @@ static int add_ref_to_set(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) == OBJ_COMMIT)
oidset_insert(data->commits, oid);
display_progress(data->progress, oidset_size(data->commits));
diff --git a/commit.c b/commit.c
index aa65183d8b6..d4aa9c7a5f8 100644
--- a/commit.c
+++ b/commit.c
@@ -585,7 +585,8 @@ int repo_parse_commit_internal(struct repository *r,
return 0;
}
- if (oid_object_info_extended(r, &item->object.oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(r->objects, &item->object.oid,
+ &oi, flags) < 0)
return quiet_on_missing ? -1 :
error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/diff.c b/diff.c
index 3af108115b3..dca87e164fb 100644
--- a/diff.c
+++ b/diff.c
@@ -4230,14 +4230,14 @@ int diff_populate_filespec(struct repository *r,
info.contentp = &s->data;
if (options && options->missing_object_cb) {
- if (!oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_SKIP_FETCH_OBJECT))
+ if (!odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_SKIP_FETCH_OBJECT))
goto object_read;
options->missing_object_cb(options->missing_object_data);
}
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
object_read:
@@ -4252,8 +4252,8 @@ int diff_populate_filespec(struct repository *r,
}
if (!info.contentp) {
info.contentp = &s->data;
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
}
s->should_free = 1;
@@ -7019,8 +7019,8 @@ void diff_add_if_missing(struct repository *r,
{
if (filespec && filespec->oid_valid &&
!S_ISGITLINK(filespec->mode) &&
- oid_object_info_extended(r, &filespec->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(r->objects, &filespec->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(to_fetch, &filespec->oid);
}
diff --git a/fetch-pack.c b/fetch-pack.c
index 47fa7fa4c49..0f5de1c94d1 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -149,8 +149,8 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
}
while (1) {
- if (oid_object_info_extended(the_repository, oid, &info,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
return NULL;
if (type == OBJ_TAG) {
struct tag *tag = (struct tag *)
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 80fe48a52c8..7ecd4d9ef50 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -310,7 +310,7 @@ static enum list_objects_filter_result filter_blobs_limit(
assert(obj->type == OBJ_BLOB);
assert((obj->flags & SEEN) == 0);
- t = oid_object_info(r, &obj->oid, &object_length);
+ t = odb_read_object_info(r->objects, &obj->oid, &object_length);
if (t != OBJ_BLOB) { /* probably OBJ_NONE */
/*
* We DO NOT have the blob locally, so we cannot
diff --git a/log-tree.c b/log-tree.c
index 1d05dc1c701..233bf9f227c 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -176,7 +176,7 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
return 0;
}
- objtype = oid_object_info(the_repository, oid, NULL);
+ objtype = odb_read_object_info(the_repository->objects, oid, NULL);
if (objtype < 0)
return 0;
obj = lookup_object_by_type(the_repository, oid, objtype);
diff --git a/merge-ort.c b/merge-ort.c
index 9f693ab1d36..f29417040c1 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -4385,8 +4385,8 @@ static void prefetch_for_content_merges(struct merge_options *opt,
if ((ci->filemask & side_mask) &&
S_ISREG(vi->mode) &&
- oid_object_info_extended(opt->repo, &vi->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(opt->repo->objects, &vi->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&to_fetch, &vi->oid);
}
}
diff --git a/object-file.c b/object-file.c
index 04da19a1a3b..3d674d1093e 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1108,7 +1108,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
oi.typep = &type;
oi.sizep = &len;
oi.contentp = &buf;
- if (oid_object_info_extended(the_repository, oid, &oi, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &oi, 0))
return error(_("cannot read object for %s"), oid_to_hex(oid));
if (compat) {
if (repo_oid_to_algop(repo, oid, compat, &compat_oid))
diff --git a/object-file.h b/object-file.h
index 5066638f8ec..67b4ffc4808 100644
--- a/object-file.h
+++ b/object-file.h
@@ -8,7 +8,7 @@
struct index_state;
/*
- * Set this to 0 to prevent oid_object_info_extended() from fetching missing
+ * Set this to 0 to prevent odb_read_object_info_extended() from fetching missing
* blobs. This has a difference only if extensions.partialClone is set.
*
* Its default value is 1.
diff --git a/object-name.c b/object-name.c
index 381536e900e..e225eb602cf 100644
--- a/object-name.c
+++ b/object-name.c
@@ -251,7 +251,7 @@ static int disambiguate_commit_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_COMMIT;
}
@@ -262,7 +262,7 @@ static int disambiguate_committish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -279,7 +279,7 @@ static int disambiguate_tree_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_TREE;
}
@@ -290,7 +290,7 @@ static int disambiguate_treeish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_TREE || kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -307,7 +307,7 @@ static int disambiguate_blob_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_BLOB;
}
@@ -399,7 +399,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
return 0;
hash = repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV);
- type = oid_object_info(ds->repo, oid, NULL);
+ type = odb_read_object_info(ds->repo->objects, oid, NULL);
if (type < 0) {
/*
@@ -514,8 +514,8 @@ static int sort_ambiguous(const void *va, const void *vb, void *ctx)
{
struct repository *sort_ambiguous_repo = ctx;
const struct object_id *a = va, *b = vb;
- int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
- int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
+ int a_type = odb_read_object_info(sort_ambiguous_repo->objects, a, NULL);
+ int b_type = odb_read_object_info(sort_ambiguous_repo->objects, b, NULL);
int a_type_sort;
int b_type_sort;
diff --git a/object.c b/object.c
index 3b15469139d..868d89eed42 100644
--- a/object.c
+++ b/object.c
@@ -214,7 +214,7 @@ enum peel_status peel_object(struct repository *r,
struct object *o = lookup_unknown_object(r, name);
if (o->type == OBJ_NONE) {
- int type = oid_object_info(r, name, NULL);
+ int type = odb_read_object_info(r->objects, name, NULL);
if (type < 0 || !object_as_type(o, type, 0))
return PEEL_INVALID;
}
@@ -315,7 +315,7 @@ struct object *parse_object_with_flags(struct repository *r,
}
if ((!obj || obj->type == OBJ_BLOB) &&
- oid_object_info(r, oid, NULL) == OBJ_BLOB) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
if (!skip_hash && stream_object_signature(r, repl) < 0) {
error(_("hash mismatch %s"), oid_to_hex(oid));
return NULL;
@@ -331,7 +331,7 @@ struct object *parse_object_with_flags(struct repository *r,
*/
if (skip_hash && discard_tree &&
(!obj || obj->type == OBJ_TREE) &&
- oid_object_info(r, oid, NULL) == OBJ_TREE) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_TREE) {
return &lookup_tree(r, oid)->object;
}
diff --git a/odb.c b/odb.c
index d6ca5b92ab8..c3fe7917161 100644
--- a/odb.c
+++ b/odb.c
@@ -647,7 +647,7 @@ static int register_all_submodule_sources(struct object_database *odb)
return ret;
}
-static int do_oid_object_info_extended(struct repository *r,
+static int do_oid_object_info_extended(struct object_database *odb,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
{
@@ -660,7 +660,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
- real = lookup_replace_object(r, oid);
+ real = lookup_replace_object(odb->repo, oid);
if (is_null_oid(real))
return -1;
@@ -668,7 +668,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (!oi)
oi = &blank_oi;
- co = find_cached_object(r->objects, real);
+ co = find_cached_object(odb, real);
if (co) {
if (oi->typep)
*(oi->typep) = co->type;
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, r->hash_algo);
+ oidclr(oi->delta_base_oid, odb->repo->hash_algo);
if (oi->contentp)
*oi->contentp = xmemdupz(co->buf, co->size);
oi->whence = OI_CACHED;
@@ -685,17 +685,17 @@ static int do_oid_object_info_extended(struct repository *r,
}
while (1) {
- if (find_pack_entry(r, real, &e))
+ if (find_pack_entry(odb->repo, real, &e))
break;
/* Most likely it's a loose object. */
- if (!loose_object_info(r, real, oi, flags))
+ if (!loose_object_info(odb->repo, real, oi, flags))
return 0;
/* Not a loose object; someone else may have just packed it. */
if (!(flags & OBJECT_INFO_QUICK)) {
- reprepare_packed_git(r);
- if (find_pack_entry(r, real, &e))
+ reprepare_packed_git(odb->repo);
+ if (find_pack_entry(odb->repo, real, &e))
break;
}
@@ -705,15 +705,15 @@ static int do_oid_object_info_extended(struct repository *r,
* `odb_add_submodule_source_by_path()` on that submodule's
* ODB). If any such ODBs exist, register them and try again.
*/
- if (register_all_submodule_sources(r->objects))
+ if (register_all_submodule_sources(odb))
/* We added some alternates; retry */
continue;
/* Check if it is a missing object */
- if (fetch_if_missing && repo_has_promisor_remote(r) &&
+ if (fetch_if_missing && repo_has_promisor_remote(odb->repo) &&
!already_retried &&
!(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) {
- promisor_remote_get_direct(r, real, 1);
+ promisor_remote_get_direct(odb->repo, real, 1);
already_retried = 1;
continue;
}
@@ -723,7 +723,7 @@ static int do_oid_object_info_extended(struct repository *r,
if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid))
die(_("replacement %s not found for %s"),
oid_to_hex(real), oid_to_hex(oid));
- if ((p = has_packed_and_bad(r, real)))
+ if ((p = has_packed_and_bad(odb->repo, real)))
die(_("packed object %s (stored in %s) is corrupt"),
oid_to_hex(real), p->pack_name);
}
@@ -736,10 +736,10 @@ static int do_oid_object_info_extended(struct repository *r,
* information below, so return early.
*/
return 0;
- rtype = packed_object_info(r, e.p, e.offset, oi);
+ rtype = packed_object_info(odb->repo, e.p, e.offset, oi);
if (rtype < 0) {
mark_bad_packed_object(e.p, real);
- return do_oid_object_info_extended(r, real, oi, 0);
+ return do_oid_object_info_extended(odb, real, oi, 0);
} else if (oi->whence == OI_PACKED) {
oi->u.packed.offset = e.offset;
oi->u.packed.pack = e.p;
@@ -787,7 +787,7 @@ static int oid_object_info_convert(struct repository *r,
oi = &new_oi;
}
- ret = oid_object_info_extended(r, &oid, oi, flags);
+ ret = odb_read_object_info_extended(r->objects, &oid, oi, flags);
if (ret)
return -1;
if (oi == input_oi)
@@ -830,33 +830,35 @@ static int oid_object_info_convert(struct repository *r,
return ret;
}
-int oid_object_info_extended(struct repository *r, const struct object_id *oid,
- struct object_info *oi, unsigned flags)
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
{
int ret;
- if (oid->algo && (hash_algo_by_ptr(r->hash_algo) != oid->algo))
- return oid_object_info_convert(r, oid, oi, flags);
+ if (oid->algo && (hash_algo_by_ptr(odb->repo->hash_algo) != oid->algo))
+ return oid_object_info_convert(odb->repo, oid, oi, flags);
obj_read_lock();
- ret = do_oid_object_info_extended(r, oid, oi, flags);
+ ret = do_oid_object_info_extended(odb, oid, oi, flags);
obj_read_unlock();
return ret;
}
/* returns enum object_type or negative */
-int oid_object_info(struct repository *r,
- const struct object_id *oid,
- unsigned long *sizep)
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep)
{
enum object_type type;
struct object_info oi = OBJECT_INFO_INIT;
oi.typep = &type;
oi.sizep = sizep;
- if (oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(odb, oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE) < 0)
return -1;
return type;
}
@@ -887,7 +889,7 @@ int pretend_object_file(struct repository *repo,
/*
* This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call oid_object_info_extended() and give
+ * deal with them should arrange to call odb_read_object_info_extended() and give
* error messages themselves.
*/
void *repo_read_object_file(struct repository *r,
@@ -902,7 +904,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (oid_object_info_extended(r, oid, &oi, flags))
+ if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
return NULL;
return data;
@@ -968,13 +970,13 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(odb->repo, oid, NULL);
+ enum object_type type = odb_read_object_info(odb, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index 0ea9d4faa70..b37a9c5d20f 100644
--- a/odb.h
+++ b/odb.h
@@ -265,9 +265,6 @@ void *repo_read_object_file(struct repository *r,
enum object_type *type,
unsigned long *size);
-/* Read and unpack an object file into memory, write memory to an object file */
-int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
-
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -336,9 +333,24 @@ struct object_info {
/* Die if object corruption (not just an object being missing) was detected. */
#define OBJECT_INFO_DIE_IF_CORRUPT 32
-int oid_object_info_extended(struct repository *r,
- const struct object_id *,
- struct object_info *, unsigned flags);
+/*
+ * Read object info from the object database and populate the `object_info`
+ * structure. Returns 0 on success, a negative error code otherwise.
+ */
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags);
+
+/*
+ * Read a subset of object info for the given object ID. Returns an `enum
+ * object_type` on success, a negative error code otherwise. If successful and
+ * `sizep` is non-NULL, then the size of the object will be written to the
+ * pointer.
+ */
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep);
enum {
/* Retry packed storage after checking packed and loose storage */
@@ -360,7 +372,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: repo_read_object_file(),
- * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
+ * read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -368,7 +380,7 @@ void odb_assert_oid_type(struct object_database *odb,
* reading functions. However, beware that in these cases zlib inflation won't
* be performed in parallel, losing performance.
*
- * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
+ * TODO: odb_read_object_info_extended()'s call stack has a recursive behavior. If
* any of its callees end up calling it, this recursive call won't benefit from
* parallel inflation.
*/
@@ -416,4 +428,22 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
+/* Compatibility wrappers, to be removed once Git 2.51 has been released. */
+#include "repository.h"
+
+static inline int oid_object_info_extended(struct repository *r,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
+{
+ return odb_read_object_info_extended(r->objects, oid, oi, flags);
+}
+
+static inline int oid_object_info(struct repository *r,
+ const struct object_id *oid,
+ unsigned long *sizep)
+{
+ return odb_read_object_info(r->objects, oid, sizep);
+}
+
#endif /* ODB_H */
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index c847369eaaa..c5183b619c1 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -144,8 +144,8 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
break;
default:
- real_type = oid_object_info(writer->to_pack->repo,
- &entry->idx.oid, NULL);
+ real_type = odb_read_object_info(writer->to_pack->repo->objects,
+ &entry->idx.oid, NULL);
break;
}
diff --git a/pack-bitmap.c b/pack-bitmap.c
index a695a794e9b..bcbb71f7502 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1868,8 +1868,8 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
size_t eindex_pos = pos - bitmap_num_objects_total(bitmap_git);
struct eindex *eindex = &bitmap_git->ext_index;
struct object *obj = eindex->objects[eindex_pos];
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects, &obj->oid,
+ &oi, 0) < 0)
die(_("unable to get size of %s"), oid_to_hex(&obj->oid));
}
@@ -3220,8 +3220,8 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)
i)))
continue;
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of '%s'"),
oid_to_hex(&obj->oid));
diff --git a/packfile.c b/packfile.c
index ac0e29e99b9..af9ccfdba62 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1321,7 +1321,7 @@ static int retry_bad_packed_offset(struct repository *r,
return OBJ_BAD;
nth_packed_object_id(&oid, p, pack_pos_to_index(p, pos));
mark_bad_packed_object(p, &oid);
- type = oid_object_info(r, &oid, NULL);
+ type = odb_read_object_info(r->objects, &oid, NULL);
if (type <= OBJ_NONE)
return OBJ_BAD;
return type;
@@ -1849,7 +1849,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
oi.typep = &type;
oi.sizep = &base_size;
oi.contentp = &base;
- if (oid_object_info_extended(r, &base_oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(r->objects, &base_oid,
+ &oi, 0) < 0)
base = NULL;
external_base = base;
diff --git a/promisor-remote.c b/promisor-remote.c
index 2baa286bfd0..be6f82d12f8 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -245,8 +245,8 @@ static int remove_fetched_oids(struct repository *repo,
struct object_id *new_oids;
for (i = 0; i < oid_nr; i++)
- if (oid_object_info_extended(repo, &old_oids[i], NULL,
- OBJECT_INFO_SKIP_FETCH_OBJECT)) {
+ if (odb_read_object_info_extended(repo->objects, &old_oids[i], NULL,
+ OBJECT_INFO_SKIP_FETCH_OBJECT)) {
remaining[i] = 1;
remaining_nr++;
}
diff --git a/protocol-caps.c b/protocol-caps.c
index 3022f69a1bd..ecdd0dc58d5 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -64,7 +64,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
strbuf_addstr(&send_buffer, oid_str);
if (info->size) {
- if (oid_object_info(r, &oid, &object_size) < 0) {
+ if (odb_read_object_info(r->objects, &oid, &object_size) < 0) {
strbuf_addstr(&send_buffer, " ");
} else {
strbuf_addf(&send_buffer, " %lu", object_size);
diff --git a/reachable.c b/reachable.c
index 9dc748f0b9a..e984b68a0c4 100644
--- a/reachable.c
+++ b/reachable.c
@@ -211,7 +211,7 @@ static void add_recent_object(const struct object_id *oid,
* later processing, and the revision machinery expects
* commits and tags to have been parsed.
*/
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0)
die("unable to get object info for %s", oid_to_hex(oid));
diff --git a/read-cache.c b/read-cache.c
index c3fa9686766..7d5bccf95dc 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3729,9 +3729,9 @@ void prefetch_cache_entries(const struct index_state *istate,
if (S_ISGITLINK(ce->ce_mode) || !must_prefetch(ce))
continue;
- if (!oid_object_info_extended(the_repository, &ce->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &ce->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &ce->oid);
}
diff --git a/ref-filter.c b/ref-filter.c
index 4ce45440ad1..f9f2c512a8c 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2302,8 +2302,8 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
oi->info.sizep = &oi->size;
oi->info.typep = &oi->type;
}
- if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(the_repository->objects, &oi->oid, &oi->info,
+ OBJECT_INFO_LOOKUP_REPLACE))
return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
oid_to_hex(&oi->oid), ref->refname);
if (oi->info.disk_sizep && oi->disk_size < 0)
diff --git a/remote.c b/remote.c
index 17a842f5684..72c36239d31 100644
--- a/remote.c
+++ b/remote.c
@@ -1182,7 +1182,7 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
BUG("'%s' is not a valid object, "
"match_explicit_lhs() should catch this!",
matched_src_name);
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type == OBJ_COMMIT) {
advise(_("The <src> part of the refspec is a commit object.\n"
"Did you mean to create a new branch by pushing to\n"
@@ -1412,7 +1412,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
continue; /* not a tag */
if (string_list_has_string(&dst_tag, ref->name))
continue; /* they already have it */
- if (oid_object_info(the_repository, &ref->new_oid, NULL) != OBJ_TAG)
+ if (odb_read_object_info(the_repository->objects,
+ &ref->new_oid, NULL) != OBJ_TAG)
continue; /* be conservative */
item = string_list_append(&src_tag, ref->name);
item->util = ref;
diff --git a/sequencer.c b/sequencer.c
index 2432d0a39ec..193459405f8 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5503,9 +5503,8 @@ int sequencer_pick_revisions(struct repository *r,
if (!repo_get_oid(r, name, &oid)) {
if (!lookup_commit_reference_gently(r, &oid, 1)) {
- enum object_type type = oid_object_info(r,
- &oid,
- NULL);
+ enum object_type type = odb_read_object_info(r->objects,
+ &oid, NULL);
res = error(_("%s: can't cherry-pick a %s"),
name, type_name(type));
goto out;
diff --git a/streaming.c b/streaming.c
index 81c42673a23..4b13827668e 100644
--- a/streaming.c
+++ b/streaming.c
@@ -44,7 +44,7 @@ struct git_istream {
union {
struct {
- char *buf; /* from oid_object_info_extended() */
+ char *buf; /* from odb_read_object_info_extended() */
unsigned long read_ptr;
} incore;
@@ -403,8 +403,8 @@ static int open_istream_incore(struct git_istream *st, struct repository *r,
oi.typep = type;
oi.sizep = &st->size;
oi.contentp = (void **)&st->u.incore.buf;
- return oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_DIE_IF_CORRUPT);
+ return odb_read_object_info_extended(r->objects, oid, &oi,
+ OBJECT_INFO_DIE_IF_CORRUPT);
}
/*****************************************************************************
@@ -422,7 +422,7 @@ static int istream_source(struct git_istream *st,
oi.typep = type;
oi.sizep = &size;
- status = oid_object_info_extended(r, oid, &oi, 0);
+ status = odb_read_object_info_extended(r->objects, oid, &oi, 0);
if (status < 0)
return status;
diff --git a/submodule.c b/submodule.c
index 788c9e55ed3..f8373a9ea7d 100644
--- a/submodule.c
+++ b/submodule.c
@@ -968,7 +968,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
return 0;
}
- type = oid_object_info(&subrepo, oid, NULL);
+ type = odb_read_object_info(subrepo.objects, oid, NULL);
switch (type) {
case OBJ_COMMIT:
@@ -1752,8 +1752,7 @@ static int fetch_start_failure(struct strbuf *err UNUSED,
static int commit_missing_in_sub(const struct object_id *oid, void *data)
{
struct repository *subrepo = data;
-
- enum object_type type = oid_object_info(subrepo, oid, NULL);
+ enum object_type type = odb_read_object_info(subrepo->objects, oid, NULL);
return type != OBJ_COMMIT;
}
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index dba227259a2..d8488007493 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -23,7 +23,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
die("could not init repo");
if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
die("could not parse oid");
- if (oid_object_info_extended(&r, &oid, &oi, 0))
+ if (odb_read_object_info_extended(r.objects, &oid, &oi, 0))
die("could not obtain object info");
printf("%d\n", (int) size);
diff --git a/tag.c b/tag.c
index 5f6868bf7b1..144048fd5e0 100644
--- a/tag.c
+++ b/tag.c
@@ -52,7 +52,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
unsigned long size;
int ret;
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type != OBJ_TAG)
return error("%s: cannot verify a non-tag object of type %s.",
name_to_report ?
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 14/17] odb: rename `repo_read_object_file()`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (12 preceding siblings ...)
2025-06-05 6:47 ` [PATCH v5 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
@ 2025-06-05 6:47 ` Patrick Steinhardt
2025-06-05 6:47 ` [PATCH v5 15/17] odb: rename `has_object()` Patrick Steinhardt
` (2 subsequent siblings)
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:47 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `repo_read_object_file()` to `odb_read_object()` to match other
functions related to the object database and our modern coding
guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 10 +++++-----
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 6 +++---
blame.c | 13 ++++++-------
builtin/cat-file.c | 26 +++++++++++---------------
builtin/difftool.c | 2 +-
builtin/fast-export.c | 6 +++---
builtin/fast-import.c | 8 ++++----
builtin/grep.c | 8 ++++----
builtin/index-pack.c | 8 ++++----
builtin/log.c | 2 +-
builtin/merge-tree.c | 12 ++++++------
builtin/mktag.c | 4 ++--
builtin/notes.c | 6 +++---
builtin/pack-objects.c | 30 +++++++++++++++---------------
builtin/tag.c | 4 ++--
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 4 ++--
bundle.c | 2 +-
combine-diff.c | 2 +-
commit.c | 6 +++---
config.c | 2 +-
dir.c | 2 +-
entry.c | 4 ++--
fmt-merge-msg.c | 4 ++--
fsck.c | 2 +-
grep.c | 4 ++--
http-push.c | 4 ++--
mailmap.c | 2 +-
match-trees.c | 4 ++--
merge-blobs.c | 8 ++++----
merge-ort.c | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 13 +++++++------
object.c | 2 +-
odb.c | 19 +++++++------------
odb.h | 29 +++++++++++++++++++++++------
read-cache.c | 6 +++---
reflog.c | 4 ++--
rerere.c | 5 ++---
submodule-config.c | 4 ++--
tag.c | 6 +++---
tree-walk.c | 6 +++---
tree.c | 4 ++--
xdiff-interface.c | 2 +-
47 files changed, 157 insertions(+), 150 deletions(-)
diff --git a/apply.c b/apply.c
index e778b4e911d..a34ced04625 100644
--- a/apply.c
+++ b/apply.c
@@ -3210,8 +3210,8 @@ static int apply_binary(struct apply_state *state,
unsigned long size;
char *result;
- result = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ result = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!result)
return error(_("the necessary postimage %s for "
"'%s' cannot be read"),
@@ -3273,8 +3273,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
unsigned long sz;
char *result;
- result = repo_read_object_file(the_repository, oid, &type,
- &sz);
+ result = odb_read_object(the_repository->objects, oid,
+ &type, &sz);
if (!result)
return -1;
/* XXX read_sha1_file NUL-terminates */
@@ -3503,7 +3503,7 @@ static int resolve_to(struct image *image, const struct object_id *result_id)
image_clear(image);
- data = repo_read_object_file(the_repository, result_id, &type, &size);
+ data = odb_read_object(the_repository->objects, result_id, &type, &size);
if (!data || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(result_id));
strbuf_attach(&image->buf, data, size, size + 1);
diff --git a/archive.c b/archive.c
index f2511d530d5..f5a9d45c8d3 100644
--- a/archive.c
+++ b/archive.c
@@ -98,7 +98,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
(args->tree ? &args->tree->object.oid : NULL), oid);
path += args->baselen;
- buffer = repo_read_object_file(the_repository, oid, type, sizep);
+ buffer = odb_read_object(the_repository->objects, oid, type, sizep);
if (buffer && S_ISREG(mode)) {
struct strbuf buf = STRBUF_INIT;
size_t size = 0;
diff --git a/attr.c b/attr.c
index e5680db7f65..d1daeb0b4d9 100644
--- a/attr.c
+++ b/attr.c
@@ -779,7 +779,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
if (get_tree_entry(istate->repo, tree_oid, path, &oid, &mode))
return NULL;
- buf = repo_read_object_file(istate->repo, &oid, &type, &sz);
+ buf = odb_read_object(istate->repo->objects, &oid, &type, &sz);
if (!buf || type != OBJ_BLOB) {
free(buf);
return NULL;
diff --git a/bisect.c b/bisect.c
index a7939216d00..f24474542ec 100644
--- a/bisect.c
+++ b/bisect.c
@@ -155,9 +155,9 @@ static void show_list(const char *debug, int counted, int nr,
unsigned commit_flags = commit->object.flags;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository,
- &commit->object.oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects,
+ &commit->object.oid, &type,
+ &size);
const char *subject_start;
int subject_len;
diff --git a/blame.c b/blame.c
index 97db3355af4..858d2d74df9 100644
--- a/blame.c
+++ b/blame.c
@@ -1041,9 +1041,9 @@ static void fill_origin_blob(struct diff_options *opt,
&o->blob_oid, 1, &file->ptr, &file_size))
;
else
- file->ptr = repo_read_object_file(the_repository,
- &o->blob_oid, &type,
- &file_size);
+ file->ptr = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &file_size);
file->size = file_size;
if (!file->ptr)
@@ -2869,10 +2869,9 @@ void setup_scoreboard(struct blame_scoreboard *sb,
&sb->final_buf_size))
;
else
- sb->final_buf = repo_read_object_file(the_repository,
- &o->blob_oid,
- &type,
- &sb->final_buf_size);
+ sb->final_buf = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &sb->final_buf_size);
if (!sb->final_buf)
die(_("cannot read blob %s for path %s"),
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index f7595fdb04e..90a3e159d11 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -74,7 +74,7 @@ static int filter_object(const char *path, unsigned mode,
{
enum object_type type;
- *buf = repo_read_object_file(the_repository, oid, &type, size);
+ *buf = odb_read_object(the_repository->objects, oid, &type, size);
if (!*buf)
return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path);
@@ -197,8 +197,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
ret = stream_blob(&oid);
goto cleanup;
}
- buf = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!buf)
die("Cannot read object %s", obj_name);
@@ -219,10 +219,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
struct object_id blob_oid;
if (odb_read_object_info(the_repository->objects,
&oid, NULL) == OBJ_TAG) {
- char *buffer = repo_read_object_file(the_repository,
- &oid,
- &type,
- &size);
+ char *buffer = odb_read_object(the_repository->objects,
+ &oid, &type, &size);
const char *target;
if (!buffer)
@@ -403,10 +401,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
if (!textconv_object(the_repository,
data->rest, 0100644, oid,
1, &contents, &size))
- contents = repo_read_object_file(the_repository,
- oid,
- &type,
- &size);
+ contents = odb_read_object(the_repository->objects,
+ oid, &type, &size);
if (!contents)
die("could not convert '%s' %s",
oid_to_hex(oid), data->rest);
@@ -423,8 +419,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
unsigned long size;
void *contents;
- contents = repo_read_object_file(the_repository, oid, &type,
- &size);
+ contents = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!contents)
die("object %s disappeared", oid_to_hex(oid));
@@ -533,8 +529,8 @@ static void batch_object_write(const char *obj_name,
size_t s = data->size;
char *buf = NULL;
- buf = repo_read_object_file(the_repository, &data->oid, &data->type,
- &data->size);
+ buf = odb_read_object(the_repository->objects, &data->oid,
+ &data->type, &data->size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&data->oid));
buf = replace_idents_using_mailmap(buf, &s);
diff --git a/builtin/difftool.c b/builtin/difftool.c
index fac613e3bc3..e4bc1f83169 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -320,7 +320,7 @@ static char *get_symlink(struct repository *repo,
} else {
enum object_type type;
unsigned long size;
- data = repo_read_object_file(repo, oid, &type, &size);
+ data = odb_read_object(repo->objects, oid, &type, &size);
if (!data)
die(_("could not read object %s for symlink %s"),
oid_to_hex(oid), path);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 6c93cf0a8aa..33f304dd0ad 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -323,7 +323,7 @@ static void export_blob(const struct object_id *oid)
object = (struct object *)lookup_blob(the_repository, oid);
eaten = 0;
} else {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
die("could not read blob %s", oid_to_hex(oid));
if (check_object_signature(the_repository, oid, buf, size,
@@ -869,8 +869,8 @@ static void handle_tag(const char *name, struct tag *tag)
return;
}
- buf = repo_read_object_file(the_repository, &tag->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &tag->object.oid,
+ &type, &size);
if (!buf)
die("could not read tag %s", oid_to_hex(&tag->object.oid));
message = memmem(buf, size, "\n\n", 2);
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 2718376f2c9..1973c504e25 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1265,7 +1265,7 @@ static void load_tree(struct tree_entry *root)
die("Can't load tree %s", oid_to_hex(oid));
} else {
enum object_type type;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_TREE)
die("Can't load tree %s", oid_to_hex(oid));
}
@@ -3002,7 +3002,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
char *buf;
if (!oe || oe->pack_id == MAX_PACK_ID) {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
} else {
type = oe->type;
buf = gfi_unpack_entry(oe, &size);
@@ -3110,8 +3110,8 @@ static struct object_entry *dereference(struct object_entry *oe,
buf = gfi_unpack_entry(oe, &size);
} else {
enum object_type unused;
- buf = repo_read_object_file(the_repository, oid, &unused,
- &size);
+ buf = odb_read_object(the_repository->objects, oid,
+ &unused, &size);
}
if (!buf)
die("Can't load object %s", oid_to_hex(oid));
diff --git a/builtin/grep.c b/builtin/grep.c
index 1435d462cd1..5de61dfffe8 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -573,8 +573,8 @@ static int grep_cache(struct grep_opt *opt,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository, &ce->oid,
- &type, &size);
+ data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &size);
if (!data)
die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
init_tree_desc(&tree, &ce->oid, data, size);
@@ -666,8 +666,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository,
- &entry.oid, &type, &size);
+ data = odb_read_object(the_repository->objects,
+ &entry.oid, &type, &size);
if (!data)
die(_("unable to read tree (%s)"),
oid_to_hex(&entry.oid));
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index d0b16908122..180d261f6ce 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -914,8 +914,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
- has_data = repo_read_object_file(the_repository, oid,
- &has_type, &has_size);
+ has_data = odb_read_object(the_repository->objects, oid,
+ &has_type, &has_size);
read_unlock();
if (!data)
data = new_data = get_data_from_pack(obj_entry);
@@ -1521,8 +1521,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue;
- data = repo_read_object_file(the_repository, &d->oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &d->oid,
+ &type, &size);
if (!data)
continue;
diff --git a/builtin/log.c b/builtin/log.c
index fe9cc5ebecb..f2040b18159 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -714,7 +714,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
unsigned long offset = 0;
if (!buf)
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index b1a17787bcf..cf8b06cadc7 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -75,9 +75,9 @@ static void *result(struct merge_list *entry, unsigned long *size)
const char *path = entry->path;
if (!entry->stage)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid, &type,
- size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid, &type,
+ size);
base = NULL;
if (entry->stage == 1) {
base = entry->blob;
@@ -100,9 +100,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)
enum object_type type;
while (entry) {
if (entry->stage == 2)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid,
+ &type, size);
entry = entry->link;
}
return NULL;
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 1809b38f937..1b391119de8 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -54,8 +54,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
void *buffer;
const struct object_id *repl;
- buffer = repo_read_object_file(the_repository, tagged_oid, &type,
- &size);
+ buffer = odb_read_object(the_repository->objects, tagged_oid,
+ &type, &size);
if (!buffer)
die(_("could not read tagged object '%s'"),
oid_to_hex(tagged_oid));
diff --git a/builtin/notes.c b/builtin/notes.c
index 783d4932ca6..a9529b1696a 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -152,7 +152,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (buf) {
if (size)
write_or_die(fd, buf, size);
@@ -319,7 +319,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
strbuf_init(&msg->buf, 0);
if (repo_get_oid(the_repository, arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
- if (!(value = repo_read_object_file(the_repository, &object, &type, &len)))
+ if (!(value = odb_read_object(the_repository->objects, &object, &type, &len)))
die(_("failed to read object '%s'."), arg);
if (type != OBJ_BLOB) {
strbuf_release(&msg->buf);
@@ -722,7 +722,7 @@ static int append_edit(int argc, const char **argv, const char *prefix,
unsigned long size;
enum object_type type;
struct strbuf buf = STRBUF_INIT;
- char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
+ char *prev_buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!prev_buf)
die(_("unable to read %s"), oid_to_hex(note));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index da35d684081..580a5c1996b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -337,13 +337,13 @@ static void *get_delta(struct object_entry *entry)
void *buf, *base_buf, *delta_buf;
enum object_type type;
- buf = repo_read_object_file(the_repository, &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &entry->idx.oid,
+ &type, &size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
- base_buf = repo_read_object_file(the_repository,
- &DELTA(entry)->idx.oid, &type,
- &base_size);
+ base_buf = odb_read_object(the_repository->objects,
+ &DELTA(entry)->idx.oid, &type,
+ &base_size);
if (!base_buf)
die("unable to read %s",
oid_to_hex(&DELTA(entry)->idx.oid));
@@ -506,9 +506,9 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
&size, NULL)) != NULL)
buf = NULL;
else {
- buf = repo_read_object_file(the_repository,
- &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects,
+ &entry->idx.oid, &type,
+ &size);
if (!buf)
die(_("unable to read %s"),
oid_to_hex(&entry->idx.oid));
@@ -1895,7 +1895,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
/* Did not find one. Either we got a bogus request or
* we need to read and perhaps cache.
*/
- data = repo_read_object_file(the_repository, oid, &type, &size);
+ data = odb_read_object(the_repository->objects, oid, &type, &size);
if (!data)
return NULL;
if (type != OBJ_TREE) {
@@ -2762,9 +2762,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
/* Load data if not already done */
if (!trg->data) {
packing_data_lock(&to_pack);
- trg->data = repo_read_object_file(the_repository,
- &trg_entry->idx.oid, &type,
- &sz);
+ trg->data = odb_read_object(the_repository->objects,
+ &trg_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!trg->data)
die(_("object %s cannot be read"),
@@ -2777,9 +2777,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
}
if (!src->data) {
packing_data_lock(&to_pack);
- src->data = repo_read_object_file(the_repository,
- &src_entry->idx.oid, &type,
- &sz);
+ src->data = odb_read_object(the_repository->objects,
+ &src_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!src->data) {
if (src_entry->preferred_base) {
diff --git a/builtin/tag.c b/builtin/tag.c
index e0b27396c6b..46cbf892e34 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -244,7 +244,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
struct strbuf payload = STRBUF_INIT;
struct strbuf signature = STRBUF_INIT;
- orig = buf = repo_read_object_file(the_repository, oid, &type, &size);
+ orig = buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return;
if (parse_signature(buf, size, &payload, &signature)) {
@@ -407,7 +407,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
strbuf_addstr(sb, "object of unknown type");
break;
case OBJ_COMMIT:
- if ((buf = repo_read_object_file(the_repository, oid, &type, &size))) {
+ if ((buf = odb_read_object(the_repository->objects, oid, &type, &size))) {
subject_len = find_commit_subject(buf, &subject_start);
strbuf_insert(sb, sb->len, subject_start, subject_len);
} else {
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index b92fd4710a9..4360872ae07 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -14,7 +14,7 @@ static char *create_temp_file(struct object_id *oid)
unsigned long size;
int fd;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 405e78bc592..4bc6575a574 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -516,8 +516,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
return;
- base = repo_read_object_file(the_repository, &base_oid, &type,
- &base_size);
+ base = odb_read_object(the_repository->objects, &base_oid,
+ &type, &base_size);
if (!base) {
error("failed to read delta-pack base object %s",
oid_to_hex(&base_oid));
diff --git a/bundle.c b/bundle.c
index e09e3c2f58c..717f056a454 100644
--- a/bundle.c
+++ b/bundle.c
@@ -305,7 +305,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
if (revs->max_age == -1 && revs->min_age == -1)
goto out;
- buf = repo_read_object_file(the_repository, &tag->oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &tag->oid, &type, &size);
if (!buf)
goto out;
line = memmem(buf, size, "\ntagger ", 8);
diff --git a/combine-diff.c b/combine-diff.c
index cf23a753407..4ea2dc93c4f 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -325,7 +325,7 @@ static char *grab_blob(struct repository *r,
*size = fill_textconv(r, textconv, df, &blob);
free_filespec(df);
} else {
- blob = repo_read_object_file(r, oid, &type, size);
+ blob = odb_read_object(r->objects, oid, &type, size);
if (!blob)
die(_("unable to read %s"), oid_to_hex(oid));
if (type != OBJ_BLOB)
diff --git a/commit.c b/commit.c
index d4aa9c7a5f8..28ee6b73ae6 100644
--- a/commit.c
+++ b/commit.c
@@ -374,7 +374,7 @@ const void *repo_get_commit_buffer(struct repository *r,
if (!ret) {
enum object_type type;
unsigned long size;
- ret = repo_read_object_file(r, &commit->object.oid, &type, &size);
+ ret = odb_read_object(r->objects, &commit->object.oid, &type, &size);
if (!ret)
die("cannot read commit object %s",
oid_to_hex(&commit->object.oid));
@@ -1275,8 +1275,8 @@ static void handle_signed_tag(const struct commit *parent, struct commit_extra_h
desc = merge_remote_util(parent);
if (!desc || !desc->obj)
return;
- buf = repo_read_object_file(the_repository, &desc->obj->oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &desc->obj->oid,
+ &type, &size);
if (!buf || type != OBJ_TAG)
goto free_return;
if (!parse_signature(buf, size, &payload, &signature))
diff --git a/config.c b/config.c
index 883dd066827..142c37215a8 100644
--- a/config.c
+++ b/config.c
@@ -1942,7 +1942,7 @@ int git_config_from_blob_oid(config_fn_t fn,
unsigned long size;
int ret;
- buf = repo_read_object_file(repo, oid, &type, &size);
+ buf = odb_read_object(repo->objects, oid, &type, &size);
if (!buf)
return error(_("unable to load config blob object '%s'"), name);
if (type != OBJ_BLOB) {
diff --git a/dir.c b/dir.c
index a374972b624..cb7bd873b17 100644
--- a/dir.c
+++ b/dir.c
@@ -302,7 +302,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
*size_out = 0;
*data_out = NULL;
- data = repo_read_object_file(the_repository, oid, &type, &sz);
+ data = odb_read_object(the_repository->objects, oid, &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return -1;
diff --git a/entry.c b/entry.c
index 75d55038d7c..cae02eb5039 100644
--- a/entry.c
+++ b/entry.c
@@ -93,8 +93,8 @@ void *read_blob_entry(const struct cache_entry *ce, size_t *size)
{
enum object_type type;
unsigned long ul;
- void *blob_data = repo_read_object_file(the_repository, &ce->oid,
- &type, &ul);
+ void *blob_data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &ul);
*size = ul;
if (blob_data) {
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 1a8c972adf3..40174efa3de 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -526,8 +526,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
struct object_id *oid = origins.items[i].util;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository, oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects, oid,
+ &type, &size);
char *origbuf = buf;
unsigned long len = size;
struct signature_check sigc = { NULL };
diff --git a/fsck.c b/fsck.c
index e69baab3af7..23965e1880f 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1293,7 +1293,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
if (oidset_contains(blobs_done, oid))
continue;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
if (is_promisor_object(the_repository, oid))
continue;
diff --git a/grep.c b/grep.c
index dc77e6c4631..932647e4a65 100644
--- a/grep.c
+++ b/grep.c
@@ -1931,8 +1931,8 @@ static int grep_source_load_oid(struct grep_source *gs)
{
enum object_type type;
- gs->buf = repo_read_object_file(gs->repo, gs->identifier, &type,
- &gs->size);
+ gs->buf = odb_read_object(gs->repo->objects, gs->identifier,
+ &type, &gs->size);
if (!gs->buf)
return error(_("'%s': unable to read %s"),
gs->name,
diff --git a/http-push.c b/http-push.c
index d1b1bb23711..9481825abfb 100644
--- a/http-push.c
+++ b/http-push.c
@@ -369,8 +369,8 @@ static void start_put(struct transfer_request *request)
ssize_t size;
git_zstream stream;
- unpacked = repo_read_object_file(the_repository, &request->obj->oid,
- &type, &len);
+ unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
+ &type, &len);
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
/* Set it up */
diff --git a/mailmap.c b/mailmap.c
index b18e74c2110..56c72102d9e 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -196,7 +196,7 @@ int read_mailmap_blob(struct string_list *map, const char *name)
if (repo_get_oid(the_repository, name, &oid) < 0)
return 0;
- buf = repo_read_object_file(the_repository, &oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &oid, &type, &size);
if (!buf)
return error("unable to read mailmap object at %s", name);
if (type != OBJ_BLOB) {
diff --git a/match-trees.c b/match-trees.c
index 4704f95c340..5a8a5c39b04 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -63,7 +63,7 @@ static void *fill_tree_desc_strict(struct repository *r,
enum object_type type;
unsigned long size;
- buffer = repo_read_object_file(r, hash, &type, &size);
+ buffer = odb_read_object(r->objects, hash, &type, &size);
if (!buffer)
die("unable to read tree (%s)", oid_to_hex(hash));
if (type != OBJ_TREE)
@@ -199,7 +199,7 @@ static int splice_tree(struct repository *r,
if (*subpath)
subpath++;
- buf = repo_read_object_file(r, oid1, &type, &sz);
+ buf = odb_read_object(r->objects, oid1, &type, &sz);
if (!buf)
die("cannot read tree %s", oid_to_hex(oid1));
init_tree_desc(&desc, oid1, buf, sz);
diff --git a/merge-blobs.c b/merge-blobs.c
index ba8a3fdfd82..6fc27994171 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -12,8 +12,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
unsigned long size;
enum object_type type;
- buf = repo_read_object_file(the_repository, &obj->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &obj->object.oid,
+ &type, &size);
if (!buf)
return -1;
if (type != OBJ_BLOB) {
@@ -79,8 +79,8 @@ void *merge_blobs(struct index_state *istate, const char *path,
return NULL;
if (!our)
our = their;
- return repo_read_object_file(the_repository, &our->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects, &our->object.oid,
+ &type, size);
}
if (fill_mmfile_blob(&f1, our) < 0)
diff --git a/merge-ort.c b/merge-ort.c
index f29417040c1..473ff61e36e 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -3629,7 +3629,7 @@ static int read_oid_strbuf(struct merge_options *opt,
void *buf;
enum object_type type;
unsigned long size;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
path, NULL, NULL, NULL,
diff --git a/notes-cache.c b/notes-cache.c
index 344f67762b8..dd56feed6e8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -87,7 +87,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
value_oid = get_note(&c->tree, key_oid);
if (!value_oid)
return NULL;
- value = repo_read_object_file(the_repository, value_oid, &type, &size);
+ value = odb_read_object(the_repository->objects, value_oid, &type, &size);
*outsize = size;
return value;
diff --git a/notes-merge.c b/notes-merge.c
index de6a52e2e7f..586939939f2 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -340,7 +340,7 @@ static void write_note_to_worktree(const struct object_id *obj,
{
enum object_type type;
unsigned long size;
- void *buf = repo_read_object_file(the_repository, note, &type, &size);
+ void *buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!buf)
die("cannot read note %s for object %s",
diff --git a/notes.c b/notes.c
index fc000e501d2..73eb5f00cf5 100644
--- a/notes.c
+++ b/notes.c
@@ -816,15 +816,15 @@ int combine_notes_concatenate(struct object_id *cur_oid,
/* read in both note blob objects */
if (!is_null_oid(new_oid))
- new_msg = repo_read_object_file(the_repository, new_oid,
- &new_type, &new_len);
+ new_msg = odb_read_object(the_repository->objects, new_oid,
+ &new_type, &new_len);
if (!new_msg || !new_len || new_type != OBJ_BLOB) {
free(new_msg);
return 0;
}
if (!is_null_oid(cur_oid))
- cur_msg = repo_read_object_file(the_repository, cur_oid,
- &cur_type, &cur_len);
+ cur_msg = odb_read_object(the_repository->objects, cur_oid,
+ &cur_type, &cur_len);
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
free(cur_msg);
free(new_msg);
@@ -880,7 +880,7 @@ static int string_list_add_note_lines(struct string_list *list,
return 0;
/* read_sha1_file NUL-terminates */
- data = repo_read_object_file(the_repository, oid, &t, &len);
+ data = odb_read_object(the_repository->objects, oid, &t, &len);
if (t != OBJ_BLOB || !data || !len) {
free(data);
return t != OBJ_BLOB || !data;
@@ -1290,7 +1290,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!oid)
return;
- if (!(msg = repo_read_object_file(the_repository, oid, &type, &msglen)) || type != OBJ_BLOB) {
+ if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
+ type != OBJ_BLOB) {
free(msg);
return;
}
diff --git a/object.c b/object.c
index 868d89eed42..c1553ee4330 100644
--- a/object.c
+++ b/object.c
@@ -335,7 +335,7 @@ struct object *parse_object_with_flags(struct repository *r,
return &lookup_tree(r, oid)->object;
}
- buffer = repo_read_object_file(r, oid, &type, &size);
+ buffer = odb_read_object(r->objects, oid, &type, &size);
if (buffer) {
if (!skip_hash &&
check_object_signature(r, repl, buffer, size, type) < 0) {
diff --git a/odb.c b/odb.c
index c3fe7917161..fc39fbe12d8 100644
--- a/odb.c
+++ b/odb.c
@@ -30,7 +30,7 @@ KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -887,15 +887,10 @@ int pretend_object_file(struct repository *repo,
return 0;
}
-/*
- * This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call odb_read_object_info_extended() and give
- * error messages themselves.
- */
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size)
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
{
struct object_info oi = OBJECT_INFO_INIT;
unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT | OBJECT_INFO_LOOKUP_REPLACE;
@@ -904,7 +899,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
+ if (odb_read_object_info_extended(odb, oid, &oi, flags))
return NULL;
return data;
@@ -926,7 +921,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = repo_read_object_file(r, &actual_oid, &type, &isize);
+ buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
diff --git a/odb.h b/odb.h
index b37a9c5d20f..a4a5154fd0f 100644
--- a/odb.h
+++ b/odb.h
@@ -140,7 +140,7 @@ struct object_database {
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -260,10 +260,19 @@ void odb_add_to_alternates_file(struct object_database *odb,
void odb_add_to_alternates_memory(struct object_database *odb,
const char *dir);
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size);
+/*
+ * Read an object from the database. Returns the object data and assigns object
+ * type and size to the `type` and `size` pointers, if these pointers are
+ * non-NULL. Returns a `NULL` pointer in case the object does not exist.
+ *
+ * This function dies on corrupt objects; the callers who want to deal with
+ * them should arrange to call odb_read_object_info_extended() and give error
+ * messages themselves.
+ */
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size);
/*
* Add an object file to the in-memory object store, without writing it
@@ -371,7 +380,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
- * following functions in parallel: repo_read_object_file(),
+ * following functions in parallel: odb_read_object(),
* read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
@@ -446,4 +455,12 @@ static inline int oid_object_info(struct repository *r,
return odb_read_object_info(r->objects, oid, sizep);
}
+static inline void *repo_read_object_file(struct repository *r,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
+{
+ return odb_read_object(r->objects, oid, type, size);
+}
+
#endif /* ODB_H */
diff --git a/read-cache.c b/read-cache.c
index 7d5bccf95dc..531d87e7905 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -254,7 +254,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
if (strbuf_readlink(&sb, ce->name, expected_size))
return -1;
- buffer = repo_read_object_file(the_repository, &ce->oid, &type, &size);
+ buffer = odb_read_object(the_repository->objects, &ce->oid, &type, &size);
if (buffer) {
if (size == sb.len)
match = memcmp(buffer, sb.buf, size);
@@ -3485,8 +3485,8 @@ void *read_blob_data_from_index(struct index_state *istate,
}
if (pos < 0)
return NULL;
- data = repo_read_object_file(the_repository, &istate->cache[pos]->oid,
- &type, &sz);
+ data = odb_read_object(the_repository->objects, &istate->cache[pos]->oid,
+ &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return NULL;
diff --git a/reflog.c b/reflog.c
index 4f8a3b717cd..747b82eada8 100644
--- a/reflog.c
+++ b/reflog.c
@@ -140,8 +140,8 @@ static int tree_is_complete(const struct object_id *oid)
if (!tree->buffer) {
enum object_type type;
unsigned long size;
- void *data = repo_read_object_file(the_repository, oid, &type,
- &size);
+ void *data = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!data) {
tree->object.flags |= INCOMPLETE;
return 0;
diff --git a/rerere.c b/rerere.c
index 951e4bf8b41..8bb97c98229 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1000,9 +1000,8 @@ static int handle_cache(struct index_state *istate,
break;
i = ce_stage(ce) - 1;
if (!mmfile[i].ptr) {
- mmfile[i].ptr = repo_read_object_file(the_repository,
- &ce->oid, &type,
- &size);
+ mmfile[i].ptr = odb_read_object(the_repository->objects,
+ &ce->oid, &type, &size);
if (!mmfile[i].ptr)
die(_("unable to read %s"),
oid_to_hex(&ce->oid));
diff --git a/submodule-config.c b/submodule-config.c
index a9f72107888..ea3a087a8bb 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -743,8 +743,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
if (submodule)
goto out;
- config = repo_read_object_file(the_repository, &oid, &type,
- &config_size);
+ config = odb_read_object(the_repository->objects, &oid,
+ &type, &config_size);
if (!config || type != OBJ_BLOB)
goto out;
diff --git a/tag.c b/tag.c
index 144048fd5e0..1d52686ee10 100644
--- a/tag.c
+++ b/tag.c
@@ -60,7 +60,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV),
type_name(type));
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return error("%s: unable to read file.",
name_to_report ?
@@ -222,8 +222,8 @@ int parse_tag(struct tag *item)
if (item->object.parsed)
return 0;
- data = repo_read_object_file(the_repository, &item->object.oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!data)
return error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/tree-walk.c b/tree-walk.c
index 34b0fff4873..766af99f466 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -795,9 +795,9 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
*/
retval = DANGLING_SYMLINK;
- contents = repo_read_object_file(r,
- ¤t_tree_oid, &type,
- &link_len);
+ contents = odb_read_object(r->objects,
+ ¤t_tree_oid, &type,
+ &link_len);
if (!contents)
goto done;
diff --git a/tree.c b/tree.c
index 341b7c2ff3f..1ef743d90f4 100644
--- a/tree.c
+++ b/tree.c
@@ -193,8 +193,8 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
if (item->object.parsed)
return 0;
- buffer = repo_read_object_file(the_repository, &item->object.oid,
- &type, &size);
+ buffer = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!buffer)
return quiet_on_missing ? -1 :
error("Could not read %s",
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 01e6e378ea6..0e5d38c9600 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -187,7 +187,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
return;
}
- ptr->ptr = repo_read_object_file(the_repository, oid, &type, &size);
+ ptr->ptr = odb_read_object(the_repository->objects, oid, &type, &size);
if (!ptr->ptr || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
ptr->size = size;
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 15/17] odb: rename `has_object()`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (13 preceding siblings ...)
2025-06-05 6:47 ` [PATCH v5 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
@ 2025-06-05 6:47 ` Patrick Steinhardt
2025-06-05 6:47 ` [PATCH v5 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
2025-06-05 6:47 ` [PATCH v5 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
16 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:47 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `has_object()` to `odb_has_object()` to match other functions
related to the object database and our modern coding guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 2 +-
builtin/backfill.c | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/clone.c | 2 +-
builtin/fetch.c | 17 +++++++++--------
builtin/fsck.c | 2 +-
builtin/index-pack.c | 4 ++--
builtin/pack-objects.c | 4 ++--
builtin/receive-pack.c | 4 ++--
builtin/remote.c | 4 ++--
builtin/show-ref.c | 4 ++--
builtin/unpack-objects.c | 4 ++--
bulk-checkin.c | 4 ++--
cache-tree.c | 15 ++++++++-------
commit-graph.c | 2 +-
commit.c | 2 +-
fetch-pack.c | 8 ++++----
http-push.c | 14 ++++++++------
http-walker.c | 8 ++++----
list-objects.c | 4 ++--
notes.c | 4 ++--
odb.c | 6 +++---
odb.h | 12 ++++++++++--
reflog.c | 2 +-
refs.c | 3 ++-
remote.c | 2 +-
send-pack.c | 2 +-
shallow.c | 12 ++++++------
upload-pack.c | 2 +-
walker.c | 4 ++--
30 files changed, 87 insertions(+), 74 deletions(-)
diff --git a/apply.c b/apply.c
index a34ced04625..a6836692d0c 100644
--- a/apply.c
+++ b/apply.c
@@ -3204,7 +3204,7 @@ static int apply_binary(struct apply_state *state,
return 0; /* deletion patch */
}
- if (has_object(the_repository, &oid, 0)) {
+ if (odb_has_object(the_repository->objects, &oid, 0)) {
/* We already have the postimage */
enum object_type type;
unsigned long size;
diff --git a/builtin/backfill.c b/builtin/backfill.c
index 0b49baa39fa..80056abe473 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -67,8 +67,8 @@ static int fill_missing_blobs(const char *path UNUSED,
return 0;
for (size_t i = 0; i < list->nr; i++) {
- if (!has_object(ctx->repo, &list->oid[i],
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_has_object(ctx->repo->objects, &list->oid[i],
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&ctx->current_batch, &list->oid[i]);
}
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 90a3e159d11..01672ec74bd 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -160,8 +160,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
goto cleanup;
case 'e':
- ret = !has_object(the_repository, &oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
+ ret = !odb_has_object(the_repository->objects, &oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
goto cleanup;
case 'w':
diff --git a/builtin/clone.c b/builtin/clone.c
index 3aabdf6570b..6d08abed37c 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -506,7 +506,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
continue;
if (ends_with(ref->name, "^{}"))
continue;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
refs_update_ref(get_main_ref_store(the_repository), msg,
ref->name, &ref->old_oid, NULL, 0,
diff --git a/builtin/fetch.c b/builtin/fetch.c
index b842bc9c51b..65ea6c84368 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -366,9 +366,9 @@ static void find_non_local_tags(const struct ref *refs,
*/
if (ends_with(ref->name, "^{}")) {
if (item &&
- !has_object(the_repository, &ref->old_oid, 0) &&
+ !odb_has_object(the_repository->objects, &ref->old_oid, 0) &&
!oidset_contains(&fetch_oids, &ref->old_oid) &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
item = NULL;
@@ -382,7 +382,7 @@ static void find_non_local_tags(const struct ref *refs,
* fetch.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -403,7 +403,7 @@ static void find_non_local_tags(const struct ref *refs,
* checked to see if it needs fetching.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -910,8 +910,8 @@ static int update_local_ref(struct ref *ref,
struct commit *current = NULL, *updated;
int fast_forward = 0;
- if (!has_object(the_repository, &ref->new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &ref->new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
if (oideq(&ref->old_oid, &ref->new_oid)) {
@@ -1330,7 +1330,8 @@ static int check_exist_and_connected(struct ref *ref_map)
* we need all direct targets to exist.
*/
for (r = rm; r; r = r->next) {
- if (!has_object(the_repository, &r->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ if (!odb_has_object(the_repository->objects, &r->old_oid,
+ HAS_OBJECT_RECHECK_PACKED))
return -1;
}
@@ -1485,7 +1486,7 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
struct object_id oid;
if (repo_get_oid(the_repository, s, &oid))
die(_("%s is not a valid object"), s);
- if (!has_object(the_repository, &oid, 0))
+ if (!odb_has_object(the_repository->objects, &oid, 0))
die(_("the object %s does not exist"), s);
oid_array_append(oids, &oid);
continue;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6e3465b0266..0084cf7400b 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -161,7 +161,7 @@ static int mark_object(struct object *obj, enum object_type type,
return 0;
if (!(obj->flags & HAS_OBJ)) {
- if (parent && !has_object(the_repository, &obj->oid, 1)) {
+ if (parent && !odb_has_object(the_repository->objects, &obj->oid, 1)) {
printf_ln(_("broken link from %7s %s\n"
" to %7s %s"),
printable_type(&parent->oid, parent->type),
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 180d261f6ce..19c67a85344 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -893,8 +893,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (startup_info->have_repository) {
read_lock();
- collision_test_needed = has_object(the_repository, oid,
- HAS_OBJECT_FETCH_PROMISOR);
+ collision_test_needed = odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_FETCH_PROMISOR);
read_unlock();
}
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 580a5c1996b..06bdeb4223b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3968,7 +3968,7 @@ static void show_object__ma_allow_any(struct object *obj, const char *name, void
* Quietly ignore ALL missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0))
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0))
return;
show_object(obj, name, data);
@@ -3982,7 +3982,7 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
* Quietly ignore EXPECTED missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0) &&
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0) &&
is_promisor_object(to_pack.repo, &obj->oid))
return;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 7ea273d93e4..26e77d70726 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1509,8 +1509,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
}
if (!is_null_oid(new_oid) &&
- !has_object(the_repository, new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error("unpack should have generated %s, "
"but I can't find it!", oid_to_hex(new_oid));
ret = "bad pack";
diff --git a/builtin/remote.c b/builtin/remote.c
index ac5b8d2a1a6..7cbda285ebe 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -454,8 +454,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
info->status = PUSH_STATUS_UPTODATE;
else if (is_null_oid(&ref->old_oid))
info->status = PUSH_STATUS_CREATE;
- else if (has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ else if (odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
ref_newer(&ref->new_oid, &ref->old_oid))
info->status = PUSH_STATUS_FASTFORWARD;
else
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 90ec1de78f9..117709cb076 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -35,8 +35,8 @@ static void show_one(const struct show_one_options *opts,
const char *hex;
struct object_id peeled;
- if (!has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die("git show-ref: bad ref %s (%s)", refname,
oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 4bc6575a574..a69d59eb50c 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -449,8 +449,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
delta_data = get_data(delta_size);
if (!delta_data)
return;
- if (has_object(the_repository, &base_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &base_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
; /* Ok we have this one */
else if (resolve_against_held(nr, &base_oid,
delta_data, delta_size))
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 55406a539e7..16df86c0ba8 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -130,8 +130,8 @@ static void flush_batch_fsync(void)
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
{
/* The object may already exist in the repository */
- if (has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 1;
/* Might want to keep the list sorted */
diff --git a/cache-tree.c b/cache-tree.c
index 9786b32b3a1..a4bc14ad15c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -239,8 +239,8 @@ int cache_tree_fully_valid(struct cache_tree *it)
if (!it)
return 0;
if (it->entry_count < 0 ||
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
for (i = 0; i < it->subtree_nr; i++) {
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -292,8 +292,8 @@ static int update_one(struct cache_tree *it,
}
if (0 <= it->entry_count &&
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return it->entry_count;
/*
@@ -399,8 +399,9 @@ static int update_one(struct cache_tree *it,
ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
!must_check_existence(ce);
if (is_null_oid(oid) ||
- (!ce_missing_ok && !has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
+ (!ce_missing_ok &&
+ !odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
strbuf_release(&buffer);
if (expected_missing)
return -1;
@@ -448,7 +449,7 @@ static int update_one(struct cache_tree *it,
struct object_id oid;
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
OBJ_TREE, &oid);
- if (has_object(the_repository, &oid, HAS_OBJECT_RECHECK_PACKED))
+ if (odb_has_object(the_repository->objects, &oid, HAS_OBJECT_RECHECK_PACKED))
oidcpy(&it->oid, &oid);
else
to_invalidate = 1;
diff --git a/commit-graph.c b/commit-graph.c
index 5f482d3377f..bd7b6f5338b 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1040,7 +1040,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
return NULL;
if (!search_commit_pos_in_graph(id, repo->objects->commit_graph, &pos))
return NULL;
- if (commit_graph_paranoia && !has_object(repo, id, 0))
+ if (commit_graph_paranoia && !odb_has_object(repo->objects, id, 0))
return NULL;
commit = lookup_commit(repo, id);
diff --git a/commit.c b/commit.c
index 28ee6b73ae6..15115125c36 100644
--- a/commit.c
+++ b/commit.c
@@ -575,7 +575,7 @@ int repo_parse_commit_internal(struct repository *r,
if (commit_graph_paranoia == -1)
commit_graph_paranoia = git_env_bool(GIT_COMMIT_GRAPH_PARANOIA, 0);
- if (commit_graph_paranoia && !has_object(r, &item->object.oid, 0)) {
+ if (commit_graph_paranoia && !odb_has_object(r->objects, &item->object.oid, 0)) {
unparse_commit(r, &item->object.oid);
return quiet_on_missing ? -1 :
error(_("commit %s exists in commit-graph but not in the object database"),
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f5de1c94d1..5e74235fc06 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -142,7 +142,7 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
commit = lookup_commit_in_graph(the_repository, oid);
if (commit) {
if (mark_tags_complete_and_check_obj_db) {
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
die_in_commit_graph_only(oid);
}
return commit;
@@ -770,7 +770,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
if (!commit) {
struct object *o;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
o = parse_object(the_repository, &ref->old_oid);
if (!o || o->type != OBJ_COMMIT)
@@ -1984,8 +1984,8 @@ static void update_shallow(struct fetch_pack_args *args,
struct oid_array extra = OID_ARRAY_INIT;
struct object_id *oid = si->shallow->oid;
for (i = 0; i < si->shallow->nr; i++)
- if (has_object(the_repository, &oid[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &oid[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
oid_array_append(&extra, &oid[i]);
if (extra.nr) {
setup_alternate_shallow(&shallow_lock,
diff --git a/http-push.c b/http-push.c
index 9481825abfb..beb41732fb6 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1447,8 +1447,8 @@ static void one_remote_ref(const char *refname)
* may be required for updating server info later.
*/
if (repo->can_update_info_refs &&
- !has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
obj = lookup_unknown_object(the_repository, &ref->old_oid);
fprintf(stderr, " fetch %s for %s\n",
oid_to_hex(&ref->old_oid), refname);
@@ -1653,14 +1653,16 @@ static int delete_remote_branch(const char *pattern, int force)
return error("Remote HEAD symrefs too deep");
if (is_null_oid(&head_oid))
return error("Unable to resolve remote HEAD");
- if (!has_object(the_repository, &head_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &head_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", oid_to_hex(&head_oid));
/* Remote branch must resolve to a known object */
if (is_null_oid(&remote_ref->old_oid))
return error("Unable to resolve remote branch %s",
remote_ref->name);
- if (!has_object(the_repository, &remote_ref->old_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &remote_ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, oid_to_hex(&remote_ref->old_oid));
/* Remote branch must be an ancestor of remote HEAD */
@@ -1881,8 +1883,8 @@ int cmd_main(int argc, const char **argv)
if (!force_all &&
!is_null_oid(&ref->old_oid) &&
!ref->force) {
- if (!has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
+ if (!odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
!ref_newer(&ref->peer_ref->new_oid,
&ref->old_oid)) {
/*
diff --git a/http-walker.c b/http-walker.c
index 05fb9ce714a..0f7ae46d7f1 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -138,8 +138,8 @@ static int fill_active_slot(void *data UNUSED)
list_for_each_safe(pos, tmp, head) {
obj_req = list_entry(pos, struct object_request, node);
if (obj_req->state == WAITING) {
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
obj_req->state = COMPLETE;
else {
start_object_request(obj_req);
@@ -497,8 +497,8 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
if (!obj_req)
return error("Couldn't find request for %s in the queue", hex);
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
if (obj_req->req)
abort_http_object_request(&obj_req->req);
abort_object_request(obj_req);
diff --git a/list-objects.c b/list-objects.c
index c50b9578584..42c17d95739 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -74,8 +74,8 @@ static void process_blob(struct traversal_context *ctx,
* of missing objects.
*/
if (ctx->revs->exclude_promisor_objects &&
- !has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ !odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
is_promisor_object(ctx->revs->repo, &obj->oid))
return;
diff --git a/notes.c b/notes.c
index 73eb5f00cf5..97b995f3f2d 100644
--- a/notes.c
+++ b/notes.c
@@ -794,8 +794,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
struct note_delete_list **l = (struct note_delete_list **) cb_data;
struct note_delete_list *n;
- if (has_object(the_repository, object_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, object_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0; /* nothing to do for this note */
/* failed to find object => prune this note */
diff --git a/odb.c b/odb.c
index fc39fbe12d8..4dccb9215d8 100644
--- a/odb.c
+++ b/odb.c
@@ -871,7 +871,7 @@ int pretend_object_file(struct repository *repo,
char *co_buf;
hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (has_object(repo, oid, 0) ||
+ if (odb_has_object(repo->objects, oid, 0) ||
find_cached_object(repo->objects, oid))
return 0;
@@ -953,7 +953,7 @@ void *read_object_with_reference(struct repository *r,
}
}
-int has_object(struct repository *r, const struct object_id *oid,
+int odb_has_object(struct object_database *odb, const struct object_id *oid,
unsigned flags)
{
unsigned object_info_flags = 0;
@@ -965,7 +965,7 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(odb, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
diff --git a/odb.h b/odb.h
index a4a5154fd0f..2532c490461 100644
--- a/odb.h
+++ b/odb.h
@@ -372,8 +372,9 @@ enum {
* Returns 1 if the object exists. This function will not lazily fetch objects
* in a partial clone by default.
*/
-int has_object(struct repository *r, const struct object_id *oid,
- unsigned flags);
+int odb_has_object(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned flags);
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect);
@@ -463,4 +464,11 @@ static inline void *repo_read_object_file(struct repository *r,
return odb_read_object(r->objects, oid, type, size);
}
+static inline int has_object(struct repository *r,
+ const struct object_id *oid,
+ unsigned flags)
+{
+ return odb_has_object(r->objects, oid, flags);
+}
+
#endif /* ODB_H */
diff --git a/reflog.c b/reflog.c
index 747b82eada8..39c205fd26e 100644
--- a/reflog.c
+++ b/reflog.c
@@ -152,7 +152,7 @@ static int tree_is_complete(const struct object_id *oid)
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
complete = 1;
while (tree_entry(&desc, &entry)) {
- if (!has_object(the_repository, &entry.oid,
+ if (!odb_has_object(the_repository->objects, &entry.oid,
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
(S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) {
tree->object.flags |= INCOMPLETE;
diff --git a/refs.c b/refs.c
index 0ff0e582a6b..26e5c2a7d9c 100644
--- a/refs.c
+++ b/refs.c
@@ -376,7 +376,8 @@ int ref_resolves_to_object(const char *refname,
{
if (flags & REF_ISBROKEN)
return 0;
- if (!has_object(repo, oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (!odb_has_object(repo->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error(_("%s does not point to a valid object!"), refname);
return 0;
}
diff --git a/remote.c b/remote.c
index 72c36239d31..5edf2a9f4b2 100644
--- a/remote.c
+++ b/remote.c
@@ -1703,7 +1703,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
if (starts_with(ref->name, "refs/tags/"))
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
- else if (!has_object(the_repository, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ else if (!odb_has_object(the_repository->objects, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||
!lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))
diff --git a/send-pack.c b/send-pack.c
index abca2dd38a7..d029f748232 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -45,7 +45,7 @@ int option_parse_push_signed(const struct option *opt,
static void feed_object(struct repository *r,
const struct object_id *oid, FILE *fh, int negative)
{
- if (negative && !has_object(r, oid, 0))
+ if (negative && !odb_has_object(r->objects, oid, 0))
return;
if (negative)
diff --git a/shallow.c b/shallow.c
index d379756e39a..ef3adb635fd 100644
--- a/shallow.c
+++ b/shallow.c
@@ -310,8 +310,8 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
if (graft->nr_parent != -1)
return 0;
if (data->flags & QUICK) {
- if (!has_object(the_repository, &graft->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &graft->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
} else if (data->flags & SEEN_ONLY) {
struct commit *c = lookup_commit(the_repository, &graft->oid);
@@ -477,8 +477,8 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
ALLOC_ARRAY(info->ours, sa->nr);
ALLOC_ARRAY(info->theirs, sa->nr);
for (size_t i = 0; i < sa->nr; i++) {
- if (has_object(the_repository, sa->oid + i,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, sa->oid + i,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
struct commit_graft *graft;
graft = lookup_commit_graft(the_repository,
&sa->oid[i]);
@@ -515,8 +515,8 @@ void remove_nonexistent_theirs_shallow(struct shallow_info *info)
for (i = dst = 0; i < info->nr_theirs; i++) {
if (i != dst)
info->theirs[dst] = info->theirs[i];
- if (has_object(the_repository, oid + info->theirs[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid + info->theirs[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
dst++;
}
info->nr_theirs = dst;
diff --git a/upload-pack.c b/upload-pack.c
index e994d6a901b..4f26f6afc77 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -509,7 +509,7 @@ static int got_oid(struct upload_pack_data *data,
{
if (get_oid_hex(hex, oid))
die("git upload-pack: expected SHA1 object, got '%s'", hex);
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
return -1;
return do_got_oid(data, oid);
}
diff --git a/walker.c b/walker.c
index a8abe8a2e78..d131af04c7b 100644
--- a/walker.c
+++ b/walker.c
@@ -150,8 +150,8 @@ static int process(struct walker *walker, struct object *obj)
return 0;
obj->flags |= SEEN;
- if (has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
/* We already have it, so we should scan it now. */
obj->flags |= TO_SCAN;
}
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 16/17] odb: rename `pretend_object_file()`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (14 preceding siblings ...)
2025-06-05 6:47 ` [PATCH v5 15/17] odb: rename `has_object()` Patrick Steinhardt
@ 2025-06-05 6:47 ` Patrick Steinhardt
2025-06-30 3:14 ` Justin Tobler
2025-06-05 6:47 ` [PATCH v5 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
16 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:47 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `pretend_object_file()` to `odb_pretend_object()` to match other
functions related to the object database and our modern coding
guidelines.
No compatibility wrapper is introduces as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
blame.c | 3 ++-
odb.c | 18 +++++++++---------
odb.h | 6 +++---
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/blame.c b/blame.c
index 858d2d74df9..dce5c8d855c 100644
--- a/blame.c
+++ b/blame.c
@@ -277,7 +277,8 @@ static struct commit *fake_working_tree_commit(struct repository *r,
convert_to_git(r->index, path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
- pretend_object_file(the_repository, buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
+ odb_pretend_object(the_repository->objects, buf.buf, buf.len,
+ OBJ_BLOB, &origin->blob_oid);
/*
* Read the current index, replace the path entry with
diff --git a/odb.c b/odb.c
index 4dccb9215d8..f6231a0556d 100644
--- a/odb.c
+++ b/odb.c
@@ -863,21 +863,21 @@ int odb_read_object_info(struct object_database *odb,
return type;
}
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid)
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid)
{
struct cached_object_entry *co;
char *co_buf;
- hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (odb_has_object(repo->objects, oid, 0) ||
- find_cached_object(repo->objects, oid))
+ hash_object_file(odb->repo->hash_algo, buf, len, type, oid);
+ if (odb_has_object(odb, oid, 0) ||
+ find_cached_object(odb, oid))
return 0;
- ALLOC_GROW(repo->objects->cached_objects,
- repo->objects->cached_object_nr + 1, repo->objects->cached_object_alloc);
- co = &repo->objects->cached_objects[repo->objects->cached_object_nr++];
+ ALLOC_GROW(odb->cached_objects,
+ odb->cached_object_nr + 1, odb->cached_object_alloc);
+ co = &odb->cached_objects[odb->cached_object_nr++];
co->value.size = len;
co->value.type = type;
co_buf = xmalloc(len);
diff --git a/odb.h b/odb.h
index 2532c490461..e4c51f8c38e 100644
--- a/odb.h
+++ b/odb.h
@@ -282,9 +282,9 @@ void *odb_read_object(struct object_database *odb,
* object in persistent storage before writing any other new objects
* that reference it.
*/
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid);
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid);
struct object_info {
/* Request */
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v5 17/17] odb: rename `read_object_with_reference()`
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
` (15 preceding siblings ...)
2025-06-05 6:47 ` [PATCH v5 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
@ 2025-06-05 6:47 ` Patrick Steinhardt
2025-06-30 3:15 ` Justin Tobler
16 siblings, 1 reply; 166+ messages in thread
From: Patrick Steinhardt @ 2025-06-05 6:47 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `read_object_with_reference()` to `odb_read_object_peeled()` to
match other functions related to the object database and our modern
coding guidelines. Furthermore though, the old name didn't really
describe very well what this function actually does, which is to walk
down any commit and tag objects until an object of the required type has
been found. This is generally referred to as "peeling", so the new name
should be way more descriptive.
No compatibility wrapper is introduces as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Documentation/user-manual.adoc | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/fast-import.c | 19 ++++++++-----------
builtin/grep.c | 9 +++------
builtin/pack-objects.c | 4 ++--
odb.c | 17 +++++++++--------
odb.h | 15 +++++++--------
tree-walk.c | 10 ++++------
8 files changed, 37 insertions(+), 45 deletions(-)
diff --git a/Documentation/user-manual.adoc b/Documentation/user-manual.adoc
index d2b478ad232..e86b2ad9f8a 100644
--- a/Documentation/user-manual.adoc
+++ b/Documentation/user-manual.adoc
@@ -4301,11 +4301,11 @@ Now, for the meat:
-----------------------------------------------------------------------------
case 0:
- buf = read_object_with_reference(sha1, argv[1], &size, NULL);
+ buf = odb_read_object_peeled(r->objects, sha1, argv[1], &size, NULL);
-----------------------------------------------------------------------------
This is how you read a blob (actually, not only a blob, but any type of
-object). To know how the function `read_object_with_reference()` actually
+object). To know how the function `odb_read_object_peeled()` actually
works, find the source code for it (something like `git grep
read_object_with | grep ":[a-z]"` in the Git repository), and read
the source.
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 01672ec74bd..08afecbf57c 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -246,8 +246,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
* fall-back to the usual case.
*/
}
- buf = read_object_with_reference(the_repository, &oid,
- exp_type_id, &size, NULL);
+ buf = odb_read_object_peeled(the_repository->objects, &oid,
+ exp_type_id, &size, NULL);
if (use_mailmap) {
size_t s = size;
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 1973c504e25..b1389c59211 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2535,10 +2535,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
oidcpy(&commit_oid, &commit_oe->idx.oid);
} else if (!repo_get_oid(the_repository, p, &commit_oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &commit_oid,
- OBJ_COMMIT, &size,
- &commit_oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &commit_oid, OBJ_COMMIT, &size,
+ &commit_oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", p);
free(buf);
@@ -2604,9 +2603,8 @@ static void parse_from_existing(struct branch *b)
unsigned long size;
char *buf;
- buf = read_object_with_reference(the_repository,
- &b->oid, OBJ_COMMIT, &size,
- &b->oid);
+ buf = odb_read_object_peeled(the_repository->objects, &b->oid,
+ OBJ_COMMIT, &size, &b->oid);
parse_from_commit(b, buf, size);
free(buf);
}
@@ -2699,10 +2697,9 @@ static struct hash_list *parse_merge(unsigned int *count)
oidcpy(&n->oid, &oe->idx.oid);
} else if (!repo_get_oid(the_repository, from, &n->oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &n->oid,
- OBJ_COMMIT,
- &size, &n->oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &n->oid, OBJ_COMMIT,
+ &size, &n->oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", from);
free(buf);
diff --git a/builtin/grep.c b/builtin/grep.c
index 5de61dfffe8..39273d9c0fd 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -522,9 +522,7 @@ static int grep_submodule(struct grep_opt *opt,
obj_read_lock();
object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
- data = read_object_with_reference(subrepo,
- oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(subrepo->objects, oid, OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
@@ -705,9 +703,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
struct strbuf base;
int hit, len;
- data = read_object_with_reference(opt->repo,
- &obj->oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(opt->repo->objects, &obj->oid,
+ OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 06bdeb4223b..e88a13dbb9f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2055,8 +2055,8 @@ static void add_preferred_base(struct object_id *oid)
if (window <= num_preferred_base++)
return;
- data = read_object_with_reference(the_repository, oid,
- OBJ_TREE, &size, &tree_oid);
+ data = odb_read_object_peeled(the_repository->objects, oid,
+ OBJ_TREE, &size, &tree_oid);
if (!data)
return;
diff --git a/odb.c b/odb.c
index f6231a0556d..7d4db7cb49c 100644
--- a/odb.c
+++ b/odb.c
@@ -905,11 +905,11 @@ void *odb_read_object(struct object_database *odb,
return data;
}
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *actual_oid_return)
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *actual_oid_return)
{
enum object_type type;
void *buffer;
@@ -921,7 +921,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
+ buffer = odb_read_object(odb, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
@@ -941,9 +941,10 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + r->hash_algo->hexsz > isize ||
+ if (ref_length + odb->repo->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid,
+ odb->repo->hash_algo)) {
free(buffer);
return NULL;
}
diff --git a/odb.h b/odb.h
index e4c51f8c38e..e922f256802 100644
--- a/odb.h
+++ b/odb.h
@@ -274,6 +274,12 @@ void *odb_read_object(struct object_database *odb,
enum object_type *type,
unsigned long *size);
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *oid_ret);
+
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -382,7 +388,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: odb_read_object(),
- * read_object_with_reference(), odb_read_object_info() and odb().
+ * odb_read_object_peeled(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -431,13 +437,6 @@ enum for_each_object_flags {
FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
};
-
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *oid_ret);
-
/* Compatibility wrappers, to be removed once Git 2.51 has been released. */
#include "repository.h"
diff --git a/tree-walk.c b/tree-walk.c
index 766af99f466..e449a1320e5 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -90,7 +90,7 @@ void *fill_tree_descriptor(struct repository *r,
void *buf = NULL;
if (oid) {
- buf = read_object_with_reference(r, oid, OBJ_TREE, &size, NULL);
+ buf = odb_read_object_peeled(r->objects, oid, OBJ_TREE, &size, NULL);
if (!buf)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
}
@@ -611,7 +611,7 @@ int get_tree_entry(struct repository *r,
unsigned long size;
struct object_id root;
- tree = read_object_with_reference(r, tree_oid, OBJ_TREE, &size, &root);
+ tree = odb_read_object_peeled(r->objects, tree_oid, OBJ_TREE, &size, &root);
if (!tree)
return -1;
@@ -681,10 +681,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
void *tree;
struct object_id root;
unsigned long size;
- tree = read_object_with_reference(r,
- ¤t_tree_oid,
- OBJ_TREE, &size,
- &root);
+ tree = odb_read_object_peeled(r->objects, ¤t_tree_oid,
+ OBJ_TREE, &size, &root);
if (!tree)
goto done;
--
2.50.0.rc1.591.g9c95f17f64.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v5 17/17] odb: rename `read_object_with_reference()`
2025-06-05 6:47 ` [PATCH v5 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
@ 2025-06-30 3:15 ` Justin Tobler
0 siblings, 0 replies; 166+ messages in thread
From: Justin Tobler @ 2025-06-30 3:15 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On 25/06/05 08:47AM, Patrick Steinhardt wrote:
> Rename `read_object_with_reference()` to `odb_read_object_peeled()` to
> match other functions related to the object database and our modern
> coding guidelines. Furthermore though, the old name didn't really
> describe very well what this function actually does, which is to walk
> down any commit and tag objects until an object of the required type has
> been found. This is generally referred to as "peeling", so the new name
> should be way more descriptive.
>
> No compatibility wrapper is introduces as the function is not used a lot
> throughout our codebase.
Same small typo:
s/introduces/introduced/
The change itself looks good though :)
-Justin
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v6 00/17] object-store: carve out the object database subsystem
2025-05-06 11:09 [PATCH 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (22 preceding siblings ...)
2025-06-05 6:46 ` [PATCH v5 " Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
` (17 more replies)
23 siblings, 18 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Hi,
this patch series refactors the object store subsystem to become more
self-contained by getting rid of `the_repository`. Instead of passing in
the repository explicitly, we start to pass in the object store itself,
which is in contrast to many other refactorings we did, but in line with
what we did for the ref store, as well.
This series also starts to properly scope functions to the carved out
object database subsystem, which requires a bit of shuffling. This
allows us to have a short-and-sweet `odb_` prefix for functions and
prepares us for a future with pluggable object backends.
The series is structured as follows:
- Patches 1 to 3 rename `struct object_store` and `struct
object_directory` as well as the code files.
- Patches 4 to 12 refactor "odb.c" to get rid of `the_repository`.
- Patches 13 to 17 adjust the name of remaining functions so that they
can be clearly attributed to the ODB. I'm happy to kick these
patches out of this series and resend them at a later point in case
they create too much turmoil.
This series is built on top of 6f84262c44a (The eleventh batch,
2025-05-05) with ps/object-store-cleanup at 8a9e27be821 (object-store:
drop `repo_has_object_file()`, 2025-04-29) merged into it. There are a
couple of trivial conflicts when merged with "seen", I have appended the
merge conflict resolution as a patch at the end of this mail.
Changes in v2:
- Fix for a copy-and-pasted commit message.
- Rename `struct odb_backend` to `struct odb_alternate`. I'm happy to
revert to the previous name if we ultimately think it's the better
suited one.
- A couple of fixes to move changes into the correct commit. `git
rebase -x 'meson compile -C build'` is now clean.
- I _didn't_ back out the rename to "odb.{c,h}". Junio has already
fixed the fallout, so it's probably more work for him to kick it out
again than to just leave it in.
- Link to v1: https://lore.kernel.org/r/20250506-pks-object-store-wo-the-repository-v1-0-c05b82e7b126@pks.im
Changes in v3:
- Polishing for some comments and commit messages.
- Link to v2: https://lore.kernel.org/r/20250509-pks-object-store-wo-the-repository-v2-0-103f59bf8e28@pks.im
Changes in v4:
- Rebased the patch series on top of 7014b55638d (A bit more topics
for -rc1, 2025-05-30). This fixes a couple of merge conflicts, most
importantly with jk/no-funny-object-types.
- Rename `struct odb_alternate` to `odb_source`.
- Link to v3: https://lore.kernel.org/r/20250514-pks-object-store-wo-the-repository-v3-0-47df1d4ead22@pks.im
Changes in v5:
- Some polishing to fix leftover terminology from previous rounds.
- Link to v4: https://lore.kernel.org/r/20250602-pks-object-store-wo-the-repository-v4-0-e986804a7c62@pks.im
Changes in v6:
- Fix a mis-merged comment.
- A couple of commit message improvements.
- Link to v5: https://lore.kernel.org/r/20250605-pks-object-store-wo-the-repository-v5-0-779d1c28774b@pks.im
Thanks!
Patrick
---
Patrick Steinhardt (17):
object-store: rename `raw_object_store` to `object_database`
object-store: rename `object_directory` to `odb_source`
object-store: rename files to "odb.{c,h}"
odb: introduce parent pointers
odb: get rid of `the_repository` in `find_odb()`
odb: get rid of `the_repository` in `assert_oid_type()`
odb: get rid of `the_repository` in `odb_mkstemp()`
odb: get rid of `the_repository` when handling alternates
odb: get rid of `the_repository` in `for_each()` functions
odb: get rid of `the_repository` when handling the primary source
odb: get rid of `the_repository` when handling submodule sources
odb: trivial refactorings to get rid of `the_repository`
odb: rename `oid_object_info()`
odb: rename `repo_read_object_file()`
odb: rename `has_object()`
odb: rename `pretend_object_file()`
odb: rename `read_object_with_reference()`
Documentation/user-manual.adoc | 4 +-
Makefile | 2 +-
apply.c | 14 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 6 +-
attr.c | 4 +-
bisect.c | 8 +-
blame.c | 22 +-
builtin/backfill.c | 6 +-
builtin/blame.c | 6 +-
builtin/cat-file.c | 62 ++---
builtin/checkout.c | 2 +-
builtin/clone.c | 14 +-
builtin/commit-graph.c | 20 +-
builtin/commit-tree.c | 4 +-
builtin/count-objects.c | 6 +-
builtin/describe.c | 5 +-
builtin/difftool.c | 4 +-
builtin/fast-export.c | 10 +-
builtin/fast-import.c | 49 ++--
builtin/fetch.c | 21 +-
builtin/fsck.c | 31 ++-
builtin/gc.c | 16 +-
builtin/grep.c | 26 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 29 +-
builtin/log.c | 4 +-
builtin/ls-files.c | 4 +-
builtin/ls-tree.c | 6 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 14 +-
builtin/mktag.c | 6 +-
builtin/mktree.c | 10 +-
builtin/multi-pack-index.c | 6 +-
builtin/notes.c | 8 +-
builtin/pack-objects.c | 70 ++---
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 6 +-
builtin/receive-pack.c | 9 +-
builtin/remote.c | 6 +-
builtin/repack.c | 7 +-
builtin/replace.c | 12 +-
builtin/rev-list.c | 8 +-
builtin/show-ref.c | 6 +-
builtin/submodule--helper.c | 11 +-
builtin/tag.c | 10 +-
builtin/unpack-file.c | 4 +-
builtin/unpack-objects.c | 12 +-
bulk-checkin.c | 6 +-
bundle-uri.c | 5 +-
bundle.c | 6 +-
cache-tree.c | 17 +-
combine-diff.c | 4 +-
commit-graph.c | 106 +++----
commit-graph.h | 20 +-
commit.c | 15 +-
config.c | 4 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 12 +-
diff.c | 20 +-
dir.c | 2 +-
entry.c | 6 +-
fetch-pack.c | 17 +-
fmt-merge-msg.c | 6 +-
fsck.c | 4 +-
grep.c | 6 +-
http-backend.c | 2 +-
http-push.c | 20 +-
http-walker.c | 12 +-
http.c | 6 +-
list-objects-filter.c | 4 +-
list-objects.c | 6 +-
log-tree.c | 2 +-
loose.c | 46 ++--
mailmap.c | 4 +-
match-trees.c | 6 +-
merge-blobs.c | 10 +-
merge-ort.c | 8 +-
meson.build | 2 +-
midx-write.c | 2 +-
midx.c | 6 +-
notes-cache.c | 4 +-
notes-merge.c | 4 +-
notes.c | 19 +-
object-file.c | 94 +++----
object-file.h | 12 +-
object-name.c | 24 +-
object-store.h | 338 -----------------------
object.c | 8 +-
object-store.c => odb.c | 413 +++++++++++++++-------------
odb.h | 473 ++++++++++++++++++++++++++++++++
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 9 +-
pack-bitmap.c | 10 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
pack-write.c | 10 +-
packfile.c | 29 +-
packfile.h | 8 +-
path.c | 4 +-
promisor-remote.c | 6 +-
protocol-caps.c | 4 +-
reachable.c | 2 +-
read-cache.c | 14 +-
ref-filter.c | 6 +-
reflog.c | 8 +-
refs.c | 7 +-
remote.c | 9 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 21 +-
repository.h | 4 +-
rerere.c | 7 +-
revision.c | 5 +-
send-pack.c | 4 +-
sequencer.c | 7 +-
server-info.c | 2 +-
shallow.c | 14 +-
streaming.c | 10 +-
submodule-config.c | 9 +-
submodule.c | 32 +--
submodule.h | 9 -
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 4 +-
t/helper/test-read-graph.c | 8 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 4 +-
tag.c | 10 +-
tmp-objdir.c | 30 +-
tree-walk.c | 18 +-
tree.c | 6 +-
unpack-trees.c | 2 +-
upload-pack.c | 4 +-
walker.c | 6 +-
xdiff-interface.c | 4 +-
140 files changed, 1453 insertions(+), 1298 deletions(-)
Range-diff versus v5:
1: 9df738c135b = 1: 55efa04c9b5 object-store: rename `raw_object_store` to `object_database`
2: 85ee1dd80f0 = 2: 9e259ec9129 object-store: rename `object_directory` to `odb_source`
3: 8a9e759fcfa = 3: 4bef9e8ca2e object-store: rename files to "odb.{c,h}"
4: 872828f8061 ! 4: 4a82e103b22 odb: introduce parent pointers
@@ odb.c: static int link_alt_odb_entry(struct repository *r, const struct strbuf *
goto error;
CALLOC_ARRAY(alternate, 1);
-- /* pathbuf.buf is already in r->objects->source_by_path */
+ alternate->odb = odb;
-+ /* pathbuf.buf is already in r->objects->alternate_by_path */
+ /* pathbuf.buf is already in r->objects->source_by_path */
alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
5: bf292f80e6a = 5: d1096993665 odb: get rid of `the_repository` in `find_odb()`
6: 03f57d8efbc = 6: 8bd70f6e303 odb: get rid of `the_repository` in `assert_oid_type()`
7: 2aafcbaf706 = 7: 97cd748c462 odb: get rid of `the_repository` in `odb_mkstemp()`
8: 9a9eaa9fe0f ! 8: bfc550d81e6 odb: get rid of `the_repository` when handling alternates
@@ Commit message
odb: get rid of `the_repository` when handling alternates
The functions to manage alternates all depend on `the_repository`.
- Refactor them to accept an object database as parameter and adjusting
- all callers. The functions are renamed accordingly.
+ Refactor them to accept an object database as a parameter and adjust all
+ callers. The functions are renamed accordingly.
Note that right now the situation is still somewhat weird because we end
- up using the path provided by the object store's repository anyway. This
- will be adapted over time though so that we instead store the path to
- the primary object directory in the object database itself.
+ up using the object store path provided by the object store's repository
+ anyway. Consequently, we could have instead passed in a pointer to the
+ repository instead of passing in the pointer to the object store. This
+ will be addressed in subsequent commits though, where we will start to
+ use the path owned by the object store itself.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
9: 1618716a75f = 9: 34649c4cbe1 odb: get rid of `the_repository` in `for_each()` functions
10: 9c282be2a37 = 10: 5954680f7be odb: get rid of `the_repository` when handling the primary source
11: eb31130c720 = 11: 25b07546210 odb: get rid of `the_repository` when handling submodule sources
12: a5d6a5fb8a1 = 12: 945c95ba26c odb: trivial refactorings to get rid of `the_repository`
13: 61e3cb25aa2 = 13: 624c80b44cb odb: rename `oid_object_info()`
14: 1ab82f81ff5 = 14: 366c2733c69 odb: rename `repo_read_object_file()`
15: 427eb9893b9 = 15: cf287279010 odb: rename `has_object()`
16: bdf62e5cf47 ! 16: 42c14c70181 odb: rename `pretend_object_file()`
@@ Commit message
functions related to the object database and our modern coding
guidelines.
- No compatibility wrapper is introduces as the function is not used a lot
+ No compatibility wrapper is introduced as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
17: 550d4a75562 ! 17: ad0b56350b0 odb: rename `read_object_with_reference()`
@@ Commit message
been found. This is generally referred to as "peeling", so the new name
should be way more descriptive.
- No compatibility wrapper is introduces as the function is not used a lot
+ No compatibility wrapper is introduced as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
base-commit: 7014b55638da979331baf8dc31c4e1d697cf2d67
change-id: 20250505-pks-object-store-wo-the-repository-9c6cbdf8d4b1
^ permalink raw reply [flat|nested] 166+ messages in thread
* [PATCH v6 01/17] object-store: rename `raw_object_store` to `object_database`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 02/17] object-store: rename `object_directory` to `odb_source` Patrick Steinhardt
` (16 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The `raw_object_store` structure is the central entry point for reading
and writing objects in a repository. The main purpose of this structure
is to manage object directories and provide an interface to access and
write objects in those object directories.
Right now, many of the functions associated with the raw object store
implicitly rely on `the_repository` to get access to its `objects`
pointer, which is the `raw_object_store`. As we want to generally get
rid of using `the_repository` across our codebase we will have to
convert this implicit dependency on this global variable into an
explicit parameter.
This conversion can be done by simply passing in an explicit pointer to
a repository and then using its `->objects` pointer. But there is a
second effort underway, which is to make the object subsystem more
selfcontained so that we can eventually have pluggable object backends.
As such, passing in a repository wouldn't make a ton of sense, and the
goal is to convert the object store interfaces such that we always pass
in a reference to the `raw_object_store` instead.
This will expose the `raw_object_store` type to a lot more callers
though, which surfaces that this type is named somewhat awkwardly. The
"raw_" prefix makes readers wonder whether there is a non-raw variant of
the object store, but there isn't. Furthermore, we nowadays want to name
functions in a way that they can be clearly attributed to a specific
subsystem, but calling them e.g. `raw_object_store_has_object()` is just
too unwieldy, even when dropping the "raw_" prefix.
Instead, rename the structure to `object_database`. This term is already
used a lot throughout our codebase, and it cannot easily be mistaken for
"object directories", either. Furthermore, its acronym ODB is already
well-known and works well as part of a function's name, like for example
`odb_has_object()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
commit-graph.c | 2 +-
commit-graph.h | 4 ++--
object-store.c | 12 ++++++------
object-store.h | 11 ++++++++---
packfile.c | 2 +-
packfile.h | 4 ++--
repository.c | 4 ++--
repository.h | 4 ++--
8 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index ad3943b6906..905fcbdf0e8 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -829,7 +829,7 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
return NULL;
}
-void close_commit_graph(struct raw_object_store *o)
+void close_commit_graph(struct object_database *o)
{
if (!o->commit_graph)
return;
diff --git a/commit-graph.h b/commit-graph.h
index 13f662827d4..20d38c100ce 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -26,7 +26,7 @@ void git_test_write_commit_graph_or_die(void);
struct commit;
struct bloom_filter_settings;
struct repository;
-struct raw_object_store;
+struct object_database;
struct string_list;
char *get_commit_graph_filename(struct object_directory *odb);
@@ -186,7 +186,7 @@ int write_commit_graph(struct object_directory *odb,
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
-void close_commit_graph(struct raw_object_store *);
+void close_commit_graph(struct object_database *);
void free_commit_graph(struct commit_graph *);
/*
diff --git a/object-store.c b/object-store.c
index 58cde0313a5..f4e8f99d90f 100644
--- a/object-store.c
+++ b/object-store.c
@@ -44,7 +44,7 @@ struct cached_object_entry {
} value;
};
-static const struct cached_object *find_cached_object(struct raw_object_store *object_store,
+static const struct cached_object *find_cached_object(struct object_database *object_store,
const struct object_id *oid)
{
static const struct cached_object empty_tree = {
@@ -86,7 +86,7 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
/*
* Return non-zero iff the path is usable as an alternate object database.
*/
-static int alt_odb_usable(struct raw_object_store *o,
+static int alt_odb_usable(struct object_database *o,
struct strbuf *path,
const char *normalized_objdir, khiter_t *pos)
{
@@ -950,9 +950,9 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct raw_object_store *raw_object_store_new(void)
+struct object_database *odb_new(void)
{
- struct raw_object_store *o = xmalloc(sizeof(*o));
+ struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
INIT_LIST_HEAD(&o->packed_git_mru);
@@ -961,7 +961,7 @@ struct raw_object_store *raw_object_store_new(void)
return o;
}
-static void free_object_directories(struct raw_object_store *o)
+static void free_object_directories(struct object_database *o)
{
while (o->odb) {
struct object_directory *next;
@@ -974,7 +974,7 @@ static void free_object_directories(struct raw_object_store *o)
o->odb_by_path = NULL;
}
-void raw_object_store_clear(struct raw_object_store *o)
+void odb_clear(struct object_database *o)
{
FREE_AND_NULL(o->alternate_db);
diff --git a/object-store.h b/object-store.h
index c5890085352..a3be27d1171 100644
--- a/object-store.h
+++ b/object-store.h
@@ -87,7 +87,12 @@ struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
-struct raw_object_store {
+/*
+ * The object database encapsulates access to objects in a repository. It
+ * manages one or more backends that store the actual objects which are
+ * configured via alternates.
+ */
+struct object_database {
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -169,8 +174,8 @@ struct raw_object_store {
unsigned packed_git_initialized : 1;
};
-struct raw_object_store *raw_object_store_new(void);
-void raw_object_store_clear(struct raw_object_store *o);
+struct object_database *odb_new(void);
+void odb_clear(struct object_database *o);
/*
* Create a temporary file rooted in the object database directory, or
diff --git a/packfile.c b/packfile.c
index 70c7208f027..c735b4d0135 100644
--- a/packfile.c
+++ b/packfile.c
@@ -359,7 +359,7 @@ void close_pack(struct packed_git *p)
oidset_clear(&p->bad_objects);
}
-void close_object_store(struct raw_object_store *o)
+void close_object_store(struct object_database *o)
{
struct packed_git *p;
diff --git a/packfile.h b/packfile.h
index 3a3c77cf05a..826eb7f475f 100644
--- a/packfile.h
+++ b/packfile.h
@@ -183,12 +183,12 @@ int close_pack_fd(struct packed_git *p);
uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
-struct raw_object_store;
+struct object_database;
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
void close_pack_windows(struct packed_git *);
void close_pack(struct packed_git *);
-void close_object_store(struct raw_object_store *o);
+void close_object_store(struct object_database *o);
void unuse_pack(struct pack_window **);
void clear_delta_base_cache(void);
struct packed_git *add_packed_git(struct repository *r, const char *path,
diff --git a/repository.c b/repository.c
index 9b3d6665fc6..07757e6e0c9 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = raw_object_store_new();
+ repo->objects = odb_new();
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -374,7 +374,7 @@ void repo_clear(struct repository *repo)
FREE_AND_NULL(repo->worktree);
FREE_AND_NULL(repo->submodule_prefix);
- raw_object_store_clear(repo->objects);
+ odb_clear(repo->objects);
FREE_AND_NULL(repo->objects);
parsed_object_pool_clear(repo->parsed_objects);
diff --git a/repository.h b/repository.h
index c4c92b2ab9c..3a5ef9c781e 100644
--- a/repository.h
+++ b/repository.h
@@ -9,7 +9,7 @@ struct git_hash_algo;
struct index_state;
struct lock_file;
struct pathspec;
-struct raw_object_store;
+struct object_database;
struct submodule_cache;
struct promisor_remote_config;
struct remote_state;
@@ -47,7 +47,7 @@ struct repository {
/*
* Holds any information related to accessing the raw object content.
*/
- struct raw_object_store *objects;
+ struct object_database *objects;
/*
* All objects in this repository that have been parsed. This structure
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 02/17] object-store: rename `object_directory` to `odb_source`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
` (15 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The `object_directory` structure is used as an access point for a single
object directory like ".git/objects". While the structure isn't yet
fully self-contained, the intent is for it to eventually contain all
information required to access objects in one specific location.
While the name "object directory" is a good fit for now, this will
change over time as we continue with the agenda to make pluggable object
databases a thing. Eventually, objects may not be accessed via any kind
of directory at all anymore, but they could instead be backed by any
kind of durable storage mechanism. While it seems quite far-fetched for
now, it is thinkable that eventually this might even be some form of a
database, for example.
As such, the current name of this structure will become worse over time
as we evolve into the direction of pluggable ODBs. Immediate next steps
will start to carve out proper self-contained object directories, which
requires us to pass in these object directories as parameters. Based on
our modern naming schema this means that those functions should then be
named after their subsystem, which means that we would start to bake the
current name into the codebase more and more.
Let's preempt this by renaming the structure. There have been a couple
alternatives that were discussed:
- `odb_backend` was discarded because it led to the association that
one object database has a single backend, but the model is that one
alternate has one backend. Furthermore, "backend" is more about the
actual backing implementation and less about the high-level concept.
- `odb_alternate` was discarded because it is a bit of a stretch to
also call the main object directory an "alternate".
Instead, pick `odb_source` as the new name. It makes it sufficiently
clear that there can be multiple sources and does not cause confusion
when mixed with the already-existing "alternate" terminology.
In the future, this change allows us to easily introduce for example a
`odb_files_source` and other format-specific implementations.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 18 +++----
builtin/count-objects.c | 4 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 14 ++---
builtin/gc.c | 14 ++---
builtin/grep.c | 2 +-
builtin/multi-pack-index.c | 4 +-
builtin/submodule--helper.c | 6 +--
bundle.c | 2 +-
commit-graph.c | 94 +++++++++++++++++-----------------
commit-graph.h | 14 ++---
diagnose.c | 8 +--
http-walker.c | 2 +-
http.c | 4 +-
loose.c | 42 +++++++--------
midx.c | 6 +--
object-file.c | 80 ++++++++++++++---------------
object-file.h | 8 +--
object-name.c | 6 +--
object-store.c | 122 ++++++++++++++++++++++----------------------
object-store.h | 38 +++++++++-----
packfile.c | 16 +++---
path.c | 2 +-
refs.c | 2 +-
repository.c | 14 ++---
submodule-config.c | 2 +-
t/helper/test-read-graph.c | 6 +--
tmp-objdir.c | 24 ++++-----
28 files changed, 284 insertions(+), 272 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index a783a86e797..98a84315342 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb = NULL;
+ struct odb_source *source = NULL;
char *graph_name;
char *chain_name;
enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE;
@@ -101,9 +101,9 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- odb = find_odb(the_repository, opts.obj_dir);
- graph_name = get_commit_graph_filename(odb);
- chain_name = get_commit_graph_chain_filename(odb);
+ source = find_odb(the_repository, opts.obj_dir);
+ graph_name = get_commit_graph_filename(source);
+ chain_name = get_commit_graph_chain_filename(source);
if (open_commit_graph(graph_name, &fd, &st))
opened = OPENED_GRAPH;
else if (errno != ENOENT)
@@ -120,7 +120,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opened == OPENED_NONE)
return 0;
else if (opened == OPENED_GRAPH)
- graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb);
+ graph = load_commit_graph_one_fd_st(the_repository, fd, &st, source);
else
graph = load_commit_graph_chain_fd_st(the_repository, fd, &st,
&incomplete_chain);
@@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
struct string_list pack_indexes = STRING_LIST_INIT_DUP;
struct strbuf buf = STRBUF_INIT;
struct oidset commits = OIDSET_INIT;
- struct object_directory *odb = NULL;
+ struct odb_source *source = NULL;
int result = 0;
enum commit_graph_write_flags flags = 0;
struct progress *progress = NULL;
@@ -289,10 +289,10 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- odb = find_odb(the_repository, opts.obj_dir);
+ source = find_odb(the_repository, opts.obj_dir);
if (opts.reachable) {
- if (write_commit_graph_reachable(odb, flags, &write_opts))
+ if (write_commit_graph_reachable(source, flags, &write_opts))
result = 1;
goto cleanup;
}
@@ -318,7 +318,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
stop_progress(&progress);
}
- if (write_commit_graph(odb,
+ if (write_commit_graph(source,
opts.stdin_packs ? &pack_indexes : NULL,
opts.stdin_commits ? &commits : NULL,
flags,
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index a88c0c9c09a..58e0af433d1 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -80,10 +80,10 @@ static int count_cruft(const char *basename UNUSED, const char *path,
return 0;
}
-static int print_alternate(struct object_directory *odb, void *data UNUSED)
+static int print_alternate(struct odb_source *alternate, void *data UNUSED)
{
printf("alternate: ");
- quote_c_style(odb->path, NULL, stdout, 0);
+ quote_c_style(alternate->path, NULL, stdout, 0);
putchar('\n');
return 0;
}
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 40a0e8d2443..a890e2864d1 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2653,7 +2653,7 @@ int cmd_fetch(int argc,
commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
trace2_region_enter("fetch", "write-commit-graph", the_repository);
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->sources,
commit_graph_flags,
NULL);
trace2_region_leave("fetch", "write-commit-graph", the_repository);
diff --git a/builtin/fsck.c b/builtin/fsck.c
index e7d96a9c8ea..6e1474f63d5 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -956,7 +956,7 @@ int cmd_fsck(int argc,
struct repository *repo UNUSED)
{
int i;
- struct object_directory *odb;
+ struct odb_source *source;
/* fsck knows how to handle missing promisor objects */
fetch_if_missing = 0;
@@ -998,8 +998,8 @@ int cmd_fsck(int argc,
mark_packed_for_connectivity, NULL, 0);
} else {
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next)
- fsck_object_dir(odb->path);
+ for (source = the_repository->objects->sources; source; source = source->next)
+ fsck_object_dir(source->path);
if (check_full) {
struct packed_git *p;
@@ -1109,11 +1109,11 @@ int cmd_fsck(int argc,
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
strvec_pushl(&commit_graph_verify.args, "commit-graph",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", source->path, NULL);
if (show_progress)
strvec_push(&commit_graph_verify.args, "--progress");
else
@@ -1127,11 +1127,11 @@ int cmd_fsck(int argc,
struct child_process midx_verify = CHILD_PROCESS_INIT;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
+ for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
- "verify", "--object-dir", odb->path, NULL);
+ "verify", "--object-dir", source->path, NULL);
if (show_progress)
strvec_push(&midx_verify.args, "--progress");
else
diff --git a/builtin/gc.c b/builtin/gc.c
index e33ba946e43..50a09eb07e3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1018,7 +1018,7 @@ int cmd_gc(int argc,
}
if (the_repository->settings.gc_write_commit_graph == 1)
- write_commit_graph_reachable(the_repository->objects->odb,
+ write_commit_graph_reachable(the_repository->objects->sources,
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
NULL);
@@ -1271,7 +1271,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
if (loose_object_auto_limit < 0)
return 1;
- return for_each_loose_file_in_objdir(the_repository->objects->odb->path,
+ return for_each_loose_file_in_objdir(the_repository->objects->sources->path,
loose_object_count,
NULL, NULL, &count);
}
@@ -1306,7 +1306,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
* Do not start pack-objects process
* if there are no loose objects.
*/
- if (!for_each_loose_file_in_objdir(r->objects->odb->path,
+ if (!for_each_loose_file_in_objdir(r->objects->sources->path,
bail_on_loose,
NULL, NULL, NULL))
return 0;
@@ -1318,7 +1318,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
strvec_push(&pack_proc.args, "--quiet");
else
strvec_push(&pack_proc.args, "--no-quiet");
- strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
+ strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->sources->path);
pack_proc.in = -1;
@@ -1346,7 +1346,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
else if (data.batch_size > 0)
data.batch_size--; /* Decrease for equality on limit. */
- for_each_loose_file_in_objdir(r->objects->odb->path,
+ for_each_loose_file_in_objdir(r->objects->sources->path,
write_loose_object_to_stdin,
NULL,
NULL,
@@ -1611,7 +1611,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
int result = 0;
struct lock_file lk;
struct repository *r = the_repository;
- char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path);
+ char *lock_path = xstrfmt("%s/maintenance", r->objects->sources->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
/*
@@ -3083,7 +3083,7 @@ static int update_background_schedule(const struct maintenance_start_opts *opts,
unsigned int i;
int result = 0;
struct lock_file lk;
- char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path);
+ char *lock_path = xstrfmt("%s/schedule", the_repository->objects->sources->path);
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
if (errno == EEXIST)
diff --git a/builtin/grep.c b/builtin/grep.c
index 3ce574a605b..76b1938bba5 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,7 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->odb->path);
+ add_submodule_odb_by_path(subrepo->objects->sources->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 69a97507324..f55bf53da83 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -294,8 +294,8 @@ int cmd_multi_pack_index(int argc,
if (the_repository &&
the_repository->objects &&
- the_repository->objects->odb)
- opts.object_dir = xstrdup(the_repository->objects->odb->path);
+ the_repository->objects->sources)
+ opts.object_dir = xstrdup(the_repository->objects->sources->path);
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 53da2116ddf..758bc6d0f24 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1582,7 +1582,7 @@ static const char alternate_error_advice[] = N_(
);
static int add_possible_reference_from_superproject(
- struct object_directory *odb, void *sas_cb)
+ struct odb_source *alt_odb, void *sas_cb)
{
struct submodule_alternate_setup *sas = sas_cb;
size_t len;
@@ -1591,12 +1591,12 @@ static int add_possible_reference_from_superproject(
* If the alternate object store is another repository, try the
* standard layout with .git/(modules/<name>)+/objects
*/
- if (strip_suffix(odb->path, "/objects", &len)) {
+ if (strip_suffix(alt_odb->path, "/objects", &len)) {
struct repository alternate;
char *sm_alternate;
struct strbuf sb = STRBUF_INIT;
struct strbuf err = STRBUF_INIT;
- strbuf_add(&sb, odb->path, len);
+ strbuf_add(&sb, alt_odb->path, len);
if (repo_init(&alternate, sb.buf, NULL) < 0)
die(_("could not get a repository handle for gitdir '%s'"),
diff --git a/bundle.c b/bundle.c
index b0a3fee2efa..2ce7525f90d 100644
--- a/bundle.c
+++ b/bundle.c
@@ -233,7 +233,7 @@ int verify_bundle(struct repository *r,
.quiet = 1,
};
- if (!r || !r->objects || !r->objects->odb)
+ if (!r || !r->objects || !r->objects->sources)
return error(_("need a repository to verify a bundle"));
for (i = 0; i < p->nr; i++) {
diff --git a/commit-graph.c b/commit-graph.c
index 905fcbdf0e8..12d32cdad1d 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -37,7 +37,7 @@ void git_test_write_commit_graph_or_die(void)
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- if (write_commit_graph_reachable(the_repository->objects->odb,
+ if (write_commit_graph_reachable(the_repository->objects->sources,
flags, NULL))
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
}
@@ -191,21 +191,21 @@ static int commit_gen_cmp(const void *va, const void *vb)
return 0;
}
-char *get_commit_graph_filename(struct object_directory *obj_dir)
+char *get_commit_graph_filename(struct odb_source *source)
{
- return xstrfmt("%s/info/commit-graph", obj_dir->path);
+ return xstrfmt("%s/info/commit-graph", source->path);
}
-static char *get_split_graph_filename(struct object_directory *odb,
+static char *get_split_graph_filename(struct odb_source *source,
const char *oid_hex)
{
- return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb->path,
+ return xstrfmt("%s/info/commit-graphs/graph-%s.graph", source->path,
oid_hex);
}
-char *get_commit_graph_chain_filename(struct object_directory *odb)
+char *get_commit_graph_chain_filename(struct odb_source *source)
{
- return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
+ return xstrfmt("%s/info/commit-graphs/commit-graph-chain", source->path);
}
static struct commit_graph *alloc_commit_graph(void)
@@ -250,7 +250,7 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb)
+ struct odb_source *source)
{
void *graph_map;
size_t graph_size;
@@ -269,7 +269,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
ret = parse_commit_graph(&r->settings, graph_map, graph_size);
if (ret)
- ret->odb = odb;
+ ret->odb_source = source;
else
munmap(graph_map, graph_size);
@@ -487,7 +487,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
static struct commit_graph *load_commit_graph_one(struct repository *r,
const char *graph_file,
- struct object_directory *odb)
+ struct odb_source *source)
{
struct stat st;
@@ -498,7 +498,7 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
if (!open_ok)
return NULL;
- g = load_commit_graph_one_fd_st(r, fd, &st, odb);
+ g = load_commit_graph_one_fd_st(r, fd, &st, source);
if (g)
g->filename = xstrdup(graph_file);
@@ -507,10 +507,10 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
}
static struct commit_graph *load_commit_graph_v1(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- char *graph_name = get_commit_graph_filename(odb);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ char *graph_name = get_commit_graph_filename(source);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
free(graph_name);
return g;
@@ -652,7 +652,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
prepare_alt_odb(r);
for (i = 0; i < count; i++) {
- struct object_directory *odb;
+ struct odb_source *source;
if (strbuf_getline_lf(&line, fp) == EOF)
break;
@@ -665,9 +665,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
valid = 0;
- for (odb = r->objects->odb; odb; odb = odb->next) {
- char *graph_name = get_split_graph_filename(odb, line.buf);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ for (source = r->objects->sources; source; source = source->next) {
+ char *graph_name = get_split_graph_filename(source, line.buf);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
free(graph_name);
@@ -701,9 +701,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
static struct commit_graph *load_commit_graph_chain(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- char *chain_file = get_commit_graph_chain_filename(odb);
+ char *chain_file = get_commit_graph_chain_filename(source);
struct stat st;
int fd;
struct commit_graph *g = NULL;
@@ -719,24 +719,24 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
}
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- struct commit_graph *g = load_commit_graph_v1(r, odb);
+ struct commit_graph *g = load_commit_graph_v1(r, source);
if (!g)
- g = load_commit_graph_chain(r, odb);
+ g = load_commit_graph_chain(r, source);
return g;
}
static void prepare_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
if (r->objects->commit_graph)
return;
- r->objects->commit_graph = read_commit_graph_one(r, odb);
+ r->objects->commit_graph = read_commit_graph_one(r, source);
}
/*
@@ -747,7 +747,7 @@ static void prepare_commit_graph_one(struct repository *r,
*/
static int prepare_commit_graph(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_source *source;
/*
* Early return if there is no git dir or if the commit graph is
@@ -779,10 +779,10 @@ static int prepare_commit_graph(struct repository *r)
return 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb;
- !r->objects->commit_graph && odb;
- odb = odb->next)
- prepare_commit_graph_one(r, odb);
+ for (source = r->objects->sources;
+ !r->objects->commit_graph && source;
+ source = source->next)
+ prepare_commit_graph_one(r, source);
return !!r->objects->commit_graph;
}
@@ -1137,7 +1137,7 @@ struct packed_commit_list {
struct write_commit_graph_context {
struct repository *r;
- struct object_directory *odb;
+ struct odb_source *odb_source;
char *graph_name;
struct oid_array oids;
struct packed_commit_list commits;
@@ -1870,7 +1870,7 @@ static int add_ref_to_set(const char *refname UNUSED,
return 0;
}
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_source *source,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts)
{
@@ -1890,7 +1890,7 @@ int write_commit_graph_reachable(struct object_directory *odb,
stop_progress(&data.progress);
- result = write_commit_graph(odb, NULL, &commits,
+ result = write_commit_graph(source, NULL, &commits,
flags, opts);
oidset_clear(&commits);
@@ -1906,7 +1906,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
int dirlen;
int ret = 0;
- strbuf_addf(&packname, "%s/pack/", ctx->odb->path);
+ strbuf_addf(&packname, "%s/pack/", ctx->odb_source->path);
dirlen = packname.len;
if (ctx->report_progress) {
strbuf_addf(&progress_title,
@@ -2060,10 +2060,10 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
strbuf_addf(&tmp_file,
"%s/info/commit-graphs/tmp_graph_XXXXXX",
- ctx->odb->path);
+ ctx->odb_source->path);
ctx->graph_name = strbuf_detach(&tmp_file, NULL);
} else {
- ctx->graph_name = get_commit_graph_filename(ctx->odb);
+ ctx->graph_name = get_commit_graph_filename(ctx->odb_source);
}
if (safe_create_leading_directories(the_repository, ctx->graph_name)) {
@@ -2073,7 +2073,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
if (ctx->split) {
- char *lock_name = get_commit_graph_chain_filename(ctx->odb);
+ char *lock_name = get_commit_graph_chain_filename(ctx->odb_source);
hold_lock_file_for_update_mode(&lk, lock_name,
LOCK_DIE_ON_ERROR, 0444);
@@ -2161,7 +2161,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
char *new_base_hash = xstrdup(oid_to_hex(&ctx->new_base_graph->oid));
- char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb, new_base_hash);
+ char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb_source, new_base_hash);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 2]);
@@ -2201,14 +2201,14 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
}
} else {
- char *graph_name = get_commit_graph_filename(ctx->odb);
+ char *graph_name = get_commit_graph_filename(ctx->odb_source);
unlink(graph_name);
free(graph_name);
}
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(hash_to_hex(file_hash));
- final_graph_name = get_split_graph_filename(ctx->odb,
+ final_graph_name = get_split_graph_filename(ctx->odb_source,
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1] = final_graph_name;
@@ -2259,7 +2259,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
flags != COMMIT_GRAPH_SPLIT_REPLACE) {
while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
(max_commits && num_commits > max_commits))) {
- if (g->odb != ctx->odb)
+ if (g->odb_source != ctx->odb_source)
break;
if (unsigned_add_overflows(num_commits, g->num_commits))
@@ -2281,10 +2281,10 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
"should be 1 with --split=replace");
if (ctx->num_commit_graphs_after == 2) {
- char *old_graph_name = get_commit_graph_filename(g->odb);
+ char *old_graph_name = get_commit_graph_filename(g->odb_source);
if (!strcmp(g->filename, old_graph_name) &&
- g->odb != ctx->odb) {
+ g->odb_source != ctx->odb_source) {
ctx->num_commit_graphs_after = 1;
ctx->new_base_graph = NULL;
}
@@ -2456,13 +2456,13 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
if (ctx->opts && ctx->opts->expire_time)
expire_time = ctx->opts->expire_time;
if (!ctx->split) {
- char *chain_file_name = get_commit_graph_chain_filename(ctx->odb);
+ char *chain_file_name = get_commit_graph_chain_filename(ctx->odb_source);
unlink(chain_file_name);
free(chain_file_name);
ctx->num_commit_graphs_after = 0;
}
- strbuf_addstr(&path, ctx->odb->path);
+ strbuf_addstr(&path, ctx->odb_source->path);
strbuf_addstr(&path, "/info/commit-graphs");
dir = opendir(path.buf);
@@ -2504,7 +2504,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
strbuf_release(&path);
}
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_source *source,
const struct string_list *const pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
@@ -2513,7 +2513,7 @@ int write_commit_graph(struct object_directory *odb,
struct repository *r = the_repository;
struct write_commit_graph_context ctx = {
.r = r,
- .odb = odb,
+ .odb_source = source,
.append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0,
.report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0,
.split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0,
diff --git a/commit-graph.h b/commit-graph.h
index 20d38c100ce..0e661db1b54 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -29,8 +29,8 @@ struct repository;
struct object_database;
struct string_list;
-char *get_commit_graph_filename(struct object_directory *odb);
-char *get_commit_graph_chain_filename(struct object_directory *odb);
+char *get_commit_graph_filename(struct odb_source *source);
+char *get_commit_graph_chain_filename(struct odb_source *source);
int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st);
@@ -89,7 +89,7 @@ struct commit_graph {
uint32_t num_commits;
struct object_id oid;
char *filename;
- struct object_directory *odb;
+ struct odb_source *odb_source;
uint32_t num_commits_in_base;
unsigned int read_generation_data;
@@ -115,12 +115,12 @@ struct commit_graph {
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb);
+ struct odb_source *source);
struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
int fd, struct stat *st,
int *incomplete_chain);
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb);
+ struct odb_source *source);
struct repo_settings;
@@ -173,10 +173,10 @@ struct commit_graph_opts {
* is not compatible with the commit-graph feature, then the
* methods will return 0 without writing a commit-graph.
*/
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_source *source,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts);
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_source *source,
const struct string_list *pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
diff --git a/diagnose.c b/diagnose.c
index b1be74be983..d08d5643aac 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -59,13 +59,13 @@ static void dir_file_stats_objects(const char *full_path,
(uintmax_t)st.st_size);
}
-static int dir_file_stats(struct object_directory *object_dir, void *data)
+static int dir_file_stats(struct odb_source *source, void *data)
{
struct strbuf *buf = data;
- strbuf_addf(buf, "Contents of %s:\n", object_dir->path);
+ strbuf_addf(buf, "Contents of %s:\n", source->path);
- for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects,
+ for_each_file_in_pack_dir(source->path, dir_file_stats_objects,
data);
return 0;
@@ -228,7 +228,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(r->objects->odb, &buf);
+ dir_file_stats(r->objects->sources, &buf);
foreach_alt_odb(dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
diff --git a/http-walker.c b/http-walker.c
index 463f7b119ad..c374e6b2056 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
ret = error("File %s has bad hash", hex);
} else if (req->rename < 0) {
struct strbuf buf = STRBUF_INIT;
- odb_loose_path(the_repository->objects->odb, &buf, &req->oid);
+ odb_loose_path(the_repository->objects->sources, &buf, &req->oid);
ret = error("unable to write sha1 filename %s", buf.buf);
strbuf_release(&buf);
}
diff --git a/http.c b/http.c
index 3c029cf8947..5e15bbab3f1 100644
--- a/http.c
+++ b/http.c
@@ -2662,7 +2662,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
oidcpy(&freq->oid, oid);
freq->localfile = -1;
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2814,7 +2814,7 @@ int finish_http_object_request(struct http_object_request *freq)
unlink_or_warn(freq->tmpfile.buf);
return -1;
}
- odb_loose_path(the_repository->objects->odb, &filename, &freq->oid);
+ odb_loose_path(the_repository->objects->sources, &filename, &freq->oid);
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
strbuf_release(&filename);
diff --git a/loose.c b/loose.c
index bb602aaa366..fe65d5b9b0f 100644
--- a/loose.c
+++ b/loose.c
@@ -44,36 +44,36 @@ static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *key, const
return 1;
}
-static int insert_loose_map(struct object_directory *odb,
+static int insert_loose_map(struct odb_source *source,
const struct object_id *oid,
const struct object_id *compat_oid)
{
- struct loose_object_map *map = odb->loose_map;
+ struct loose_object_map *map = source->loose_map;
int inserted = 0;
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
if (inserted)
- oidtree_insert(odb->loose_objects_cache, compat_oid);
+ oidtree_insert(source->loose_objects_cache, compat_oid);
return inserted;
}
-static int load_one_loose_object_map(struct repository *repo, struct object_directory *dir)
+static int load_one_loose_object_map(struct repository *repo, struct odb_source *source)
{
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
FILE *fp;
- if (!dir->loose_map)
- loose_object_map_init(&dir->loose_map);
- if (!dir->loose_objects_cache) {
- ALLOC_ARRAY(dir->loose_objects_cache, 1);
- oidtree_init(dir->loose_objects_cache);
+ if (!source->loose_map)
+ loose_object_map_init(&source->loose_map);
+ if (!source->loose_objects_cache) {
+ ALLOC_ARRAY(source->loose_objects_cache, 1);
+ oidtree_init(source->loose_objects_cache);
}
- insert_loose_map(dir, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
- insert_loose_map(dir, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
- insert_loose_map(dir, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
+ insert_loose_map(source, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
+ insert_loose_map(source, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
+ insert_loose_map(source, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
repo_common_path_replace(repo, &path, "objects/loose-object-idx");
fp = fopen(path.buf, "rb");
@@ -93,7 +93,7 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
parse_oid_hex_algop(p, &compat_oid, &p, repo->compat_hash_algo) ||
p != buf.buf + buf.len)
goto err;
- insert_loose_map(dir, &oid, &compat_oid);
+ insert_loose_map(source, &oid, &compat_oid);
}
strbuf_release(&buf);
@@ -107,15 +107,15 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
int repo_read_loose_object_map(struct repository *repo)
{
- struct object_directory *dir;
+ struct odb_source *source;
if (!should_use_loose_object_map(repo))
return 0;
prepare_alt_odb(repo);
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- if (load_one_loose_object_map(repo, dir) < 0) {
+ for (source = repo->objects->sources; source; source = source->next) {
+ if (load_one_loose_object_map(repo, source) < 0) {
return -1;
}
}
@@ -124,7 +124,7 @@ int repo_read_loose_object_map(struct repository *repo)
int repo_write_loose_object_map(struct repository *repo)
{
- kh_oid_map_t *map = repo->objects->odb->loose_map->to_compat;
+ kh_oid_map_t *map = repo->objects->sources->loose_map->to_compat;
struct lock_file lock;
int fd;
khiter_t iter;
@@ -212,7 +212,7 @@ int repo_add_loose_object_map(struct repository *repo, const struct object_id *o
if (!should_use_loose_object_map(repo))
return 0;
- inserted = insert_loose_map(repo->objects->odb, oid, compat_oid);
+ inserted = insert_loose_map(repo->objects->sources, oid, compat_oid);
if (inserted)
return write_one_object(repo, oid, compat_oid);
return 0;
@@ -223,12 +223,12 @@ int repo_loose_object_map_oid(struct repository *repo,
const struct git_hash_algo *to,
struct object_id *dest)
{
- struct object_directory *dir;
+ struct odb_source *source;
kh_oid_map_t *map;
khiter_t pos;
- for (dir = repo->objects->odb; dir; dir = dir->next) {
- struct loose_object_map *loose_map = dir->loose_map;
+ for (source = repo->objects->sources; source; source = source->next) {
+ struct loose_object_map *loose_map = source->loose_map;
if (!loose_map)
continue;
map = (to == repo->compat_hash_algo) ?
diff --git a/midx.c b/midx.c
index cd6e766ce2b..3c5bc821730 100644
--- a/midx.c
+++ b/midx.c
@@ -832,7 +832,7 @@ void clear_midx_file(struct repository *r)
{
struct strbuf midx = STRBUF_INIT;
- get_midx_filename(r->hash_algo, &midx, r->objects->odb->path);
+ get_midx_filename(r->hash_algo, &midx, r->objects->sources->path);
if (r->objects && r->objects->multi_pack_index) {
close_midx(r->objects->multi_pack_index);
@@ -842,8 +842,8 @@ void clear_midx_file(struct repository *r)
if (remove_path(midx.buf))
die(_("failed to clear multi-pack-index at %s"), midx.buf);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_BITMAP, NULL);
- clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_REV, NULL);
+ clear_midx_files_ext(r->objects->sources->path, MIDX_EXT_BITMAP, NULL);
+ clear_midx_files_ext(r->objects->sources->path, MIDX_EXT_REV, NULL);
strbuf_release(&midx);
}
diff --git a/object-file.c b/object-file.c
index 1ac04c28916..6bad1d3dd1c 100644
--- a/object-file.c
+++ b/object-file.c
@@ -55,12 +55,12 @@ static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
}
}
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_source *source,
struct strbuf *buf,
const struct object_id *oid)
{
strbuf_reset(buf);
- strbuf_addstr(buf, odb->path);
+ strbuf_addstr(buf, source->path);
strbuf_addch(buf, '/');
fill_loose_path(buf, oid);
return buf->buf;
@@ -88,27 +88,27 @@ int check_and_freshen_file(const char *fn, int freshen)
return 1;
}
-static int check_and_freshen_odb(struct object_directory *odb,
+static int check_and_freshen_odb(struct odb_source *source,
const struct object_id *oid,
int freshen)
{
static struct strbuf path = STRBUF_INIT;
- odb_loose_path(odb, &path, oid);
+ odb_loose_path(source, &path, oid);
return check_and_freshen_file(path.buf, freshen);
}
static int check_and_freshen_local(const struct object_id *oid, int freshen)
{
- return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
+ return check_and_freshen_odb(the_repository->objects->sources, oid, freshen);
}
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
- if (check_and_freshen_odb(odb, oid, freshen))
+ for (source = the_repository->objects->sources->next; source; source = source->next) {
+ if (check_and_freshen_odb(source, oid, freshen))
return 1;
}
return 0;
@@ -202,12 +202,12 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct stat *st, const char **path)
{
- struct object_directory *odb;
+ struct odb_source *source;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (source = r->objects->sources; source; source = source->next) {
+ *path = odb_loose_path(source, &buf, oid);
if (!lstat(*path, st))
return 0;
}
@@ -223,13 +223,13 @@ static int open_loose_object(struct repository *r,
const struct object_id *oid, const char **path)
{
int fd;
- struct object_directory *odb;
+ struct odb_source *source;
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (source = r->objects->sources; source; source = source->next) {
+ *path = odb_loose_path(source, &buf, oid);
fd = git_open(*path);
if (fd >= 0)
return fd;
@@ -244,11 +244,11 @@ static int open_loose_object(struct repository *r,
static int quick_has_loose(struct repository *r,
const struct object_id *oid)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- if (oidtree_contains(odb_loose_cache(odb, oid), oid))
+ for (source = r->objects->sources; source; source = source->next) {
+ if (oidtree_contains(odb_loose_cache(source, oid), oid))
return 1;
}
return 0;
@@ -694,7 +694,7 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
/* Finalize a file on disk, and close it. */
static void close_loose_object(int fd, const char *filename)
{
- if (the_repository->objects->odb->will_destroy)
+ if (the_repository->objects->sources->will_destroy)
goto out;
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
@@ -876,7 +876,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
prepare_loose_object_bulk_checkin();
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
fd = start_loose_object_common(&tmp_file, filename.buf, flags,
&stream, compressed, sizeof(compressed),
@@ -1023,7 +1023,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
goto cleanup;
}
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
/* We finally know the object path, and create the missing dir. */
dirlen = directory_size(filename.buf);
@@ -1437,11 +1437,11 @@ int for_each_loose_file_in_objdir(const char *path,
int for_each_loose_object(each_loose_object_fn cb, void *data,
enum for_each_object_flags flags)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
- int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
+ for (source = the_repository->objects->sources; source; source = source->next) {
+ int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
NULL, data);
if (r)
return r;
@@ -1461,43 +1461,43 @@ static int append_loose_object(const struct object_id *oid,
return 0;
}
-struct oidtree *odb_loose_cache(struct object_directory *odb,
- const struct object_id *oid)
+struct oidtree *odb_loose_cache(struct odb_source *source,
+ const struct object_id *oid)
{
int subdir_nr = oid->hash[0];
struct strbuf buf = STRBUF_INIT;
- size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
+ size_t word_bits = bitsizeof(source->loose_objects_subdir_seen[0]);
size_t word_index = subdir_nr / word_bits;
size_t mask = (size_t)1u << (subdir_nr % word_bits);
uint32_t *bitmap;
if (subdir_nr < 0 ||
- subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
+ subdir_nr >= bitsizeof(source->loose_objects_subdir_seen))
BUG("subdir_nr out of range");
- bitmap = &odb->loose_objects_subdir_seen[word_index];
+ bitmap = &source->loose_objects_subdir_seen[word_index];
if (*bitmap & mask)
- return odb->loose_objects_cache;
- if (!odb->loose_objects_cache) {
- ALLOC_ARRAY(odb->loose_objects_cache, 1);
- oidtree_init(odb->loose_objects_cache);
+ return source->loose_objects_cache;
+ if (!source->loose_objects_cache) {
+ ALLOC_ARRAY(source->loose_objects_cache, 1);
+ oidtree_init(source->loose_objects_cache);
}
- strbuf_addstr(&buf, odb->path);
+ strbuf_addstr(&buf, source->path);
for_each_file_in_obj_subdir(subdir_nr, &buf,
append_loose_object,
NULL, NULL,
- odb->loose_objects_cache);
+ source->loose_objects_cache);
*bitmap |= mask;
strbuf_release(&buf);
- return odb->loose_objects_cache;
+ return source->loose_objects_cache;
}
-void odb_clear_loose_cache(struct object_directory *odb)
+void odb_clear_loose_cache(struct odb_source *source)
{
- oidtree_clear(odb->loose_objects_cache);
- FREE_AND_NULL(odb->loose_objects_cache);
- memset(&odb->loose_objects_subdir_seen, 0,
- sizeof(odb->loose_objects_subdir_seen));
+ oidtree_clear(source->loose_objects_cache);
+ FREE_AND_NULL(source->loose_objects_cache);
+ memset(&source->loose_objects_subdir_seen, 0,
+ sizeof(source->loose_objects_subdir_seen));
}
static int check_stream_oid(git_zstream *stream,
diff --git a/object-file.h b/object-file.h
index 6f411424523..9a18859b2e0 100644
--- a/object-file.h
+++ b/object-file.h
@@ -24,23 +24,23 @@ enum {
int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
-struct object_directory;
+struct odb_source;
/*
* Populate and return the loose object cache array corresponding to the
* given object ID.
*/
-struct oidtree *odb_loose_cache(struct object_directory *odb,
+struct oidtree *odb_loose_cache(struct odb_source *source,
const struct object_id *oid);
/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
+void odb_clear_loose_cache(struct odb_source *source);
/*
* Put in `buf` the name of the file in the local object database that
* would be used to store a loose object with the specified oid.
*/
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_source *source,
struct strbuf *buf,
const struct object_id *oid);
diff --git a/object-name.c b/object-name.c
index 9288b2dd245..544634d0f40 100644
--- a/object-name.c
+++ b/object-name.c
@@ -112,10 +112,10 @@ static enum cb_next match_prefix(const struct object_id *oid, void *arg)
static void find_short_object_filename(struct disambiguate_state *ds)
{
- struct object_directory *odb;
+ struct odb_source *source;
- for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next)
- oidtree_each(odb_loose_cache(odb, &ds->bin_pfx),
+ for (source = ds->repo->objects->sources; source && !ds->ambiguous; source = source->next)
+ oidtree_each(odb_loose_cache(source, &ds->bin_pfx),
&ds->bin_pfx, ds->len, match_prefix, ds);
}
diff --git a/object-store.c b/object-store.c
index f4e8f99d90f..5c04a1018f7 100644
--- a/object-store.c
+++ b/object-store.c
@@ -27,7 +27,7 @@
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
- struct object_directory *, 1, fspathhash, fspatheq)
+ struct odb_source *, 1, fspathhash, fspatheq)
/*
* This is meant to hold a *small* number of objects that you would
@@ -104,18 +104,18 @@ static int alt_odb_usable(struct object_database *o,
* Prevent the common mistake of listing the same
* thing twice, or object directory itself.
*/
- if (!o->odb_by_path) {
+ if (!o->source_by_path) {
khiter_t p;
- o->odb_by_path = kh_init_odb_path_map();
- assert(!o->odb->next);
- p = kh_put_odb_path_map(o->odb_by_path, o->odb->path, &r);
+ o->source_by_path = kh_init_odb_path_map();
+ assert(!o->sources->next);
+ p = kh_put_odb_path_map(o->source_by_path, o->sources->path, &r);
assert(r == 1); /* never used */
- kh_value(o->odb_by_path, p) = o->odb;
+ kh_value(o->source_by_path, p) = o->sources;
}
if (fspatheq(path->buf, normalized_objdir))
return 0;
- *pos = kh_put_odb_path_map(o->odb_by_path, path->buf, &r);
+ *pos = kh_put_odb_path_map(o->source_by_path, path->buf, &r);
/* r: 0 = exists, 1 = never used, 2 = deleted */
return r == 0 ? 0 : 1;
}
@@ -124,7 +124,7 @@ static int alt_odb_usable(struct object_database *o,
* Prepare alternate object database registry.
*
* The variable alt_odb_list points at the list of struct
- * object_directory. The elements on this list come from
+ * odb_source. The elements on this list come from
* non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
* environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
* whose contents is similar to that environment variable but can be
@@ -141,7 +141,7 @@ static void read_info_alternates(struct repository *r,
static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
const char *relative_base, int depth, const char *normalized_objdir)
{
- struct object_directory *ent;
+ struct odb_source *alternate;
struct strbuf pathbuf = STRBUF_INIT;
struct strbuf tmp = STRBUF_INIT;
khiter_t pos;
@@ -170,19 +170,19 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
goto error;
- CALLOC_ARRAY(ent, 1);
- /* pathbuf.buf is already in r->objects->odb_by_path */
- ent->path = strbuf_detach(&pathbuf, NULL);
+ CALLOC_ARRAY(alternate, 1);
+ /* pathbuf.buf is already in r->objects->source_by_path */
+ alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->odb_tail = ent;
- r->objects->odb_tail = &(ent->next);
- ent->next = NULL;
- assert(r->objects->odb_by_path);
- kh_value(r->objects->odb_by_path, pos) = ent;
+ *r->objects->sources_tail = alternate;
+ r->objects->sources_tail = &(alternate->next);
+ alternate->next = NULL;
+ assert(r->objects->source_by_path);
+ kh_value(r->objects->source_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, ent->path, depth + 1);
+ read_info_alternates(r, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -234,7 +234,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->odb->path, 1);
+ strbuf_realpath(&objdirbuf, r->objects->sources->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
@@ -321,9 +321,9 @@ void add_to_alternates_memory(const char *reference)
'\n', NULL, 0);
}
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
{
- struct object_directory *new_odb;
+ struct odb_source *source;
/*
* Make sure alternates are initialized, or else our entry may be
@@ -335,41 +335,41 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
- new_odb = xcalloc(1, sizeof(*new_odb));
- new_odb->path = xstrdup(dir);
+ source = xcalloc(1, sizeof(*source));
+ source->path = xstrdup(dir);
/*
* Disable ref updates while a temporary odb is active, since
* the objects in the database may roll back.
*/
- new_odb->disable_ref_updates = 1;
- new_odb->will_destroy = will_destroy;
- new_odb->next = the_repository->objects->odb;
- the_repository->objects->odb = new_odb;
- return new_odb->next;
+ source->disable_ref_updates = 1;
+ source->will_destroy = will_destroy;
+ source->next = the_repository->objects->sources;
+ the_repository->objects->sources = source;
+ return source->next;
}
-static void free_object_directory(struct object_directory *odb)
+static void free_object_directory(struct odb_source *source)
{
- free(odb->path);
- odb_clear_loose_cache(odb);
- loose_object_map_clear(&odb->loose_map);
- free(odb);
+ free(source->path);
+ odb_clear_loose_cache(source);
+ loose_object_map_clear(&source->loose_map);
+ free(source);
}
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
+void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
{
- struct object_directory *cur_odb = the_repository->objects->odb;
+ struct odb_source *cur_alt = the_repository->objects->sources;
- if (strcmp(old_path, cur_odb->path))
+ if (strcmp(old_path, cur_alt->path))
BUG("expected %s as primary object store; found %s",
- old_path, cur_odb->path);
+ old_path, cur_alt->path);
- if (cur_odb->next != restore_odb)
+ if (cur_alt->next != restore_alt)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->odb = restore_odb;
- free_object_directory(cur_odb);
+ the_repository->objects->sources = restore_alt;
+ free_object_directory(cur_alt);
}
/*
@@ -442,15 +442,15 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct object_directory *find_odb(struct repository *r, const char *obj_dir)
+struct odb_source *find_odb(struct repository *r, const char *obj_dir)
{
- struct object_directory *odb;
+ struct odb_source *source;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- strbuf_realpath(&odb_path_real, odb->path, 1);
+ for (source = r->objects->sources; source; source = source->next) {
+ strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
}
@@ -458,9 +458,9 @@ struct object_directory *find_odb(struct repository *r, const char *obj_dir)
free(obj_dir_real);
strbuf_release(&odb_path_real);
- if (!odb)
+ if (!source)
die(_("could not find object directory matching %s"), obj_dir);
- return odb;
+ return source;
}
static void fill_alternate_refs_command(struct child_process *cmd,
@@ -527,14 +527,14 @@ struct alternate_refs_data {
void *data;
};
-static int refs_from_alternate_cb(struct object_directory *e,
+static int refs_from_alternate_cb(struct odb_source *alternate,
void *data)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
struct alternate_refs_data *cb = data;
- if (!strbuf_realpath(&path, e->path, 0))
+ if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
if (!strbuf_strip_suffix(&path, "/objects"))
goto out;
@@ -563,12 +563,12 @@ void for_each_alternate_ref(alternate_ref_fn fn, void *data)
int foreach_alt_odb(alt_odb_fn fn, void *cb)
{
- struct object_directory *ent;
+ struct odb_source *alternate;
int r = 0;
prepare_alt_odb(the_repository);
- for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {
- r = fn(ent, cb);
+ for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
+ r = fn(alternate, cb);
if (r)
break;
}
@@ -582,14 +582,14 @@ void prepare_alt_odb(struct repository *r)
link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->odb->path, 0);
+ read_info_alternates(r, r->objects->sources->path, 0);
r->objects->loaded_alternates = 1;
}
int has_alt_odb(struct repository *r)
{
prepare_alt_odb(r);
- return !!r->objects->odb->next;
+ return !!r->objects->sources->next;
}
int obj_read_use_lock = 0;
@@ -963,15 +963,15 @@ struct object_database *odb_new(void)
static void free_object_directories(struct object_database *o)
{
- while (o->odb) {
- struct object_directory *next;
+ while (o->sources) {
+ struct odb_source *next;
- next = o->odb->next;
- free_object_directory(o->odb);
- o->odb = next;
+ next = o->sources->next;
+ free_object_directory(o->sources);
+ o->sources = next;
}
- kh_destroy_odb_path_map(o->odb_by_path);
- o->odb_by_path = NULL;
+ kh_destroy_odb_path_map(o->source_by_path);
+ o->source_by_path = NULL;
}
void odb_clear(struct object_database *o)
@@ -986,7 +986,7 @@ void odb_clear(struct object_database *o)
o->commit_graph_attempted = 0;
free_object_directories(o);
- o->odb_tail = NULL;
+ o->sources_tail = NULL;
o->loaded_alternates = 0;
for (size_t i = 0; i < o->cached_object_nr; i++)
diff --git a/object-store.h b/object-store.h
index a3be27d1171..d199d757d76 100644
--- a/object-store.h
+++ b/object-store.h
@@ -13,8 +13,20 @@ struct oidtree;
struct strbuf;
struct repository;
-struct object_directory {
- struct object_directory *next;
+/*
+ * The source is the part of the object database that stores the actual
+ * objects. It thus encapsulates the logic to read and write the specific
+ * on-disk format. An object database can have multiple sources:
+ *
+ * - The primary source, which is typically located in "$GIT_DIR/objects".
+ * This is where new objects are usually written to.
+ *
+ * - Alternate sources, which are configured via "objects/info/alternates" or
+ * via the GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable. These
+ * alternate sources are only used to read objects.
+ */
+struct odb_source {
+ struct odb_source *next;
/*
* Used to store the results of readdir(3) calls when we are OK
@@ -44,8 +56,8 @@ struct object_directory {
int will_destroy;
/*
- * Path to the alternative object store. If this is a relative path,
- * it is relative to the current working directory.
+ * Path to the source. If this is a relative path, it is relative to
+ * the current working directory.
*/
char *path;
};
@@ -53,8 +65,8 @@ struct object_directory {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
+struct odb_source *find_odb(struct repository *r, const char *obj_dir);
+typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
@@ -76,12 +88,12 @@ void add_to_alternates_memory(const char *dir);
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
*/
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy);
/*
* Restore a previous ODB replaced by set_temporary_main_odb.
*/
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+void restore_primary_odb(struct odb_source *restore_alternate, const char *old_path);
struct packed_git;
struct multi_pack_index;
@@ -89,7 +101,7 @@ struct cached_object_entry;
/*
* The object database encapsulates access to objects in a repository. It
- * manages one or more backends that store the actual objects which are
+ * manages one or more sources that store the actual objects which are
* configured via alternates.
*/
struct object_database {
@@ -98,16 +110,16 @@ struct object_database {
* cannot be NULL after initialization). Subsequent directories are
* alternates.
*/
- struct object_directory *odb;
- struct object_directory **odb_tail;
- struct kh_odb_path_map *odb_by_path;
+ struct odb_source *sources;
+ struct odb_source **sources_tail;
+ struct kh_odb_path_map *source_by_path;
int loaded_alternates;
/*
* 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.
+ * populate the "sources" list when prepare_alt_odb() is run.
*/
char *alternate_db;
diff --git a/packfile.c b/packfile.c
index c735b4d0135..60661ad0095 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1029,16 +1029,16 @@ static void prepare_packed_git_mru(struct repository *r)
static void prepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_source *source;
if (r->objects->packed_git_initialized)
return;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- int local = (odb == r->objects->odb);
- prepare_multi_pack_index_one(r, odb->path, local);
- prepare_packed_git_one(r, odb->path, local);
+ for (source = r->objects->sources; source; source = source->next) {
+ int local = (source == r->objects->sources);
+ prepare_multi_pack_index_one(r, source->path, local);
+ prepare_packed_git_one(r, source->path, local);
}
rearrange_packed_git(r);
@@ -1048,7 +1048,7 @@ static void prepare_packed_git(struct repository *r)
void reprepare_packed_git(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_source *source;
obj_read_lock();
@@ -1061,8 +1061,8 @@ void reprepare_packed_git(struct repository *r)
r->objects->loaded_alternates = 0;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next)
- odb_clear_loose_cache(odb);
+ for (source = r->objects->sources; source; source = source->next)
+ odb_clear_loose_cache(source);
r->objects->approximate_object_count_valid = 0;
r->objects->packed_git_initialized = 0;
diff --git a/path.c b/path.c
index 3b598b2847f..c347829aa66 100644
--- a/path.c
+++ b/path.c
@@ -397,7 +397,7 @@ static void adjust_git_path(struct repository *repo,
strbuf_splice(buf, 0, buf->len,
repo->index_file, strlen(repo->index_file));
else if (dir_prefix(base, "objects"))
- replace_dir(buf, git_dir_len + 7, repo->objects->odb->path);
+ replace_dir(buf, git_dir_len + 7, repo->objects->sources->path);
else if (repo_settings_get_hooks_path(repo) && dir_prefix(base, "hooks"))
replace_dir(buf, git_dir_len + 5, repo_settings_get_hooks_path(repo));
else if (repo->different_commondir)
diff --git a/refs.c b/refs.c
index dce5c49ca2b..5f6a386cc93 100644
--- a/refs.c
+++ b/refs.c
@@ -2477,7 +2477,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
break;
}
- if (refs->repo->objects->odb->disable_ref_updates) {
+ if (refs->repo->objects->sources->disable_ref_updates) {
strbuf_addstr(err,
_("ref updates forbidden inside quarantine environment"));
return -1;
diff --git a/repository.c b/repository.c
index 07757e6e0c9..7528beccddf 100644
--- a/repository.c
+++ b/repository.c
@@ -107,9 +107,9 @@ const char *repo_get_common_dir(struct repository *repo)
const char *repo_get_object_directory(struct repository *repo)
{
- if (!repo->objects->odb)
+ if (!repo->objects->sources)
BUG("repository hasn't been set up");
- return repo->objects->odb->path;
+ return repo->objects->sources->path;
}
const char *repo_get_index_file(struct repository *repo)
@@ -165,14 +165,14 @@ void repo_set_gitdir(struct repository *repo,
repo_set_commondir(repo, o->commondir);
- if (!repo->objects->odb) {
- CALLOC_ARRAY(repo->objects->odb, 1);
- repo->objects->odb_tail = &repo->objects->odb->next;
+ if (!repo->objects->sources) {
+ CALLOC_ARRAY(repo->objects->sources, 1);
+ repo->objects->sources_tail = &repo->objects->sources->next;
}
- expand_base_dir(&repo->objects->odb->path, o->object_dir,
+ expand_base_dir(&repo->objects->sources->path, o->object_dir,
repo->commondir, "objects");
- repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
+ repo->objects->sources->disable_ref_updates = o->disable_ref_updates;
free(repo->objects->alternate_db);
repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
diff --git a/submodule-config.c b/submodule-config.c
index 8630e27947d..b30d9365fbd 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->odb->path);
+ add_submodule_odb_by_path(repo->objects->sources->path);
} else {
goto out;
}
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 8b413b644be..53b633e2ba6 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -73,15 +73,15 @@ static void dump_graph_bloom_filters(struct commit_graph *graph)
int cmd__read_graph(int argc, const char **argv)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb;
+ struct odb_source *source;
int ret = 0;
setup_git_directory();
- odb = the_repository->objects->odb;
+ source = the_repository->objects->sources;
prepare_repo_settings(the_repository);
- graph = read_commit_graph_one(the_repository, odb);
+ graph = read_commit_graph_one(the_repository, source);
if (!graph) {
ret = 1;
goto done;
diff --git a/tmp-objdir.c b/tmp-objdir.c
index c38fbeb5e8a..056484404be 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -17,7 +17,7 @@ struct tmp_objdir {
struct repository *repo;
struct strbuf path;
struct strvec env;
- struct object_directory *prev_odb;
+ struct odb_source *prev_source;
int will_destroy;
};
@@ -46,8 +46,8 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
if (t == the_tmp_objdir)
the_tmp_objdir = NULL;
- if (t->prev_odb)
- restore_primary_odb(t->prev_odb, t->path.buf);
+ if (t->prev_source)
+ restore_primary_odb(t->prev_source, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -276,11 +276,11 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (!t)
return 0;
- if (t->prev_odb) {
- if (t->repo->objects->odb->will_destroy)
+ if (t->prev_source) {
+ if (t->repo->objects->sources->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_odb, t->path.buf);
- t->prev_odb = NULL;
+ restore_primary_odb(t->prev_source, t->path.buf);
+ t->prev_source = NULL;
}
strbuf_addbuf(&src, &t->path);
@@ -309,19 +309,19 @@ void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
- if (t->prev_odb)
+ if (t->prev_source)
BUG("the primary object database is already replaced");
- t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_source = set_temporary_primary_odb(t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
{
- if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
+ if (!the_tmp_objdir || !the_tmp_objdir->prev_source)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
- the_tmp_objdir->prev_odb = NULL;
+ restore_primary_odb(the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
+ the_tmp_objdir->prev_source = NULL;
return the_tmp_objdir;
}
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 03/17] object-store: rename files to "odb.{c,h}"
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 01/17] object-store: rename `raw_object_store` to `object_database` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 02/17] object-store: rename `object_directory` to `odb_source` Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 04/17] odb: introduce parent pointers Patrick Steinhardt
` (14 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
In the preceding commits we have renamed the structures contained in
"object-store.h" to `struct object_database` and `struct odb_backend`.
As such, the code files "object-store.{c,h}" are confusingly named now.
Rename them to "odb.{c,h}" accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Makefile | 2 +-
apply.c | 2 +-
archive-tar.c | 2 +-
archive-zip.c | 2 +-
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 2 +-
blame.c | 2 +-
builtin/backfill.c | 2 +-
builtin/blame.c | 2 +-
builtin/cat-file.c | 2 +-
builtin/checkout.c | 2 +-
builtin/clone.c | 2 +-
builtin/commit-graph.c | 2 +-
builtin/commit-tree.c | 2 +-
builtin/describe.c | 2 +-
builtin/difftool.c | 2 +-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 2 +-
builtin/fetch.c | 2 +-
builtin/fsck.c | 2 +-
builtin/grep.c | 2 +-
builtin/hash-object.c | 2 +-
builtin/index-pack.c | 2 +-
builtin/log.c | 2 +-
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 2 +-
builtin/merge-file.c | 2 +-
builtin/merge-tree.c | 2 +-
builtin/mktag.c | 2 +-
builtin/mktree.c | 2 +-
builtin/multi-pack-index.c | 2 +-
builtin/notes.c | 2 +-
builtin/pack-objects.c | 2 +-
builtin/pack-redundant.c | 2 +-
builtin/prune.c | 2 +-
builtin/receive-pack.c | 2 +-
builtin/remote.c | 2 +-
builtin/repack.c | 2 +-
builtin/replace.c | 2 +-
builtin/rev-list.c | 2 +-
builtin/show-ref.c | 2 +-
builtin/submodule--helper.c | 2 +-
builtin/tag.c | 2 +-
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 2 +-
bulk-checkin.c | 2 +-
bundle-uri.c | 2 +-
bundle.c | 2 +-
cache-tree.c | 2 +-
combine-diff.c | 2 +-
commit-graph.c | 2 +-
commit-graph.h | 2 +-
commit.c | 2 +-
config.c | 2 +-
connected.c | 2 +-
contrib/coccinelle/the_repository.cocci | 2 +-
diagnose.c | 2 +-
diff.c | 2 +-
entry.c | 2 +-
fetch-pack.c | 2 +-
fmt-merge-msg.c | 2 +-
fsck.c | 2 +-
grep.c | 2 +-
http-backend.c | 2 +-
http-push.c | 2 +-
http-walker.c | 2 +-
http.c | 2 +-
list-objects-filter.c | 2 +-
list-objects.c | 2 +-
loose.c | 2 +-
mailmap.c | 2 +-
match-trees.c | 2 +-
merge-blobs.c | 2 +-
merge-ort.c | 2 +-
meson.build | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 2 +-
object-file.c | 2 +-
object-file.h | 2 +-
object-store.c => odb.c | 2 +-
object-store.h => odb.h | 6 +++---
oss-fuzz/fuzz-pack-idx.c | 2 +-
pack-bitmap-write.c | 2 +-
pack-bitmap.c | 2 +-
pack-check.c | 2 +-
pack-mtimes.c | 2 +-
pack-objects.h | 2 +-
pack-revindex.c | 2 +-
packfile.c | 2 +-
packfile.h | 4 ++--
path.c | 2 +-
promisor-remote.c | 2 +-
protocol-caps.c | 2 +-
read-cache.c | 2 +-
ref-filter.c | 2 +-
reflog.c | 2 +-
refs.c | 2 +-
remote.c | 2 +-
replace-object.c | 2 +-
replace-object.h | 2 +-
repository.c | 2 +-
rerere.c | 2 +-
revision.c | 2 +-
send-pack.c | 2 +-
sequencer.c | 2 +-
server-info.c | 2 +-
shallow.c | 2 +-
streaming.c | 2 +-
submodule-config.c | 2 +-
submodule.c | 2 +-
t/helper/test-find-pack.c | 2 +-
t/helper/test-pack-mtimes.c | 2 +-
t/helper/test-partial-clone.c | 2 +-
t/helper/test-read-graph.c | 2 +-
t/helper/test-read-midx.c | 2 +-
t/helper/test-ref-store.c | 2 +-
tag.c | 2 +-
tmp-objdir.c | 2 +-
tree-walk.c | 2 +-
tree.c | 2 +-
unpack-trees.c | 2 +-
upload-pack.c | 2 +-
walker.c | 2 +-
xdiff-interface.c | 2 +-
126 files changed, 129 insertions(+), 129 deletions(-)
diff --git a/Makefile b/Makefile
index 70d1543b6b8..4b1bf897791 100644
--- a/Makefile
+++ b/Makefile
@@ -1085,8 +1085,8 @@ LIB_OBJS += notes.o
LIB_OBJS += object-file-convert.o
LIB_OBJS += object-file.o
LIB_OBJS += object-name.o
-LIB_OBJS += object-store.o
LIB_OBJS += object.o
+LIB_OBJS += odb.o
LIB_OBJS += oid-array.o
LIB_OBJS += oidmap.o
LIB_OBJS += oidset.o
diff --git a/apply.c b/apply.c
index 8bbe6ed2240..e778b4e911d 100644
--- a/apply.c
+++ b/apply.c
@@ -14,7 +14,7 @@
#include "abspath.h"
#include "base85.h"
#include "config.h"
-#include "object-store.h"
+#include "odb.h"
#include "delta.h"
#include "diff.h"
#include "dir.h"
diff --git a/archive-tar.c b/archive-tar.c
index 282b48196f9..249164ea77d 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -11,7 +11,7 @@
#include "hex.h"
#include "tar.h"
#include "archive.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "streaming.h"
#include "run-command.h"
diff --git a/archive-zip.c b/archive-zip.c
index 405da6f3d83..df8866d5bae 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -12,7 +12,7 @@
#include "hex.h"
#include "streaming.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "userdiff.h"
#include "write-or-die.h"
diff --git a/archive.c b/archive.c
index 8309ea213e6..7fa2cc2596a 100644
--- a/archive.c
+++ b/archive.c
@@ -14,7 +14,7 @@
#include "pretty.h"
#include "setup.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 86b6109fc4e..e5680db7f65 100644
--- a/attr.c
+++ b/attr.c
@@ -22,7 +22,7 @@
#include "read-cache-ll.h"
#include "refs.h"
#include "revision.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/bisect.c b/bisect.c
index a327468c75b..a7939216d00 100644
--- a/bisect.c
+++ b/bisect.c
@@ -20,7 +20,7 @@
#include "commit-slab.h"
#include "commit-reach.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "dir.h"
diff --git a/blame.c b/blame.c
index 57daa45e899..0ceea080a80 100644
--- a/blame.c
+++ b/blame.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "refs.h"
-#include "object-store.h"
+#include "odb.h"
#include "cache-tree.h"
#include "mergesort.h"
#include "commit.h"
diff --git a/builtin/backfill.c b/builtin/backfill.c
index fa82ad2f6ff..0b49baa39fa 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -13,7 +13,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "promisor-remote.h"
diff --git a/builtin/blame.c b/builtin/blame.c
index 944952e30eb..15eda60af90 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -28,7 +28,7 @@
#include "line-log.h"
#include "progress.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "blame.h"
#include "refs.h"
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 67a5ff2b9eb..f3a925a8183 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -24,7 +24,7 @@
#include "pack-bitmap.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "mailmap.h"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d185982f3a6..e7dd66173dd 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -20,7 +20,7 @@
#include "merge-ort-wrappers.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "path.h"
#include "preload-index.h"
diff --git a/builtin/clone.c b/builtin/clone.c
index 91b9cd0d164..1eafeefb48d 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -25,7 +25,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "tree-walk.h"
#include "unpack-trees.h"
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 98a84315342..f04eaba5259 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -6,7 +6,7 @@
#include "hex.h"
#include "parse-options.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "progress.h"
#include "replace-object.h"
#include "strbuf.h"
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index ad6b2c93209..546069f8682 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -9,7 +9,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "parse-options.h"
diff --git a/builtin/describe.c b/builtin/describe.c
index 2d50883b729..96cb68e5e5d 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -19,7 +19,7 @@
#include "setup.h"
#include "strvec.h"
#include "run-command.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects.h"
#include "commit-slab.h"
#include "wildmatch.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index a3b64ce6942..fac613e3bc3 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -30,7 +30,7 @@
#include "strbuf.h"
#include "lockfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "entry.h"
#include "setup.h"
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 37c01d6c6fe..0505f289a94 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "object.h"
#include "tag.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index b2839c5f439..52c792488e1 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -24,7 +24,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "mem-pool.h"
#include "commit-reach.h"
#include "khash.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index a890e2864d1..b842bc9c51b 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -14,7 +14,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "oid-array.h"
#include "commit.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6e1474f63d5..9abd7b25580 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "read-cache-ll.h"
#include "replace-object.h"
diff --git a/builtin/grep.c b/builtin/grep.c
index 76b1938bba5..a1d7ee7af39 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -26,7 +26,7 @@
#include "submodule-config.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pager.h"
#include "path.h"
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index 6a99ec250d0..e28f000221f 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -11,7 +11,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bb7925bd29f..1aabe6b8ee2 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -21,7 +21,7 @@
#include "packfile.h"
#include "pack-revindex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "oidset.h"
#include "path.h"
diff --git a/builtin/log.c b/builtin/log.c
index b450cd3bde8..fe9cc5ebecb 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -15,7 +15,7 @@
#include "hex.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "color.h"
#include "commit.h"
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index be74f0a03b2..821339b07d4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -25,7 +25,7 @@
#include "setup.h"
#include "sparse-index.h"
#include "submodule.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 8aafc30ca48..62b6fd58c16 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -10,7 +10,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "tree.h"
#include "path.h"
#include "quote.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 2b16b10d2ca..9464f275629 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -7,7 +7,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "gettext.h"
#include "setup.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index 7f41665dfd7..b1a17787bcf 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -10,7 +10,7 @@
#include "commit-reach.h"
#include "merge-ort.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "blob.h"
#include "merge-blobs.h"
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 7ac11c46d53..1809b38f937 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -6,7 +6,7 @@
#include "strbuf.h"
#include "replace-object.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "fsck.h"
#include "config.h"
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 4b478034675..016b0e5b224 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -12,7 +12,7 @@
#include "tree.h"
#include "parse-options.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static struct treeent {
unsigned mode;
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index f55bf53da83..aa25b06f9d0 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -7,7 +7,7 @@
#include "midx.h"
#include "strbuf.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/builtin/notes.c b/builtin/notes.c
index a3f433ca4c0..783d4932ca6 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -16,7 +16,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "pretty.h"
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 8b33edc2ff5..99b63cb0980 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -32,7 +32,7 @@
#include "list.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "dir.h"
#include "midx.h"
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 5d1fc781761..3134cb8c689 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -13,7 +13,7 @@
#include "hex.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#define BLKSIZE 512
diff --git a/builtin/prune.c b/builtin/prune.c
index e930caa0c0a..7bbfb14c2be 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -17,7 +17,7 @@
#include "replace-object.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "shallow.h"
static const char * const prune_usage[] = {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index a317d6c278d..0f5958c4a66 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -33,7 +33,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "protocol.h"
#include "commit-reach.h"
diff --git a/builtin/remote.c b/builtin/remote.c
index 0d6755bcb71..ac5b8d2a1a6 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -14,7 +14,7 @@
#include "rebase.h"
#include "refs.h"
#include "refspec.h"
-#include "object-store.h"
+#include "odb.h"
#include "strvec.h"
#include "commit-reach.h"
#include "progress.h"
diff --git a/builtin/repack.c b/builtin/repack.c
index 59214dbdfdf..16782320058 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -17,7 +17,7 @@
#include "midx.h"
#include "packfile.h"
#include "prune-packed.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "shallow.h"
#include "pack.h"
diff --git a/builtin/replace.c b/builtin/replace.c
index 48c7c6a2d56..11c7e2d4c0c 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "tag.h"
#include "wildmatch.h"
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 0984b607bf0..0ee37a32cb2 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -14,7 +14,7 @@
#include "object.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "parse-options.h"
#include "log-tree.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 623a52a45f8..90ec1de78f9 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "refs/refs-internal.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "string-list.h"
#include "parse-options.h"
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 758bc6d0f24..84f7fa53424 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -28,7 +28,7 @@
#include "diff.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "advice.h"
#include "branch.h"
#include "list-objects-filter-options.h"
diff --git a/builtin/tag.c b/builtin/tag.c
index 4742b27d16e..cf2ea4b4993 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -19,7 +19,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "tag.h"
#include "parse-options.h"
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index e33acfc4ee4..b92fd4710a9 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
static char *create_temp_file(struct object_id *oid)
{
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index e905d5f4e19..7bf395eec84 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -9,7 +9,7 @@
#include "git-zlib.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "delta.h"
#include "pack.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 678e2ecc2c2..55406a539e7 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -17,7 +17,7 @@
#include "tmp-objdir.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
static int odb_transaction_nesting;
diff --git a/bundle-uri.c b/bundle-uri.c
index 9accf157b44..2e623f8627a 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -14,7 +14,7 @@
#include "fetch-pack.h"
#include "remote.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
static struct {
enum bundle_list_heuristic heuristic;
diff --git a/bundle.c b/bundle.c
index 2ce7525f90d..e09e3c2f58c 100644
--- a/bundle.c
+++ b/bundle.c
@@ -7,7 +7,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "object.h"
#include "commit.h"
diff --git a/cache-tree.c b/cache-tree.c
index fa3858e2829..9786b32b3a1 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -10,7 +10,7 @@
#include "cache-tree.h"
#include "bulk-checkin.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "read-cache-ll.h"
#include "replace-object.h"
#include "repository.h"
diff --git a/combine-diff.c b/combine-diff.c
index dfae9f7995d..cf23a753407 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -2,7 +2,7 @@
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "convert.h"
#include "diff.h"
diff --git a/commit-graph.c b/commit-graph.c
index 12d32cdad1d..6ced5b366e7 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -13,7 +13,7 @@
#include "refs.h"
#include "hash-lookup.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "alloc.h"
diff --git a/commit-graph.h b/commit-graph.h
index 0e661db1b54..78ab7b875b2 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -1,7 +1,7 @@
#ifndef COMMIT_GRAPH_H
#define COMMIT_GRAPH_H
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
diff --git a/commit.c b/commit.c
index e915b2b9a12..1d30f8ce15a 100644
--- a/commit.c
+++ b/commit.c
@@ -9,7 +9,7 @@
#include "hex.h"
#include "repository.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "diff.h"
#include "revision.h"
diff --git a/config.c b/config.c
index b18b5617fcd..883dd066827 100644
--- a/config.c
+++ b/config.c
@@ -31,7 +31,7 @@
#include "hashmap.h"
#include "string-list.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "path.h"
#include "utf8.h"
diff --git a/connected.c b/connected.c
index 4415388beba..18c13245d8e 100644
--- a/connected.c
+++ b/connected.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "run-command.h"
#include "sigchain.h"
#include "connected.h"
diff --git a/contrib/coccinelle/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
index 765ad689678..ea7fe1c8db7 100644
--- a/contrib/coccinelle/the_repository.cocci
+++ b/contrib/coccinelle/the_repository.cocci
@@ -77,7 +77,7 @@
|
- diff_setup
+ repo_diff_setup
-// object-store.h
+// odb.h
|
- read_object_file
+ repo_read_object_file
diff --git a/diagnose.c b/diagnose.c
index d08d5643aac..ad0d5c12465 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -7,7 +7,7 @@
#include "gettext.h"
#include "hex.h"
#include "strvec.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "repository.h"
diff --git a/diff.c b/diff.c
index 90e8003dd11..3af108115b3 100644
--- a/diff.c
+++ b/diff.c
@@ -23,7 +23,7 @@
#include "color.h"
#include "run-command.h"
#include "utf8.h"
-#include "object-store.h"
+#include "odb.h"
#include "userdiff.h"
#include "submodule.h"
#include "hashmap.h"
diff --git a/entry.c b/entry.c
index f36ec5ad242..75d55038d7c 100644
--- a/entry.c
+++ b/entry.c
@@ -1,7 +1,7 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index fa4231fee74..cf157f5d7e5 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -24,7 +24,7 @@
#include "oid-array.h"
#include "oidset.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "connected.h"
#include "fetch-negotiator.h"
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 501b5acdd44..1a8c972adf3 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -6,7 +6,7 @@
#include "environment.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "diff.h"
#include "diff-merges.h"
#include "hex.h"
diff --git a/fsck.c b/fsck.c
index 8dc8472ceb3..e69baab3af7 100644
--- a/fsck.c
+++ b/fsck.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "dir.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "object.h"
diff --git a/grep.c b/grep.c
index f8d535182c3..dc77e6c4631 100644
--- a/grep.c
+++ b/grep.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "grep.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "userdiff.h"
#include "xdiff-interface.h"
diff --git a/http-backend.c b/http-backend.c
index 0c575aa88aa..ad8c4037493 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -18,7 +18,7 @@
#include "url.h"
#include "strvec.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "protocol.h"
#include "date.h"
#include "write-or-die.h"
diff --git a/http-push.c b/http-push.c
index f9e67cabd4b..d1b1bb23711 100644
--- a/http-push.c
+++ b/http-push.c
@@ -20,7 +20,7 @@
#include "url.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#ifdef EXPAT_NEEDS_XMLPARSE_H
diff --git a/http-walker.c b/http-walker.c
index c374e6b2056..05fb9ce714a 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -10,7 +10,7 @@
#include "transport.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct alt_base {
char *base;
diff --git a/http.c b/http.c
index 5e15bbab3f1..8f4f701a818 100644
--- a/http.c
+++ b/http.c
@@ -19,7 +19,7 @@
#include "packfile.h"
#include "string-list.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "tempfile.h"
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 78b397bc194..80fe48a52c8 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -12,7 +12,7 @@
#include "oidmap.h"
#include "oidset.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
/* Remember to update object flag allocation in object.h */
/*
diff --git a/list-objects.c b/list-objects.c
index 597114281f6..c50b9578584 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -14,7 +14,7 @@
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace.h"
#include "environment.h"
diff --git a/loose.c b/loose.c
index fe65d5b9b0f..fab4041c03d 100644
--- a/loose.c
+++ b/loose.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "hash.h"
#include "path.h"
-#include "object-store.h"
+#include "odb.h"
#include "hex.h"
#include "repository.h"
#include "wrapper.h"
diff --git a/mailmap.c b/mailmap.c
index 9e2642a043b..b18e74c2110 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -6,7 +6,7 @@
#include "string-list.h"
#include "mailmap.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
char *git_mailmap_file;
diff --git a/match-trees.c b/match-trees.c
index 72922d5d64e..4704f95c340 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -7,7 +7,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
static int score_missing(unsigned mode)
diff --git a/merge-blobs.c b/merge-blobs.c
index 53f36dbc175..ba8a3fdfd82 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -4,7 +4,7 @@
#include "merge-ll.h"
#include "blob.h"
#include "merge-blobs.h"
-#include "object-store.h"
+#include "odb.h"
static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
{
diff --git a/merge-ort.c b/merge-ort.c
index 47b3d1730ec..9f693ab1d36 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -39,7 +39,7 @@
#include "mem-pool.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/meson.build b/meson.build
index 596f5ac7110..3fad0e39987 100644
--- a/meson.build
+++ b/meson.build
@@ -396,8 +396,8 @@ libgit_sources = [
'object-file-convert.c',
'object-file.c',
'object-name.c',
- 'object-store.c',
'object.c',
+ 'odb.c',
'oid-array.c',
'oidmap.c',
'oidset.c',
diff --git a/notes-cache.c b/notes-cache.c
index 150241b15e0..344f67762b8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "notes-cache.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "pretty.h"
#include "repository.h"
#include "commit.h"
diff --git a/notes-merge.c b/notes-merge.c
index dae8e6a281a..de6a52e2e7f 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -8,7 +8,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "diff.h"
diff --git a/notes.c b/notes.c
index 0a128f1de98..fc000e501d2 100644
--- a/notes.c
+++ b/notes.c
@@ -8,7 +8,7 @@
#include "notes.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "utf8.h"
#include "strbuf.h"
#include "tree-walk.h"
diff --git a/object-file.c b/object-file.c
index 6bad1d3dd1c..2d3af8a77c0 100644
--- a/object-file.c
+++ b/object-file.c
@@ -21,7 +21,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidtree.h"
#include "pack.h"
#include "packfile.h"
diff --git a/object-file.h b/object-file.h
index 9a18859b2e0..5066638f8ec 100644
--- a/object-file.h
+++ b/object-file.h
@@ -3,7 +3,7 @@
#include "git-zlib.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
struct index_state;
diff --git a/object-store.c b/odb.c
similarity index 99%
rename from object-store.c
rename to odb.c
index 5c04a1018f7..d1025ac182d 100644
--- a/object-store.c
+++ b/odb.c
@@ -13,7 +13,7 @@
#include "loose.h"
#include "object-file-convert.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "path.h"
#include "promisor-remote.h"
diff --git a/object-store.h b/odb.h
similarity index 99%
rename from object-store.h
rename to odb.h
index d199d757d76..6f56b168e46 100644
--- a/object-store.h
+++ b/odb.h
@@ -1,5 +1,5 @@
-#ifndef OBJECT_STORE_H
-#define OBJECT_STORE_H
+#ifndef ODB_H
+#define ODB_H
#include "hashmap.h"
#include "object.h"
@@ -352,4 +352,4 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
-#endif /* OBJECT_STORE_H */
+#endif /* ODB_H */
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 609a343ee3e..d2a92f34d98 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 7f400ee0121..37648b57125 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -4,7 +4,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index ac6d62b980c..a695a794e9b 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -17,7 +17,7 @@
#include "packfile.h"
#include "repository.h"
#include "trace2.h"
-#include "object-store.h"
+#include "odb.h"
#include "list-objects-filter-options.h"
#include "midx.h"
#include "config.h"
diff --git a/pack-check.c b/pack-check.c
index 874897d6cba..67cb2cf72f2 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -8,7 +8,7 @@
#include "progress.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
struct idx_entry {
off_t offset;
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 20900ca88d3..8e1f2dec0ef 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-mtimes.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
diff --git a/pack-objects.h b/pack-objects.h
index 475a2d67ce3..1ac8644201b 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -1,7 +1,7 @@
#ifndef PACK_OBJECTS_H
#define PACK_OBJECTS_H
-#include "object-store.h"
+#include "odb.h"
#include "thread-utils.h"
#include "pack.h"
#include "packfile.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index ffcde48870d..0cc422a1e67 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "pack-revindex.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "strbuf.h"
#include "trace2.h"
diff --git a/packfile.c b/packfile.c
index 60661ad0095..346c2f9ce90 100644
--- a/packfile.c
+++ b/packfile.c
@@ -19,7 +19,7 @@
#include "tree-walk.h"
#include "tree.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "midx.h"
#include "commit-graph.h"
#include "pack-revindex.h"
diff --git a/packfile.h b/packfile.h
index 826eb7f475f..53c3b7d3b43 100644
--- a/packfile.h
+++ b/packfile.h
@@ -3,10 +3,10 @@
#include "list.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
-/* in object-store.h */
+/* in odb.h */
struct object_info;
struct packed_git {
diff --git a/path.c b/path.c
index c347829aa66..7f56eaf9930 100644
--- a/path.c
+++ b/path.c
@@ -15,7 +15,7 @@
#include "submodule-config.h"
#include "path.h"
#include "packfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "lockfile.h"
#include "exec-cmd.h"
diff --git a/promisor-remote.c b/promisor-remote.c
index 9d058586dfa..2baa286bfd0 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -3,7 +3,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "config.h"
#include "trace2.h"
diff --git a/protocol-caps.c b/protocol-caps.c
index 9b8db37a210..3022f69a1bd 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -6,7 +6,7 @@
#include "hash.h"
#include "hex.h"
#include "object.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
#include "string-list.h"
#include "strbuf.h"
diff --git a/read-cache.c b/read-cache.c
index c0bb760ad47..c3fa9686766 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -20,7 +20,7 @@
#include "refs.h"
#include "dir.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "tree.h"
#include "commit.h"
diff --git a/ref-filter.c b/ref-filter.c
index 7a274633cfc..4ce45440ad1 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "wildmatch.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "repo-settings.h"
#include "repository.h"
diff --git a/reflog.c b/reflog.c
index 15d81ebea97..4f8a3b717cd 100644
--- a/reflog.c
+++ b/reflog.c
@@ -5,7 +5,7 @@
#include "config.h"
#include "gettext.h"
#include "parse-options.h"
-#include "object-store.h"
+#include "odb.h"
#include "reflog.h"
#include "refs.h"
#include "revision.h"
diff --git a/refs.c b/refs.c
index 5f6a386cc93..0ff0e582a6b 100644
--- a/refs.c
+++ b/refs.c
@@ -19,7 +19,7 @@
#include "run-command.h"
#include "hook.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "path.h"
#include "submodule.h"
diff --git a/remote.c b/remote.c
index 4099183cacd..17a842f5684 100644
--- a/remote.c
+++ b/remote.c
@@ -12,7 +12,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "commit.h"
#include "diff.h"
diff --git a/replace-object.c b/replace-object.c
index f8c5f68837f..3eae0510745 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -2,7 +2,7 @@
#include "gettext.h"
#include "hex.h"
#include "oidmap.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "refs.h"
#include "repository.h"
diff --git a/replace-object.h b/replace-object.h
index 3052e96a620..4c9f2a2383d 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -3,7 +3,7 @@
#include "oidmap.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
struct replace_object {
struct oidmap_entry original;
diff --git a/repository.c b/repository.c
index 7528beccddf..13426db0f2b 100644
--- a/repository.c
+++ b/repository.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "config.h"
#include "object.h"
#include "lockfile.h"
diff --git a/rerere.c b/rerere.c
index 3cd37c5f0ae..951e4bf8b41 100644
--- a/rerere.c
+++ b/rerere.c
@@ -18,7 +18,7 @@
#include "path.h"
#include "pathspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "strmap.h"
#define RESOLVED 0
diff --git a/revision.c b/revision.c
index 2c36a9c179e..cdefe7d6e48 100644
--- a/revision.c
+++ b/revision.c
@@ -8,7 +8,7 @@
#include "hex.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "oidset.h"
#include "tag.h"
#include "blob.h"
diff --git a/send-pack.c b/send-pack.c
index 86592ce526d..abca2dd38a7 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -4,7 +4,7 @@
#include "date.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "pkt-line.h"
#include "sideband.h"
#include "run-command.h"
diff --git a/sequencer.c b/sequencer.c
index 1ee0abbd451..2432d0a39ec 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -13,7 +13,7 @@
#include "dir.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "object.h"
#include "pager.h"
#include "commit.h"
diff --git a/server-info.c b/server-info.c
index d6cd20a39d7..9bb30d9ab71 100644
--- a/server-info.c
+++ b/server-info.c
@@ -11,7 +11,7 @@
#include "packfile.h"
#include "path.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "server-info.h"
#include "strbuf.h"
#include "tempfile.h"
diff --git a/shallow.c b/shallow.c
index faeeeb45f98..d379756e39a 100644
--- a/shallow.c
+++ b/shallow.c
@@ -5,7 +5,7 @@
#include "repository.h"
#include "tempfile.h"
#include "lockfile.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tag.h"
#include "pkt-line.h"
diff --git a/streaming.c b/streaming.c
index 6d6512e2e0d..81c42673a23 100644
--- a/streaming.c
+++ b/streaming.c
@@ -10,7 +10,7 @@
#include "streaming.h"
#include "repository.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "replace-object.h"
#include "packfile.h"
diff --git a/submodule-config.c b/submodule-config.c
index b30d9365fbd..9c80f9f7b66 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -13,7 +13,7 @@
#include "submodule.h"
#include "strbuf.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "parse-options.h"
#include "thread-utils.h"
#include "tree-walk.h"
diff --git a/submodule.c b/submodule.c
index ead3fb5dadc..9b1018877df 100644
--- a/submodule.c
+++ b/submodule.c
@@ -27,7 +27,7 @@
#include "parse-options.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index 76c2f4eba85..611a13a3261 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -2,7 +2,7 @@
#include "test-tool.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "setup.h"
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index fdf1b13437b..d51aaa3dc40 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "pack-mtimes.h"
#include "setup.h"
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 34f1aee5581..dba227259a2 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "hex.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "setup.h"
/*
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 53b633e2ba6..ef5339bbee9 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "bloom.h"
#include "setup.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index ac81390899a..da2aa036b57 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "midx.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "packfile.h"
#include "setup.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 4cfc7c90b59..2920ca59d72 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -5,7 +5,7 @@
#include "refs.h"
#include "setup.h"
#include "worktree.h"
-#include "object-store.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "strbuf.h"
diff --git a/tag.c b/tag.c
index 05be39067cf..5f6868bf7b1 100644
--- a/tag.c
+++ b/tag.c
@@ -5,7 +5,7 @@
#include "environment.h"
#include "tag.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "tree.h"
#include "blob.h"
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 056484404be..bef2f917cd2 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -10,7 +10,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "quote.h"
-#include "object-store.h"
+#include "odb.h"
#include "repository.h"
struct tmp_objdir {
diff --git a/tree-walk.c b/tree-walk.c
index 90655d52378..34b0fff4873 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -6,7 +6,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "odb.h"
#include "trace2.h"
#include "tree.h"
#include "pathspec.h"
diff --git a/tree.c b/tree.c
index b85f56267fb..341b7c2ff3f 100644
--- a/tree.c
+++ b/tree.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "tree.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "alloc.h"
#include "tree-walk.h"
diff --git a/unpack-trees.c b/unpack-trees.c
index 471837f0329..f38c761ab98 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -26,7 +26,7 @@
#include "symlinks.h"
#include "trace2.h"
#include "fsmonitor.h"
-#include "object-store.h"
+#include "odb.h"
#include "promisor-remote.h"
#include "entry.h"
#include "parallel-checkout.h"
diff --git a/upload-pack.c b/upload-pack.c
index 26f29b85b55..e994d6a901b 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -10,7 +10,7 @@
#include "pkt-line.h"
#include "sideband.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "oid-array.h"
#include "object.h"
#include "commit.h"
diff --git a/walker.c b/walker.c
index b470d43e54d..a8abe8a2e78 100644
--- a/walker.c
+++ b/walker.c
@@ -5,7 +5,7 @@
#include "hex.h"
#include "walker.h"
#include "repository.h"
-#include "object-store.h"
+#include "odb.h"
#include "commit.h"
#include "strbuf.h"
#include "tree.h"
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 1edcd319e6e..01e6e378ea6 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "config.h"
#include "hex.h"
-#include "object-store.h"
+#include "odb.h"
#include "strbuf.h"
#include "xdiff-interface.h"
#include "xdiff/xtypes.h"
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 04/17] odb: introduce parent pointers
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (2 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 03/17] object-store: rename files to "odb.{c,h}" Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
` (13 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
In subsequent commits we'll get rid of our use of `the_repository` in
"odb.c" in favor of explicitly passing in a `struct object_database` or
a `struct odb_source`. In some cases though we'll need access to the
repository, for example to read a config value from it, but we don't
have a way to access the repository owning a specific object database.
Introduce parent pointers for `struct object_database` to its owning
repository as well as for `struct odb_source` to its owning object
database, which will allow us to adapt those use cases.
Note that this change requires us to pass through the object database to
`link_alt_odb_entry()` so that we can set up the parent pointers for any
source there. The callchain is adapted to pass through the object
database accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 45 ++++++++++++++++++++++++++-------------------
odb.h | 8 +++++++-
repository.c | 3 ++-
3 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/odb.c b/odb.c
index d1025ac182d..0464d7f54a2 100644
--- a/odb.c
+++ b/odb.c
@@ -135,11 +135,15 @@ static int alt_odb_usable(struct object_database *o,
* of the object ID, an extra slash for the first level indirection, and
* the terminating NUL.
*/
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth);
-static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
- const char *relative_base, int depth, const char *normalized_objdir)
+
+static int link_alt_odb_entry(struct object_database *odb,
+ const struct strbuf *entry,
+ const char *relative_base,
+ int depth,
+ const char *normalized_objdir)
{
struct odb_source *alternate;
struct strbuf pathbuf = STRBUF_INIT;
@@ -167,22 +171,23 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
while (pathbuf.len && pathbuf.buf[pathbuf.len - 1] == '/')
strbuf_setlen(&pathbuf, pathbuf.len - 1);
- if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
+ if (!alt_odb_usable(odb, &pathbuf, normalized_objdir, &pos))
goto error;
CALLOC_ARRAY(alternate, 1);
+ alternate->odb = odb;
/* pathbuf.buf is already in r->objects->source_by_path */
alternate->path = strbuf_detach(&pathbuf, NULL);
/* add the alternate entry */
- *r->objects->sources_tail = alternate;
- r->objects->sources_tail = &(alternate->next);
+ *odb->sources_tail = alternate;
+ odb->sources_tail = &(alternate->next);
alternate->next = NULL;
- assert(r->objects->source_by_path);
- kh_value(r->objects->source_by_path, pos) = alternate;
+ assert(odb->source_by_path);
+ kh_value(odb->source_by_path, pos) = alternate;
/* recursively add alternates */
- read_info_alternates(r, alternate->path, depth + 1);
+ read_info_alternates(odb, alternate->path, depth + 1);
ret = 0;
error:
strbuf_release(&tmp);
@@ -219,7 +224,7 @@ static const char *parse_alt_odb_entry(const char *string,
return end;
}
-static void link_alt_odb_entries(struct repository *r, const char *alt,
+static void link_alt_odb_entries(struct object_database *odb, const char *alt,
int sep, const char *relative_base, int depth)
{
struct strbuf objdirbuf = STRBUF_INIT;
@@ -234,20 +239,20 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
return;
}
- strbuf_realpath(&objdirbuf, r->objects->sources->path, 1);
+ strbuf_realpath(&objdirbuf, odb->sources->path, 1);
while (*alt) {
alt = parse_alt_odb_entry(alt, sep, &entry);
if (!entry.len)
continue;
- link_alt_odb_entry(r, &entry,
+ link_alt_odb_entry(odb, &entry,
relative_base, depth, objdirbuf.buf);
}
strbuf_release(&entry);
strbuf_release(&objdirbuf);
}
-static void read_info_alternates(struct repository *r,
+static void read_info_alternates(struct object_database *odb,
const char *relative_base,
int depth)
{
@@ -261,7 +266,7 @@ static void read_info_alternates(struct repository *r,
return;
}
- link_alt_odb_entries(r, buf.buf, '\n', relative_base, depth);
+ link_alt_odb_entries(odb, buf.buf, '\n', relative_base, depth);
strbuf_release(&buf);
free(path);
}
@@ -303,7 +308,7 @@ void add_to_alternates_file(const char *reference)
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
free(alts);
@@ -317,7 +322,7 @@ void add_to_alternates_memory(const char *reference)
*/
prepare_alt_odb(the_repository);
- link_alt_odb_entries(the_repository, reference,
+ link_alt_odb_entries(the_repository->objects, reference,
'\n', NULL, 0);
}
@@ -336,6 +341,7 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* alternate
*/
source = xcalloc(1, sizeof(*source));
+ source->odb = the_repository->objects;
source->path = xstrdup(dir);
/*
@@ -580,9 +586,9 @@ void prepare_alt_odb(struct repository *r)
if (r->objects->loaded_alternates)
return;
- link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r, r->objects->sources->path, 0);
+ read_info_alternates(r->objects, r->objects->sources->path, 0);
r->objects->loaded_alternates = 1;
}
@@ -950,11 +956,12 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect)
type_name(expect));
}
-struct object_database *odb_new(void)
+struct object_database *odb_new(struct repository *repo)
{
struct object_database *o = xmalloc(sizeof(*o));
memset(o, 0, sizeof(*o));
+ o->repo = repo;
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
diff --git a/odb.h b/odb.h
index 6f56b168e46..c3851e29668 100644
--- a/odb.h
+++ b/odb.h
@@ -28,6 +28,9 @@ struct repository;
struct odb_source {
struct odb_source *next;
+ /* Object database that owns this object source. */
+ struct object_database *odb;
+
/*
* Used to store the results of readdir(3) calls when we are OK
* sacrificing accuracy due to races for speed. That includes
@@ -105,6 +108,9 @@ struct cached_object_entry;
* configured via alternates.
*/
struct object_database {
+ /* Repository that owns this database. */
+ struct repository *repo;
+
/*
* Set of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
@@ -186,7 +192,7 @@ struct object_database {
unsigned packed_git_initialized : 1;
};
-struct object_database *odb_new(void);
+struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
/*
diff --git a/repository.c b/repository.c
index 13426db0f2b..c606e1153c8 100644
--- a/repository.c
+++ b/repository.c
@@ -52,7 +52,7 @@ static void set_default_hash_algo(struct repository *repo)
void initialize_repository(struct repository *repo)
{
- repo->objects = odb_new();
+ repo->objects = odb_new(repo);
repo->remote_state = remote_state_new();
repo->parsed_objects = parsed_object_pool_new(repo);
ALLOC_ARRAY(repo->index, 1);
@@ -167,6 +167,7 @@ void repo_set_gitdir(struct repository *repo,
if (!repo->objects->sources) {
CALLOC_ARRAY(repo->objects->sources, 1);
+ repo->objects->sources->odb = repo->objects;
repo->objects->sources_tail = &repo->objects->sources->next;
}
expand_base_dir(&repo->objects->sources->path, o->object_dir,
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 05/17] odb: get rid of `the_repository` in `find_odb()`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (3 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 04/17] odb: introduce parent pointers Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
` (12 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Get rid of our dependency on `the_repository` in `find_odb()` by passing
in the object database in which we want to search for the source and
adjusting all callers.
Rename the function to `odb_find_source()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-graph.c | 4 ++--
midx-write.c | 2 +-
odb.c | 6 +++---
odb.h | 7 ++++++-
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index f04eaba5259..77d7e88a98c 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -101,7 +101,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- source = find_odb(the_repository, opts.obj_dir);
+ source = odb_find_source(the_repository->objects, opts.obj_dir);
graph_name = get_commit_graph_filename(source);
chain_name = get_commit_graph_chain_filename(source);
if (open_commit_graph(graph_name, &fd, &st))
@@ -289,7 +289,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- source = find_odb(the_repository, opts.obj_dir);
+ source = odb_find_source(the_repository->objects, opts.obj_dir);
if (opts.reachable) {
if (write_commit_graph_reachable(source, flags, &write_opts))
diff --git a/midx-write.c b/midx-write.c
index ba4a94950a8..f2cfb85476e 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -922,7 +922,7 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
struct strbuf cur_path_real = STRBUF_INIT;
/* Ensure the given object_dir is local, or a known alternate. */
- find_odb(r, obj_dir_real);
+ odb_find_source(r->objects, obj_dir_real);
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
strbuf_realpath(&cur_path_real, cur->object_dir, 1);
diff --git a/odb.c b/odb.c
index 0464d7f54a2..240fc62ca2b 100644
--- a/odb.c
+++ b/odb.c
@@ -448,14 +448,14 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
return ref_git;
}
-struct odb_source *find_odb(struct repository *r, const char *obj_dir)
+struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir)
{
struct odb_source *source;
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(r);
- for (source = r->objects->sources; source; source = source->next) {
+ prepare_alt_odb(odb->repo);
+ for (source = odb->sources; source; source = source->next) {
strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
break;
diff --git a/odb.h b/odb.h
index c3851e29668..941329c6943 100644
--- a/odb.h
+++ b/odb.h
@@ -68,7 +68,6 @@ struct odb_source {
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
-struct odb_source *find_odb(struct repository *r, const char *obj_dir);
typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
@@ -195,6 +194,12 @@ struct object_database {
struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o);
+/*
+ * Find source by its object directory path. Dies in case the source couldn't
+ * be found.
+ */
+struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+
/*
* Create a temporary file rooted in the object database directory, or
* die on failure. The filename is taken from "pattern", which should have the
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 06/17] odb: get rid of `the_repository` in `assert_oid_type()`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (4 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 05/17] odb: get rid of `the_repository` in `find_odb()` Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 07/17] odb: get rid of `the_repository` in `odb_mkstemp()` Patrick Steinhardt
` (11 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Get rid of our dependency on `the_repository` in `assert_oid_type()` by
passing in the object database as a parameter and adjusting all callers.
Rename the function to `odb_assert_oid_type()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/commit-tree.c | 2 +-
commit.c | 2 +-
odb.c | 5 +++--
odb.h | 3 ++-
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 546069f8682..31cfd9bd15d 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -48,7 +48,7 @@ static int parse_parent_arg_callback(const struct option *opt,
if (repo_get_oid_commit(the_repository, arg, &oid))
die(_("not a valid object name %s"), arg);
- assert_oid_type(&oid, OBJ_COMMIT);
+ odb_assert_oid_type(the_repository->objects, &oid, OBJ_COMMIT);
new_parent(lookup_commit(the_repository, &oid), parents);
return 0;
}
diff --git a/commit.c b/commit.c
index 1d30f8ce15a..aa65183d8b6 100644
--- a/commit.c
+++ b/commit.c
@@ -1706,7 +1706,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
/* Not having i18n.commitencoding is the same as having utf-8 */
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
- assert_oid_type(tree, OBJ_TREE);
+ odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);
if (memchr(msg, '\0', msg_len))
return error("a NUL byte in commit log message not allowed.");
diff --git a/odb.c b/odb.c
index 240fc62ca2b..d0ca2990774 100644
--- a/odb.c
+++ b/odb.c
@@ -946,9 +946,10 @@ int has_object(struct repository *r, const struct object_id *oid,
return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
}
-void assert_oid_type(const struct object_id *oid, enum object_type expect)
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = oid_object_info(odb->repo, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index 941329c6943..13f5da45f54 100644
--- a/odb.h
+++ b/odb.h
@@ -302,7 +302,8 @@ enum {
int has_object(struct repository *r, const struct object_id *oid,
unsigned flags);
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
+void odb_assert_oid_type(struct object_database *odb,
+ const struct object_id *oid, enum object_type expect);
/*
* Enabling the object read lock allows multiple threads to safely call the
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 07/17] odb: get rid of `the_repository` in `odb_mkstemp()`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (5 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 06/17] odb: get rid of `the_repository` in `assert_oid_type()` Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
` (10 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Get rid of our dependency on `the_repository` in `odb_mkstemp()` by
passing in the object database as a parameter and adjusting all callers.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 3 ++-
builtin/index-pack.c | 2 +-
bundle-uri.c | 3 ++-
odb.c | 9 +++++----
odb.h | 7 ++++---
pack-bitmap-write.c | 3 ++-
pack-write.c | 10 ++++++----
7 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 52c792488e1..413304db9b5 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -763,7 +763,8 @@ static void start_packfile(void)
struct packed_git *p;
int pack_fd;
- pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX");
+ pack_fd = odb_mkstemp(the_repository->objects, &tmp_file,
+ "pack/tmp_pack_XXXXXX");
FLEX_ALLOC_STR(p, pack_name, tmp_file.buf);
strbuf_release(&tmp_file);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 1aabe6b8ee2..4d4d989eb1a 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -362,7 +362,7 @@ static const char *open_pack_file(const char *pack_name)
input_fd = 0;
if (!pack_name) {
struct strbuf tmp_file = STRBUF_INIT;
- output_fd = odb_mkstemp(&tmp_file,
+ output_fd = odb_mkstemp(the_repository->objects, &tmp_file,
"pack/tmp_pack_XXXXXX");
pack_name = strbuf_detach(&tmp_file, NULL);
} else {
diff --git a/bundle-uri.c b/bundle-uri.c
index 2e623f8627a..f94e780e967 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -278,7 +278,8 @@ static char *find_temp_filename(void)
* Find a temporary filename that is available. This is briefly
* racy, but unlikely to collide.
*/
- fd = odb_mkstemp(&name, "bundles/tmp_uri_XXXXXX");
+ fd = odb_mkstemp(the_repository->objects, &name,
+ "bundles/tmp_uri_XXXXXX");
if (fd < 0) {
warning(_("failed to create temporary file"));
return NULL;
diff --git a/odb.c b/odb.c
index d0ca2990774..8967e9fd548 100644
--- a/odb.c
+++ b/odb.c
@@ -63,7 +63,8 @@ static const struct cached_object *find_cached_object(struct object_database *ob
return NULL;
}
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern)
{
int fd;
/*
@@ -71,15 +72,15 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
* restrictive except to remove write permission.
*/
int mode = 0444;
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
fd = git_mkstemp_mode(temp_filename->buf, mode);
if (0 <= fd)
return fd;
/* slow path */
/* some mkstemp implementations erase temp_filename on failure */
- repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
- safe_create_leading_directories(the_repository, temp_filename->buf);
+ repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
+ safe_create_leading_directories(odb->repo, temp_filename->buf);
return xmkstemp_mode(temp_filename->buf, mode);
}
diff --git a/odb.h b/odb.h
index 13f5da45f54..5de952608f3 100644
--- a/odb.h
+++ b/odb.h
@@ -201,12 +201,13 @@ void odb_clear(struct object_database *o);
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
/*
- * Create a temporary file rooted in the object database directory, or
- * die on failure. The filename is taken from "pattern", which should have the
+ * Create a temporary file rooted in the primary alternate's directory, or die
+ * on failure. The filename is taken from "pattern", which should have the
* usual "XXXXXX" trailer, and the resulting filename is written into the
* "template" buffer. Returns the open descriptor.
*/
-int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
+int odb_mkstemp(struct object_database *odb,
+ struct strbuf *temp_filename, const char *pattern);
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 37648b57125..c847369eaaa 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1052,7 +1052,8 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
struct bitmap_disk_header header;
- int fd = odb_mkstemp(&tmp_file, "pack/tmp_bitmap_XXXXXX");
+ int fd = odb_mkstemp(writer->repo->objects, &tmp_file,
+ "pack/tmp_bitmap_XXXXXX");
if (writer->pseudo_merges_nr)
options |= BITMAP_OPT_PSEUDO_MERGES;
diff --git a/pack-write.c b/pack-write.c
index 6b06315f80a..eccdc798e36 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -84,7 +84,8 @@ const char *write_idx_file(struct repository *repo,
} else {
if (!index_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_idx_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_idx_XXXXXX");
index_name = strbuf_detach(&tmp_file, NULL);
} else {
unlink(index_name);
@@ -259,7 +260,8 @@ char *write_rev_file_order(struct repository *repo,
if (flags & WRITE_REV) {
if (!rev_name) {
struct strbuf tmp_file = STRBUF_INIT;
- fd = odb_mkstemp(&tmp_file, "pack/tmp_rev_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file,
+ "pack/tmp_rev_XXXXXX");
path = strbuf_detach(&tmp_file, NULL);
} else {
unlink(rev_name);
@@ -342,7 +344,7 @@ static char *write_mtimes_file(struct repository *repo,
if (!to_pack)
BUG("cannot call write_mtimes_file with NULL packing_data");
- fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmp_file, "pack/tmp_mtimes_XXXXXX");
mtimes_name = strbuf_detach(&tmp_file, NULL);
f = hashfd(repo->hash_algo, fd, mtimes_name);
@@ -531,7 +533,7 @@ struct hashfile *create_tmp_packfile(struct repository *repo,
struct strbuf tmpname = STRBUF_INIT;
int fd;
- fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
+ fd = odb_mkstemp(repo->objects, &tmpname, "pack/tmp_pack_XXXXXX");
*pack_tmp_name = strbuf_detach(&tmpname, NULL);
return hashfd(repo->hash_algo, fd, *pack_tmp_name);
}
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 08/17] odb: get rid of `the_repository` when handling alternates
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (6 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 07/17] odb: get rid of `the_repository` in `odb_mkstemp()` Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
` (9 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The functions to manage alternates all depend on `the_repository`.
Refactor them to accept an object database as a parameter and adjust all
callers. The functions are renamed accordingly.
Note that right now the situation is still somewhat weird because we end
up using the object store path provided by the object store's repository
anyway. Consequently, we could have instead passed in a pointer to the
repository instead of passing in the pointer to the object store. This
will be addressed in subsequent commits though, where we will start to
use the path owned by the object store itself.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/clone.c | 10 +++++----
builtin/fsck.c | 6 +++---
builtin/grep.c | 2 +-
builtin/repack.c | 3 ++-
commit-graph.c | 4 ++--
loose.c | 2 +-
object-file.c | 10 ++++-----
object-name.c | 2 +-
odb.c | 44 ++++++++++++++++++---------------------
odb.h | 53 ++++++++++++++++++++++++++++++++---------------
packfile.c | 4 ++--
submodule.c | 3 ++-
t/helper/test-ref-store.c | 2 +-
tmp-objdir.c | 2 +-
14 files changed, 83 insertions(+), 64 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 1eafeefb48d..3aabdf6570b 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -171,7 +171,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
} else {
struct strbuf sb = STRBUF_INIT;
strbuf_addf(&sb, "%s/objects", ref_git);
- add_to_alternates_file(sb.buf);
+ odb_add_to_alternates_file(the_repository->objects, sb.buf);
strbuf_release(&sb);
}
@@ -212,12 +212,14 @@ static void copy_alternates(struct strbuf *src, const char *src_repo)
if (!line.len || line.buf[0] == '#')
continue;
if (is_absolute_path(line.buf)) {
- add_to_alternates_file(line.buf);
+ odb_add_to_alternates_file(the_repository->objects,
+ line.buf);
continue;
}
abs_path = mkpathdup("%s/objects/%s", src_repo, line.buf);
if (!normalize_path_copy(abs_path, abs_path))
- add_to_alternates_file(abs_path);
+ odb_add_to_alternates_file(the_repository->objects,
+ abs_path);
else
warning("skipping invalid relative alternate: %s/%s",
src_repo, line.buf);
@@ -352,7 +354,7 @@ static void clone_local(const char *src_repo, const char *dest_repo)
struct strbuf alt = STRBUF_INIT;
get_common_dir(&alt, src_repo);
strbuf_addstr(&alt, "/objects");
- add_to_alternates_file(alt.buf);
+ odb_add_to_alternates_file(the_repository->objects, alt.buf);
strbuf_release(&alt);
} else {
struct strbuf src = STRBUF_INIT;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 9abd7b25580..014aa1344e2 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -997,7 +997,7 @@ int cmd_fsck(int argc,
for_each_packed_object(the_repository,
mark_packed_for_connectivity, NULL, 0);
} else {
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next)
fsck_object_dir(source->path);
@@ -1108,7 +1108,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_commit_graph) {
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&commit_graph_verify);
commit_graph_verify.git_cmd = 1;
@@ -1126,7 +1126,7 @@ int cmd_fsck(int argc,
if (the_repository->settings.core_multi_pack_index) {
struct child_process midx_verify = CHILD_PROCESS_INIT;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
diff --git a/builtin/grep.c b/builtin/grep.c
index a1d7ee7af39..336cfcab6fb 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -462,7 +462,7 @@ static int grep_submodule(struct grep_opt *opt,
/*
* NEEDSWORK: repo_read_gitmodules() might call
- * add_to_alternates_memory() via config_from_gitmodules(). This
+ * odb_add_to_alternates_memory() via config_from_gitmodules(). This
* operation causes a race condition with concurrent object readings
* performed by the worker threads. That's why we need obj_read_lock()
* here. It should be removed once it's no longer necessary to add the
diff --git a/builtin/repack.c b/builtin/repack.c
index 16782320058..8145474cf8d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1256,7 +1256,8 @@ int cmd_repack(int argc,
if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
die(_(incremental_bitmap_conflict_error));
- if (write_bitmaps && po_args.local && has_alt_odb(the_repository)) {
+ if (write_bitmaps && po_args.local &&
+ odb_has_alternates(the_repository->objects)) {
/*
* When asked to do a local repack, but we have
* packfiles that are inherited from an alternate, then
diff --git a/commit-graph.c b/commit-graph.c
index 6ced5b366e7..59265f89385 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -649,7 +649,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
count = st->st_size / (the_hash_algo->hexsz + 1);
CALLOC_ARRAY(oids, count);
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (i = 0; i < count; i++) {
struct odb_source *source;
@@ -778,7 +778,7 @@ static int prepare_commit_graph(struct repository *r)
if (!commit_graph_compatible(r))
return 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources;
!r->objects->commit_graph && source;
source = source->next)
diff --git a/loose.c b/loose.c
index fab4041c03d..519f5db7935 100644
--- a/loose.c
+++ b/loose.c
@@ -112,7 +112,7 @@ int repo_read_loose_object_map(struct repository *repo)
if (!should_use_loose_object_map(repo))
return 0;
- prepare_alt_odb(repo);
+ odb_prepare_alternates(repo->objects);
for (source = repo->objects->sources; source; source = source->next) {
if (load_one_loose_object_map(repo, source) < 0) {
diff --git a/object-file.c b/object-file.c
index 2d3af8a77c0..04da19a1a3b 100644
--- a/object-file.c
+++ b/object-file.c
@@ -106,7 +106,7 @@ static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
struct odb_source *source;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources->next; source; source = source->next) {
if (check_and_freshen_odb(source, oid, freshen))
return 1;
@@ -205,7 +205,7 @@ static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct odb_source *source;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
*path = odb_loose_path(source, &buf, oid);
if (!lstat(*path, st))
@@ -227,7 +227,7 @@ static int open_loose_object(struct repository *r,
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
*path = odb_loose_path(source, &buf, oid);
fd = git_open(*path);
@@ -246,7 +246,7 @@ static int quick_has_loose(struct repository *r,
{
struct odb_source *source;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
if (oidtree_contains(odb_loose_cache(source, oid), oid))
return 1;
@@ -1439,7 +1439,7 @@ int for_each_loose_object(each_loose_object_fn cb, void *data,
{
struct odb_source *source;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next) {
int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
NULL, data);
diff --git a/object-name.c b/object-name.c
index 544634d0f40..381536e900e 100644
--- a/object-name.c
+++ b/object-name.c
@@ -376,7 +376,7 @@ static int init_object_disambiguation(struct repository *r,
ds->hex_pfx[len] = '\0';
ds->repo = r;
ds->bin_pfx.algo = algo ? hash_algo_by_ptr(algo) : GIT_HASH_UNKNOWN;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
return 0;
}
diff --git a/odb.c b/odb.c
index 8967e9fd548..691a8c7c681 100644
--- a/odb.c
+++ b/odb.c
@@ -272,10 +272,11 @@ static void read_info_alternates(struct object_database *odb,
free(path);
}
-void add_to_alternates_file(const char *reference)
+void odb_add_to_alternates_file(struct object_database *odb,
+ const char *reference)
{
struct lock_file lock = LOCK_INIT;
- char *alts = repo_git_path(the_repository, "objects/info/alternates");
+ char *alts = repo_git_path(odb->repo, "objects/info/alternates");
FILE *in, *out;
int found = 0;
@@ -308,22 +309,23 @@ void add_to_alternates_file(const char *reference)
fprintf_or_die(out, "%s\n", reference);
if (commit_lock_file(&lock))
die_errno(_("unable to move new alternates file into place"));
- if (the_repository->objects->loaded_alternates)
- link_alt_odb_entries(the_repository->objects, reference,
+ if (odb->loaded_alternates)
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
free(alts);
}
-void add_to_alternates_memory(const char *reference)
+void odb_add_to_alternates_memory(struct object_database *odb,
+ const char *reference)
{
/*
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(odb);
- link_alt_odb_entries(the_repository->objects, reference,
+ link_alt_odb_entries(odb, reference,
'\n', NULL, 0);
}
@@ -335,7 +337,7 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
/*
* Make a new primary odb and link the old primary ODB in as an
@@ -379,12 +381,6 @@ void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
free_object_directory(cur_alt);
}
-/*
- * Compute the exact path an alternate is at and returns it. In case of
- * error NULL is returned and the human readable error is added to `err`
- * `path` may be relative and should point to $GIT_DIR.
- * `err` must not be null.
- */
char *compute_alternate_path(const char *path, struct strbuf *err)
{
char *ref_git = NULL;
@@ -455,7 +451,7 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT;
- prepare_alt_odb(odb->repo);
+ odb_prepare_alternates(odb);
for (source = odb->sources; source; source = source->next) {
strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf))
@@ -573,7 +569,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
struct odb_source *alternate;
int r = 0;
- prepare_alt_odb(the_repository);
+ odb_prepare_alternates(the_repository->objects);
for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
r = fn(alternate, cb);
if (r)
@@ -582,21 +578,21 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
return r;
}
-void prepare_alt_odb(struct repository *r)
+void odb_prepare_alternates(struct object_database *odb)
{
- if (r->objects->loaded_alternates)
+ if (odb->loaded_alternates)
return;
- link_alt_odb_entries(r->objects, r->objects->alternate_db, PATH_SEP, NULL, 0);
+ link_alt_odb_entries(odb, odb->alternate_db, PATH_SEP, NULL, 0);
- read_info_alternates(r->objects, r->objects->sources->path, 0);
- r->objects->loaded_alternates = 1;
+ read_info_alternates(odb, odb->sources->path, 0);
+ odb->loaded_alternates = 1;
}
-int has_alt_odb(struct repository *r)
+int odb_has_alternates(struct object_database *odb)
{
- prepare_alt_odb(r);
- return !!r->objects->sources->next;
+ odb_prepare_alternates(odb);
+ return !!odb->sources->next;
}
int obj_read_use_lock = 0;
diff --git a/odb.h b/odb.h
index 5de952608f3..eba16929a81 100644
--- a/odb.h
+++ b/odb.h
@@ -13,6 +13,14 @@ struct oidtree;
struct strbuf;
struct repository;
+/*
+ * Compute the exact path an alternate is at and returns it. In case of
+ * error NULL is returned and the human readable error is added to `err`
+ * `path` may be relative and should point to $GIT_DIR.
+ * `err` must not be null.
+ */
+char *compute_alternate_path(const char *path, struct strbuf *err);
+
/*
* The source is the part of the object database that stores the actual
* objects. It thus encapsulates the logic to read and write the specific
@@ -65,27 +73,11 @@ struct odb_source {
char *path;
};
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
-/*
- * 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);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -124,7 +116,7 @@ struct object_database {
/*
* A list of alternate object directories loaded from the environment;
* this should not generally need to be accessed directly, but will
- * populate the "sources" list when prepare_alt_odb() is run.
+ * populate the "sources" list when odb_prepare_alternates() is run.
*/
char *alternate_db;
@@ -209,6 +201,33 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
int odb_mkstemp(struct object_database *odb,
struct strbuf *temp_filename, const char *pattern);
+/*
+ * Prepare alternate object sources for the given database by reading
+ * "objects/info/alternates" and opening the respective sources.
+ */
+void odb_prepare_alternates(struct object_database *odb);
+
+/*
+ * Check whether the object database has any alternates. The primary object
+ * source does not count as alternate.
+ */
+int odb_has_alternates(struct object_database *odb);
+
+/*
+ * Add the directory to the on-disk alternates file; the new entry will also
+ * take effect in the current process.
+ */
+void odb_add_to_alternates_file(struct object_database *odb,
+ const char *dir);
+
+/*
+ * Add the directory to the in-memory list of alternate sources (along with any
+ * recursive alternates it points to), but do not modify the on-disk alternates
+ * file.
+ */
+void odb_add_to_alternates_memory(struct object_database *odb,
+ const char *dir);
+
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,
diff --git a/packfile.c b/packfile.c
index 346c2f9ce90..ac0e29e99b9 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1034,7 +1034,7 @@ static void prepare_packed_git(struct repository *r)
if (r->objects->packed_git_initialized)
return;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next) {
int local = (source == r->objects->sources);
prepare_multi_pack_index_one(r, source->path, local);
@@ -1059,7 +1059,7 @@ void reprepare_packed_git(struct repository *r)
* the lifetime of the process.
*/
r->objects->loaded_alternates = 0;
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (source = r->objects->sources; source; source = source->next)
odb_clear_loose_cache(source);
diff --git a/submodule.c b/submodule.c
index 9b1018877df..386be234230 100644
--- a/submodule.c
+++ b/submodule.c
@@ -189,7 +189,8 @@ int register_all_submodule_odb_as_alternates(void)
int ret = added_submodule_odb_paths.nr;
for (i = 0; i < added_submodule_odb_paths.nr; i++)
- add_to_alternates_memory(added_submodule_odb_paths.items[i].string);
+ odb_add_to_alternates_memory(the_repository->objects,
+ added_submodule_odb_paths.items[i].string);
if (ret) {
string_list_clear(&added_submodule_odb_paths, 0);
trace2_data_intmax("submodule", the_repository,
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 2920ca59d72..8d9a271845c 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -79,7 +79,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)
if (!repo_submodule_path_append(the_repository,
&sb, gitdir, "objects/"))
die("computing submodule path failed");
- add_to_alternates_memory(sb.buf);
+ odb_add_to_alternates_memory(the_repository->objects, sb.buf);
strbuf_release(&sb);
*refs = repo_get_submodule_ref_store(the_repository, gitdir);
diff --git a/tmp-objdir.c b/tmp-objdir.c
index bef2f917cd2..4120badf5ce 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -304,7 +304,7 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)
void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
{
- add_to_alternates_memory(t->path.buf);
+ odb_add_to_alternates_memory(t->repo->objects, t->path.buf);
}
void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 09/17] odb: get rid of `the_repository` in `for_each()` functions
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (7 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 08/17] odb: get rid of `the_repository` when handling alternates Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 10/17] odb: get rid of `the_repository` when handling the primary source Patrick Steinhardt
` (8 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
There are a couple of iterator-style functions that execute a callback
for each instance of a given set, all of which currently depend on
`the_repository`. Refactor them to instead take an object database as
parameter so that we can get rid of this dependency.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/count-objects.c | 2 +-
builtin/receive-pack.c | 3 ++-
builtin/submodule--helper.c | 3 ++-
diagnose.c | 2 +-
fetch-pack.c | 3 ++-
odb.c | 36 +++++++++++++++++++-----------------
odb.h | 23 ++++++++++++++++++-----
revision.c | 3 ++-
8 files changed, 47 insertions(+), 28 deletions(-)
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 58e0af433d1..f687647931e 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -159,7 +159,7 @@ int cmd_count_objects(int argc,
printf("prune-packable: %lu\n", packed_loose);
printf("garbage: %lu\n", garbage);
printf("size-garbage: %s\n", garbage_buf.buf);
- foreach_alt_odb(print_alternate, NULL);
+ odb_for_each_alternate(the_repository->objects, print_alternate, NULL);
strbuf_release(&loose_buf);
strbuf_release(&pack_buf);
strbuf_release(&garbage_buf);
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 0f5958c4a66..7ea273d93e4 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -359,7 +359,8 @@ static void write_head_info(void)
refs_for_each_fullref_in(get_main_ref_store(the_repository), "",
exclude_patterns, show_ref_cb, &seen);
- for_each_alternate_ref(show_one_alternate_ref, &seen);
+ odb_for_each_alternate_ref(the_repository->objects,
+ show_one_alternate_ref, &seen);
oidset_clear(&seen);
strvec_clear(&excludes_vector);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 84f7fa53424..7ca483cab52 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1668,7 +1668,8 @@ static void prepare_possible_alternates(const char *sm_name,
die(_("Value '%s' for submodule.alternateErrorStrategy is not recognized"), error_strategy);
if (!strcmp(sm_alternate, "superproject"))
- foreach_alt_odb(add_possible_reference_from_superproject, &sas);
+ odb_for_each_alternate(the_repository->objects,
+ add_possible_reference_from_superproject, &sas);
else if (!strcmp(sm_alternate, "no"))
; /* do nothing */
else
diff --git a/diagnose.c b/diagnose.c
index ad0d5c12465..5092bf80d35 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -229,7 +229,7 @@ int create_diagnostics_archive(struct repository *r,
strbuf_reset(&buf);
strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
dir_file_stats(r->objects->sources, &buf);
- foreach_alt_odb(dir_file_stats, &buf);
+ odb_for_each_alternate(r->objects, dir_file_stats, &buf);
strvec_push(&archiver_args, buf.buf);
strbuf_reset(&buf);
diff --git a/fetch-pack.c b/fetch-pack.c
index cf157f5d7e5..47fa7fa4c49 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -115,7 +115,8 @@ static void for_each_cached_alternate(struct fetch_negotiator *negotiator,
size_t i;
if (!initialized) {
- for_each_alternate_ref(cache_one_alternate, &cache);
+ odb_for_each_alternate_ref(the_repository->objects,
+ cache_one_alternate, &cache);
initialized = 1;
}
diff --git a/odb.c b/odb.c
index 691a8c7c681..03fb68605c1 100644
--- a/odb.c
+++ b/odb.c
@@ -494,8 +494,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
}
static void read_alternate_refs(const char *path,
- alternate_ref_fn *cb,
- void *data)
+ odb_for_each_alternate_ref_fn *cb,
+ void *payload)
{
struct child_process cmd = CHILD_PROCESS_INIT;
struct strbuf line = STRBUF_INIT;
@@ -517,7 +517,7 @@ static void read_alternate_refs(const char *path,
break;
}
- cb(&oid, data);
+ cb(&oid, payload);
}
fclose(fh);
@@ -526,16 +526,16 @@ static void read_alternate_refs(const char *path,
}
struct alternate_refs_data {
- alternate_ref_fn *fn;
- void *data;
+ odb_for_each_alternate_ref_fn *fn;
+ void *payload;
};
static int refs_from_alternate_cb(struct odb_source *alternate,
- void *data)
+ void *payload)
{
struct strbuf path = STRBUF_INIT;
size_t base_len;
- struct alternate_refs_data *cb = data;
+ struct alternate_refs_data *cb = payload;
if (!strbuf_realpath(&path, alternate->path, 0))
goto out;
@@ -549,29 +549,31 @@ static int refs_from_alternate_cb(struct odb_source *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->data);
+ read_alternate_refs(path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
return 0;
}
-void for_each_alternate_ref(alternate_ref_fn fn, void *data)
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload)
{
- struct alternate_refs_data cb;
- cb.fn = fn;
- cb.data = data;
- foreach_alt_odb(refs_from_alternate_cb, &cb);
+ struct alternate_refs_data data;
+ data.fn = cb;
+ data.payload = payload;
+ odb_for_each_alternate(odb, refs_from_alternate_cb, &data);
}
-int foreach_alt_odb(alt_odb_fn fn, void *cb)
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload)
{
struct odb_source *alternate;
int r = 0;
- odb_prepare_alternates(the_repository->objects);
- for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
- r = fn(alternate, cb);
+ odb_prepare_alternates(odb);
+ for (alternate = odb->sources->next; alternate; alternate = alternate->next) {
+ r = cb(alternate, payload);
if (r)
break;
}
diff --git a/odb.h b/odb.h
index eba16929a81..7e65e9707c1 100644
--- a/odb.h
+++ b/odb.h
@@ -73,11 +73,6 @@ struct odb_source {
char *path;
};
-typedef int alt_odb_fn(struct odb_source *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
-
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -192,6 +187,24 @@ void odb_clear(struct object_database *o);
*/
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+/*
+ * Iterate through all alternates of the database and execute the provided
+ * callback function for each of them. Stop iterating once the callback
+ * function returns a non-zero value, in which case the value is bubbled up
+ * from the callback.
+ */
+typedef int odb_for_each_alternate_fn(struct odb_source *, void *);
+int odb_for_each_alternate(struct object_database *odb,
+ odb_for_each_alternate_fn cb, void *payload);
+
+/*
+ * Iterate through all alternates of the database and yield their respective
+ * references.
+ */
+typedef void odb_for_each_alternate_ref_fn(const struct object_id *oid, void *);
+void odb_for_each_alternate_ref(struct object_database *odb,
+ odb_for_each_alternate_ref_fn cb, void *payload);
+
/*
* Create a temporary file rooted in the primary alternate's directory, or die
* on failure. The filename is taken from "pattern", which should have the
diff --git a/revision.c b/revision.c
index cdefe7d6e48..b0364f556ee 100644
--- a/revision.c
+++ b/revision.c
@@ -1907,7 +1907,8 @@ static void add_alternate_refs_to_pending(struct rev_info *revs,
struct add_alternate_refs_data data;
data.revs = revs;
data.flags = flags;
- for_each_alternate_ref(add_one_alternate_ref, &data);
+ odb_for_each_alternate_ref(the_repository->objects,
+ add_one_alternate_ref, &data);
}
static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 10/17] odb: get rid of `the_repository` when handling the primary source
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (8 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 09/17] odb: get rid of `the_repository` in `for_each()` functions Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 11/17] odb: get rid of `the_repository` when handling submodule sources Patrick Steinhardt
` (7 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The functions `set_temporary_primary_odb()` and `restore_primary_odb()`
are responsible for managing a temporary primary source for the
database. Both of these functions implicitly rely on `the_repository`.
Refactor them to instead take an explicit object database parameter as
argument and adjust callers. Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 27 +++++++++++++++------------
odb.h | 26 +++++++++++++++-----------
tmp-objdir.c | 10 ++++++----
3 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/odb.c b/odb.c
index 03fb68605c1..4f03be7f770 100644
--- a/odb.c
+++ b/odb.c
@@ -329,7 +329,8 @@ void odb_add_to_alternates_memory(struct object_database *odb,
'\n', NULL, 0);
}
-struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
+struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
+ const char *dir, int will_destroy)
{
struct odb_source *source;
@@ -337,14 +338,14 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
* Make sure alternates are initialized, or else our entry may be
* overwritten when they are.
*/
- odb_prepare_alternates(the_repository->objects);
+ odb_prepare_alternates(odb);
/*
* Make a new primary odb and link the old primary ODB in as an
* alternate
*/
source = xcalloc(1, sizeof(*source));
- source->odb = the_repository->objects;
+ source->odb = odb;
source->path = xstrdup(dir);
/*
@@ -353,8 +354,8 @@ struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
*/
source->disable_ref_updates = 1;
source->will_destroy = will_destroy;
- source->next = the_repository->objects->sources;
- the_repository->objects->sources = source;
+ source->next = odb->sources;
+ odb->sources = source;
return source->next;
}
@@ -366,19 +367,21 @@ static void free_object_directory(struct odb_source *source)
free(source);
}
-void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
+void odb_restore_primary_source(struct object_database *odb,
+ struct odb_source *restore_source,
+ const char *old_path)
{
- struct odb_source *cur_alt = the_repository->objects->sources;
+ struct odb_source *cur_source = odb->sources;
- if (strcmp(old_path, cur_alt->path))
+ if (strcmp(old_path, cur_source->path))
BUG("expected %s as primary object store; found %s",
- old_path, cur_alt->path);
+ old_path, cur_source->path);
- if (cur_alt->next != restore_alt)
+ if (cur_source->next != restore_source)
BUG("we expect the old primary object store to be the first alternate");
- the_repository->objects->sources = restore_alt;
- free_object_directory(cur_alt);
+ odb->sources = restore_source;
+ free_object_directory(cur_source);
}
char *compute_alternate_path(const char *path, struct strbuf *err)
diff --git a/odb.h b/odb.h
index 7e65e9707c1..4e2d1004f8a 100644
--- a/odb.h
+++ b/odb.h
@@ -73,17 +73,6 @@ struct odb_source {
char *path;
};
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy);
-
-/*
- * Restore a previous ODB replaced by set_temporary_main_odb.
- */
-void restore_primary_odb(struct odb_source *restore_alternate, const char *old_path);
-
struct packed_git;
struct multi_pack_index;
struct cached_object_entry;
@@ -187,6 +176,21 @@ void odb_clear(struct object_database *o);
*/
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary source.
+ */
+struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
+ const char *dir, int will_destroy);
+
+/*
+ * Restore the primary source that was previously replaced by
+ * `odb_set_temporary_primary_source()`.
+ */
+void odb_restore_primary_source(struct object_database *odb,
+ struct odb_source *restore_source,
+ const char *old_path);
+
/*
* Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 4120badf5ce..ae01eae9c41 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -47,7 +47,7 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
the_tmp_objdir = NULL;
if (t->prev_source)
- restore_primary_odb(t->prev_source, t->path.buf);
+ odb_restore_primary_source(t->repo->objects, t->prev_source, t->path.buf);
err = remove_dir_recursively(&t->path, 0);
@@ -279,7 +279,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (t->prev_source) {
if (t->repo->objects->sources->will_destroy)
BUG("migrating an ODB that was marked for destruction");
- restore_primary_odb(t->prev_source, t->path.buf);
+ odb_restore_primary_source(t->repo->objects, t->prev_source, t->path.buf);
t->prev_source = NULL;
}
@@ -311,7 +311,8 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
{
if (t->prev_source)
BUG("the primary object database is already replaced");
- t->prev_source = set_temporary_primary_odb(t->path.buf, will_destroy);
+ t->prev_source = odb_set_temporary_primary_source(t->repo->objects,
+ t->path.buf, will_destroy);
t->will_destroy = will_destroy;
}
@@ -320,7 +321,8 @@ struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
if (!the_tmp_objdir || !the_tmp_objdir->prev_source)
return NULL;
- restore_primary_odb(the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
+ odb_restore_primary_source(the_tmp_objdir->repo->objects,
+ the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
the_tmp_objdir->prev_source = NULL;
return the_tmp_objdir;
}
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 11/17] odb: get rid of `the_repository` when handling submodule sources
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (9 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 10/17] odb: get rid of `the_repository` when handling the primary source Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
` (6 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
The "--recursive" flag for git-grep(1) allows users to grep for a string
across submodule boundaries. To make this work we add each submodule's
object sources to our own object database so that the objects can be
accessed directly.
The infrastructure for this depends on a global string list of submodule
paths. The caller is expected to call `add_submodule_odb_by_path()` for
each source and the object database will then eventually register all
submodule sources via `do_oid_object_info_extended()` in case it isn't
able to look up a specific object.
This reliance on global state is of course suboptimal with regards to
our libification efforts.
Refactor the logic so that the list of submodule sources is instead
tracked in the object database itself. This allows us to lose the
condition of `r == the_repository` before registering submodule sources
as we only ever add submodule sources to `the_repository` anyway. As
such, behaviour before and after this refactoring should always be the
same.
Rename the functions accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/grep.c | 3 ++-
odb.c | 37 +++++++++++++++++++++++++++++++------
odb.h | 15 +++++++++++++++
submodule-config.c | 3 ++-
submodule.c | 26 --------------------------
submodule.h | 9 ---------
6 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 336cfcab6fb..cfcf916bce1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -505,7 +505,8 @@ static int grep_submodule(struct grep_opt *opt,
* lazily registered as alternates when needed (and except in an
* unexpected code interaction, it won't be needed).
*/
- add_submodule_odb_by_path(subrepo->objects->sources->path);
+ odb_add_submodule_source_by_path(the_repository->objects,
+ subrepo->objects->sources->path);
obj_read_unlock();
memcpy(&subopt, opt, sizeof(subopt));
diff --git a/odb.c b/odb.c
index 4f03be7f770..f0b27bd936b 100644
--- a/odb.c
+++ b/odb.c
@@ -24,6 +24,7 @@
#include "strbuf.h"
#include "strvec.h"
#include "submodule.h"
+#include "trace2.h"
#include "write-or-die.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
@@ -469,6 +470,12 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
return source;
}
+void odb_add_submodule_source_by_path(struct object_database *odb,
+ const char *path)
+{
+ string_list_insert(&odb->submodule_source_paths, path);
+}
+
static void fill_alternate_refs_command(struct child_process *cmd,
const char *repo_path)
{
@@ -623,6 +630,23 @@ void disable_obj_read_lock(void)
int fetch_if_missing = 1;
+static int register_all_submodule_sources(struct object_database *odb)
+{
+ int ret = odb->submodule_source_paths.nr;
+
+ for (size_t i = 0; i < odb->submodule_source_paths.nr; i++)
+ odb_add_to_alternates_memory(odb,
+ odb->submodule_source_paths.items[i].string);
+ if (ret) {
+ string_list_clear(&odb->submodule_source_paths, 0);
+ trace2_data_intmax("submodule", odb->repo,
+ "register_all_submodule_sources/registered", ret);
+ if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
+ BUG("register_all_submodule_sources() called");
+ }
+ return ret;
+}
+
static int do_oid_object_info_extended(struct repository *r,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
@@ -676,13 +700,12 @@ static int do_oid_object_info_extended(struct repository *r,
}
/*
- * If r is the_repository, this might be an attempt at
- * accessing a submodule object as if it were in the_repository
- * (having called add_submodule_odb() on that submodule's ODB).
- * If any such ODBs exist, register them and try again.
+ * This might be an attempt at accessing a submodule object as
+ * if it were in main object store (having called
+ * `odb_add_submodule_source_by_path()` on that submodule's
+ * ODB). If any such ODBs exist, register them and try again.
*/
- if (r == the_repository &&
- register_all_submodule_odb_as_alternates())
+ if (register_all_submodule_sources(r->objects))
/* We added some alternates; retry */
continue;
@@ -968,6 +991,7 @@ struct object_database *odb_new(struct repository *repo)
INIT_LIST_HEAD(&o->packed_git_mru);
hashmap_init(&o->pack_map, pack_map_entry_cmp, NULL, 0);
pthread_mutex_init(&o->replace_mutex, NULL);
+ string_list_init_dup(&o->submodule_source_paths);
return o;
}
@@ -1017,4 +1041,5 @@ void odb_clear(struct object_database *o)
o->packed_git = NULL;
hashmap_clear(&o->pack_map);
+ string_list_clear(&o->submodule_source_paths, 0);
}
diff --git a/odb.h b/odb.h
index 4e2d1004f8a..0ea9d4faa70 100644
--- a/odb.h
+++ b/odb.h
@@ -6,6 +6,7 @@
#include "list.h"
#include "oidset.h"
#include "oidmap.h"
+#include "string-list.h"
#include "thread-utils.h"
struct oidmap;
@@ -165,6 +166,12 @@ struct object_database {
* packs.
*/
unsigned packed_git_initialized : 1;
+
+ /*
+ * Submodule source paths that will be added as additional sources to
+ * allow lookup of submodule objects via the main object database.
+ */
+ struct string_list submodule_source_paths;
};
struct object_database *odb_new(struct repository *repo);
@@ -191,6 +198,14 @@ void odb_restore_primary_source(struct object_database *odb,
struct odb_source *restore_source,
const char *old_path);
+/*
+ * Call odb_add_submodule_source_by_path() to add the submodule at the given
+ * path to a list. The object stores of all submodules in that list will be
+ * added as additional sources in the object store when looking up objects.
+ */
+void odb_add_submodule_source_by_path(struct object_database *odb,
+ const char *path);
+
/*
* Iterate through all alternates of the database and execute the provided
* callback function for each of them. Stop iterating once the callback
diff --git a/submodule-config.c b/submodule-config.c
index 9c80f9f7b66..a9f72107888 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -810,7 +810,8 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
- add_submodule_odb_by_path(repo->objects->sources->path);
+ odb_add_submodule_source_by_path(the_repository->objects,
+ repo->objects->sources->path);
} else {
goto out;
}
diff --git a/submodule.c b/submodule.c
index 386be234230..788c9e55ed3 100644
--- a/submodule.c
+++ b/submodule.c
@@ -31,7 +31,6 @@
#include "commit-reach.h"
#include "read-cache-ll.h"
#include "setup.h"
-#include "trace2.h"
static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
static int initialized_fetch_ref_tips;
@@ -176,31 +175,6 @@ void stage_updated_gitmodules(struct index_state *istate)
die(_("staging updated .gitmodules failed"));
}
-static struct string_list added_submodule_odb_paths = STRING_LIST_INIT_DUP;
-
-void add_submodule_odb_by_path(const char *path)
-{
- string_list_insert(&added_submodule_odb_paths, path);
-}
-
-int register_all_submodule_odb_as_alternates(void)
-{
- int i;
- int ret = added_submodule_odb_paths.nr;
-
- for (i = 0; i < added_submodule_odb_paths.nr; i++)
- odb_add_to_alternates_memory(the_repository->objects,
- added_submodule_odb_paths.items[i].string);
- if (ret) {
- string_list_clear(&added_submodule_odb_paths, 0);
- trace2_data_intmax("submodule", the_repository,
- "register_all_submodule_odb_as_alternates/registered", ret);
- if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0))
- BUG("register_all_submodule_odb_as_alternates() called");
- }
- return ret;
-}
-
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
const char *path)
{
diff --git a/submodule.h b/submodule.h
index db980c1d083..b10e16e6c06 100644
--- a/submodule.h
+++ b/submodule.h
@@ -104,15 +104,6 @@ int submodule_uses_gitfile(const char *path);
#define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
int bad_to_remove_submodule(const char *path, unsigned flags);
-/*
- * Call add_submodule_odb_by_path() to add the submodule at the given
- * path to a list. When register_all_submodule_odb_as_alternates() is
- * called, the object stores of all submodules in that list will be
- * added as alternates in the_repository.
- */
-void add_submodule_odb_by_path(const char *path);
-int register_all_submodule_odb_as_alternates(void);
-
/*
* Checks if there are submodule changes in a..b. If a is the null OID,
* checks b and all its ancestors instead.
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 12/17] odb: trivial refactorings to get rid of `the_repository`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (10 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 11/17] odb: get rid of `the_repository` when handling submodule sources Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
` (5 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
All of the external functions provided by the object database subsystem
don't depend on `the_repository` anymore, but some internal functions
still do. Refactor those cases by plumbing through the repository that
owns the object database.
This change allows us to get rid of the `USE_THE_REPOSITORY_VARIABLE`
preprocessor define.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
odb.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/odb.c b/odb.c
index f0b27bd936b..5a88701550e 100644
--- a/odb.c
+++ b/odb.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "abspath.h"
#include "commit-graph.h"
@@ -476,12 +474,13 @@ void odb_add_submodule_source_by_path(struct object_database *odb,
string_list_insert(&odb->submodule_source_paths, path);
}
-static void fill_alternate_refs_command(struct child_process *cmd,
+static void fill_alternate_refs_command(struct repository *repo,
+ struct child_process *cmd,
const char *repo_path)
{
const char *value;
- if (!git_config_get_value("core.alternateRefsCommand", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsCommand", &value)) {
cmd->use_shell = 1;
strvec_push(&cmd->args, value);
@@ -493,7 +492,7 @@ static void fill_alternate_refs_command(struct child_process *cmd,
strvec_push(&cmd->args, "for-each-ref");
strvec_push(&cmd->args, "--format=%(objectname)");
- if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
+ if (!repo_config_get_value(repo, "core.alternateRefsPrefixes", &value)) {
strvec_push(&cmd->args, "--");
strvec_split(&cmd->args, value);
}
@@ -503,7 +502,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
cmd->out = -1;
}
-static void read_alternate_refs(const char *path,
+static void read_alternate_refs(struct repository *repo,
+ const char *path,
odb_for_each_alternate_ref_fn *cb,
void *payload)
{
@@ -511,7 +511,7 @@ static void read_alternate_refs(const char *path,
struct strbuf line = STRBUF_INIT;
FILE *fh;
- fill_alternate_refs_command(&cmd, path);
+ fill_alternate_refs_command(repo, &cmd, path);
if (start_command(&cmd))
return;
@@ -521,7 +521,7 @@ static void read_alternate_refs(const char *path,
struct object_id oid;
const char *p;
- if (parse_oid_hex(line.buf, &oid, &p) || *p) {
+ if (parse_oid_hex_algop(line.buf, &oid, &p, repo->hash_algo) || *p) {
warning(_("invalid line while parsing alternate refs: %s"),
line.buf);
break;
@@ -559,7 +559,7 @@ static int refs_from_alternate_cb(struct odb_source *alternate,
goto out;
strbuf_setlen(&path, base_len);
- read_alternate_refs(path.buf, cb->fn, cb->payload);
+ read_alternate_refs(alternate->odb->repo, path.buf, cb->fn, cb->payload);
out:
strbuf_release(&path);
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, the_repository->hash_algo);
+ oidclr(oi->delta_base_oid, r->hash_algo);
if (oi->contentp)
*oi->contentp = xmemdupz(co->buf, co->size);
oi->whence = OI_CACHED;
@@ -763,10 +763,10 @@ static int oid_object_info_convert(struct repository *r,
void *content;
int ret;
- if (repo_oid_to_algop(r, input_oid, the_hash_algo, &oid)) {
+ if (repo_oid_to_algop(r, input_oid, r->hash_algo, &oid)) {
if (do_die)
die(_("missing mapping of %s to %s"),
- oid_to_hex(input_oid), the_hash_algo->name);
+ oid_to_hex(input_oid), r->hash_algo->name);
return -1;
}
@@ -797,8 +797,8 @@ static int oid_object_info_convert(struct repository *r,
struct strbuf outbuf = STRBUF_INIT;
if (type != OBJ_BLOB) {
- ret = convert_object_file(the_repository, &outbuf,
- the_hash_algo, input_algo,
+ ret = convert_object_file(r, &outbuf,
+ r->hash_algo, input_algo,
content, size, type, !do_die);
free(content);
if (ret == -1)
@@ -944,9 +944,9 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + the_hash_algo->hexsz > isize ||
+ if (ref_length + r->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
free(buffer);
return NULL;
}
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 13/17] odb: rename `oid_object_info()`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (11 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 12/17] odb: trivial refactorings to get rid of `the_repository` Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
` (4 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `oid_object_info()` to `odb_read_object_info()` as well as their
`_extended()` variant to match other functions related to the object
database and our modern coding guidelines.
Introduce compatibility wrappers so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
archive.c | 2 +-
blame.c | 4 +--
builtin/blame.c | 4 +--
builtin/cat-file.c | 26 ++++++++++---------
builtin/describe.c | 3 ++-
builtin/fast-export.c | 2 +-
builtin/fast-import.c | 17 ++++++------
builtin/fsck.c | 7 ++---
builtin/gc.c | 2 +-
builtin/grep.c | 2 +-
builtin/index-pack.c | 13 +++++-----
builtin/ls-files.c | 2 +-
builtin/ls-tree.c | 4 +--
builtin/mktree.c | 8 +++---
builtin/pack-objects.c | 30 ++++++++++++----------
builtin/prune.c | 4 +--
builtin/repack.c | 2 +-
builtin/replace.c | 10 ++++----
builtin/rev-list.c | 6 +++--
builtin/tag.c | 4 +--
builtin/unpack-objects.c | 2 +-
commit-graph.c | 2 +-
commit.c | 3 ++-
diff.c | 18 ++++++-------
fetch-pack.c | 4 +--
list-objects-filter.c | 2 +-
log-tree.c | 2 +-
merge-ort.c | 4 +--
object-file.c | 2 +-
object-file.h | 2 +-
object-name.c | 16 ++++++------
object.c | 6 ++---
odb.c | 60 ++++++++++++++++++++++---------------------
odb.h | 46 +++++++++++++++++++++++++++------
pack-bitmap-write.c | 4 +--
pack-bitmap.c | 8 +++---
packfile.c | 5 ++--
promisor-remote.c | 4 +--
protocol-caps.c | 2 +-
reachable.c | 2 +-
read-cache.c | 6 ++---
ref-filter.c | 4 +--
remote.c | 5 ++--
sequencer.c | 5 ++--
streaming.c | 8 +++---
submodule.c | 5 ++--
t/helper/test-partial-clone.c | 2 +-
tag.c | 2 +-
48 files changed, 213 insertions(+), 170 deletions(-)
diff --git a/archive.c b/archive.c
index 7fa2cc2596a..f2511d530d5 100644
--- a/archive.c
+++ b/archive.c
@@ -215,7 +215,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
/* Stream it? */
if (S_ISREG(mode) && !args->convert &&
- oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
+ odb_read_object_info(args->repo->objects, oid, &size) == OBJ_BLOB &&
size > repo_settings_get_big_file_threshold(the_repository))
return write_entry(args, oid, path.buf, path.len, mode, NULL, size);
diff --git a/blame.c b/blame.c
index 0ceea080a80..97db3355af4 100644
--- a/blame.c
+++ b/blame.c
@@ -116,7 +116,7 @@ static void verify_working_tree_path(struct repository *r,
unsigned short mode;
if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
- oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
+ odb_read_object_info(r->objects, &blob_oid, NULL) == OBJ_BLOB)
return;
}
@@ -1245,7 +1245,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
return 0;
if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
goto error_out;
- if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
+ if (odb_read_object_info(r->objects, &origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out;
return 0;
error_out:
diff --git a/builtin/blame.c b/builtin/blame.c
index 15eda60af90..91586e6852b 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -837,7 +837,7 @@ static int is_a_rev(const char *name)
if (repo_get_oid(the_repository, name, &oid))
return 0;
- return OBJ_NONE < oid_object_info(the_repository, &oid, NULL);
+ return OBJ_NONE < odb_read_object_info(the_repository->objects, &oid, NULL);
}
static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
@@ -848,7 +848,7 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
oidcpy(&oid, oid_ret);
while (1) {
struct object *obj;
- int kind = oid_object_info(r, &oid, NULL);
+ int kind = odb_read_object_info(r->objects, &oid, NULL);
if (kind == OBJ_COMMIT) {
oidcpy(oid_ret, &oid);
return 0;
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index f3a925a8183..f7595fdb04e 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -132,7 +132,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
switch (opt) {
case 't':
oi.typep = &type;
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
printf("%s\n", type_name(type));
ret = 0;
@@ -146,7 +146,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
oi.contentp = (void**)&buf;
}
- if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
@@ -180,7 +180,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
/* else fallthrough */
case 'p':
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("Not a valid object name %s", obj_name);
@@ -217,7 +217,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
if (exp_type_id == OBJ_BLOB) {
struct object_id blob_oid;
- if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
+ if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_TAG) {
char *buffer = repo_read_object_file(the_repository,
&oid,
&type,
@@ -235,7 +236,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
} else
oidcpy(&blob_oid, &oid);
- if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB) {
+ if (odb_read_object_info(the_repository->objects,
+ &blob_oid, NULL) == OBJ_BLOB) {
ret = stream_blob(&blob_oid);
goto cleanup;
}
@@ -294,7 +296,7 @@ struct expand_data {
/*
* After a mark_query run, this object_info is set up to be
- * passed to oid_object_info_extended. It will point to the data
+ * passed to odb_read_object_info_extended. It will point to the data
* elements above, so you can retrieve the response from there.
*/
struct object_info info;
@@ -484,12 +486,12 @@ static void batch_object_write(const char *obj_name,
data->info.sizep = &data->size;
if (pack)
- ret = packed_object_info(the_repository, pack, offset,
- &data->info);
+ ret = packed_object_info(the_repository, pack,
+ offset, &data->info);
else
- ret = oid_object_info_extended(the_repository,
- &data->oid, &data->info,
- OBJECT_INFO_LOOKUP_REPLACE);
+ ret = odb_read_object_info_extended(the_repository->objects,
+ &data->oid, &data->info,
+ OBJECT_INFO_LOOKUP_REPLACE);
if (ret < 0) {
report_object_status(opt, obj_name, &data->oid, "missing");
return;
@@ -872,7 +874,7 @@ static int batch_objects(struct batch_options *opt)
/*
* Expand once with our special mark_query flag, which will prime the
- * object_info to be handed to oid_object_info_extended for each
+ * object_info to be handed to odb_read_object_info_extended for each
* object.
*/
memset(&data, 0, sizeof(data));
diff --git a/builtin/describe.c b/builtin/describe.c
index 96cb68e5e5d..fbf305d7624 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -552,7 +552,8 @@ static void describe(const char *arg, int last_one)
if (cmit)
describe_commit(&oid, &sb);
- else if (oid_object_info(the_repository, &oid, NULL) == OBJ_BLOB)
+ else if (odb_read_object_info(the_repository->objects,
+ &oid, NULL) == OBJ_BLOB)
describe_blob(oid, &sb);
else
die(_("%s is neither a commit nor blob"), arg);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 0505f289a94..6c93cf0a8aa 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -1200,7 +1200,7 @@ static void import_marks(char *input_file, int check_exists)
if (last_idnum < mark)
last_idnum = mark;
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(&oid));
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 413304db9b5..2718376f2c9 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1756,8 +1756,8 @@ static void insert_object_entry(struct mark_set **s, struct object_id *oid, uint
struct object_entry *e;
e = find_object(oid);
if (!e) {
- enum object_type type = oid_object_info(the_repository,
- oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
e = insert_object(oid);
@@ -2416,8 +2416,8 @@ static void file_change_m(const char *p, struct branch *b)
enum object_type expected = S_ISDIR(mode) ?
OBJ_TREE: OBJ_BLOB;
enum object_type type = oe ? oe->type :
- oid_object_info(the_repository, &oid,
- NULL);
+ odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("%s not found: %s",
S_ISDIR(mode) ? "Tree" : "Blob",
@@ -2553,7 +2553,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
die("Not a blob (actually a %s): %s",
type_name(oe->type), command_buf.buf);
} else if (!is_null_oid(&oid)) {
- enum object_type type = oid_object_info(the_repository, &oid,
+ enum object_type type = odb_read_object_info(the_repository->objects, &oid,
NULL);
if (type < 0)
die("Blob not found: %s", command_buf.buf);
@@ -2895,7 +2895,8 @@ static void parse_new_tag(const char *arg)
} else if (!repo_get_oid(the_repository, from, &oid)) {
struct object_entry *oe = find_object(&oid);
if (!oe) {
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ &oid, NULL);
if (type < 0)
die("Not a valid object: %s", from);
} else
@@ -3085,8 +3086,8 @@ static struct object_entry *dereference(struct object_entry *oe,
const unsigned hexsz = the_hash_algo->hexsz;
if (!oe) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(oid));
/* cache it! */
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 014aa1344e2..6e3465b0266 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -71,7 +71,8 @@ static const char *printable_type(const struct object_id *oid,
const char *ret;
if (type == OBJ_NONE)
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
ret = type_name(type);
if (!ret)
@@ -232,8 +233,8 @@ static void mark_unreachable_referents(const struct object_id *oid)
* (and we want to avoid parsing blobs).
*/
if (obj->type == OBJ_NONE) {
- enum object_type type = oid_object_info(the_repository,
- &obj->oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ &obj->oid, NULL);
if (type > 0)
object_as_type(obj, type, 0);
}
diff --git a/builtin/gc.c b/builtin/gc.c
index 50a09eb07e3..ff551fab439 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1080,7 +1080,7 @@ static int dfs_on_ref(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
commit = lookup_commit(the_repository, oid);
diff --git a/builtin/grep.c b/builtin/grep.c
index cfcf916bce1..1435d462cd1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -520,7 +520,7 @@ static int grep_submodule(struct grep_opt *opt,
struct strbuf base = STRBUF_INIT;
obj_read_lock();
- object_type = oid_object_info(subrepo, oid, NULL);
+ object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
data = read_object_with_reference(subrepo,
oid, OBJ_TREE,
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 4d4d989eb1a..d0b16908122 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -260,7 +260,8 @@ static unsigned check_object(struct object *obj)
if (!(obj->flags & FLAG_CHECKED)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects,
+ &obj->oid, &size);
if (type <= 0)
die(_("did not receive expected object %s"),
oid_to_hex(&obj->oid));
@@ -908,7 +909,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
enum object_type has_type;
unsigned long has_size;
read_lock();
- has_type = oid_object_info(the_repository, oid, &has_size);
+ has_type = odb_read_object_info(the_repository->objects, oid, &has_size);
if (has_type < 0)
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
@@ -1501,9 +1502,9 @@ static void fix_unresolved_deltas(struct hashfile *f)
struct oid_array to_fetch = OID_ARRAY_INIT;
for (i = 0; i < nr_ref_deltas; i++) {
struct ref_delta_entry *d = sorted_by_pos[i];
- if (!oid_object_info_extended(the_repository, &d->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &d->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &d->oid);
}
@@ -1829,7 +1830,7 @@ static void repack_local_links(void)
oidset_iter_init(&outgoing_links, &iter);
while ((oid = oidset_iter_next(&iter))) {
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info, 0))
/* Missing; assume it is a promisor object */
continue;
if (info.whence == OI_PACKED && info.u.packed.pack->pack_promisor)
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 821339b07d4..ff975e7be06 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -251,7 +251,7 @@ static void expand_objectsize(struct repository *repo, struct strbuf *line,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(repo, oid, &size) < 0)
+ if (odb_read_object_info(repo->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 62b6fd58c16..4d616dd5282 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -27,7 +27,7 @@ static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
{
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects, oid, &size) < 0)
die(_("could not get object info about '%s'"),
oid_to_hex(oid));
if (padded)
@@ -217,7 +217,7 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base,
if (type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
+ if (odb_read_object_info(the_repository->objects, oid, &size) == OBJ_BAD)
xsnprintf(size_text, sizeof(size_text), "BAD");
else
xsnprintf(size_text, sizeof(size_text),
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 016b0e5b224..81df7f6099f 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -124,10 +124,10 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing)
/* Check the type of object identified by oid without fetching objects */
oi.typep = &obj_type;
- if (oid_object_info_extended(the_repository, &oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_QUICK |
- OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_QUICK |
+ OBJECT_INFO_SKIP_FETCH_OBJECT) < 0)
obj_type = -1;
if (obj_type < 0) {
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 99b63cb0980..da35d684081 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2154,10 +2154,10 @@ static void prefetch_to_pack(uint32_t object_index_start) {
for (i = object_index_start; i < to_pack.nr_objects; i++) {
struct object_entry *entry = to_pack.objects + i;
- if (!oid_object_info_extended(the_repository,
- &entry->idx.oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &entry->idx.oid,
+ NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &entry->idx.oid);
}
@@ -2298,19 +2298,19 @@ static void check_object(struct object_entry *entry, uint32_t object_index)
/*
* No choice but to fall back to the recursive delta walk
- * with oid_object_info() to find about the object type
+ * with odb_read_object_info() to find about the object type
* at this point...
*/
give_up:
unuse_pack(&w_curs);
}
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) {
if (repo_has_promisor_remote(the_repository)) {
prefetch_to_pack(object_index);
- if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0)
type = -1;
} else {
type = -1;
@@ -2384,12 +2384,13 @@ static void drop_reused_delta(struct object_entry *entry)
if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
/*
* We failed to get the info from this pack for some reason;
- * fall back to oid_object_info, which may find another copy.
+ * fall back to odb_read_object_info, which may find another copy.
* And if that fails, the error will be recorded in oe_type(entry)
* and dealt with in prepare_pack().
*/
oe_set_type(entry,
- oid_object_info(the_repository, &entry->idx.oid, &size));
+ odb_read_object_info(the_repository->objects,
+ &entry->idx.oid, &size));
} else {
oe_set_type(entry, type);
}
@@ -2677,7 +2678,8 @@ unsigned long oe_get_size_slow(struct packing_data *pack,
if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
packing_data_lock(&to_pack);
- if (oid_object_info(the_repository, &e->idx.oid, &size) < 0)
+ if (odb_read_object_info(the_repository->objects,
+ &e->idx.oid, &size) < 0)
die(_("unable to get size of %s"),
oid_to_hex(&e->idx.oid));
packing_data_unlock(&to_pack);
@@ -4063,7 +4065,7 @@ static void add_objects_in_unpacked_packs(void)
static int add_loose_object(const struct object_id *oid, const char *path,
void *data UNUSED)
{
- enum object_type type = oid_object_info(the_repository, oid, NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0) {
warning(_("loose object at %s could not be examined"), path);
@@ -4449,7 +4451,7 @@ static int option_parse_cruft_expiration(const struct option *opt UNUSED,
static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED)
{
struct object_info info = OBJECT_INFO_INIT;
- if (oid_object_info_extended(the_repository, &obj->oid, &info, 0))
+ if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0))
BUG("should_include_obj should only be called on existing objects");
return info.whence != OI_PACKED || !info.u.packed.pack->pack_promisor;
}
diff --git a/builtin/prune.c b/builtin/prune.c
index 7bbfb14c2be..339017c7ccf 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -99,8 +99,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
if (st.st_mtime > expire)
return 0;
if (show_only || verbose) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = odb_read_object_info(the_repository->objects,
+ oid, NULL);
printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? type_name(type) : "unknown");
}
diff --git a/builtin/repack.c b/builtin/repack.c
index 8145474cf8d..a89c2b704fb 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -707,7 +707,7 @@ static int midx_snapshot_ref_one(const char *refname UNUSED,
if (oidset_insert(&data->seen, oid))
return 0; /* already seen */
- if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
fprintf(data->f->fp, "%s%s\n", data->preferred ? "+" : "",
diff --git a/builtin/replace.c b/builtin/replace.c
index 11c7e2d4c0c..5ff2ab723cb 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -65,8 +65,8 @@ static int show_reference(const char *refname,
if (repo_get_oid(data->repo, refname, &object))
return error(_("failed to resolve '%s' as a valid ref"), refname);
- obj_type = oid_object_info(data->repo, &object, NULL);
- repl_type = oid_object_info(data->repo, oid, NULL);
+ obj_type = odb_read_object_info(data->repo->objects, &object, NULL);
+ repl_type = odb_read_object_info(data->repo->objects, oid, NULL);
printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
oid_to_hex(oid), type_name(repl_type));
@@ -185,8 +185,8 @@ static int replace_object_oid(const char *object_ref,
struct strbuf err = STRBUF_INIT;
int res = 0;
- obj_type = oid_object_info(the_repository, object, NULL);
- repl_type = oid_object_info(the_repository, repl, NULL);
+ obj_type = odb_read_object_info(the_repository->objects, object, NULL);
+ repl_type = odb_read_object_info(the_repository->objects, repl, NULL);
if (!force && obj_type != repl_type)
return error(_("Objects must be of the same type.\n"
"'%s' points to a replaced object of type '%s'\n"
@@ -334,7 +334,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
if (repo_get_oid(the_repository, object_ref, &old_oid) < 0)
return error(_("not a valid object name: '%s'"), object_ref);
- type = oid_object_info(the_repository, &old_oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &old_oid, NULL);
if (type < 0)
return error(_("unable to get object type for %s"),
oid_to_hex(&old_oid));
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 0ee37a32cb2..4d0c460f186 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -110,7 +110,8 @@ static off_t get_object_disk_usage(struct object *obj)
off_t size;
struct object_info oi = OBJECT_INFO_INIT;
oi.disk_sizep = &size;
- if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid));
return size;
}
@@ -346,7 +347,8 @@ static void show_commit(struct commit *commit, void *data)
static int finish_object(struct object *obj, const char *name, void *cb_data)
{
struct rev_list_info *info = cb_data;
- if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) {
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, NULL, 0) < 0) {
finish_object__ma(obj, name);
return 1;
}
diff --git a/builtin/tag.c b/builtin/tag.c
index cf2ea4b4993..e0b27396c6b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -304,7 +304,7 @@ static void create_tag(const struct object_id *object, const char *object_ref,
struct strbuf header = STRBUF_INIT;
int should_edit;
- type = oid_object_info(the_repository, object, NULL);
+ type = odb_read_object_info(the_repository->objects, object, NULL);
if (type <= OBJ_NONE)
die(_("bad object type."));
@@ -401,7 +401,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
}
strbuf_addstr(sb, " (");
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
switch (type) {
default:
strbuf_addstr(sb, "object of unknown type");
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 7bf395eec84..405e78bc592 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -232,7 +232,7 @@ static int check_object(struct object *obj, enum object_type type,
if (!(obj->flags & FLAG_OPEN)) {
unsigned long size;
- int type = oid_object_info(the_repository, &obj->oid, &size);
+ int type = odb_read_object_info(the_repository->objects, &obj->oid, &size);
if (type != obj->type || type <= 0)
die("object of unexpected type");
obj->flags |= FLAG_WRITTEN;
diff --git a/commit-graph.c b/commit-graph.c
index 59265f89385..5f482d3377f 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1862,7 +1862,7 @@ static int add_ref_to_set(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) == OBJ_COMMIT)
oidset_insert(data->commits, oid);
display_progress(data->progress, oidset_size(data->commits));
diff --git a/commit.c b/commit.c
index aa65183d8b6..d4aa9c7a5f8 100644
--- a/commit.c
+++ b/commit.c
@@ -585,7 +585,8 @@ int repo_parse_commit_internal(struct repository *r,
return 0;
}
- if (oid_object_info_extended(r, &item->object.oid, &oi, flags) < 0)
+ if (odb_read_object_info_extended(r->objects, &item->object.oid,
+ &oi, flags) < 0)
return quiet_on_missing ? -1 :
error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/diff.c b/diff.c
index 3af108115b3..dca87e164fb 100644
--- a/diff.c
+++ b/diff.c
@@ -4230,14 +4230,14 @@ int diff_populate_filespec(struct repository *r,
info.contentp = &s->data;
if (options && options->missing_object_cb) {
- if (!oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE |
- OBJECT_INFO_SKIP_FETCH_OBJECT))
+ if (!odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE |
+ OBJECT_INFO_SKIP_FETCH_OBJECT))
goto object_read;
options->missing_object_cb(options->missing_object_data);
}
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
object_read:
@@ -4252,8 +4252,8 @@ int diff_populate_filespec(struct repository *r,
}
if (!info.contentp) {
info.contentp = &s->data;
- if (oid_object_info_extended(r, &s->oid, &info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(r->objects, &s->oid, &info,
+ OBJECT_INFO_LOOKUP_REPLACE))
die("unable to read %s", oid_to_hex(&s->oid));
}
s->should_free = 1;
@@ -7019,8 +7019,8 @@ void diff_add_if_missing(struct repository *r,
{
if (filespec && filespec->oid_valid &&
!S_ISGITLINK(filespec->mode) &&
- oid_object_info_extended(r, &filespec->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(r->objects, &filespec->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(to_fetch, &filespec->oid);
}
diff --git a/fetch-pack.c b/fetch-pack.c
index 47fa7fa4c49..0f5de1c94d1 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -149,8 +149,8 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
}
while (1) {
- if (oid_object_info_extended(the_repository, oid, &info,
- OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &info,
+ OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK))
return NULL;
if (type == OBJ_TAG) {
struct tag *tag = (struct tag *)
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 80fe48a52c8..7ecd4d9ef50 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -310,7 +310,7 @@ static enum list_objects_filter_result filter_blobs_limit(
assert(obj->type == OBJ_BLOB);
assert((obj->flags & SEEN) == 0);
- t = oid_object_info(r, &obj->oid, &object_length);
+ t = odb_read_object_info(r->objects, &obj->oid, &object_length);
if (t != OBJ_BLOB) { /* probably OBJ_NONE */
/*
* We DO NOT have the blob locally, so we cannot
diff --git a/log-tree.c b/log-tree.c
index 1d05dc1c701..233bf9f227c 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -176,7 +176,7 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
return 0;
}
- objtype = oid_object_info(the_repository, oid, NULL);
+ objtype = odb_read_object_info(the_repository->objects, oid, NULL);
if (objtype < 0)
return 0;
obj = lookup_object_by_type(the_repository, oid, objtype);
diff --git a/merge-ort.c b/merge-ort.c
index 9f693ab1d36..f29417040c1 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -4385,8 +4385,8 @@ static void prefetch_for_content_merges(struct merge_options *opt,
if ((ci->filemask & side_mask) &&
S_ISREG(vi->mode) &&
- oid_object_info_extended(opt->repo, &vi->oid, NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ odb_read_object_info_extended(opt->repo->objects, &vi->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&to_fetch, &vi->oid);
}
}
diff --git a/object-file.c b/object-file.c
index 04da19a1a3b..3d674d1093e 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1108,7 +1108,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
oi.typep = &type;
oi.sizep = &len;
oi.contentp = &buf;
- if (oid_object_info_extended(the_repository, oid, &oi, 0))
+ if (odb_read_object_info_extended(the_repository->objects, oid, &oi, 0))
return error(_("cannot read object for %s"), oid_to_hex(oid));
if (compat) {
if (repo_oid_to_algop(repo, oid, compat, &compat_oid))
diff --git a/object-file.h b/object-file.h
index 5066638f8ec..67b4ffc4808 100644
--- a/object-file.h
+++ b/object-file.h
@@ -8,7 +8,7 @@
struct index_state;
/*
- * Set this to 0 to prevent oid_object_info_extended() from fetching missing
+ * Set this to 0 to prevent odb_read_object_info_extended() from fetching missing
* blobs. This has a difference only if extensions.partialClone is set.
*
* Its default value is 1.
diff --git a/object-name.c b/object-name.c
index 381536e900e..e225eb602cf 100644
--- a/object-name.c
+++ b/object-name.c
@@ -251,7 +251,7 @@ static int disambiguate_commit_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_COMMIT;
}
@@ -262,7 +262,7 @@ static int disambiguate_committish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -279,7 +279,7 @@ static int disambiguate_tree_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_TREE;
}
@@ -290,7 +290,7 @@ static int disambiguate_treeish_only(struct repository *r,
struct object *obj;
int kind;
- kind = oid_object_info(r, oid, NULL);
+ kind = odb_read_object_info(r->objects, oid, NULL);
if (kind == OBJ_TREE || kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
@@ -307,7 +307,7 @@ static int disambiguate_blob_only(struct repository *r,
const struct object_id *oid,
void *cb_data UNUSED)
{
- int kind = oid_object_info(r, oid, NULL);
+ int kind = odb_read_object_info(r->objects, oid, NULL);
return kind == OBJ_BLOB;
}
@@ -399,7 +399,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
return 0;
hash = repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV);
- type = oid_object_info(ds->repo, oid, NULL);
+ type = odb_read_object_info(ds->repo->objects, oid, NULL);
if (type < 0) {
/*
@@ -514,8 +514,8 @@ static int sort_ambiguous(const void *va, const void *vb, void *ctx)
{
struct repository *sort_ambiguous_repo = ctx;
const struct object_id *a = va, *b = vb;
- int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
- int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
+ int a_type = odb_read_object_info(sort_ambiguous_repo->objects, a, NULL);
+ int b_type = odb_read_object_info(sort_ambiguous_repo->objects, b, NULL);
int a_type_sort;
int b_type_sort;
diff --git a/object.c b/object.c
index 3b15469139d..868d89eed42 100644
--- a/object.c
+++ b/object.c
@@ -214,7 +214,7 @@ enum peel_status peel_object(struct repository *r,
struct object *o = lookup_unknown_object(r, name);
if (o->type == OBJ_NONE) {
- int type = oid_object_info(r, name, NULL);
+ int type = odb_read_object_info(r->objects, name, NULL);
if (type < 0 || !object_as_type(o, type, 0))
return PEEL_INVALID;
}
@@ -315,7 +315,7 @@ struct object *parse_object_with_flags(struct repository *r,
}
if ((!obj || obj->type == OBJ_BLOB) &&
- oid_object_info(r, oid, NULL) == OBJ_BLOB) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
if (!skip_hash && stream_object_signature(r, repl) < 0) {
error(_("hash mismatch %s"), oid_to_hex(oid));
return NULL;
@@ -331,7 +331,7 @@ struct object *parse_object_with_flags(struct repository *r,
*/
if (skip_hash && discard_tree &&
(!obj || obj->type == OBJ_TREE) &&
- oid_object_info(r, oid, NULL) == OBJ_TREE) {
+ odb_read_object_info(r->objects, oid, NULL) == OBJ_TREE) {
return &lookup_tree(r, oid)->object;
}
diff --git a/odb.c b/odb.c
index 5a88701550e..40eacdfe2da 100644
--- a/odb.c
+++ b/odb.c
@@ -647,7 +647,7 @@ static int register_all_submodule_sources(struct object_database *odb)
return ret;
}
-static int do_oid_object_info_extended(struct repository *r,
+static int do_oid_object_info_extended(struct object_database *odb,
const struct object_id *oid,
struct object_info *oi, unsigned flags)
{
@@ -660,7 +660,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (flags & OBJECT_INFO_LOOKUP_REPLACE)
- real = lookup_replace_object(r, oid);
+ real = lookup_replace_object(odb->repo, oid);
if (is_null_oid(real))
return -1;
@@ -668,7 +668,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (!oi)
oi = &blank_oi;
- co = find_cached_object(r->objects, real);
+ co = find_cached_object(odb, real);
if (co) {
if (oi->typep)
*(oi->typep) = co->type;
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
if (oi->disk_sizep)
*(oi->disk_sizep) = 0;
if (oi->delta_base_oid)
- oidclr(oi->delta_base_oid, r->hash_algo);
+ oidclr(oi->delta_base_oid, odb->repo->hash_algo);
if (oi->contentp)
*oi->contentp = xmemdupz(co->buf, co->size);
oi->whence = OI_CACHED;
@@ -685,17 +685,17 @@ static int do_oid_object_info_extended(struct repository *r,
}
while (1) {
- if (find_pack_entry(r, real, &e))
+ if (find_pack_entry(odb->repo, real, &e))
break;
/* Most likely it's a loose object. */
- if (!loose_object_info(r, real, oi, flags))
+ if (!loose_object_info(odb->repo, real, oi, flags))
return 0;
/* Not a loose object; someone else may have just packed it. */
if (!(flags & OBJECT_INFO_QUICK)) {
- reprepare_packed_git(r);
- if (find_pack_entry(r, real, &e))
+ reprepare_packed_git(odb->repo);
+ if (find_pack_entry(odb->repo, real, &e))
break;
}
@@ -705,15 +705,15 @@ static int do_oid_object_info_extended(struct repository *r,
* `odb_add_submodule_source_by_path()` on that submodule's
* ODB). If any such ODBs exist, register them and try again.
*/
- if (register_all_submodule_sources(r->objects))
+ if (register_all_submodule_sources(odb))
/* We added some alternates; retry */
continue;
/* Check if it is a missing object */
- if (fetch_if_missing && repo_has_promisor_remote(r) &&
+ if (fetch_if_missing && repo_has_promisor_remote(odb->repo) &&
!already_retried &&
!(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) {
- promisor_remote_get_direct(r, real, 1);
+ promisor_remote_get_direct(odb->repo, real, 1);
already_retried = 1;
continue;
}
@@ -723,7 +723,7 @@ static int do_oid_object_info_extended(struct repository *r,
if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid))
die(_("replacement %s not found for %s"),
oid_to_hex(real), oid_to_hex(oid));
- if ((p = has_packed_and_bad(r, real)))
+ if ((p = has_packed_and_bad(odb->repo, real)))
die(_("packed object %s (stored in %s) is corrupt"),
oid_to_hex(real), p->pack_name);
}
@@ -736,10 +736,10 @@ static int do_oid_object_info_extended(struct repository *r,
* information below, so return early.
*/
return 0;
- rtype = packed_object_info(r, e.p, e.offset, oi);
+ rtype = packed_object_info(odb->repo, e.p, e.offset, oi);
if (rtype < 0) {
mark_bad_packed_object(e.p, real);
- return do_oid_object_info_extended(r, real, oi, 0);
+ return do_oid_object_info_extended(odb, real, oi, 0);
} else if (oi->whence == OI_PACKED) {
oi->u.packed.offset = e.offset;
oi->u.packed.pack = e.p;
@@ -787,7 +787,7 @@ static int oid_object_info_convert(struct repository *r,
oi = &new_oi;
}
- ret = oid_object_info_extended(r, &oid, oi, flags);
+ ret = odb_read_object_info_extended(r->objects, &oid, oi, flags);
if (ret)
return -1;
if (oi == input_oi)
@@ -830,33 +830,35 @@ static int oid_object_info_convert(struct repository *r,
return ret;
}
-int oid_object_info_extended(struct repository *r, const struct object_id *oid,
- struct object_info *oi, unsigned flags)
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
{
int ret;
- if (oid->algo && (hash_algo_by_ptr(r->hash_algo) != oid->algo))
- return oid_object_info_convert(r, oid, oi, flags);
+ if (oid->algo && (hash_algo_by_ptr(odb->repo->hash_algo) != oid->algo))
+ return oid_object_info_convert(odb->repo, oid, oi, flags);
obj_read_lock();
- ret = do_oid_object_info_extended(r, oid, oi, flags);
+ ret = do_oid_object_info_extended(odb, oid, oi, flags);
obj_read_unlock();
return ret;
}
/* returns enum object_type or negative */
-int oid_object_info(struct repository *r,
- const struct object_id *oid,
- unsigned long *sizep)
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep)
{
enum object_type type;
struct object_info oi = OBJECT_INFO_INIT;
oi.typep = &type;
oi.sizep = sizep;
- if (oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_LOOKUP_REPLACE) < 0)
+ if (odb_read_object_info_extended(odb, oid, &oi,
+ OBJECT_INFO_LOOKUP_REPLACE) < 0)
return -1;
return type;
}
@@ -887,7 +889,7 @@ int pretend_object_file(struct repository *repo,
/*
* This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call oid_object_info_extended() and give
+ * deal with them should arrange to call odb_read_object_info_extended() and give
* error messages themselves.
*/
void *repo_read_object_file(struct repository *r,
@@ -902,7 +904,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (oid_object_info_extended(r, oid, &oi, flags))
+ if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
return NULL;
return data;
@@ -968,13 +970,13 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect)
{
- enum object_type type = oid_object_info(odb->repo, oid, NULL);
+ enum object_type type = odb_read_object_info(odb, oid, NULL);
if (type < 0)
die(_("%s is not a valid object"), oid_to_hex(oid));
if (type != expect)
diff --git a/odb.h b/odb.h
index 0ea9d4faa70..b37a9c5d20f 100644
--- a/odb.h
+++ b/odb.h
@@ -265,9 +265,6 @@ void *repo_read_object_file(struct repository *r,
enum object_type *type,
unsigned long *size);
-/* Read and unpack an object file into memory, write memory to an object file */
-int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
-
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -336,9 +333,24 @@ struct object_info {
/* Die if object corruption (not just an object being missing) was detected. */
#define OBJECT_INFO_DIE_IF_CORRUPT 32
-int oid_object_info_extended(struct repository *r,
- const struct object_id *,
- struct object_info *, unsigned flags);
+/*
+ * Read object info from the object database and populate the `object_info`
+ * structure. Returns 0 on success, a negative error code otherwise.
+ */
+int odb_read_object_info_extended(struct object_database *odb,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags);
+
+/*
+ * Read a subset of object info for the given object ID. Returns an `enum
+ * object_type` on success, a negative error code otherwise. If successful and
+ * `sizep` is non-NULL, then the size of the object will be written to the
+ * pointer.
+ */
+int odb_read_object_info(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned long *sizep);
enum {
/* Retry packed storage after checking packed and loose storage */
@@ -360,7 +372,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: repo_read_object_file(),
- * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
+ * read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -368,7 +380,7 @@ void odb_assert_oid_type(struct object_database *odb,
* reading functions. However, beware that in these cases zlib inflation won't
* be performed in parallel, losing performance.
*
- * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
+ * TODO: odb_read_object_info_extended()'s call stack has a recursive behavior. If
* any of its callees end up calling it, this recursive call won't benefit from
* parallel inflation.
*/
@@ -416,4 +428,22 @@ void *read_object_with_reference(struct repository *r,
unsigned long *size,
struct object_id *oid_ret);
+/* Compatibility wrappers, to be removed once Git 2.51 has been released. */
+#include "repository.h"
+
+static inline int oid_object_info_extended(struct repository *r,
+ const struct object_id *oid,
+ struct object_info *oi,
+ unsigned flags)
+{
+ return odb_read_object_info_extended(r->objects, oid, oi, flags);
+}
+
+static inline int oid_object_info(struct repository *r,
+ const struct object_id *oid,
+ unsigned long *sizep)
+{
+ return odb_read_object_info(r->objects, oid, sizep);
+}
+
#endif /* ODB_H */
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index c847369eaaa..c5183b619c1 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -144,8 +144,8 @@ void bitmap_writer_build_type_index(struct bitmap_writer *writer,
break;
default:
- real_type = oid_object_info(writer->to_pack->repo,
- &entry->idx.oid, NULL);
+ real_type = odb_read_object_info(writer->to_pack->repo->objects,
+ &entry->idx.oid, NULL);
break;
}
diff --git a/pack-bitmap.c b/pack-bitmap.c
index a695a794e9b..bcbb71f7502 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1868,8 +1868,8 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
size_t eindex_pos = pos - bitmap_num_objects_total(bitmap_git);
struct eindex *eindex = &bitmap_git->ext_index;
struct object *obj = eindex->objects[eindex_pos];
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects, &obj->oid,
+ &oi, 0) < 0)
die(_("unable to get size of %s"), oid_to_hex(&obj->oid));
}
@@ -3220,8 +3220,8 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)
i)))
continue;
- if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,
- &oi, 0) < 0)
+ if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of '%s'"),
oid_to_hex(&obj->oid));
diff --git a/packfile.c b/packfile.c
index ac0e29e99b9..af9ccfdba62 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1321,7 +1321,7 @@ static int retry_bad_packed_offset(struct repository *r,
return OBJ_BAD;
nth_packed_object_id(&oid, p, pack_pos_to_index(p, pos));
mark_bad_packed_object(p, &oid);
- type = oid_object_info(r, &oid, NULL);
+ type = odb_read_object_info(r->objects, &oid, NULL);
if (type <= OBJ_NONE)
return OBJ_BAD;
return type;
@@ -1849,7 +1849,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
oi.typep = &type;
oi.sizep = &base_size;
oi.contentp = &base;
- if (oid_object_info_extended(r, &base_oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(r->objects, &base_oid,
+ &oi, 0) < 0)
base = NULL;
external_base = base;
diff --git a/promisor-remote.c b/promisor-remote.c
index 2baa286bfd0..be6f82d12f8 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -245,8 +245,8 @@ static int remove_fetched_oids(struct repository *repo,
struct object_id *new_oids;
for (i = 0; i < oid_nr; i++)
- if (oid_object_info_extended(repo, &old_oids[i], NULL,
- OBJECT_INFO_SKIP_FETCH_OBJECT)) {
+ if (odb_read_object_info_extended(repo->objects, &old_oids[i], NULL,
+ OBJECT_INFO_SKIP_FETCH_OBJECT)) {
remaining[i] = 1;
remaining_nr++;
}
diff --git a/protocol-caps.c b/protocol-caps.c
index 3022f69a1bd..ecdd0dc58d5 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -64,7 +64,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
strbuf_addstr(&send_buffer, oid_str);
if (info->size) {
- if (oid_object_info(r, &oid, &object_size) < 0) {
+ if (odb_read_object_info(r->objects, &oid, &object_size) < 0) {
strbuf_addstr(&send_buffer, " ");
} else {
strbuf_addf(&send_buffer, " %lu", object_size);
diff --git a/reachable.c b/reachable.c
index 9dc748f0b9a..e984b68a0c4 100644
--- a/reachable.c
+++ b/reachable.c
@@ -211,7 +211,7 @@ static void add_recent_object(const struct object_id *oid,
* later processing, and the revision machinery expects
* commits and tags to have been parsed.
*/
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type < 0)
die("unable to get object info for %s", oid_to_hex(oid));
diff --git a/read-cache.c b/read-cache.c
index c3fa9686766..7d5bccf95dc 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3729,9 +3729,9 @@ void prefetch_cache_entries(const struct index_state *istate,
if (S_ISGITLINK(ce->ce_mode) || !must_prefetch(ce))
continue;
- if (!oid_object_info_extended(the_repository, &ce->oid,
- NULL,
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_read_object_info_extended(the_repository->objects,
+ &ce->oid, NULL,
+ OBJECT_INFO_FOR_PREFETCH))
continue;
oid_array_append(&to_fetch, &ce->oid);
}
diff --git a/ref-filter.c b/ref-filter.c
index 4ce45440ad1..f9f2c512a8c 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2302,8 +2302,8 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
oi->info.sizep = &oi->size;
oi->info.typep = &oi->type;
}
- if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
- OBJECT_INFO_LOOKUP_REPLACE))
+ if (odb_read_object_info_extended(the_repository->objects, &oi->oid, &oi->info,
+ OBJECT_INFO_LOOKUP_REPLACE))
return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
oid_to_hex(&oi->oid), ref->refname);
if (oi->info.disk_sizep && oi->disk_size < 0)
diff --git a/remote.c b/remote.c
index 17a842f5684..72c36239d31 100644
--- a/remote.c
+++ b/remote.c
@@ -1182,7 +1182,7 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
BUG("'%s' is not a valid object, "
"match_explicit_lhs() should catch this!",
matched_src_name);
- type = oid_object_info(the_repository, &oid, NULL);
+ type = odb_read_object_info(the_repository->objects, &oid, NULL);
if (type == OBJ_COMMIT) {
advise(_("The <src> part of the refspec is a commit object.\n"
"Did you mean to create a new branch by pushing to\n"
@@ -1412,7 +1412,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
continue; /* not a tag */
if (string_list_has_string(&dst_tag, ref->name))
continue; /* they already have it */
- if (oid_object_info(the_repository, &ref->new_oid, NULL) != OBJ_TAG)
+ if (odb_read_object_info(the_repository->objects,
+ &ref->new_oid, NULL) != OBJ_TAG)
continue; /* be conservative */
item = string_list_append(&src_tag, ref->name);
item->util = ref;
diff --git a/sequencer.c b/sequencer.c
index 2432d0a39ec..193459405f8 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -5503,9 +5503,8 @@ int sequencer_pick_revisions(struct repository *r,
if (!repo_get_oid(r, name, &oid)) {
if (!lookup_commit_reference_gently(r, &oid, 1)) {
- enum object_type type = oid_object_info(r,
- &oid,
- NULL);
+ enum object_type type = odb_read_object_info(r->objects,
+ &oid, NULL);
res = error(_("%s: can't cherry-pick a %s"),
name, type_name(type));
goto out;
diff --git a/streaming.c b/streaming.c
index 81c42673a23..4b13827668e 100644
--- a/streaming.c
+++ b/streaming.c
@@ -44,7 +44,7 @@ struct git_istream {
union {
struct {
- char *buf; /* from oid_object_info_extended() */
+ char *buf; /* from odb_read_object_info_extended() */
unsigned long read_ptr;
} incore;
@@ -403,8 +403,8 @@ static int open_istream_incore(struct git_istream *st, struct repository *r,
oi.typep = type;
oi.sizep = &st->size;
oi.contentp = (void **)&st->u.incore.buf;
- return oid_object_info_extended(r, oid, &oi,
- OBJECT_INFO_DIE_IF_CORRUPT);
+ return odb_read_object_info_extended(r->objects, oid, &oi,
+ OBJECT_INFO_DIE_IF_CORRUPT);
}
/*****************************************************************************
@@ -422,7 +422,7 @@ static int istream_source(struct git_istream *st,
oi.typep = type;
oi.sizep = &size;
- status = oid_object_info_extended(r, oid, &oi, 0);
+ status = odb_read_object_info_extended(r->objects, oid, &oi, 0);
if (status < 0)
return status;
diff --git a/submodule.c b/submodule.c
index 788c9e55ed3..f8373a9ea7d 100644
--- a/submodule.c
+++ b/submodule.c
@@ -968,7 +968,7 @@ static int check_has_commit(const struct object_id *oid, void *data)
return 0;
}
- type = oid_object_info(&subrepo, oid, NULL);
+ type = odb_read_object_info(subrepo.objects, oid, NULL);
switch (type) {
case OBJ_COMMIT:
@@ -1752,8 +1752,7 @@ static int fetch_start_failure(struct strbuf *err UNUSED,
static int commit_missing_in_sub(const struct object_id *oid, void *data)
{
struct repository *subrepo = data;
-
- enum object_type type = oid_object_info(subrepo, oid, NULL);
+ enum object_type type = odb_read_object_info(subrepo->objects, oid, NULL);
return type != OBJ_COMMIT;
}
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index dba227259a2..d8488007493 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -23,7 +23,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
die("could not init repo");
if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
die("could not parse oid");
- if (oid_object_info_extended(&r, &oid, &oi, 0))
+ if (odb_read_object_info_extended(r.objects, &oid, &oi, 0))
die("could not obtain object info");
printf("%d\n", (int) size);
diff --git a/tag.c b/tag.c
index 5f6868bf7b1..144048fd5e0 100644
--- a/tag.c
+++ b/tag.c
@@ -52,7 +52,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
unsigned long size;
int ret;
- type = oid_object_info(the_repository, oid, NULL);
+ type = odb_read_object_info(the_repository->objects, oid, NULL);
if (type != OBJ_TAG)
return error("%s: cannot verify a non-tag object of type %s.",
name_to_report ?
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 14/17] odb: rename `repo_read_object_file()`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (12 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 13/17] odb: rename `oid_object_info()` Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 15/17] odb: rename `has_object()` Patrick Steinhardt
` (3 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `repo_read_object_file()` to `odb_read_object()` to match other
functions related to the object database and our modern coding
guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 10 +++++-----
archive.c | 2 +-
attr.c | 2 +-
bisect.c | 6 +++---
blame.c | 13 ++++++-------
builtin/cat-file.c | 26 +++++++++++---------------
builtin/difftool.c | 2 +-
builtin/fast-export.c | 6 +++---
builtin/fast-import.c | 8 ++++----
builtin/grep.c | 8 ++++----
builtin/index-pack.c | 8 ++++----
builtin/log.c | 2 +-
builtin/merge-tree.c | 12 ++++++------
builtin/mktag.c | 4 ++--
builtin/notes.c | 6 +++---
builtin/pack-objects.c | 30 +++++++++++++++---------------
builtin/tag.c | 4 ++--
builtin/unpack-file.c | 2 +-
builtin/unpack-objects.c | 4 ++--
bundle.c | 2 +-
combine-diff.c | 2 +-
commit.c | 6 +++---
config.c | 2 +-
dir.c | 2 +-
entry.c | 4 ++--
fmt-merge-msg.c | 4 ++--
fsck.c | 2 +-
grep.c | 4 ++--
http-push.c | 4 ++--
mailmap.c | 2 +-
match-trees.c | 4 ++--
merge-blobs.c | 8 ++++----
merge-ort.c | 2 +-
notes-cache.c | 2 +-
notes-merge.c | 2 +-
notes.c | 13 +++++++------
object.c | 2 +-
odb.c | 19 +++++++------------
odb.h | 29 +++++++++++++++++++++++------
read-cache.c | 6 +++---
reflog.c | 4 ++--
rerere.c | 5 ++---
submodule-config.c | 4 ++--
tag.c | 6 +++---
tree-walk.c | 6 +++---
tree.c | 4 ++--
xdiff-interface.c | 2 +-
47 files changed, 157 insertions(+), 150 deletions(-)
diff --git a/apply.c b/apply.c
index e778b4e911d..a34ced04625 100644
--- a/apply.c
+++ b/apply.c
@@ -3210,8 +3210,8 @@ static int apply_binary(struct apply_state *state,
unsigned long size;
char *result;
- result = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ result = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!result)
return error(_("the necessary postimage %s for "
"'%s' cannot be read"),
@@ -3273,8 +3273,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
unsigned long sz;
char *result;
- result = repo_read_object_file(the_repository, oid, &type,
- &sz);
+ result = odb_read_object(the_repository->objects, oid,
+ &type, &sz);
if (!result)
return -1;
/* XXX read_sha1_file NUL-terminates */
@@ -3503,7 +3503,7 @@ static int resolve_to(struct image *image, const struct object_id *result_id)
image_clear(image);
- data = repo_read_object_file(the_repository, result_id, &type, &size);
+ data = odb_read_object(the_repository->objects, result_id, &type, &size);
if (!data || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(result_id));
strbuf_attach(&image->buf, data, size, size + 1);
diff --git a/archive.c b/archive.c
index f2511d530d5..f5a9d45c8d3 100644
--- a/archive.c
+++ b/archive.c
@@ -98,7 +98,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
(args->tree ? &args->tree->object.oid : NULL), oid);
path += args->baselen;
- buffer = repo_read_object_file(the_repository, oid, type, sizep);
+ buffer = odb_read_object(the_repository->objects, oid, type, sizep);
if (buffer && S_ISREG(mode)) {
struct strbuf buf = STRBUF_INIT;
size_t size = 0;
diff --git a/attr.c b/attr.c
index e5680db7f65..d1daeb0b4d9 100644
--- a/attr.c
+++ b/attr.c
@@ -779,7 +779,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
if (get_tree_entry(istate->repo, tree_oid, path, &oid, &mode))
return NULL;
- buf = repo_read_object_file(istate->repo, &oid, &type, &sz);
+ buf = odb_read_object(istate->repo->objects, &oid, &type, &sz);
if (!buf || type != OBJ_BLOB) {
free(buf);
return NULL;
diff --git a/bisect.c b/bisect.c
index a7939216d00..f24474542ec 100644
--- a/bisect.c
+++ b/bisect.c
@@ -155,9 +155,9 @@ static void show_list(const char *debug, int counted, int nr,
unsigned commit_flags = commit->object.flags;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository,
- &commit->object.oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects,
+ &commit->object.oid, &type,
+ &size);
const char *subject_start;
int subject_len;
diff --git a/blame.c b/blame.c
index 97db3355af4..858d2d74df9 100644
--- a/blame.c
+++ b/blame.c
@@ -1041,9 +1041,9 @@ static void fill_origin_blob(struct diff_options *opt,
&o->blob_oid, 1, &file->ptr, &file_size))
;
else
- file->ptr = repo_read_object_file(the_repository,
- &o->blob_oid, &type,
- &file_size);
+ file->ptr = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &file_size);
file->size = file_size;
if (!file->ptr)
@@ -2869,10 +2869,9 @@ void setup_scoreboard(struct blame_scoreboard *sb,
&sb->final_buf_size))
;
else
- sb->final_buf = repo_read_object_file(the_repository,
- &o->blob_oid,
- &type,
- &sb->final_buf_size);
+ sb->final_buf = odb_read_object(the_repository->objects,
+ &o->blob_oid, &type,
+ &sb->final_buf_size);
if (!sb->final_buf)
die(_("cannot read blob %s for path %s"),
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index f7595fdb04e..90a3e159d11 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -74,7 +74,7 @@ static int filter_object(const char *path, unsigned mode,
{
enum object_type type;
- *buf = repo_read_object_file(the_repository, oid, &type, size);
+ *buf = odb_read_object(the_repository->objects, oid, &type, size);
if (!*buf)
return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path);
@@ -197,8 +197,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
ret = stream_blob(&oid);
goto cleanup;
}
- buf = repo_read_object_file(the_repository, &oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &oid,
+ &type, &size);
if (!buf)
die("Cannot read object %s", obj_name);
@@ -219,10 +219,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
struct object_id blob_oid;
if (odb_read_object_info(the_repository->objects,
&oid, NULL) == OBJ_TAG) {
- char *buffer = repo_read_object_file(the_repository,
- &oid,
- &type,
- &size);
+ char *buffer = odb_read_object(the_repository->objects,
+ &oid, &type, &size);
const char *target;
if (!buffer)
@@ -403,10 +401,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
if (!textconv_object(the_repository,
data->rest, 0100644, oid,
1, &contents, &size))
- contents = repo_read_object_file(the_repository,
- oid,
- &type,
- &size);
+ contents = odb_read_object(the_repository->objects,
+ oid, &type, &size);
if (!contents)
die("could not convert '%s' %s",
oid_to_hex(oid), data->rest);
@@ -423,8 +419,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
unsigned long size;
void *contents;
- contents = repo_read_object_file(the_repository, oid, &type,
- &size);
+ contents = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!contents)
die("object %s disappeared", oid_to_hex(oid));
@@ -533,8 +529,8 @@ static void batch_object_write(const char *obj_name,
size_t s = data->size;
char *buf = NULL;
- buf = repo_read_object_file(the_repository, &data->oid, &data->type,
- &data->size);
+ buf = odb_read_object(the_repository->objects, &data->oid,
+ &data->type, &data->size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&data->oid));
buf = replace_idents_using_mailmap(buf, &s);
diff --git a/builtin/difftool.c b/builtin/difftool.c
index fac613e3bc3..e4bc1f83169 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -320,7 +320,7 @@ static char *get_symlink(struct repository *repo,
} else {
enum object_type type;
unsigned long size;
- data = repo_read_object_file(repo, oid, &type, &size);
+ data = odb_read_object(repo->objects, oid, &type, &size);
if (!data)
die(_("could not read object %s for symlink %s"),
oid_to_hex(oid), path);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 6c93cf0a8aa..33f304dd0ad 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -323,7 +323,7 @@ static void export_blob(const struct object_id *oid)
object = (struct object *)lookup_blob(the_repository, oid);
eaten = 0;
} else {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
die("could not read blob %s", oid_to_hex(oid));
if (check_object_signature(the_repository, oid, buf, size,
@@ -869,8 +869,8 @@ static void handle_tag(const char *name, struct tag *tag)
return;
}
- buf = repo_read_object_file(the_repository, &tag->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &tag->object.oid,
+ &type, &size);
if (!buf)
die("could not read tag %s", oid_to_hex(&tag->object.oid));
message = memmem(buf, size, "\n\n", 2);
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 2718376f2c9..1973c504e25 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1265,7 +1265,7 @@ static void load_tree(struct tree_entry *root)
die("Can't load tree %s", oid_to_hex(oid));
} else {
enum object_type type;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_TREE)
die("Can't load tree %s", oid_to_hex(oid));
}
@@ -3002,7 +3002,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
char *buf;
if (!oe || oe->pack_id == MAX_PACK_ID) {
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
} else {
type = oe->type;
buf = gfi_unpack_entry(oe, &size);
@@ -3110,8 +3110,8 @@ static struct object_entry *dereference(struct object_entry *oe,
buf = gfi_unpack_entry(oe, &size);
} else {
enum object_type unused;
- buf = repo_read_object_file(the_repository, oid, &unused,
- &size);
+ buf = odb_read_object(the_repository->objects, oid,
+ &unused, &size);
}
if (!buf)
die("Can't load object %s", oid_to_hex(oid));
diff --git a/builtin/grep.c b/builtin/grep.c
index 1435d462cd1..5de61dfffe8 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -573,8 +573,8 @@ static int grep_cache(struct grep_opt *opt,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository, &ce->oid,
- &type, &size);
+ data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &size);
if (!data)
die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
init_tree_desc(&tree, &ce->oid, data, size);
@@ -666,8 +666,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data;
unsigned long size;
- data = repo_read_object_file(the_repository,
- &entry.oid, &type, &size);
+ data = odb_read_object(the_repository->objects,
+ &entry.oid, &type, &size);
if (!data)
die(_("unable to read tree (%s)"),
oid_to_hex(&entry.oid));
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index d0b16908122..180d261f6ce 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -914,8 +914,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
- has_data = repo_read_object_file(the_repository, oid,
- &has_type, &has_size);
+ has_data = odb_read_object(the_repository->objects, oid,
+ &has_type, &has_size);
read_unlock();
if (!data)
data = new_data = get_data_from_pack(obj_entry);
@@ -1521,8 +1521,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue;
- data = repo_read_object_file(the_repository, &d->oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &d->oid,
+ &type, &size);
if (!data)
continue;
diff --git a/builtin/log.c b/builtin/log.c
index fe9cc5ebecb..f2040b18159 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -714,7 +714,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
unsigned long offset = 0;
if (!buf)
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index b1a17787bcf..cf8b06cadc7 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -75,9 +75,9 @@ static void *result(struct merge_list *entry, unsigned long *size)
const char *path = entry->path;
if (!entry->stage)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid, &type,
- size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid, &type,
+ size);
base = NULL;
if (entry->stage == 1) {
base = entry->blob;
@@ -100,9 +100,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)
enum object_type type;
while (entry) {
if (entry->stage == 2)
- return repo_read_object_file(the_repository,
- &entry->blob->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects,
+ &entry->blob->object.oid,
+ &type, size);
entry = entry->link;
}
return NULL;
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 1809b38f937..1b391119de8 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -54,8 +54,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
void *buffer;
const struct object_id *repl;
- buffer = repo_read_object_file(the_repository, tagged_oid, &type,
- &size);
+ buffer = odb_read_object(the_repository->objects, tagged_oid,
+ &type, &size);
if (!buffer)
die(_("could not read tagged object '%s'"),
oid_to_hex(tagged_oid));
diff --git a/builtin/notes.c b/builtin/notes.c
index 783d4932ca6..a9529b1696a 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -152,7 +152,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
{
unsigned long size;
enum object_type type;
- char *buf = repo_read_object_file(the_repository, oid, &type, &size);
+ char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (buf) {
if (size)
write_or_die(fd, buf, size);
@@ -319,7 +319,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
strbuf_init(&msg->buf, 0);
if (repo_get_oid(the_repository, arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
- if (!(value = repo_read_object_file(the_repository, &object, &type, &len)))
+ if (!(value = odb_read_object(the_repository->objects, &object, &type, &len)))
die(_("failed to read object '%s'."), arg);
if (type != OBJ_BLOB) {
strbuf_release(&msg->buf);
@@ -722,7 +722,7 @@ static int append_edit(int argc, const char **argv, const char *prefix,
unsigned long size;
enum object_type type;
struct strbuf buf = STRBUF_INIT;
- char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
+ char *prev_buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!prev_buf)
die(_("unable to read %s"), oid_to_hex(note));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index da35d684081..580a5c1996b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -337,13 +337,13 @@ static void *get_delta(struct object_entry *entry)
void *buf, *base_buf, *delta_buf;
enum object_type type;
- buf = repo_read_object_file(the_repository, &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &entry->idx.oid,
+ &type, &size);
if (!buf)
die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
- base_buf = repo_read_object_file(the_repository,
- &DELTA(entry)->idx.oid, &type,
- &base_size);
+ base_buf = odb_read_object(the_repository->objects,
+ &DELTA(entry)->idx.oid, &type,
+ &base_size);
if (!base_buf)
die("unable to read %s",
oid_to_hex(&DELTA(entry)->idx.oid));
@@ -506,9 +506,9 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
&size, NULL)) != NULL)
buf = NULL;
else {
- buf = repo_read_object_file(the_repository,
- &entry->idx.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects,
+ &entry->idx.oid, &type,
+ &size);
if (!buf)
die(_("unable to read %s"),
oid_to_hex(&entry->idx.oid));
@@ -1895,7 +1895,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
/* Did not find one. Either we got a bogus request or
* we need to read and perhaps cache.
*/
- data = repo_read_object_file(the_repository, oid, &type, &size);
+ data = odb_read_object(the_repository->objects, oid, &type, &size);
if (!data)
return NULL;
if (type != OBJ_TREE) {
@@ -2762,9 +2762,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
/* Load data if not already done */
if (!trg->data) {
packing_data_lock(&to_pack);
- trg->data = repo_read_object_file(the_repository,
- &trg_entry->idx.oid, &type,
- &sz);
+ trg->data = odb_read_object(the_repository->objects,
+ &trg_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!trg->data)
die(_("object %s cannot be read"),
@@ -2777,9 +2777,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
}
if (!src->data) {
packing_data_lock(&to_pack);
- src->data = repo_read_object_file(the_repository,
- &src_entry->idx.oid, &type,
- &sz);
+ src->data = odb_read_object(the_repository->objects,
+ &src_entry->idx.oid, &type,
+ &sz);
packing_data_unlock(&to_pack);
if (!src->data) {
if (src_entry->preferred_base) {
diff --git a/builtin/tag.c b/builtin/tag.c
index e0b27396c6b..46cbf892e34 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -244,7 +244,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
struct strbuf payload = STRBUF_INIT;
struct strbuf signature = STRBUF_INIT;
- orig = buf = repo_read_object_file(the_repository, oid, &type, &size);
+ orig = buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return;
if (parse_signature(buf, size, &payload, &signature)) {
@@ -407,7 +407,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
strbuf_addstr(sb, "object of unknown type");
break;
case OBJ_COMMIT:
- if ((buf = repo_read_object_file(the_repository, oid, &type, &size))) {
+ if ((buf = odb_read_object(the_repository->objects, oid, &type, &size))) {
subject_len = find_commit_subject(buf, &subject_start);
strbuf_insert(sb, sb->len, subject_start, subject_len);
} else {
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index b92fd4710a9..4360872ae07 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -14,7 +14,7 @@ static char *create_temp_file(struct object_id *oid)
unsigned long size;
int fd;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 405e78bc592..4bc6575a574 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -516,8 +516,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
return;
- base = repo_read_object_file(the_repository, &base_oid, &type,
- &base_size);
+ base = odb_read_object(the_repository->objects, &base_oid,
+ &type, &base_size);
if (!base) {
error("failed to read delta-pack base object %s",
oid_to_hex(&base_oid));
diff --git a/bundle.c b/bundle.c
index e09e3c2f58c..717f056a454 100644
--- a/bundle.c
+++ b/bundle.c
@@ -305,7 +305,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
if (revs->max_age == -1 && revs->min_age == -1)
goto out;
- buf = repo_read_object_file(the_repository, &tag->oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &tag->oid, &type, &size);
if (!buf)
goto out;
line = memmem(buf, size, "\ntagger ", 8);
diff --git a/combine-diff.c b/combine-diff.c
index cf23a753407..4ea2dc93c4f 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -325,7 +325,7 @@ static char *grab_blob(struct repository *r,
*size = fill_textconv(r, textconv, df, &blob);
free_filespec(df);
} else {
- blob = repo_read_object_file(r, oid, &type, size);
+ blob = odb_read_object(r->objects, oid, &type, size);
if (!blob)
die(_("unable to read %s"), oid_to_hex(oid));
if (type != OBJ_BLOB)
diff --git a/commit.c b/commit.c
index d4aa9c7a5f8..28ee6b73ae6 100644
--- a/commit.c
+++ b/commit.c
@@ -374,7 +374,7 @@ const void *repo_get_commit_buffer(struct repository *r,
if (!ret) {
enum object_type type;
unsigned long size;
- ret = repo_read_object_file(r, &commit->object.oid, &type, &size);
+ ret = odb_read_object(r->objects, &commit->object.oid, &type, &size);
if (!ret)
die("cannot read commit object %s",
oid_to_hex(&commit->object.oid));
@@ -1275,8 +1275,8 @@ static void handle_signed_tag(const struct commit *parent, struct commit_extra_h
desc = merge_remote_util(parent);
if (!desc || !desc->obj)
return;
- buf = repo_read_object_file(the_repository, &desc->obj->oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &desc->obj->oid,
+ &type, &size);
if (!buf || type != OBJ_TAG)
goto free_return;
if (!parse_signature(buf, size, &payload, &signature))
diff --git a/config.c b/config.c
index 883dd066827..142c37215a8 100644
--- a/config.c
+++ b/config.c
@@ -1942,7 +1942,7 @@ int git_config_from_blob_oid(config_fn_t fn,
unsigned long size;
int ret;
- buf = repo_read_object_file(repo, oid, &type, &size);
+ buf = odb_read_object(repo->objects, oid, &type, &size);
if (!buf)
return error(_("unable to load config blob object '%s'"), name);
if (type != OBJ_BLOB) {
diff --git a/dir.c b/dir.c
index a374972b624..cb7bd873b17 100644
--- a/dir.c
+++ b/dir.c
@@ -302,7 +302,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
*size_out = 0;
*data_out = NULL;
- data = repo_read_object_file(the_repository, oid, &type, &sz);
+ data = odb_read_object(the_repository->objects, oid, &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return -1;
diff --git a/entry.c b/entry.c
index 75d55038d7c..cae02eb5039 100644
--- a/entry.c
+++ b/entry.c
@@ -93,8 +93,8 @@ void *read_blob_entry(const struct cache_entry *ce, size_t *size)
{
enum object_type type;
unsigned long ul;
- void *blob_data = repo_read_object_file(the_repository, &ce->oid,
- &type, &ul);
+ void *blob_data = odb_read_object(the_repository->objects, &ce->oid,
+ &type, &ul);
*size = ul;
if (blob_data) {
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 1a8c972adf3..40174efa3de 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -526,8 +526,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
struct object_id *oid = origins.items[i].util;
enum object_type type;
unsigned long size;
- char *buf = repo_read_object_file(the_repository, oid, &type,
- &size);
+ char *buf = odb_read_object(the_repository->objects, oid,
+ &type, &size);
char *origbuf = buf;
unsigned long len = size;
struct signature_check sigc = { NULL };
diff --git a/fsck.c b/fsck.c
index e69baab3af7..23965e1880f 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1293,7 +1293,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
if (oidset_contains(blobs_done, oid))
continue;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
if (is_promisor_object(the_repository, oid))
continue;
diff --git a/grep.c b/grep.c
index dc77e6c4631..932647e4a65 100644
--- a/grep.c
+++ b/grep.c
@@ -1931,8 +1931,8 @@ static int grep_source_load_oid(struct grep_source *gs)
{
enum object_type type;
- gs->buf = repo_read_object_file(gs->repo, gs->identifier, &type,
- &gs->size);
+ gs->buf = odb_read_object(gs->repo->objects, gs->identifier,
+ &type, &gs->size);
if (!gs->buf)
return error(_("'%s': unable to read %s"),
gs->name,
diff --git a/http-push.c b/http-push.c
index d1b1bb23711..9481825abfb 100644
--- a/http-push.c
+++ b/http-push.c
@@ -369,8 +369,8 @@ static void start_put(struct transfer_request *request)
ssize_t size;
git_zstream stream;
- unpacked = repo_read_object_file(the_repository, &request->obj->oid,
- &type, &len);
+ unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
+ &type, &len);
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
/* Set it up */
diff --git a/mailmap.c b/mailmap.c
index b18e74c2110..56c72102d9e 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -196,7 +196,7 @@ int read_mailmap_blob(struct string_list *map, const char *name)
if (repo_get_oid(the_repository, name, &oid) < 0)
return 0;
- buf = repo_read_object_file(the_repository, &oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, &oid, &type, &size);
if (!buf)
return error("unable to read mailmap object at %s", name);
if (type != OBJ_BLOB) {
diff --git a/match-trees.c b/match-trees.c
index 4704f95c340..5a8a5c39b04 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -63,7 +63,7 @@ static void *fill_tree_desc_strict(struct repository *r,
enum object_type type;
unsigned long size;
- buffer = repo_read_object_file(r, hash, &type, &size);
+ buffer = odb_read_object(r->objects, hash, &type, &size);
if (!buffer)
die("unable to read tree (%s)", oid_to_hex(hash));
if (type != OBJ_TREE)
@@ -199,7 +199,7 @@ static int splice_tree(struct repository *r,
if (*subpath)
subpath++;
- buf = repo_read_object_file(r, oid1, &type, &sz);
+ buf = odb_read_object(r->objects, oid1, &type, &sz);
if (!buf)
die("cannot read tree %s", oid_to_hex(oid1));
init_tree_desc(&desc, oid1, buf, sz);
diff --git a/merge-blobs.c b/merge-blobs.c
index ba8a3fdfd82..6fc27994171 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -12,8 +12,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
unsigned long size;
enum object_type type;
- buf = repo_read_object_file(the_repository, &obj->object.oid, &type,
- &size);
+ buf = odb_read_object(the_repository->objects, &obj->object.oid,
+ &type, &size);
if (!buf)
return -1;
if (type != OBJ_BLOB) {
@@ -79,8 +79,8 @@ void *merge_blobs(struct index_state *istate, const char *path,
return NULL;
if (!our)
our = their;
- return repo_read_object_file(the_repository, &our->object.oid,
- &type, size);
+ return odb_read_object(the_repository->objects, &our->object.oid,
+ &type, size);
}
if (fill_mmfile_blob(&f1, our) < 0)
diff --git a/merge-ort.c b/merge-ort.c
index f29417040c1..473ff61e36e 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -3629,7 +3629,7 @@ static int read_oid_strbuf(struct merge_options *opt,
void *buf;
enum object_type type;
unsigned long size;
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) {
path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
path, NULL, NULL, NULL,
diff --git a/notes-cache.c b/notes-cache.c
index 344f67762b8..dd56feed6e8 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -87,7 +87,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
value_oid = get_note(&c->tree, key_oid);
if (!value_oid)
return NULL;
- value = repo_read_object_file(the_repository, value_oid, &type, &size);
+ value = odb_read_object(the_repository->objects, value_oid, &type, &size);
*outsize = size;
return value;
diff --git a/notes-merge.c b/notes-merge.c
index de6a52e2e7f..586939939f2 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -340,7 +340,7 @@ static void write_note_to_worktree(const struct object_id *obj,
{
enum object_type type;
unsigned long size;
- void *buf = repo_read_object_file(the_repository, note, &type, &size);
+ void *buf = odb_read_object(the_repository->objects, note, &type, &size);
if (!buf)
die("cannot read note %s for object %s",
diff --git a/notes.c b/notes.c
index fc000e501d2..73eb5f00cf5 100644
--- a/notes.c
+++ b/notes.c
@@ -816,15 +816,15 @@ int combine_notes_concatenate(struct object_id *cur_oid,
/* read in both note blob objects */
if (!is_null_oid(new_oid))
- new_msg = repo_read_object_file(the_repository, new_oid,
- &new_type, &new_len);
+ new_msg = odb_read_object(the_repository->objects, new_oid,
+ &new_type, &new_len);
if (!new_msg || !new_len || new_type != OBJ_BLOB) {
free(new_msg);
return 0;
}
if (!is_null_oid(cur_oid))
- cur_msg = repo_read_object_file(the_repository, cur_oid,
- &cur_type, &cur_len);
+ cur_msg = odb_read_object(the_repository->objects, cur_oid,
+ &cur_type, &cur_len);
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
free(cur_msg);
free(new_msg);
@@ -880,7 +880,7 @@ static int string_list_add_note_lines(struct string_list *list,
return 0;
/* read_sha1_file NUL-terminates */
- data = repo_read_object_file(the_repository, oid, &t, &len);
+ data = odb_read_object(the_repository->objects, oid, &t, &len);
if (t != OBJ_BLOB || !data || !len) {
free(data);
return t != OBJ_BLOB || !data;
@@ -1290,7 +1290,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!oid)
return;
- if (!(msg = repo_read_object_file(the_repository, oid, &type, &msglen)) || type != OBJ_BLOB) {
+ if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
+ type != OBJ_BLOB) {
free(msg);
return;
}
diff --git a/object.c b/object.c
index 868d89eed42..c1553ee4330 100644
--- a/object.c
+++ b/object.c
@@ -335,7 +335,7 @@ struct object *parse_object_with_flags(struct repository *r,
return &lookup_tree(r, oid)->object;
}
- buffer = repo_read_object_file(r, oid, &type, &size);
+ buffer = odb_read_object(r->objects, oid, &type, &size);
if (buffer) {
if (!skip_hash &&
check_object_signature(r, repl, buffer, size, type) < 0) {
diff --git a/odb.c b/odb.c
index 40eacdfe2da..5419d5dff6d 100644
--- a/odb.c
+++ b/odb.c
@@ -30,7 +30,7 @@ KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -887,15 +887,10 @@ int pretend_object_file(struct repository *repo,
return 0;
}
-/*
- * This function dies on corrupt objects; the callers who want to
- * deal with them should arrange to call odb_read_object_info_extended() and give
- * error messages themselves.
- */
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size)
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
{
struct object_info oi = OBJECT_INFO_INIT;
unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT | OBJECT_INFO_LOOKUP_REPLACE;
@@ -904,7 +899,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
- if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
+ if (odb_read_object_info_extended(odb, oid, &oi, flags))
return NULL;
return data;
@@ -926,7 +921,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = repo_read_object_file(r, &actual_oid, &type, &isize);
+ buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
diff --git a/odb.h b/odb.h
index b37a9c5d20f..a4a5154fd0f 100644
--- a/odb.h
+++ b/odb.h
@@ -140,7 +140,7 @@ struct object_database {
/*
* This is meant to hold a *small* number of objects that you would
- * want repo_read_object_file() to be able to return, but yet you do not want
+ * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
@@ -260,10 +260,19 @@ void odb_add_to_alternates_file(struct object_database *odb,
void odb_add_to_alternates_memory(struct object_database *odb,
const char *dir);
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size);
+/*
+ * Read an object from the database. Returns the object data and assigns object
+ * type and size to the `type` and `size` pointers, if these pointers are
+ * non-NULL. Returns a `NULL` pointer in case the object does not exist.
+ *
+ * This function dies on corrupt objects; the callers who want to deal with
+ * them should arrange to call odb_read_object_info_extended() and give error
+ * messages themselves.
+ */
+void *odb_read_object(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size);
/*
* Add an object file to the in-memory object store, without writing it
@@ -371,7 +380,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
- * following functions in parallel: repo_read_object_file(),
+ * following functions in parallel: odb_read_object(),
* read_object_with_reference(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
@@ -446,4 +455,12 @@ static inline int oid_object_info(struct repository *r,
return odb_read_object_info(r->objects, oid, sizep);
}
+static inline void *repo_read_object_file(struct repository *r,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size)
+{
+ return odb_read_object(r->objects, oid, type, size);
+}
+
#endif /* ODB_H */
diff --git a/read-cache.c b/read-cache.c
index 7d5bccf95dc..531d87e7905 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -254,7 +254,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
if (strbuf_readlink(&sb, ce->name, expected_size))
return -1;
- buffer = repo_read_object_file(the_repository, &ce->oid, &type, &size);
+ buffer = odb_read_object(the_repository->objects, &ce->oid, &type, &size);
if (buffer) {
if (size == sb.len)
match = memcmp(buffer, sb.buf, size);
@@ -3485,8 +3485,8 @@ void *read_blob_data_from_index(struct index_state *istate,
}
if (pos < 0)
return NULL;
- data = repo_read_object_file(the_repository, &istate->cache[pos]->oid,
- &type, &sz);
+ data = odb_read_object(the_repository->objects, &istate->cache[pos]->oid,
+ &type, &sz);
if (!data || type != OBJ_BLOB) {
free(data);
return NULL;
diff --git a/reflog.c b/reflog.c
index 4f8a3b717cd..747b82eada8 100644
--- a/reflog.c
+++ b/reflog.c
@@ -140,8 +140,8 @@ static int tree_is_complete(const struct object_id *oid)
if (!tree->buffer) {
enum object_type type;
unsigned long size;
- void *data = repo_read_object_file(the_repository, oid, &type,
- &size);
+ void *data = odb_read_object(the_repository->objects, oid,
+ &type, &size);
if (!data) {
tree->object.flags |= INCOMPLETE;
return 0;
diff --git a/rerere.c b/rerere.c
index 951e4bf8b41..8bb97c98229 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1000,9 +1000,8 @@ static int handle_cache(struct index_state *istate,
break;
i = ce_stage(ce) - 1;
if (!mmfile[i].ptr) {
- mmfile[i].ptr = repo_read_object_file(the_repository,
- &ce->oid, &type,
- &size);
+ mmfile[i].ptr = odb_read_object(the_repository->objects,
+ &ce->oid, &type, &size);
if (!mmfile[i].ptr)
die(_("unable to read %s"),
oid_to_hex(&ce->oid));
diff --git a/submodule-config.c b/submodule-config.c
index a9f72107888..ea3a087a8bb 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -743,8 +743,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
if (submodule)
goto out;
- config = repo_read_object_file(the_repository, &oid, &type,
- &config_size);
+ config = odb_read_object(the_repository->objects, &oid,
+ &type, &config_size);
if (!config || type != OBJ_BLOB)
goto out;
diff --git a/tag.c b/tag.c
index 144048fd5e0..1d52686ee10 100644
--- a/tag.c
+++ b/tag.c
@@ -60,7 +60,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV),
type_name(type));
- buf = repo_read_object_file(the_repository, oid, &type, &size);
+ buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf)
return error("%s: unable to read file.",
name_to_report ?
@@ -222,8 +222,8 @@ int parse_tag(struct tag *item)
if (item->object.parsed)
return 0;
- data = repo_read_object_file(the_repository, &item->object.oid, &type,
- &size);
+ data = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!data)
return error("Could not read %s",
oid_to_hex(&item->object.oid));
diff --git a/tree-walk.c b/tree-walk.c
index 34b0fff4873..766af99f466 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -795,9 +795,9 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
*/
retval = DANGLING_SYMLINK;
- contents = repo_read_object_file(r,
- ¤t_tree_oid, &type,
- &link_len);
+ contents = odb_read_object(r->objects,
+ ¤t_tree_oid, &type,
+ &link_len);
if (!contents)
goto done;
diff --git a/tree.c b/tree.c
index 341b7c2ff3f..1ef743d90f4 100644
--- a/tree.c
+++ b/tree.c
@@ -193,8 +193,8 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
if (item->object.parsed)
return 0;
- buffer = repo_read_object_file(the_repository, &item->object.oid,
- &type, &size);
+ buffer = odb_read_object(the_repository->objects, &item->object.oid,
+ &type, &size);
if (!buffer)
return quiet_on_missing ? -1 :
error("Could not read %s",
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 01e6e378ea6..0e5d38c9600 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -187,7 +187,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
return;
}
- ptr->ptr = repo_read_object_file(the_repository, oid, &type, &size);
+ ptr->ptr = odb_read_object(the_repository->objects, oid, &type, &size);
if (!ptr->ptr || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
ptr->size = size;
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 15/17] odb: rename `has_object()`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (13 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 14/17] odb: rename `repo_read_object_file()` Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
` (2 subsequent siblings)
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `has_object()` to `odb_has_object()` to match other functions
related to the object database and our modern coding guidelines.
Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
apply.c | 2 +-
builtin/backfill.c | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/clone.c | 2 +-
builtin/fetch.c | 17 +++++++++--------
builtin/fsck.c | 2 +-
builtin/index-pack.c | 4 ++--
builtin/pack-objects.c | 4 ++--
builtin/receive-pack.c | 4 ++--
builtin/remote.c | 4 ++--
builtin/show-ref.c | 4 ++--
builtin/unpack-objects.c | 4 ++--
bulk-checkin.c | 4 ++--
cache-tree.c | 15 ++++++++-------
commit-graph.c | 2 +-
commit.c | 2 +-
fetch-pack.c | 8 ++++----
http-push.c | 14 ++++++++------
http-walker.c | 8 ++++----
list-objects.c | 4 ++--
notes.c | 4 ++--
odb.c | 6 +++---
odb.h | 12 ++++++++++--
reflog.c | 2 +-
refs.c | 3 ++-
remote.c | 2 +-
send-pack.c | 2 +-
shallow.c | 12 ++++++------
upload-pack.c | 2 +-
walker.c | 4 ++--
30 files changed, 87 insertions(+), 74 deletions(-)
diff --git a/apply.c b/apply.c
index a34ced04625..a6836692d0c 100644
--- a/apply.c
+++ b/apply.c
@@ -3204,7 +3204,7 @@ static int apply_binary(struct apply_state *state,
return 0; /* deletion patch */
}
- if (has_object(the_repository, &oid, 0)) {
+ if (odb_has_object(the_repository->objects, &oid, 0)) {
/* We already have the postimage */
enum object_type type;
unsigned long size;
diff --git a/builtin/backfill.c b/builtin/backfill.c
index 0b49baa39fa..80056abe473 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -67,8 +67,8 @@ static int fill_missing_blobs(const char *path UNUSED,
return 0;
for (size_t i = 0; i < list->nr; i++) {
- if (!has_object(ctx->repo, &list->oid[i],
- OBJECT_INFO_FOR_PREFETCH))
+ if (!odb_has_object(ctx->repo->objects, &list->oid[i],
+ OBJECT_INFO_FOR_PREFETCH))
oid_array_append(&ctx->current_batch, &list->oid[i]);
}
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 90a3e159d11..01672ec74bd 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -160,8 +160,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
goto cleanup;
case 'e':
- ret = !has_object(the_repository, &oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
+ ret = !odb_has_object(the_repository->objects, &oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR);
goto cleanup;
case 'w':
diff --git a/builtin/clone.c b/builtin/clone.c
index 3aabdf6570b..6d08abed37c 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -506,7 +506,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
continue;
if (ends_with(ref->name, "^{}"))
continue;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
refs_update_ref(get_main_ref_store(the_repository), msg,
ref->name, &ref->old_oid, NULL, 0,
diff --git a/builtin/fetch.c b/builtin/fetch.c
index b842bc9c51b..65ea6c84368 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -366,9 +366,9 @@ static void find_non_local_tags(const struct ref *refs,
*/
if (ends_with(ref->name, "^{}")) {
if (item &&
- !has_object(the_repository, &ref->old_oid, 0) &&
+ !odb_has_object(the_repository->objects, &ref->old_oid, 0) &&
!oidset_contains(&fetch_oids, &ref->old_oid) &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
item = NULL;
@@ -382,7 +382,7 @@ static void find_non_local_tags(const struct ref *refs,
* fetch.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -403,7 +403,7 @@ static void find_non_local_tags(const struct ref *refs,
* checked to see if it needs fetching.
*/
if (item &&
- !has_object(the_repository, &item->oid, 0) &&
+ !odb_has_object(the_repository->objects, &item->oid, 0) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
@@ -910,8 +910,8 @@ static int update_local_ref(struct ref *ref,
struct commit *current = NULL, *updated;
int fast_forward = 0;
- if (!has_object(the_repository, &ref->new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &ref->new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
if (oideq(&ref->old_oid, &ref->new_oid)) {
@@ -1330,7 +1330,8 @@ static int check_exist_and_connected(struct ref *ref_map)
* we need all direct targets to exist.
*/
for (r = rm; r; r = r->next) {
- if (!has_object(the_repository, &r->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ if (!odb_has_object(the_repository->objects, &r->old_oid,
+ HAS_OBJECT_RECHECK_PACKED))
return -1;
}
@@ -1485,7 +1486,7 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
struct object_id oid;
if (repo_get_oid(the_repository, s, &oid))
die(_("%s is not a valid object"), s);
- if (!has_object(the_repository, &oid, 0))
+ if (!odb_has_object(the_repository->objects, &oid, 0))
die(_("the object %s does not exist"), s);
oid_array_append(oids, &oid);
continue;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 6e3465b0266..0084cf7400b 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -161,7 +161,7 @@ static int mark_object(struct object *obj, enum object_type type,
return 0;
if (!(obj->flags & HAS_OBJ)) {
- if (parent && !has_object(the_repository, &obj->oid, 1)) {
+ if (parent && !odb_has_object(the_repository->objects, &obj->oid, 1)) {
printf_ln(_("broken link from %7s %s\n"
" to %7s %s"),
printable_type(&parent->oid, parent->type),
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 180d261f6ce..19c67a85344 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -893,8 +893,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (startup_info->have_repository) {
read_lock();
- collision_test_needed = has_object(the_repository, oid,
- HAS_OBJECT_FETCH_PROMISOR);
+ collision_test_needed = odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_FETCH_PROMISOR);
read_unlock();
}
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 580a5c1996b..06bdeb4223b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3968,7 +3968,7 @@ static void show_object__ma_allow_any(struct object *obj, const char *name, void
* Quietly ignore ALL missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0))
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0))
return;
show_object(obj, name, data);
@@ -3982,7 +3982,7 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
* Quietly ignore EXPECTED missing objects. This avoids problems with
* staging them now and getting an odd error later.
*/
- if (!has_object(the_repository, &obj->oid, 0) &&
+ if (!odb_has_object(the_repository->objects, &obj->oid, 0) &&
is_promisor_object(to_pack.repo, &obj->oid))
return;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 7ea273d93e4..26e77d70726 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1509,8 +1509,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
}
if (!is_null_oid(new_oid) &&
- !has_object(the_repository, new_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, new_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error("unpack should have generated %s, "
"but I can't find it!", oid_to_hex(new_oid));
ret = "bad pack";
diff --git a/builtin/remote.c b/builtin/remote.c
index ac5b8d2a1a6..7cbda285ebe 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -454,8 +454,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
info->status = PUSH_STATUS_UPTODATE;
else if (is_null_oid(&ref->old_oid))
info->status = PUSH_STATUS_CREATE;
- else if (has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ else if (odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
ref_newer(&ref->new_oid, &ref->old_oid))
info->status = PUSH_STATUS_FASTFORWARD;
else
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 90ec1de78f9..117709cb076 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -35,8 +35,8 @@ static void show_one(const struct show_one_options *opts,
const char *hex;
struct object_id peeled;
- if (!has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
die("git show-ref: bad ref %s (%s)", refname,
oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 4bc6575a574..a69d59eb50c 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -449,8 +449,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
delta_data = get_data(delta_size);
if (!delta_data)
return;
- if (has_object(the_repository, &base_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &base_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
; /* Ok we have this one */
else if (resolve_against_held(nr, &base_oid,
delta_data, delta_size))
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 55406a539e7..16df86c0ba8 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -130,8 +130,8 @@ static void flush_batch_fsync(void)
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
{
/* The object may already exist in the repository */
- if (has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 1;
/* Might want to keep the list sorted */
diff --git a/cache-tree.c b/cache-tree.c
index 9786b32b3a1..a4bc14ad15c 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -239,8 +239,8 @@ int cache_tree_fully_valid(struct cache_tree *it)
if (!it)
return 0;
if (it->entry_count < 0 ||
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
for (i = 0; i < it->subtree_nr; i++) {
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -292,8 +292,8 @@ static int update_one(struct cache_tree *it,
}
if (0 <= it->entry_count &&
- has_object(the_repository, &it->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ odb_has_object(the_repository->objects, &it->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return it->entry_count;
/*
@@ -399,8 +399,9 @@ static int update_one(struct cache_tree *it,
ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
!must_check_existence(ce);
if (is_null_oid(oid) ||
- (!ce_missing_ok && !has_object(the_repository, oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
+ (!ce_missing_ok &&
+ !odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))) {
strbuf_release(&buffer);
if (expected_missing)
return -1;
@@ -448,7 +449,7 @@ static int update_one(struct cache_tree *it,
struct object_id oid;
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
OBJ_TREE, &oid);
- if (has_object(the_repository, &oid, HAS_OBJECT_RECHECK_PACKED))
+ if (odb_has_object(the_repository->objects, &oid, HAS_OBJECT_RECHECK_PACKED))
oidcpy(&it->oid, &oid);
else
to_invalidate = 1;
diff --git a/commit-graph.c b/commit-graph.c
index 5f482d3377f..bd7b6f5338b 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1040,7 +1040,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
return NULL;
if (!search_commit_pos_in_graph(id, repo->objects->commit_graph, &pos))
return NULL;
- if (commit_graph_paranoia && !has_object(repo, id, 0))
+ if (commit_graph_paranoia && !odb_has_object(repo->objects, id, 0))
return NULL;
commit = lookup_commit(repo, id);
diff --git a/commit.c b/commit.c
index 28ee6b73ae6..15115125c36 100644
--- a/commit.c
+++ b/commit.c
@@ -575,7 +575,7 @@ int repo_parse_commit_internal(struct repository *r,
if (commit_graph_paranoia == -1)
commit_graph_paranoia = git_env_bool(GIT_COMMIT_GRAPH_PARANOIA, 0);
- if (commit_graph_paranoia && !has_object(r, &item->object.oid, 0)) {
+ if (commit_graph_paranoia && !odb_has_object(r->objects, &item->object.oid, 0)) {
unparse_commit(r, &item->object.oid);
return quiet_on_missing ? -1 :
error(_("commit %s exists in commit-graph but not in the object database"),
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f5de1c94d1..5e74235fc06 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -142,7 +142,7 @@ static struct commit *deref_without_lazy_fetch(const struct object_id *oid,
commit = lookup_commit_in_graph(the_repository, oid);
if (commit) {
if (mark_tags_complete_and_check_obj_db) {
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
die_in_commit_graph_only(oid);
}
return commit;
@@ -770,7 +770,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
if (!commit) {
struct object *o;
- if (!has_object(the_repository, &ref->old_oid, 0))
+ if (!odb_has_object(the_repository->objects, &ref->old_oid, 0))
continue;
o = parse_object(the_repository, &ref->old_oid);
if (!o || o->type != OBJ_COMMIT)
@@ -1984,8 +1984,8 @@ static void update_shallow(struct fetch_pack_args *args,
struct oid_array extra = OID_ARRAY_INIT;
struct object_id *oid = si->shallow->oid;
for (i = 0; i < si->shallow->nr; i++)
- if (has_object(the_repository, &oid[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &oid[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
oid_array_append(&extra, &oid[i]);
if (extra.nr) {
setup_alternate_shallow(&shallow_lock,
diff --git a/http-push.c b/http-push.c
index 9481825abfb..beb41732fb6 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1447,8 +1447,8 @@ static void one_remote_ref(const char *refname)
* may be required for updating server info later.
*/
if (repo->can_update_info_refs &&
- !has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ !odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
obj = lookup_unknown_object(the_repository, &ref->old_oid);
fprintf(stderr, " fetch %s for %s\n",
oid_to_hex(&ref->old_oid), refname);
@@ -1653,14 +1653,16 @@ static int delete_remote_branch(const char *pattern, int force)
return error("Remote HEAD symrefs too deep");
if (is_null_oid(&head_oid))
return error("Unable to resolve remote HEAD");
- if (!has_object(the_repository, &head_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &head_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", oid_to_hex(&head_oid));
/* Remote branch must resolve to a known object */
if (is_null_oid(&remote_ref->old_oid))
return error("Unable to resolve remote branch %s",
remote_ref->name);
- if (!has_object(the_repository, &remote_ref->old_oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &remote_ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, oid_to_hex(&remote_ref->old_oid));
/* Remote branch must be an ancestor of remote HEAD */
@@ -1881,8 +1883,8 @@ int cmd_main(int argc, const char **argv)
if (!force_all &&
!is_null_oid(&ref->old_oid) &&
!ref->force) {
- if (!has_object(the_repository, &ref->old_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
+ if (!odb_has_object(the_repository->objects, &ref->old_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
!ref_newer(&ref->peer_ref->new_oid,
&ref->old_oid)) {
/*
diff --git a/http-walker.c b/http-walker.c
index 05fb9ce714a..0f7ae46d7f1 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -138,8 +138,8 @@ static int fill_active_slot(void *data UNUSED)
list_for_each_safe(pos, tmp, head) {
obj_req = list_entry(pos, struct object_request, node);
if (obj_req->state == WAITING) {
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
obj_req->state = COMPLETE;
else {
start_object_request(obj_req);
@@ -497,8 +497,8 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
if (!obj_req)
return error("Couldn't find request for %s in the queue", hex);
- if (has_object(the_repository, &obj_req->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj_req->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
if (obj_req->req)
abort_http_object_request(&obj_req->req);
abort_object_request(obj_req);
diff --git a/list-objects.c b/list-objects.c
index c50b9578584..42c17d95739 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -74,8 +74,8 @@ static void process_blob(struct traversal_context *ctx,
* of missing objects.
*/
if (ctx->revs->exclude_promisor_objects &&
- !has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
+ !odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) &&
is_promisor_object(ctx->revs->repo, &obj->oid))
return;
diff --git a/notes.c b/notes.c
index 73eb5f00cf5..97b995f3f2d 100644
--- a/notes.c
+++ b/notes.c
@@ -794,8 +794,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
struct note_delete_list **l = (struct note_delete_list **) cb_data;
struct note_delete_list *n;
- if (has_object(the_repository, object_oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, object_oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0; /* nothing to do for this note */
/* failed to find object => prune this note */
diff --git a/odb.c b/odb.c
index 5419d5dff6d..ecb6711a27b 100644
--- a/odb.c
+++ b/odb.c
@@ -871,7 +871,7 @@ int pretend_object_file(struct repository *repo,
char *co_buf;
hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (has_object(repo, oid, 0) ||
+ if (odb_has_object(repo->objects, oid, 0) ||
find_cached_object(repo->objects, oid))
return 0;
@@ -953,7 +953,7 @@ void *read_object_with_reference(struct repository *r,
}
}
-int has_object(struct repository *r, const struct object_id *oid,
+int odb_has_object(struct object_database *odb, const struct object_id *oid,
unsigned flags)
{
unsigned object_info_flags = 0;
@@ -965,7 +965,7 @@ int has_object(struct repository *r, const struct object_id *oid,
if (!(flags & HAS_OBJECT_FETCH_PROMISOR))
object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT;
- return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0;
+ return odb_read_object_info_extended(odb, oid, NULL, object_info_flags) >= 0;
}
void odb_assert_oid_type(struct object_database *odb,
diff --git a/odb.h b/odb.h
index a4a5154fd0f..2532c490461 100644
--- a/odb.h
+++ b/odb.h
@@ -372,8 +372,9 @@ enum {
* Returns 1 if the object exists. This function will not lazily fetch objects
* in a partial clone by default.
*/
-int has_object(struct repository *r, const struct object_id *oid,
- unsigned flags);
+int odb_has_object(struct object_database *odb,
+ const struct object_id *oid,
+ unsigned flags);
void odb_assert_oid_type(struct object_database *odb,
const struct object_id *oid, enum object_type expect);
@@ -463,4 +464,11 @@ static inline void *repo_read_object_file(struct repository *r,
return odb_read_object(r->objects, oid, type, size);
}
+static inline int has_object(struct repository *r,
+ const struct object_id *oid,
+ unsigned flags)
+{
+ return odb_has_object(r->objects, oid, flags);
+}
+
#endif /* ODB_H */
diff --git a/reflog.c b/reflog.c
index 747b82eada8..39c205fd26e 100644
--- a/reflog.c
+++ b/reflog.c
@@ -152,7 +152,7 @@ static int tree_is_complete(const struct object_id *oid)
init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
complete = 1;
while (tree_entry(&desc, &entry)) {
- if (!has_object(the_repository, &entry.oid,
+ if (!odb_has_object(the_repository->objects, &entry.oid,
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) ||
(S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) {
tree->object.flags |= INCOMPLETE;
diff --git a/refs.c b/refs.c
index 0ff0e582a6b..26e5c2a7d9c 100644
--- a/refs.c
+++ b/refs.c
@@ -376,7 +376,8 @@ int ref_resolves_to_object(const char *refname,
{
if (flags & REF_ISBROKEN)
return 0;
- if (!has_object(repo, oid, HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (!odb_has_object(repo->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
error(_("%s does not point to a valid object!"), refname);
return 0;
}
diff --git a/remote.c b/remote.c
index 72c36239d31..5edf2a9f4b2 100644
--- a/remote.c
+++ b/remote.c
@@ -1703,7 +1703,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
if (starts_with(ref->name, "refs/tags/"))
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
- else if (!has_object(the_repository, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
+ else if (!odb_has_object(the_repository->objects, &ref->old_oid, HAS_OBJECT_RECHECK_PACKED))
reject_reason = REF_STATUS_REJECT_FETCH_FIRST;
else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) ||
!lookup_commit_reference_gently(the_repository, &ref->new_oid, 1))
diff --git a/send-pack.c b/send-pack.c
index abca2dd38a7..d029f748232 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -45,7 +45,7 @@ int option_parse_push_signed(const struct option *opt,
static void feed_object(struct repository *r,
const struct object_id *oid, FILE *fh, int negative)
{
- if (negative && !has_object(r, oid, 0))
+ if (negative && !odb_has_object(r->objects, oid, 0))
return;
if (negative)
diff --git a/shallow.c b/shallow.c
index d379756e39a..ef3adb635fd 100644
--- a/shallow.c
+++ b/shallow.c
@@ -310,8 +310,8 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
if (graft->nr_parent != -1)
return 0;
if (data->flags & QUICK) {
- if (!has_object(the_repository, &graft->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (!odb_has_object(the_repository->objects, &graft->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 0;
} else if (data->flags & SEEN_ONLY) {
struct commit *c = lookup_commit(the_repository, &graft->oid);
@@ -477,8 +477,8 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
ALLOC_ARRAY(info->ours, sa->nr);
ALLOC_ARRAY(info->theirs, sa->nr);
for (size_t i = 0; i < sa->nr; i++) {
- if (has_object(the_repository, sa->oid + i,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, sa->oid + i,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
struct commit_graft *graft;
graft = lookup_commit_graft(the_repository,
&sa->oid[i]);
@@ -515,8 +515,8 @@ void remove_nonexistent_theirs_shallow(struct shallow_info *info)
for (i = dst = 0; i < info->nr_theirs; i++) {
if (i != dst)
info->theirs[dst] = info->theirs[i];
- if (has_object(the_repository, oid + info->theirs[i],
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
+ if (odb_has_object(the_repository->objects, oid + info->theirs[i],
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
dst++;
}
info->nr_theirs = dst;
diff --git a/upload-pack.c b/upload-pack.c
index e994d6a901b..4f26f6afc77 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -509,7 +509,7 @@ static int got_oid(struct upload_pack_data *data,
{
if (get_oid_hex(hex, oid))
die("git upload-pack: expected SHA1 object, got '%s'", hex);
- if (!has_object(the_repository, oid, 0))
+ if (!odb_has_object(the_repository->objects, oid, 0))
return -1;
return do_got_oid(data, oid);
}
diff --git a/walker.c b/walker.c
index a8abe8a2e78..d131af04c7b 100644
--- a/walker.c
+++ b/walker.c
@@ -150,8 +150,8 @@ static int process(struct walker *walker, struct object *obj)
return 0;
obj->flags |= SEEN;
- if (has_object(the_repository, &obj->oid,
- HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
+ if (odb_has_object(the_repository->objects, &obj->oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR)) {
/* We already have it, so we should scan it now. */
obj->flags |= TO_SCAN;
}
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 16/17] odb: rename `pretend_object_file()`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (14 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 15/17] odb: rename `has_object()` Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 12:22 ` [PATCH v6 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
2025-07-01 14:26 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Justin Tobler
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `pretend_object_file()` to `odb_pretend_object()` to match other
functions related to the object database and our modern coding
guidelines.
No compatibility wrapper is introduced as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
blame.c | 3 ++-
odb.c | 18 +++++++++---------
odb.h | 6 +++---
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/blame.c b/blame.c
index 858d2d74df9..dce5c8d855c 100644
--- a/blame.c
+++ b/blame.c
@@ -277,7 +277,8 @@ static struct commit *fake_working_tree_commit(struct repository *r,
convert_to_git(r->index, path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
- pretend_object_file(the_repository, buf.buf, buf.len, OBJ_BLOB, &origin->blob_oid);
+ odb_pretend_object(the_repository->objects, buf.buf, buf.len,
+ OBJ_BLOB, &origin->blob_oid);
/*
* Read the current index, replace the path entry with
diff --git a/odb.c b/odb.c
index ecb6711a27b..217903d7b14 100644
--- a/odb.c
+++ b/odb.c
@@ -863,21 +863,21 @@ int odb_read_object_info(struct object_database *odb,
return type;
}
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid)
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid)
{
struct cached_object_entry *co;
char *co_buf;
- hash_object_file(repo->hash_algo, buf, len, type, oid);
- if (odb_has_object(repo->objects, oid, 0) ||
- find_cached_object(repo->objects, oid))
+ hash_object_file(odb->repo->hash_algo, buf, len, type, oid);
+ if (odb_has_object(odb, oid, 0) ||
+ find_cached_object(odb, oid))
return 0;
- ALLOC_GROW(repo->objects->cached_objects,
- repo->objects->cached_object_nr + 1, repo->objects->cached_object_alloc);
- co = &repo->objects->cached_objects[repo->objects->cached_object_nr++];
+ ALLOC_GROW(odb->cached_objects,
+ odb->cached_object_nr + 1, odb->cached_object_alloc);
+ co = &odb->cached_objects[odb->cached_object_nr++];
co->value.size = len;
co->value.type = type;
co_buf = xmalloc(len);
diff --git a/odb.h b/odb.h
index 2532c490461..e4c51f8c38e 100644
--- a/odb.h
+++ b/odb.h
@@ -282,9 +282,9 @@ void *odb_read_object(struct object_database *odb,
* object in persistent storage before writing any other new objects
* that reference it.
*/
-int pretend_object_file(struct repository *repo,
- void *buf, unsigned long len, enum object_type type,
- struct object_id *oid);
+int odb_pretend_object(struct object_database *odb,
+ void *buf, unsigned long len, enum object_type type,
+ struct object_id *oid);
struct object_info {
/* Request */
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* [PATCH v6 17/17] odb: rename `read_object_with_reference()`
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (15 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 16/17] odb: rename `pretend_object_file()` Patrick Steinhardt
@ 2025-07-01 12:22 ` Patrick Steinhardt
2025-07-01 14:26 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Justin Tobler
17 siblings, 0 replies; 166+ messages in thread
From: Patrick Steinhardt @ 2025-07-01 12:22 UTC (permalink / raw)
To: git; +Cc: Derrick Stolee, Junio C Hamano, Toon Claes, Justin Tobler
Rename `read_object_with_reference()` to `odb_read_object_peeled()` to
match other functions related to the object database and our modern
coding guidelines. Furthermore though, the old name didn't really
describe very well what this function actually does, which is to walk
down any commit and tag objects until an object of the required type has
been found. This is generally referred to as "peeling", so the new name
should be way more descriptive.
No compatibility wrapper is introduced as the function is not used a lot
throughout our codebase.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Documentation/user-manual.adoc | 4 ++--
builtin/cat-file.c | 4 ++--
builtin/fast-import.c | 19 ++++++++-----------
builtin/grep.c | 9 +++------
builtin/pack-objects.c | 4 ++--
odb.c | 17 +++++++++--------
odb.h | 15 +++++++--------
tree-walk.c | 10 ++++------
8 files changed, 37 insertions(+), 45 deletions(-)
diff --git a/Documentation/user-manual.adoc b/Documentation/user-manual.adoc
index d2b478ad232..e86b2ad9f8a 100644
--- a/Documentation/user-manual.adoc
+++ b/Documentation/user-manual.adoc
@@ -4301,11 +4301,11 @@ Now, for the meat:
-----------------------------------------------------------------------------
case 0:
- buf = read_object_with_reference(sha1, argv[1], &size, NULL);
+ buf = odb_read_object_peeled(r->objects, sha1, argv[1], &size, NULL);
-----------------------------------------------------------------------------
This is how you read a blob (actually, not only a blob, but any type of
-object). To know how the function `read_object_with_reference()` actually
+object). To know how the function `odb_read_object_peeled()` actually
works, find the source code for it (something like `git grep
read_object_with | grep ":[a-z]"` in the Git repository), and read
the source.
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 01672ec74bd..08afecbf57c 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -246,8 +246,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
* fall-back to the usual case.
*/
}
- buf = read_object_with_reference(the_repository, &oid,
- exp_type_id, &size, NULL);
+ buf = odb_read_object_peeled(the_repository->objects, &oid,
+ exp_type_id, &size, NULL);
if (use_mailmap) {
size_t s = size;
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 1973c504e25..b1389c59211 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -2535,10 +2535,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
oidcpy(&commit_oid, &commit_oe->idx.oid);
} else if (!repo_get_oid(the_repository, p, &commit_oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &commit_oid,
- OBJ_COMMIT, &size,
- &commit_oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &commit_oid, OBJ_COMMIT, &size,
+ &commit_oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", p);
free(buf);
@@ -2604,9 +2603,8 @@ static void parse_from_existing(struct branch *b)
unsigned long size;
char *buf;
- buf = read_object_with_reference(the_repository,
- &b->oid, OBJ_COMMIT, &size,
- &b->oid);
+ buf = odb_read_object_peeled(the_repository->objects, &b->oid,
+ OBJ_COMMIT, &size, &b->oid);
parse_from_commit(b, buf, size);
free(buf);
}
@@ -2699,10 +2697,9 @@ static struct hash_list *parse_merge(unsigned int *count)
oidcpy(&n->oid, &oe->idx.oid);
} else if (!repo_get_oid(the_repository, from, &n->oid)) {
unsigned long size;
- char *buf = read_object_with_reference(the_repository,
- &n->oid,
- OBJ_COMMIT,
- &size, &n->oid);
+ char *buf = odb_read_object_peeled(the_repository->objects,
+ &n->oid, OBJ_COMMIT,
+ &size, &n->oid);
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", from);
free(buf);
diff --git a/builtin/grep.c b/builtin/grep.c
index 5de61dfffe8..39273d9c0fd 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -522,9 +522,7 @@ static int grep_submodule(struct grep_opt *opt,
obj_read_lock();
object_type = odb_read_object_info(subrepo->objects, oid, NULL);
obj_read_unlock();
- data = read_object_with_reference(subrepo,
- oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(subrepo->objects, oid, OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
@@ -705,9 +703,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
struct strbuf base;
int hit, len;
- data = read_object_with_reference(opt->repo,
- &obj->oid, OBJ_TREE,
- &size, NULL);
+ data = odb_read_object_peeled(opt->repo->objects, &obj->oid,
+ OBJ_TREE, &size, NULL);
if (!data)
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 06bdeb4223b..e88a13dbb9f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2055,8 +2055,8 @@ static void add_preferred_base(struct object_id *oid)
if (window <= num_preferred_base++)
return;
- data = read_object_with_reference(the_repository, oid,
- OBJ_TREE, &size, &tree_oid);
+ data = odb_read_object_peeled(the_repository->objects, oid,
+ OBJ_TREE, &size, &tree_oid);
if (!data)
return;
diff --git a/odb.c b/odb.c
index 217903d7b14..1f48a0448e3 100644
--- a/odb.c
+++ b/odb.c
@@ -905,11 +905,11 @@ void *odb_read_object(struct object_database *odb,
return data;
}
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *actual_oid_return)
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *actual_oid_return)
{
enum object_type type;
void *buffer;
@@ -921,7 +921,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1;
const char *ref_type = NULL;
- buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
+ buffer = odb_read_object(odb, &actual_oid, &type, &isize);
if (!buffer)
return NULL;
if (type == required_type) {
@@ -941,9 +941,10 @@ void *read_object_with_reference(struct repository *r,
}
ref_length = strlen(ref_type);
- if (ref_length + r->hash_algo->hexsz > isize ||
+ if (ref_length + odb->repo->hash_algo->hexsz > isize ||
memcmp(buffer, ref_type, ref_length) ||
- get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
+ get_oid_hex_algop((char *) buffer + ref_length, &actual_oid,
+ odb->repo->hash_algo)) {
free(buffer);
return NULL;
}
diff --git a/odb.h b/odb.h
index e4c51f8c38e..e922f256802 100644
--- a/odb.h
+++ b/odb.h
@@ -274,6 +274,12 @@ void *odb_read_object(struct object_database *odb,
enum object_type *type,
unsigned long *size);
+void *odb_read_object_peeled(struct object_database *odb,
+ const struct object_id *oid,
+ enum object_type required_type,
+ unsigned long *size,
+ struct object_id *oid_ret);
+
/*
* Add an object file to the in-memory object store, without writing it
* to disk.
@@ -382,7 +388,7 @@ void odb_assert_oid_type(struct object_database *odb,
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: odb_read_object(),
- * read_object_with_reference(), odb_read_object_info() and odb().
+ * odb_read_object_peeled(), odb_read_object_info() and odb().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used
@@ -431,13 +437,6 @@ enum for_each_object_flags {
FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
};
-
-void *read_object_with_reference(struct repository *r,
- const struct object_id *oid,
- enum object_type required_type,
- unsigned long *size,
- struct object_id *oid_ret);
-
/* Compatibility wrappers, to be removed once Git 2.51 has been released. */
#include "repository.h"
diff --git a/tree-walk.c b/tree-walk.c
index 766af99f466..e449a1320e5 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -90,7 +90,7 @@ void *fill_tree_descriptor(struct repository *r,
void *buf = NULL;
if (oid) {
- buf = read_object_with_reference(r, oid, OBJ_TREE, &size, NULL);
+ buf = odb_read_object_peeled(r->objects, oid, OBJ_TREE, &size, NULL);
if (!buf)
die(_("unable to read tree (%s)"), oid_to_hex(oid));
}
@@ -611,7 +611,7 @@ int get_tree_entry(struct repository *r,
unsigned long size;
struct object_id root;
- tree = read_object_with_reference(r, tree_oid, OBJ_TREE, &size, &root);
+ tree = odb_read_object_peeled(r->objects, tree_oid, OBJ_TREE, &size, &root);
if (!tree)
return -1;
@@ -681,10 +681,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
void *tree;
struct object_id root;
unsigned long size;
- tree = read_object_with_reference(r,
- ¤t_tree_oid,
- OBJ_TREE, &size,
- &root);
+ tree = odb_read_object_peeled(r->objects, ¤t_tree_oid,
+ OBJ_TREE, &size, &root);
if (!tree)
goto done;
--
2.50.0.195.g74e6fc65d0.dirty
^ permalink raw reply related [flat|nested] 166+ messages in thread
* Re: [PATCH v6 00/17] object-store: carve out the object database subsystem
2025-07-01 12:22 ` [PATCH v6 00/17] object-store: carve out the object database subsystem Patrick Steinhardt
` (16 preceding siblings ...)
2025-07-01 12:22 ` [PATCH v6 17/17] odb: rename `read_object_with_reference()` Patrick Steinhardt
@ 2025-07-01 14:26 ` Justin Tobler
17 siblings, 0 replies; 166+ messages in thread
From: Justin Tobler @ 2025-07-01 14:26 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, Derrick Stolee, Junio C Hamano, Toon Claes
On 25/07/01 02:22PM, Patrick Steinhardt wrote:
> Hi,
>
> this patch series refactors the object store subsystem to become more
> self-contained by getting rid of `the_repository`. Instead of passing in
> the repository explicitly, we start to pass in the object store itself,
> which is in contrast to many other refactorings we did, but in line with
> what we did for the ref store, as well.
>
> This series also starts to properly scope functions to the carved out
> object database subsystem, which requires a bit of shuffling. This
> allows us to have a short-and-sweet `odb_` prefix for functions and
> prepares us for a future with pluggable object backends.
Nice to see the odb subsystem take shape and become more self-contained.
> The series is structured as follows:
>
> - Patches 1 to 3 rename `struct object_store` and `struct
> object_directory` as well as the code files.
>
> - Patches 4 to 12 refactor "odb.c" to get rid of `the_repository`.
>
> - Patches 13 to 17 adjust the name of remaining functions so that they
> can be clearly attributed to the ODB. I'm happy to kick these
> patches out of this series and resend them at a later point in case
> they create too much turmoil.
>
> This series is built on top of 6f84262c44a (The eleventh batch,
> 2025-05-05) with ps/object-store-cleanup at 8a9e27be821 (object-store:
> drop `repo_has_object_file()`, 2025-04-29) merged into it. There are a
> couple of trivial conflicts when merged with "seen", I have appended the
> merge conflict resolution as a patch at the end of this mail.
[snip]
> Changes in v6:
> - Fix a mis-merged comment.
> - A couple of commit message improvements.
> - Link to v5: https://lore.kernel.org/r/20250605-pks-object-store-wo-the-repository-v5-0-779d1c28774b@pks.im
The changes in the range-diff are good. This version looks good to me.
-Justin
^ permalink raw reply [flat|nested] 166+ messages in thread