provide a helper to set the commit buffer
authorJeff King <peff@peff.net>
Tue, 10 Jun 2014 21:40:14 +0000 (17:40 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 13 Jun 2014 19:08:17 +0000 (12:08 -0700)
Right now this is just a one-liner, but abstracting it will
make it easier to change later.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/blame.c
commit.c
commit.h
object.c
index 85a36813069f91e3a9b8ea5aa172d015265b9385..38784ab9d6714400cbb7e7c555ef5a19376d307e 100644 (file)
@@ -2046,7 +2046,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)));
-       commit->buffer = strbuf_detach(&msg, NULL);
+       set_commit_buffer(commit, strbuf_detach(&msg, NULL));
 
        if (!contents_from || strcmp("-", contents_from)) {
                struct stat st;
index 11a05c1f24f541fa3495adc502cb292c3891fab4..fc8b4e287d7e0219d13569d40ddb3c90a7a4b96b 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -245,6 +245,11 @@ int unregister_shallow(const unsigned char *sha1)
        return 0;
 }
 
+void set_commit_buffer(struct commit *commit, void *buffer)
+{
+       commit->buffer = buffer;
+}
+
 void free_commit_buffer(struct commit *commit)
 {
        free(commit->buffer);
@@ -335,7 +340,7 @@ int parse_commit(struct commit *item)
        }
        ret = parse_commit_buffer(item, buffer, size);
        if (save_commit_buffer && !ret) {
-               item->buffer = buffer;
+               set_commit_buffer(item, buffer);
                return 0;
        }
        free(buffer);
index d72ed4334049b161116d945bfdbc08d59068ce1a..cc89128894d2514ff70e5d46bc149c95b44a7760 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -51,6 +51,12 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
 int parse_commit(struct commit *item);
 void parse_commit_or_die(struct commit *item);
 
+/*
+ * Associate an object buffer with the commit. The ownership of the
+ * memory is handed over to the commit, and must be free()-able.
+ */
+void set_commit_buffer(struct commit *, void *buffer);
+
 /*
  * Free any cached object buffer associated with the commit.
  */
index 57a0890a87b66ea493337409606e57fd44d29f90..44ca6572045e055f21094bf6fffad43ed36da9ca 100644 (file)
--- a/object.c
+++ b/object.c
@@ -198,7 +198,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
                        if (parse_commit_buffer(commit, buffer, size))
                                return NULL;
                        if (!commit->buffer) {
-                               commit->buffer = buffer;
+                               set_commit_buffer(commit, buffer);
                                *eaten_p = 1;
                        }
                        obj = &commit->object;