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 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 1, 2025 at 14:22 UTC a1e2581a1e9ca2a85ae0a018ba5fb8fe5db3c322
28 files changed +284 -272
builtin/commit-graph.c
+9 -9
@@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
66 struct repository *repo UNUSED)
67 {
68 struct commit_graph *graph = NULL;
69 - struct object_directory *odb = NULL;
69 + struct odb_source *source = NULL;
70 char *graph_name;
71 char *chain_name;
72 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,
101 if (opts.progress)
102 flags |= COMMIT_GRAPH_WRITE_PROGRESS;
103
104 - odb = find_odb(the_repository, opts.obj_dir);
105 - graph_name = get_commit_graph_filename(odb);
106 - chain_name = get_commit_graph_chain_filename(odb);
104 + source = find_odb(the_repository, opts.obj_dir);
105 + graph_name = get_commit_graph_filename(source);
106 + chain_name = get_commit_graph_chain_filename(source);
107 if (open_commit_graph(graph_name, &fd, &st))
108 opened = OPENED_GRAPH;
109 else if (errno != ENOENT)
@@ -120,7 +120,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
120 if (opened == OPENED_NONE)
121 return 0;
122 else if (opened == OPENED_GRAPH)
123 - graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb);
123 + graph = load_commit_graph_one_fd_st(the_repository, fd, &st, source);
124 else
125 graph = load_commit_graph_chain_fd_st(the_repository, fd, &st,
126 &incomplete_chain);
@@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
221 struct string_list pack_indexes = STRING_LIST_INIT_DUP;
222 struct strbuf buf = STRBUF_INIT;
223 struct oidset commits = OIDSET_INIT;
224 - struct object_directory *odb = NULL;
224 + struct odb_source *source = NULL;
225 int result = 0;
226 enum commit_graph_write_flags flags = 0;
227 struct progress *progress = NULL;
@@ -289,10 +289,10 @@ static int graph_write(int argc, const char **argv, const char *prefix,
289 git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
290 flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
291
292 - odb = find_odb(the_repository, opts.obj_dir);
292 + source = find_odb(the_repository, opts.obj_dir);
293
294 if (opts.reachable) {
295 - if (write_commit_graph_reachable(odb, flags, &write_opts))
295 + if (write_commit_graph_reachable(source, flags, &write_opts))
296 result = 1;
297 goto cleanup;
298 }
@@ -318,7 +318,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
318 stop_progress(&progress);
319 }
320
321 - if (write_commit_graph(odb,
321 + if (write_commit_graph(source,
322 opts.stdin_packs ? &pack_indexes : NULL,
323 opts.stdin_commits ? &commits : NULL,
324 flags,
builtin/count-objects.c
+2 -2
@@ -80,10 +80,10 @@ static int count_cruft(const char *basename UNUSED, const char *path,
80 return 0;
81 }
82
83 -static int print_alternate(struct object_directory *odb, void *data UNUSED)
83 +static int print_alternate(struct odb_source *alternate, void *data UNUSED)
84 {
85 printf("alternate: ");
86 - quote_c_style(odb->path, NULL, stdout, 0);
86 + quote_c_style(alternate->path, NULL, stdout, 0);
87 putchar('\n');
88 return 0;
89 }
builtin/fetch.c
+1 -1
@@ -2653,7 +2653,7 @@ int cmd_fetch(int argc,
2653 commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
2654
2655 trace2_region_enter("fetch", "write-commit-graph", the_repository);
2656 - write_commit_graph_reachable(the_repository->objects->odb,
2656 + write_commit_graph_reachable(the_repository->objects->sources,
2657 commit_graph_flags,
2658 NULL);
2659 trace2_region_leave("fetch", "write-commit-graph", the_repository);
builtin/fsck.c
+7 -7
@@ -956,7 +956,7 @@ int cmd_fsck(int argc,
956 struct repository *repo UNUSED)
957 {
958 int i;
959 - struct object_directory *odb;
959 + struct odb_source *source;
960
961 /* fsck knows how to handle missing promisor objects */
962 fetch_if_missing = 0;
@@ -998,8 +998,8 @@ int cmd_fsck(int argc,
998 mark_packed_for_connectivity, NULL, 0);
999 } else {
1000 prepare_alt_odb(the_repository);
1001 - for (odb = the_repository->objects->odb; odb; odb = odb->next)
1002 - fsck_object_dir(odb->path);
1001 + for (source = the_repository->objects->sources; source; source = source->next)
1002 + fsck_object_dir(source->path);
1003
1004 if (check_full) {
1005 struct packed_git *p;
@@ -1109,11 +1109,11 @@ int cmd_fsck(int argc,
1109 struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
1110
1111 prepare_alt_odb(the_repository);
1112 - for (odb = the_repository->objects->odb; odb; odb = odb->next) {
1112 + for (source = the_repository->objects->sources; source; source = source->next) {
1113 child_process_init(&commit_graph_verify);
1114 commit_graph_verify.git_cmd = 1;
1115 strvec_pushl(&commit_graph_verify.args, "commit-graph",
1116 - "verify", "--object-dir", odb->path, NULL);
1116 + "verify", "--object-dir", source->path, NULL);
1117 if (show_progress)
1118 strvec_push(&commit_graph_verify.args, "--progress");
1119 else
@@ -1127,11 +1127,11 @@ int cmd_fsck(int argc,
1127 struct child_process midx_verify = CHILD_PROCESS_INIT;
1128
1129 prepare_alt_odb(the_repository);
1130 - for (odb = the_repository->objects->odb; odb; odb = odb->next) {
1130 + for (source = the_repository->objects->sources; source; source = source->next) {
1131 child_process_init(&midx_verify);
1132 midx_verify.git_cmd = 1;
1133 strvec_pushl(&midx_verify.args, "multi-pack-index",
1134 - "verify", "--object-dir", odb->path, NULL);
1134 + "verify", "--object-dir", source->path, NULL);
1135 if (show_progress)
1136 strvec_push(&midx_verify.args, "--progress");
1137 else
builtin/gc.c
+7 -7
@@ -1018,7 +1018,7 @@ int cmd_gc(int argc,
1018 }
1019
1020 if (the_repository->settings.gc_write_commit_graph == 1)
1021 - write_commit_graph_reachable(the_repository->objects->odb,
1021 + write_commit_graph_reachable(the_repository->objects->sources,
1022 !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
1023 NULL);
1024
@@ -1271,7 +1271,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
1271 if (loose_object_auto_limit < 0)
1272 return 1;
1273
1274 - return for_each_loose_file_in_objdir(the_repository->objects->odb->path,
1274 + return for_each_loose_file_in_objdir(the_repository->objects->sources->path,
1275 loose_object_count,
1276 NULL, NULL, &count);
1277 }
@@ -1306,7 +1306,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
1306 * Do not start pack-objects process
1307 * if there are no loose objects.
1308 */
1309 - if (!for_each_loose_file_in_objdir(r->objects->odb->path,
1309 + if (!for_each_loose_file_in_objdir(r->objects->sources->path,
1310 bail_on_loose,
1311 NULL, NULL, NULL))
1312 return 0;
@@ -1318,7 +1318,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
1318 strvec_push(&pack_proc.args, "--quiet");
1319 else
1320 strvec_push(&pack_proc.args, "--no-quiet");
1321 - strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);
1321 + strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->sources->path);
1322
1323 pack_proc.in = -1;
1324
@@ -1346,7 +1346,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
1346 else if (data.batch_size > 0)
1347 data.batch_size--; /* Decrease for equality on limit. */
1348
1349 - for_each_loose_file_in_objdir(r->objects->odb->path,
1349 + for_each_loose_file_in_objdir(r->objects->sources->path,
1350 write_loose_object_to_stdin,
1351 NULL,
1352 NULL,
@@ -1611,7 +1611,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
1611 int result = 0;
1612 struct lock_file lk;
1613 struct repository *r = the_repository;
1614 - char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path);
1614 + char *lock_path = xstrfmt("%s/maintenance", r->objects->sources->path);
1615
1616 if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
1617 /*
@@ -3083,7 +3083,7 @@ static int update_background_schedule(const struct maintenance_start_opts *opts,
3083 unsigned int i;
3084 int result = 0;
3085 struct lock_file lk;
3086 - char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path);
3086 + char *lock_path = xstrfmt("%s/schedule", the_repository->objects->sources->path);
3087
3088 if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
3089 if (errno == EEXIST)
builtin/grep.c
+1 -1
@@ -505,7 +505,7 @@ static int grep_submodule(struct grep_opt *opt,
505 * lazily registered as alternates when needed (and except in an
506 * unexpected code interaction, it won't be needed).
507 */
508 - add_submodule_odb_by_path(subrepo->objects->odb->path);
508 + add_submodule_odb_by_path(subrepo->objects->sources->path);
509 obj_read_unlock();
510
511 memcpy(&subopt, opt, sizeof(subopt));
builtin/multi-pack-index.c
+2 -2
@@ -294,8 +294,8 @@ int cmd_multi_pack_index(int argc,
294
295 if (the_repository &&
296 the_repository->objects &&
297 - the_repository->objects->odb)
298 - opts.object_dir = xstrdup(the_repository->objects->odb->path);
297 + the_repository->objects->sources)
298 + opts.object_dir = xstrdup(the_repository->objects->sources->path);
299
300 argc = parse_options(argc, argv, prefix, options,
301 builtin_multi_pack_index_usage, 0);
builtin/submodule--helper.c
+3 -3
@@ -1582,7 +1582,7 @@ static const char alternate_error_advice[] = N_(
1582 );
1583
1584 static int add_possible_reference_from_superproject(
1585 - struct object_directory *odb, void *sas_cb)
1585 + struct odb_source *alt_odb, void *sas_cb)
1586 {
1587 struct submodule_alternate_setup *sas = sas_cb;
1588 size_t len;
@@ -1591,12 +1591,12 @@ static int add_possible_reference_from_superproject(
1591 * If the alternate object store is another repository, try the
1592 * standard layout with .git/(modules/<name>)+/objects
1593 */
1594 - if (strip_suffix(odb->path, "/objects", &len)) {
1594 + if (strip_suffix(alt_odb->path, "/objects", &len)) {
1595 struct repository alternate;
1596 char *sm_alternate;
1597 struct strbuf sb = STRBUF_INIT;
1598 struct strbuf err = STRBUF_INIT;
1599 - strbuf_add(&sb, odb->path, len);
1599 + strbuf_add(&sb, alt_odb->path, len);
1600
1601 if (repo_init(&alternate, sb.buf, NULL) < 0)
1602 die(_("could not get a repository handle for gitdir '%s'"),
bundle.c
+1 -1
@@ -233,7 +233,7 @@ int verify_bundle(struct repository *r,
233 .quiet = 1,
234 };
235
236 - if (!r || !r->objects || !r->objects->odb)
236 + if (!r || !r->objects || !r->objects->sources)
237 return error(_("need a repository to verify a bundle"));
238
239 for (i = 0; i < p->nr; i++) {
commit-graph.c
+47 -47
@@ -37,7 +37,7 @@ void git_test_write_commit_graph_or_die(void)
37 if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
38 flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
39
40 - if (write_commit_graph_reachable(the_repository->objects->odb,
40 + if (write_commit_graph_reachable(the_repository->objects->sources,
41 flags, NULL))
42 die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
43 }
@@ -191,21 +191,21 @@ static int commit_gen_cmp(const void *va, const void *vb)
191 return 0;
192 }
193
194 -char *get_commit_graph_filename(struct object_directory *obj_dir)
194 +char *get_commit_graph_filename(struct odb_source *source)
195 {
196 - return xstrfmt("%s/info/commit-graph", obj_dir->path);
196 + return xstrfmt("%s/info/commit-graph", source->path);
197 }
198
199 -static char *get_split_graph_filename(struct object_directory *odb,
199 +static char *get_split_graph_filename(struct odb_source *source,
200 const char *oid_hex)
201 {
202 - return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb->path,
202 + return xstrfmt("%s/info/commit-graphs/graph-%s.graph", source->path,
203 oid_hex);
204 }
205
206 -char *get_commit_graph_chain_filename(struct object_directory *odb)
206 +char *get_commit_graph_chain_filename(struct odb_source *source)
207 {
208 - return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
208 + return xstrfmt("%s/info/commit-graphs/commit-graph-chain", source->path);
209 }
210
211 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)
250
251 struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
252 int fd, struct stat *st,
253 - struct object_directory *odb)
253 + struct odb_source *source)
254 {
255 void *graph_map;
256 size_t graph_size;
@@ -269,7 +269,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
269 ret = parse_commit_graph(&r->settings, graph_map, graph_size);
270
271 if (ret)
272 - ret->odb = odb;
272 + ret->odb_source = source;
273 else
274 munmap(graph_map, graph_size);
275
@@ -487,7 +487,7 @@ free_and_return:
487
488 static struct commit_graph *load_commit_graph_one(struct repository *r,
489 const char *graph_file,
490 - struct object_directory *odb)
490 + struct odb_source *source)
491 {
492
493 struct stat st;
@@ -498,7 +498,7 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
498 if (!open_ok)
499 return NULL;
500
501 - g = load_commit_graph_one_fd_st(r, fd, &st, odb);
501 + g = load_commit_graph_one_fd_st(r, fd, &st, source);
502
503 if (g)
504 g->filename = xstrdup(graph_file);
@@ -507,10 +507,10 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
507 }
508
509 static struct commit_graph *load_commit_graph_v1(struct repository *r,
510 - struct object_directory *odb)
510 + struct odb_source *source)
511 {
512 - char *graph_name = get_commit_graph_filename(odb);
513 - struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
512 + char *graph_name = get_commit_graph_filename(source);
513 + struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
514 free(graph_name);
515
516 return g;
@@ -652,7 +652,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
652 prepare_alt_odb(r);
653
654 for (i = 0; i < count; i++) {
655 - struct object_directory *odb;
655 + struct odb_source *source;
656
657 if (strbuf_getline_lf(&line, fp) == EOF)
658 break;
@@ -665,9 +665,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
665 }
666
667 valid = 0;
668 - for (odb = r->objects->odb; odb; odb = odb->next) {
669 - char *graph_name = get_split_graph_filename(odb, line.buf);
670 - struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
668 + for (source = r->objects->sources; source; source = source->next) {
669 + char *graph_name = get_split_graph_filename(source, line.buf);
670 + struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
671
672 free(graph_name);
673
@@ -701,9 +701,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
701 }
702
703 static struct commit_graph *load_commit_graph_chain(struct repository *r,
704 - struct object_directory *odb)
704 + struct odb_source *source)
705 {
706 - char *chain_file = get_commit_graph_chain_filename(odb);
706 + char *chain_file = get_commit_graph_chain_filename(source);
707 struct stat st;
708 int fd;
709 struct commit_graph *g = NULL;
@@ -719,24 +719,24 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
719 }
720
721 struct commit_graph *read_commit_graph_one(struct repository *r,
722 - struct object_directory *odb)
722 + struct odb_source *source)
723 {
724 - struct commit_graph *g = load_commit_graph_v1(r, odb);
724 + struct commit_graph *g = load_commit_graph_v1(r, source);
725
726 if (!g)
727 - g = load_commit_graph_chain(r, odb);
727 + g = load_commit_graph_chain(r, source);
728
729 return g;
730 }
731
732 static void prepare_commit_graph_one(struct repository *r,
733 - struct object_directory *odb)
733 + struct odb_source *source)
734 {
735
736 if (r->objects->commit_graph)
737 return;
738
739 - r->objects->commit_graph = read_commit_graph_one(r, odb);
739 + r->objects->commit_graph = read_commit_graph_one(r, source);
740 }
741
742 /*
@@ -747,7 +747,7 @@ static void prepare_commit_graph_one(struct repository *r,
747 */
748 static int prepare_commit_graph(struct repository *r)
749 {
750 - struct object_directory *odb;
750 + struct odb_source *source;
751
752 /*
753 * 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)
779 return 0;
780
781 prepare_alt_odb(r);
782 - for (odb = r->objects->odb;
783 - !r->objects->commit_graph && odb;
784 - odb = odb->next)
785 - prepare_commit_graph_one(r, odb);
782 + for (source = r->objects->sources;
783 + !r->objects->commit_graph && source;
784 + source = source->next)
785 + prepare_commit_graph_one(r, source);
786 return !!r->objects->commit_graph;
787 }
788
@@ -1137,7 +1137,7 @@ struct packed_commit_list {
1137
1138 struct write_commit_graph_context {
1139 struct repository *r;
1140 - struct object_directory *odb;
1140 + struct odb_source *odb_source;
1141 char *graph_name;
1142 struct oid_array oids;
1143 struct packed_commit_list commits;
@@ -1870,7 +1870,7 @@ static int add_ref_to_set(const char *refname UNUSED,
1870 return 0;
1871 }
1872
1873 -int write_commit_graph_reachable(struct object_directory *odb,
1873 +int write_commit_graph_reachable(struct odb_source *source,
1874 enum commit_graph_write_flags flags,
1875 const struct commit_graph_opts *opts)
1876 {
@@ -1890,7 +1890,7 @@ int write_commit_graph_reachable(struct object_directory *odb,
1890
1891 stop_progress(&data.progress);
1892
1893 - result = write_commit_graph(odb, NULL, &commits,
1893 + result = write_commit_graph(source, NULL, &commits,
1894 flags, opts);
1895
1896 oidset_clear(&commits);
@@ -1906,7 +1906,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
1906 int dirlen;
1907 int ret = 0;
1908
1909 - strbuf_addf(&packname, "%s/pack/", ctx->odb->path);
1909 + strbuf_addf(&packname, "%s/pack/", ctx->odb_source->path);
1910 dirlen = packname.len;
1911 if (ctx->report_progress) {
1912 strbuf_addf(&progress_title,
@@ -2060,10 +2060,10 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2060
2061 strbuf_addf(&tmp_file,
2062 "%s/info/commit-graphs/tmp_graph_XXXXXX",
2063 - ctx->odb->path);
2063 + ctx->odb_source->path);
2064 ctx->graph_name = strbuf_detach(&tmp_file, NULL);
2065 } else {
2066 - ctx->graph_name = get_commit_graph_filename(ctx->odb);
2066 + ctx->graph_name = get_commit_graph_filename(ctx->odb_source);
2067 }
2068
2069 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)
2073 }
2074
2075 if (ctx->split) {
2076 - char *lock_name = get_commit_graph_chain_filename(ctx->odb);
2076 + char *lock_name = get_commit_graph_chain_filename(ctx->odb_source);
2077
2078 hold_lock_file_for_update_mode(&lk, lock_name,
2079 LOCK_DIE_ON_ERROR, 0444);
@@ -2161,7 +2161,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2161
2162 if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
2163 char *new_base_hash = xstrdup(oid_to_hex(&ctx->new_base_graph->oid));
2164 - char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb, new_base_hash);
2164 + char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb_source, new_base_hash);
2165
2166 free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
2167 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)
2201 }
2202 }
2203 } else {
2204 - char *graph_name = get_commit_graph_filename(ctx->odb);
2204 + char *graph_name = get_commit_graph_filename(ctx->odb_source);
2205 unlink(graph_name);
2206 free(graph_name);
2207 }
2208
2209 free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
2210 ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(hash_to_hex(file_hash));
2211 - final_graph_name = get_split_graph_filename(ctx->odb,
2211 + final_graph_name = get_split_graph_filename(ctx->odb_source,
2212 ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
2213 free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1]);
2214 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)
2259 flags != COMMIT_GRAPH_SPLIT_REPLACE) {
2260 while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
2261 (max_commits && num_commits > max_commits))) {
2262 - if (g->odb != ctx->odb)
2262 + if (g->odb_source != ctx->odb_source)
2263 break;
2264
2265 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)
2281 "should be 1 with --split=replace");
2282
2283 if (ctx->num_commit_graphs_after == 2) {
2284 - char *old_graph_name = get_commit_graph_filename(g->odb);
2284 + char *old_graph_name = get_commit_graph_filename(g->odb_source);
2285
2286 if (!strcmp(g->filename, old_graph_name) &&
2287 - g->odb != ctx->odb) {
2287 + g->odb_source != ctx->odb_source) {
2288 ctx->num_commit_graphs_after = 1;
2289 ctx->new_base_graph = NULL;
2290 }
@@ -2456,13 +2456,13 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
2456 if (ctx->opts && ctx->opts->expire_time)
2457 expire_time = ctx->opts->expire_time;
2458 if (!ctx->split) {
2459 - char *chain_file_name = get_commit_graph_chain_filename(ctx->odb);
2459 + char *chain_file_name = get_commit_graph_chain_filename(ctx->odb_source);
2460 unlink(chain_file_name);
2461 free(chain_file_name);
2462 ctx->num_commit_graphs_after = 0;
2463 }
2464
2465 - strbuf_addstr(&path, ctx->odb->path);
2465 + strbuf_addstr(&path, ctx->odb_source->path);
2466 strbuf_addstr(&path, "/info/commit-graphs");
2467 dir = opendir(path.buf);
2468
@@ -2504,7 +2504,7 @@ out:
2504 strbuf_release(&path);
2505 }
2506
2507 -int write_commit_graph(struct object_directory *odb,
2507 +int write_commit_graph(struct odb_source *source,
2508 const struct string_list *const pack_indexes,
2509 struct oidset *commits,
2510 enum commit_graph_write_flags flags,
@@ -2513,7 +2513,7 @@ int write_commit_graph(struct object_directory *odb,
2513 struct repository *r = the_repository;
2514 struct write_commit_graph_context ctx = {
2515 .r = r,
2516 - .odb = odb,
2516 + .odb_source = source,
2517 .append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0,
2518 .report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0,
2519 .split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0,
commit-graph.h
+7 -7
@@ -29,8 +29,8 @@ struct repository;
29 struct object_database;
30 struct string_list;
31
32 -char *get_commit_graph_filename(struct object_directory *odb);
33 -char *get_commit_graph_chain_filename(struct object_directory *odb);
32 +char *get_commit_graph_filename(struct odb_source *source);
33 +char *get_commit_graph_chain_filename(struct odb_source *source);
34 int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
35 int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st);
36
@@ -89,7 +89,7 @@ struct commit_graph {
89 uint32_t num_commits;
90 struct object_id oid;
91 char *filename;
92 - struct object_directory *odb;
92 + struct odb_source *odb_source;
93
94 uint32_t num_commits_in_base;
95 unsigned int read_generation_data;
@@ -115,12 +115,12 @@ struct commit_graph {
115
116 struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
117 int fd, struct stat *st,
118 - struct object_directory *odb);
118 + struct odb_source *source);
119 struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
120 int fd, struct stat *st,
121 int *incomplete_chain);
122 struct commit_graph *read_commit_graph_one(struct repository *r,
123 - struct object_directory *odb);
123 + struct odb_source *source);
124
125 struct repo_settings;
126
@@ -173,10 +173,10 @@ struct commit_graph_opts {
173 * is not compatible with the commit-graph feature, then the
174 * methods will return 0 without writing a commit-graph.
175 */
176 -int write_commit_graph_reachable(struct object_directory *odb,
176 +int write_commit_graph_reachable(struct odb_source *source,
177 enum commit_graph_write_flags flags,
178 const struct commit_graph_opts *opts);
179 -int write_commit_graph(struct object_directory *odb,
179 +int write_commit_graph(struct odb_source *source,
180 const struct string_list *pack_indexes,
181 struct oidset *commits,
182 enum commit_graph_write_flags flags,
diagnose.c
+4 -4
@@ -59,13 +59,13 @@ static void dir_file_stats_objects(const char *full_path,
59 (uintmax_t)st.st_size);
60 }
61
62 -static int dir_file_stats(struct object_directory *object_dir, void *data)
62 +static int dir_file_stats(struct odb_source *source, void *data)
63 {
64 struct strbuf *buf = data;
65
66 - strbuf_addf(buf, "Contents of %s:\n", object_dir->path);
66 + strbuf_addf(buf, "Contents of %s:\n", source->path);
67
68 - for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects,
68 + for_each_file_in_pack_dir(source->path, dir_file_stats_objects,
69 data);
70
71 return 0;
@@ -228,7 +228,7 @@ int create_diagnostics_archive(struct repository *r,
228
229 strbuf_reset(&buf);
230 strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
231 - dir_file_stats(r->objects->odb, &buf);
231 + dir_file_stats(r->objects->sources, &buf);
232 foreach_alt_odb(dir_file_stats, &buf);
233 strvec_push(&archiver_args, buf.buf);
234
http-walker.c
+1 -1
@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
543 ret = error("File %s has bad hash", hex);
544 } else if (req->rename < 0) {
545 struct strbuf buf = STRBUF_INIT;
546 - odb_loose_path(the_repository->objects->odb, &buf, &req->oid);
546 + odb_loose_path(the_repository->objects->sources, &buf, &req->oid);
547 ret = error("unable to write sha1 filename %s", buf.buf);
548 strbuf_release(&buf);
549 }
http.c
+2 -2
@@ -2662,7 +2662,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
2662 oidcpy(&freq->oid, oid);
2663 freq->localfile = -1;
2664
2665 - odb_loose_path(the_repository->objects->odb, &filename, oid);
2665 + odb_loose_path(the_repository->objects->sources, &filename, oid);
2666 strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
2667
2668 strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2814,7 +2814,7 @@ int finish_http_object_request(struct http_object_request *freq)
2814 unlink_or_warn(freq->tmpfile.buf);
2815 return -1;
2816 }
2817 - odb_loose_path(the_repository->objects->odb, &filename, &freq->oid);
2817 + odb_loose_path(the_repository->objects->sources, &filename, &freq->oid);
2818 freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
2819 strbuf_release(&filename);
2820
loose.c
+21 -21
@@ -44,36 +44,36 @@ static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *key, const
44 return 1;
45 }
46
47 -static int insert_loose_map(struct object_directory *odb,
47 +static int insert_loose_map(struct odb_source *source,
48 const struct object_id *oid,
49 const struct object_id *compat_oid)
50 {
51 - struct loose_object_map *map = odb->loose_map;
51 + struct loose_object_map *map = source->loose_map;
52 int inserted = 0;
53
54 inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
55 inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
56 if (inserted)
57 - oidtree_insert(odb->loose_objects_cache, compat_oid);
57 + oidtree_insert(source->loose_objects_cache, compat_oid);
58
59 return inserted;
60 }
61
62 -static int load_one_loose_object_map(struct repository *repo, struct object_directory *dir)
62 +static int load_one_loose_object_map(struct repository *repo, struct odb_source *source)
63 {
64 struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
65 FILE *fp;
66
67 - if (!dir->loose_map)
68 - loose_object_map_init(&dir->loose_map);
69 - if (!dir->loose_objects_cache) {
70 - ALLOC_ARRAY(dir->loose_objects_cache, 1);
71 - oidtree_init(dir->loose_objects_cache);
67 + if (!source->loose_map)
68 + loose_object_map_init(&source->loose_map);
69 + if (!source->loose_objects_cache) {
70 + ALLOC_ARRAY(source->loose_objects_cache, 1);
71 + oidtree_init(source->loose_objects_cache);
72 }
73
74 - insert_loose_map(dir, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
75 - insert_loose_map(dir, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
76 - insert_loose_map(dir, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
74 + insert_loose_map(source, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
75 + insert_loose_map(source, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
76 + insert_loose_map(source, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
77
78 repo_common_path_replace(repo, &path, "objects/loose-object-idx");
79 fp = fopen(path.buf, "rb");
@@ -93,7 +93,7 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
93 parse_oid_hex_algop(p, &compat_oid, &p, repo->compat_hash_algo) ||
94 p != buf.buf + buf.len)
95 goto err;
96 - insert_loose_map(dir, &oid, &compat_oid);
96 + insert_loose_map(source, &oid, &compat_oid);
97 }
98
99 strbuf_release(&buf);
@@ -107,15 +107,15 @@ err:
107
108 int repo_read_loose_object_map(struct repository *repo)
109 {
110 - struct object_directory *dir;
110 + struct odb_source *source;
111
112 if (!should_use_loose_object_map(repo))
113 return 0;
114
115 prepare_alt_odb(repo);
116
117 - for (dir = repo->objects->odb; dir; dir = dir->next) {
118 - if (load_one_loose_object_map(repo, dir) < 0) {
117 + for (source = repo->objects->sources; source; source = source->next) {
118 + if (load_one_loose_object_map(repo, source) < 0) {
119 return -1;
120 }
121 }
@@ -124,7 +124,7 @@ int repo_read_loose_object_map(struct repository *repo)
124
125 int repo_write_loose_object_map(struct repository *repo)
126 {
127 - kh_oid_map_t *map = repo->objects->odb->loose_map->to_compat;
127 + kh_oid_map_t *map = repo->objects->sources->loose_map->to_compat;
128 struct lock_file lock;
129 int fd;
130 khiter_t iter;
@@ -212,7 +212,7 @@ int repo_add_loose_object_map(struct repository *repo, const struct object_id *o
212 if (!should_use_loose_object_map(repo))
213 return 0;
214
215 - inserted = insert_loose_map(repo->objects->odb, oid, compat_oid);
215 + inserted = insert_loose_map(repo->objects->sources, oid, compat_oid);
216 if (inserted)
217 return write_one_object(repo, oid, compat_oid);
218 return 0;
@@ -223,12 +223,12 @@ int repo_loose_object_map_oid(struct repository *repo,
223 const struct git_hash_algo *to,
224 struct object_id *dest)
225 {
226 - struct object_directory *dir;
226 + struct odb_source *source;
227 kh_oid_map_t *map;
228 khiter_t pos;
229
230 - for (dir = repo->objects->odb; dir; dir = dir->next) {
231 - struct loose_object_map *loose_map = dir->loose_map;
230 + for (source = repo->objects->sources; source; source = source->next) {
231 + struct loose_object_map *loose_map = source->loose_map;
232 if (!loose_map)
233 continue;
234 map = (to == repo->compat_hash_algo) ?
midx.c
+3 -3
@@ -832,7 +832,7 @@ void clear_midx_file(struct repository *r)
832 {
833 struct strbuf midx = STRBUF_INIT;
834
835 - get_midx_filename(r->hash_algo, &midx, r->objects->odb->path);
835 + get_midx_filename(r->hash_algo, &midx, r->objects->sources->path);
836
837 if (r->objects && r->objects->multi_pack_index) {
838 close_midx(r->objects->multi_pack_index);
@@ -842,8 +842,8 @@ void clear_midx_file(struct repository *r)
842 if (remove_path(midx.buf))
843 die(_("failed to clear multi-pack-index at %s"), midx.buf);
844
845 - clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_BITMAP, NULL);
846 - clear_midx_files_ext(r->objects->odb->path, MIDX_EXT_REV, NULL);
845 + clear_midx_files_ext(r->objects->sources->path, MIDX_EXT_BITMAP, NULL);
846 + clear_midx_files_ext(r->objects->sources->path, MIDX_EXT_REV, NULL);
847
848 strbuf_release(&midx);
849 }
object-file.c
+40 -40
@@ -55,12 +55,12 @@ static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
55 }
56 }
57
58 -const char *odb_loose_path(struct object_directory *odb,
58 +const char *odb_loose_path(struct odb_source *source,
59 struct strbuf *buf,
60 const struct object_id *oid)
61 {
62 strbuf_reset(buf);
63 - strbuf_addstr(buf, odb->path);
63 + strbuf_addstr(buf, source->path);
64 strbuf_addch(buf, '/');
65 fill_loose_path(buf, oid);
66 return buf->buf;
@@ -88,27 +88,27 @@ int check_and_freshen_file(const char *fn, int freshen)
88 return 1;
89 }
90
91 -static int check_and_freshen_odb(struct object_directory *odb,
91 +static int check_and_freshen_odb(struct odb_source *source,
92 const struct object_id *oid,
93 int freshen)
94 {
95 static struct strbuf path = STRBUF_INIT;
96 - odb_loose_path(odb, &path, oid);
96 + odb_loose_path(source, &path, oid);
97 return check_and_freshen_file(path.buf, freshen);
98 }
99
100 static int check_and_freshen_local(const struct object_id *oid, int freshen)
101 {
102 - return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
102 + return check_and_freshen_odb(the_repository->objects->sources, oid, freshen);
103 }
104
105 static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
106 {
107 - struct object_directory *odb;
107 + struct odb_source *source;
108
109 prepare_alt_odb(the_repository);
110 - for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
111 - if (check_and_freshen_odb(odb, oid, freshen))
110 + for (source = the_repository->objects->sources->next; source; source = source->next) {
111 + if (check_and_freshen_odb(source, oid, freshen))
112 return 1;
113 }
114 return 0;
@@ -202,12 +202,12 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
202 static int stat_loose_object(struct repository *r, const struct object_id *oid,
203 struct stat *st, const char **path)
204 {
205 - struct object_directory *odb;
205 + struct odb_source *source;
206 static struct strbuf buf = STRBUF_INIT;
207
208 prepare_alt_odb(r);
209 - for (odb = r->objects->odb; odb; odb = odb->next) {
210 - *path = odb_loose_path(odb, &buf, oid);
209 + for (source = r->objects->sources; source; source = source->next) {
210 + *path = odb_loose_path(source, &buf, oid);
211 if (!lstat(*path, st))
212 return 0;
213 }
@@ -223,13 +223,13 @@ static int open_loose_object(struct repository *r,
223 const struct object_id *oid, const char **path)
224 {
225 int fd;
226 - struct object_directory *odb;
226 + struct odb_source *source;
227 int most_interesting_errno = ENOENT;
228 static struct strbuf buf = STRBUF_INIT;
229
230 prepare_alt_odb(r);
231 - for (odb = r->objects->odb; odb; odb = odb->next) {
232 - *path = odb_loose_path(odb, &buf, oid);
231 + for (source = r->objects->sources; source; source = source->next) {
232 + *path = odb_loose_path(source, &buf, oid);
233 fd = git_open(*path);
234 if (fd >= 0)
235 return fd;
@@ -244,11 +244,11 @@ static int open_loose_object(struct repository *r,
244 static int quick_has_loose(struct repository *r,
245 const struct object_id *oid)
246 {
247 - struct object_directory *odb;
247 + struct odb_source *source;
248
249 prepare_alt_odb(r);
250 - for (odb = r->objects->odb; odb; odb = odb->next) {
251 - if (oidtree_contains(odb_loose_cache(odb, oid), oid))
250 + for (source = r->objects->sources; source; source = source->next) {
251 + if (oidtree_contains(odb_loose_cache(source, oid), oid))
252 return 1;
253 }
254 return 0;
@@ -694,7 +694,7 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
694 /* Finalize a file on disk, and close it. */
695 static void close_loose_object(int fd, const char *filename)
696 {
697 - if (the_repository->objects->odb->will_destroy)
697 + if (the_repository->objects->sources->will_destroy)
698 goto out;
699
700 if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
@@ -876,7 +876,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
876 if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
877 prepare_loose_object_bulk_checkin();
878
879 - odb_loose_path(the_repository->objects->odb, &filename, oid);
879 + odb_loose_path(the_repository->objects->sources, &filename, oid);
880
881 fd = start_loose_object_common(&tmp_file, filename.buf, flags,
882 &stream, compressed, sizeof(compressed),
@@ -1023,7 +1023,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
1023 goto cleanup;
1024 }
1025
1026 - odb_loose_path(the_repository->objects->odb, &filename, oid);
1026 + odb_loose_path(the_repository->objects->sources, &filename, oid);
1027
1028 /* We finally know the object path, and create the missing dir. */
1029 dirlen = directory_size(filename.buf);
@@ -1437,11 +1437,11 @@ int for_each_loose_file_in_objdir(const char *path,
1437 int for_each_loose_object(each_loose_object_fn cb, void *data,
1438 enum for_each_object_flags flags)
1439 {
1440 - struct object_directory *odb;
1440 + struct odb_source *source;
1441
1442 prepare_alt_odb(the_repository);
1443 - for (odb = the_repository->objects->odb; odb; odb = odb->next) {
1444 - int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
1443 + for (source = the_repository->objects->sources; source; source = source->next) {
1444 + int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
1445 NULL, data);
1446 if (r)
1447 return r;
@@ -1461,43 +1461,43 @@ static int append_loose_object(const struct object_id *oid,
1461 return 0;
1462 }
1463
1464 -struct oidtree *odb_loose_cache(struct object_directory *odb,
1465 - const struct object_id *oid)
1464 +struct oidtree *odb_loose_cache(struct odb_source *source,
1465 + const struct object_id *oid)
1466 {
1467 int subdir_nr = oid->hash[0];
1468 struct strbuf buf = STRBUF_INIT;
1469 - size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
1469 + size_t word_bits = bitsizeof(source->loose_objects_subdir_seen[0]);
1470 size_t word_index = subdir_nr / word_bits;
1471 size_t mask = (size_t)1u << (subdir_nr % word_bits);
1472 uint32_t *bitmap;
1473
1474 if (subdir_nr < 0 ||
1475 - subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
1475 + subdir_nr >= bitsizeof(source->loose_objects_subdir_seen))
1476 BUG("subdir_nr out of range");
1477
1478 - bitmap = &odb->loose_objects_subdir_seen[word_index];
1478 + bitmap = &source->loose_objects_subdir_seen[word_index];
1479 if (*bitmap & mask)
1480 - return odb->loose_objects_cache;
1481 - if (!odb->loose_objects_cache) {
1482 - ALLOC_ARRAY(odb->loose_objects_cache, 1);
1483 - oidtree_init(odb->loose_objects_cache);
1480 + return source->loose_objects_cache;
1481 + if (!source->loose_objects_cache) {
1482 + ALLOC_ARRAY(source->loose_objects_cache, 1);
1483 + oidtree_init(source->loose_objects_cache);
1484 }
1485 - strbuf_addstr(&buf, odb->path);
1485 + strbuf_addstr(&buf, source->path);
1486 for_each_file_in_obj_subdir(subdir_nr, &buf,
1487 append_loose_object,
1488 NULL, NULL,
1489 - odb->loose_objects_cache);
1489 + source->loose_objects_cache);
1490 *bitmap |= mask;
1491 strbuf_release(&buf);
1492 - return odb->loose_objects_cache;
1492 + return source->loose_objects_cache;
1493 }
1494
1495 -void odb_clear_loose_cache(struct object_directory *odb)
1495 +void odb_clear_loose_cache(struct odb_source *source)
1496 {
1497 - oidtree_clear(odb->loose_objects_cache);
1498 - FREE_AND_NULL(odb->loose_objects_cache);
1499 - memset(&odb->loose_objects_subdir_seen, 0,
1500 - sizeof(odb->loose_objects_subdir_seen));
1497 + oidtree_clear(source->loose_objects_cache);
1498 + FREE_AND_NULL(source->loose_objects_cache);
1499 + memset(&source->loose_objects_subdir_seen, 0,
1500 + sizeof(source->loose_objects_subdir_seen));
1501 }
1502
1503 static int check_stream_oid(git_zstream *stream,
object-file.h
+4 -4
@@ -24,23 +24,23 @@ enum {
24 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);
25 int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);
26
27 -struct object_directory;
27 +struct odb_source;
28
29 /*
30 * Populate and return the loose object cache array corresponding to the
31 * given object ID.
32 */
33 -struct oidtree *odb_loose_cache(struct object_directory *odb,
33 +struct oidtree *odb_loose_cache(struct odb_source *source,
34 const struct object_id *oid);
35
36 /* Empty the loose object cache for the specified object directory. */
37 -void odb_clear_loose_cache(struct object_directory *odb);
37 +void odb_clear_loose_cache(struct odb_source *source);
38
39 /*
40 * Put in `buf` the name of the file in the local object database that
41 * would be used to store a loose object with the specified oid.
42 */
43 -const char *odb_loose_path(struct object_directory *odb,
43 +const char *odb_loose_path(struct odb_source *source,
44 struct strbuf *buf,
45 const struct object_id *oid);
46
object-name.c
+3 -3
@@ -112,10 +112,10 @@ static enum cb_next match_prefix(const struct object_id *oid, void *arg)
112
113 static void find_short_object_filename(struct disambiguate_state *ds)
114 {
115 - struct object_directory *odb;
115 + struct odb_source *source;
116
117 - for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next)
118 - oidtree_each(odb_loose_cache(odb, &ds->bin_pfx),
117 + for (source = ds->repo->objects->sources; source && !ds->ambiguous; source = source->next)
118 + oidtree_each(odb_loose_cache(source, &ds->bin_pfx),
119 &ds->bin_pfx, ds->len, match_prefix, ds);
120 }
121
object-store.c
+61 -61
@@ -27,7 +27,7 @@
27 #include "write-or-die.h"
28
29 KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
30 - struct object_directory *, 1, fspathhash, fspatheq)
30 + struct odb_source *, 1, fspathhash, fspatheq)
31
32 /*
33 * 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,
104 * Prevent the common mistake of listing the same
105 * thing twice, or object directory itself.
106 */
107 - if (!o->odb_by_path) {
107 + if (!o->source_by_path) {
108 khiter_t p;
109
110 - o->odb_by_path = kh_init_odb_path_map();
111 - assert(!o->odb->next);
112 - p = kh_put_odb_path_map(o->odb_by_path, o->odb->path, &r);
110 + o->source_by_path = kh_init_odb_path_map();
111 + assert(!o->sources->next);
112 + p = kh_put_odb_path_map(o->source_by_path, o->sources->path, &r);
113 assert(r == 1); /* never used */
114 - kh_value(o->odb_by_path, p) = o->odb;
114 + kh_value(o->source_by_path, p) = o->sources;
115 }
116 if (fspatheq(path->buf, normalized_objdir))
117 return 0;
118 - *pos = kh_put_odb_path_map(o->odb_by_path, path->buf, &r);
118 + *pos = kh_put_odb_path_map(o->source_by_path, path->buf, &r);
119 /* r: 0 = exists, 1 = never used, 2 = deleted */
120 return r == 0 ? 0 : 1;
121 }
@@ -124,7 +124,7 @@ static int alt_odb_usable(struct object_database *o,
124 * Prepare alternate object database registry.
125 *
126 * The variable alt_odb_list points at the list of struct
127 - * object_directory. The elements on this list come from
127 + * odb_source. The elements on this list come from
128 * non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT
129 * environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates,
130 * whose contents is similar to that environment variable but can be
@@ -141,7 +141,7 @@ static void read_info_alternates(struct repository *r,
141 static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
142 const char *relative_base, int depth, const char *normalized_objdir)
143 {
144 - struct object_directory *ent;
144 + struct odb_source *alternate;
145 struct strbuf pathbuf = STRBUF_INIT;
146 struct strbuf tmp = STRBUF_INIT;
147 khiter_t pos;
@@ -170,19 +170,19 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry,
170 if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos))
171 goto error;
172
173 - CALLOC_ARRAY(ent, 1);
174 - /* pathbuf.buf is already in r->objects->odb_by_path */
175 - ent->path = strbuf_detach(&pathbuf, NULL);
173 + CALLOC_ARRAY(alternate, 1);
174 + /* pathbuf.buf is already in r->objects->source_by_path */
175 + alternate->path = strbuf_detach(&pathbuf, NULL);
176
177 /* add the alternate entry */
178 - *r->objects->odb_tail = ent;
179 - r->objects->odb_tail = &(ent->next);
180 - ent->next = NULL;
181 - assert(r->objects->odb_by_path);
182 - kh_value(r->objects->odb_by_path, pos) = ent;
178 + *r->objects->sources_tail = alternate;
179 + r->objects->sources_tail = &(alternate->next);
180 + alternate->next = NULL;
181 + assert(r->objects->source_by_path);
182 + kh_value(r->objects->source_by_path, pos) = alternate;
183
184 /* recursively add alternates */
185 - read_info_alternates(r, ent->path, depth + 1);
185 + read_info_alternates(r, alternate->path, depth + 1);
186 ret = 0;
187 error:
188 strbuf_release(&tmp);
@@ -234,7 +234,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt,
234 return;
235 }
236
237 - strbuf_realpath(&objdirbuf, r->objects->odb->path, 1);
237 + strbuf_realpath(&objdirbuf, r->objects->sources->path, 1);
238
239 while (*alt) {
240 alt = parse_alt_odb_entry(alt, sep, &entry);
@@ -321,9 +321,9 @@ void add_to_alternates_memory(const char *reference)
321 '\n', NULL, 0);
322 }
323
324 -struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy)
324 +struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy)
325 {
326 - struct object_directory *new_odb;
326 + struct odb_source *source;
327
328 /*
329 * 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
335 * Make a new primary odb and link the old primary ODB in as an
336 * alternate
337 */
338 - new_odb = xcalloc(1, sizeof(*new_odb));
339 - new_odb->path = xstrdup(dir);
338 + source = xcalloc(1, sizeof(*source));
339 + source->path = xstrdup(dir);
340
341 /*
342 * Disable ref updates while a temporary odb is active, since
343 * the objects in the database may roll back.
344 */
345 - new_odb->disable_ref_updates = 1;
346 - new_odb->will_destroy = will_destroy;
347 - new_odb->next = the_repository->objects->odb;
348 - the_repository->objects->odb = new_odb;
349 - return new_odb->next;
345 + source->disable_ref_updates = 1;
346 + source->will_destroy = will_destroy;
347 + source->next = the_repository->objects->sources;
348 + the_repository->objects->sources = source;
349 + return source->next;
350 }
351
352 -static void free_object_directory(struct object_directory *odb)
352 +static void free_object_directory(struct odb_source *source)
353 {
354 - free(odb->path);
355 - odb_clear_loose_cache(odb);
356 - loose_object_map_clear(&odb->loose_map);
357 - free(odb);
354 + free(source->path);
355 + odb_clear_loose_cache(source);
356 + loose_object_map_clear(&source->loose_map);
357 + free(source);
358 }
359
360 -void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
360 +void restore_primary_odb(struct odb_source *restore_alt, const char *old_path)
361 {
362 - struct object_directory *cur_odb = the_repository->objects->odb;
362 + struct odb_source *cur_alt = the_repository->objects->sources;
363
364 - if (strcmp(old_path, cur_odb->path))
364 + if (strcmp(old_path, cur_alt->path))
365 BUG("expected %s as primary object store; found %s",
366 - old_path, cur_odb->path);
366 + old_path, cur_alt->path);
367
368 - if (cur_odb->next != restore_odb)
368 + if (cur_alt->next != restore_alt)
369 BUG("we expect the old primary object store to be the first alternate");
370
371 - the_repository->objects->odb = restore_odb;
372 - free_object_directory(cur_odb);
371 + the_repository->objects->sources = restore_alt;
372 + free_object_directory(cur_alt);
373 }
374
375 /*
@@ -442,15 +442,15 @@ out:
442 return ref_git;
443 }
444
445 -struct object_directory *find_odb(struct repository *r, const char *obj_dir)
445 +struct odb_source *find_odb(struct repository *r, const char *obj_dir)
446 {
447 - struct object_directory *odb;
447 + struct odb_source *source;
448 char *obj_dir_real = real_pathdup(obj_dir, 1);
449 struct strbuf odb_path_real = STRBUF_INIT;
450
451 prepare_alt_odb(r);
452 - for (odb = r->objects->odb; odb; odb = odb->next) {
453 - strbuf_realpath(&odb_path_real, odb->path, 1);
452 + for (source = r->objects->sources; source; source = source->next) {
453 + strbuf_realpath(&odb_path_real, source->path, 1);
454 if (!strcmp(obj_dir_real, odb_path_real.buf))
455 break;
456 }
@@ -458,9 +458,9 @@ struct object_directory *find_odb(struct repository *r, const char *obj_dir)
458 free(obj_dir_real);
459 strbuf_release(&odb_path_real);
460
461 - if (!odb)
461 + if (!source)
462 die(_("could not find object directory matching %s"), obj_dir);
463 - return odb;
463 + return source;
464 }
465
466 static void fill_alternate_refs_command(struct child_process *cmd,
@@ -527,14 +527,14 @@ struct alternate_refs_data {
527 void *data;
528 };
529
530 -static int refs_from_alternate_cb(struct object_directory *e,
530 +static int refs_from_alternate_cb(struct odb_source *alternate,
531 void *data)
532 {
533 struct strbuf path = STRBUF_INIT;
534 size_t base_len;
535 struct alternate_refs_data *cb = data;
536
537 - if (!strbuf_realpath(&path, e->path, 0))
537 + if (!strbuf_realpath(&path, alternate->path, 0))
538 goto out;
539 if (!strbuf_strip_suffix(&path, "/objects"))
540 goto out;
@@ -563,12 +563,12 @@ void for_each_alternate_ref(alternate_ref_fn fn, void *data)
563
564 int foreach_alt_odb(alt_odb_fn fn, void *cb)
565 {
566 - struct object_directory *ent;
566 + struct odb_source *alternate;
567 int r = 0;
568
569 prepare_alt_odb(the_repository);
570 - for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {
571 - r = fn(ent, cb);
570 + for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {
571 + r = fn(alternate, cb);
572 if (r)
573 break;
574 }
@@ -582,14 +582,14 @@ void prepare_alt_odb(struct repository *r)
582
583 link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
584
585 - read_info_alternates(r, r->objects->odb->path, 0);
585 + read_info_alternates(r, r->objects->sources->path, 0);
586 r->objects->loaded_alternates = 1;
587 }
588
589 int has_alt_odb(struct repository *r)
590 {
591 prepare_alt_odb(r);
592 - return !!r->objects->odb->next;
592 + return !!r->objects->sources->next;
593 }
594
595 int obj_read_use_lock = 0;
@@ -963,15 +963,15 @@ struct object_database *odb_new(void)
963
964 static void free_object_directories(struct object_database *o)
965 {
966 - while (o->odb) {
967 - struct object_directory *next;
966 + while (o->sources) {
967 + struct odb_source *next;
968
969 - next = o->odb->next;
970 - free_object_directory(o->odb);
971 - o->odb = next;
969 + next = o->sources->next;
970 + free_object_directory(o->sources);
971 + o->sources = next;
972 }
973 - kh_destroy_odb_path_map(o->odb_by_path);
974 - o->odb_by_path = NULL;
973 + kh_destroy_odb_path_map(o->source_by_path);
974 + o->source_by_path = NULL;
975 }
976
977 void odb_clear(struct object_database *o)
@@ -986,7 +986,7 @@ void odb_clear(struct object_database *o)
986 o->commit_graph_attempted = 0;
987
988 free_object_directories(o);
989 - o->odb_tail = NULL;
989 + o->sources_tail = NULL;
990 o->loaded_alternates = 0;
991
992 for (size_t i = 0; i < o->cached_object_nr; i++)
object-store.h
+25 -13
@@ -13,8 +13,20 @@ struct oidtree;
13 struct strbuf;
14 struct repository;
15
16 -struct object_directory {
17 - struct object_directory *next;
16 +/*
17 + * The source is the part of the object database that stores the actual
18 + * objects. It thus encapsulates the logic to read and write the specific
19 + * on-disk format. An object database can have multiple sources:
20 + *
21 + * - The primary source, which is typically located in "$GIT_DIR/objects".
22 + * This is where new objects are usually written to.
23 + *
24 + * - Alternate sources, which are configured via "objects/info/alternates" or
25 + * via the GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable. These
26 + * alternate sources are only used to read objects.
27 + */
28 +struct odb_source {
29 + struct odb_source *next;
30
31 /*
32 * Used to store the results of readdir(3) calls when we are OK
@@ -44,8 +56,8 @@ struct object_directory {
56 int will_destroy;
57
58 /*
47 - * Path to the alternative object store. If this is a relative path,
48 - * it is relative to the current working directory.
59 + * Path to the source. If this is a relative path, it is relative to
60 + * the current working directory.
61 */
62 char *path;
63 };
@@ -53,8 +65,8 @@ struct object_directory {
65 void prepare_alt_odb(struct repository *r);
66 int has_alt_odb(struct repository *r);
67 char *compute_alternate_path(const char *path, struct strbuf *err);
56 -struct object_directory *find_odb(struct repository *r, const char *obj_dir);
57 -typedef int alt_odb_fn(struct object_directory *, void *);
68 +struct odb_source *find_odb(struct repository *r, const char *obj_dir);
69 +typedef int alt_odb_fn(struct odb_source *, void *);
70 int foreach_alt_odb(alt_odb_fn, void*);
71 typedef void alternate_ref_fn(const struct object_id *oid, void *);
72 void for_each_alternate_ref(alternate_ref_fn, void *);
@@ -76,12 +88,12 @@ void add_to_alternates_memory(const char *dir);
88 * Replace the current writable object directory with the specified temporary
89 * object directory; returns the former primary object directory.
90 */
79 -struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
91 +struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy);
92
93 /*
94 * Restore a previous ODB replaced by set_temporary_main_odb.
95 */
84 -void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
96 +void restore_primary_odb(struct odb_source *restore_alternate, const char *old_path);
97
98 struct packed_git;
99 struct multi_pack_index;
@@ -89,7 +101,7 @@ struct cached_object_entry;
101
102 /*
103 * The object database encapsulates access to objects in a repository. It
92 - * manages one or more backends that store the actual objects which are
104 + * manages one or more sources that store the actual objects which are
105 * configured via alternates.
106 */
107 struct object_database {
@@ -98,16 +110,16 @@ struct object_database {
110 * cannot be NULL after initialization). Subsequent directories are
111 * alternates.
112 */
101 - struct object_directory *odb;
102 - struct object_directory **odb_tail;
103 - struct kh_odb_path_map *odb_by_path;
113 + struct odb_source *sources;
114 + struct odb_source **sources_tail;
115 + struct kh_odb_path_map *source_by_path;
116
117 int loaded_alternates;
118
119 /*
120 * A list of alternate object directories loaded from the environment;
121 * this should not generally need to be accessed directly, but will
110 - * populate the "odb" list when prepare_alt_odb() is run.
122 + * populate the "sources" list when prepare_alt_odb() is run.
123 */
124 char *alternate_db;
125
packfile.c
+8 -8
@@ -1029,16 +1029,16 @@ static void prepare_packed_git_mru(struct repository *r)
1029
1030 static void prepare_packed_git(struct repository *r)
1031 {
1032 - struct object_directory *odb;
1032 + struct odb_source *source;
1033
1034 if (r->objects->packed_git_initialized)
1035 return;
1036
1037 prepare_alt_odb(r);
1038 - for (odb = r->objects->odb; odb; odb = odb->next) {
1039 - int local = (odb == r->objects->odb);
1040 - prepare_multi_pack_index_one(r, odb->path, local);
1041 - prepare_packed_git_one(r, odb->path, local);
1038 + for (source = r->objects->sources; source; source = source->next) {
1039 + int local = (source == r->objects->sources);
1040 + prepare_multi_pack_index_one(r, source->path, local);
1041 + prepare_packed_git_one(r, source->path, local);
1042 }
1043 rearrange_packed_git(r);
1044
@@ -1048,7 +1048,7 @@ static void prepare_packed_git(struct repository *r)
1048
1049 void reprepare_packed_git(struct repository *r)
1050 {
1051 - struct object_directory *odb;
1051 + struct odb_source *source;
1052
1053 obj_read_lock();
1054
@@ -1061,8 +1061,8 @@ void reprepare_packed_git(struct repository *r)
1061 r->objects->loaded_alternates = 0;
1062 prepare_alt_odb(r);
1063
1064 - for (odb = r->objects->odb; odb; odb = odb->next)
1065 - odb_clear_loose_cache(odb);
1064 + for (source = r->objects->sources; source; source = source->next)
1065 + odb_clear_loose_cache(source);
1066
1067 r->objects->approximate_object_count_valid = 0;
1068 r->objects->packed_git_initialized = 0;
path.c
+1 -1
@@ -397,7 +397,7 @@ static void adjust_git_path(struct repository *repo,
397 strbuf_splice(buf, 0, buf->len,
398 repo->index_file, strlen(repo->index_file));
399 else if (dir_prefix(base, "objects"))
400 - replace_dir(buf, git_dir_len + 7, repo->objects->odb->path);
400 + replace_dir(buf, git_dir_len + 7, repo->objects->sources->path);
401 else if (repo_settings_get_hooks_path(repo) && dir_prefix(base, "hooks"))
402 replace_dir(buf, git_dir_len + 5, repo_settings_get_hooks_path(repo));
403 else if (repo->different_commondir)
refs.c
+1 -1
@@ -2477,7 +2477,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
2477 break;
2478 }
2479
2480 - if (refs->repo->objects->odb->disable_ref_updates) {
2480 + if (refs->repo->objects->sources->disable_ref_updates) {
2481 strbuf_addstr(err,
2482 _("ref updates forbidden inside quarantine environment"));
2483 return -1;
repository.c
+7 -7
@@ -107,9 +107,9 @@ const char *repo_get_common_dir(struct repository *repo)
107
108 const char *repo_get_object_directory(struct repository *repo)
109 {
110 - if (!repo->objects->odb)
110 + if (!repo->objects->sources)
111 BUG("repository hasn't been set up");
112 - return repo->objects->odb->path;
112 + return repo->objects->sources->path;
113 }
114
115 const char *repo_get_index_file(struct repository *repo)
@@ -165,14 +165,14 @@ void repo_set_gitdir(struct repository *repo,
165
166 repo_set_commondir(repo, o->commondir);
167
168 - if (!repo->objects->odb) {
169 - CALLOC_ARRAY(repo->objects->odb, 1);
170 - repo->objects->odb_tail = &repo->objects->odb->next;
168 + if (!repo->objects->sources) {
169 + CALLOC_ARRAY(repo->objects->sources, 1);
170 + repo->objects->sources_tail = &repo->objects->sources->next;
171 }
172 - expand_base_dir(&repo->objects->odb->path, o->object_dir,
172 + expand_base_dir(&repo->objects->sources->path, o->object_dir,
173 repo->commondir, "objects");
174
175 - repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
175 + repo->objects->sources->disable_ref_updates = o->disable_ref_updates;
176
177 free(repo->objects->alternate_db);
178 repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
submodule-config.c
+1 -1
@@ -810,7 +810,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
810 repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
811 config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
812 if (repo != the_repository)
813 - add_submodule_odb_by_path(repo->objects->odb->path);
813 + add_submodule_odb_by_path(repo->objects->sources->path);
814 } else {
815 goto out;
816 }
t/helper/test-read-graph.c
+3 -3
@@ -73,15 +73,15 @@ static void dump_graph_bloom_filters(struct commit_graph *graph)
73 int cmd__read_graph(int argc, const char **argv)
74 {
75 struct commit_graph *graph = NULL;
76 - struct object_directory *odb;
76 + struct odb_source *source;
77 int ret = 0;
78
79 setup_git_directory();
80 - odb = the_repository->objects->odb;
80 + source = the_repository->objects->sources;
81
82 prepare_repo_settings(the_repository);
83
84 - graph = read_commit_graph_one(the_repository, odb);
84 + graph = read_commit_graph_one(the_repository, source);
85 if (!graph) {
86 ret = 1;
87 goto done;
tmp-objdir.c
+12 -12
@@ -17,7 +17,7 @@ struct tmp_objdir {
17 struct repository *repo;
18 struct strbuf path;
19 struct strvec env;
20 - struct object_directory *prev_odb;
20 + struct odb_source *prev_source;
21 int will_destroy;
22 };
23
@@ -46,8 +46,8 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
46 if (t == the_tmp_objdir)
47 the_tmp_objdir = NULL;
48
49 - if (t->prev_odb)
50 - restore_primary_odb(t->prev_odb, t->path.buf);
49 + if (t->prev_source)
50 + restore_primary_odb(t->prev_source, t->path.buf);
51
52 err = remove_dir_recursively(&t->path, 0);
53
@@ -276,11 +276,11 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
276 if (!t)
277 return 0;
278
279 - if (t->prev_odb) {
280 - if (t->repo->objects->odb->will_destroy)
279 + if (t->prev_source) {
280 + if (t->repo->objects->sources->will_destroy)
281 BUG("migrating an ODB that was marked for destruction");
282 - restore_primary_odb(t->prev_odb, t->path.buf);
283 - t->prev_odb = NULL;
282 + restore_primary_odb(t->prev_source, t->path.buf);
283 + t->prev_source = NULL;
284 }
285
286 strbuf_addbuf(&src, &t->path);
@@ -309,19 +309,19 @@ void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
309
310 void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
311 {
312 - if (t->prev_odb)
312 + if (t->prev_source)
313 BUG("the primary object database is already replaced");
314 - t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
314 + t->prev_source = set_temporary_primary_odb(t->path.buf, will_destroy);
315 t->will_destroy = will_destroy;
316 }
317
318 struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
319 {
320 - if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
320 + if (!the_tmp_objdir || !the_tmp_objdir->prev_source)
321 return NULL;
322
323 - restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
324 - the_tmp_objdir->prev_odb = NULL;
323 + restore_primary_odb(the_tmp_objdir->prev_source, the_tmp_objdir->path.buf);
324 + the_tmp_objdir->prev_source = NULL;
325 return the_tmp_objdir;
326 }
327