Skip to content

Commit

Permalink
cocci: apply the "commit.h" part of "the_repository.pending"
Browse files Browse the repository at this point in the history
Apply the part of "the_repository.pending.cocci" pertaining to
"commit.h".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
avar authored and gitster committed Mar 28, 2023
1 parent cb338c2 commit ecb5091
Show file tree
Hide file tree
Showing 44 changed files with 196 additions and 174 deletions.
4 changes: 2 additions & 2 deletions blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,

if (sg_origin[i])
continue;
if (parse_commit(p))
if (repo_parse_commit(the_repository, p))
continue;
porigin = find(sb->repo, p, origin, sb->bloom_data);
if (!porigin)
Expand Down Expand Up @@ -2592,7 +2592,7 @@ void assign_blame(struct blame_scoreboard *sb, int opt)
* so hold onto it in the meantime.
*/
blame_origin_incref(suspect);
parse_commit(commit);
repo_parse_commit(the_repository, commit);
if (sb->reverse ||
(!(commit->object.flags & UNINTERESTING) &&
!(revs->max_age != -1 && commit->date < revs->max_age)))
Expand Down
7 changes: 4 additions & 3 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,8 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
size_t ident_len;
struct ident_split id;

buffer = logmsg_reencode(commit, NULL, get_commit_output_encoding());
buffer = repo_logmsg_reencode(the_repository, commit, NULL,
get_commit_output_encoding());

ident_line = find_commit_header(buffer, "author", &ident_len);
if (!ident_line)
Expand Down Expand Up @@ -1361,7 +1362,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid));
state->msg = xstrdup(msg + 2);
state->msg_len = strlen(state->msg);
unuse_commit_buffer(commit, buffer);
repo_unuse_commit_buffer(the_repository, commit, buffer);
}

/**
Expand Down Expand Up @@ -1404,7 +1405,7 @@ static void write_index_patch(const struct am_state *state)

if (!repo_get_oid(the_repository, "HEAD", &head)) {
struct commit *commit = lookup_commit_or_die(&head, "HEAD");
tree = get_commit_tree(commit);
tree = repo_get_commit_tree(the_repository, commit);
} else
tree = lookup_tree(the_repository,
the_repository->hash_algo->empty_tree);
Expand Down
6 changes: 3 additions & 3 deletions builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ static void get_commit_info(struct commit *commit,
const char *message;

encoding = get_log_output_encoding();
message = logmsg_reencode(commit, NULL, encoding);
message = repo_logmsg_reencode(the_repository, commit, NULL, encoding);
get_ac_line(message, "\nauthor ",
&ret->author, &ret->author_mail,
&ret->author_time, &ret->author_tz);

if (!detailed) {
unuse_commit_buffer(commit, message);
repo_unuse_commit_buffer(the_repository, commit, message);
return;
}

Expand All @@ -219,7 +219,7 @@ static void get_commit_info(struct commit *commit,
else
strbuf_addf(&ret->summary, "(%s)", oid_to_hex(&commit->object.oid));

unuse_commit_buffer(commit, message);
repo_unuse_commit_buffer(the_repository, commit, message);
}

/*
Expand Down
13 changes: 8 additions & 5 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ static void describe_detached_head(const char *msg, struct commit *commit)
{
struct strbuf sb = STRBUF_INIT;

if (!parse_commit(commit))
if (!repo_parse_commit(the_repository, commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
if (print_sha1_ellipsis()) {
fprintf(stderr, "%s %s... %s\n", msg,
Expand Down Expand Up @@ -755,7 +755,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
BUG("'switch --orphan' should never accept a commit as starting point");
new_tree = parse_tree_indirect(the_hash_algo->empty_tree);
} else
new_tree = get_commit_tree(new_branch_info->commit);
new_tree = repo_get_commit_tree(the_repository,
new_branch_info->commit);
if (opts->discard_changes) {
ret = reset_tree(new_tree, opts, 1, writeout_error, new_branch_info);
if (ret)
Expand Down Expand Up @@ -817,7 +818,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
*/
if (!old_branch_info->commit)
return 1;
old_tree = get_commit_tree(old_branch_info->commit);
old_tree = repo_get_commit_tree(the_repository,
old_branch_info->commit);

