X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-rerere.c;h=b463c07f04b127ee3d1e17962813367fb4a5a588;hb=566842f62bdf1f16c2e94fb431445d2e6c0f3f0b;hp=318d959d89669f09e12b1b97ca62f100e1a58ecd;hpb=ea44949605781d1947ba1422ee541867e7ce9b81;p=git.git diff --git a/builtin-rerere.c b/builtin-rerere.c index 318d959d8..b463c07f0 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) { @@ -105,11 +112,11 @@ 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, ">>>>>>> ")) { hunk_no++; hunk = 0; if (memcmp(one->ptr, two->ptr, one->nr < two->nr ? @@ -131,6 +138,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) @@ -154,13 +163,17 @@ static int find_conflict(struct path_list *conflict) return error("Could not read index"); for (i = 0; i + 2 < active_nr; i++) { struct cache_entry *e1 = active_cache[i]; - struct cache_entry *e2 = active_cache[i + 1]; - struct cache_entry *e3 = active_cache[i + 2]; - if (ce_stage(e1) == 1 && ce_stage(e2) == 2 && - ce_stage(e3) == 3 && ce_same_name(e1, e2) && - ce_same_name(e1, e3)) { + struct cache_entry *e2 = active_cache[i+1]; + struct cache_entry *e3 = active_cache[i+2]; + if (ce_stage(e1) == 1 && + ce_stage(e2) == 2 && + ce_stage(e3) == 3 && + ce_same_name(e1, e2) && ce_same_name(e1, e3) && + S_ISREG(ntohl(e1->ce_mode)) && + S_ISREG(ntohl(e2->ce_mode)) && + S_ISREG(ntohl(e3->ce_mode))) { path_list_insert((const char *)e1->name, conflict); - i += 3; + i += 2; } } return 0;