Skip to content

Commit 43262d8

Browse files
committed
Merge branch 'jk/squelch-missing-link-warning-for-unreachable'
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}
2 parents 0e04b24 + ce4e7b2 commit 43262d8

File tree

7 files changed

+34
-9
lines changed

7 files changed

+34
-9
lines changed

commit.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
357357
return 0;
358358
}
359359

360-
int parse_commit(struct commit *item)
360+
int parse_commit_gently(struct commit *item, int quiet_on_missing)
361361
{
362362
enum object_type type;
363363
void *buffer;
@@ -370,7 +370,8 @@ int parse_commit(struct commit *item)
370370
return 0;
371371
buffer = read_sha1_file(item->object.sha1, &type, &size);
372372
if (!buffer)
373-
return error("Could not read %s",
373+
return quiet_on_missing ? -1 :
374+
error("Could not read %s",
374375
sha1_to_hex(item->object.sha1));
375376
if (type != OBJ_COMMIT) {
376377
free(buffer);

commit.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ struct commit *lookup_commit_reference_by_name(const char *name);
5959
struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name);
6060

6161
int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size);
62-
int parse_commit(struct commit *item);
62+
int parse_commit_gently(struct commit *item, int quiet_on_missing);
63+
static inline int parse_commit(struct commit *item)
64+
{
65+
return parse_commit_gently(item, 0);
66+
}
6367
void parse_commit_or_die(struct commit *item);
6468

6569
/*

list-objects.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void process_tree(struct rev_info *revs,
8181
die("bad tree object");
8282
if (obj->flags & (UNINTERESTING | SEEN))
8383
return;
84-
if (parse_tree(tree) < 0) {
84+
if (parse_tree_gently(tree, revs->ignore_missing_links) < 0) {
8585
if (revs->ignore_missing_links)
8686
return;
8787
die("bad tree object %s", sha1_to_hex(obj->sha1));

revision.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
817817
parent = parent->next;
818818
if (p)
819819
p->object.flags |= UNINTERESTING;
820-
if (parse_commit(p) < 0)
820+
if (parse_commit_gently(p, 1) < 0)
821821
continue;
822822
if (p->parents)
823823
mark_parents_uninteresting(p);
@@ -844,7 +844,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
844844
for (parent = commit->parents; parent; parent = parent->next) {
845845
struct commit *p = parent->item;
846846

847-
if (parse_commit(p) < 0)
847+
if (parse_commit_gently(p, revs->ignore_missing_links) < 0)
848848
return -1;
849849
if (revs->show_source && !p->util)
850850
p->util = commit->util;

t/t6501-freshen-objects.sh

+15
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,19 @@ for repack in '' true; do
129129
'
130130
done
131131

132+
test_expect_success 'do not complain about existing broken links' '
133+
cat >broken-commit <<-\EOF &&
134+
tree 0000000000000000000000000000000000000001
135+
parent 0000000000000000000000000000000000000002
136+
author whatever <[email protected]> 1234 -0000
137+
committer whatever <[email protected]> 1234 -0000
138+
139+
some message
140+
EOF
141+
commit=$(git hash-object -t commit -w broken-commit) &&
142+
git gc 2>stderr &&
143+
verbose git cat-file -e $commit &&
144+
test_must_be_empty stderr
145+
'
146+
132147
test_done

tree.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
204204
return 0;
205205
}
206206

207-
int parse_tree(struct tree *item)
207+
int parse_tree_gently(struct tree *item, int quiet_on_missing)
208208
{
209209
enum object_type type;
210210
void *buffer;
@@ -214,7 +214,8 @@ int parse_tree(struct tree *item)
214214
return 0;
215215
buffer = read_sha1_file(item->object.sha1, &type, &size);
216216
if (!buffer)
217-
return error("Could not read %s",
217+
return quiet_on_missing ? -1 :
218+
error("Could not read %s",
218219
sha1_to_hex(item->object.sha1));
219220
if (type != OBJ_TREE) {
220221
free(buffer);

tree.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ struct tree *lookup_tree(const unsigned char *sha1);
1616

1717
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
1818

19-
int parse_tree(struct tree *tree);
19+
int parse_tree_gently(struct tree *tree, int quiet_on_missing);
20+
static inline int parse_tree(struct tree *tree)
21+
{
22+
return parse_tree_gently(tree, 0);
23+
}
2024
void free_tree_buffer(struct tree *tree);
2125

2226
/* Parses and returns the tree in the given ent, chasing tags and commits. */

0 commit comments

Comments
 (0)