Skip to content

Commit

Permalink
provide a helper to set the commit buffer
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 13, 2014
1 parent 0fb370d commit 66c2827
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 66c2827

Please sign in to comment.