git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/1] Preserve topological ordering after merges
@ 2020-01-07 10:30 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:11 ` [PATCH 0/1] Preserve topological ordering after merges Johannes Schindelin
  0 siblings, 2 replies; 11+ messages in thread
From: Sergey Rudyshin via GitGitGadget @ 2020-01-07 10:30 UTC (permalink / raw)
  To: git; +Cc: Sergey Rudyshin, Junio C Hamano

This modifies the algoritm of topopological ordering. The problem with the
current algoritm is that it displays the graph below as following

* 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 staiting that C shoud be between D
and B The new algorithm solves this issue

Here is an example: 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 becase A is
already printed step back to B print B so on

This change makes option "--topo-order" obsolete, because for a single
commit there is only one way to order parents. "--date-order" and
"--author-date-order" are preserved and make sence only for the case when
multiple commits are given to be able to sort those commits.

Sergey Rudyshin (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

 Documentation/git-rev-list.txt             |   4 +-
 Documentation/rev-list-options.txt         |  41 +++---
 commit.c                                   | 149 ++++++++++++++-------
 commit.h                                   |   4 +-
 t/t4202-log.sh                             |  15 +--
 t/t4215-log-skewed-merges.sh               |  44 +++---
 t/t6003-rev-list-topo-order.sh             |  54 ++++----
 t/t6012-rev-list-simplify.sh               |   8 +-
 t/t6016-rev-list-graph-simplify-history.sh |  41 +++---
 t/t6600-test-reach.sh                      |   6 +-
 10 files changed, 214 insertions(+), 152 deletions(-)


base-commit: 8679ef24ed64018bb62170c43ce73e0261c0600a
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-514%2FSergeyRudyshin%2Ftopo_order_fix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-514/SergeyRudyshin/topo_order_fix-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/514
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [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
  2020-01-07 10:30 [PATCH 0/1] Preserve topological ordering after merges Sergey Rudyshin via GitGitGadget
@ 2020-01-07 10:30 ` Sergey Rudyshin via GitGitGadget
  2020-01-07 12:08   ` Johannes Schindelin
  2020-01-07 12:14   ` Derrick Stolee
  2020-01-07 12:11 ` [PATCH 0/1] Preserve topological ordering after merges Johannes Schindelin
  1 sibling, 2 replies; 11+ messages in thread
From: Sergey Rudyshin via GitGitGadget @ 2020-01-07 10:30 UTC (permalink / raw)
  To: git; +Cc: Sergey Rudyshin, Junio C Hamano, Sergey Rudyshin

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

Here is an example:
* 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.

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.

Signed-off-by: Sergey Rudyshin <540555@gmail.com>
---
 Documentation/git-rev-list.txt             |   4 +-
 Documentation/rev-list-options.txt         |  41 +++---
 commit.c                                   | 149 ++++++++++++++-------
 commit.h                                   |   4 +-
 t/t4202-log.sh                             |  15 +--
 t/t4215-log-skewed-merges.sh               |  44 +++---
 t/t6003-rev-list-topo-order.sh             |  54 ++++----
 t/t6012-rev-list-simplify.sh               |   8 +-
 t/t6016-rev-list-graph-simplify-history.sh |  41 +++---
 t/t6600-test-reach.sh                      |   6 +-
 10 files changed, 214 insertions(+), 152 deletions(-)

diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
index 025c911436..ad1fda7a54 100644
--- a/Documentation/git-rev-list.txt
+++ b/Documentation/git-rev-list.txt
@@ -3,7 +3,7 @@ git-rev-list(1)
 
 NAME
 ----
-git-rev-list - Lists commit objects in reverse chronological order
+git-rev-list - Lists commit objects in reverse topological order
 
 
 SYNOPSIS
@@ -17,7 +17,7 @@ DESCRIPTION
 List commits that are reachable by following the `parent` links from the
 given commit(s), but exclude commits that are reachable from the one(s)
 given with a '{caret}' in front of them.  The output is given in reverse
-chronological order by default.
+topological order by default.
 
 You can think of this as a set operation.  Commits given on the command
 line form a set of commits that are reachable from any of them, and then
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index bfd02ade99..7ab2f451ae 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -643,39 +643,42 @@ ifndef::git-shortlog[]
 Commit Ordering
 ~~~~~~~~~~~~~~~
 
-By default, the commits are shown in reverse chronological order.
+By default, the commits are shown in reverse topological order.
++
+Meaning that no parents are shown before all of its children and
+merges do not change the previous order.
++
+E.g., if commit M0 produces topologically ordered list of 
+commits L0 then commit M1 created by merging any commit into M0
+produces list L1 which starts with L0
++
+In case if multiple commits are given via the command line
+the following parameters determine the order among them:
 
 --date-order::
-	Show no parents before all of its children are shown, but
-	otherwise show commits in the commit timestamp order.
+	show commits in the commit timestamp order.
 
 --author-date-order::
-	Show no parents before all of its children are shown, but
-	otherwise show commits in the author timestamp order.
+	show commits in the author timestamp order.
 
 --topo-order::
-	Show no parents before all of its children are shown, and
-	avoid showing commits on multiple lines of history
-	intermixed.
+	show commits in the commit timestamp order.
+	this is deprecated and will be
+	removed in the future.
 +
 For example, in a commit history like this:
 +
 ----------------------------------------------------------------
-
-    ---1----2----4----7
-	\	       \
-	 3----5----6----8---
-
+   1----2-----------5
+    \    \         /
+     -----\---3---4---6
+           \     /
+            ----
 ----------------------------------------------------------------
 +
 where the numbers denote the order of commit timestamps, `git
 rev-list` and friends with `--date-order` show the commits in the
-timestamp order: 8 7 6 5 4 3 2 1.
-+
-With `--topo-order`, they would show 8 6 5 3 7 4 2 1 (or 8 7 4 2 6 5
-3 1); some older commits are shown before newer ones in order to
-avoid showing the commits from two parallel development track mixed
-together.
+following order: 1 2 3 4 5 6.
 
 --reverse::
 	Output the commits chosen to be shown (see Commit Limiting
diff --git a/commit.c b/commit.c
index 434ec030d6..01e9d07db9 100644
--- a/commit.c
+++ b/commit.c
@@ -738,6 +738,12 @@ int compare_commits_by_author_date(const void *a_, const void *b_,
 	return 0;
 }
 
+static int compare_commits_by_author_date_rev(const void *a_, const void *b_,
+				   void *cb_data)
+{
+	return compare_commits_by_author_date(b_, a_, cb_data);
+}
+
 int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused)
 {
 	const struct commit *a = a_, *b = b_;
@@ -767,36 +773,83 @@ int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused)
 	return 0;
 }
 
+static int compare_commits_by_commit_date_rev(const void *a_, const void *b_, void *unused)
+{
+	return compare_commits_by_commit_date (b_, a_, unused);
+}
+
+struct maze {
+	struct commit *ret;
+	struct commit *out;
+};
+
+define_commit_slab(maze_slab, struct maze *);
+
+/*
+ * returns the next commit while exploring the maze
+ * current commit has the information:
+ * 	- what was the last commit we went for (OUT)
+ * 	- from which commit we came in (RET)
+ * trying to find a parent next to OUT
+ * if it does not exists returns RET
+ * otherwise returns the found parent
+ */
+static struct commit *get_next(struct commit *commit, struct maze *mz, struct indegree_slab *indegree)
+{
+	struct commit_list *parents = commit->parents;
+	struct commit *next = NULL;
+	int found = 0;
+
+	while (parents) {
+		struct commit *parent = parents->item;
+
+		if (*indegree_slab_at(indegree, parent)) {
+
+			if (!mz->out || found) {
+				next = parent;
+				break;
+			} else if  (mz->out == parent) {
+				found = 1;
+			}
+		}
+		parents = parents->next;
+	}
+
+	if (!next) next = mz->ret;
+
+	return next;
+}
+
 /*
  * Performs an in-place topological sort on the list supplied.
  */
 void sort_in_topological_order(struct commit_list **list, enum rev_sort_order sort_order)
 {
 	struct commit_list *next, *orig = *list;
-	struct commit_list **pptr;
+	struct commit_list **pptr = list;
 	struct indegree_slab indegree;
-	struct prio_queue queue;
+	struct prio_queue queue_tips;
 	struct commit *commit;
 	struct author_date_slab author_date;
+	struct maze_slab maze;
+	struct maze *mz;
 
 	if (!orig)
 		return;
 	*list = NULL;
 
 	init_indegree_slab(&indegree);
-	memset(&queue, '\0', sizeof(queue));
+	init_maze_slab(&maze);
+	memset(&queue_tips, '\0', sizeof(queue_tips));
 
 	switch (sort_order) {
-	default: /* REV_SORT_IN_GRAPH_ORDER */
-		queue.compare = NULL;
-		break;
-	case REV_SORT_BY_COMMIT_DATE:
-		queue.compare = compare_commits_by_commit_date;
+	default: 
+		queue_tips.compare = compare_commits_by_commit_date_rev;
 		break;
 	case REV_SORT_BY_AUTHOR_DATE:
 		init_author_date_slab(&author_date);
-		queue.compare = compare_commits_by_author_date;
-		queue.cb_data = &author_date;
+		queue_tips.compare = compare_commits_by_author_date_rev;
+		queue_tips.cb_data = &author_date;
 		break;
 	}
 
@@ -804,9 +857,10 @@ 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;
 		*(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);
+		mz = xmalloc(sizeof(struct maze));
+		mz->ret = NULL;
+		mz->out = NULL;
+		*(maze_slab_at(&maze, commit)) = mz;
 	}
 
 	/* 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);
+		}
 	}
 
-	/*
-	 * This is unfortunate; the initial tips need to be shown
-	 * in the order given from the revision traversal machinery.
-	 */
-	if (sort_order == REV_SORT_IN_GRAPH_ORDER)
-		prio_queue_reverse(&queue);
-
 	/* We no longer need the commit list */
 	free_commit_list(orig);
 
 	pptr = list;
 	*list = NULL;
-	while ((commit = prio_queue_get(&queue)) != NULL) {
-		struct commit_list *parents;
-
-		for (parents = commit->parents; parents ; parents = parents->next) {
-			struct commit *parent = parents->item;
-			int *pi = indegree_slab_at(&indegree, parent);
 
-			if (!*pi)
+	while ((commit = prio_queue_get(&queue_tips)) != NULL) {
+		struct commit *prev_commit = NULL;
+		while (commit) {
+			mz = *(maze_slab_at(&maze, commit));
+			if (!prev_commit) {
+				/* either a new tip or 
+				 * after entering an already visited commit
+				 */
+			}
+			else if (!mz->out) {
+				/* happens only once for every commit
+				 * note that for tips RET is set to NULL
+				 */
+				mz->ret = prev_commit;
+			} 
+			else if (prev_commit != mz->out) {
+				/* entered an already visited commit
+				 * step back
+				 */
+				commit = prev_commit;
+				prev_commit = NULL;
 				continue;
-
-			/*
-			 * parents are only enqueued for emission
-			 * when all their children have been emitted thereby
-			 * guaranteeing topological order.
-			 */
-			if (--(*pi) == 1)
-				prio_queue_put(&queue, parent);
+			}
+			mz->out = get_next(commit, mz, &indegree);
+			if (mz->out == mz->ret) {
+				/* upon leaving a commit emit it */
+				*pptr = commit_list_insert(commit, pptr);
+			}
+			prev_commit = commit;
+			commit = mz->out;
 		}
-		/*
-		 * all children of commit have already been
-		 * emitted. we can emit it now.
-		 */
-		*(indegree_slab_at(&indegree, commit)) = 0;
-
-		pptr = &commit_list_insert(commit, pptr)->next;
 	}
 
 	clear_indegree_slab(&indegree);
-	clear_prio_queue(&queue);
+	clear_maze_slab(&maze);
+	clear_prio_queue(&queue_tips);
 	if (sort_order == REV_SORT_BY_AUTHOR_DATE)
 		clear_author_date_slab(&author_date);
 }
diff --git a/commit.h b/commit.h
index 221cdaa34b..1fe3cc240e 100644
--- a/commit.h
+++ b/commit.h
@@ -209,7 +209,7 @@ struct commit *pop_commit(struct commit_list **stack);
 void clear_commit_marks(struct commit *commit, unsigned int mark);
 void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark);
 
-
+/* TODO get rid of rev_sort_order in a favour of positional parameters */
 enum rev_sort_order {
 	REV_SORT_IN_GRAPH_ORDER = 0,
 	REV_SORT_BY_COMMIT_DATE,
@@ -222,8 +222,6 @@ enum rev_sort_order {
  *   invariant of resulting list is:
  *      a reachable from b => ord(b) < ord(a)
  *   sort_order further specifies:
- *   REV_SORT_IN_GRAPH_ORDER: try to show a commit on a single-parent
- *                            chain together.
  *   REV_SORT_BY_COMMIT_DATE: show eligible commits in committer-date order.
  */
 void sort_in_topological_order(struct commit_list **, enum rev_sort_order);
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 2c9489484a..46f04b36a3 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -635,17 +635,16 @@ test_expect_success 'set up more tangled history' '
 cat > expect <<\EOF
 *   Merge tag 'reach'
 |\
-| \
+| * reach
+| |
 |  \
 *-. \   Merge tags 'octopus-a' and 'octopus-b'
 |\ \ \
-* | | | seventh
 | | * | octopus-b
-| |/ /
-|/| |
-| * | octopus-a
-|/ /
-| * reach
+| | |/
+| * / octopus-a
+| |/
+* / seventh
 |/
 *   Merge branch 'tangle'
 |\
@@ -673,7 +672,7 @@ cat > expect <<\EOF
 * initial
 EOF
 
-test_expect_success 'log --graph with merge' '
+test_expect_success 'log --graph with merge tag reach' '
 	git log --graph --date-order --pretty=tformat:%s |
 		sed "s/ *\$//" >actual &&
 	test_cmp expect actual
diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh
index 18709a723e..91630c0cae 100755
--- a/t/t4215-log-skewed-merges.sh
+++ b/t/t4215-log-skewed-merges.sh
@@ -5,7 +5,7 @@ test_description='git log --graph of skewed merges'
 . ./test-lib.sh
 
 check_graph () {
-	cat >expect &&
+	sed "s/ *$//" >expect &&
 	git log --graph --pretty=tformat:%s "$@" >actual.raw &&
 	sed "s/ *$//" actual.raw >actual &&
 	test_cmp expect actual
@@ -185,20 +185,21 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed
 
 	check_graph --date-order <<-\EOF
 	*   4_H
-	|\
+	|\  
 	| *   4_G
-	| |\
+	| |\  
+	| | * 4_C
 	| * | 4_F
-	|/| |
+	|/| | 
 	| * |   4_E
-	| |\ \
-	| | * | 4_D
-	| |/ /
-	|/| |
-	| | * 4_C
-	| |/
+	| |\ \  
+	| | |/  
+	| |/|   
+	| | * 4_D
+	| |/  
+	|/|   
 	| * 4_B
-	|/
+	|/  
 	* 4_A
 	EOF
 '
@@ -221,21 +222,20 @@ test_expect_success 'log --graph with octopus merge with column joining its penu
 
 	check_graph <<-\EOF
 	*   5_H
-	|\
+	|\  
 	| *-.   5_G
-	| |\ \
+	| |\ \  
 	| | | * 5_F
 	| | * |   5_E
-	| |/|\ \
-	| |_|/ /
-	|/| | /
-	| | |/
-	* | | 5_D
+	| |/|\ \  
+	| |_|/ /  
+	|/| | /   
+	| | |/    
 	| | * 5_C
-	| |/
-	|/|
-	| * 5_B
-	|/
+	| * | 5_B
+	| |/  
+	* / 5_D
+	|/  
 	* 5_A
 	EOF
 '
diff --git a/t/t6003-rev-list-topo-order.sh b/t/t6003-rev-list-topo-order.sh
index 24d1836f41..19cb79bc29 100755
--- a/t/t6003-rev-list-topo-order.sh
+++ b/t/t6003-rev-list-topo-order.sh
@@ -87,12 +87,12 @@ c3
 c2
 c1
 b4
-a3
-a2
-a1
 b3
 b2
 b1
+a3
+a2
+a1
 a0
 l2
 l1
@@ -105,15 +105,15 @@ l5
 l4
 l3
 a4
-b4
-a3
-a2
 c3
 c2
+c1
+b4
 b3
 b2
-c1
 b1
+a3
+a2
 a1
 a0
 l2
@@ -127,12 +127,12 @@ l5
 l4
 l3
 a4
-b4
 c3
 c2
+c1
+b4
 b3
 b2
-c1
 b1
 a3
 a2
@@ -205,12 +205,12 @@ c3
 c2
 c1
 b4
-a3
-a2
-a1
 b3
 b2
 b1
+a3
+a2
+a1
 a0
 l2
 EOF
@@ -224,12 +224,12 @@ c3
 c2
 c1
 b4
-a3
-a2
-a1
 b3
 b2
 b1
+a3
+a2
+a1
 a0
 l2
 EOF
@@ -237,10 +237,10 @@ EOF
 test_output_expect_success 'prune near topo' 'git rev-list --topo-order a4 ^c3' <<EOF
 a4
 b4
+b3
 a3
 a2
 a1
-b3
 EOF
 
 test_output_expect_success "head has no parent" 'git rev-list --topo-order  root' <<EOF
@@ -297,8 +297,8 @@ c3
 c2
 c1
 b4
-a3
-a2
+b3
+b2
 EOF
 
 test_output_expect_success "max-count 10 - non topo order" 'git rev-list --max-count=10 l5' <<EOF
@@ -376,12 +376,12 @@ c3
 c2
 c1
 b4
-a3
-a2
-a1
 b3
 b2
 b1
+a3
+a2
+a1
 a0
 l2
 l1
@@ -399,12 +399,12 @@ c3
 c2
 c1
 b4
-a3
-a2
-a1
 b3
 b2
 b1
+a3
+a2
+a1
 a0
 l2
 l1
@@ -428,12 +428,12 @@ c3
 c2
 c1
 b4
-a3
-a2
-a1
 b3
 b2
 b1
+a3
+a2
+a1
 a0
 l2
 l1
diff --git a/t/t6012-rev-list-simplify.sh b/t/t6012-rev-list-simplify.sh
index a10f0df02b..9f687b6b22 100755
--- a/t/t6012-rev-list-simplify.sh
+++ b/t/t6012-rev-list-simplify.sh
@@ -122,16 +122,16 @@ check_result () {
 
 check_result 'L K J I H F E D C G B A' --full-history --topo-order
 check_result 'L K I H G F E D C B J A' --full-history
-check_result 'L K I H G F E D C B J A' --full-history --date-order
-check_result 'L K I H G F E D B C J A' --full-history --author-date-order
+check_result 'L K J I H F E D C G B A' --full-history --date-order
+check_result 'L K J I H F E D C G B A' --full-history --author-date-order
 check_result 'K I H E C B A' --full-history -- file
 check_result 'K I H E C B A' --full-history --topo-order -- file
 check_result 'K I H E C B A' --full-history --date-order -- file
-check_result 'K I H E B C A' --full-history --author-date-order -- file
+check_result 'K I H E C B A' --full-history --author-date-order -- file
 check_result 'I E C B A' --simplify-merges -- file
 check_result 'I E C B A' --simplify-merges --topo-order -- file
 check_result 'I E C B A' --simplify-merges --date-order -- file
-check_result 'I E B C A' --simplify-merges --author-date-order -- file
+check_result 'I E C B A' --simplify-merges --author-date-order -- file
 check_result 'I B A' -- file
 check_result 'I B A' --topo-order -- file
 check_result 'I B A' --date-order -- file
diff --git a/t/t6016-rev-list-graph-simplify-history.sh b/t/t6016-rev-list-graph-simplify-history.sh
index f5e6e92f5b..5750c6f0fd 100755
--- a/t/t6016-rev-list-graph-simplify-history.sh
+++ b/t/t6016-rev-list-graph-simplify-history.sh
@@ -235,27 +235,28 @@ test_expect_success '--graph ^C3' '
 # I don't think the ordering of the boundary commits is really
 # that important, but this test depends on it.  If the ordering ever changes
 # in the code, we'll need to update this test.
-test_expect_success '--graph --boundary ^C3' '
+test_expect_success '--graph --boundary --all ^C3' '
 	rm -f expected &&
-	echo "* $A7" >> expected &&
-	echo "*   $A6" >> expected &&
-	echo "|\\  " >> expected &&
-	echo "| * $C4" >> expected &&
-	echo "* | $A5" >> expected &&
-	echo "| |     " >> expected &&
-	echo "|  \\    " >> expected &&
-	echo "*-. \\   $A4" >> expected &&
-	echo "|\\ \\ \\  " >> expected &&
-	echo "| * | | $B2" >> expected &&
-	echo "| * | | $B1" >> expected &&
-	echo "* | | | $A3" >> expected &&
-	echo "o | | | $A2" >> expected &&
-	echo "|/ / /  " >> expected &&
-	echo "o / / $A1" >> expected &&
-	echo " / /  " >> expected &&
-	echo "| o $C3" >> expected &&
-	echo "|/  " >> expected &&
-	echo "o $C2" >> expected &&
+	cat >> expected <<-TESTDATA &&
+	* $A7
+	*   $A6
+	|\  
+	| * $C4
+	* | $A5
+	| |     
+	|  \    
+	*-. \   $A4
+	|\ \ \  
+	| * | | $B2
+	| * | | $B1
+	* | | | $A3
+	| | | o $C3
+	| | |/  
+	| | o $C2
+	o | $A2
+	|/  
+	o $A1
+	TESTDATA
 	git rev-list --graph --boundary --all ^C3 > actual &&
 	test_cmp expected actual
 	'
diff --git a/t/t6600-test-reach.sh b/t/t6600-test-reach.sh
index b24d850036..a6d389c4fd 100755
--- a/t/t6600-test-reach.sh
+++ b/t/t6600-test-reach.sh
@@ -339,6 +339,8 @@ test_expect_success 'rev-list: ancestry-path topo-order' '
 	run_three_modes git rev-list --topo-order --ancestry-path commit-3-3..commit-6-6
 '
 
+# TODO get rid of the "sort" below 
+# if commitGraph is enabled then sort_in_topological_order is not envoked
 test_expect_success 'rev-list: symmetric difference topo-order' '
 	git rev-parse \
 		commit-6-6 commit-5-6 commit-4-6 \
@@ -349,8 +351,8 @@ test_expect_success 'rev-list: symmetric difference topo-order' '
 		commit-6-1 commit-5-1 commit-4-1 \
 		commit-3-8 commit-2-8 commit-1-8 \
 		commit-3-7 commit-2-7 commit-1-7 \
-	>expect &&
-	run_three_modes git rev-list --topo-order commit-3-8...commit-6-6
+	| sort >expect &&
+	run_three_modes git rev-list --topo-order commit-3-8...commit-6-6 | sort
 '
 
 test_expect_success 'get_reachable_subset:all' '
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* 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
  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
  1 sibling, 2 replies; 11+ messages in thread
From: Johannes Schindelin @ 2020-01-07 12:08 UTC (permalink / raw)
  To: Sergey Rudyshin via GitGitGadget
  Cc: git, Sergey Rudyshin, Junio C Hamano, Sergey Rudyshin

Hi Sergey,

please note that the commit message's first line should not be longer than
76 characters per line, and it should be followed by an empty line. I
think that you forgot the empty line, looking at
https://github.com/gitgitgadget/git/pull/514/commits/542a02020c8578d0e004cb9c929bced8719b902a

Ciao,
Johannes

On Tue, 7 Jan 2020, 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
>
> Here is an example:
> * 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.
>
> 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.
>
> Signed-off-by: Sergey Rudyshin <540555@gmail.com>
> ---
>  Documentation/git-rev-list.txt             |   4 +-
>  Documentation/rev-list-options.txt         |  41 +++---
>  commit.c                                   | 149 ++++++++++++++-------
>  commit.h                                   |   4 +-
>  t/t4202-log.sh                             |  15 +--
>  t/t4215-log-skewed-merges.sh               |  44 +++---
>  t/t6003-rev-list-topo-order.sh             |  54 ++++----
>  t/t6012-rev-list-simplify.sh               |   8 +-
>  t/t6016-rev-list-graph-simplify-history.sh |  41 +++---
>  t/t6600-test-reach.sh                      |   6 +-
>  10 files changed, 214 insertions(+), 152 deletions(-)
>
> diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
> index 025c911436..ad1fda7a54 100644
> --- a/Documentation/git-rev-list.txt
> +++ b/Documentation/git-rev-list.txt
> @@ -3,7 +3,7 @@ git-rev-list(1)
>
>  NAME
>  ----
> -git-rev-list - Lists commit objects in reverse chronological order
> +git-rev-list - Lists commit objects in reverse topological order
>
>
>  SYNOPSIS
> @@ -17,7 +17,7 @@ DESCRIPTION
>  List commits that are reachable by following the `parent` links from the
>  given commit(s), but exclude commits that are reachable from the one(s)
>  given with a '{caret}' in front of them.  The output is given in reverse
> -chronological order by default.
> +topological order by default.
>
>  You can think of this as a set operation.  Commits given on the command
>  line form a set of commits that are reachable from any of them, and then
> diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
> index bfd02ade99..7ab2f451ae 100644
> --- a/Documentation/rev-list-options.txt
> +++ b/Documentation/rev-list-options.txt
> @@ -643,39 +643,42 @@ ifndef::git-shortlog[]
>  Commit Ordering
>  ~~~~~~~~~~~~~~~
>
> -By default, the commits are shown in reverse chronological order.
> +By default, the commits are shown in reverse topological order.
> ++
> +Meaning that no parents are shown before all of its children and
> +merges do not change the previous order.
> ++
> +E.g., if commit M0 produces topologically ordered list of
> +commits L0 then commit M1 created by merging any commit into M0
> +produces list L1 which starts with L0
> ++
> +In case if multiple commits are given via the command line
> +the following parameters determine the order among them:
>
>  --date-order::
> -	Show no parents before all of its children are shown, but
> -	otherwise show commits in the commit timestamp order.
> +	show commits in the commit timestamp order.
>
>  --author-date-order::
> -	Show no parents before all of its children are shown, but
> -	otherwise show commits in the author timestamp order.
> +	show commits in the author timestamp order.
>
>  --topo-order::
> -	Show no parents before all of its children are shown, and
> -	avoid showing commits on multiple lines of history
> -	intermixed.
> +	show commits in the commit timestamp order.
> +	this is deprecated and will be
> +	removed in the future.
>  +
>  For example, in a commit history like this:
>  +
>  ----------------------------------------------------------------
> -
> -    ---1----2----4----7
> -	\	       \
> -	 3----5----6----8---
> -
> +   1----2-----------5
> +    \    \         /
> +     -----\---3---4---6
> +           \     /
> +            ----
>  ----------------------------------------------------------------
>  +
>  where the numbers denote the order of commit timestamps, `git
>  rev-list` and friends with `--date-order` show the commits in the
> -timestamp order: 8 7 6 5 4 3 2 1.
> -+
> -With `--topo-order`, they would show 8 6 5 3 7 4 2 1 (or 8 7 4 2 6 5
> -3 1); some older commits are shown before newer ones in order to
> -avoid showing the commits from two parallel development track mixed
> -together.
> +following order: 1 2 3 4 5 6.
>
>  --reverse::
>  	Output the commits chosen to be shown (see Commit Limiting
> diff --git a/commit.c b/commit.c
> index 434ec030d6..01e9d07db9 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -738,6 +738,12 @@ int compare_commits_by_author_date(const void *a_, const void *b_,
>  	return 0;
>  }
>
> +static int compare_commits_by_author_date_rev(const void *a_, const void *b_,
> +				   void *cb_data)
> +{
> +	return compare_commits_by_author_date(b_, a_, cb_data);
> +}
> +
>  int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused)
>  {
>  	const struct commit *a = a_, *b = b_;
> @@ -767,36 +773,83 @@ int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused)
>  	return 0;
>  }
>
> +static int compare_commits_by_commit_date_rev(const void *a_, const void *b_, void *unused)
> +{
> +	return compare_commits_by_commit_date (b_, a_, unused);
> +}
> +
> +struct maze {
> +	struct commit *ret;
> +	struct commit *out;
> +};
> +
> +define_commit_slab(maze_slab, struct maze *);
> +
> +/*
> + * returns the next commit while exploring the maze
> + * current commit has the information:
> + * 	- what was the last commit we went for (OUT)
> + * 	- from which commit we came in (RET)
> + * trying to find a parent next to OUT
> + * if it does not exists returns RET
> + * otherwise returns the found parent
> + */
> +static struct commit *get_next(struct commit *commit, struct maze *mz, struct indegree_slab *indegree)
> +{
> +	struct commit_list *parents = commit->parents;
> +	struct commit *next = NULL;
> +	int found = 0;
> +
> +	while (parents) {
> +		struct commit *parent = parents->item;
> +
> +		if (*indegree_slab_at(indegree, parent)) {
> +
> +			if (!mz->out || found) {
> +				next = parent;
> +				break;
> +			} else if  (mz->out == parent) {
> +				found = 1;
> +			}
> +		}
> +		parents = parents->next;
> +	}
> +
> +	if (!next) next = mz->ret;
> +
> +	return next;
> +}
> +
>  /*
>   * Performs an in-place topological sort on the list supplied.
>   */
>  void sort_in_topological_order(struct commit_list **list, enum rev_sort_order sort_order)
>  {
>  	struct commit_list *next, *orig = *list;
> -	struct commit_list **pptr;
> +	struct commit_list **pptr = list;
>  	struct indegree_slab indegree;
> -	struct prio_queue queue;
> +	struct prio_queue queue_tips;
>  	struct commit *commit;
>  	struct author_date_slab author_date;
> +	struct maze_slab maze;
> +	struct maze *mz;
>
>  	if (!orig)
>  		return;
>  	*list = NULL;
>
>  	init_indegree_slab(&indegree);
> -	memset(&queue, '\0', sizeof(queue));
> +	init_maze_slab(&maze);
> +	memset(&queue_tips, '\0', sizeof(queue_tips));
>
>  	switch (sort_order) {
> -	default: /* REV_SORT_IN_GRAPH_ORDER */
> -		queue.compare = NULL;
> -		break;
> -	case REV_SORT_BY_COMMIT_DATE:
> -		queue.compare = compare_commits_by_commit_date;
> +	default:
> +		queue_tips.compare = compare_commits_by_commit_date_rev;
>  		break;
>  	case REV_SORT_BY_AUTHOR_DATE:
>  		init_author_date_slab(&author_date);
> -		queue.compare = compare_commits_by_author_date;
> -		queue.cb_data = &author_date;
> +		queue_tips.compare = compare_commits_by_author_date_rev;
> +		queue_tips.cb_data = &author_date;
>  		break;
>  	}
>
> @@ -804,9 +857,10 @@ 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;
>  		*(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);
> +		mz = xmalloc(sizeof(struct maze));
> +		mz->ret = NULL;
> +		mz->out = NULL;
> +		*(maze_slab_at(&maze, commit)) = mz;
>  	}
>
>  	/* 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);
> +		}
>  	}
>
> -	/*
> -	 * This is unfortunate; the initial tips need to be shown
> -	 * in the order given from the revision traversal machinery.
> -	 */
> -	if (sort_order == REV_SORT_IN_GRAPH_ORDER)
> -		prio_queue_reverse(&queue);
> -
>  	/* We no longer need the commit list */
>  	free_commit_list(orig);
>
>  	pptr = list;
>  	*list = NULL;
> -	while ((commit = prio_queue_get(&queue)) != NULL) {
> -		struct commit_list *parents;
> -
> -		for (parents = commit->parents; parents ; parents = parents->next) {
> -			struct commit *parent = parents->item;
> -			int *pi = indegree_slab_at(&indegree, parent);
>
> -			if (!*pi)
> +	while ((commit = prio_queue_get(&queue_tips)) != NULL) {
> +		struct commit *prev_commit = NULL;
> +		while (commit) {
> +			mz = *(maze_slab_at(&maze, commit));
> +			if (!prev_commit) {
> +				/* either a new tip or
> +				 * after entering an already visited commit
> +				 */
> +			}
> +			else if (!mz->out) {
> +				/* happens only once for every commit
> +				 * note that for tips RET is set to NULL
> +				 */
> +				mz->ret = prev_commit;
> +			}
> +			else if (prev_commit != mz->out) {
> +				/* entered an already visited commit
> +				 * step back
> +				 */
> +				commit = prev_commit;
> +				prev_commit = NULL;
>  				continue;
> -
> -			/*
> -			 * parents are only enqueued for emission
> -			 * when all their children have been emitted thereby
> -			 * guaranteeing topological order.
> -			 */
> -			if (--(*pi) == 1)
> -				prio_queue_put(&queue, parent);
> +			}
> +			mz->out = get_next(commit, mz, &indegree);
> +			if (mz->out == mz->ret) {
> +				/* upon leaving a commit emit it */
> +				*pptr = commit_list_insert(commit, pptr);
> +			}
> +			prev_commit = commit;
> +			commit = mz->out;
>  		}
> -		/*
> -		 * all children of commit have already been
> -		 * emitted. we can emit it now.
> -		 */
> -		*(indegree_slab_at(&indegree, commit)) = 0;
> -
> -		pptr = &commit_list_insert(commit, pptr)->next;
>  	}
>
>  	clear_indegree_slab(&indegree);
> -	clear_prio_queue(&queue);
> +	clear_maze_slab(&maze);
> +	clear_prio_queue(&queue_tips);
>  	if (sort_order == REV_SORT_BY_AUTHOR_DATE)
>  		clear_author_date_slab(&author_date);
>  }
> diff --git a/commit.h b/commit.h
> index 221cdaa34b..1fe3cc240e 100644
> --- a/commit.h
> +++ b/commit.h
> @@ -209,7 +209,7 @@ struct commit *pop_commit(struct commit_list **stack);
>  void clear_commit_marks(struct commit *commit, unsigned int mark);
>  void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark);
>
> -
> +/* TODO get rid of rev_sort_order in a favour of positional parameters */
>  enum rev_sort_order {
>  	REV_SORT_IN_GRAPH_ORDER = 0,
>  	REV_SORT_BY_COMMIT_DATE,
> @@ -222,8 +222,6 @@ enum rev_sort_order {
>   *   invariant of resulting list is:
>   *      a reachable from b => ord(b) < ord(a)
>   *   sort_order further specifies:
> - *   REV_SORT_IN_GRAPH_ORDER: try to show a commit on a single-parent
> - *                            chain together.
>   *   REV_SORT_BY_COMMIT_DATE: show eligible commits in committer-date order.
>   */
>  void sort_in_topological_order(struct commit_list **, enum rev_sort_order);
> diff --git a/t/t4202-log.sh b/t/t4202-log.sh
> index 2c9489484a..46f04b36a3 100755
> --- a/t/t4202-log.sh
> +++ b/t/t4202-log.sh
> @@ -635,17 +635,16 @@ test_expect_success 'set up more tangled history' '
>  cat > expect <<\EOF
>  *   Merge tag 'reach'
>  |\
> -| \
> +| * reach
> +| |
>  |  \
>  *-. \   Merge tags 'octopus-a' and 'octopus-b'
>  |\ \ \
> -* | | | seventh
>  | | * | octopus-b
> -| |/ /
> -|/| |
> -| * | octopus-a
> -|/ /
> -| * reach
> +| | |/
> +| * / octopus-a
> +| |/
> +* / seventh
>  |/
>  *   Merge branch 'tangle'
>  |\
> @@ -673,7 +672,7 @@ cat > expect <<\EOF
>  * initial
>  EOF
>
> -test_expect_success 'log --graph with merge' '
> +test_expect_success 'log --graph with merge tag reach' '
>  	git log --graph --date-order --pretty=tformat:%s |
>  		sed "s/ *\$//" >actual &&
>  	test_cmp expect actual
> diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh
> index 18709a723e..91630c0cae 100755
> --- a/t/t4215-log-skewed-merges.sh
> +++ b/t/t4215-log-skewed-merges.sh
> @@ -5,7 +5,7 @@ test_description='git log --graph of skewed merges'
>  . ./test-lib.sh
>
>  check_graph () {
> -	cat >expect &&
> +	sed "s/ *$//" >expect &&
>  	git log --graph --pretty=tformat:%s "$@" >actual.raw &&
>  	sed "s/ *$//" actual.raw >actual &&
>  	test_cmp expect actual
> @@ -185,20 +185,21 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed
>
>  	check_graph --date-order <<-\EOF
>  	*   4_H
> -	|\
> +	|\
>  	| *   4_G
> -	| |\
> +	| |\
> +	| | * 4_C
>  	| * | 4_F
> -	|/| |
> +	|/| |
>  	| * |   4_E
> -	| |\ \
> -	| | * | 4_D
> -	| |/ /
> -	|/| |
> -	| | * 4_C
> -	| |/
> +	| |\ \
> +	| | |/
> +	| |/|
> +	| | * 4_D
> +	| |/
> +	|/|
>  	| * 4_B
> -	|/
> +	|/
>  	* 4_A
>  	EOF
>  '
> @@ -221,21 +222,20 @@ test_expect_success 'log --graph with octopus merge with column joining its penu
>
>  	check_graph <<-\EOF
>  	*   5_H
> -	|\
> +	|\
>  	| *-.   5_G
> -	| |\ \
> +	| |\ \
>  	| | | * 5_F
>  	| | * |   5_E
> -	| |/|\ \
> -	| |_|/ /
> -	|/| | /
> -	| | |/
> -	* | | 5_D
> +	| |/|\ \
> +	| |_|/ /
> +	|/| | /
> +	| | |/
>  	| | * 5_C
> -	| |/
> -	|/|
> -	| * 5_B
> -	|/
> +	| * | 5_B
> +	| |/
> +	* / 5_D
> +	|/
>  	* 5_A
>  	EOF
>  '
> diff --git a/t/t6003-rev-list-topo-order.sh b/t/t6003-rev-list-topo-order.sh
> index 24d1836f41..19cb79bc29 100755
> --- a/t/t6003-rev-list-topo-order.sh
> +++ b/t/t6003-rev-list-topo-order.sh
> @@ -87,12 +87,12 @@ c3
>  c2
>  c1
>  b4
> -a3
> -a2
> -a1
>  b3
>  b2
>  b1
> +a3
> +a2
> +a1
>  a0
>  l2
>  l1
> @@ -105,15 +105,15 @@ l5
>  l4
>  l3
>  a4
> -b4
> -a3
> -a2
>  c3
>  c2
> +c1
> +b4
>  b3
>  b2
> -c1
>  b1
> +a3
> +a2
>  a1
>  a0
>  l2
> @@ -127,12 +127,12 @@ l5
>  l4
>  l3
>  a4
> -b4
>  c3
>  c2
> +c1
> +b4
>  b3
>  b2
> -c1
>  b1
>  a3
>  a2
> @@ -205,12 +205,12 @@ c3
>  c2
>  c1
>  b4
> -a3
> -a2
> -a1
>  b3
>  b2
>  b1
> +a3
> +a2
> +a1
>  a0
>  l2
>  EOF
> @@ -224,12 +224,12 @@ c3
>  c2
>  c1
>  b4
> -a3
> -a2
> -a1
>  b3
>  b2
>  b1
> +a3
> +a2
> +a1
>  a0
>  l2
>  EOF
> @@ -237,10 +237,10 @@ EOF
>  test_output_expect_success 'prune near topo' 'git rev-list --topo-order a4 ^c3' <<EOF
>  a4
>  b4
> +b3
>  a3
>  a2
>  a1
> -b3
>  EOF
>
>  test_output_expect_success "head has no parent" 'git rev-list --topo-order  root' <<EOF
> @@ -297,8 +297,8 @@ c3
>  c2
>  c1
>  b4
> -a3
> -a2
> +b3
> +b2
>  EOF
>
>  test_output_expect_success "max-count 10 - non topo order" 'git rev-list --max-count=10 l5' <<EOF
> @@ -376,12 +376,12 @@ c3
>  c2
>  c1
>  b4
> -a3
> -a2
> -a1
>  b3
>  b2
>  b1
> +a3
> +a2
> +a1
>  a0
>  l2
>  l1
> @@ -399,12 +399,12 @@ c3
>  c2
>  c1
>  b4
> -a3
> -a2
> -a1
>  b3
>  b2
>  b1
> +a3
> +a2
> +a1
>  a0
>  l2
>  l1
> @@ -428,12 +428,12 @@ c3
>  c2
>  c1
>  b4
> -a3
> -a2
> -a1
>  b3
>  b2
>  b1
> +a3
> +a2
> +a1
>  a0
>  l2
>  l1
> diff --git a/t/t6012-rev-list-simplify.sh b/t/t6012-rev-list-simplify.sh
> index a10f0df02b..9f687b6b22 100755
> --- a/t/t6012-rev-list-simplify.sh
> +++ b/t/t6012-rev-list-simplify.sh
> @@ -122,16 +122,16 @@ check_result () {
>
>  check_result 'L K J I H F E D C G B A' --full-history --topo-order
>  check_result 'L K I H G F E D C B J A' --full-history
> -check_result 'L K I H G F E D C B J A' --full-history --date-order
> -check_result 'L K I H G F E D B C J A' --full-history --author-date-order
> +check_result 'L K J I H F E D C G B A' --full-history --date-order
> +check_result 'L K J I H F E D C G B A' --full-history --author-date-order
>  check_result 'K I H E C B A' --full-history -- file
>  check_result 'K I H E C B A' --full-history --topo-order -- file
>  check_result 'K I H E C B A' --full-history --date-order -- file
> -check_result 'K I H E B C A' --full-history --author-date-order -- file
> +check_result 'K I H E C B A' --full-history --author-date-order -- file
>  check_result 'I E C B A' --simplify-merges -- file
>  check_result 'I E C B A' --simplify-merges --topo-order -- file
>  check_result 'I E C B A' --simplify-merges --date-order -- file
> -check_result 'I E B C A' --simplify-merges --author-date-order -- file
> +check_result 'I E C B A' --simplify-merges --author-date-order -- file
>  check_result 'I B A' -- file
>  check_result 'I B A' --topo-order -- file
>  check_result 'I B A' --date-order -- file
> diff --git a/t/t6016-rev-list-graph-simplify-history.sh b/t/t6016-rev-list-graph-simplify-history.sh
> index f5e6e92f5b..5750c6f0fd 100755
> --- a/t/t6016-rev-list-graph-simplify-history.sh
> +++ b/t/t6016-rev-list-graph-simplify-history.sh
> @@ -235,27 +235,28 @@ test_expect_success '--graph ^C3' '
>  # I don't think the ordering of the boundary commits is really
>  # that important, but this test depends on it.  If the ordering ever changes
>  # in the code, we'll need to update this test.
> -test_expect_success '--graph --boundary ^C3' '
> +test_expect_success '--graph --boundary --all ^C3' '
>  	rm -f expected &&
> -	echo "* $A7" >> expected &&
> -	echo "*   $A6" >> expected &&
> -	echo "|\\  " >> expected &&
> -	echo "| * $C4" >> expected &&
> -	echo "* | $A5" >> expected &&
> -	echo "| |     " >> expected &&
> -	echo "|  \\    " >> expected &&
> -	echo "*-. \\   $A4" >> expected &&
> -	echo "|\\ \\ \\  " >> expected &&
> -	echo "| * | | $B2" >> expected &&
> -	echo "| * | | $B1" >> expected &&
> -	echo "* | | | $A3" >> expected &&
> -	echo "o | | | $A2" >> expected &&
> -	echo "|/ / /  " >> expected &&
> -	echo "o / / $A1" >> expected &&
> -	echo " / /  " >> expected &&
> -	echo "| o $C3" >> expected &&
> -	echo "|/  " >> expected &&
> -	echo "o $C2" >> expected &&
> +	cat >> expected <<-TESTDATA &&
> +	* $A7
> +	*   $A6
> +	|\
> +	| * $C4
> +	* | $A5
> +	| |
> +	|  \
> +	*-. \   $A4
> +	|\ \ \
> +	| * | | $B2
> +	| * | | $B1
> +	* | | | $A3
> +	| | | o $C3
> +	| | |/
> +	| | o $C2
> +	o | $A2
> +	|/
> +	o $A1
> +	TESTDATA
>  	git rev-list --graph --boundary --all ^C3 > actual &&
>  	test_cmp expected actual
>  	'
> diff --git a/t/t6600-test-reach.sh b/t/t6600-test-reach.sh
> index b24d850036..a6d389c4fd 100755
> --- a/t/t6600-test-reach.sh
> +++ b/t/t6600-test-reach.sh
> @@ -339,6 +339,8 @@ test_expect_success 'rev-list: ancestry-path topo-order' '
>  	run_three_modes git rev-list --topo-order --ancestry-path commit-3-3..commit-6-6
>  '
>
> +# TODO get rid of the "sort" below
> +# if commitGraph is enabled then sort_in_topological_order is not envoked
>  test_expect_success 'rev-list: symmetric difference topo-order' '
>  	git rev-parse \
>  		commit-6-6 commit-5-6 commit-4-6 \
> @@ -349,8 +351,8 @@ test_expect_success 'rev-list: symmetric difference topo-order' '
>  		commit-6-1 commit-5-1 commit-4-1 \
>  		commit-3-8 commit-2-8 commit-1-8 \
>  		commit-3-7 commit-2-7 commit-1-7 \
> -	>expect &&
> -	run_three_modes git rev-list --topo-order commit-3-8...commit-6-6
> +	| sort >expect &&
> +	run_three_modes git rev-list --topo-order commit-3-8...commit-6-6 | sort
>  '
>
>  test_expect_success 'get_reachable_subset:all' '
> --
> gitgitgadget
>
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/1] Preserve topological ordering after merges
  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:11 ` Johannes Schindelin
  2020-01-08 12:50   ` Sergey Rudyshin
  1 sibling, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2020-01-07 12:11 UTC (permalink / raw)
  To: Sergey Rudyshin via GitGitGadget; +Cc: git, Sergey Rudyshin, Junio C Hamano

Hi Sergey,

On Tue, 7 Jan 2020, Sergey Rudyshin via GitGitGadget wrote:

> This modifies the algoritm of topopological ordering. The problem with the
> current algoritm is that it displays the graph below as following
>
> * 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 staiting that C shoud be between D
> and B The new algorithm solves this issue
>
> Here is an example: 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 becase A is
> already printed step back to B print B so on
>
> This change makes option "--topo-order" obsolete, because for a single
> commit there is only one way to order parents. "--date-order" and
> "--author-date-order" are preserved and make sence only for the case when
> multiple commits are given to be able to sort those commits.

I have to admit that I am not a fan of this change, as I find that there
are legitimate use cases where I want to order the commits by commit
topology, and other use cases where I want to order them by date.

Maybe other reviewers agree with your reasoning, though, in that case you
still will need to address the test failures in t4202, t4215 and t6012:
https://dev.azure.com/gitgitgadget/git/_build/results?buildId=25867&view=ms.vss-test-web.build-test-results-tab

Ciao,
Johannes

>
> Sergey Rudyshin (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
>
>  Documentation/git-rev-list.txt             |   4 +-
>  Documentation/rev-list-options.txt         |  41 +++---
>  commit.c                                   | 149 ++++++++++++++-------
>  commit.h                                   |   4 +-
>  t/t4202-log.sh                             |  15 +--
>  t/t4215-log-skewed-merges.sh               |  44 +++---
>  t/t6003-rev-list-topo-order.sh             |  54 ++++----
>  t/t6012-rev-list-simplify.sh               |   8 +-
>  t/t6016-rev-list-graph-simplify-history.sh |  41 +++---
>  t/t6600-test-reach.sh                      |   6 +-
>  10 files changed, 214 insertions(+), 152 deletions(-)
>
>
> base-commit: 8679ef24ed64018bb62170c43ce73e0261c0600a
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-514%2FSergeyRudyshin%2Ftopo_order_fix-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-514/SergeyRudyshin/topo_order_fix-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/514
> --
> gitgitgadget
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* 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
  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 12:14   ` Derrick Stolee
  2020-01-08 15:11     ` Sergey Rudyshin
  1 sibling, 1 reply; 11+ messages in thread
From: Derrick Stolee @ 2020-01-07 12:14 UTC (permalink / raw)
  To: Sergey Rudyshin via GitGitGadget, git; +Cc: Sergey Rudyshin, Junio C Hamano

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.

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

> 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.

>  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.

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.

>  	/* 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.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 11+ messages in thread

* 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
  2020-01-07 12:08   ` Johannes Schindelin
