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

Re: [PATCH] builtin/commit.c: prevent bad commits

From
Jeff King <peff@peff.net>
Date
Apr 1, 2018, 22:50 UTC
Message-ID
<20180401225016.GA21634@sigill.intra.peff.net>
In-Reply-To
<20180401140650.18928-1-alonid@gmail.com>
On Sun, Apr 01, 2018 at 05:06:50PM +0300, Dan Aloni wrote:
Show 14 quoted lines
> These commits which have hashes starting with the hex string 'bad',
> always give me the chills. Why should a perfectly good commit be
> jinxed?
> 
> Statistically, one of 4096 commits may be 'bad'. This change adds a
> '--prevent-bad' switch to the commit command in order to prevent such
> commit hashes from being generated. Internally, the commit is retried
> with a slight commit meta-data modification - a newline is added to the
> end of the commit message. The meta-data change results in a different
> hash, that if we are lucky enough (4095/4096 chance) may not be 'bad'.
> 
> Note that this change does not affect actual software quality maintained
> using Git. Thus, it is recommended keep testing all generated versions
> regardless of commit hash jinxes.
Cute.

A while back we had patches to generate "desirable" commit prefixes, and they were focused on making the brute-forcing as fast as possible. I don't think I've seen this reverse case, but it's much easier: we can be fairly slow since the probability of hitting the bad case repeatedly is low.

Show 21 quoted lines
> @@ -1583,12 +1585,34 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>  		append_merge_tag_headers(parents, &tail);
>  	}
>  
> -	if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
> -				 parents, &oid, author_ident.buf, sign_commit,
> -				 extra)) {
> -		rollback_index_files();
> -		die(_("failed to write commit object"));
> +	for (;;) {
> +		char *oid_hex;
> +		struct commit_list *copy_parents;
> +
> +		copy_parents = copy_commit_list(parents);
> +
> +		if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
> +					 parents, &oid, author_ident.buf, sign_commit,
> +					 extra)) {
> +			rollback_index_files();
> +			die(_("failed to write commit object"));
> +		}
You could still have a "bad" tree. :)
-Peff
Previous: Junio C Hamano
Message 3 of 3 in “builtin/commit.c: prevent bad commits”
  1. builtin/commit.c: prevent bad commitsDan Aloni, Apr 1, 2018
  2. Junio C HamanoApr 1, 2018
  3. Jeff KingApr 1, 2018

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.