git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 1/2] lib-log-graph: move check_graph function

From
Pablo Sabater <pabloosabaterr@gmail.com>
Date
Jun 12, 2026, 13:48 UTC
Message-ID
<20260612-ps-pre-commit-indent-v4-1-e8492037ebae@gmail.com>
In-Reply-To
<20260612-ps-pre-commit-indent-v4-0-e8492037ebae@gmail.com>

check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file.

Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph.

This function is needed for the following commit which includes graph tests in a new file and requires check_graph.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
---
 t/lib-log-graph.sh                         |  5 +++++
 t/t4215-log-skewed-merges.sh               | 33 +++++++++++++-----------------
 t/t6016-rev-list-graph-simplify-history.sh | 25 +++++++++-------------
 3 files changed, 29 insertions(+), 34 deletions(-)
diff --git a/t/lib-log-graph.sh b/t/lib-log-graph.sh
index bf952ef920..1eae8f60c2 100644
--- a/t/lib-log-graph.sh
+++ b/t/lib-log-graph.sh
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () {
 	test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors &&
 	test_cmp expect.colors output.colors
 }
+
+lib_test_check_graph () {
+	cat >expect &&
+	lib_test_cmp_graph --format=%s "$@"
+}
diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh
index 1612f05f1b..eebab71039 100755
--- a/t/t4215-log-skewed-merges.sh
+++ b/t/t4215-log-skewed-merges.sh
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-log-graph.sh
 
-check_graph () {
-	cat >expect &&
-	lib_test_cmp_graph --format=%s "$@"
-}
-
 test_expect_success 'log --graph with merge fusing with its left and right neighbors' '
 	git checkout --orphan _p &&
 	test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh
 	git checkout _p && git merge --no-ff _r -m G &&
 	git checkout @^^ && git merge --no-ff _p -m H &&
 
-	check_graph <<-\EOF
+	lib_test_check_graph <<-\EOF
 	*   H
 	|\
 	| *   G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' '
 	git checkout 0_p && git merge --no-ff 0_s -m 0_G &&
 	git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H &&
 
-	check_graph <<-\EOF
+	lib_test_check_graph <<-\EOF
 	*-----.   0_H
 	|\ \ \ \
 	| | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' '
 	git checkout 1_p && git merge --no-ff 1_r -m 1_G &&
 	git checkout @^^ && git merge --no-ff 1_p -m 1_H &&
 
-	check_graph <<-\EOF
+	lib_test_check_graph <<-\EOF
 	*   1_H
 	|\
 	| *   1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal
 	git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J &&
 	git checkout 2_p && git merge --no-ff 2_s -m 2_K &&
 
-	check_graph <<-\EOF
+	lib_test_check_graph <<-\EOF
 	*   2_K
 	|\
 	| *   2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s
 	git checkout 3_p && git merge --no-ff 3_r -m 3_H &&
 	git checkout @^^ && git merge --no-ff 3_p -m 3_J &&
 
-	check_graph <<-\EOF
+	lib_test_check_graph <<-\EOF
 	*   3_J
 	|\
 	| *   3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed
 	git merge --no-ff 4_p -m 4_G &&
 	git checkout @^^ && git merge --no-ff 4_s -m 4_H &&
 
-	check_graph --date-order <<-\EOF
+	lib_test_check_graph --date-order <<-\EOF
 	*   4_H
 	|\
 	| *   4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu
 	git checkout 5_r &&
 	git merge --no-ff 5_s -m 5_H &&
 
-	check_graph <<-\EOF
+	lib_test_check_graph <<-\EOF
 	*   5_H
 	|\
 	| *-.   5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' '
 	git checkout 6_1 &&
 	git merge --no-ff 6_2 -m 6_I &&
 
-	check_graph 6_1 6_3 6_5 <<-\EOF
+	lib_test_check_graph 6_1 6_3 6_5 <<-\EOF
 	*   6_I
 	|\
 	| | *   6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' '
 	git checkout -b M_7 7_1 &&
 	git merge --no-ff 7_2 7_3 -m 7_M4 &&
 
-	check_graph M_1 M_3 M_5 M_7 <<-\EOF
+	lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF
 	*   7_M1
 	|\
 	| | *   7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' '
 '
 
 test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' '
