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

Re: [PATCH] log: --remerge-diff needs to keep around commit parents

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 11, 2024, 01:46 UTC
Message-ID
<xmqq7c9ak0e9.fsf@gitster.g>
In-Reply-To
<pull.1825.git.1731073435641.gitgitgadget@gmail.com>

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

Show 10 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> To show a remerge diff, the merge needs to be recreated. For that to
> work, the merge base(s) need to be found, which means that the commits'
> parents have to be traversed until common ancestors are found (if any).
>
> However, one optimization that hails all the way back to
> cb115748ec0d (Some more memory leak avoidance, 2006-06-17) is to release
> the commit's list of parents immediately after showing it. This can break
> the merge base computation.
Show 5 quoted lines
> Note that it matters more clearly when traversing the commits in
> reverse: In that instance, if a parent of a merge commit has been shown
> as part of the `git log` command, by the time the merge commit's diff
> needs to be computed, that parent commit's list of parent commits will
> have been set to `NULL` and as a result no merge base will be found.
Ouch.

I am curious about "more clearly" in the above, though. Do we also lose parents before a base can be computed during a forward traversal? Unlike the reflog walk, we won't show the same commit twice, so unless we are traversing some of the history of our parents *and* showing these ancestors found there _before_ we need to show the merge in question, I do not think the issue would surface during a forward traversal. So the problematic case is when we are not doing topological display, and traversing down to a commit with skewed timestamp causes it to be shown (and lose its parents due to memory optimization) because it appears much newer than our merge, and there is an ancestry chain leading to it that passes commits other than our merge, or something?

> Let's fix this by special-casing the `remerge_diff` mode, similar to
> what we did with reflogs in f35650dff6a4 (log: do not free parents when
> walking reflog, 2017-07-07).
OK.
Show 13 quoted lines
> diff --git a/builtin/log.c b/builtin/log.c
> index c0a8bb95e98..a297c6caf59 100644
> --- a/builtin/log.c
> +++ b/builtin/log.c
> @@ -522,7 +522,7 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
>  			 * but we didn't actually show the commit.
>  			 */
>  			rev->max_count++;
> -		if (!rev->reflog_info) {
> +		if (!rev->reflog_info && !rev->remerge_diff) {
>  			/*
>  			 * We may show a given commit multiple times when
>  			 * walking the reflogs.
OK, that's trivial ;-)
Show 14 quoted lines
> diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh
> index 07323ebafe0..a68c6bfa036 100755
> --- a/t/t4069-remerge-diff.sh
> +++ b/t/t4069-remerge-diff.sh
> @@ -317,4 +317,11 @@ test_expect_success 'remerge-diff turns off history simplification' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'remerge-diff with --reverse' '
> +	git log -1 --remerge-diff --oneline ab_resolution^ >expect &&
> +	git log -1 --remerge-diff --oneline ab_resolution >>expect &&
> +	git log -2 --remerge-diff --oneline ab_resolution --reverse >actual &&
> +	test_cmp expect actual
> +'

This is the trivially reproducible "show in reverse" case. Nice finding.

Will queue.
Previous: Junio C HamanoNext: Johannes Schindelin
Message 4 of 9 in “log: --remerge-diff needs to keep around commit parents”
  1. log: --remerge-diff needs to keep around commit parentsJohannes Schindelin via GitGitGadget, Nov 8, 2024
  2. Elijah NewrenNov 8, 2024
  3. Junio C HamanoNov 11, 2024
  4. Junio C HamanoNov 11, 2024
  5. Johannes SchindelinNov 11, 2024
  6. Junio C HamanoNov 11, 2024
  7. log: --remerge-diff needs to keep around commit parentsJohannes Schindelin via GitGitGadget, Nov 11, 2024
  8. log: --remerge-diff needs to keep around commit parentsJohannes Schindelin via GitGitGadget, Dec 12, 2024
  9. Junio C HamanoDec 13, 2024

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.