]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-rerere.c
Merge branch 'jc/remote'
[git.git] / builtin-rerere.c
index 004eda2acdf9b8ac5a66f9717d2244613b23768e..f6409b93c19aff7f8d820e52e39f45d717e31996 100644 (file)
@@ -112,15 +112,18 @@ static int handle_file(const char *path,
                SHA1_Init(&ctx);
 
        while (fgets(buf, sizeof(buf), f)) {
-               if (!strncmp("<<<<<<< ", buf, 8))
+               if (!prefixcmp(buf, "<<<<<<< "))
                        hunk = 1;
-               else if (!strncmp("=======", buf, 7))
+               else if (!prefixcmp(buf, "======="))
                        hunk = 2;
-               else if (!strncmp(">>>>>>> ", buf, 8)) {
+               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;
@@ -431,4 +434,3 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
        path_list_clear(&merge_rr, 1);
        return 0;
 }
-