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

Re: [PATCH 1/2] rebase -i: fix counting of fixups after rebase --skip

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 24, 2026, 21:01 UTC
Message-ID
<xmqqbjbw5cgx.fsf@gitster.g>
In-Reply-To
<c37a518486a8fa9832a6dbbe6048cda70af87d73.1784304378.git.phillip.wood@dunelm.org.uk>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 15 quoted lines
> @@ -3281,7 +3281,13 @@ static int read_populate_opts(struct replay_opts *opts)
>  			const char *p = ctx->current_fixups.buf;
>  			ctx->current_fixup_count = 1;
>  			while ((p = strchr(p, '\n'))) {
> -				ctx->current_fixup_count++;
> +				/*
> +				 * Older versions of git accidentally
> +				 * inserted blank lines when a fixup
> +				 * was skipped.
> +				 */
> +				if (p[1] != '\n')
> +					ctx->current_fixup_count++;
>  				p++;
>  			}
>  		}

If we hit the LF at the very end (e.g. "fixup A\n" at the end of the file), strchr() would have moved p to the newline, and p[1] will be '\0', no? And because p[1] != '\n' and wouldn't current_fixup_count be incremented again? It might be safer to check p[1] != '\n' && p[1] != '\0' to avoid counting a trailing newline as an extra command when reading legacy files.

Show 8 quoted lines
> @@ -5353,6 +5359,9 @@ static int commit_staged_changes(struct repository *r,
>  			if (!len)
>  				BUG("Incorrect current_fixups:\n%s", p);
>  			while (len && p[len - 1] != '\n')
> +				len--;
> +			/* Remove trailing newline */
> +			if (len)
>  				len--;

So we removed all the non newline from the end, and the loop would break if !len or p[len - 1] == '\n'. And in the latter case, we also drop that '\n'. Which sounds right.

Thanks.
Previous: Phillip WoodNext: Phillip Wood
Message 3 of 10 in “rebase: a couple of fixup fixes”
  1. 0/2 rebase: a couple of fixup fixesPhillip Wood, Jul 17, 2026
  2. 1/2 rebase -i: fix counting of fixups after rebase --skipPhillip Wood, Jul 17, 2026
  3. Junio C HamanoJul 24, 2026
  4. 2/2 rebase: remember fixup -c after skipping fixup/squashPhillip Wood, Jul 17, 2026
  5. Junio C HamanoJul 24, 2026
  6. Phillip WoodJul 26, 2026
  7. Junio C HamanoJul 26, 2026
  8. 0/2 rebase: a couple of fixup fixesPhillip Wood, Jul 26, 2026
  9. 1/2 rebase -i: fix counting of fixups after rebase --skipPhillip Wood, Jul 26, 2026
  10. 2/2 rebase: remember fixup -c after skipping fixup/squashPhillip Wood, Jul 26, 2026

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.