Skip to content

Commit

Permalink
builtin: add a repository parameter for builtin functions
Browse files Browse the repository at this point in the history
In order to reduce the usage of the global the_repository, add a
parameter to builtin functions that will get passed a repository
variable.

This commit uses UNUSED on most of the builtin functions, as subsequent
commits will modify the actual builtins to pass the repository parameter
down.

Signed-off-by: John Cai <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
john-cai authored and gitster committed Sep 13, 2024
1 parent 4590f2e commit 9b1cb50
Show file tree
Hide file tree
Showing 127 changed files with 703 additions and 296 deletions.
277 changes: 139 additions & 138 deletions builtin.h

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ int interactive_add(const char **argv, const char *prefix, int patch)
return ret;
}

static int edit_patch(int argc, const char **argv, const char *prefix)
static int edit_patch(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
char *file = git_pathdup("ADD_EDIT.patch");
struct child_process child = CHILD_PROCESS_INIT;
Expand Down Expand Up @@ -358,7 +361,10 @@ static int add_files(struct dir_struct *dir, int flags)
return exit_status;
}

int cmd_add(int argc, const char **argv, const char *prefix)
int cmd_add(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
int exit_status = 0;
struct pathspec pathspec;
Expand Down Expand Up @@ -387,7 +393,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (edit_interactive) {
if (pathspec_from_file)
die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--edit");
return(edit_patch(argc, argv, prefix));
return(edit_patch(argc, argv, prefix, the_repository));
}
argc--;
argv++;
Expand Down
5 changes: 4 additions & 1 deletion builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,10 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
return 0;
}

int cmd_am(int argc, const char **argv, const char *prefix)
int cmd_am(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
struct am_state state;
int binary = -1;
Expand Down
7 changes: 5 additions & 2 deletions builtin/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
#include "builtin.h"
#include "strvec.h"

int cmd_annotate(int argc, const char **argv, const char *prefix)
int cmd_annotate(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
struct strvec args = STRVEC_INIT;
int i;
Expand All @@ -18,5 +21,5 @@ int cmd_annotate(int argc, const char **argv, const char *prefix)
strvec_push(&args, argv[i]);
}

return cmd_blame(args.nr, args.v, prefix);
return cmd_blame(args.nr, args.v, prefix, the_repository);
}
5 changes: 4 additions & 1 deletion builtin/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ static const char * const apply_usage[] = {
NULL
};