@ 2020-01-07 17:01     ` Junio C Hamano
  2020-01-08  7:51     ` Sergey Rudyshin
  1 sibling, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2020-01-07 17:01 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Sergey Rudyshin via GitGitGadget, git, Sergey Rudyshin

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Hi Sergey,
>
> please note that the commit message's first line should not be longer than
> 76 characters per line, and it should be followed by an empty line. I
> think that you forgot the empty line, looking at
> https://github.com/gitgitgadget/git/pull/514/commits/542a02020c8578d0e004cb9c929bced8719b902a

Thanks for a good suggestion.

Also, please do *not* CC iterations of a patch to me that hasn't
seen a concensus that it is a good idea on the list yet, unless
you know I am the area expert and am interested in seeing it.

Thanks.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* 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
  2020-01-07 12:08   ` Johannes Schindelin
  2020-01-07 17:01     ` Junio C Hamano
@ 2020-01-08  7:51     ` Sergey Rudyshin
  1 sibling, 0 replies; 11+ messages in thread
From: Sergey Rudyshin @ 2020-01-08  7:51 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Sergey Rudyshin via GitGitGadget, git, Junio C Hamano

Hi, Johannes,
thank you for your comment
Indeed i forgot to put an emty line. Will fix it.

On Tue, Jan 7, 2020 at 3:08 PM Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>
> Hi Sergey,
>
> please note that the commit message's first line should not be longer than
> 76 characters per line, and it should be followed by an empty line. I
> think that you forgot the empty line, looking at
> https://github.com/gitgitgadget/git/pull/514/commits/542a02020c8578d0e004cb9c929bced8719b902a
>
> Ciao,
> Johannes
>
> On Tue, 7 Jan 2020, 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
> >
> > Here is an example:
> > * 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.
> >
> > 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.
> >
> > Signed-off-by: Sergey Rudyshin <540555@gmail.com>
> > ---
> >  Documentation/git-rev-list.txt             |   4 +-
> >  Documentation/rev-list-options.txt         |  41 +++---
> >  commit.c                                   | 149 ++++++++++++++-------
> >  commit.h                                   |   4 +-
> >  t/t4202-log.sh                             |  15 +--
> >  t/t4215-log-skewed-merges.sh               |  44 +++---
> >  t/t6003-rev-list-topo-order.sh             |  54 ++++----
> >  t/t6012-rev-list-simplify.sh               |   8 +-
> >  t/t6016-rev-list-graph-simplify-history.sh |  41 +++---
> >  t/t6600-test-reach.sh                      |   6 +-
> >  10 files changed, 214 insertions(+), 152 deletions(-)
> >
> > diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
> > index 025c911436..ad1fda7a54 100644
> > --- a/Documentation/git-rev-list.txt
> > +++ b/Documentation/git-rev-list.txt
> > @@ -3,7 +3,7 @@ git-rev-list(1)
> >
> >  NAME
> >  ----
> > -git-rev-list - Lists commit objects in reverse chronological order
> > +git-rev-list - Lists commit objects in reverse topological order
> >
> >
> >  SYNOPSIS
> > @@ -17,7 +17,7 @@ DESCRIPTION
> >  List commits that are reachable by following the `parent` links from the
> >  given commit(s), but exclude commits that are reachable from the one(s)
> >  given with a '{caret}' in front of them.  The output is given in reverse
> > -chronological order by default.
> > +topological order by default.
> >
> >  You can think of this as a set operation.  Commits given on the command
> >  line form a set of commits that are reachable from any of them, and then
> > diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
> > index bfd02ade99..7ab2f451ae 100644
> > --- a/Documentation/rev-list-options.txt
> > +++ b/Documentation/rev-list-options.txt
> > @@ -643,39 +643,42 @@ ifndef::git-shortlog[]
> >  Commit Ordering
> >  ~~~~~~~~~~~~~~~
> >
> > -By default, the commits are shown in reverse chronological order.
> > +By default, the commits are shown in reverse topological order.
> > ++
> > +Meaning that no parents are shown before all of its children and
> > +merges do not change the previous order.
> > ++
> > +E.g., if commit M0 produces topologically ordered list of
> > +commits L0 then commit M1 created by merging any commit into M0
> > +produces list L1 which starts with L0
> > ++
> > +In case if multiple commits are given via the command line
> > +the following parameters determine the order among them:
> >
> >  --date-order::
> > -     Show no parents before all of its children are shown, but
> > -     otherwise show commits in the commit timestamp order.
> > +     show commits in the commit timestamp order.
> >
> >  --author-date-order::
> > -     Show no parents before all of its children are shown, but
> > -     otherwise show commits in the author timestamp order.
> > +     show commits in the author timestamp order.
> >
> >  --topo-order::
> > -     Show no parents before all of its children are shown, and
> > -     avoid showing commits on multiple lines of history
> > -     intermixed.
> > +     show commits in the commit timestamp order.
> > +     this is deprecated and will be
> > +     removed in the future.
> >  +
> >  For example, in a commit history like this:
> >  +
> >  ----------------------------------------------------------------
> > -
> > -    ---1----2----4----7
> > -     \              \
> > -      3----5----6----8---
> > -
> > +   1----2-----------5
> > +    \    \         /
> > +     -----\---3---4---6
> > +           \     /
> > +            ----
> >  ----------------------------------------------------------------
> >  +
> >  where the numbers denote the order of commit timestamps, `git
> >  rev-list` and friends with `--date-order` show the commits in the
> > -timestamp order: 8 7 6 5 4 3 2 1.
> > -+
> > -With `--topo-order`, they would show 8 6 5 3 7 4 2 1 (or 8 7 4 2 6 5
> > -3 1); some older commits are shown before newer ones in order to
> > -avoid showing the commits from two parallel development track mixed
> > -together.
> > +following order: 1 2 3 4 5 6.
> >
> >  --reverse::
> >       Output the commits chosen to be shown (see Commit Limiting
> > diff --git a/commit.c b/commit.c
> > index 434ec030d6..01e9d07db9 100644
> > --- a/commit.c
> > +++ b/commit.c
> > @@ -738,6 +738,12 @@ int compare_commits_by_author_date(const void *a_, const void *b_,
> >       return 0;
> >  }
> >
> > +static int compare_commits_by_author_date_rev(const void *a_, const void *b_,
> > +                                void *cb_data)
> > +{
> > +     return compare_commits_by_author_date(b_, a_, cb_data);
> > +}
> > +
> >  int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused)
> >  {
> >       const struct commit *a = a_, *b = b_;
> > @@ -767,36 +773,83 @@ int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused)
> >       return 0;
> >  }
> >
> > +static int compare_commits_by_commit_date_rev(const void *a_, const void *b_, void *unused)
> > +{
> > +     return compare_commits_by_commit_date (b_, a_, unused);
> > +}
> > +
> > +struct maze {
> > +     struct commit *ret;
> > +     struct commit *out;
> > +};
> > +
> > +define_commit_slab(maze_slab, struct maze *);
> > +
> > +/*
> > + * returns the next commit while exploring the maze
> > + * current commit has the information:
> > + *   - what was the last commit we went for (OUT)
> > + *   - from which commit we came in (RET)
> > + * trying to find a parent next to OUT
> > + * if it does not exists returns RET
> > + * otherwise returns the found parent
> > + */
> > +static struct commit *get_next(struct commit *commit, struct maze *mz, struct indegree_slab *indegree)
> > +{
> > +     struct commit_list *parents = commit->parents;
> > +     struct commit *next = NULL;
> > +     int found = 0;
> > +
> > +     while (parents) {
> > +             struct commit *parent = parents->item;
> > +
> > +             if (*indegree_slab_at(indegree, parent)) {
> > +
> > +                     if (!mz->out || found) {
> > +                             next = parent;
> > +                             break;
> > +                     } else if  (mz->out == parent) {
> > +                             found = 1;
> > +                     }
> > +             }
> > +             parents = parents->next;
> > +     }
> > +
> > +     if (!next) next = mz->ret;
> > +
> > +     return next;
> > +}
> > +
> >  /*
> >   * Performs an in-place topological sort on the list supplied.
> >   */
> >  void sort_in_topological_order(struct commit_list **list, enum rev_sort_order sort_order)
> >  {
> >       struct commit_list *next, *orig = *list;
> > -     struct commit_list **pptr;
> > +     struct commit_list **pptr = list;
> >       struct indegree_slab indegree;
> > -     struct prio_queue queue;
> > +     struct prio_queue queue_tips;
> >       struct commit *commit;
> >       struct author_date_slab author_date;
> > +     struct maze_slab maze;
> > +     struct maze *mz;
> >
> >       if (!orig)
> >               return;
> >       *list = NULL;
> >
> >       init_indegree_slab(&indegree);
> > -     memset(&queue, '\0', sizeof(queue));
> > +     init_maze_slab(&maze);
> > +     memset(&queue_tips, '\0', sizeof(queue_tips));
> >
> >       switch (sort_order) {
> > -     default: /* REV_SORT_IN_GRAPH_ORDER */
> > -             queue.compare = NULL;
> > -             break;
> > -     case REV_SORT_BY_COMMIT_DATE:
> > -             queue.compare = compare_commits_by_commit_date;
> > +     default:
> > +             queue_tips.compare = compare_commits_by_commit_date_rev;
> >               break;
> >       case REV_SORT_BY_AUTHOR_DATE:
> >               init_author_date_slab(&author_date);
> > -             queue.compare = compare_commits_by_author_date;
> > -             queue.cb_data = &author_date;
> > +             queue_tips.compare = compare_commits_by_author_date_rev;
> > +             queue_tips.cb_data = &author_date;
> >               break;
> >       }
> >
> > @@ -804,9 +857,10 @@ 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;
> >               *(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);
> > +             mz = xmalloc(sizeof(struct maze));
> > +             mz->ret = NULL;
> > +             mz->out = NULL;
> > +             *(maze_slab_at(&maze, commit)) = mz;
> >       }
> >
> >       /* 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);
> > +             }
> >       }
> >
> > -     /*
> > -      * This is unfortunate; the initial tips need to be shown
> > -      * in the order given from the revision traversal machinery.
> > -      */
> > -     if (sort_order == REV_SORT_IN_GRAPH_ORDER)
> > -             prio_queue_reverse(&queue);
> > -
> >       /* We no longer need the commit list */
> >       free_commit_list(orig);
> >
> >       pptr = list;
> >       *list = NULL;
> > -     while ((commit = prio_queue_get(&queue)) != NULL) {
> > -             struct commit_list *parents;
> > -
> > -             for (parents = commit->parents; parents ; parents = parents->next) {
> > -                     struct commit *parent = parents->item;
> > -                     int *pi = indegree_slab_at(&indegree, parent);
> >
> > -                     if (!*pi)
> > +     while ((commit = prio_queue_get(&queue_tips)) != NULL) {
> > +             struct commit *prev_commit = NULL;
> > +             while (commit) {
> > +                     mz = *(maze_slab_at(&maze, commit));
> > +                     if (!prev_commit) {
> > +                             /* either a new tip or
> > +                              * after entering an already visited commit
> > +                              */
> > +                     }
> > +                     else if (!mz->out) {
> > +                             /* happens only once for every commit
> > +                              * note that for tips RET is set to NULL
> > +                              */
> > +                             mz->ret = prev_commit;
> > +                     }
> > +                     else if (prev_commit != mz->out) {
> > +                             /* entered an already visited commit
> > +                              * step back
> > +                              */
> > +                             commit = prev_commit;
> > +                             prev_commit = NULL;
> >                               continue;
> > -
> > -                     /*
> > -                      * parents are only enqueued for emission
> > -                      * when all their children have been emitted thereby
> > -                      * guaranteeing topological order.
> > -                      */
> > -                     if (--(*pi) == 1)
> > -                             prio_queue_put(&queue, parent);
> > +                     }
> > +                     mz->out = get_next(commit, mz, &indegree);
> > +                     if (mz->out == mz->ret) {
> > +                             /* upon leaving a commit emit it */
> > +                             *pptr = commit_list_insert(commit, pptr);
> > +                     }
> > +                     prev_commit = commit;
> > +                     commit = mz->out;
> >               }
> > -             /*
> > -              * all children of commit have already been
> > -              * emitted. we can emit it now.
> > -              */
> > -             *(indegree_slab_at(&indegree, commit)) = 0;
> > -
> > -             pptr = &commit_list_insert(commit, pptr)->next;
> >       }
> >
> >       clear_indegree_slab(&indegree);
> > -     clear_prio_queue(&queue);
> > +     clear_maze_slab(&maze);
> > +     clear_prio_queue(&queue_tips);
> >       if (sort_order == REV_SORT_BY_AUTHOR_DATE)
> >               clear_author_date_slab(&author_date);
> >  }
> > diff --git a/commit.h b/commit.h
> > index 221cdaa34b..1fe3cc240e 100644
> > --- a/commit.h
> > +++ b/commit.h
> > @@ -209,7 +209,7 @@ struct commit *pop_commit(struct commit_list **stack);
> >  void clear_commit_marks(struct commit *commit, unsigned int mark);
> >  void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark);
> >
> > -
> > +/* TODO get rid of rev_sort_order in a favour of positional parameters */
> >  enum rev_sort_order {
> >       REV_SORT_IN_GRAPH_ORDER = 0,
> >       REV_SORT_BY_COMMIT_DATE,
> > @@ -222,8 +222,6 @@ enum rev_sort_order {
> >   *   invariant of resulting list is:
> >   *      a reachable from b => ord(b) < ord(a)
> >   *   sort_order further specifies:
> > - *   REV_SORT_IN_GRAPH_ORDER: try to show a commit on a single-parent
> > - *                            chain together.
> >   *   REV_SORT_BY_COMMIT_DATE: show eligible commits in committer-date order.
> >   */
> >  void sort_in_topological_order(struct commit_list **, enum rev_sort_order);
> > diff --git a/t/t4202-log.sh b/t/t4202-log.sh
> > index 2c9489484a..46f04b36a3 100755
> > --- a/t/t4202-log.sh
> > +++ b/t/t4202-log.sh
> > @@ -635,17 +635,16 @@ test_expect_success 'set up more tangled history' '
> >  cat > expect <<\EOF
> >  *   Merge tag 'reach'
> >  |\
> > -| \
> > +| * reach
> > +| |
> >  |  \
> >  *-. \   Merge tags 'octopus-a' and 'octopus-b'
> >  |\ \ \
> > -* | | | seventh
> >  | | * | octopus-b
> > -| |/ /
> > -|/| |
> > -| * | octopus-a
> > -|/ /
> > -| * reach
> > +| | |/
> > +| * / octopus-a
> > +| |/
> > +* / seventh
> >  |/
> >  *   Merge branch 'tangle'
> >  |\
> > @@ -673,7 +672,7 @@ cat > expect <<\EOF
> >  * initial
> >  EOF
> >
> > -test_expect_success 'log --graph with merge' '
> > +test_expect_success 'log --graph with merge tag reach' '
> >       git log --graph --date-order --pretty=tformat:%s |
> >               sed "s/ *\$//" >actual &&
> >       test_cmp expect actual
> > diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh
> > index 18709a723e..91630c0cae 100755
> > --- a/t/t4215-log-skewed-merges.sh
> > +++ b/t/t4215-log-skewed-merges.sh
> > @@ -5,7 +5,7 @@ test_description='git log --graph of skewed merges'
> >  . ./test-lib.sh
> >
> >  check_graph () {
> > -     cat >expect &&
> > +     sed "s/ *$//" >expect &&
> >       git log --graph --pretty=tformat:%s "$@" >actual.raw &&
> >       sed "s/ *$//" actual.raw >actual &&
> >       test_cmp expect actual
> > @@ -185,20 +185,21 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed
> >
> >       check_graph --date-order <<-\EOF
> >       *   4_H
> > -     |\
> > +     |\
> >       | *   4_G
> > -     | |\
> > +     | |\
> > +     | | * 4_C
> >       | * | 4_F
> > -     |/| |
> > +     |/| |
> >       | * |   4_E
> > -     | |\ \
> > -     | | * | 4_D
> > -     | |/ /
> > -     |/| |
> > -     | | * 4_C
> > -     | |/
> > +     | |\ \
> > +     | | |/
> > +     | |/|
> > +     | | * 4_D
> > +     | |/
> > +     |/|
> >       | * 4_B
> > -     |/
> > +     |/
> >       * 4_A
> >       EOF
> >  '
> > @@ -221,21 +222,20 @@ test_expect_success 'log --graph with octopus merge with column joining its penu
> >
> >       check_graph <<-\EOF
> >       *   5_H
> > -     |\
> > +     |\
> >       | *-.   5_G
> > -     | |\ \
> > +     | |\ \
> >       | | | * 5_F
> >       | | * |   5_E
> > -     | |/|\ \
> > -     | |_|/ /
> > -     |/| | /
> > -     | | |/
> > -     * | | 5_D
> > +     | |/|\ \
> > +     | |_|/ /
> > +     |/| | /
> > +     | | |/
> >       | | * 5_C
> > -     | |/
> > -     |/|
> > -     | * 5_B
> > -     |/
> > +     | * | 5_B
> > +     | |/
> > +     * / 5_D
> > +     |/
> >       * 5_A
> >       EOF
> >  '
> > diff --git a/t/t6003-rev-list-topo-order.sh b/t/t6003-rev-list-topo-order.sh
> > index 24d1836f41..19cb79bc29 100755
> > --- a/t/t6003-rev-list-topo-order.sh
> > +++ b/t/t6003-rev-list-topo-order.sh
> > @@ -87,12 +87,12 @@ c3
> >  c2
> >  c1
> >  b4
> > -a3
> > -a2
> > -a1
> >  b3
> >  b2
> >  b1
> > +a3
> > +a2
> > +a1
> >  a0
> >  l2
> >  l1
> > @@ -105,15 +105,15 @@ l5
> >  l4
> >  l3
> >  a4
> > -b4
> > -a3
> > -a2
> >  c3
> >  c2
> > +c1
> > +b4
> >  b3
> >  b2
> > -c1
> >  b1
> > +a3
> > +a2
> >  a1
> >  a0
> >  l2
> > @@ -127,12 +127,12 @@ l5
> >  l4
> >  l3
> >  a4
> > -b4
> >  c3
> >  c2
> > +c1
> > +b4
> >  b3
> >  b2
> > -c1
> >  b1
> >  a3
> >  a2
> > @@ -205,12 +205,12 @@ c3
> >  c2
> >  c1
> >  b4
> > -a3
> > -a2
> > -a1
> >  b3
> >  b2
> >  b1
> > +a3
> > +a2
> > +a1
> >  a0
> >  l2
> >  EOF
> > @@ -224,12 +224,12 @@ c3
> >  c2
> >  c1
> >  b4
> > -a3
> > -a2
> > -a1
> >  b3
> >  b2
> >  b1
> > +a3
> > +a2
> > +a1
> >  a0
> >  l2
> >  EOF
> > @@ -237,10 +237,10 @@ EOF
> >  test_output_expect_success 'prune near topo' 'git rev-list --topo-order a4 ^c3' <<EOF
> >  a4
> >  b4
> > +b3
> >  a3
> >  a2
> >  a1
> > -b3
> >  EOF
> >
> >  test_output_expect_success "head has no parent" 'git rev-list --topo-order  root' <<EOF
> > @@ -297,8 +297,8 @@ c3
> >  c2
> >  c1
> >  b4
> > -a3
> > -a2
> > +b3
> > +b2
> >  EOF
> >
> >  test_output_expect_success "max-count 10 - non topo order" 'git rev-list --max-count=10 l5' <<EOF
> > @@ -376,12 +376,12 @@ c3
> >  c2
> >  c1
> >  b4
> > -a3
> > -a2
> > -a1
> >  b3
> >  b2
> >  b1
> > +a3
> > +a2
> > +a1
> >  a0
> >  l2
> >  l1
> > @@ -399,12 +399,12 @@ c3
> >  c2
> >  c1
> >  b4
> > -a3
> > -a2
> > -a1
> >  b3
> >  b2
> >  b1
> > +a3
> > +a2
> > +a1
> >  a0
> >  l2
> >  l1
> > @@ -428,12 +428,12 @@ c3
> >  c2
> >  c1
> >  b4
> > -a3
> > -a2
> > -a1
> >  b3
> >  b2
> >  b1
> > +a3
> > +a2
> > +a1
> >  a0
> >  l2
> >  l1
> > diff --git a/t/t6012-rev-list-simplify.sh b/t/t6012-rev-list-simplify.sh
> > index a10f0df02b..9f687b6b22 100755
> > --- a/t/t6012-rev-list-simplify.sh
> > +++ b/t/t6012-rev-list-simplify.sh
> > @@ -122,16 +122,16 @@ check_result () {
> >
> >  check_result 'L K J I H F E D C G B A' --full-history --topo-order
> >  check_result 'L K I H G F E D C B J A' --full-history
> > -check_result 'L K I H G F E D C B J A' --full-history --date-order
> > -check_result 'L K I H G F E D B C J A' --full-history --author-date-order
> > +check_result 'L K J I H F E D C G B A' --full-history --date-order
> > +check_result 'L K J I H F E D C G B A' --full-history --author-date-order
> >  check_result 'K I H E C B A' --full-history -- file
> >  check_result 'K I H E C B A' --full-history --topo-order -- file
> >  check_result 'K I H E C B A' --full-history --date-order -- file
> > -check_result 'K I H E B C A' --full-history --author-date-order -- file
> > +check_result 'K I H E C B A' --full-history --author-date-order -- file
> >  check_result 'I E C B A' --simplify-merges -- file
> >  check_result 'I E C B A' --simplify-merges --topo-order -- file
> >  check_result 'I E C B A' --simplify-merges --date-order -- file
> > -check_result 'I E B C A' --simplify-merges --author-date-order -- file
> > +check_result 'I E C B A' --simplify-merges --author-date-order -- file
> >  check_result 'I B A' -- file
> >  check_result 'I B A' --topo-order -- file
> >  check_result 'I B A' --date-order -- file
> > diff --git a/t/t6016-rev-list-graph-simplify-history.sh b/t/t6016-rev-list-graph-simplify-history.sh
> > index f5e6e92f5b..5750c6f0fd 100755
> > --- a/t/t6016-rev-list-graph-simplify-history.sh
> > +++ b/t/t6016-rev-list-graph-simplify-history.sh
> > @@ -235,27 +235,28 @@ test_expect_success '--graph ^C3' '
> >  # I don't think the ordering of the boundary commits is really
> >  # that important, but this test depends on it.  If the ordering ever changes
> >  # in the code, we'll need to update this test.
> > -test_expect_success '--graph --boundary ^C3' '
> > +test_expect_success '--graph --boundary --all ^C3' '
> >       rm -f expected &&
> > -     echo "* $A7" >> expected &&
> > -     echo "*   $A6" >> expected &&
> > -     echo "|\\  " >> expected &&
> > -     echo "| * $C4" >> expected &&
> > -     echo "* | $A5" >> expected &&
> > -     echo "| |     " >> expected &&
> > -     echo "|  \\    " >> expected &&
> > -     echo "*-. \\   $A4" >> expected &&
> > -     echo "|\\ \\ \\  " >> expected &&
> > -     echo "| * | | $B2" >> expected &&
> > -     echo "| * | | $B1" >> expected &&
> > -     echo "* | | | $A3" >> expected &&
> > -     echo "o | | | $A2" >> expected &&
> > -     echo "|/ / /  " >> expected &&
> > -     echo "o / / $A1" >> expected &&
> > -     echo " / /  " >> expected &&
> > -     echo "| o $C3" >> expected &&
> > -     echo "|/  " >> expected &&
> > -     echo "o $C2" >> expected &&
> > +     cat >> expected <<-TESTDATA &&
> > +     * $A7
> > +     *   $A6
> > +     |\
> > +     | * $C4
> > +     * | $A5
> > +     | |
> > +     |  \
> > +     *-. \   $A4
> > +     |\ \ \
> > +     | * | | $B2
> > +     | * | | $B1
> > +     * | | | $A3
> > +     | | | o $C3
> > +     | | |/
> > +     | | o $C2
> > +     o | $A2
> > +     |/
> > +     o $A1
> > +     TESTDATA
> >       git rev-list --graph --boundary --all ^C3 > actual &&
> >       test_cmp expected actual
> >       '
> > diff --git a/t/t6600-test-reach.sh b/t/t6600-test-reach.sh
> > index b24d850036..a6d389c4fd 100755
> > --- a/t/t6600-test-reach.sh
> > +++ b/t/t6600-test-reach.sh
> > @@ -339,6 +339,8 @@ test_expect_success 'rev-list: ancestry-path topo-order' '
> >       run_three_modes git rev-list --topo-order --ancestry-path commit-3-3..commit-6-6
> >  '
> >
> > +# TODO get rid of the "sort" below
> > +# if commitGraph is enabled then sort_in_topological_order is not envoked
> >  test_expect_success 'rev-list: symmetric difference topo-order' '
> >       git rev-parse \
> >               commit-6-6 commit-5-6 commit-4-6 \
> > @@ -349,8 +351,8 @@ test_expect_success 'rev-list: symmetric difference topo-order' '
> >               commit-6-1 commit-5-1 commit-4-1 \
> >               commit-3-8 commit-2-8 commit-1-8 \
> >               commit-3-7 commit-2-7 commit-1-7 \
> > -     >expect &&
> > -     run_three_modes git rev-list --topo-order commit-3-8...commit-6-6
> > +     | sort >expect &&
> > +     run_three_modes git rev-list --topo-order commit-3-8...commit-6-6 | sort
> >  '
> >
> >  test_expect_success 'get_reachable_subset:all' '
> > --
> > gitgitgadget
> >
> >

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/1] Preserve topological ordering after merges
  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
  0 siblings, 1 reply; 11+ messages in thread
From: Sergey Rudyshin @ 2020-01-08 12:50 UTC (permalink / raw)
  To: Johannes Schindelin, Sergey Rudyshin via GitGitGadget; +Cc: git, Junio C Hamano

Hi Johannes,
thanks for you comments!
please find my replies below


07.01.2020 15:11, Johannes Schindelin wrote:
> Hi Sergey,
> 
> On Tue, 7 Jan 2020, Sergey Rudyshin via GitGitGadget wrote:
> 
>> This modifies the algoritm of topopological ordering. The problem with the
>> current algoritm is that it displays the graph below as following
>>
>> * 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 staiting that C shoud be between D
>> and B The new algorithm solves this issue
>>
>> Here is an example: 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 becase A is
>> already printed step back to B print B so on
>>
>> This change makes option "--topo-order" obsolete, because for a single
>> commit there is only one way to order parents. "--date-order" and
>> "--author-date-order" are preserved and make sence only for the case when
>> multiple commits are given to be able to sort those commits.
> 
> I have to admit that I am not a fan of this change, as I find that there
> are legitimate use cases where I want to order the commits by commit
> topology, and other use cases where I want to order them by date.
> 
> Maybe other reviewers agree with your reasoning, though, in that case you
> still will need to address the test failures in t4202, t4215 and t6012:
> https://dev.azure.com/gitgitgadget/git/_build/results?buildId=25867&view=ms.vss-test-web.build-test-results-tab
> 
> Ciao,
> Johannes

let me explain in more detail why I thought it would make sense to stop 
using "--topo-order".
in case if a user specifies a single commit, like this
git rev-list E
with a new algorithm the options "--date-order", "--author-date-order", 
"--topo-order" do not change the ordering. Because there is only one way 
to sort any git graph with a single tip.

in case if a user specifies multiple tips, like this
git rev-list --topo-order C B ^A
current version of git displays commits ordered by commit timestamp
which does not seem like a topological ordering.

so I decided to change the documentation so that "--topo-order" and 
"--date-order" be the same. And since "--topo-order" does not add 
anything new decided to deprecate it.

Form my point of view there should be no options to sort at all.
The topology should be derived from the order provided by the user
git rev-list --topo-order C B ^A
should result in C, B
git rev-list --topo-order B C ^A
should result in B, C

Regarding the failed test
I'll try to find the reason but what puzzles me is why those tests 
(t4202, t4215 and t6012) succeeded on all other platforms (linux32, 
osx-clang, windows, ...) and only failed on linux-gcc.
In my machine those tests do not fail either (gcc (Ubuntu 
5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/1] Preserve topological ordering after merges
  2020-01-08 12:50   ` Sergey Rudyshin
