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

Re: [PATCH 3/5] git-cherry-pick: Add ignore-if-made-empty option [v2]

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 5, 2012, 21:01 UTC
Message-ID
<7vobr551vs.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1333654745-7898-4-git-send-email-nhorman@tuxdriver.com>
Neil Horman <nhorman@tuxdriver.com> writes:
> Subject: Re: [PATCH 3/5] git-cherry-pick: Add ignore-if-made-empty option [v2]
Please don't do this.  The tools do not strip the garbage at the end.
Instead, do it like either one of these:
	Subject: [PATCH 3/5 (v2)] mumble mumble...
	Subject: [PATCH v2 3/5] mumble mumble...

The latter is more appropriate when resending everything, including the ones that did not change from the earlier round.

Show 10 quoted lines
> Since we'll be using git-cherry-pick to enhance git-rebase's ability to preserve
> empty commits, we open ourselves to the possibility of preserving commits that
> are made empty by a previous merge as well, which is almost certainly not what
> we want (most of the time).  To handle this, we can add the ignore-if-made-empty
> option.  If enabled, it will look at cherry-picked commits, and if the origional
> sha1 has the same tree as its parent, then the cherry-pick is comitted as an
> empty commit, otherwise the commit is skipped (because it previously made
> changes to the tree, but no longer does).
>
> Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Show 10 quoted lines
> diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
> index c283d8c..bb7eb4a 100644
> --- a/Documentation/git-cherry-pick.txt
> +++ b/Documentation/git-cherry-pick.txt
> @@ -103,7 +103,7 @@ effect to your index in a row.
>  	cherry-pick'ed commit, then a fast forward to this commit will
>  	be performed.
>  
> ---allow-empty:
> +--allow-empty:::

A single colon is already buggy, but three colons is equally bad. Please fix that in the original point this bug was introduced. I guess it was 2/5 of this series?

Show 6 quoted lines
> @@ -112,6 +112,14 @@ effect to your index in a row.
>  	commits that meet the "fast-forward" requirement will be kept
>  	even without this option.
>  
> +--ignore-if-made-empty::
> +	If the --allow-empty option is used, all empty commits are kept,

Literal strings the user may type are typically set in tt font (i.e. `--allow-empty`).

> +	including those which were made empty due to a previous change.
> +	While this may be desireable, likely it is not.

Mental note. Up to this point, the reader is told that "--allow-empty" alone is likely to do a wrong thing.

> +	This option
> +	restricts the scope of --allow-empty to only those commits which
> +	were created as empty commits ...

And the user is asked to give "--ignore-if-made-empty" in addition to "--allow-empty" to get a saner and more likely to be useful behaviour. Isn't that backwards? This "the other option is insane, and please make it saner" option needs a lot more typing than the more insane option.

I would expect that "--allow-empty" would by default filter ones that are originally non-empty but are made unnecessary (we are allowing empty commits in the original history to be cherry-picked, but the general principle that unnecessary commits must not be picked still is in effect). If you want to give a user the other more insane mode of operation, it is OK to let the user give a different option *instead* *of* the saner "--allow-empty".

Perhaps name that "--keep-unnecessary-commit" (it is no longer about allowing empty commits in the original history to be picked; it is about keeping unnecessary and irrelevant commits in the resulting history).

