git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Derrick Stolee <stolee@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
	Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, peff@peff.net, me@ttaylorr.com,
	philipoakley@iee.email, sandals@crustytoothpaste.net,
	Johannes.Schindelin@gmx.de,
	Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH v3] revision: --show-pulls adds helpful merges
Date: Fri, 10 Apr 2020 17:43:05 -0400	[thread overview]
Message-ID: <28075cfb-34bb-1109-5685-8d662e7559c3@gmail.com> (raw)
In-Reply-To: <xmqq369bjebo.fsf@gitster.c.googlers.com>

On 4/10/2020 4:06 PM, Junio C Hamano wrote:
> "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>>   A----C1----C2--- ... ---Cn----M------P1---P2--- ... ---Pn
>>    \     \     \            \  /      /    /            /
>>     \     \__.. \            \/ ..__T1    /           Tn
>>      \           \__..       /\     ..__T2           /
>>       \_____________________B  \____________________/
>>
>> If the commits T1, T2, ... Tn did not change the file, then all of
>> P1 through Pn will be TREESAME to their first parent, but not
>> TREESAME to their second. This means that all of those merge commits
>> appear in the --full-history view, with edges that immediately
>> collapse into the lower history without introducing interesting
>> single-parent commits.
>>
>> The --simplify-merges option was introduced to remove these extra
>> merge commits. By noticing that the rewritten parents are reachable
>> from their first parents, those edges can be simplified away. Finally,
>> the commits now look like single-parent commits that are TREESAME to
>> their "only" parent. Thus, they are removed and this issue does not
>> cause issues anymore. However, this also ends up removing the commit
>> M from the history view! Even worse, the --simplify-merges option
>> requires walking the entire history before returning a single result.
> 
> True.  It is not advisable to use --simplify-merges unless you are
> limiting the history at the bottom for that reason.

I will modify my advice to include this "limiting the history at the
bottom" advice.

>> In some sense, users are asking for the "first" merge commit to
>> bring in the change to their branch. As long as the parent order is
>> consistent, this can be handled with the following rule:
>>
>>   Include a merge commit if it is not TREESAME to its first
>>   parent, but is TREESAME to a later parent.
> 
> "but is" -> "even if it is" would make it a bit more accurate, I
> would think.  Normally, such a merge that is treesame to some side
> branch is omitted from the output, but the rule wants it to be shown
> even if all the changes were brought in from one single parent.

This is an excellent clarification, since the way I wrote it does not
describe every merge that we include. I wrote it to include the "extra"
merges that are included. A better strategy is to include a complete
description of every merge commit that appears in the output, as you
defined it.

