Skip to content

Commit 23c2044

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0616617 commit 23c2044

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

list-objects.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ static void process_tree_contents(struct traversal_context *ctx,
133133
base, entry.path);
134134
else {
135135
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+
}
136141
b->object.flags |= NOT_USER_GIVEN;
137142
process_blob(ctx, b, base, entry.path);
138143
}

t/t6102-rev-list-unexpected-objects.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ test_expect_failure 'traverse unexpected non-blob entry (lone)' '
2020
test_must_fail git rev-list --objects $broken_tree
2121
'
2222

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
2526
'
2627

2728
test_expect_success 'setup unexpected non-tree entry' '

0 commit comments

Comments
 (0)