X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-rerere.c;h=8c2c8bdc18a69e4dff7386548e5f7ea78a133f7b;hb=d01fb92f8d27cf8f0a843f4e9c0f8f022856b34d;hp=b8867ab4add83dee4ab99108e96949bcd65290a0;hpb=2c7ca1fcf19d3803a225130491e26dca86d1781d;p=git.git diff --git a/builtin-rerere.c b/builtin-rerere.c index b8867ab4a..8c2c8bdc1 100644 --- a/builtin-rerere.c +++ b/builtin-rerere.c @@ -78,6 +78,13 @@ static void append_line(struct buffer *buffer, const char *line) buffer->nr += len; } +static void clear_buffer(struct buffer *buffer) +{ + free(buffer->ptr); + buffer->ptr = NULL; + buffer->nr = buffer->alloc = 0; +} + static int handle_file(const char *path, unsigned char *sha1, const char *output) { @@ -110,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; @@ -131,6 +141,8 @@ static int handle_file(const char *path, SHA1_Update(&ctx, two->ptr, two->nr); SHA1_Update(&ctx, "\0", 1); } + clear_buffer(one); + clear_buffer(two); } else if (hunk == 1) append_line(one, buf); else if (hunk == 2)