Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 66c2827

Browse files
peffgitster
authored andcommitted
provide a helper to set the commit buffer
Right now this is just a one-liner, but abstracting it will make it easier to change later. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0fb370d commit 66c2827

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
20462046
ident, ident, path,
20472047
(!contents_from ? path :
20482048
(!strcmp(contents_from, "-") ? "standard input" : contents_from)));
2049-
commit->buffer = strbuf_detach(&msg, NULL);
2049+
set_commit_buffer(commit, strbuf_detach(&msg, NULL));
20502050

20512051
if (!contents_from || strcmp("-", contents_from)) {
20522052
struct stat st;

commit.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ int unregister_shallow(const unsigned char *sha1)
245245
return 0;
246246
}
247247

248+
void set_commit_buffer(struct commit *commit, void *buffer)
249+
{
250+
commit->buffer = buffer;
251+
}
252+
248253
void free_commit_buffer(struct commit *commit)
249254
{
250255
free(commit->buffer);
@@ -335,7 +340,7 @@ int parse_commit(struct commit *item)
335340
}
336341
ret = parse_commit_buffer(item, buffer, size);
337342
if (save_commit_buffer && !ret) {
338-
item->buffer = buffer;
343+
set_commit_buffer(item, buffer);
339344
return 0;
340345
}
341346
free(buffer);

commit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
5151
int parse_commit(struct commit *item);
5252
void parse_commit_or_die(struct commit *item);
5353

54+
/*
55+
* Associate an object buffer with the commit. The ownership of the
56+
* memory is handed over to the commit, and must be free()-able.
57+
*/
58+
void set_commit_buffer(struct commit *, void *buffer);
59+
5460
/*
5561
* Free any cached object buffer associated with the commit.
5662
*/

object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
198198
if (parse_commit_buffer(commit, buffer, size))
199199
return NULL;
200200
if (!commit->buffer) {
201-
commit->buffer = buffer;
201+
set_commit_buffer(commit, buffer);
202202
*eaten_p = 1;
203203
}
204204
obj = &commit->object;

0 commit comments

Comments
 (0)