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

Re: [PATCH 2/3] rebase -i --keep-empty: don't prune empty commits

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 21, 2018, 22:38 UTC
Message-ID
<nycvar.QRO.7.76.6.1803212336420.77@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz>
In-Reply-To
<xmqqfu4uslar.fsf@gitster-ct.c.googlers.com>
Hi Junio,
On Tue, 20 Mar 2018, Junio C Hamano wrote:
Show 51 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> >> +		if (!keep_empty && is_empty)
> >>  			strbuf_addf(&buf, "%c ", comment_line_char);
> 
> We are not trying to preserve an empty one, and have found an empty
> one, so we comment it out, and then...
> 
> >> +		if (is_empty || !(commit->object.flags & PATCHSAME)) {
> >
> > May I suggest inverting the logic here, to make the code more obvious and
> > also to avoid indenting the block even further?
> >
> > 		if (!is_empty && (commit->object.flags & PATCHSAME))
> > 			continue;
> 
> ... if a non-empty one that already appears in the upstream, we do
> not do anything to it.  There is no room for keep-empty or lack of
> it to affect what happens to these commits.
> 
> Otherwise the insn is emitted for the commit.
> 
> >> +			strbuf_addf(&buf, "%s %s ", insn,
> >> +				    oid_to_hex(&commit->object.oid));
> >> +			pretty_print_commit(&pp, commit, &buf);
> >> +			strbuf_addch(&buf, '\n');
> >> +			fputs(buf.buf, out);
> >> +		}
> 
> I tend to agree that the suggested structure is easier to follow
> than Phillip's version.
> 
> But I wonder if this is even easier to follow.  It makes it even
> more clear that patchsame commits that are not empty are discarded
> unconditionally.
> 
> 	while ((commit = get_revision(&revs))) {
> 		int is_empty  = is_original_commit_empty(commit);
> 		if (!is_empty && (commit->object.flags & PATCHSAME))
> 			continue;
> 		strbuf_reset(&buf);
> 		if (!keep_empty && is_empty)
> 			strbuf_addf(&buf, "%c ", comment_line_char);
> 		strbuf_addf(&buf, "%s %s ", insn,
> 			    oid_to_hex(&commit->object.oid));
> 		pretty_print_commit(&pp, commit, &buf);
> 		strbuf_addch(&buf, '\n');
> 		fputs(buf.buf, out);
> 	}
> 
> Or did I screw up the rewrite?

This looks correct. And the postimage is easier to follow than the one of my suggested change.

My version is easier to review on the mailing list, of course, as it minimizes the diff... ;-)

Ciao, Dscho

Previous: Phillip WoodNext: Junio C Hamano
Message 7 of 10 in “rebase --keep-empty/--root fixes”
  1. 0/3 rebase --keep-empty/--root fixesPhillip Wood, Mar 20, 2018
  2. 3/3 rebase: respect --no-keep-emptyPhillip Wood, Mar 20, 2018
  3. 2/3 rebase -i --keep-empty: don't prune empty commitsPhillip Wood, Mar 20, 2018
  4. Johannes SchindelinMar 20, 2018
  5. Junio C HamanoMar 20, 2018
  6. Phillip WoodMar 20, 2018
  7. Johannes SchindelinMar 21, 2018
  8. Junio C HamanoMar 29, 2018
  9. 1/3 rebase --root: stop assuming squash_onto is unsetPhillip Wood, Mar 20, 2018
  10. Johannes SchindelinMar 20, 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.