>> Update Documentation/rev-list-options.txt with significant details
>> around this option. This requires updating the example in the
>> History Simplification section to demonstrate some of the problems
>> with TREESAME second parents.
> 
> Good.
> 
>> diff --git a/revision.c b/revision.c
>> index 8136929e236..f89dd6caa55 100644
>> --- a/revision.c
>> +++ b/revision.c
>> @@ -870,7 +870,19 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
>>  			}
>>  			parent->next = NULL;
>>  			commit->parents = parent;
>> -			commit->object.flags |= TREESAME;
>> +
>> +			/*
>> +			 * A merge commit is a "diversion" if it is not
>> +			 * TREESAME to its first parent but is TREESAME
>> +			 * to a later parent. In the simplified history,
>> +			 * we "divert" the history walk to the later
>> +			 * parent. These commits are shown when "show_pulls"
>> +			 * is enabled, so do not mark the object as
>> +			 * TREESAME here.
> 
> As we no longer use the word "diversion", this explanation should
> shift the focus from defining the word "diversion" and giving its
> background to explaining why the above parent rewriting is done and
> why the TREESAME marking is conditional, e.g.

Sorry about this. I intended to replace all references to this old
terminology, but failed.

>       			The tree of the merge and of the parent are
>       			the same; from here on, we stop following
>       			histories of all other parents but this one
>       			by culling commit->parents list.  We also
>       			normally mark the merge commit TREESAME as
>       			the merge itself did not introduce any
>       			change relative to the parent, but we
>       			refrain from doing so for the first parent
>       			under "--show-pulls" mode, in order to let
>       			the output phase to show the merge, which is
>       			the last commit before we divert our walk to
>       			a side history.
> 
> or something along that line.

This is pretty good. I plan to take it with very minor modifications in my
next version.

> 
>> +			if (!revs->show_pulls || !nth_parent)
>> +				commit->object.flags |= TREESAME;
>> +
>>  			return;
> 
>> @@ -897,6 +909,10 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
>>  				relevant_change = 1;
>>  			else
>>  				irrelevant_change = 1;
>> +
>> +			if (!nth_parent)
>> +				commit->object.flags |= PULL_MERGE;
> 
> For a three-parent merge that brings in changes to the first parent,
> if the result matches the second parent, we would have returned in
> the previous hunk before having a chance to inspect the third one
> and marking the merge result with PULL_MERGE, but if you swap the
> order of the second and the third parent, the second parent, which
> has different tree from the result, would not return in the previous
> hunk and cause the merge with PULL_MERGE here.  And then when we
> inspect the third parent, the previous hunk's return would kick in.
> So for two merges that merge exactly the same two branches on top of
> exactly the same commit on the mainline, you sometimes mark the
> result with PULL_MERGE and sometimes don't, depending on the order
> of the second and the third parent.
> 
> That feels iffy.  Treating the first parent differently from others
> is what we intend to do with this change, bhut this hunk treats the
> other parents differently depending on the merge order.

It is worth adding a test with an octopus merge to really be clear
about the intended behavior. When describing the concept, I've been
careful to say "TREESAME to the first parent" and "not TREESAME to
a later parent" instead of assuming two parents. In the default
mode, we should not reach here unless we found a TREESAME parent
that was not the first parent, since we stop visiting parents after
we find any TREESAME parent. But this would change for --full-history
or --simplify-merges.

>> @@ -3019,7 +3037,8 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c
>>  	if (!cnt ||
>>  	    (commit->object.flags & UNINTERESTING) ||
>>  	    !(commit->object.flags & TREESAME) ||
>> -	    (parent = one_relevant_parent(revs, commit->parents)) == NULL)
>> +	    (parent = one_relevant_parent(revs, commit->parents)) == NULL ||
>> +	    (revs->show_pulls && (commit->object.flags & PULL_MERGE)))
>>  		st->simplified = commit;
> 
> ... hence, wouldn't we see different result here ...
> 
>> @@ -3602,6 +3621,10 @@ enum commit_action get_commit_action(struct rev_info *revs, struct commit *commi
>>  			/* drop merges unless we want parenthood */
>>  			if (!want_ancestry(revs))
>>  				return commit_ignore;
>> +
>> +			if (revs->show_pulls && (commit->object.flags & PULL_MERGE))
>> +				return commit_show;
> 
> ... and also here?

If there is a flaw in how I set PULL_MERGE, then hopefully the fix is where
I assign the PULL_MERGE flag and these lines do not need to change.

Thanks,
-Stolee

      reply	other threads:[~2020-04-10 21:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-08  1:22 [PATCH] revision: --include-diversions " Derrick Stolee via GitGitGadget
2020-04-08  1:30 ` Junio C Hamano
2020-04-08  1:39   ` Derrick Stolee
2020-04-08 15:28     ` Derrick Stolee
2020-04-08 19:46       ` Junio C Hamano
2020-04-08 20:05         ` Jeff King
2020-04-08 20:22           ` Derrick Stolee
2020-04-08 21:35             ` Junio C Hamano
2020-04-08 23:59               ` Derrick Stolee
2020-04-09  0:08                 ` Junio C Hamano
2020-04-09 11:52                   ` Derrick Stolee
2020-04-09 14:28                   ` Philip Oakley
2020-04-09 15:56                     ` Junio C Hamano
2020-04-09 17:20                       ` Derrick Stolee
2020-04-09 18:24                         ` Jeff King
2020-04-09 18:55                           ` Junio C Hamano
2020-04-09 19:21                             ` Jeff King
2020-04-08  2:13 ` brian m. carlson
2020-04-08 18:48 ` Jeff King
2020-04-09  0:01 ` [PATCH v2] " Derrick Stolee via GitGitGadget
2020-04-10 12:19   ` [PATCH v3] revision: --show-pulls " Derrick Stolee via GitGitGadget
2020-04-10 20:06     ` Junio C Hamano
2020-04-10 21:43       ` Derrick Stolee [this message]

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=28075cfb-34bb-1109-5685-8d662e7559c3@gmail.com \
    --to=stolee@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    --cc=philipoakley@iee.email \
    --cc=sandals@crustytoothpaste.net \
    --subject='Re: [PATCH v3] revision: --show-pulls adds helpful merges' \
    /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

Code repositories for project(s) associated with this inbox:

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).