@ 2020-01-08 13:37     ` Derrick Stolee
  2020-01-08 17:04       ` Sergey Rudyshin
  0 siblings, 1 reply; 11+ messages in thread
From: Derrick Stolee @ 2020-01-08 13:37 UTC (permalink / raw)
  To: Sergey Rudyshin, Johannes Schindelin,
	Sergey Rudyshin via GitGitGadget
  Cc: git, Junio C Hamano

On 1/8/2020 7:50 AM, Sergey Rudyshin wrote:
> let me explain in more detail why I thought it would make sense to stop using "--topo-order".
> in case if a user specifies a single commit, like this
> git rev-list E
> with a new algorithm the options "--date-order", "--author-date-order", "--topo-order" do not change the ordering. Because there is only one way to sort any git graph with a single tip.

This is false, unless your history is always linear (no merge commits).

> in case if a user specifies multiple tips, like this
> git rev-list --topo-order C B ^A
> current version of git displays commits ordered by commit timestamp
> which does not seem like a topological ordering.

Are you talking about which of C and B are shown first? They are shown in an order based on your input. If C and B are independent (neither can reach the other), then they will swap order if you write "git rev-list --topo-order B C ^A".

> so I decided to change the documentation so that "--topo-order" and "--date-order" be the same. And since "--topo-order" does not add anything new decided to deprecate it.

