git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] write_index: optionally allow broken null sha1s

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 25, 2013, 06:15 UTC
Message-ID
<20130825061500.GR2882@elie.Belkin>
In-Reply-To
<20130824013310.GA9343@sigill.intra.peff.net>
Hi,
Jeff King wrote:
Show 11 quoted lines
> ---
> I was tempted to not involve filter-branch in this commit at all, and
> instead require the user to manually invoke
>
>   GIT_ALLOW_NULL_SHA1=1 git filter-branch ...
>
> to perform such a filter.  That would be slightly safer, but requires
> some specialized knowledge from the user (and advice on using
> filter-branch to remove such entries already exists on places like
> stackoverflow, and this patch makes it Just Work on recent versions of
> git).

The above few paragraphs explained the most mysterious part of the patch to me. I think they would be fine to include in the commit message.

[...]
Show 19 quoted lines
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -1817,8 +1817,17 @@ int write_index(struct index_state *istate, int newfd)
>  			continue;
>  		if (!ce_uptodate(ce) && is_racy_timestamp(istate, ce))
>  			ce_smudge_racily_clean_entry(ce);
> -		if (is_null_sha1(ce->sha1))
> -			return error("cache entry has null sha1: %s", ce->name);
> +		if (is_null_sha1(ce->sha1)) {
> +			static const char msg[] = "cache entry has null sha1: %s";
> +			static int allow = -1;
> +
> +			if (allow < 0)
> +				allow = git_env_bool("GIT_ALLOW_NULL_SHA1", 0);
> +			if (allow)
> +				warning(msg, ce->name);
> +			else
> +				return error(msg, ce->name);
> +		}
Makes sense.
[...]
Show 22 quoted lines
> --- /dev/null
> +++ b/t/t7009-filter-branch-null-sha1.sh
> @@ -0,0 +1,54 @@
> +#!/bin/sh
> +
> +test_description='filter-branch removal of trees with null sha1'
> +. ./test-lib.sh
> +
> +test_expect_success 'create base commits' '
> +	test_commit one &&
> +	test_commit two &&
> +	test_commit three
> +'
> +
> +test_expect_success 'create a commit with a bogus null sha1 in the tree' '
> +	test_tick &&
> +	tree=$(
> +		{
> +			git ls-tree HEAD &&
> +			printf "160000 commit $_z40\\tbroken"
> +		} | git mktree
> +	) &&

To avoid pipes involving git commands, since they can losing the exit status (and hence information about whether git crashed):

	{
		git ls-tree HEAD &&
		echo "160000 commit $_z40	broken"
	} >listing &&
	echo "add broken entry" >msg &&
	tree=$(git mktree <listing) &&
	test_tick &&
	commit=$(git commit-tree "$tree" -p HEAD <msg) &&
	git update-ref HEAD "$commit"
The rest looks good.

Thanks, Jonathan

Previous: Jeff KingNext: Jeff King
Message 2 of 13 in “write_index: optionally allow broken null sha1s”
  1. write_index: optionally allow broken null sha1sJeff King, Aug 24, 2013
  2. Jonathan NiederAug 25, 2013
  3. [PATCHv2] write_index: optionally allow broken null sha1sJeff King, Aug 25, 2013
  4. Jonathan NiederAug 25, 2013
  5. Junio C HamanoAug 26, 2013
  6. Jeff KingAug 26, 2013
  7. Junio C HamanoAug 26, 2013
  8. Jeff KingAug 26, 2013
  9. Jeff KingAug 26, 2013
  10. Jonathan NiederAug 26, 2013
  11. Jeff KingAug 26, 2013
  12. Junio C HamanoAug 27, 2013
  13. [PATCHv3] write_index: optionally allow broken null sha1sJeff King, Aug 27, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.