]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/blame.c
commit: record buffer length in cache
[thirdparty/git.git] / builtin / blame.c
index 857d98a3247c9ba63cf14fa33c9d65fa5b77761b..b84e375b5c5cdd2c6f0a18f0c57462131cb14ec3 100644 (file)
@@ -1998,6 +1998,18 @@ static void append_merge_parents(struct commit_list **tail)
        strbuf_release(&line);
 }
 
+/*
+ * This isn't as simple as passing sb->buf and sb->len, because we
+ * want to transfer ownership of the buffer to the commit (so we
+ * must use detach).
+ */
+static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb)
+{
+       size_t len;
+       void *buf = strbuf_detach(sb, &len);
+       set_commit_buffer(c, buf, len);
+}
+
 /*
  * Prepare a dummy commit that represents the work tree (or staged) item.
  * Note that annotating work tree item never works in the reverse.
@@ -2046,7 +2058,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
                    ident, ident, path,
                    (!contents_from ? path :
                     (!strcmp(contents_from, "-") ? "standard input" : contents_from)));
-       set_commit_buffer(commit, strbuf_detach(&msg, NULL));
+       set_commit_buffer_from_strbuf(commit, &msg);
 
        if (!contents_from || strcmp("-", contents_from)) {
                struct stat st;