-	check_graph --graph-lane-limit=2 M_7 <<-\EOF
+	lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF
 	*-.   7_M4
 	|\ \
 	| | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' '
 '
 
 test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' '
-	check_graph --graph-lane-limit=1 M_7 <<-\EOF
+	lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF
 	*-~  7_M4
 	|\~
 	| ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge
 '
 
 test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' '
-	check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF
+	lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF
 	*   7_M1
 	|\
 	| | *   7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' '
 '
 
 test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' '
-	check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF
+	lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF
 	*   7_M1
 	|\
 	| | *   7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir
 '
 
 test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' '
-	check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF
+	lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF
 	*   7_M1
 	|\
 	| | *   7_M2
diff --git a/t/t6016-rev-list-graph-simplify-history.sh b/t/t6016-rev-list-graph-simplify-history.sh
index 54b0a6f5f8..e0d9c3c1ac 100755
--- a/t/t6016-rev-list-graph-simplify-history.sh
+++ b/t/t6016-rev-list-graph-simplify-history.sh
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-log-graph.sh
 
-check_graph () {
-	cat >expect &&
-	lib_test_cmp_graph --format=%s "$@"
-}
-
 test_expect_success 'set up rev-list --graph test' '
 	# 3 commits on branch A
 	test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' '
 '
 
 test_expect_success '--graph --all' '
-	check_graph --all <<-\EOF
+	lib_test_check_graph --all <<-\EOF
 	* A7
 	*   A6
 	|\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' '
 # that undecorated merges are interesting, even with --simplify-by-decoration
 test_expect_success '--graph --simplify-by-decoration' '
 	git tag -d A4 &&
-	check_graph --all --simplify-by-decoration <<-\EOF
+	lib_test_check_graph --all --simplify-by-decoration <<-\EOF
 	* A7
 	*   A6
 	|\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' '
 
 # Graph with branch B simplified away
 test_expect_success '--graph --simplify-by-decoration prune branch B' '
-	check_graph --simplify-by-decoration --all <<-\EOF
+	lib_test_check_graph --simplify-by-decoration --all <<-\EOF
 	* A7
 	*   A6
 	|\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' '
 '
 
 test_expect_success '--graph --full-history -- bar.txt' '
-	check_graph --full-history --all -- bar.txt <<-\EOF
+	lib_test_check_graph --full-history --all -- bar.txt <<-\EOF
 	* A7
 	*   A6
 	|\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' '
 '
 
 test_expect_success '--graph --full-history --simplify-merges -- bar.txt' '
-	check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF
+	lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF
 	* A7
 	*   A6
 	|\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' '
 '
 
 test_expect_success '--graph -- bar.txt' '
-	check_graph --all -- bar.txt <<-\EOF
+	lib_test_check_graph --all -- bar.txt <<-\EOF
 	* A7
 	* A5
 	* A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' '
 '
 
 test_expect_success '--graph --sparse -- bar.txt' '
-	check_graph --sparse --all -- bar.txt <<-\EOF
+	lib_test_check_graph --sparse --all -- bar.txt <<-\EOF
 	* A7
 	* A6
 	* A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' '
 '
 
 test_expect_success '--graph ^C4' '
-	check_graph --all ^C4 <<-\EOF
+	lib_test_check_graph --all ^C4 <<-\EOF
 	* A7
 	* A6
 	* A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' '
 '
 
 test_expect_success '--graph ^C3' '
-	check_graph --all ^C3 <<-\EOF
+	lib_test_check_graph --all ^C3 <<-\EOF
 	* A7
 	*   A6
 	|\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' '
 # 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' '
-	check_graph --boundary --all ^C3 <<-\EOF
+	lib_test_check_graph --boundary --all ^C3 <<-\EOF
 	* A7
 	*   A6
 	|\
