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

Re: [PATCH 2/4] rebase: avoid double reflog entry when switching branches

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 4, 2019, 18:38 UTC
Message-ID
<xmqqimz4cloh.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<4c5f87b9dc245bf27785aa5559d4b35d87c4bcbf.1545398254.git.gitgitgadget@gmail.com>

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 5 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> When switching a branch *and* updating said branch to a different
> revision, let's avoid a double entry by first updating the branch and
> then adjusting the symbolic ref HEAD.

Ah, in the original sequence, HEAD is updated twice, leaving two reflog entries for HEAD (and one for the underlying "switch_to" branch by virtue of REF_UPDATE_VIA_HEAD). In the new sequence, update_ref() updates the underlying "switch_to" and then HEAD, so we'd get one reflog entry for each of them.

Makes sense. s/let's avoid a double entry/& in HEAD's reflog/ would have avoided wasting reader's time who needlessly wondered where that redundancy came from, though.

Show 25 quoted lines
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  builtin/rebase.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index e1dfa74ca8..768bea0da8 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -438,10 +438,11 @@ static int reset_head(struct object_id *oid, const char *action,
>  				 detach_head ? REF_NO_DEREF : 0,
>  				 UPDATE_REFS_MSG_ON_ERR);
>  	else {
> -		ret = create_symref("HEAD", switch_to_branch, msg.buf);
> +		ret = update_ref(reflog_orig_head, switch_to_branch, oid,
> +				 NULL, 0, UPDATE_REFS_MSG_ON_ERR);
>  		if (!ret)
> -			ret = update_ref(reflog_head, "HEAD", oid, NULL, 0,
> -					 UPDATE_REFS_MSG_ON_ERR);
> +			ret = create_symref("HEAD", switch_to_branch,
> +					    reflog_head);
>  	}
>  
>  leave_reset_head:
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin
Message 3 of 27 in “Let the builtin rebase call the git am command directly”
  1. 0/4 Let the builtin rebase call the git am command directlyJohannes Schindelin via GitGitGadget, Dec 21, 2018
  2. 2/4 rebase: avoid double reflog entry when switching branchesJohannes Schindelin via GitGitGadget, Dec 21, 2018
  3. Junio C HamanoJan 4, 2019
  4. Johannes SchindelinJan 18, 2019
  5. 1/4 rebase: move `reset_head()` into a better spotJohannes Schindelin via GitGitGadget, Dec 21, 2018
  6. Junio C HamanoJan 4, 2019
  7. 3/4 rebase: teach `reset_head()` to optionally skip the worktreeJohannes Schindelin via GitGitGadget, Dec 21, 2018
  8. Junio C HamanoJan 4, 2019
  9. Junio C HamanoJan 4, 2019
  10. Johannes SchindelinJan 18, 2019
  11. 4/4 built-in rebase: call `git am` directlyJohannes Schindelin via GitGitGadget, Dec 21, 2018
  12. Junio C HamanoJan 4, 2019
  13. Johannes SchindelinJan 18, 2019
  14. Junio C HamanoJan 18, 2019
  15. Johannes SchindelinJan 18, 2019
  16. Junio C HamanoJan 4, 2019
  17. Junio C HamanoJan 7, 2019
  18. 0/4 Let the builtin rebase call the git am command directlyJohannes Schindelin via GitGitGadget, Jan 18, 2019
  19. 1/4 rebase: move `reset_head()` into a better spotJohannes Schindelin via GitGitGadget, Jan 18, 2019
  20. 2/4 rebase: avoid double reflog entry when switching branchesJohannes Schindelin via GitGitGadget, Jan 18, 2019
  21. 3/4 rebase: teach `reset_head()` to optionally skip the worktreeJohannes Schindelin via GitGitGadget, Jan 18, 2019
  22. 4/4 built-in rebase: call `git am` directlyJohannes Schindelin via GitGitGadget, Jan 18, 2019
  23. Alban GruinJan 26, 2019
  24. Johannes SchindelinJan 29, 2019
  25. Junio C HamanoJan 18, 2019
  26. Junio C HamanoJan 18, 2019
  27. Johannes SchindelinJan 18, 2019

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.