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>
This commit is contained in:
Taylor Blau
2020-04-13 22:04:25 -06:00
committed by Junio C Hamano
parent f4781068fa
commit 6830c36077
4 changed files with 52 additions and 31 deletions

View File

@ -137,7 +137,7 @@ static int write_option_parse_split(const struct option *opt, const char *arg,
static int graph_write(int argc, const char **argv)
{
struct string_list *pack_indexes = NULL;
struct string_list *commit_hex = NULL;
struct oidset commits = OIDSET_INIT;
struct object_directory *odb = NULL;
struct string_list lines;
int result = 0;
@ -210,7 +210,20 @@ static int graph_write(int argc, const char **argv)
if (opts.stdin_packs)
pack_indexes = &lines;
if (opts.stdin_commits) {
commit_hex = &lines;
struct string_list_item *item;
oidset_init(&commits, lines.nr);
for_each_string_list_item(item, &lines) {
struct object_id oid;
const char *end;
if (parse_oid_hex(item->string, &oid, &end)) {
error(_("unexpected non-hex object ID: "
"%s"), item->string);
return 1;
}
oidset_insert(&commits, &oid);
}
flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS;
}
@ -219,7 +232,7 @@ static int graph_write(int argc, const char **argv)
if (write_commit_graph(odb,
pack_indexes,
commit_hex,
opts.stdin_commits ? &commits : NULL,
flags,
&split_opts))
result = 1;