mirror of
https://github.com/git/git.git
synced 2026-08-07 00:22:05 +00:00
fsck: check HAS_OBJ more consistently
There are two spots that call lookup_object() and assume
that a non-NULL result means we have the object:
1. When we're checking the objects given to us by the user
on the command line.
2. When we're checking if a reflog entry is valid.
This generally follows fsck's mental model that we will have
looked at and loaded a "struct object" for each object in
the repository. But it misses one case: if another object
_mentioned_ an object, but we didn't actually parse it or
verify that it exists, it will still have a struct.
It's not clear if this is a triggerable bug or not.
Certainly the later parts of the reachability check need to
be careful of this, and do so by checking the HAS_OBJ flag.
But both of these steps happen before we start traversing,
so probably we won't have followed any links yet. Still,
it's easy enough to be defensive here.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
c3271a0e47
commit
c2d17b3b6e
@@ -398,7 +398,7 @@ static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1,
|
||||
|
||||
if (!is_null_sha1(sha1)) {
|
||||
obj = lookup_object(sha1);
|
||||
if (obj) {
|
||||
if (obj && (obj->flags & HAS_OBJ)) {
|
||||
if (timestamp && name_objects)
|
||||
add_decoration(fsck_walk_options.object_names,
|
||||
obj,
|
||||
@@ -755,7 +755,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
|
||||
if (!get_sha1(arg, sha1)) {
|
||||
struct object *obj = lookup_object(sha1);
|
||||
|
||||
if (!obj) {
|
||||
if (!obj || !(obj->flags & HAS_OBJ)) {
|
||||
error("%s: object missing", sha1_to_hex(sha1));
|
||||
errors_found |= ERROR_OBJECT;
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user