use get_commit_buffer everywhere
Each of these sites assumes that commit->buffer is valid. Since they would segfault if this was not the case, they are likely to be correct in practice. However, we can future-proof them by using get_commit_buffer. And as a side effect, we abstract away the final bare uses of commit->buffer. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
b66103c3ba
commit
bc6b8fc130
|
@ -279,6 +279,7 @@ static const char *find_encoding(const char *begin, const char *end)
|
|||
static void handle_commit(struct commit *commit, struct rev_info *rev)
|
||||
{
|
||||
int saved_output_format = rev->diffopt.output_format;
|
||||
const char *commit_buffer;
|
||||
const char *author, *author_end, *committer, *committer_end;
|
||||
const char *encoding, *message;
|
||||
char *reencoded = NULL;
|
||||
|
@ -288,7 +289,8 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
|
|||
rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
|
||||
|
||||
parse_commit_or_die(commit);
|
||||
author = strstr(commit->buffer, "\nauthor ");
|
||||
commit_buffer = get_commit_buffer(commit);
|
||||
author = strstr(commit_buffer, "\nauthor ");
|
||||
if (!author)
|
||||
die ("Could not find author in commit %s",
|
||||
sha1_to_hex(commit->object.sha1));
|
||||
|
@ -335,6 +337,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
|
|||
? strlen(message) : 0),
|
||||
reencoded ? reencoded : message ? message : "");
|
||||
free(reencoded);
|
||||
unuse_commit_buffer(commit, commit_buffer);
|
||||
|
||||
for (i = 0, p = commit->parents; p; p = p->next) {
|
||||
int mark = get_object_mark(&p->item->object);
|
||||
|
|
|
@ -230,12 +230,14 @@ static void add_branch_desc(struct strbuf *out, const char *name)
|
|||
static void record_person(int which, struct string_list *people,
|
||||
struct commit *commit)
|
||||
{
|
||||
const char *buffer;
|
||||
char *name_buf, *name, *name_end;
|
||||
struct string_list_item *elem;
|
||||
const char *field;
|
||||
|
||||
field = (which == 'a') ? "\nauthor " : "\ncommitter ";
|
||||
name = strstr(commit->buffer, field);
|
||||
buffer = get_commit_buffer(commit);
|
||||
name = strstr(buffer, field);
|
||||
if (!name)
|
||||
return;
|
||||
name += strlen(field);
|
||||
|
@ -247,6 +249,7 @@ static void record_person(int which, struct string_list *people,
|
|||
if (name_end < name)
|
||||
return;
|
||||
name_buf = xmemdupz(name, name_end - name + 1);
|
||||
unuse_commit_buffer(commit, buffer);
|
||||
|
||||
elem = string_list_lookup(people, name_buf);
|
||||
if (!elem) {
|
||||
|
|
|
@ -918,9 +918,12 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
|
|||
log_write_email_headers(rev, head, &pp.subject, &pp.after_subject,
|
||||
&need_8bit_cte);
|
||||
|
||||
for (i = 0; !need_8bit_cte && i < nr; i++)
|
||||
if (has_non_ascii(list[i]->buffer))
|
||||
for (i = 0; !need_8bit_cte && i < nr; i++) {
|
||||
const char *buf = get_commit_buffer(list[i]);
|
||||
if (has_non_ascii(buf))
|
||||
need_8bit_cte = 1;
|
||||
unuse_commit_buffer(list[i], buf);
|
||||
}
|
||||
|
||||
if (!branch_name)
|
||||
branch_name = find_branch_name(rev);
|
||||
|
|
13
fsck.c
13
fsck.c
|
@ -276,9 +276,10 @@ static int fsck_ident(const char **ident, struct object *obj, fsck_error error_f
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int fsck_commit(struct commit *commit, fsck_error error_func)
|
||||
static int fsck_commit_buffer(struct commit *commit, const char *buffer,
|
||||
fsck_error error_func)
|
||||
{
|
||||
const char *buffer = commit->buffer, *tmp;
|
||||
const char *tmp;
|
||||
unsigned char tree_sha1[20], sha1[20];
|
||||
struct commit_graft *graft;
|
||||
int parents = 0;
|
||||
|
@ -336,6 +337,14 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int fsck_commit(struct commit *commit, fsck_error error_func)
|
||||
{
|
||||
const char *buffer = get_commit_buffer(commit);
|
||||
int ret = fsck_commit_buffer(commit, buffer, error_func);
|
||||
unuse_commit_buffer(commit, buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fsck_tag(struct tag *tag, fsck_error error_func)
|
||||
{
|
||||
struct object *tagged = tag->tagged;
|
||||
|
|
|
@ -190,9 +190,11 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
|
|||
printf(_("(bad commit)\n"));
|
||||
else {
|
||||
const char *title;
|
||||
int len = find_commit_subject(commit->buffer, &title);
|
||||
const char *msg = get_commit_buffer(commit);
|
||||
int len = find_commit_subject(msg, &title);
|
||||
if (len)
|
||||
printf("%.*s\n", len, title);
|
||||
unuse_commit_buffer(commit, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -672,7 +672,8 @@ int notes_merge_commit(struct notes_merge_options *o,
|
|||
DIR *dir;
|
||||
struct dirent *e;
|
||||
struct strbuf path = STRBUF_INIT;
|
||||
char *msg = strstr(partial_commit->buffer, "\n\n");
|
||||
const char *buffer = get_commit_buffer(partial_commit);
|
||||
const char *msg = strstr(buffer, "\n\n");
|
||||
int baselen;
|
||||
|
||||
strbuf_addstr(&path, git_path(NOTES_MERGE_WORKTREE));
|
||||
|
@ -721,6 +722,7 @@ int notes_merge_commit(struct notes_merge_options *o,
|
|||
|
||||
create_notes_commit(partial_tree, partial_commit->parents,
|
||||
msg, strlen(msg), result_sha1);
|
||||
unuse_commit_buffer(partial_commit, buffer);
|
||||
if (o->verbosity >= 4)
|
||||
printf("Finalized notes merge commit: %s\n",
|
||||
sha1_to_hex(result_sha1));
|
||||
|
|
|
@ -662,10 +662,12 @@ static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
|
|||
int subject_len;
|
||||
|
||||
for (cur = todo_list; cur; cur = cur->next) {
|
||||
const char *commit_buffer = get_commit_buffer(cur->item);
|
||||
sha1_abbrev = find_unique_abbrev(cur->item->object.sha1, DEFAULT_ABBREV);
|
||||
subject_len = find_commit_subject(cur->item->buffer, &subject);
|
||||
subject_len = find_commit_subject(commit_buffer, &subject);
|
||||
strbuf_addf(buf, "%s %s %.*s\n", action_str, sha1_abbrev,
|
||||
subject_len, subject);
|
||||
unuse_commit_buffer(cur->item, commit_buffer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue