Topo-sort before --simplify-merges
This makes the algorithm more honest about what it is doing. We start from an already limited, topo-sorted list, and postprocess it by simplifying the irrelevant merges away. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 3, 2008 at 17:47 UTC
65347030590bcc251a9ff2ed96487a0f1b9e9fa8
2 files changed
+95
-3
revision.c
+2
-3
@@ -1493,6 +1493,8 @@ static void simplify_merges(struct rev_info *revs)
1493
struct commit_list *list;
1494
struct commit_list *yet_to_do, **tail;
1495
1496
+ sort_in_topological_order(&revs->commits, revs->lifo);
1497
+
1498
/* feed the list reversed */
1499
yet_to_do = NULL;
1500
for (list = revs->commits; list; list = list->next)
@@ -1522,9 +1524,6 @@ static void simplify_merges(struct rev_info *revs)
1524
if (commit->util == commit)
1525
tail = &commit_list_insert(commit, tail)->next;
1526
}
1525
-
1526
- /* sort topologically at the end */
1527
- sort_in_topological_order(&revs->commits, revs->lifo);
1527
}
1528
1529
static void set_children(struct rev_info *revs)
t/t6012-rev-list-simplify.sh
new
+93
@@ -0,0 +1,93 @@
1
+#!/bin/sh
2
+
3
+test_description='merge simplification'
4
+
5
+. ./test-lib.sh
6
+
7
+note () {
8
+ git tag "$1"
9
+}
10
+
11
+_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
12
+_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
13
+
14
+unnote () {
15
+ git name-rev --tags --stdin | sed -e "s|$_x40 (tags/\([^)]*\)) |\1 |g"
16
+}
17
+
18
+test_expect_success setup '
19
+ echo "Hi there" >file &&
20
+ git add file &&
21
+ test_tick && git commit -m "Initial file" &&
22
+ note A &&
23
+
24
+ git branch other-branch &&
25
+
26
+ echo "Hello" >file &&
27
+ git add file &&
28
+ test_tick && git commit -m "Modified file" &&
29
+ note B &&
30
+
31
+ git checkout other-branch &&
32
+
33
+ echo "Hello" >file &&
34
+ git add file &&
35
+ test_tick && git commit -m "Modified the file identically" &&
36
+ note C &&
37
+
38
+ echo "This is a stupid example" >another-file &&
39
+ git add another-file &&
40
+ test_tick && git commit -m "Add another file" &&
41
+ note D &&
42
+
43
+ test_tick && git merge -m "merge" master &&
44
+ note E &&
45
+
46
+ echo "Yet another" >elif &&
47
+ git add elif &&
48
+ test_tick && git commit -m "Irrelevant change" &&
49
+ note F &&
50
+
51
+ git checkout master &&
52
+ echo "Yet another" >elif &&
53
+ git add elif &&
54
+ test_tick && git commit -m "Another irrelevant change" &&
55
+ note G &&
56
+
57
+ test_tick && git merge -m "merge" other-branch &&
58
+ note H &&
59
+
60
+ echo "Final change" >file &&
61
+ test_tick && git commit -a -m "Final change" &&
62
+ note I
63
+'
64
+
65
+FMT='tformat:%P %H | %s'
66
+
67
+check_result () {
68
+ for c in $1
69
+ do
70
+ echo "$c"
71
+ done >expect &&
72
+ shift &&
73
+ param="$*" &&
74
+ test_expect_success "log $param" '
75
+ git log --pretty="$FMT" --parents $param |
76
+ unnote >actual &&
77
+ sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
78
+ test_cmp expect check || {
79
+ cat actual
80
+ false
81
+ }
82
+ '
83
+}
84
+
85
+check_result 'I H G F E D C B A' --full-history
86
+check_result 'I H E C B A' --full-history -- file
87
+check_result 'I H E C B A' --full-history --topo-order -- file
88
+check_result 'I H E C B A' --full-history --date-order -- file
89
+check_result 'I E C B A' --simplify-merges -- file
90
+check_result 'I B A' -- file
91
+check_result 'I B A' --topo-order -- file
92
+
93
+test_done