Hi, Jeff King wrote:
> --- > 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. [...] > --- 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. [...] > --- /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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html