Based on this sentence, it is clear that you do not understand the difference between --topo-order and --date-order. Please take time to examine the output difference for the Git repo with the following commands:

	git log --oneline --graph --topo-order
	git log --oneline --graph --date-order

> Regarding the failed test
> I'll try to find the reason but what puzzles me is why those tests (t4202, t4215 and t6012) succeeded on all other platforms (linux32, osx-clang, windows, ...) and only failed on linux-gcc.
> In my machine those tests do not fail either (gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609)

Try running the tests with GIT_TEST_COMMIT_GRAPH=1.

-Stolee
 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* 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
  2020-01-07 12:14   ` Derrick Stolee
@ 2020-01-08 15:11     ` Sergey Rudyshin
  0 siblings, 0 replies; 11+ messages in thread
From: Sergey Rudyshin @ 2020-01-08 15:11 UTC (permalink / raw)
  To: Derrick Stolee, Sergey Rudyshin via GitGitGadget, git; +Cc: Junio C Hamano

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
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/1] Preserve topological ordering after merges
  2020-01-08 13:37     ` Derrick Stolee
@ 2020-01-08 17:04       ` Sergey Rudyshin
  0 siblings, 0 replies; 11+ messages in thread
From: Sergey Rudyshin @ 2020-01-08 17:04 UTC (permalink / raw)
  To: Derrick Stolee, Johannes Schindelin,
	Sergey Rudyshin via GitGitGadget; +Cc: git