int cmd_apply(int argc, const char **argv, const char *prefix)
int cmd_apply(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
int force_apply = 0;
int options = 0;
Expand Down
5 changes: 4 additions & 1 deletion builtin/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ static int run_remote_archiver(int argc, const char **argv,
PARSE_OPT_KEEP_UNKNOWN_OPT | \
PARSE_OPT_NO_INTERNAL_HELP )

int cmd_archive(int argc, const char **argv, const char *prefix)
int cmd_archive(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
const char *exec = "git-upload-archive";
char *output = NULL;
Expand Down
5 changes: 4 additions & 1 deletion builtin/bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,10 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
return res;
}

int cmd_bisect(int argc, const char **argv, const char *prefix)
int cmd_bisect(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
int res = 0;
parse_opt_subcommand_fn *fn = NULL;
Expand Down
5 changes: 4 additions & 1 deletion builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,10 @@ static void build_ignorelist(struct blame_scoreboard *sb,
}
}

int cmd_blame(int argc, const char **argv, const char *prefix)
int cmd_blame(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
struct rev_info revs;
char *path = NULL;
Expand Down
5 changes: 4 additions & 1 deletion builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,10 @@ static int edit_branch_description(const char *branch_name)
return 0;
}

int cmd_branch(int argc, const char **argv, const char *prefix)
int cmd_branch(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
/* possible actions */
int delete = 0, rename = 0, copy = 0, list = 0,
Expand Down
5 changes: 4 additions & 1 deletion builtin/bugreport.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ static void get_header(struct strbuf *buf, const char *title)
strbuf_addf(buf, "\n\n[%s]\n", title);
}

int cmd_bugreport(int argc, const char **argv, const char *prefix)
int cmd_bugreport(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
struct strbuf buffer = STRBUF_INIT;
struct strbuf report_path = STRBUF_INIT;
Expand Down
5 changes: 4 additions & 1 deletion builtin/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
return ret;
}

int cmd_bundle(int argc, const char **argv, const char *prefix)
int cmd_bundle(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *fn = NULL;
struct option options[] = {
Expand Down
7 changes: 5 additions & 2 deletions builtin/cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
const char *ls_args[3] = { NULL };
ls_args[0] = "ls-tree";
ls_args[1] = obj_name;
ret = cmd_ls_tree(2, ls_args, NULL);
ret = cmd_ls_tree(2, ls_args, NULL, the_repository);
goto cleanup;
}

Expand Down Expand Up @@ -923,7 +923,10 @@ static int batch_option_callback(const struct option *opt,
return 0;
}

int cmd_cat_file(int argc, const char **argv, const char *prefix)
int cmd_cat_file(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
int opt = 0;
int opt_cw = 0;
Expand Down
5 changes: 4 additions & 1 deletion builtin/check-attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ static NORETURN void error_with_usage(const char *msg)
usage_with_options(check_attr_usage, check_attr_options);
}

int cmd_check_attr(int argc, const char **argv, const char *prefix)
int cmd_check_attr(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
struct attr_check *check;
struct object_id initialized_oid;
Expand Down
5 changes: 4 additions & 1 deletion builtin/check-ignore.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix)
return num_ignored;
}

int cmd_check_ignore(int argc, const char **argv, const char *prefix)
int cmd_check_ignore(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
int num_ignored;
struct dir_struct dir = DIR_INIT;
Expand Down
5 changes: 4 additions & 1 deletion builtin/check-mailmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ static void check_mailmap(struct string_list *mailmap, const char *contact)
printf("<%.*s>\n", (int)maillen, mail);
}

int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
int cmd_check_mailmap(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
int i;
struct string_list mailmap = STRING_LIST_INIT_NODUP;
Expand Down
5 changes: 4 additions & 1 deletion builtin/check-ref-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ static int check_ref_format_branch(const char *arg)
return 0;
}

int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
int cmd_check_ref_format(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
int i;
int normalize = 0;
Expand Down
5 changes: 4 additions & 1 deletion builtin/checkout--worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ static const char * const checkout_worker_usage[] = {
NULL
};

int cmd_checkout__worker(int argc, const char **argv, const char *prefix)
int cmd_checkout__worker(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
struct checkout state = CHECKOUT_INIT;
struct option checkout_worker_options[] = {
Expand Down
5 changes: 4 additions & 1 deletion builtin/checkout-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ static int option_parse_stage(const struct option *opt,
return 0;
}

int cmd_checkout_index(int argc, const char **argv, const char *prefix)
int cmd_checkout_index(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
int i;
struct lock_file lock_file = LOCK_INIT;
Expand Down
15 changes: 12 additions & 3 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,10 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
return ret;
}

int cmd_checkout(int argc, const char **argv, const char *prefix)
int cmd_checkout(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
struct checkout_opts opts = CHECKOUT_OPTS_INIT;
struct option *options;
Expand Down Expand Up @@ -2000,7 +2003,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
checkout_usage);
}

int cmd_switch(int argc, const char **argv, const char *prefix)
int cmd_switch(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
struct checkout_opts opts = CHECKOUT_OPTS_INIT;
struct option *options = NULL;
Expand Down Expand Up @@ -2036,7 +2042,10 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
switch_branch_usage);
}

int cmd_restore(int argc, const char **argv, const char *prefix)
int cmd_restore(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
struct checkout_opts opts = CHECKOUT_OPTS_INIT;
struct option *options;
Expand Down
5 changes: 4 additions & 1 deletion builtin/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,10 @@ static void correct_untracked_entries(struct dir_struct *dir)
dir->nr = dst;
}

int cmd_clean(int argc, const char **argv, const char *prefix)
int cmd_clean(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
int i, res;
int dry_run = 0, remove_directories = 0, quiet = 0, ignored = 0;
Expand Down
5 changes: 4 additions & 1 deletion builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,10 @@ static int path_exists(const char *path)
return !stat(path, &sb);
}

int cmd_clone(int argc, const char **argv, const char *prefix)
int cmd_clone(int argc,
const char **argv,
const char *prefix,
struct repository *repository UNUSED)
{
int is_bundle = 0, is_local;
int reject_shallow = 0;
Expand Down
5 changes: 4 additions & 1 deletion builtin/column.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ static int column_config(const char *var, const char *value,
return git_column_config(var, value, cb, &colopts);
}

int cmd_column(int argc, const char **argv, const char *prefix)
int cmd_column(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
struct string_list list = STRING_LIST_INIT_DUP;
struct strbuf sb = STRBUF_INIT;
Expand Down
5 changes: 4 additions & 1 deletion builtin/commit-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ static int graph_write(int argc, const char **argv, const char *prefix)
return result;
}

int cmd_commit_graph(int argc, const char **argv, const char *prefix)
int cmd_commit_graph(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *fn = NULL;
struct option builtin_commit_graph_options[] = {
Expand Down
5 changes: 4 additions & 1 deletion builtin/commit-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ static int parse_file_arg_callback(const struct option *opt,
return 0;
}

int cmd_commit_tree(int argc, const char **argv, const char *prefix)
int cmd_commit_tree(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
static struct strbuf buffer = STRBUF_INIT;
struct commit_list *parents = NULL;
Expand Down
10 changes: 8 additions & 2 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,10 @@ static int git_status_config(const char *k, const char *v,
return git_diff_ui_config(k, v, ctx, NULL);
}

int cmd_status(int argc, const char **argv, const char *prefix)
int cmd_status(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
static int no_renames = -1;
static const char *rename_score_arg = (const char *)-1;
Expand Down Expand Up @@ -1641,7 +1644,10 @@ static int git_commit_config(const char *k, const char *v,
return git_status_config(k, v, ctx, s);
}

int cmd_commit(int argc, const char **argv, const char *prefix)
int cmd_commit(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
static struct wt_status s;
static struct option builtin_commit_options[] = {
Expand Down
5 changes: 4 additions & 1 deletion builtin/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,10 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
return ret;
}

int cmd_config(int argc, const char **argv, const char *prefix)
int cmd_config(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
parse_opt_subcommand_fn *subcommand = NULL;
struct option subcommand_opts[] = {
Expand Down
5 changes: 4 additions & 1 deletion builtin/count-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ static char const * const count_objects_usage[] = {
NULL
};

int cmd_count_objects(int argc, const char **argv, const char *prefix)
int cmd_count_objects(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
{
int human_readable = 0;
struct option opts[] = {
Expand Down
Loading

0 comments on commit 9b1cb50

Please sign in to comment.