@matheusbsbs / matheus-bagliano / commits / 5b6653e523
Fork 0

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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed May 13, 2020 at 15:59 UTC 5b6653e523cd2a0357924caef339adfeab12903b
1 file changed +21 -3
builtin/commit-graph.c
+21 -3
@@ -6,6 +6,7 @@
6 #include "repository.h"
7 #include "commit-graph.h"
8 #include "object-store.h"
9 +#include "progress.h"
10
11 static char const * const builtin_commit_graph_usage[] = {
12 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,
139 return 0;
140 }
141
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)
144 {
145 + struct commit *result;
146 struct object_id oid;
147 const char *end;
148
149 if (parse_oid_hex(hash, &oid, &end))
150 return error(_("unexpected non-hex object ID: %s"), hash);
151
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 +
160 return 0;
161 }
162
@@ -158,6 +168,7 @@ static int graph_write(int argc, const char **argv)
168 struct object_directory *odb = NULL;
169 int result = 0;
170 enum commit_graph_write_flags flags = 0;
171 + struct progress *progress = NULL;
172
173 static struct option builtin_commit_graph_write_options[] = {
174 OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -228,13 +239,18 @@ static int graph_write(int argc, const char **argv)
239 } else if (opts.stdin_commits) {
240 oidset_init(&commits, 0);
241 flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS;
242 + if (opts.progress)
243 + progress = start_delayed_progress(
244 + _("Collecting commits from input"), 0);
245
246 while (strbuf_getline(&buf, stdin) != EOF) {
233 - if (read_one_commit(&commits, buf.buf)) {
247 + if (read_one_commit(&commits, progress, buf.buf)) {
248 result = 1;
249 goto cleanup;
250 }
251 }
252 +
253 +
254 }
255
256 if (write_commit_graph(odb,
@@ -247,6 +263,8 @@ static int graph_write(int argc, const char **argv)
263 cleanup:
264 string_list_clear(&pack_indexes, 0);
265 strbuf_release(&buf);
266 + if (progress)
267 + stop_progress(&progress);
268 return result;
269 }
270