Hi Derrick,

Thank you for your comments!

08.01.2020 16:37, Derrick Stolee wrote:
> On 1/8/2020 7:50 AM, Sergey Rudyshin wrote:
>> let me explain in more detail why I thought it would make sense to stop using "--topo-order".
>> in case if a user specifies a single commit, like this
>> git rev-list E
>> with a new algorithm the options "--date-order", "--author-date-order", "--topo-order" do not change the ordering. Because there is only one way to sort any git graph with a single tip.
> 
> This is false, unless your history is always linear (no merge commits).

Would it be possible to provide some test script which would prove you 
point? We could run it against the binary created based from 
https://github.com/gitgitgadget/git/pull/514/commits/542a02020c8578d0e004cb9c929bced8719b902a


> 
>> in case if a user specifies multiple tips, like this
>> git rev-list --topo-order C B ^A
>> current version of git displays commits ordered by commit timestamp
>> which does not seem like a topological ordering.
> 
> Are you talking about which of C and B are shown first? They are shown in an order based on your input. If C and B are independent (neither can reach the other), then they will swap order if you write "git rev-list --topo-order B C ^A".
> 

Please find a script showing that commits are always sorted by commit 
timestamp no matter how they appear in the input.

$ cat ./test.sh
#!/bin/bash
export LANGUAGE=en
GIT=/usr/bin/git
$GIT --version
rm -rf .git
$GIT init
export GIT_COMMITTER_DATE="2000-01-01T00:00:00 +0000"
$GIT commit -m "0" --allow-empty
$GIT tag 0
export GIT_COMMITTER_DATE="2001-01-01T00:00:00 +0000"
$GIT checkout --orphan b1
$GIT commit -m "1" --allow-empty
$GIT tag 1
export GIT_COMMITTER_DATE="2002-01-01T00:00:00 +0000"
$GIT checkout --orphan b2
$GIT commit -m "2" --allow-empty
$GIT tag 2

