git/builtin
Michael Haggerty 8afc493d11 for-each-ref: report broken references correctly
If there is a loose reference file with invalid contents, "git
for-each-ref" incorrectly reports the problem as being a missing
object with name NULL_SHA1:

    $ echo '12345678' >.git/refs/heads/nonsense
    $ git for-each-ref
    fatal: missing object 0000000000000000000000000000000000000000 for refs/heads/nonsense

With an explicit "--format" string, it can even report that the
reference validly points at NULL_SHA1:

    $ git for-each-ref --format='%(objectname) %(refname)'
    0000000000000000000000000000000000000000 refs/heads/nonsense
    $ echo $?
    0

This has been broken since

    b7dd2d2 for-each-ref: Do not lookup objects when they will not be used (2009-05-27)

, which changed for-each-ref from using for_each_ref() to using
git_for_each_rawref() in order to avoid looking up the referred-to
objects unnecessarily. (When "git for-each-ref" is given a "--format"
string that doesn't include information about the pointed-to object,
it does not look up the object at all, which makes it considerably
faster. Iterating with DO_FOR_EACH_INCLUDE_BROKEN is essential to this
optimization because otherwise for_each_ref() would itself need to
check whether the object exists as part of its brokenness test.)

But for_each_rawref() includes broken references in the iteration, and
"git for-each-ref" doesn't itself reject references with REF_ISBROKEN.
The result is that broken references are processed *as if* they had
the value NULL_SHA1, which is the value stored in entries for broken
references.

Change "git for-each-ref" to emit warnings for references that are
REF_ISBROKEN but to otherwise skip them.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-06-02 13:09:16 -07:00
..
2014-11-21 10:19:14 -08:00
2014-07-16 11:10:11 -07:00
2014-12-22 12:27:36 -08:00
2015-01-22 13:46:38 -08:00
2014-12-22 12:27:12 -08:00
2014-12-22 09:57:42 -08:00
2014-01-17 12:21:20 -08:00
2015-02-13 13:16:12 -08:00
2014-11-25 15:24:55 -08:00
2015-03-20 12:40:56 -07:00
2014-10-29 10:07:56 -07:00
2014-04-30 10:30:02 -07:00
2015-01-07 12:55:05 -08:00
2014-10-08 13:05:25 -07:00