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@xxxxxxxxx>
* 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