fnc () {
	echo "$@"
	$GIT log --graph --pretty=tformat:"%D %ci" "$@" | sed 's/-01-01 
00:00:00 +0000//'
}
fnc --topo-order 0 1
fnc --topo-order 1 0

fnc --date-order 0 1
fnc --date-order 1 0

fnc --topo-order 1 2
fnc --topo-order 2 1

fnc --date-order 1 2
fnc --date-order 2 1

fnc --topo-order 0 1 2
fnc --topo-order 2 1 0

$ ./test.sh
git version 2.7.4
Initialized empty Git repository in /tmp/git_test_case_ordering/.git/
[master (root-commit) 0a449fc] 0
Switched to a new branch 'b1'
[b1 (root-commit) 070d07f] 1
Switched to a new branch 'b2'
[b2 (root-commit) c751327] 2
--topo-order 0 1
* tag: 1, b1 2001
* tag: 0, master 2000
--topo-order 1 0
* tag: 1, b1 2001
* tag: 0, master 2000
--date-order 0 1
* tag: 1, b1 2001
* tag: 0, master 2000
--date-order 1 0
* tag: 1, b1 2001
* tag: 0, master 2000
--topo-order 1 2
* HEAD -> b2, tag: 2 2002
* tag: 1, b1 2001
--topo-order 2 1
* HEAD -> b2, tag: 2 2002
* tag: 1, b1 2001
--date-order 1 2
* HEAD -> b2, tag: 2 2002
* tag: 1, b1 2001
--date-order 2 1
* HEAD -> b2, tag: 2 2002
* tag: 1, b1 2001
--topo-order 0 1 2
* HEAD -> b2, tag: 2 2002
* tag: 1, b1 2001
* tag: 0, master 2000
--topo-order 2 1 0
* HEAD -> b2, tag: 2 2002
* tag: 1, b1 2001
* tag: 0, master 2000



>> so I decided to change the documentation so that "--topo-order" and "--date-order" be the same. And since "--topo-order" does not add anything new decided to deprecate it.
> 
> Based on this sentence, it is clear that you do not understand the difference between --topo-order and --date-order. Please take time to examine the output difference for the Git repo with the following commands:
> 
> 	git log --oneline --graph --topo-order
> 	git log --oneline --graph --date-order
> 

Hope that the script above will clarify what i meant.

>> Regarding the failed test
>> I'll try to find the reason but what puzzles me is why those tests (t4202, t4215 and t6012) succeeded on all other platforms (linux32, osx-clang, windows, ...) and only failed on linux-gcc.
>> In my machine those tests do not fail either (gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609)
> 
> Try running the tests with GIT_TEST_COMMIT_GRAPH=1.
> 

Yes it helped. With that option the tests starts to fail.
I'll try to find out how COMMIT_GRAPH works and fix it.

> -Stolee
>   
> 

PS
excluded Junio from the loop per his request.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-01-08 17:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).