commit-graph: require resolved packfile paths for stdin_packs

Users can ask git-commit-graph(1) to write a commit graph specifically
for a set of packfiles via the "--stdin-packs" option. Those users are
expected to pass in relative paths, and those eventually get resolved in
`fill_oids_from_packs()`. This ties the logic in "commit-graph.c" to the
specific object database source, as the subsystem now needs to assume
where a specific packfile is located relative to the source itself.

Refactor the logic to instead require the caller to pass in resolved
packfiles to untangle that dependency. This also makes the next change
easier to implement, where we'll get rid of passing the source to the
commit-graph subsystem.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt authored and Junio C Hamano committed 2026-10-08 07:31:18 -07:00
1 parent c46c1e3772
commit 778d260c31
2 files changed
+19 -13

No files matched your search

+14 -3
View File
@@ -8,6 +8,7 @@
#include "parse-options.h"
#include "commit-graph.h"
#include "odb.h"
#include "odb/source.h"
#include "progress.h"
#include "replace-object.h"
#include "strbuf.h"
@@ -302,9 +303,19 @@ static int graph_write(int argc, const char **argv, const char *prefix,
}
if (opts.stdin_packs) {
while (strbuf_getline(&buf, stdin) != EOF)
string_list_append_nodup(&pack_indexes,
strbuf_detach(&buf, NULL));
struct strbuf packname = STRBUF_INIT;
size_t dirlen;
strbuf_addf(&packname, "%s/pack/", source->path);
dirlen = packname.len;
while (strbuf_getline(&buf, stdin) != EOF) {
strbuf_setlen(&packname, dirlen);
strbuf_addbuf(&packname, &buf);
string_list_append(&pack_indexes, packname.buf);
}
strbuf_release(&packname);
} else if (opts.stdin_commits) {
oidset_init(&commits, 0);
if (opts.progress)
+5 -10
View File
@@ -1936,12 +1936,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
{
uint32_t i;
struct strbuf progress_title = STRBUF_INIT;
struct strbuf packname = STRBUF_INIT;
int dirlen;
int ret = 0;
strbuf_addf(&packname, "%s/pack/", ctx->odb_source->path);
dirlen = packname.len;
if (ctx->report_progress) {
strbuf_addf(&progress_title,
Q_("Finding commits for commit graph in %"PRIuMAX" pack",
@@ -1954,15 +1950,15 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
}
for (i = 0; i < pack_indexes->nr; i++) {
struct packed_git *p;
strbuf_setlen(&packname, dirlen);
strbuf_addstr(&packname, pack_indexes->items[i].string);
p = add_packed_git(ctx->r, packname.buf, packname.len, 1);
p = add_packed_git(ctx->r, pack_indexes->items[i].string,
strlen(pack_indexes->items[i].string), 1);
if (!p) {
ret = error(_("error adding pack %s"), packname.buf);
ret = error(_("error adding pack %s"), pack_indexes->items[i].string);
goto cleanup;
}
if (open_pack_index(p)) {
ret = error(_("error opening index for %s"), packname.buf);
ret = error(_("error opening index for %s"), pack_indexes->items[i].string);
close_pack(p);
free(p);
goto cleanup;
@@ -1976,7 +1972,6 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
cleanup:
stop_progress(&ctx->progress);
strbuf_release(&progress_title);
strbuf_release(&packname);
return ret;
}