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

Re: [PATCH v4 2/4] git-cherry-pick: Add keep-redundant-commits option

From
Neil Horman <nhorman@tuxdriver.com>
Date
Apr 12, 2012, 10:49 UTC
Message-ID
<20120412104916.GB32669@hmsreliant.think-freely.org>
In-Reply-To
<7vty0phc8s.fsf@alter.siamese.dyndns.org>
On Wed, Apr 11, 2012 at 08:15:15PM -0700, Junio C Hamano wrote:
Show 31 quoted lines
> Neil Horman <nhorman@tuxdriver.com> writes:
> 
> >> > -static int run_git_commit(const char *defmsg, struct replay_opts *opts)
> >> > +int run_git_commit(const char *defmsg, struct replay_opts *opts, int empty)
> >> >  {
> >> > -	/* 7 is max possible length of our args array including NULL */
> >> > -	const char *args[7];
> >> > -	int i = 0;
> >> > +	struct argv_array array;
> >> > +	int rc;
> >> > +
> >> > +	if (!empty && !opts->keep_if_made_empty) {
> >> > +		unsigned char head_sha1[20];
> >> > +		struct commit *head_commit;
> >> > +		int need_free = 0;
> >> > +
> >> > +		resolve_ref_unsafe("HEAD", head_sha1, 1, NULL);
> >> > +		head_commit = lookup_commit(head_sha1);
> >> 
> >> No error checking whatsoever?  HEAD might be pointing at a branch that
> >> hasn't been born, for example.
> >> 
> > Sorry, I had presumed that HEAD could be guaranteed to be good here, given that
> > we validate it in rollback_single_pick via read_ref_full.  But I can add
> > additional checking here.
> 
> As long as it is clear that we always have "HEAD" here, it is not strictly
> necessary, but we'd probably feel better, especially now that the function
> is (for some reason) made into a global one and may gain other new callers
> outside this file scope.
> 

Gah! Thanks for that, its not meant to be static. I made that global so that gdb could see it and set a breakpoint on it, while I was figuring out the segfault I was getting when active_cache_tree was NULL. I'll fix that.

Show 22 quoted lines
> >> >  	if (opts->allow_empty)
> >> > -		args[i++] = "--allow-empty";
> >> > +		argv_array_push(&array, "--allow-empty");
> >> 
> >> If --keep-if-made-empty is not given but --allow-empty was, it is fine to
> >> give --allow-empty here, but otherwise, it logically is iffy and is likely
> >> to become a cause of future bugs to pass --allow-empty to "git commit",
> >> even though the earlier check _ought_ to catch problematic cases, no?
> >> 
> > Not sure I follow your reasoning here.  We need to pass allow-empty to git
> > commit here if git cherry-pick set either allow-empty or keep-redundant-commits
> > (the latter setting opts->empty), Can you give an example of what might be
> > problematic in the future?
> 
> Thinking about it again, I think this part of your patch is correct.
> 
> We may pass an index that yields the same tree as "HEAD" if the original
> was empty, or the original was not empty but the merge found the commit
> unneeded.  In either case, if "--keep-unnecessary" or "--allow-empty" was
> given, we want to record the empty commit, and opts->allow_empty is set
> when either option was given from the command line.
> 

Yes, exactly. Thanks.

> Thanks.
> 
Previous: Junio C HamanoNext: Neil Horman
Message 9 of 16 in “Enhance git-rebases flexibiilty in handling empty commits”
  1. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 11, 2012
  2. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 11, 2012
  3. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 11, 2012
  4. Junio C HamanoApr 11, 2012
  5. Neil HormanApr 11, 2012
  6. Junio C HamanoApr 11, 2012
  7. Neil HormanApr 11, 2012
  8. Junio C HamanoApr 12, 2012
  9. Neil HormanApr 12, 2012
  10. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 11, 2012
  11. Junio C HamanoApr 11, 2012
  12. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 11, 2012
  13. Junio C HamanoApr 11, 2012
  14. Neil HormanApr 11, 2012
  15. Junio C HamanoApr 12, 2012
  16. Neil HormanApr 12, 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.