fsck_tree(): fix shadowed variable
authorJeff King <peff@peff.net>
Sat, 1 May 2021 15:41:38 +0000 (11:41 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 3 May 2021 05:41:08 +0000 (14:41 +0900)
commit9e1947cb482c8fc7e1d0c8334f126ced5062b895
treed10901aeed79f906bc04a84401bf7e6d010cac9a
parent963d02a24a1e6cec02cadf0d682af0bf222647ab
fsck_tree(): fix shadowed variable

Commit b2f2039c2b (fsck: accept an oid instead of a "struct tree" for
fsck_tree(), 2019-10-18) introduced a new "oid" parameter to
fsck_tree(), and we pass it to the report() function when we find
problems. However, that is shadowed within the tree-walking loop by the
existing "oid" variable which we use to store the oid of each tree
entry. As a result, we may report the wrong oid for some problems we
detect within the loop (the entry oid, instead of the tree oid).

Our tests didn't catch this because they checked only that we found the
expected fsck problem, not that it was attached to the correct object.

Let's rename both variables in the function to avoid confusion. This
makes the diff a little noisy (e.g., all of the report() calls outside
the loop were already correct but need to be touched), but makes sure we
catch all cases and will avoid similar confusion in the future.

And we can update the test to be a bit more specific and catch this
problem.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fsck.c
t/t7415-submodule-names.sh