rerere: make sorting really stable.
The earlier code does not swap hunks when the beginning of the first side is identical to the whole of the second side. In such a case, the first one should sort later. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 4, 2007 at 14:12 UTC
2b93edbf32700d91c500806e4502077829d66d21
2 files changed
+10
-6
builtin-rerere.c
+5
-2
@@ -117,10 +117,13 @@ static int handle_file(const char *path,
117
else if (!prefixcmp(buf, "======="))
118
hunk = 2;
119
else if (!prefixcmp(buf, ">>>>>>> ")) {
120
+ int one_is_longer = (one->nr > two->nr);
121
+ int common_len = one_is_longer ? two->nr : one->nr;
122
+ int cmp = memcmp(one->ptr, two->ptr, common_len);
123
+
124
hunk_no++;
125
hunk = 0;
122
- if (memcmp(one->ptr, two->ptr, one->nr < two->nr ?
123
- one->nr : two->nr) > 0) {
126
+ if ((cmp > 0) || ((cmp == 0) && one_is_longer)) {
127
struct buffer *swap = one;
128
one = two;
129
two = swap;
t/t4200-rerere.sh
+5
-4
@@ -35,7 +35,8 @@ git commit -q -a -m first
35
36
git checkout -b second master
37
git show first:a1 |
38
-sed -e 's/To die, t/To die! T/' -e 's/life;$/life./' > a1
38
+sed -e 's/To die, t/To die! T/' > a1
39
+echo "* END *" >>a1
40
git commit -q -a -m second
41
42
# activate rerere
@@ -53,7 +54,7 @@ test_expect_success 'no postimage or thisimage yet' \
54
test_expect_success 'preimage has right number of lines' '
55
56
cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
56
- test $cnt = 10
57
+ test $cnt = 9
58
59
'
60
@@ -75,10 +76,10 @@ cat > expect << EOF
76
For in that sleep of death what dreams may come
77
When we have shuffled off this mortal coil,
78
Must give us pause: there's the respect
79
+ That makes calamity of so long life;
80
-<<<<<<<
79
--That makes calamity of so long life.
81
-=======
81
- That makes calamity of so long life;
82
+-* END *
83
->>>>>>>
84
EOF
85
git rerere diff > out