Code

Merge branch 'lt/dirwalk'
[git.git] / builtin-rerere.c
index 58c5fed91d9d8f2f0fd573f5621344f795f1c11c..b463c07f04b127ee3d1e17962813367fb4a5a588 100644 (file)
@@ -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)