From: Jeff King <peff@peff.net>
To: Michael Haggerty <mhagger@alum.mit.edu>
Cc: Junio C Hamano <gitster@pobox.com>,
Anders Kaseorg <andersk@mit.edu>,
Stefan Beller <sbeller@google.com>,
git@vger.kernel.org
Subject: Re: [PATCH v3 4/4] read_loose_refs(): treat NULL_SHA1 loose references as broken
Date: Wed, 3 Jun 2015 10:08:04 -0400 [thread overview]
Message-ID: <20150603140803.GA23901@peff.net> (raw)
In-Reply-To: <eb79f7d96ec74445f7adf62757119273280e09c9.1433339279.git.mhagger@alum.mit.edu>
On Wed, Jun 03, 2015 at 03:51:59PM +0200, Michael Haggerty wrote:
> NULL_SHA1 is used to indicate of "invalid SHA-1" throughout our code
s/of/an/ ?
> (and the code of other git implementations), so it is vastly more
> likely that a reference was set to this value due to a software bug
> than that NULL_SHA1 is the legitimate SHA-1 of an actual object.
> Therefore, if a loose reference has the value NULL_SHA1, consider it
> to be broken.
>
> Amusingly, each of the other 2^160-1 possible SHA-1 values is exactly
> as unlikely as NULL_SHA1 to be the SHA-1 of an actual object. The
> difference is that most of those other values are also very unlikely
> to be written to a loose reference file by accident, whereas
> accidentally writing NULL_SHA1 to a loose reference file would be an
> easy mistake to make.
FWIW, I think this justification (and the comment below) reads better
than what you had before.
> diff --git a/refs.c b/refs.c
> index 6736424..83af13d 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -1324,6 +1324,16 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
> if (!read_ok) {
> hashclr(sha1);
> flag |= REF_ISBROKEN;
> + } else if (is_null_sha1(sha1)) {
> + /*
> + * It is so astronomically unlikely
> + * that NULL_SHA1 is the SHA-1 of an
> + * actual object that we consider its
> + * appearance in a loose reference
> + * file to be repo corruption
> + * (probably due to a software bug).
> + */
> + flag |= REF_ISBROKEN;
Nice. After reading the other thread, I did not think we needed to
bother with more refactoring here, but I agree this end result flows
nicely.
-Peff
next prev parent reply other threads:[~2015-06-03 14:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-03 13:51 [PATCH v3 0/4] Fix how for-each-ref handles broken loose references Michael Haggerty
2015-06-03 13:51 ` [PATCH v3 1/4] t6301: new tests of for-each-ref error handling Michael Haggerty
2015-06-03 13:51 ` [PATCH v3 2/4] for-each-ref: report broken references correctly Michael Haggerty
2015-06-03 13:51 ` [PATCH v3 3/4] read_loose_refs(): simplify function logic Michael Haggerty
2015-06-03 13:51 ` [PATCH v3 4/4] read_loose_refs(): treat NULL_SHA1 loose references as broken Michael Haggerty
2015-06-03 14:08 ` Jeff King [this message]
2015-06-03 18:51 ` Junio C Hamano
2015-06-03 20:15 ` Jeff King
2015-06-03 21:20 ` Junio C Hamano
2015-06-08 9:26 ` Michael Haggerty
2015-06-08 17:37 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150603140803.GA23901@peff.net \
--to=peff@peff.net \
--cc=andersk@mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mhagger@alum.mit.edu \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.