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

Re: [PATCH] refs: add \t to reflog in the files backend

From
Jeff King <peff@peff.net>
Date
Jul 31, 2020, 17:36 UTC
Message-ID
<20200731173649.GA843002@coredump.intra.peff.net>
In-Reply-To
<pull.688.git.1596195370757.gitgitgadget@gmail.com>
On Fri, Jul 31, 2020 at 11:36:10AM +0000, Han-Wen Nienhuys via GitGitGadget wrote:
Show 25 quoted lines
> diff --git a/refs.c b/refs.c
> index 89814c7be4..2dd851fe81 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -907,7 +907,6 @@ static void copy_reflog_msg(struct strbuf *sb, const char *msg)
>  	char c;
>  	int wasspace = 1;
>  
> -	strbuf_addch(sb, '\t');
>  	while ((c = *msg++)) {
>  		if (wasspace && isspace(c))
>  			continue;
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index e0aba23eb2..985631f33e 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -1628,8 +1628,10 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
>  	int ret = 0;
>  
>  	strbuf_addf(&sb, "%s %s %s", oid_to_hex(old_oid), oid_to_hex(new_oid), committer);
> -	if (msg && *msg)
> +	if (msg && *msg) {
> +		strbuf_addch(&sb, '\t');
>  		strbuf_addstr(&sb, msg);
> +	}

I wondered here whether the existing code would always write the tab, even for an entry with no message, since we seem to unconditionally add the tab in the hunk above.

But it looks like we only call copy_reflog_msg() if it's non-empty:
  static char *normalize_reflog_message(const char *msg)
  {
          struct strbuf sb = STRBUF_INIT;
  
          if (msg && *msg)
                  copy_reflog_msg(&sb, msg);
          return strbuf_detach(&sb, NULL);
  }

so this is retaining that behavior (and indeed, doing a simple "git update-ref" confirms that we currently omit the tab in this case).

So the patch looks good (and the intent seems obviously good to me, as well).

-Peff
Previous: Junio C Hamano
Message 3 of 3 in “refs: add \t to reflog in the files backend”
  1. refs: add \t to reflog in the files backendHan-Wen Nienhuys via GitGitGadget, Jul 31, 2020
  2. Junio C HamanoJul 31, 2020
  3. Jeff KingJul 31, 2020

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.