And error out if both options are given.
Show 10 quoted lines
> +static int run_git_commit(const char *defmsg, struct replay_opts *opts, int empty)
> +{
> +	struct argv_array array;
> +	int rc;
> +
> +	argv_array_init(&array);
> +	argv_array_push(&array, "commit");
> +	argv_array_push(&array, "-n");
> +
> +	if ((!empty) && (opts->ignore_if_made_empty)) {
Style: lose the extra and unnecessary parentheses, especially when the
expression inside them are so trivial, i.e.
	if (!empty && opts->ignore_if_made_empty) {

although I suspect that redesign of the command line interface might make it a moot point to polish this part of the code without major rethinking.

> +		/* Note: This implies --dry-run */
> +		argv_array_push(&array, "--porcelain");
> +		if (run_command_v_opt(array.argv, RUN_GIT_CMD) == 1) {

The only thing you want to check at this point is if the contents of the index being committed is the same as the tree of HEAD. Why do we even want to incur this much overhead?

Isn't running "diff-index --cached HEAD" sufficient?
> +			/* The dry run exit code of 1 tells us this is
> + 			 * an empty commit, just skip it.
> + 			 */
	/*
         * Our multi-line comments are
         * formatted this way.
         */
Show 24 quoted lines
> +			argv_array_clear(&array);
> +			return 0;
> +		}
> +		argv_array_pop(&array, 1);
> +	}
> +
>  
>  	if (opts->signoff)
> +		argv_array_push(&array, "-s");
>  	if (!opts->edit) {
> +		argv_array_push(&array, "-F");
> +		argv_array_push(&array, defmsg);
>  	}
> +	
>  	if (opts->allow_empty)
> +		argv_array_push(&array, "--allow-empty");
> +
> +
> +	rc = run_command_v_opt(array.argv, RUN_GIT_CMD);
> +	argv_array_clear(&array);
> +	return rc;
> +}
> +
> +static int is_origional_commit_empty(struct commit *commit)
What is origional?
Is there a reason why this series is not marked as WIP or RFC?

I am starting to wonder if it is worth spending time on careful reviewing, or it would be sufficient to give a cursory review quickly to give you more time to polish your re-roll.

Show 40 quoted lines
> +{
> +	struct argv_array argv_array;
> +	struct child_process cp;
> +	char ptree[41], pptree[41];
> +	int pipefd[2];
> +	FILE *output;
> +	int ret = 0;
> +
> +	if (pipe2(pipefd, 0) < 0)
> +		return 0;
> +
> +	output = xfdopen(pipefd[0], "r");
> +
> +	argv_array_init(&argv_array);
> +	memset(&cp, 0, sizeof(struct child_process));
>  
> -	args[i] = NULL;
> +	argv_array_push(&argv_array, "rev-parse");
> +	argv_array_pushf(&argv_array, "%s^{tree}", sha1_to_hex(commit->object.sha1));
>  
> -	return run_command_v_opt(args, RUN_GIT_CMD);
> +	cp.git_cmd = 1;
> +	cp.no_stdin = 1;
> +	cp.no_stderr = 1;
> +	cp.out = pipefd[1];
> +	cp.argv = argv_array.argv;
> +
> +	if (start_command(&cp) < 0)
> +		goto out;
> +
> +	if (fscanf(output, "%s\n", ptree) < 1)
> +		goto out;
> +
> +	finish_command(&cp);
> +
> +	fclose(output);
> +	close(pipefd[0]);
> +	argv_array_clear(&argv_array);
> +
> +	if (pipe2(pipefd, 0) < 0)
Huh?  "man pipe2" and see if it is portable.
Previous: Neil HormanNext: Neil Horman
Message 34 of 121 in “Enhance git-rebases flexibiilty in handling empty commits”
  1. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Mar 30, 2012
  2. 1/4 git-cherry-pick: add keep-empty optionNeil Horman, Mar 30, 2012
  3. Junio C HamanoMar 30, 2012
  4. Jeff KingMar 30, 2012
  5. Neil HormanMar 31, 2012
  6. 2/4 git-rebase: add keep_empty flagNeil Horman, Mar 30, 2012
  7. Junio C HamanoMar 30, 2012
  8. Neil HormanMar 31, 2012
  9. 3/4 git-commit-am: Allow automatic rebasing to preserve empty commitsNeil Horman, Mar 30, 2012
  10. Junio C HamanoMar 30, 2012
  11. Neil HormanMar 31, 2012
  12. Junio C HamanoMar 30, 2012
  13. Neil HormanMar 31, 2012
  14. 4/4 git-commit-interactive: Allow rebasing to preserve empty commitsNeil Horman, Mar 30, 2012
  15. Junio C HamanoMar 30, 2012
  16. Neil HormanMar 31, 2012
  17. Junio C HamanoMar 30, 2012
  18. 0/5 Enhance git-rebases flexibiilty handling empty commits [v2]Neil Horman, Apr 5, 2012
  19. 1/5 argv-array: Add argv_array_pop function [v2]Neil Horman, Apr 5, 2012
  20. Junio C HamanoApr 5, 2012
  21. Neil HormanApr 5, 2012
  22. Neil HormanApr 6, 2012
  23. Jeff KingApr 6, 2012
  24. Neil HormanApr 6, 2012
  25. Junio C HamanoApr 6, 2012
  26. Jeff KingApr 6, 2012
  27. Cc tags in the commit message (Re: [PATCH 1/5] argv-array: Add argv_array_pop function [v2])Jonathan Nieder, Apr 6, 2012
  28. Junio C HamanoApr 6, 2012
  29. Jeff KingApr 6, 2012
  30. Junio C HamanoApr 6, 2012
  31. Neil HormanApr 6, 2012
  32. 2/5 git-cherry-pick: add allow-empty option [v2]Neil Horman, Apr 5, 2012
  33. 3/5 git-cherry-pick: Add ignore-if-made-empty option [v2]Neil Horman, Apr 5, 2012
  34. Junio C HamanoApr 5, 2012
  35. Neil HormanApr 5, 2012
  36. Junio C HamanoApr 6, 2012
  37. Neil HormanApr 6, 2012
  38. Johannes SixtApr 6, 2012
  39. 4/5 git-cherry-pick: Add test to validate new options [v2]Neil Horman, Apr 5, 2012
  40. 5/5 git-rebase: add keep_empty flag [v2]Neil Horman, Apr 5, 2012
  41. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 10, 2012
  42. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 10, 2012
  43. Junio C HamanoApr 10, 2012
  44. Neil HormanApr 10, 2012
  45. Junio C HamanoApr 10, 2012
  46. Neil HormanApr 10, 2012
  47. Junio C HamanoApr 10, 2012
  48. Neil HormanApr 10, 2012
  49. Junio C HamanoApr 10, 2012
  50. Neil HormanApr 11, 2012
  51. Junio C HamanoApr 11, 2012
  52. Neil HormanApr 11, 2012
  53. Junio C HamanoApr 11, 2012
  54. Neil HormanApr 11, 2012
  55. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 10, 2012
  56. Junio C HamanoApr 10, 2012
  57. Neil HormanApr 10, 2012
  58. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 10, 2012
  59. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 10, 2012
  60. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 13, 2012
  61. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 13, 2012
  62. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 13, 2012
  63. Clemens BuchacherApr 15, 2012
  64. Neil HormanApr 16, 2012
  65. Clemens BuchacherApr 16, 2012
  66. Neil HormanApr 17, 2012
  67. Junio C HamanoApr 17, 2012
  68. Clemens BuchacherApr 17, 2012
  69. Neil HormanApr 18, 2012
  70. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 13, 2012
  71. Clemens BuchacherApr 15, 2012
  72. Neil HormanApr 16, 2012
  73. Neil HormanApr 16, 2012
  74. Junio C HamanoApr 16, 2012
  75. Neil HormanApr 16, 2012
  76. Clemens BuchacherApr 16, 2012
  77. Neil HormanApr 17, 2012
  78. Clemens BuchacherApr 17, 2012
  79. Neil HormanApr 18, 2012
  80. Clemens BuchacherApr 18, 2012
  81. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 13, 2012
  82. Clemens BuchacherApr 15, 2012
  83. Neil HormanApr 16, 2012
  84. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 17, 2012
  85. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 17, 2012
  86. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 17, 2012
  87. Clemens BuchacherApr 17, 2012
  88. Neil HormanApr 18, 2012
  89. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 17, 2012
  90. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 17, 2012
  91. Clemens BuchacherApr 17, 2012
  92. Neil HormanApr 18, 2012
  93. Junio C HamanoApr 18, 2012
  94. Neil HormanApr 19, 2012
  95. Junio C HamanoApr 19, 2012
  96. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 18, 2012
  97. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 18, 2012
  98. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 18, 2012
  99. Junio C HamanoApr 18, 2012
  100. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 18, 2012
  101. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 18, 2012
  102. Zbigniew Jędrzejewski-SzmekApr 19, 2012
  103. Thomas RastApr 19, 2012
  104. Zbigniew Jędrzejewski-SzmekApr 19, 2012
  105. Neil HormanApr 19, 2012
  106. Junio C HamanoApr 19, 2012
  107. Junio C HamanoApr 19, 2012
  108. Neil HormanApr 20, 2012
  109. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 20, 2012
  110. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 20, 2012
  111. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 20, 2012
  112. Junio C HamanoApr 20, 2012
  113. Neil HormanApr 20, 2012
  114. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 20, 2012
  115. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 20, 2012
  116. Junio C HamanoApr 25, 2012
  117. Neil HormanApr 25, 2012
  118. Martin von ZweigbergkJul 18, 2012
  119. Johannes SixtJul 18, 2012
  120. Martin von ZweigbergkJul 18, 2012
  121. Neil HormanJul 18, 2012

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.