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

Re: [PATCH] rebase -i: fix numbering in squash message

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 15, 2018, 19:17 UTC
Message-ID
<xmqqy3d7h21r.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<27c91e67-7567-f820-c641-c7980965fcef@talktalk.net>
Phillip Wood <phillip.wood@talktalk.net> writes:
Show 14 quoted lines
>> I wonder if it makes it easier to read, understand and maintain if
>> there were a local variable that gets opts->current_fixup_count+2 at
>> the beginning of the function, make these three places refer to that
>> variable, and move the increment of opts->current_fixup_count down
>> in the function, after the "if we are squashing, do this, if we are
>> fixing up, do that, otherwise, we do not know what we are doing"
>> cascade.  And use the more common post-increment, as we no longer
>> depend on the returned value while at it.
>> 
>> IOW, something like this (untested), on top of yours.
>
> I think you'd need to change commit_staged_changes() as well as it
> relies on the current_fixup_count counting the number of fixups, not the
> number of fixups plus two.
I suspect you misread what I wrote (see below for the patch).  

The fixup_count is a new local variable in update_squash_messages() that holds N+2; in other words, I am not suggesting to change what opts->current_fixup_count means.

Show 5 quoted lines
> Having said that using 'current_fixup_count +
> 2' to create the labels and incrementing the count at the end of
> update_squash_messages() would probably be clearer than my version. I'm
> about to go away so it'll probably be the second week of September
> before I can re-roll this, will that be too late for getting it into 2.19?

I actually do not mind to go with what you originally sent, unless a cleaned up version is vastly more readable. After all, a clean-up can be done separately and safely.

Thanks.
Show 51 quoted lines
>>  sequencer.c | 10 ++++++----
>>  1 file changed, 6 insertions(+), 4 deletions(-)
>> 
>> diff --git a/sequencer.c b/sequencer.c
>> index 77d3c2346f..f82c283a89 100644
>> --- a/sequencer.c
>> +++ b/sequencer.c
>> @@ -1331,8 +1331,9 @@ static int update_squash_messages(enum todo_command command,
>>  	struct strbuf buf = STRBUF_INIT;
>>  	int res;
>>  	const char *message, *body;
>> +	int fixup_count = opts->current_fixup_count + 2;
>>  
>> -	if (opts->current_fixup_count > 0) {
>> +	if (fixup_count > 2) {
>>  		struct strbuf header = STRBUF_INIT;
>>  		char *eol;
>>  
>> @@ -1345,7 +1346,7 @@ static int update_squash_messages(enum todo_command command,
>>  
>>  		strbuf_addf(&header, "%c ", comment_line_char);
>>  		strbuf_addf(&header, _("This is a combination of %d commits."),
>> -			    opts->current_fixup_count + 2);
>> +			    fixup_count);
>>  		strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len);
>>  		strbuf_release(&header);
>>  	} else {
>> @@ -1387,18 +1388,19 @@ static int update_squash_messages(enum todo_command command,
>>  		unlink(rebase_path_fixup_msg());
>>  		strbuf_addf(&buf, "\n%c ", comment_line_char);
>>  		strbuf_addf(&buf, _("This is the commit message #%d:"),
>> -			    ++opts->current_fixup_count + 1);
>> +			    fixup_count);
>>  		strbuf_addstr(&buf, "\n\n");
>>  		strbuf_addstr(&buf, body);
>>  	} else if (command == TODO_FIXUP) {
>>  		strbuf_addf(&buf, "\n%c ", comment_line_char);
>>  		strbuf_addf(&buf, _("The commit message #%d will be skipped:"),
>> -			    ++opts->current_fixup_count + 1);
>> +			    fixup_count);
>>  		strbuf_addstr(&buf, "\n\n");
>>  		strbuf_add_commented_lines(&buf, body, strlen(body));
>>  	} else
>>  		return error(_("unknown command: %d"), command);
>>  	unuse_commit_buffer(commit, message);
>> +	opts->current_fixup_count++;
>>  
>>  	res = write_message(buf.buf, buf.len, rebase_path_squash_msg(), 0);
>>  	strbuf_release(&buf);
>> 
>> 
Previous: Phillip WoodNext: Johannes Schindelin
Message 4 of 5 in “rebase -i: fix numbering in squash message”
  1. rebase -i: fix numbering in squash messagePhillip Wood, Aug 15, 2018
  2. Junio C HamanoAug 15, 2018
  3. Phillip WoodAug 15, 2018
  4. Junio C HamanoAug 15, 2018
  5. Johannes SchindelinAug 16, 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.