public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Michael Haggerty <mhagger@alum•mit.edu>
Cc: Anders Kaseorg <andersk@mit•edu>,
	Stefan Beller <sbeller@google•com>, Jeff King <peff@peff•net>,
	git@vger•kernel.org
Subject: Re: [PATCH v2 3/3] read_loose_refs(): treat NULL_SHA1 loose references as broken
Date: Tue, 02 Jun 2015 13:11:33 -0700	[thread overview]
Message-ID: <xmqq7frl3m6i.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1433260647-18181-4-git-send-email-mhagger@alum.mit.edu> (Michael Haggerty's message of "Tue, 2 Jun 2015 17:57:27 +0200")

Michael Haggerty <mhagger@alum•mit.edu> writes:

> NULL_SHA1 is never a valid value for a reference. If a loose reference
> has that value, mark it as broken.
>
> Why check NULL_SHA1 and not the nearly 2^160 other SHA-1s that are
> also invalid in a given repository? Because (a) it is cheap to test
> for NULL_SHA1, and (b) NULL_SHA1 is often used as a "SHA-1 is invalid"
> value inside of Git client source code (not only ours!), and
> accidentally writing it to a loose reference file would be an easy
> mistake to make.
>
> Signed-off-by: Michael Haggerty <mhagger@alum•mit.edu>
> ---
>  refs.c                         | 7 +++++++
>  t/t6301-for-each-ref-errors.sh | 2 +-
>  2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/refs.c b/refs.c
> index 47e4e53..c28fde1 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -1321,6 +1321,13 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
>  				hashclr(sha1);
>  				flag |= REF_ISBROKEN;
>  			}
> +
> +			if (!(flag & REF_ISBROKEN) && is_null_sha1(sha1)) {
> +				/* NULL_SHA1 is never a valid reference value. */
> +				hashclr(sha1);

Do you need to clear after checking with is_null_sha1()?

> +				flag |= REF_ISBROKEN;
> +			}
> +
>  			if (check_refname_format(refname.buf,
>  						 REFNAME_ALLOW_ONELEVEL)) {
>  				hashclr(sha1);
> diff --git a/t/t6301-for-each-ref-errors.sh b/t/t6301-for-each-ref-errors.sh
> index 72d2397..cdb67a0 100755
> --- a/t/t6301-for-each-ref-errors.sh
> +++ b/t/t6301-for-each-ref-errors.sh
> @@ -24,7 +24,7 @@ test_expect_success 'Broken refs are reported correctly' '
>  	test_cmp broken-err err
>  '
>  
> -test_expect_failure 'NULL_SHA1 refs are reported correctly' '
> +test_expect_success 'NULL_SHA1 refs are reported correctly' '
>  	r=refs/heads/zeros &&
>  	echo $ZEROS >.git/$r &&
>  	test_when_finished "rm -f .git/$r" &&

      parent reply	other threads:[~2015-06-02 20:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-02 15:57 [PATCH v2 0/3] Fix how for-each-ref handles broken loose references Michael Haggerty
2015-06-02 15:57 ` [PATCH v2 1/3] t6301: new tests of for-each-ref error handling Michael Haggerty
2015-06-02 15:57 ` [PATCH v2 2/3] for-each-ref: report broken references correctly Michael Haggerty
2015-06-02 15:57 ` [PATCH v2 3/3] read_loose_refs(): treat NULL_SHA1 loose references as broken Michael Haggerty
2015-06-02 17:28   ` Stefan Beller
2015-06-02 21:10     ` Michael Haggerty
2015-06-03  9:09       ` Jeff King
2015-06-02 20:11   ` Junio C Hamano [this message]

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=xmqq7frl3m6i.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=andersk@mit$(echo .)edu \
    --cc=git@vger$(echo .)kernel.org \
    --cc=mhagger@alum$(echo .)mit.edu \
    --cc=peff@peff$(echo .)net \
    --cc=sbeller@google$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox