Skip to content

Commit

Permalink
Merge branch 'jk/squelch-missing-link-warning-for-unreachable'
Browse files Browse the repository at this point in the history
Recent "git prune" traverses young unreachable objects to safekeep
old objects in the reachability chain from them, which sometimes
caused error messages that are unnecessarily alarming.

* jk/squelch-missing-link-warning-for-unreachable:
  suppress errors on missing UNINTERESTING links
  silence broken link warnings with revs->ignore_missing_links
  add quieter versions of parse_{tree,commit}
  • Loading branch information
Junio C Hamano committed Jun 11, 2015
2 parents 0e04b24 + ce4e7b2 commit 43262d8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
5 changes: 3 additions & 2 deletions commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,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;
Expand All @@ -370,7 +370,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);
Expand Down
6 changes: 5 additions & 1 deletion commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*
Expand Down
2 changes: 1 addition & 1 deletion list-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,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);
Expand All @@ -844,7 +844,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;
Expand Down
15 changes: 15 additions & 0 deletions t/t6501-freshen-objects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <whatever@example.com> 1234 -0000
committer whatever <whatever@example.com> 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
5 changes: 3 additions & 2 deletions tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,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;
Expand All @@ -214,7 +214,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);
Expand Down
6 changes: 5 additions & 1 deletion tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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. */
Expand Down

0 comments on commit 43262d8

Please sign in to comment.