summaryrefslogtreecommitdiff
path: root/commit-graph.c
diff options
context:
space:
mode:
authorLibravatar Taylor Blau <me@ttaylorr.com>2020-04-13 22:04:25 -0600
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-04-15 09:20:30 -0700
commit6830c360777468434184f60023e2562348c9dacc (patch)
tree1cf8125fb2e1d96f34115fee5aebae075a7ab414 /commit-graph.c
parentoidset: introduce 'oidset_size' (diff)
downloadtgif-6830c360777468434184f60023e2562348c9dacc.tar.xz
commit-graph.h: replace 'commit_hex' with 'commits'
The 'write_commit_graph()' function takes in either a string list of pack indices, or a string list of hexadecimal commit OIDs. These correspond to the '--stdin-packs' and '--stdin-commits' mode(s) from 'git commit-graph write'. Using a string_list of hexadecimal commit IDs is not the most efficient use of memory, since we can instead use the 'struct oidset', which is more well-suited for this case. This has another benefit which will become apparent in the following commit. This is that we are about to disambiguate the kinds of errors we produce with '--stdin-commits' into "non-hex input" and "hex-input, but referring to a non-commit object". By having 'write_commit_graph' take in a 'struct oidset *' of commits, we place the burden on the caller (in this case, the builtin) to handle the first case, and the commit-graph machinery can handle the second case. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 36e1d6f9b3..bf86e4a92b 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1136,13 +1136,13 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
stop_progress(&ctx->progress);
}
-static int add_ref_to_list(const char *refname,
- const struct object_id *oid,
- int flags, void *cb_data)
+static int add_ref_to_set(const char *refname,
+ const struct object_id *oid,
+ int flags, void *cb_data)
{
- struct string_list *list = (struct string_list *)cb_data;
+ struct oidset *commits = (struct oidset *)cb_data;
- string_list_append(list, oid_to_hex(oid));
+ oidset_insert(commits, oid);
return 0;
}
@@ -1150,14 +1150,14 @@ int write_commit_graph_reachable(struct object_directory *odb,
enum commit_graph_write_flags flags,
const struct split_commit_graph_opts *split_opts)
{
- struct string_list list = STRING_LIST_INIT_DUP;
+ struct oidset commits = OIDSET_INIT;
int result;
- for_each_ref(add_ref_to_list, &list);
- result = write_commit_graph(odb, NULL, &list,
+ for_each_ref(add_ref_to_set, &commits);
+ result = write_commit_graph(odb, NULL, &commits,
flags, split_opts);
- string_list_clear(&list, 0);
+ oidset_clear(&commits);
return result;
}
@@ -1206,39 +1206,46 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
return 0;
}
-static int fill_oids_from_commit_hex(struct write_commit_graph_context *ctx,
- struct string_list *commit_hex)
+static int fill_oids_from_commits(struct write_commit_graph_context *ctx,
+ struct oidset *commits)
{
- uint32_t i;
+ uint32_t i = 0;
struct strbuf progress_title = STRBUF_INIT;
+ struct oidset_iter iter;
+ struct object_id *oid;
+
+ if (!oidset_size(commits))
+ return 0;
if (ctx->report_progress) {
strbuf_addf(&progress_title,
Q_("Finding commits for commit graph from %d ref",
"Finding commits for commit graph from %d refs",
- commit_hex->nr),
- commit_hex->nr);
+ oidset_size(commits)),
+ oidset_size(commits));
ctx->progress = start_delayed_progress(
progress_title.buf,
- commit_hex->nr);
+ oidset_size(commits));
}
- for (i = 0; i < commit_hex->nr; i++) {
- const char *end;
- struct object_id oid;
+
+ oidset_iter_init(commits, &iter);
+ while ((oid = oidset_iter_next(&iter))) {
struct commit *result;
- display_progress(ctx->progress, i + 1);
- if (!parse_oid_hex(commit_hex->items[i].string, &oid, &end) &&
- (result = lookup_commit_reference_gently(ctx->r, &oid, 1))) {
+ display_progress(ctx->progress, ++i);
+
+ result = lookup_commit_reference_gently(ctx->r, oid, 1);
+ if (result) {
ALLOC_GROW(ctx->oids.list, ctx->oids.nr + 1, ctx->oids.alloc);
oidcpy(&ctx->oids.list[ctx->oids.nr], &(result->object.oid));
ctx->oids.nr++;
} else if (ctx->check_oids) {
error(_("invalid commit object id: %s"),
- commit_hex->items[i].string);
+ oid_to_hex(oid));
return -1;
}
}
+
stop_progress(&ctx->progress);
strbuf_release(&progress_title);
@@ -1785,7 +1792,7 @@ out:
int write_commit_graph(struct object_directory *odb,
struct string_list *pack_indexes,
- struct string_list *commit_hex,
+ struct oidset *commits,
enum commit_graph_write_flags flags,
const struct split_commit_graph_opts *split_opts)
{
@@ -1861,12 +1868,12 @@ int write_commit_graph(struct object_directory *odb,
goto cleanup;
}
- if (commit_hex) {
- if ((res = fill_oids_from_commit_hex(ctx, commit_hex)))
+ if (commits) {
+ if ((res = fill_oids_from_commits(ctx, commits)))
goto cleanup;
}
- if (!pack_indexes && !commit_hex)
+ if (!pack_indexes && !commits)
fill_oids_from_all_packs(ctx);
close_reachable(ctx);