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

Re: [PATCH v4 5/5] fast-export, fast-import: add support for signed-commits

From
Junio C Hamano <gitster@pobox.com>
Date
May 3, 2021, 05:09 UTC
Message-ID
<xmqq1rao9zev.fsf@gitster.g>
In-Reply-To
<20210430232537.1131641-6-lukeshu@lukeshu.com>
Luke Shumaker <lukeshu@lukeshu.com> writes:
Show 16 quoted lines
> From: Luke Shumaker <lukeshu@datawire.io>
>
> fast-export has a --signed-tags= option that controls how to handle tag
> signatures.  However, there is no equivalent for commit signatures; it
> just silently strips the signature out of the commit (analogously to
> --signed-tags=strip).
>
> While signatures are generally problematic for fast-export/fast-import
> (because hashes are likely to change), if they're going to support tag
> signatures, there's no reason to not also support commit signatures.
>
> So, implement a --signed-commits= option that mirrors the --signed-tags=
> option.
>
> On the fast-export side, try to be as much like signed-tags as possible,
> in both implementation and in user-interface.  This will changes the
s/changes/change/;
Show 6 quoted lines
> default behavior to '--signed-commits=abort' from what is now
> '--signed-commits=strip'.  In order to provide an escape hatch for users
> of third-party tools that call fast-export and do not yet know of the
> --signed-commits= option, add an environment variable
> 'FAST_EXPORT_SIGNED_COMMITS_NOABORT=1' that changes the default to
> '--signed-commits=warn-strip'.
Nicely explained.
Show 25 quoted lines
> +static const char *find_commit_multiline_header(const char *msg,
> +						const char *key,
> +						const char **end)
> +{
> +	static struct strbuf val = STRBUF_INIT;
> +	const char *bol, *eol;
> +	size_t len;
> +
> +	strbuf_reset(&val);
> +
> +	bol = find_commit_header(msg, key, &len);
> +	if (!bol)
> +		return NULL;
> +	eol = bol + len;
> +	strbuf_add(&val, bol, len);
> +
> +	while (eol[0] == '\n' && eol[1] == ' ') {
> +		bol = eol + 2;
> +		eol = strchrnul(bol, '\n');
> +		strbuf_addch(&val, '\n');
> +		strbuf_add(&val, bol, eol - bol);
> +	}
> +
> +	*end = eol;
> +	return val.buf;

It is not exactly wrong per se, but using non-static (on stack) strbuf would make it easier to follow. You can then lose the strbuf_reset() upfront, and then this will call strbuf_detach().

Show 24 quoted lines
> diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh
> index 892737439b..cd51c78418 100755
> --- a/t/t9350-fast-export.sh
> +++ b/t/t9350-fast-export.sh
> @@ -8,6 +8,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
>  export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
>  
>  . ./test-lib.sh
> +. "$TEST_DIRECTORY/lib-gpg.sh"
>  
>  test_expect_success 'setup' '
>  
> @@ -284,9 +285,94 @@ test_expect_success 'signed-tags=warn-strip' '
>  	test -s err
>  '
>  
> +test_expect_success GPG 'set up signed commit' '
> +
> +	# Generate a commit with both "gpgsig" and "encoding" set, so
> +	# that we can test that fast-import gets the ordering correct
> +	# between the two.
> +	test_config i18n.commitEncoding ISO-8859-1 &&
> +	git checkout -f -b commit-signing main &&
> +	echo Sign your name > file-sign &&

Style. >file-sign (lose SP between the redirection operator and its operand).

Show 9 quoted lines
> +	git add file-sign &&
> +	git commit -S -m "signed commit" &&
> +	COMMIT_SIGNING=$(git rev-parse --verify commit-signing)
> +
> +'
> +
> +test_expect_success GPG 'signed-commits default' '
> +
> +	unset FAST_EXPORT_SIGNED_COMMITS_NOABORT &&
sane_unset would be safer here.
Show 10 quoted lines
> +	test_must_fail git fast-export --reencode=no commit-signing &&
> +
> +	FAST_EXPORT_SIGNED_COMMITS_NOABORT=1 git fast-export --reencode=no commit-signing >output 2>err &&
> +	! grep ^gpgsig output &&
> +	grep "^encoding ISO-8859-1" output &&
> +	test -s err &&
> +	sed "s/commit-signing/commit-strip-signing/" output |
> +		(cd new &&
> +		 git fast-import &&
> +		 test $COMMIT_SIGNING != $(git rev-parse --verify refs/heads/commit-strip-signing))

Let's not force readers to match nested parentheses visually (applies to multiple places in this patch):

	sed "s/commit-signing/commit-strip-signing/" output | (
		cd new &&
		git fast-import &&
		STRIPPED=$(git rev-parse --verify refs/heads/commit-strip-signing) &&
		test $COMMIT_SIGNING != $STRIPPED
	)
>  test_expect_success 'setup submodule' '
>  
>  	git checkout -f main &&
> +	{ git update-ref -d refs/heads/commit-signing || true; } &&
	test_might_fail git update-ref -d refs/heads/commit-signing &&
Previous: Luke ShumakerNext: Christian Couder
Message 32 of 60 in “fast-export, fast-import: implement signed-commits”
  1. 0/3 fast-export, fast-import: implement signed-commitsLuke Shumaker, Apr 22, 2021
  2. 1/3 git-fast-import.txt: add missing LF in the BNFLuke Shumaker, Apr 22, 2021
  3. 2/3 fast-export: rename --signed-tags='warn' to 'warn-verbatim'Luke Shumaker, Apr 22, 2021
  4. Eric SunshineApr 22, 2021
  5. Luke ShumakerApr 22, 2021
  6. Luke ShumakerApr 22, 2021
  7. 3/3 fast-export, fast-import: implement signed-commitsLuke Shumaker, Apr 22, 2021
  8. 0/3 fast-export, fast-import: implement signed-commitsLuke Shumaker, Apr 23, 2021
  9. 1/3 git-fast-import.txt: add missing LF in the BNFLuke Shumaker, Apr 23, 2021
  10. 2/3 fast-export: rename --signed-tags='warn' to 'warn-verbatim'Luke Shumaker, Apr 23, 2021
  11. Junio C HamanoApr 28, 2021
  12. Luke ShumakerApr 29, 2021
  13. Junio C HamanoApr 30, 2021
  14. 3/3 fast-export, fast-import: implement signed-commitsLuke Shumaker, Apr 23, 2021
  15. Junio C HamanoApr 28, 2021
  16. Luke ShumakerApr 29, 2021
  17. Elijah NewrenApr 29, 2021
  18. Junio C HamanoApr 29, 2021
  19. Elijah NewrenApr 30, 2021
  20. Junio C HamanoApr 30, 2021
  21. Luke ShumakerApr 30, 2021
  22. Luke ShumakerApr 30, 2021
  23. Elijah NewrenApr 30, 2021
  24. Luke ShumakerApr 30, 2021
  25. 0/5 fast-export, fast-import: add support for signed-commitsLuke Shumaker, Apr 30, 2021
  26. 1/5 git-fast-import.txt: add missing LF in the BNFLuke Shumaker, Apr 30, 2021
  27. 2/5 fast-export: rename --signed-tags='warn' to 'warn-verbatim'Luke Shumaker, Apr 30, 2021
  28. 3/5 git-fast-export.txt: clarify why 'verbatim' may not be a good ideaLuke Shumaker, Apr 30, 2021
  29. 4/5 fast-export: do not modify memory from get_commit_bufferLuke Shumaker, Apr 30, 2021
  30. Junio C HamanoMay 3, 2021
  31. 5/5 fast-export, fast-import: add support for signed-commitsLuke Shumaker, Apr 30, 2021
  32. Junio C HamanoMay 3, 2021
  33. 0/6 fast-export, fast-import: add support for signed-commitsChristian Couder, Feb 24, 2025
  34. 1/6 git-fast-import.adoc: add missing LF in the BNFChristian Couder, Feb 24, 2025
  35. 2/6 fast-export: fix missing whitespace after switchChristian Couder, Feb 24, 2025
  36. 3/6 fast-export: rename --signed-tags='warn' to 'warn-verbatim'Christian Couder, Feb 24, 2025
  37. 4/6 git-fast-export.txt: clarify why 'verbatim' may not be a good ideaChristian Couder, Feb 24, 2025
  38. Elijah NewrenFeb 24, 2025
  39. Christian CouderMar 10, 2025
  40. 5/6 fast-export: do not modify memory from get_commit_bufferChristian Couder, Feb 24, 2025
  41. 6/6 fast-export, fast-import: add support for signed-commitsChristian Couder, Feb 24, 2025
  42. Elijah NewrenFeb 25, 2025
  43. Junio C HamanoFeb 25, 2025
  44. Christian CouderMar 10, 2025
  45. Junio C HamanoFeb 24, 2025
  46. Elijah NewrenFeb 25, 2025
  47. Patrick SteinhardtFeb 25, 2025
  48. Elijah NewrenFeb 25, 2025
  49. Junio C HamanoFeb 25, 2025
  50. Christian CouderMar 10, 2025
  51. Phillip WoodFeb 25, 2025
  52. Christian CouderMar 10, 2025
  53. 0/6 fast-export, fast-import: add support for signed-commitsChristian Couder, Mar 10, 2025
  54. 1/6 git-fast-import.adoc: add missing LF in the BNFChristian Couder, Mar 10, 2025
  55. 2/6 fast-export: fix missing whitespace after switchChristian Couder, Mar 10, 2025
  56. 3/6 fast-export: rename --signed-tags='warn' to 'warn-verbatim'Christian Couder, Mar 10, 2025
  57. 4/6 git-fast-export.adoc: clarify why 'verbatim' may not be a good ideaChristian Couder, Mar 10, 2025
  58. 5/6 fast-export: do not modify memory from get_commit_bufferChristian Couder, Mar 10, 2025
  59. 6/6 fast-export, fast-import: add support for signed-commitsChristian Couder, Mar 10, 2025
  60. Elijah NewrenMar 10, 2025

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.