if (repo_index_has_changes(the_repository, old_tree, &sb))
die(_("cannot continue with staged changes in "
Expand Down Expand Up @@ -1006,7 +1008,7 @@ static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
strbuf_addstr(sb, " ");
strbuf_add_unique_abbrev(sb, &commit->object.oid, DEFAULT_ABBREV);
strbuf_addch(sb, ' ');
if (!parse_commit(commit))
if (!repo_parse_commit(the_repository, commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
strbuf_addch(sb, '\n');
}
Expand Down Expand Up @@ -1206,7 +1208,8 @@ static void setup_new_branch_info_and_source_tree(
*source_tree = parse_tree_indirect(rev);
} else {
parse_commit_or_die(new_branch_info->commit);
*source_tree = get_commit_tree(new_branch_info->commit);
*source_tree = repo_get_commit_tree(the_repository,
new_branch_info->commit);
}
}

Expand Down
8 changes: 4 additions & 4 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,15 @@ static void prepare_amend_commit(struct commit *commit, struct strbuf *sb,
{
const char *buffer, *subject, *fmt;

buffer = get_commit_buffer(commit, NULL);
buffer = repo_get_commit_buffer(the_repository, commit, NULL);
find_commit_subject(buffer, &subject);
/*
* If we amend the 'amend!' commit then we don't want to
* duplicate the subject line.
*/
fmt = starts_with(subject, "amend!") ? "%b" : "%B";
format_commit_message(commit, fmt, sb, ctx);
unuse_commit_buffer(commit, buffer);
repo_unuse_commit_buffer(the_repository, commit, buffer);
}

static int prepare_to_commit(const char *index_file, const char *prefix,
Expand Down Expand Up @@ -1183,7 +1183,7 @@ static const char *read_commit_message(const char *name)
if (!commit)
die(_("could not lookup commit %s"), name);
out_enc = get_commit_output_encoding();
return logmsg_reencode(commit, NULL, out_enc);
return repo_logmsg_reencode(the_repository, commit, NULL, out_enc);
}

/*
Expand Down Expand Up @@ -1718,7 +1718,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
current_head = NULL;
else {
current_head = lookup_commit_or_die(&oid, "HEAD");
if (parse_commit(current_head))
if (repo_parse_commit(the_repository, current_head))
die(_("could not parse HEAD commit"));
}
verbose = -1; /* unspecified */
Expand Down
4 changes: 2 additions & 2 deletions builtin/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static unsigned long finish_depth_computation(
best->depth++;
while (parents) {
struct commit *p = parents->item;
parse_commit(p);
repo_parse_commit(the_repository, p);
if (!(p->object.flags & SEEN))
commit_list_insert_by_date(p, list);
p->object.flags |= c->object.flags;
Expand Down Expand Up @@ -404,7 +404,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
}
while (parents) {
struct commit *p = parents->item;
parse_commit(p);
repo_parse_commit(the_repository, p);
if (!(p->object.flags & SEEN))
commit_list_insert_by_date(p, &list);
p->object.flags |= c->object.flags;
Expand Down
3 changes: 2 additions & 1 deletion builtin/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
if (!obj)
die(_("invalid object '%s' given."), name);
if (obj->type == OBJ_COMMIT)
obj = &get_commit_tree(((struct commit *)obj))->object;
obj = &repo_get_commit_tree(the_repository,
((struct commit *)obj))->object;

if (obj->type == OBJ_TREE) {
if (sdiff.skip && bitmap_get(sdiff.skip, i))
Expand Down
4 changes: 2 additions & 2 deletions builtin/fast-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;

parse_commit_or_die(commit);
commit_buffer = get_commit_buffer(commit, NULL);
commit_buffer = repo_get_commit_buffer(the_repository, commit, NULL);
author = strstr(commit_buffer, "\nauthor ");
if (!author)
die("could not find author in commit %s",
Expand Down Expand Up @@ -699,7 +699,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);
repo_unuse_commit_buffer(the_repository, commit, commit_buffer);

for (i = 0, p = commit->parents; p; p = p->next) {
struct object *obj = &p->item->object;
Expand Down
4 changes: 2 additions & 2 deletions builtin/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ static int dfs_on_ref(const char *refname UNUSED,
commit = lookup_commit(the_repository, oid);
if (!commit)
return 0;
if (parse_commit(commit) ||
if (repo_parse_commit(the_repository, commit) ||
commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
return 0;

Expand All @@ -837,7 +837,7 @@ static int dfs_on_ref(const char *refname UNUSED,
commit = pop_commit(&stack);

for (parent = commit->parents; parent; parent = parent->next) {
if (parse_commit(parent->item) ||
if (repo_parse_commit(the_repository, parent->item) ||
commit_graph_position(parent->item) != COMMIT_NOT_FROM_GRAPH ||
parent->item->object.flags & SEEN)
continue;
Expand Down
5 changes: 3 additions & 2 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,11 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte, 0);

for (i = 0; !need_8bit_cte && i < nr; i++) {
const char *buf = get_commit_buffer(list[i], NULL);
const char *buf = repo_get_commit_buffer(the_repository,
list[i], NULL);
if (has_non_ascii(buf))
need_8bit_cte = 1;
unuse_commit_buffer(list[i], buf);
repo_unuse_commit_buffer(the_repository, list[i], buf);
}

if (!branch_name)
Expand Down
6 changes: 3 additions & 3 deletions builtin/merge-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ static int real_merge(struct merge_tree_options *o,
die(_("could not lookup commit %s"), merge_base);

opt.ancestor = merge_base;
base_tree = get_commit_tree(base_commit);
parent1_tree = get_commit_tree(parent1);
parent2_tree = get_commit_tree(parent2);
base_tree = repo_get_commit_tree(the_repository, base_commit);
parent1_tree = repo_get_commit_tree(the_repository, parent1);
parent2_tree = repo_get_commit_tree(the_repository, parent2);
merge_incore_nonrecursive(&opt, base_tree, parent1_tree, parent2_tree, &result);
} else {
/*
Expand Down
3 changes: 2 additions & 1 deletion builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* Must first ensure that index matches HEAD before
* attempting a trivial merge.
*/
struct tree *head_tree = get_commit_tree(head_commit);
struct tree *head_tree = repo_get_commit_tree(the_repository,
head_commit);
struct strbuf sb = STRBUF_INIT;

if (repo_index_has_changes(the_repository, head_tree,
Expand Down
4 changes: 2 additions & 2 deletions builtin/name-rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static void name_rev(struct commit *start_commit,
size_t parents_to_queue_nr, parents_to_queue_alloc = 0;
struct rev_name *start_name;

parse_commit(start_commit);
repo_parse_commit(the_repository, start_commit);
if (commit_is_before_cutoff(start_commit))
return;

Expand Down Expand Up @@ -211,7 +211,7 @@ static void name_rev(struct commit *start_commit,
struct rev_name *parent_name;
int generation, distance;

parse_commit(parent);
repo_parse_commit(the_repository, parent);
if (commit_is_before_cutoff(parent))
continue;

Expand Down
2 changes: 1 addition & 1 deletion builtin/notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ static int merge_commit(struct notes_merge_options *o)
die(_("failed to read ref NOTES_MERGE_PARTIAL"));
else if (!(partial = lookup_commit_reference(the_repository, &oid)))
die(_("could not find commit from NOTES_MERGE_PARTIAL."));
else if (parse_commit(partial))
else if (repo_parse_commit(the_repository, partial))
die(_("could not parse commit from NOTES_MERGE_PARTIAL."));

if (partial->parents)
Expand Down
2 changes: 1 addition & 1 deletion builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ static int checkout_up_to_date(struct rebase_options *options)
static int is_linear_history(struct commit *from, struct commit *to)
{
while (to && to != from) {
parse_commit(to);
repo_parse_commit(the_repository, to);
if (!to->parents)
return 1;
if (to->parents->next)
Expand Down
4 changes: 2 additions & 2 deletions builtin/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,9 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
if (!commit)
return error(_("could not parse %s"), old_ref);

buffer = get_commit_buffer(commit, &size);
buffer = repo_get_commit_buffer(the_repository, commit, &size);
strbuf_add(&buf, buffer, size);
unuse_commit_buffer(commit, buffer);
repo_unuse_commit_buffer(the_repository, commit, buffer);

if (replace_parents(&buf, argc - 1, &argv[1]) < 0) {
strbuf_release(&buf);
Expand Down
5 changes: 3 additions & 2 deletions builtin/shortlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ static void insert_records_from_trailers(struct shortlog *log,
* Using format_commit_message("%B") would be simpler here, but
* this saves us copying the message.
*/
commit_buffer = logmsg_reencode(commit, NULL, ctx->output_encoding);
commit_buffer = repo_logmsg_reencode(the_repository, commit, NULL,
ctx->output_encoding);
body = strstr(commit_buffer, "\n\n");
if (!body)
return;
Expand All @@ -202,7 +203,7 @@ static void insert_records_from_trailers(struct shortlog *log,
trailer_iterator_release(&iter);

strbuf_release(&ident);
unuse_commit_buffer(commit, commit_buffer);
repo_unuse_commit_buffer(the_repository, commit, commit_buffer);
}

static int shortlog_needs_dedup(const struct shortlog *log)
Expand Down
4 changes: 2 additions & 2 deletions builtin/show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static void join_revs(struct commit_list **list_p,
parents = parents->next;
if ((this_flag & flags) == flags)
continue;
parse_commit(p);
repo_parse_commit(the_repository, p);
if (mark_seen(p, seen_p) && !still_interesting)
extra--;
p->object.flags |= flags;
Expand Down Expand Up @@ -842,7 +842,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
if (!commit)
die(_("cannot find commit %s (%s)"),
ref_name[num_rev], oid_to_hex(&revkey));
parse_commit(commit);
repo_parse_commit(the_repository, commit);
mark_seen(commit, &seen);

/* rev#0 uses bit REV_SHIFT, rev#1 uses bit REV_SHIFT+1,
Expand Down
2 changes: 1 addition & 1 deletion commit-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)

graph_commit = lookup_commit(r, &cur_oid);
odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
if (parse_commit_internal(odb_commit, 0, 0)) {
if (repo_parse_commit_internal(the_repository, odb_commit, 0, 0)) {
graph_report(_("failed to parse commit %s from object database for commit-graph"),
oid_to_hex(&cur_oid));
continue;
Expand Down
Loading

0 comments on commit ecb5091

Please sign in to comment.