All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Cc: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
	"D. Ben Knoble" <ben.knoble@gmail.com>,
	Harald Nordgren <haraldnordgren@gmail.com>
Subject: Re: [PATCH v4 0/2] reflog: add format %gb
Date: Fri, 6 Nov 2026 11:08:05 +0000	[thread overview]
Message-ID: <edd1c36a-bd2a-4bcf-a6b1-3e08dfcda344@gmail.com> (raw)
In-Reply-To: <pull.2448.v4.git.git.1793826938.gitgitgadget@gmail.com>

Hi Harald

On 04/11/2026 21:15, Harald Nordgren via GitGitGadget wrote:
> 
> It follows branch switches, branch renames and rebases, including "git
> rebase ", rebases of a detached HEAD and rebases of a branch that was
> already up to date. When HEAD was detached, the entry shows "detached at ".

The "detached at " labels show the commit before we switch away from a
detached HEAD, not the commit where HEAD was detached. The parsing of
"rebase: checkout <revision>" is still not quite right - it treats
"origin/main" as a branch name and is confused by commits where the
subject starts with "checkout " (I think the way to avoid that is to
check that the reflog message does not match the commit subject [1]).
Here is a failing test for those issues which also checks we handle
':' in a url in $GIT_REFLOG_ACTION correctly.

test_expect_success '%gb labels branches and detached HEADs' '
	test_create_repo origin &&
	(
		cd origin &&
		test_commit O1 &&
		test_commit O2
	) &&
	git clone origin downstream &&
	(
		cd origin &&
		test_commit O3
	) &&
	(
		cd downstream &&
		test_commit L1 &&
		git branch side &&
		test_commit L2 &&
		git pull -r "file://$TRASH_DIRECTORY/origin" &&
		test_commit L3 &&
		GIT_REFLOG_ACTION="sync switch" git rebase -i FETCH_HEAD side^0 &&
		H1=$(git rev-parse --short HEAD) &&
		test_commit "checkout main" L4.t L4 L4 &&
		git rebase FETCH_HEAD side &&
		test_commit L5 &&
		git rebase origin/main origin/main &&
		H2=$(git rev-parse --short HEAD) &&
		test_commit L6 &&
		git rebase main refs/heads/main &&
		H3=$(git rev-parse --short HEAD) &&
		test_commit L7 &&
		git switch side &&
		test_commit L8 &&
		git checkout origin/main &&
		H4=$(git rev-parse --short HEAD) &&
		test_commit L9 &&

		cat >expect <<-EOF &&
		commit: l9 (detached at $H4) &&
		checkout: moving from side to origin/main (detached at $H4)
		commit: L8 (side)
		checkout: moving from $(git rev-parse L7) to side (side)
		commit: L7 (detached at $H3)
		rebase: checkout refs/heads/main (detached at $H3)
		commit: L6 (detached at $H2)
		rebase: checkout origin/main (detached at $H2)
		commit: L5 (side)
		rebase (finish): returning to refs/heads/side (side)
		rebase (pick): L1 (side)
		rebase (start): checkout FETCH_HEAD (side)
		commit: checkout main (detached at $H1)
		sync switch (pick): L1 (detached at $H1)
		sync switch (start): checkout FETCH_HEAD (detached at $H1)
		commit: L3 (main)
		pull -r file://$TRASH_DIRECTORY/origin (finish): returning to refs/heads/main (main)
		pull -r file://$TRASH_DIRECTORY/origin (pick): L2 (main)
		pull -r file://$TRASH_DIRECTORY/origin (pick): L1 (main)
		pull -r file://$TRASH_DIRECTORY/origin (start): checkout $(git rev-parse FETCH_HEAD) (main)
		commit: L2 (main)
		commit: L1 (main)
		clone: from $TRASH_DIRECTORY/origin (main)
		EOF

		git log -g --format="%gs (%gb)" >actual &&
		test_cmp expect actual
	)
'

Thanks

Phillip

[1] https://github.com/phillipwood/git/blob/c11b0dcb38d4dbe26c41053569d4fae27fdf0de6/object-name.c#L1301

