git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Sergey Rudyshin <540555@gmail.com>
To: Derrick Stolee <stolee@gmail.com>,
	Sergey Rudyshin via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 1/1] Preserve topological ordering after merges This modifies the algorithm of topopological ordering. The problem with the current algoritm is that it displays the graph below as follows
Date: Wed, 8 Jan 2020 18:11:05 +0300	[thread overview]
Message-ID: <db0c60f3-a61d-51d3-1e29-0227365e7850@gmail.com> (raw)
In-Reply-To: <6c86f1e9-b70b-10b1-f2c5-589312f73a4c@gmail.com>

Hi Derrick,
thank you for you feedback!

07.01.2020 15:14, Derrick Stolee wrote:
> On 1/7/2020 5:30 AM, Sergey Rudyshin via GitGitGadget wrote:
>> From: Sergey Rudyshin <540555@gmail.com>
>>
>> * E
>> |\
>> | * D
>> | |\
>> | |/
>> |/|
>> * | C
>> | * B
>> |/
>> * A
>>
>> commit B is placed between A and C, which is wrong
>> because E stays that D and B comes after C
>>
>> the only correct solution here is
>>
>> * E
>> |\
>> | * D
>> | |\
>> | |/
>> |/|
>> | * B
>> * | C
>> |/
>> * A
>>
>> while it seems that it contradicts to
>> D stating that C should be between D and B
>> The new algorithm solves this issue
> 
> This ordering concern makes sense _somewhat_, because D is the
> second parent of D and that wants to say "Show everything in C..D
> before showing C". The issues is that since C is the second parent
> of D, the topo-ordering says "Show everything in B..C before showing
> things reachable from B". It is unfortunate that these constraints
> collide.
>  > Perhaps your description could do a better job clarifying this
> issue and how your algorithm change fixes the problem.
> 

The proposed algorithm allows to solve collisions you mentioned by 
sticking to the rule which can be summarized as "new commits do not 
change history".
And with that rule in mind choosing between C and B becomes obvious. C 
comes before B because there was a moment in the history when C existed 
and B did not.

Let's imagine the following scenario.
Some person maintains some branch.
At some point in time the branch contains only two commits A and C.
"git rev-list --topo-order" produces "A,C"
then the maintainer merges some branch and
"git rev-list --topo-order" starts to produces "A,B,C,..."
which is confusing.

The algorithm itself is similar to the wall follower used in maze solving.
If you imagine git graph like a maze where edges corresponds to 
corridors and nodes to junctions then using "right-hand rule" you would 
traverse the maze. When leaving a junctions if all corridors are visited 
  assigning the next number to the junctions you are effectively 
ordering them.

Let me repeat the example from my first letter
* walk to to the root via "first" parents;
* go E -> C -> A;
* print A because it has no parents;
* step back to C;
* print C because it has no other parents;
* then step back to E;
* go D -> B -> A;
* do not print A because A is already printed;
* step back to B;
* print B;
* so on.


> However, I'm not sure we even want to make the change, as this
> is still a valid topological order (parents appear after children).
> When we have an ambiguous pair (like B and C) the order can differ.
> The --topo-order option tries to group commits by when they were
> introduced, and that's the reason for presenting the commits reachable
> from the later parents before presenting the commits from earlier
> parents.
> 
> The only documentation we have is from [1]:
> 
> "Show no parents before all of its children are shown, and avoid
> showing commits on multiple lines of history intermixed."
> 
> The first part of the sentence is still true, and the second part
> is ambiguous of how to do that.
> 
> [1] https://git-scm.com/docs/git-log#Documentation/git-log.txt---topo-order
> 

Agreed that it is a a valid topological order but rather for a directed 
acyclic graph. Git has an additional property: edges (parents) are 
ordered. Which makes only one way to order it. Ignoring information that 
parents were ordered we had to invent three similar orderings, one of 
them was ambiguous. For some reason two options do not "avoid showing 
commits on multiple lines of history intermixed". A little confusing.

I think we have an opportunity here to remove options for sorting 
eventually thus simplifying leaning curve for users and give them some 
new features.

