list-objects.c: handle unexpected non-blob entries
Fix one of the cases described in the previous commit where a tree-entry that is promised to a blob is in fact a non-blob. When 'lookup_blob()' returns NULL, it is because Git has cached the requested object as a non-blob. In this case, prevent a SIGSEGV by 'die()'-ing immediately before attempting to dereference the result. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Apr 9, 2019 at 19:13 UTC
23c204455bf2198806e8c7b0cd86b20a50a379d0
2 files changed
+8
-2
list-objects.c
+5
@@ -133,6 +133,11 @@ static void process_tree_contents(struct traversal_context *ctx,
133
base, entry.path);
134
else {
135
struct blob *b = lookup_blob(ctx->revs->repo, &entry.oid);
136
+ if (!b) {
137
+ die(_("entry '%s' in tree %s has blob mode, "
138
+ "but is not a blob"),
139
+ entry.path, oid_to_hex(&tree->object.oid));
140
+ }
141
b->object.flags |= NOT_USER_GIVEN;
142
process_blob(ctx, b, base, entry.path);
143
}
t/t6102-rev-list-unexpected-objects.sh
+3
-2
@@ -20,8 +20,9 @@ test_expect_failure 'traverse unexpected non-blob entry (lone)' '
20
test_must_fail git rev-list --objects $broken_tree
21
'
22
23
-test_expect_failure 'traverse unexpected non-blob entry (seen)' '
24
- test_must_fail git rev-list --objects $tree $broken_tree
23
+test_expect_success 'traverse unexpected non-blob entry (seen)' '
24
+ test_must_fail git rev-list --objects $tree $broken_tree >output 2>&1 &&
25
+ test_i18ngrep "is not a blob" output
26
'
27
28
test_expect_success 'setup unexpected non-tree entry' '