Skip to content

Commit 5b6653e

Browse files
ttaylorrgitster
authored andcommitted
builtin/commit-graph.c: dereference tags in builtin
When given a list of commits, the commit-graph machinery calls 'lookup_commit_reference_gently()' on each element in the set and treats the resulting set of OIDs as the base over which to close for reachability. In an earlier collection of commits, the 'git commit-graph write --reachable' case made the inner-most call to 'lookup_commit_reference_gently()' by peeling references before they were passed over to the commit-graph internals. Do the analog for 'git commit-graph write --stdin-commits' by calling 'lookup_commit_reference_gently()' outside of the commit-graph machinery, making the inner-most call a noop. Since this may incur additional processing time, surround 'read_one_commit' with a progress meter to provide output to the caller. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa8953c commit 5b6653e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

builtin/commit-graph.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "repository.h"
77
#include "commit-graph.h"
88
#include "object-store.h"
9+
#include "progress.h"
910

1011
static char const * const builtin_commit_graph_usage[] = {
1112
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
@@ -138,15 +139,24 @@ static int write_option_parse_split(const struct option *opt, const char *arg,
138139
return 0;
139140
}
140141

141-
static int read_one_commit(struct oidset *commits, const char *hash)
142+
static int read_one_commit(struct oidset *commits, struct progress *progress,
143+
const char *hash)
142144
{
145+
struct commit *result;
143146
struct object_id oid;
144147
const char *end;
145148

146149
if (parse_oid_hex(hash, &oid, &end))
147150
return error(_("unexpected non-hex object ID: %s"), hash);
148151

149-
oidset_insert(commits, &oid);
152+
result = lookup_commit_reference_gently(the_repository, &oid, 1);
153+
if (result)
154+
oidset_insert(commits, &result->object.oid);
155+
else
156+
return error(_("invalid commit object id: %s"), hash);
157+
158+
display_progress(progress, oidset_size(commits));
159+
150160
return 0;
151161
}
152162

@@ -158,6 +168,7 @@ static int graph_write(int argc, const char **argv)
158168
struct object_directory *odb = NULL;
159169
int result = 0;
160170
enum commit_graph_write_flags flags = 0;
171+
struct progress *progress = NULL;
161172

162173
static struct option builtin_commit_graph_write_options[] = {
163174
OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -228,13 +239,18 @@ static int graph_write(int argc, const char **argv)
228239
} else if (opts.stdin_commits) {
229240
oidset_init(&commits, 0);
230241
flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS;
242+
if (opts.progress)
243+
progress = start_delayed_progress(
244+
_("Collecting commits from input"), 0);
231245

232246
while (strbuf_getline(&buf, stdin) != EOF) {
233-
if (read_one_commit(&commits, buf.buf)) {
247+
if (read_one_commit(&commits, progress, buf.buf)) {
234248
result = 1;
235249
goto cleanup;
236250
}
237251
}
252+
253+
238254
}
239255

240256
if (write_commit_graph(odb,
@@ -247,6 +263,8 @@ static int graph_write(int argc, const char **argv)
247263
cleanup:
248264
string_list_clear(&pack_indexes, 0);
249265
strbuf_release(&buf);
266+
if (progress)
267+
stop_progress(&progress);
250268
return result;
251269
}
252270

0 commit comments

Comments
 (0)