Let me step aside and tell why I am proposing this patch in the first 
place. I am a database developer. And me and my team, we have so called 
"migrations": a set of scripts which are to be applied to a database. 
Those scripts are to have a numbers in its filenames so that a tool 
could install them in a particular order (here is example 
https://flywaydb.org/getstarted/how). In our scenario multiple 
developers create those scripts on theirs branches. Those branches get 
merged into a single integration branch. If Git could preserve commit 
ordering after merges it would be possible to generate those filenames 
automatically. Now it can't. So here am i.


>> This change makes option "--topo-order" obsolete, because
>> there is only one way to order parents of a single commit.
>> "--date-order" and "--author-date-order" are preserved and make sense
>> only for the case when multiple commits are given
>> to be able to sort those commits.
> 
> This part of the change needs to be removed. The default sort does
> not preserve topological orderings (like --date-order does), and
> so is much faster to output, especially without a commit-graph file.
> 

Yes indeed. Will fix it.

>>   void sort_in_topological_order(struct commit_list **list, enum rev_sort_order sort_order)
> 
> Since you are only editing this code, and not the incremental topo-order code, your
> test changes will likely break when run with GIT_TEST_COMMIT_GRAPH=1. When the commit-graph
> exists and generation numbers are calculated, we use a different algorithm for topo-order.
> 

Yes this needs to be reconciled. But unfortunately have no experience in 
the code for commit graph.

> I've been meaning to clean up this "duplicated" logic by deleting this method in favor of
> the incremental algorithm in all cases. It needs some perf testing to make sure that
> refactor doesn't have too large of a perf hit in the case of no commit-graph.
>
Given that the new algorithm is pretty simple we could duplicate it 
there once again.

>>   	/* update the indegree */
>> @@ -832,51 +886,56 @@ void sort_in_topological_order(struct commit_list **list, enum rev_sort_order so
>>   	for (next = orig; next; next = next->next) {
>>   		struct commit *commit = next->item;
>>   
>> -		if (*(indegree_slab_at(&indegree, commit)) == 1)
>> -			prio_queue_put(&queue, commit);
>> +		if (*(indegree_slab_at(&indegree, commit)) == 1) {
>> +			/* also record the author dates, if needed */
>> +			if (sort_order == REV_SORT_BY_AUTHOR_DATE)
>> +				record_author_date(&author_date, commit);
>> +			prio_queue_put(&queue_tips, commit);
>> +		}
> 
> Your code change looks rather large for what I expected to be a much simpler change.
> Likely the only thing we need is to avoid adding to the priority queue if we already
> have the commit in the queue (maybe using a hashset storing the commits that we've
> added to the queue). I believe the reason C appears before B in your example is that
> it was added to the queue a second time, and the queue behaves like a stack in the
> topo-order case.
> 
Probably the new code itself could be simplified a bit.
Thanks for suggestion I'll try to think this way.

> Thanks,
> -Stolee
> 

  reply	other threads:[~2020-01-08 15:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-07 10:30 [PATCH 0/1] Preserve topological ordering after merges Sergey Rudyshin via GitGitGadget
2020-01-07 10:30 ` [PATCH 1/1] Preserve topological ordering after merges This modifies the algorithm of topopological ordering. The problem with the current algoritm is that it displays the graph below as follows Sergey Rudyshin via GitGitGadget
2020-01-07 12:08   ` Johannes Schindelin
2020-01-07 17:01     ` Junio C Hamano
2020-01-08  7:51     ` Sergey Rudyshin
2020-01-07 12:14   ` Derrick Stolee
2020-01-08 15:11     ` Sergey Rudyshin [this message]
2020-01-07 12:11 ` [PATCH 0/1] Preserve topological ordering after merges Johannes Schindelin
2020-01-08 12:50   ` Sergey Rudyshin
2020-01-08 13:37     ` Derrick Stolee
2020-01-08 17:04       ` Sergey Rudyshin

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=db0c60f3-a61d-51d3-1e29-0227365e7850@gmail.com \
    --to=540555@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=stolee@gmail.com \
    /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.
Code repositories for project(s) associated with this public 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).