git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / Atom feed
* [PATCH] refs: add \t to reflog in the files backend
@ 2020-07-31 11:36 Han-Wen Nienhuys via GitGitGadget
  2020-07-31 17:17 ` Junio C Hamano
  2020-07-31 17:36 ` Jeff King
  0 siblings, 2 replies; 3+ messages in thread
From: Han-Wen Nienhuys via GitGitGadget @ 2020-07-31 11:36 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys, Han-Wen Nienhuys

From: Han-Wen Nienhuys <hanwen@google.com>

commit 523fa69c3 (Jul 10, 2020) "reflog: cleanse messages in the
refs.c layer" centralized reflog normalizaton.  However, the
normalizaton added a leading "\t" to the message. This is an artifact
of the reflog storage format in the files backend, so it should be
added there.

Routines that parse back the reflog (such as grab_nth_branch_switch)
expect the "\t" to not be in the message, so without this fix, git
with reftable cannot process the "@{-1}" syntax.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
    refs: add \t to reflog in the files backend
    
    commit 523fa69c3 (Jul 10, 2020) "reflog: cleanse messages in the refs.c
    layer" centralized reflog normalizaton. However, the normalizaton added
    a leading "\t" to the message. This is an artifact of the reflog storage
    format in the files backend, so it should be added there.
    
    Routines that parse back the reflog (such as grab_nth_branch_switch)
    expect the "\t" to not be in the message, so without this fix, git with
    reftable cannot process the "@{-1}" syntax.
    
    Signed-off-by: Han-Wen Nienhuys hanwen@google.com [hanwen@google.com]

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-688%2Fhanwen%2Ftab-reflog-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-688/hanwen/tab-reflog-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/688

 refs.c               | 1 -
 refs/files-backend.c | 4 +++-
 2 files changed, 3 insertions(+), 2 deletions(-)

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);
+	}
 	strbuf_addch(&sb, '\n');
 	if (write_in_full(fd, sb.buf, sb.len) < 0)
 		ret = -1;

base-commit: e8ab941b671da6890181aea5b5755d1d9eea24ec
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] refs: add \t to reflog in the files backend
  2020-07-31 11:36 [PATCH] refs: add \t to reflog in the files backend Han-Wen Nienhuys via GitGitGadget
@ 2020-07-31 17:17 ` Junio C Hamano
  2020-07-31 17:36 ` Jeff King
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2020-07-31 17:17 UTC (permalink / raw)
  To: Han-Wen Nienhuys via GitGitGadget; +Cc: git, Han-Wen Nienhuys, Han-Wen Nienhuys

"Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Han-Wen Nienhuys <hanwen@google.com>
>
> commit 523fa69c3 (Jul 10, 2020) "reflog: cleanse messages in the
> refs.c layer" centralized reflog normalizaton.  However, the
> normalizaton added a leading "\t" to the message. This is an artifact
> of the reflog storage format in the files backend, so it should be
> added there.

I agree with you that it makes sense to move the logic to add "\t"
before the log message from generic layer to the backend.  Thanks
for spotting and correcting.

Will queue.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] refs: add \t to reflog in the files backend
  2020-07-31 11:36 [PATCH] refs: add \t to reflog in the files backend Han-Wen Nienhuys via GitGitGadget
  2020-07-31 17:17 ` Junio C Hamano
@ 2020-07-31 17:36 ` Jeff King
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2020-07-31 17:36 UTC (permalink / raw)
  To: Han-Wen Nienhuys via GitGitGadget; +Cc: git, Han-Wen Nienhuys, Han-Wen Nienhuys

On Fri, Jul 31, 2020 at 11:36:10AM +0000, Han-Wen Nienhuys via GitGitGadget wrote:

> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-31 17:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31 11:36 [PATCH] refs: add \t to reflog in the files backend Han-Wen Nienhuys via GitGitGadget
2020-07-31 17:17 ` Junio C Hamano
2020-07-31 17:36 ` Jeff King

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git