-- 
2.54.0
Previous: Pablo SabaterNext: Pablo Sabater
Message 17 of 119 in “graph: add indentation for commits preceded by a root”
  1. 0/1 graph: add indentation for commits preceded by a rootPablo Sabater, Apr 2, 2026
  2. 1/1 graph: add indentation for commits preceded by a rootPablo Sabater, Apr 2, 2026
  3. Junio C HamanoApr 3, 2026
  4. PabloApr 3, 2026
  5. Junio C HamanoApr 3, 2026
  6. PabloApr 3, 2026
  7. 0/1 graph: add indentation for commits preceded by a parentless commitPablo Sabater, Apr 4, 2026
  8. 1/1 graph: add indentation for commits preceded by a parentless commitPablo Sabater, Apr 4, 2026
  9. PabloApr 10, 2026
  10. Junio C HamanoApr 10, 2026
  11. 0/1 graph: add indentation for commits preceded by a parentless commitPablo Sabater, Apr 27, 2026
  12. 1/1 graph: add indentation for commits preceded by a parentless commitPablo Sabater, Apr 27, 2026
  13. Jeff KingMay 13, 2026
  14. Pablo SabaterMay 14, 2026
  15. PabloApr 27, 2026
  16. 0/2 graph: indent visual roots in graphPablo Sabater, Jun 12, 2026
  17. 1/2 lib-log-graph: move check_graph functionPablo Sabater, Jun 12, 2026
  18. 2/2 graph: indent visual root in graphPablo Sabater, Jun 12, 2026
  19. Junio C HamanoJun 13, 2026
  20. 0/2 graph: indent visual roots in graphPablo Sabater, Jun 13, 2026
  21. 1/2 lib-log-graph: move check_graph functionPablo Sabater, Jun 13, 2026
  22. 2/2 graph: indent visual root in graphPablo Sabater, Jun 13, 2026
  23. Junio C HamanoJun 14, 2026
  24. Pablo SabaterJun 14, 2026
  25. Junio C HamanoJun 15, 2026
  26. Pablo SabaterJun 16, 2026
  27. Junio C HamanoJun 16, 2026
  28. Jeff KingJun 17, 2026
  29. Pablo SabaterJun 18, 2026
  30. Junio C HamanoJun 18, 2026
  31. Jeff KingJun 18, 2026
  32. Jeff KingJun 18, 2026
  33. Kristofer KarlssonJun 19, 2026
  34. Jeff KingJun 21, 2026
  35. Kristofer KarlssonJun 22, 2026
  36. Chandra PratapJun 17, 2026
  37. 0/3 graph: indent visual roots in graphPablo Sabater, Jun 20, 2026
  38. 1/3 lib-log-graph: move check_graph functionPablo Sabater, Jun 20, 2026
  39. 2/3 revision: add peek functions for lookaheadPablo Sabater, Jun 20, 2026
  40. Pablo SabaterJun 20, 2026
  41. Junio C HamanoJun 20, 2026
  42. Junio C HamanoJun 20, 2026
  43. Junio C HamanoJun 21, 2026
  44. Chandra PratapJun 21, 2026
  45. Kristofer KarlssonJun 22, 2026
  46. Junio C HamanoJun 29, 2026
  47. Pablo SabaterJun 29, 2026
  48. 3/3 graph: indent visual root in graphPablo Sabater, Jun 20, 2026
  49. 0/3 graph: indent visual roots in graphPablo Sabater, Jul 4, 2026
  50. 1/3 lib-log-graph: move check_graph functionPablo Sabater, Jul 4, 2026
  51. 2/3 graph: add a 2 commit buffer for lookaheadPablo Sabater, Jul 4, 2026
  52. Chandra PratapJul 6, 2026
  53. Kristofer KarlssonJul 6, 2026
  54. Chandra PratapJul 6, 2026
  55. Pablo SabaterJul 7, 2026
  56. Pablo SabaterJul 7, 2026
  57. 3/3 graph: indent visual root in graphPablo Sabater, Jul 4, 2026
  58. 0/4 graph: indent visual roots in graphPablo Sabater, Jul 10, 2026
  59. 1/4 lib-log-graph: move check_graph functionPablo Sabater, Jul 10, 2026
  60. 2/4 revision: add next_commit_to_show()Pablo Sabater, Jul 10, 2026
  61. 3/4 graph: add a 2 commit buffer for lookaheadPablo Sabater, Jul 10, 2026
  62. 4/4 graph: indent visual root in graphPablo Sabater, Jul 10, 2026
  63. Mirko FainaJul 10, 2026
  64. Pablo SabaterJul 10, 2026
  65. 0/4 graph: indent visual roots in graphPablo Sabater, Jul 11, 2026
  66. 1/4 lib-log-graph: move check_graph functionPablo Sabater, Jul 11, 2026
  67. 2/4 revision: add next_commit_to_show()Pablo Sabater, Jul 11, 2026
  68. 3/4 graph: add a 2 commit buffer for lookaheadPablo Sabater, Jul 11, 2026
  69. 4/4 graph: indent visual root in graphPablo Sabater, Jul 11, 2026
  70. Mirko FainaJul 11, 2026
  71. Pablo SabaterJul 11, 2026
  72. Mirko FainaJul 11, 2026
  73. Chandra PratapJul 12, 2026
  74. Mirko FainaJul 12, 2026
  75. Mirko FainaJul 12, 2026
  76. Pablo SabaterJul 12, 2026
  77. Mirko FainaJul 12, 2026
  78. Chandra PratapJul 13, 2026
  79. 0/7 graph: indent visual roots in graphPablo Sabater, Jul 13, 2026
  80. 1/7 lib-log-graph: move check_graph functionPablo Sabater, Jul 13, 2026
  81. 2/7 revision: add next_commit_to_show()Pablo Sabater, Jul 13, 2026
  82. 3/7 graph: add a 2 commit buffer for lookaheadPablo Sabater, Jul 13, 2026
  83. 4/7 graph: indent visual root in graphPablo Sabater, Jul 13, 2026
  84. 5/7 graph: wrap cascading commits after 4 columnsPablo Sabater, Jul 13, 2026
  85. 6/7 graph: move config reading into graph_read_config()Pablo Sabater, Jul 13, 2026
  86. 7/7 graph: add --[no-]graph-indent and log.graphIndentPablo Sabater, Jul 13, 2026
  87. Mirko FainaJul 13, 2026
  88. Pablo SabaterJul 13, 2026
  89. 0/7 graph: indent visual roots in graphPablo Sabater, Jul 13, 2026
  90. 1/7 lib-log-graph: move check_graph functionPablo Sabater, Jul 13, 2026
  91. 2/7 revision: add next_commit_to_show()Pablo Sabater, Jul 13, 2026
  92. 3/7 graph: add a 2 commit buffer for lookaheadPablo Sabater, Jul 13, 2026
  93. 4/7 graph: indent visual root in graphPablo Sabater, Jul 13, 2026
  94. 6/7 graph: move config reading into graph_read_config()Pablo Sabater, Jul 13, 2026
  95. 7/7 graph: add --[no-]graph-indent and log.graphIndentPablo Sabater, Jul 13, 2026
  96. Chandra PratapJul 14, 2026
  97. Pablo SabaterJul 14, 2026
  98. 5/7 graph: wrap cascading commits after 4 columnsPablo Sabater, Jul 13, 2026
  99. Junio C HamanoJul 13, 2026
  100. Pablo SabaterJul 13, 2026
  101. 0/7 graph: indent visual roots in graphPablo Sabater, Jul 14, 2026
  102. 1/7 lib-log-graph: move check_graph functionPablo Sabater, Jul 14, 2026
  103. 2/7 revision: add next_commit_to_show()Pablo Sabater, Jul 14, 2026
  104. 3/7 graph: add a 2 commit buffer for lookaheadPablo Sabater, Jul 14, 2026
  105. 4/7 graph: indent visual root in graphPablo Sabater, Jul 14, 2026
  106. 5/7 graph: wrap cascading commits after 4 columnsPablo Sabater, Jul 14, 2026
  107. 6/7 graph: move config reading into graph_read_config()Pablo Sabater, Jul 14, 2026
  108. 7/7 graph: add --[no-]graph-indent and log.graphIndentPablo Sabater, Jul 14, 2026
  109. Chandra PratapJul 15, 2026
  110. Phillip WoodMay 14, 2026
  111. Pablo SabaterMay 14, 2026
  112. Phillip WoodMay 15, 2026
  113. Chandra PratapMay 17, 2026
  114. Pablo SabaterMay 18, 2026
  115. Junio C HamanoMay 19, 2026
  116. Pablo SabaterMay 19, 2026
  117. Junio C HamanoJun 10, 2026
  118. Pablo SabaterJun 10, 2026
  119. Chandra PratapMay 19, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.