> 
> Changes in v4:
> 
>   * %gb now names the right branch when git rebase <upstream> <branch> runs
>     with GIT_REFLOG_ACTION set.
>   * Reworded the %gb commit message.
> 
> Changes in v3:
> 
>   * Dropped --operations.
>   * Replaced --historical-branch with a %gb placeholder for --format, e.g.
>     git log -g --format='%h %gd: (%gb) %gs'.
>   * %gb names the right branch after git rebase <upstream> <branch>, a rebase
>     of a detached HEAD and an up-to-date rebase.
>   * Named the returning to and checkout reflog strings in reflog.h too.
> 
> Changes in v2:
> 
>   * Move the "historical branch" rightward in the display for cleaner
>     alignment.
>   * Improve commit messages.
> 
> Harald Nordgren (2):
>    reflog: name the strings that mark switches, renames and rebase steps
>    pretty: add %gb to name the branch of each reflog entry
> 
>   Documentation/pretty-formats.adoc |   3 +
>   builtin/branch.c                  |   3 +-
>   builtin/checkout.c                |   3 +-
>   builtin/rebase.c                  |  19 ++--
>   object-name.c                     |   3 +-
>   pretty.c                          |   4 +
>   reflog-walk.c                     | 167 ++++++++++++++++++++++++++++--
>   reflog-walk.h                     |   2 +
>   reflog.h                          |   8 ++
>   sequencer.c                       |  13 +--
>   t/t1414-reflog-walk.sh            | 137 ++++++++++++++++++++++++
>   wt-status.c                       |   3 +-
>   12 files changed, 340 insertions(+), 25 deletions(-)
> 
> 
> base-commit: 750f5de7dfe9a4062f95088212b063f189d50e91
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2448%2FHaraldNordgren%2Freflog-operations-v4
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2448/HaraldNordgren/reflog-operations-v4
> Pull-Request: https://github.com/git/git/pull/2448
> 
> Range-diff vs v3:
> 
>   1:  4d779e8da3 = 1:  f960a24b8b reflog: name the strings that mark switches, renames and rebase steps
>   2:  dee548f9b1 ! 2:  99a1047702 pretty: add %gb to name the branch of each reflog entry
>       @@ Commit message
>                1a2b3c4 HEAD@{3}: (main) commit: fix typo
>                5d6e7f8 HEAD@{4}: (main) checkout: moving from topic to main
>        
>       -    The branch is read from the entries that branch switches, branch
>       -    renames and rebases leave behind. The entries of a rebase are named
>       -    after the branch being rebased. When HEAD was detached, the entry
>       -    shows "detached at <commit>" with the commit HEAD was at when it
>       -    moved on. When nothing older in the reflog says which branch a rebase
>       -    started on, the rebase is taken to have started on the branch it
>       -    rebased. For the reflog of any other ref, "%gb" is the name of that
>       -    ref.
>       +    The branch is read from the entries created by branch switches,
>       +    branch renames and rebases. The entries of a rebase are labeled with
>       +    the branch being rebased. When HEAD was detached, the entry shows
>       +    "detached at <commit>" with the commit HEAD was at when it moved on.
>       +    When nothing older in the reflog says which branch a rebase started
>       +    on, the rebase is taken to have started on the branch it rebased. For
>       +    the reflog of any other ref, "%gb" is the name of that ref.
>        
>            Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
>        
>       @@ reflog-walk.c: static void complete_reflogs_clear(void *util, const char *str UN
>        +	return p;
>        +}
>        +
>       ++static const char *skip_rebase_checkout(const char *message)
>       ++{
>       ++	const char *p = strstr(message, " (");
>       ++	const char *colon = strstr(message, ": ");
>       ++
>       ++	if (!colon || (p && p < colon) ||
>       ++	    !skip_prefix(colon + 2, REFLOG_CHECKOUT, &p))
>       ++		return NULL;
>       ++	return p;
>       ++}
>       ++
>        +struct branch_move {
>        +	const char *from, *to;
>        +	size_t from_len, to_len;
>       @@ reflog-walk.c: static void complete_reflogs_clear(void *util, const char *str UN
>        +		   skip_prefix(to, REFLOG_RETURNING_TO, &to)) {
>        +		move->from = move->to = to;
>        +		move->from_len = strcspn(to, "\n");
>       -+	} else if (skip_prefix(message, "rebase: " REFLOG_CHECKOUT, &to)) {
>       ++	} else if ((to = skip_rebase_checkout(message))) {
>        +		move->to = to;
>        +	} else if (!skip_rebase_step(message, REFLOG_STEP_START)) {
>        +		return false;
>       @@ t/t1414-reflog-walk.sh: test_expect_success 'walk prefers reflog to ref tip' '
>        +	)
>        +'
>        +
>       ++test_expect_success '%gb follows "git rebase <upstream> <branch>" with GIT_REFLOG_ACTION' '
>       ++	(
>       ++		cd branches &&
>       ++		git switch main &&
>       ++		GIT_REFLOG_ACTION="sync switch" git rebase main topic &&
>       ++
>       ++		cat >expect <<-\EOF &&
>       ++		(topic) sync switch: checkout topic
>       ++		(main) checkout: moving from topic to main
>       ++		EOF
>       ++		git log -g -2 --format="(%gb) %gs" >actual &&
>       ++		test_cmp expect actual
>       ++	)
>       ++'
>       ++
>        +test_expect_success '%gb names a detached HEAD by the commit it was left at' '
>        +	(
>        +		cd branches &&
> 


  parent reply	other threads:[~2026-11-06 11:08 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 13:13 [PATCH 0/3] reflog: add --operations and --historical-branch Harald Nordgren via GitGitGadget
2026-10-15 13:13 ` [PATCH 1/3] reflog: name the strings that mark switches, renames and rebase steps Harald Nordgren via GitGitGadget
2026-10-15 14:35   ` Kristoffer Haugsbakk
2026-10-15 20:52     ` Harald Nordgren
2026-10-15 13:13 ` [PATCH 2/3] reflog: add --operations to show one entry per command Harald Nordgren via GitGitGadget
2026-10-15 13:13 ` [PATCH 3/3] reflog: add --historical-branch to name the branch of each entry Harald Nordgren via GitGitGadget
2026-10-15 14:36 ` [PATCH 0/3] reflog: add --operations and --historical-branch Kristoffer Haugsbakk
2026-10-15 15:24   ` Harald Nordgren
2026-10-15 15:35     ` Kristoffer Haugsbakk
2026-10-15 20:47       ` Harald Nordgren
2026-10-16 18:26     ` D. Ben Knoble
2026-10-23 15:31   ` Harald Nordgren
2026-10-16 18:36 ` D. Ben Knoble
2026-10-17 10:03   ` Harald Nordgren
2026-10-18 18:27 ` [PATCH v2 " Harald Nordgren via GitGitGadget
2026-10-18 18:27   ` [PATCH v2 1/3] reflog: name the strings that mark switches, renames and rebase steps Harald Nordgren via GitGitGadget
2026-10-23 21:19     ` Junio C Hamano
2026-10-23 22:47       ` Harald Nordgren
2026-10-23 22:55         ` Junio C Hamano
2026-10-18 18:27   ` [PATCH v2 2/3] reflog: add --operations to show one entry per command Harald Nordgren via GitGitGadget
2026-10-18 18:27   ` [PATCH v2 3/3] reflog: add --historical-branch to name the branch of each entry Harald Nordgren via GitGitGadget
2026-10-25 19:18     ` Kristoffer Haugsbakk
2026-10-25 20:22       ` Harald Nordgren
2026-10-26  8:39         ` Kristoffer Haugsbakk
2026-10-26  8:42           ` Harald Nordgren
2026-10-23 15:32   ` [PATCH v2 0/3] reflog: add --operations and --historical-branch Harald Nordgren
2026-10-24 13:51   ` Phillip Wood
2026-10-24 15:22     ` D. Ben Knoble
2026-10-24 16:40     ` Junio C Hamano
2026-10-24 18:46       ` Harald Nordgren
2026-10-25 18:52         ` Kristoffer Haugsbakk
2026-10-26 10:52       ` Phillip Wood
2026-10-26 11:00         ` Harald Nordgren
2026-10-26 15:07           ` Junio C Hamano
2026-10-27 13:40             ` Ben Knoble
2026-10-27 19:24               ` Junio C Hamano
2026-10-27 19:33               ` Harald Nordgren
2026-10-27 13:37         ` Ben Knoble
2026-10-24 19:12     ` Harald Nordgren
2026-10-27  8:38 ` [PATCH v3 0/2] " Harald Nordgren via GitGitGadget
2026-10-27  8:38   ` [PATCH v3 1/2] reflog: name the strings that mark switches, renames and rebase steps Harald Nordgren via GitGitGadget
2026-10-27  8:38   ` [PATCH v3 2/2] pretty: add %gb to name the branch of each reflog entry Harald Nordgren via GitGitGadget
2026-11-03 16:16     ` Phillip Wood
2026-11-04 21:15 ` [PATCH v4 0/2] reflog: add format %gb Harald Nordgren via GitGitGadget
2026-11-04 21:15   ` [PATCH v4 1/2] reflog: name the strings that mark switches, renames and rebase steps Harald Nordgren via GitGitGadget
2026-11-04 21:15   ` [PATCH v4 2/2] pretty: add %gb to name the branch of each reflog entry Harald Nordgren via GitGitGadget
2026-11-06 11:08   ` Phillip Wood [this message]
2026-11-07  9:59     ` [PATCH v4 0/2] reflog: add format %gb Harald Nordgren
2026-11-07 11:55 ` [PATCH v5 " Harald Nordgren via GitGitGadget
2026-11-07 11:55   ` [PATCH v5 1/2] reflog: name the strings that mark switches, renames and rebase steps Harald Nordgren via GitGitGadget
2026-11-07 11:55   ` [PATCH v5 2/2] pretty: add %gb to name the branch of each reflog entry Harald Nordgren via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=edd1c36a-bd2a-4bcf-a6b1-3e08dfcda344@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=ben.knoble@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=haraldnordgren@gmail.com \
    --cc=kristofferhaugsbakk@fastmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.