Skip to content

Commit

Permalink
Merge branch 'ab/remove-implicit-use-of-the-repository'
Browse files Browse the repository at this point in the history
Code clean-up around the use of the_repository.

* ab/remove-implicit-use-of-the-repository:
  libs: use "struct repository *" argument, not "the_repository"
  post-cocci: adjust comments for recent repo_* migration
  cocci: apply the "revision.h" part of "the_repository.pending"
  cocci: apply the "rerere.h" part of "the_repository.pending"
  cocci: apply the "refs.h" part of "the_repository.pending"
  cocci: apply the "promisor-remote.h" part of "the_repository.pending"
  cocci: apply the "packfile.h" part of "the_repository.pending"
  cocci: apply the "pretty.h" part of "the_repository.pending"
  cocci: apply the "object-store.h" part of "the_repository.pending"
  cocci: apply the "diff.h" part of "the_repository.pending"
  cocci: apply the "commit.h" part of "the_repository.pending"
  cocci: apply the "commit-reach.h" part of "the_repository.pending"
  cocci: apply the "cache.h" part of "the_repository.pending"
  cocci: add missing "the_repository" macros to "pending"
  cocci: sort "the_repository" rules by header
  cocci: fix incorrect & verbose "the_repository" rules
  cocci: remove dead rule from "the_repository.pending.cocci"
  • Loading branch information
