From 9cc2b07a7c95fad0bb5e3a7a8db29bebdb90d92b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 1 Jun 2015 05:56:26 -0400 Subject: [PATCH 1/3] add quieter versions of parse_{tree,commit} When we call parse_commit, it will complain to stderr if the object does not exist or cannot be read. This means that we may produce useless error messages if this situation is expected (e.g., because the object is marked UNINTERESTING, or because revs->ignore_missing_links is set). We can fix this by adding a new "parse_X_gently" form that takes a flag to suppress the messages. The existing "parse_X" form is already gentle in the sense that it returns an error rather than dying, and we could in theory just add a "quiet" flag to it (with existing callers passing "0"). But doing it this way means we do not have to disturb existing callers. Note also that the new flag is "quiet_on_missing", and not just "quiet". We could add a flag to suppress _all_ errors, but besides being a more invasive change (we would have to pass the flag down to sub-functions, too), there is a good reason not to: we would never want to use it. Missing a linked object is expected in some circumstances, but it is never expected to have a malformed commit, or to get a tree when we wanted a commit. We should always complain about these corruptions. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- commit.c | 5 +++-- commit.h | 6 +++++- tree.c | 5 +++-- tree.h | 6 +++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/commit.c b/commit.c index 19cf8f9c6..388819c4e 100644 --- a/commit.c +++ b/commit.c @@ -353,7 +353,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s return 0; } -int parse_commit(struct commit *item) +int parse_commit_gently(struct commit *item, int quiet_on_missing) { enum object_type type; void *buffer; @@ -366,7 +366,8 @@ int parse_commit(struct commit *item) return 0; buffer = read_sha1_file(item->object.sha1, &type, &size); if (!buffer) - return error("Could not read %s", + return quiet_on_missing ? -1 : + error("Could not read %s", sha1_to_hex(item->object.sha1)); if (type != OBJ_COMMIT) { free(buffer); diff --git a/commit.h b/commit.h index bc68ccbe6..61bda25b3 100644 --- a/commit.h +++ b/commit.h @@ -59,7 +59,11 @@ struct commit *lookup_commit_reference_by_name(const char *name); struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name); int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size); -int parse_commit(struct commit *item); +int parse_commit_gently(struct commit *item, int quiet_on_missing); +static inline int parse_commit(struct commit *item) +{ + return parse_commit_gently(item, 0); +} void parse_commit_or_die(struct commit *item); /* diff --git a/tree.c b/tree.c index bb02c1caa..194a84074 100644 --- a/tree.c +++ b/tree.c @@ -198,7 +198,7 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size) return 0; } -int parse_tree(struct tree *item) +int parse_tree_gently(struct tree *item, int quiet_on_missing) { enum object_type type; void *buffer; @@ -208,7 +208,8 @@ int parse_tree(struct tree *item) return 0; buffer = read_sha1_file(item->object.sha1, &type, &size); if (!buffer) - return error("Could not read %s", + return quiet_on_missing ? -1 : + error("Could not read %s", sha1_to_hex(item->object.sha1)); if (type != OBJ_TREE) { free(buffer); diff --git a/tree.h b/tree.h index d84ac63e5..35332fba8 100644 --- a/tree.h +++ b/tree.h @@ -15,7 +15,11 @@ struct tree *lookup_tree(const unsigned char *sha1); int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); -int parse_tree(struct tree *tree); +int parse_tree_gently(struct tree *tree, int quiet_on_missing); +static inline int parse_tree(struct tree *tree) +{ + return parse_tree_gently(tree, 0); +} void free_tree_buffer(struct tree *tree); /* Parses and returns the tree in the given ent, chasing tags and commits. */ From daf7d86783b1bd2065881a3f0957f69c79a52fd7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 1 Jun 2015 05:56:37 -0400 Subject: [PATCH 2/3] silence broken link warnings with revs->ignore_missing_links We set revs->ignore_missing_links to instruct the revision-walking machinery that we know the history graph may be incomplete. For example, we use it when walking unreachable but recent objects; we want to add what we can, but it's OK if the history is incomplete. However, we still print error messages for the missing objects, which can be confusing. This is not an error, but just a normal situation when transitioning from a repository last pruned by an older git (which can leave broken segments of history) to a more recent one (where we try to preserve whole reachable segments). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- list-objects.c | 2 +- revision.c | 2 +- t/t6501-freshen-objects.sh | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/list-objects.c b/list-objects.c index 2910becd6..90c21abc5 100644 --- a/list-objects.c +++ b/list-objects.c @@ -81,7 +81,7 @@ static void process_tree(struct rev_info *revs, die("bad tree object"); if (obj->flags & (UNINTERESTING | SEEN)) return; - if (parse_tree(tree) < 0) { + if (parse_tree_gently(tree, revs->ignore_missing_links) < 0) { if (revs->ignore_missing_links) return; die("bad tree object %s", sha1_to_hex(obj->sha1)); diff --git a/revision.c b/revision.c index 75dda928e..983e4c49f 100644 --- a/revision.c +++ b/revision.c @@ -834,7 +834,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, for (parent = commit->parents; parent; parent = parent->next) { struct commit *p = parent->item; - if (parse_commit(p) < 0) + if (parse_commit_gently(p, revs->ignore_missing_links) < 0) return -1; if (revs->show_source && !p->util) p->util = commit->util; diff --git a/t/t6501-freshen-objects.sh b/t/t6501-freshen-objects.sh index 157f3f91d..2adf82507 100755 --- a/t/t6501-freshen-objects.sh +++ b/t/t6501-freshen-objects.sh @@ -129,4 +129,19 @@ for repack in '' true; do ' done +test_expect_success 'do not complain about existing broken links' ' + cat >broken-commit <<-\EOF && + tree 0000000000000000000000000000000000000001 + parent 0000000000000000000000000000000000000002 + author whatever 1234 -0000 + committer whatever 1234 -0000 + + some message + EOF + commit=$(git hash-object -t commit -w broken-commit) && + git gc 2>stderr && + verbose git cat-file -e $commit && + test_must_be_empty stderr +' + test_done From ce4e7b2ac38cfe5e4c165411d2e37b22e445ab88 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 1 Jun 2015 05:56:40 -0400 Subject: [PATCH 3/3] suppress errors on missing UNINTERESTING links When we are traversing commit parents along the UNINTERESTING side of a revision walk, we do not care if the parent turns out to be missing. That lets us limit traversals using unreachable and possibly incomplete sections of history. However, we do still print error messages about the missing commits; this patch suppresses the error, as well. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- revision.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/revision.c b/revision.c index 983e4c49f..9f5476dc7 100644 --- a/revision.c +++ b/revision.c @@ -807,7 +807,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, parent = parent->next; if (p) p->object.flags |= UNINTERESTING; - if (parse_commit(p) < 0) + if (parse_commit_gently(p, 1) < 0) continue; if (p->parents) mark_parents_uninteresting(p);