summaryrefslogtreecommitdiff
path: root/builtin-rerere.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-04-04 14:12:03 -0700
committerJunio C Hamano <junkio@cox.net>2007-04-04 14:12:03 -0700
commit2b93edbf32700d91c500806e4502077829d66d21 (patch)
treea2e9a4709978fe8af2bf0ed9da371ec8c90db109 /builtin-rerere.c
parent364b8523529163ffeeb71521239a18ac1f550512 (diff)
downloadgit-2b93edbf32700d91c500806e4502077829d66d21.tar.gz
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>
Diffstat (limited to 'builtin-rerere.c')
-rw-r--r--builtin-rerere.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/builtin-rerere.c b/builtin-rerere.c
index b463c07f04..8c2c8bdc18 100644
--- a/builtin-rerere.c
+++ b/builtin-rerere.c
@@ -117,10 +117,13 @@ static int handle_file(const char *path,
else if (!prefixcmp(buf, "======="))
hunk = 2;
else if (!prefixcmp(buf, ">>>>>>> ")) {
+ int one_is_longer = (one->nr > two->nr);
+ int common_len = one_is_longer ? two->nr : one->nr;
+ int cmp = memcmp(one->ptr, two->ptr, common_len);
+
hunk_no++;
hunk = 0;
- if (memcmp(one->ptr, two->ptr, one->nr < two->nr ?
- one->nr : two->nr) > 0) {
+ if ((cmp > 0) || ((cmp == 0) && one_is_longer)) {
struct buffer *swap = one;
one = two;
two = swap;