gitster committed Apr 6, 2023
2 parents 06e9e72 + 4a93b89 commit 72871b1
Show file tree
Hide file tree
Showing 148 changed files with 958 additions and 873 deletions.
2 changes: 1 addition & 1 deletion add-interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ static int get_modified_files(struct repository *r,
opt.def = is_initial ?
empty_tree_oid_hex() : oid_to_hex(&head_oid);

init_revisions(&rev, NULL);
repo_init_revisions(r, &rev, NULL);
setup_revisions(0, NULL, &rev, &opt);

rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
Expand Down
2 changes: 1 addition & 1 deletion add-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
strvec_push(&args,
/* could be on an unborn branch */
!strcmp("HEAD", s->revision) &&
get_oid("HEAD", &oid) ?
repo_get_oid(the_repository, "HEAD", &oid) ?
empty_tree_oid_hex() : s->revision);
}
color_arg_index = args.nr;
Expand Down
13 changes: 8 additions & 5 deletions apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -3203,7 +3203,8 @@ static int apply_binary(struct apply_state *state,
unsigned long size;
char *result;

result = read_object_file(&oid, &type, &size);
result = repo_read_object_file(the_repository, &oid, &type,
&size);
if (!result)
return error(_("the necessary postimage %s for "
"'%s' cannot be read"),
Expand Down Expand Up @@ -3266,7 +3267,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
unsigned long sz;
char *result;

result = read_object_file(oid, &type, &sz);
result = repo_read_object_file(the_repository, oid, &type,
&sz);
if (!result)
return -1;
/* XXX read_sha1_file NUL-terminates */
Expand Down Expand Up @@ -3494,7 +3496,8 @@ static int resolve_to(struct image *image, const struct object_id *result_id)

clear_image(image);

image->buf = read_object_file(result_id, &type, &size);
image->buf = repo_read_object_file(the_repository, result_id, &type,
&size);
if (!image->buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(result_id));
image->len = size;
Expand Down Expand Up @@ -3612,7 +3615,7 @@ static int try_threeway(struct apply_state *state,
/* Preimage the patch was prepared for */
if (patch->is_new)
write_object_file("", 0, OBJ_BLOB, &pre_oid);
else if (get_oid(patch->old_oid_prefix, &pre_oid) ||
else if (repo_get_oid(the_repository, patch->old_oid_prefix, &pre_oid) ||
read_blob_object(&buf, &pre_oid, patch->old_mode))
return error(_("repository lacks the necessary blob to perform 3-way merge."));

Expand Down Expand Up @@ -4129,7 +4132,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
else
return error(_("sha1 information is lacking or "
"useless for submodule %s"), name);
} else if (!get_oid_blob(patch->old_oid_prefix, &oid)) {
} else if (!repo_get_oid_blob(the_repository, patch->old_oid_prefix, &oid)) {
; /* ok */
} else if (!patch->lines_added && !patch->lines_deleted) {
/* mode-only change: update the current */
Expand Down
12 changes: 7 additions & 5 deletions archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ static void format_subst(const struct commit *commit,
strbuf_add(&fmt, b + 8, c - b - 8);

strbuf_add(buf, src, b - src);
format_commit_message(commit, fmt.buf, buf, ctx);
repo_format_commit_message(the_repository, commit, fmt.buf,
buf, ctx);
len -= c + 1 - src;
src = c + 1;
}
Expand All @@ -86,7 +87,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
(args->tree ? &args->tree->object.oid : NULL), oid);

path += args->baselen;
buffer = read_object_file(oid, type, sizep);
buffer = repo_read_object_file(the_repository, oid, type, sizep);
if (buffer && S_ISREG(mode)) {
struct strbuf buf = STRBUF_INIT;
size_t size = 0;
Expand Down Expand Up @@ -457,13 +458,14 @@ static void parse_treeish_arg(const char **argv,
const char *colon = strchrnul(name, ':');
int refnamelen = colon - name;

if (!dwim_ref(name, refnamelen, &oid, &ref, 0))
if (!repo_dwim_ref(the_repository, name, refnamelen, &oid, &ref, 0))
die(_("no such ref: %.*s"), refnamelen, name);
} else {
dwim_ref(name, strlen(name), &oid, &ref, 0);
repo_dwim_ref(the_repository, name, strlen(name), &oid, &ref,
0);
}

if (get_oid(name, &oid))
if (repo_get_oid(the_repository, name, &oid))
die(_("not a valid object name: %s"), name);

commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1);
Expand Down
11 changes: 7 additions & 4 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ static void show_list(const char *debug, int counted, int nr,
unsigned commit_flags = commit->object.flags;
enum object_type type;
unsigned long size;
char *buf = read_object_file(&commit->object.oid, &type,
&size);
char *buf = repo_read_object_file(the_repository,
&commit->object.oid, &type,
&size);
const char *subject_start;
int subject_len;

Expand Down Expand Up @@ -752,7 +753,8 @@ enum bisect_error bisect_checkout(const struct object_id *bisect_rev,
}

commit = lookup_commit_reference(the_repository, bisect_rev);
format_commit_message(commit, "[%H] %s%n", &commit_msg, &pp);
repo_format_commit_message(the_repository, commit, "[%H] %s%n",
&commit_msg, &pp);
fputs(commit_msg.buf, stdout);
strbuf_release(&commit_msg);

Expand Down Expand Up @@ -847,7 +849,8 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int
enum bisect_error res = BISECT_OK;
struct commit_list *result;

result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1);
result = repo_get_merge_bases_many(the_repository, rev[0], rev_nr - 1,
rev + 1);

for (; result; result = result->next) {
const struct object_id *mb = &result->item->object.oid;
Expand Down
15 changes: 9 additions & 6 deletions blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,8 +1026,9 @@ static void fill_origin_blob(struct diff_options *opt,
&o->blob_oid, 1, &file->ptr, &file_size))
;
else
file->ptr = read_object_file(&o->blob_oid, &type,
&file_size);
file->ptr = repo_read_object_file(the_repository,
&o->blob_oid, &type,
&file_size);
file->size = file_size;

if (!file->ptr)
Expand Down Expand Up @@ -2427,7 +2428,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 @@ -2590,7 +2591,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 Expand Up @@ -2851,8 +2852,10 @@ void setup_scoreboard(struct blame_scoreboard *sb,
&sb->final_buf_size))
;
else
sb->final_buf = read_object_file(&o->blob_oid, &type,
&sb->final_buf_size);
sb->final_buf = repo_read_object_file(the_repository,
&o->blob_oid,
&type,
&sb->final_buf_size);

if (!sb->final_buf)
die(_("cannot read blob %s for path %s"),
Expand Down
7 changes: 4 additions & 3 deletions branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
explicit_tracking = 1;

real_ref = NULL;
if (get_oid_mb(start_name, &oid)) {
if (repo_get_oid_mb(r, start_name, &oid)) {
if (explicit_tracking) {
int code = die_message(_(upstream_missing), start_name);
advise_if_enabled(ADVICE_SET_UPSTREAM_FAILURE,
Expand All @@ -542,7 +542,8 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
die(_("not a valid object name: '%s'"), start_name);
}

switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref, 0)) {
switch (repo_dwim_ref(r, start_name, strlen(start_name), &oid,
&real_ref, 0)) {
case 0:
/* Not branching from any existing branch */
if (explicit_tracking)
Expand Down Expand Up @@ -773,7 +774,7 @@ void create_branches_recursively(struct repository *r, const char *name,
name);
}

create_branch(the_repository, name, start_commitish, force, 0, reflog, quiet,
create_branch(r, name, start_commitish, force, 0, reflog, quiet,
BRANCH_TRACK_NEVER, dry_run);
if (dry_run)
return;
Expand Down
23 changes: 12 additions & 11 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
else
write_state_text(state, "applying", "");

if (!get_oid("HEAD", &curr_head)) {
if (!repo_get_oid(the_repository, "HEAD", &curr_head)) {
write_state_text(state, "abort-safety", oid_to_hex(&curr_head));
if (!state->rebasing)
update_ref("am", "ORIG_HEAD", &curr_head, NULL, 0,
Expand Down Expand Up @@ -1110,7 +1110,7 @@ static void am_next(struct am_state *state)
unlink(am_path(state, "original-commit"));
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);

if (!get_oid("HEAD", &head))
if (!repo_get_oid(the_repository, "HEAD", &head))
write_state_text(state, "abort-safety", oid_to_hex(&head));
else
write_state_text(state, "abort-safety", "");
Expand Down Expand Up @@ -1330,7 +1330,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 @@ -1362,7 +1363,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 @@ -1403,9 +1404,9 @@ static void write_index_patch(const struct am_state *state)
struct rev_info rev_info;
FILE *fp;

if (!get_oid("HEAD", &head)) {
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 Expand Up @@ -1557,7 +1558,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
struct commit *result;
char *their_tree_name;

if (get_oid("HEAD", &our_tree) < 0)
if (repo_get_oid(the_repository, "HEAD", &our_tree) < 0)
oidcpy(&our_tree, the_hash_algo->empty_tree);

if (build_fake_ancestor(state, index_path))
Expand Down Expand Up @@ -1647,7 +1648,7 @@ static void do_commit(const struct am_state *state)
if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL))
die(_("git write-tree failed to write a tree"));

if (!get_oid_commit("HEAD", &parent)) {
if (!repo_get_oid_commit(the_repository, "HEAD", &parent)) {
old_oid = &parent;
commit_list_insert(lookup_commit(the_repository, &parent),
&parents);
Expand Down Expand Up @@ -2089,7 +2090,7 @@ static void am_skip(struct am_state *state)

am_rerere_clear();

if (get_oid("HEAD", &head))
if (repo_get_oid(the_repository, "HEAD", &head))
oidcpy(&head, the_hash_algo->empty_tree);

if (clean_index(&head, &head))
Expand Down Expand Up @@ -2131,7 +2132,7 @@ static int safe_to_abort(const struct am_state *state)
oidclr(&abort_safety);
strbuf_release(&sb);

if (get_oid("HEAD", &head))
if (repo_get_oid(the_repository, "HEAD", &head))
oidclr(&head);

if (oideq(&head, &abort_safety))
Expand Down Expand Up @@ -2164,7 +2165,7 @@ static void am_abort(struct am_state *state)
if (!has_curr_head)
oidcpy(&curr_head, the_hash_algo->empty_tree);

has_orig_head = !get_oid("ORIG_HEAD", &orig_head);
has_orig_head = !repo_get_oid(the_repository, "ORIG_HEAD", &orig_head);
if (!has_orig_head)
oidcpy(&orig_head, the_hash_algo->empty_tree);

Expand Down
Loading

0 comments on commit 72871b1

Please sign in to comment.