Skip to content

Commit ffe0055

Browse files
abhishekkumar2718gitster
authored andcommitted
lib-log-graph: consolidate colored graph cmp logic
Signed-off-by: Abhishek Kumar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 989eea9 commit ffe0055

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

t/lib-log-graph.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ lib_test_cmp_short_graph () {
2020
sanitize_log_output >output.sanitized <output &&
2121
test_i18ncmp expect output.sanitized
2222
}
23+
24+
lib_test_cmp_colored_graph () {
25+
git log --graph --color=always "$@" >output.colors.raw &&
26+
test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors &&
27+
test_cmp expect.colors output.colors
28+
}

t/t4202-log.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,7 @@ EOF
537537

538538
test_expect_success 'log --graph with merge with log.graphColors' '
539539
test_config log.graphColors " blue,invalid-color, cyan, red , " &&
540-
git log --color=always --graph --date-order --pretty=tformat:%s |
541-
test_decode_color | sed "s/ *\$//" >actual &&
542-
test_cmp expect.colors actual
540+
lib_test_cmp_colored_graph --date-order --format=%s
543541
'
544542

545543
test_expect_success 'log --raw --graph -m with merge' '

t/t4214-log-graph-octopus.sh

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ test_cmp_graph () {
1010
lib_test_cmp_graph --color=never --date-order --format=%s "$@"
1111
}
1212

13+
test_cmp_colored_graph () {
14+
lib_test_cmp_colored_graph --date-order --format=%s "$@"
15+
}
16+
1317
test_expect_success 'set up merge history' '
1418
test_commit initial &&
1519
for i in 1 2 3 4 ; do
@@ -60,9 +64,7 @@ test_expect_success 'log --graph with tricky octopus merge with colors' '
6064
<MAGENTA>|<RESET><MAGENTA>/<RESET>
6165
* initial
6266
EOF
63-
git log --color=always --graph --date-order --pretty=tformat:%s left octopus-merge >actual.colors.raw &&
64-
test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
65-
test_cmp expect.colors actual.colors
67+
test_cmp_colored_graph left octopus-merge
6668
'
6769

6870
# Repeat the previous two tests with "normal" octopus merge (i.e.,
@@ -97,9 +99,7 @@ test_expect_success 'log --graph with normal octopus merge with colors' '
9799
* initial
98100
EOF
99101
test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
100-
git log --color=always --graph --date-order --pretty=tformat:%s octopus-merge >actual.colors.raw &&
101-
test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
102-
test_cmp expect.colors actual.colors
102+
test_cmp_colored_graph octopus-merge
103103
'
104104

105105
test_expect_success 'log --graph with normal octopus merge and child, no color' '
@@ -133,9 +133,7 @@ test_expect_success 'log --graph with normal octopus and child merge with colors
133133
* initial
134134
EOF
135135
test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
136-
git log --color=always --graph --date-order --pretty=tformat:%s after-merge >actual.colors.raw &&
137-
test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
138-
test_cmp expect.colors actual.colors
136+
test_cmp_colored_graph after-merge
139137
'
140138

141139
test_expect_success 'log --graph with tricky octopus merge and its child, no color' '
@@ -171,9 +169,7 @@ test_expect_success 'log --graph with tricky octopus merge and its child with co
171169
<CYAN>|<RESET><CYAN>/<RESET>
172170
* initial
173171
EOF
174-
git log --color=always --graph --date-order --pretty=tformat:%s left after-merge >actual.colors.raw &&
175-
test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
176-
test_cmp expect.colors actual.colors
172+
test_cmp_colored_graph left after-merge
177173
'
178174

179175
test_expect_success 'log --graph with crossover in octopus merge, no color' '
@@ -215,9 +211,7 @@ test_expect_success 'log --graph with crossover in octopus merge with colors' '
215211
<MAGENTA>|<RESET><MAGENTA>/<RESET>
216212
* initial
217213
EOF
218-
git log --color=always --graph --date-order --pretty=tformat:%s after-4 octopus-merge >actual.colors.raw &&
219-
test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
220-
test_cmp expect.colors actual.colors
214+
test_cmp_colored_graph after-4 octopus-merge
221215
'
222216

223217
test_expect_success 'log --graph with crossover in octopus merge and its child, no color' '
@@ -261,9 +255,7 @@ test_expect_success 'log --graph with crossover in octopus merge and its child w
261255
<CYAN>|<RESET><CYAN>/<RESET>
262256
* initial
263257
EOF
264-
git log --color=always --graph --date-order --pretty=tformat:%s after-4 after-merge >actual.colors.raw &&
265-
test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
266-
test_cmp expect.colors actual.colors
258+
test_cmp_colored_graph after-4 after-merge
267259
'
268260

269261
test_expect_success 'log --graph with unrelated commit and octopus tip, no color' '
@@ -305,9 +297,7 @@ test_expect_success 'log --graph with unrelated commit and octopus tip with colo
305297
<RED>|<RESET><RED>/<RESET>
306298
* initial
307299
EOF
308-
git log --color=always --graph --date-order --pretty=tformat:%s after-initial octopus-merge >actual.colors.raw &&
309-
test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
310-
test_cmp expect.colors actual.colors
300+
test_cmp_colored_graph after-initial octopus-merge
311301
'
312302

313303
test_expect_success 'log --graph with unrelated commit and octopus child, no color' '
@@ -351,9 +341,7 @@ test_expect_success 'log --graph with unrelated commit and octopus child with co
351341
<RED>|<RESET><RED>/<RESET>
352342
* initial
353343
EOF
354-
git log --color=always --graph --date-order --pretty=tformat:%s after-initial after-merge >actual.colors.raw &&
355-
test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
356-
test_cmp expect.colors actual.colors
344+
test_cmp_colored_graph after-initial after-merge
357345
'
358346

359347
test_done

t/t4215-log-skewed-merges.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,7 @@ test_expect_success 'log --graph with multiple tips and colors' '
305305
<BLUE>|<RESET><BLUE>/<RESET>
306306
* 6_A
307307
EOF
308-
git log --color=always --graph --date-order --pretty=tformat:%s 6_1 6_3 6_5 >actual.colors.raw &&
309-
test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
310-
test_cmp expect.colors actual.colors
308+
lib_test_cmp_colored_graph --date-order --pretty=tformat:%s 6_1 6_3 6_5
311309
'
312310

313311
test_expect_success 'log --graph with multiple tips' '

0 commit comments

Comments
 (0)