]> source.dussan.org Git - jgit.git/commit
RevWalk: new topo sort to not mix lines of history 49/158449/7
authorAlex Spradlin <alexaspradlin@google.com>
Wed, 26 Feb 2020 23:31:37 +0000 (15:31 -0800)
committerAlex Spradlin <alexaspradlin@google.com>
Wed, 11 Mar 2020 22:39:38 +0000 (15:39 -0700)
commite498d43186264f4592d5c9b9303037734cc38b0d
tree5a617d8231e5e652a13e8cf529d563e3ff50ab50
parent04e16afb05912f3a163d8cda3560a5b2f1ea997f
RevWalk: new topo sort to not mix lines of history

The topological sort algorithm in TopoSortGenerator for RevWalk may mix
multiple lines of history, producing results that differ from C git's
git-log whose man page states: "Show no parents before all of its
children are shown, and avoid showing commits on multiple lines of
history intermixed." Lines of history are mixed because
TopoSortGenerator merely delays producing a commit until all of its
children have been produced; it does not immediately produce a commit
after its last child has been produced.

Therefore, add a new RevSort option called TOPO_KEEP_BRANCH_TOGETHER
with a new topo sort algorithm in TopoNonIntermixGenerator. In the
Generator, when the last child of a commit has been produced, unpop
that commit so that it will be returned upon the subsequent call to
next(). To avoid producing duplicates, mark commits that have not yet
been produced as TOPO_QUEUED so that when a commit is popped, it is
produced if and only if TOPO_QUEUED is set.

To support nesting with other generators that may produce the same
commit multiple times like DepthGenerator (for example, StartGenerator
does this), do not increment parent inDegree for the same child commit
more than once.

Commit b5e764abd21bd4593287361a625ecc49bc0efd77 modified the existing
TopoSortGenerator to avoid mixing lines of history, but it was reverted
in e40c38ab08837473375c571c2f07ab680fc1985d because the new behavior
caused problems for EGit users. This motivated adding a new Generator
for the new behavior.

Signed-off-by: Alex Spradlin <alexaspradlin@google.com>
Change-Id: Icbb24eac98c00e45c175b01e1c8122554f617933
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FirstParentRevWalkTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkSortTest.java
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObject.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevSort.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/StartGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoNonIntermixSortGenerator.java [new file with mode: 0644]