summaryrefslogtreecommitdiff
path: root/builtin/commit-graph.c
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2020-05-13 21:59:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-05-18 19:51:11 (GMT)
commit2f00c355cb79ee86bddc9f2fef91ac380a6023fc (patch)
tree0aad4074cd3a15b6e7983ae7b0fb6c57c308f16f /builtin/commit-graph.c
parent1f1304d4976f54b1afa5d71b55e41c6c1b5f9ac1 (diff)
downloadgit-2f00c355cb79ee86bddc9f2fef91ac380a6023fc.zip
git-2f00c355cb79ee86bddc9f2fef91ac380a6023fc.tar.gz
git-2f00c355cb79ee86bddc9f2fef91ac380a6023fc.tar.bz2
commit-graph: drop COMMIT_GRAPH_WRITE_CHECK_OIDS flag
Since 7c5c9b9c57 (commit-graph: error out on invalid commit oids in 'write --stdin-commits', 2019-08-05), the commit-graph builtin dies on receiving non-commit OIDs as input to '--stdin-commits'. This behavior can be cumbersome to work around in, say, the case of piping 'git for-each-ref' to 'git commit-graph write --stdin-commits' if the caller does not want to cull out non-commits themselves. In this situation, it would be ideal if 'git commit-graph write' wrote the graph containing the inputs that did pertain to commits, and silently ignored the remainder of the input. Some options have been proposed to the effect of '--[no-]check-oids' which would allow callers to have the commit-graph builtin do just that. After some discussion, it is difficult to imagine a caller who wouldn't want to pass '--no-check-oids', suggesting that we should get rid of the behavior of complaining about non-commit inputs altogether. If callers do wish to retain this behavior, they can easily work around this change by doing the following: git for-each-ref --format='%(objectname) %(objecttype) %(*objecttype)' | awk ' !/commit/ { print "not-a-commit:"$1 } /commit/ { print $1 } ' | git commit-graph write --stdin-commits To make it so that valid OIDs that refer to non-existent objects are indeed an error after loosening the error handling, perform an extra lookup to make sure that object indeed exists before sending it to the commit-graph internals. Helped-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 'builtin/commit-graph.c')
-rw-r--r--builtin/commit-graph.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 97eb3b7..75455da 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -7,6 +7,7 @@
#include "commit-graph.h"
#include "object-store.h"
#include "progress.h"
+#include "tag.h"
static char const * const builtin_commit_graph_usage[] = {
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
@@ -142,18 +143,19 @@ static int write_option_parse_split(const struct option *opt, const char *arg,
static int read_one_commit(struct oidset *commits, struct progress *progress,
const char *hash)
{
- struct commit *result;
+ struct object *result;
struct object_id oid;
const char *end;
if (parse_oid_hex(hash, &oid, &end))
return error(_("unexpected non-hex object ID: %s"), hash);
- result = lookup_commit_reference_gently(the_repository, &oid, 1);
- if (result)
- oidset_insert(commits, &result->object.oid);
- else
- return error(_("invalid commit object id: %s"), hash);
+ result = deref_tag(the_repository, parse_object(the_repository, &oid),
+ NULL, 0);
+ if (!result)
+ return error(_("invalid object: %s"), hash);
+ else if (object_as_type(the_repository, result, OBJ_COMMIT, 1))
+ oidset_insert(commits, &result->oid);
display_progress(progress, oidset_size(commits));
@@ -238,7 +240,6 @@ static int graph_write(int argc, const char **argv)
strbuf_detach(&buf, NULL));
} else if (opts.stdin_commits) {
oidset_init(&commits, 0);
- flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS;
if (opts.progress)
progress = start_delayed_progress(
_("Collecting commits from input"), 0);