Skip to content

Commit f7e7ddc

Browse files
committed
Merge branch 'ps/object-store-midx-dedup-info' into seen
* ps/object-store-midx-dedup-info: midx: compute paths via their source midx: stop duplicating info redundant with its owning source midx: write multi-pack indices via their source midx: load multi-pack indices via their source midx: drop redundant `struct repository` parameter odb: return newly created in-memory sources odb: allow `odb_find_source()` to fail odb: store locality in object database sources
2 parents b0d7a56 + c00c0a6 commit f7e7ddc

15 files changed

+242
-234
lines changed

builtin/commit-graph.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
103103
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
104104

105105
source = odb_find_source(the_repository->objects, opts.obj_dir);
106+
if (!source)
107+
die(_("could not find object directory matching %s"), opts.obj_dir);
106108
graph_name = get_commit_graph_filename(source);
107109
chain_name = get_commit_graph_chain_filename(source);
108110
if (open_commit_graph(graph_name, &fd, &st))
@@ -291,6 +293,8 @@ static int graph_write(int argc, const char **argv, const char *prefix,
291293
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
292294

293295
source = odb_find_source(the_repository->objects, opts.obj_dir);
296+
if (!source)
297+
die(_("could not find object directory matching %s"), opts.obj_dir);
294298

295299
if (opts.reachable) {
296300
if (write_commit_graph_reachable(source, flags, &write_opts))

builtin/multi-pack-index.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,20 @@ static int parse_object_dir(const struct option *opt, const char *arg,
6565
char **value = opt->value;
6666
free(*value);
6767
if (unset)
68-
*value = xstrdup(repo_get_object_directory(the_repository));
68+
*value = xstrdup(the_repository->objects->sources->path);
6969
else
7070
*value = real_pathdup(arg, 1);
7171
return 0;
7272
}
7373

74+
static struct odb_source *handle_object_dir_option(struct repository *repo)
75+
{
76+
struct odb_source *source = odb_find_source(repo->objects, opts.object_dir);
77+
if (!source)
78+
source = odb_add_to_alternates_memory(repo->objects, opts.object_dir);
79+
return source;
80+
}
81+
7482
static struct option common_opts[] = {
7583
OPT_CALLBACK(0, "object-dir", &opts.object_dir,
7684
N_("directory"),
@@ -140,6 +148,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
140148
N_("refs snapshot for selecting bitmap commits")),
141149
OPT_END(),
142150
};
151+
struct odb_source *source;
143152
int ret;
144153

145154
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
@@ -158,6 +167,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
158167
if (argc)
159168
usage_with_options(builtin_multi_pack_index_write_usage,
160169
options);
170+
source = handle_object_dir_option(repo);
161171

162172
FREE_AND_NULL(options);
163173

@@ -166,7 +176,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
166176

167177
read_packs_from_stdin(&packs);
168178

169-
ret = write_midx_file_only(repo, opts.object_dir, &packs,
179+
ret = write_midx_file_only(source, &packs,
170180
opts.preferred_pack,
171181
opts.refs_snapshot, opts.flags);
172182

@@ -177,7 +187,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
177187

178188
}
179189

180-
ret = write_midx_file(repo, opts.object_dir, opts.preferred_pack,
190+
ret = write_midx_file(source, opts.preferred_pack,
181191
opts.refs_snapshot, opts.flags);
182192

183193
free(opts.refs_snapshot);
@@ -194,6 +204,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
194204
N_("force progress reporting"), MIDX_PROGRESS),
195205
OPT_END(),
196206
};
207+
struct odb_source *source;
208+
197209
options = add_common_options(builtin_multi_pack_index_verify_options);
198210

199211
trace2_cmd_mode(argv[0]);
@@ -206,10 +218,11 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
206218
if (argc)
207219
usage_with_options(builtin_multi_pack_index_verify_usage,
208220
options);
221+
source = handle_object_dir_option(the_repository);
209222

210223
FREE_AND_NULL(options);
211224

212-
return verify_midx_file(the_repository, opts.object_dir, opts.flags);
225+
return verify_midx_file(source, opts.flags);
213226
}
214227

215228
static int cmd_multi_pack_index_expire(int argc, const char **argv,
@@ -222,6 +235,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
222235
N_("force progress reporting"), MIDX_PROGRESS),
223236
OPT_END(),
224237
};
238+
struct odb_source *source;
239+
225240
options = add_common_options(builtin_multi_pack_index_expire_options);
226241

227242
trace2_cmd_mode(argv[0]);
@@ -234,10 +249,11 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
234249
if (argc)
235250
usage_with_options(builtin_multi_pack_index_expire_usage,
236251
options);
252+
source = handle_object_dir_option(the_repository);
237253

238254
FREE_AND_NULL(options);
239255

240-
return expire_midx_packs(the_repository, opts.object_dir, opts.flags);
256+
return expire_midx_packs(source, opts.flags);
241257
}
242258

243259
static int cmd_multi_pack_index_repack(int argc, const char **argv,
@@ -252,6 +268,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
252268
N_("force progress reporting"), MIDX_PROGRESS),
253269
OPT_END(),
254270
};
271+
struct odb_source *source;
255272

256273
options = add_common_options(builtin_multi_pack_index_repack_options);
257274

@@ -266,11 +283,11 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
266283
if (argc)
267284
usage_with_options(builtin_multi_pack_index_repack_usage,
268285
options);
286+
source = handle_object_dir_option(the_repository);
269287

270288
FREE_AND_NULL(options);
271289

272-
return midx_repack(the_repository, opts.object_dir,
273-
(size_t)opts.batch_size, opts.flags);
290+
return midx_repack(source, (size_t)opts.batch_size, opts.flags);
274291
}
275292

276293
int cmd_multi_pack_index(int argc,

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17411741
struct multi_pack_index *m = get_multi_pack_index(source);
17421742
struct pack_entry e;
17431743

1744-
if (m && fill_midx_entry(the_repository, oid, &e, m)) {
1744+
if (m && fill_midx_entry(m, oid, &e)) {
17451745
want = want_object_in_pack_one(e.p, oid, exclude, found_pack, found_offset, found_mtime);
17461746
if (want != -1)
17471747
return want;

builtin/repack.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ static void mark_packs_for_deletion(struct existing_packs *existing,
223223
static void remove_redundant_pack(const char *dir_name, const char *base_name)
224224
{
225225
struct strbuf buf = STRBUF_INIT;
226-
struct multi_pack_index *m = get_multi_pack_index(the_repository->objects->sources);
226+
struct odb_source *source = the_repository->objects->sources;
227+
struct multi_pack_index *m = get_multi_pack_index(source);
227228
strbuf_addf(&buf, "%s.pack", base_name);
228-
if (m && m->local && midx_contains_pack(m, buf.buf))
229+
if (m && source->local && midx_contains_pack(m, buf.buf))
229230
clear_midx_file(the_repository);
230231
strbuf_insertf(&buf, 0, "%s/", dir_name);
231232
unlink_pack_path(buf.buf, 1);
@@ -1711,7 +1712,7 @@ int cmd_repack(int argc,
17111712
unsigned flags = 0;
17121713
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0))
17131714
flags |= MIDX_WRITE_INCREMENTAL;
1714-
write_midx_file(the_repository, repo_get_object_directory(the_repository),
1715+
write_midx_file(the_repository->objects->sources,
17151716
NULL, NULL, flags);
17161717
}
17171718

0 commit comments

Comments
 (0)