зеркало из https://github.com/microsoft/git.git
Merge branch 'rs/fsck-null-return-from-lookup'
Improve behaviour of "git fsck" upon finding a missing object. * rs/fsck-null-return-from-lookup: fsck: handle NULL return of lookup_blob() and lookup_tree()
This commit is contained in:
Коммит
6defdc9fe8
8
fsck.c
8
fsck.c
|
@ -358,15 +358,15 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (S_ISDIR(entry.mode)) {
|
if (S_ISDIR(entry.mode)) {
|
||||||
obj = &lookup_tree(entry.oid)->object;
|
obj = (struct object *)lookup_tree(entry.oid);
|
||||||
if (name)
|
if (name && obj)
|
||||||
put_object_name(options, obj, "%s%s/", name,
|
put_object_name(options, obj, "%s%s/", name,
|
||||||
entry.path);
|
entry.path);
|
||||||
result = options->walk(obj, OBJ_TREE, data, options);
|
result = options->walk(obj, OBJ_TREE, data, options);
|
||||||
}
|
}
|
||||||
else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
|
else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) {
|
||||||
obj = &lookup_blob(entry.oid)->object;
|
obj = (struct object *)lookup_blob(entry.oid);
|
||||||
if (name)
|
if (name && obj)
|
||||||
put_object_name(options, obj, "%s%s", name,
|
put_object_name(options, obj, "%s%s", name,
|
||||||
entry.path);
|
entry.path);
|
||||||
result = options->walk(obj, OBJ_BLOB, data, options);
|
result = options->walk(obj, OBJ_BLOB, data, options);
|
||||||
|
|
|
@ -222,6 +222,28 @@ test_expect_success 'unparseable tree object' '
|
||||||
test_i18ngrep ! "fatal: empty filename in tree entry" out
|
test_i18ngrep ! "fatal: empty filename in tree entry" out
|
||||||
'
|
'
|
||||||
|
|
||||||
|
hex2oct() {
|
||||||
|
perl -ne 'printf "\\%03o", hex for /../g'
|
||||||
|
}
|
||||||
|
|
||||||
|
test_expect_success 'tree entry with type mismatch' '
|
||||||
|
test_when_finished "remove_object \$blob" &&
|
||||||
|
test_when_finished "remove_object \$tree" &&
|
||||||
|
test_when_finished "remove_object \$commit" &&
|
||||||
|
test_when_finished "git update-ref -d refs/heads/type_mismatch" &&
|
||||||
|
blob=$(echo blob | git hash-object -w --stdin) &&
|
||||||
|
blob_bin=$(echo $blob | hex2oct) &&
|
||||||
|
tree=$(
|
||||||
|
printf "40000 dir\0${blob_bin}100644 file\0${blob_bin}" |
|
||||||
|
git hash-object -t tree --stdin -w --literally
|
||||||
|
) &&
|
||||||
|
commit=$(git commit-tree $tree) &&
|
||||||
|
git update-ref refs/heads/type_mismatch $commit &&
|
||||||
|
test_must_fail git fsck >out 2>&1 &&
|
||||||
|
test_i18ngrep "is a blob, not a tree" out &&
|
||||||
|
test_i18ngrep ! "dangling blob" out
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'tag pointing to nonexistent' '
|
test_expect_success 'tag pointing to nonexistent' '
|
||||||
cat >invalid-tag <<-\EOF &&
|
cat >invalid-tag <<-\EOF &&
|
||||||
object ffffffffffffffffffffffffffffffffffffffff
|
object ffffffffffffffffffffffffffffffffffffffff
|
||||||
|
|
Загрузка…
Ссылка в новой задаче