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

Re: [PATCH v2 1/2] trailer: append trailers in-process and drop the fork to `interpret-trailers`

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 11, 2025, 00:09 UTC
Message-ID
<xmqq8qlzkukw.fsf@gitster.g>
In-Reply-To
<20250610123459.278582-2-me@linux.beauty>
Li Chen <me@linux.beauty> writes:
Show 6 quoted lines
> * `amend_strbuf_with_trailers()`
>   – parses the existing message,
>   – merges trailers from the command line and config,
>   – formats the final trailer block, and
>   – rewrites the supplied `struct strbuf`
>   without ever leaving the current process.

If such a helper function exists, shouldn't "interpret-trailers" be able to lose quite a lot of lines, at least nearly as many as the new lines introduced to this new function, by making it call this function as well? And that would ensure that the internal call can safely replace the external call and produce exactly the same output? If so, that can be a pure refactoring patch that can become a commit on its own, I presume?

> * `amend_file_with_trailers()` becomes a thin wrapper that reads a file
>   into a `strbuf`, calls the new helper, and writes the result back.
> * `builtin/rebase.c` now calls `amend_file_with_trailers()` instead of
>   executing `interpret-trailers`.
And then these two changes can become a separate patch on top?
> -int amend_file_with_trailers(const char *path, const struct strvec *trailer_args)

This lone "removed line" can be avoided if the patch did not touch this line ...

Show 35 quoted lines
> +static size_t first_comment_pos(const struct strbuf *buf)
>  {
> -	struct child_process run_trailer = CHILD_PROCESS_INIT;
> -
> -	run_trailer.git_cmd = 1;
> -	strvec_pushl(&run_trailer.args, "interpret-trailers",
> -		     "--in-place", "--no-divider",
> -		     path, NULL);
> -	strvec_pushv(&run_trailer.args, trailer_args->v);
> -	return run_command(&run_trailer);
> +	const char *p = buf->buf;
> +	const char *end = buf->buf + buf->len;
> +
> +	while (p < end) {
> +		const char *line = p;
> +		const char *nl = memchr(p, '\n', end - p);
> +		size_t len = nl ? (size_t)(nl - p) : (size_t)(end - p);
> +
> +		/* skip leading whitespace */
> +		size_t i = 0;
> +		while (i < len && isspace((unsigned char)line[i]))
> +			i++;
> +
> +		if (i < len && line[i] == '#')
> +			return (size_t)(line - buf->buf); /* comment starts here */
> +
> +		if (!nl)              /* last line without newline */
> +			break;
> +		p = nl + 1;
> +	}
> +	return buf->len;          /* no comment line found */
> +}
> +
> +int amend_strbuf_with_trailers(struct strbuf *buf,
> +							   const struct strvec *trailer_args)
... like this?
Previous: Li ChenNext: phillip.wood123@gmail.com
Message 3 of 7 in “rebase: support --trailer”
  1. 0/2 rebase: support --trailerLi Chen, Jun 10, 2025
  2. 1/2 trailer: append trailers in-process and drop the fork to `interpret-trailers`Li Chen, Jun 10, 2025
  3. Junio C HamanoJun 11, 2025
  4. phillip.wood123@gmail.comJun 11, 2025
  5. Junio C HamanoJun 11, 2025
  6. Li ChenJun 12, 2025
  7. 2/2 rebase: support --trailerLi Chen, Jun 10, 2025

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.