]> asedeno.scripts.mit.edu Git - git.git/blobdiff - diff.c
Merge branch 'maint'
[git.git] / diff.c
diff --git a/diff.c b/diff.c
index fb6d077f06338271f16bfabb3e0c45f000de15ac..dfb8595b7086c71b3be0ece408d65a7285f42e9f 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -197,7 +197,7 @@ static char *quote_two(const char *one, const char *two)
                strbuf_addstr(&res, one);
                strbuf_addstr(&res, two);
        }
-       return res.buf;
+       return strbuf_detach(&res, NULL);
 }
 
 static const char *external_diff(void)
@@ -662,7 +662,7 @@ static char *pprint_rename(const char *a, const char *b)
                quote_c_style(a, &name, NULL, 0);
                strbuf_addstr(&name, " => ");
                quote_c_style(b, &name, NULL, 0);
-               return name.buf;
+               return strbuf_detach(&name, NULL);
        }
 
        /* Find common prefix */
@@ -710,7 +710,7 @@ static char *pprint_rename(const char *a, const char *b)
                strbuf_addch(&name, '}');
                strbuf_add(&name, a + len_a - sfx_length, sfx_length);
        }
-       return name.buf;
+       return strbuf_detach(&name, NULL);
 }
 
 struct diffstat_t {
@@ -827,7 +827,7 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
                        strbuf_init(&buf, 0);
                        if (quote_c_style(file->name, &buf, NULL, 0)) {
                                free(file->name);
-                               file->name = buf.buf;
+                               file->name = strbuf_detach(&buf, NULL);
                        } else {
                                strbuf_release(&buf);
                        }
@@ -1512,6 +1512,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
 static int populate_from_stdin(struct diff_filespec *s)
 {
        struct strbuf buf;
+       size_t size = 0;
 
        strbuf_init(&buf, 0);
        if (strbuf_read(&buf, 0, 0) < 0)
@@ -1519,8 +1520,8 @@ static int populate_from_stdin(struct diff_filespec *s)
                                     strerror(errno));
 
        s->should_munmap = 0;
-       s->size = buf.len;
-       s->data = strbuf_detach(&buf);
+       s->data = strbuf_detach(&buf, &size);
+       s->size = size;
        s->should_free = 1;
        return 0;
 }
@@ -1610,10 +1611,11 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
                 */
                strbuf_init(&buf, 0);
                if (convert_to_git(s->path, s->data, s->size, &buf)) {
+                       size_t size = 0;
                        munmap(s->data, s->size);
                        s->should_munmap = 0;
-                       s->data = buf.buf;
-                       s->size = buf.len;
+                       s->data = strbuf_detach(&buf, &size);
+                       s->size = size;
                        s->should_free = 1;
                }
        }
@@ -1629,7 +1631,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
        return 0;
 }
 
-void diff_free_filespec_data(struct diff_filespec *s)
+void diff_free_filespec_blob(struct diff_filespec *s)
 {
        if (s->should_free)
                free(s->data);
@@ -1640,6 +1642,11 @@ void diff_free_filespec_data(struct diff_filespec *s)
                s->should_free = s->should_munmap = 0;
                s->data = NULL;
        }
+}
+
+void diff_free_filespec_data(struct diff_filespec *s)
+{
+       diff_free_filespec_blob(s);
        free(s->cnt_data);
        s->cnt_data = NULL;
 }