diff --git a/attr.c b/attr.c index 4999b7e09da930..75369547b306d6 100644 --- a/attr.c +++ b/attr.c @@ -881,10 +881,11 @@ const char *git_attr_system_file(void) const char *git_attr_global_file(void) { - if (!git_attributes_file) - git_attributes_file = xdg_config_home("attributes"); + struct repo_config_values *cfg = repo_config_values(the_repository); + if (!cfg->attributes_file) + cfg->attributes_file = xdg_config_home("attributes"); - return git_attributes_file; + return cfg->attributes_file; } int git_attr_system_is_enabled(void) diff --git a/branch.h b/branch.h index ec2f35fda449aa..3dc6e2a0ffe635 100644 --- a/branch.h +++ b/branch.h @@ -15,8 +15,6 @@ enum branch_track { BRANCH_TRACK_SIMPLE, }; -extern enum branch_track git_branch_track; - /* Functions for acting on the information about branches. */ /** diff --git a/builtin/am.c b/builtin/am.c index e0c767e223dbce..990b6c54e70b30 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1216,7 +1216,7 @@ static int parse_mail(struct am_state *state, const char *mail) setup_mailinfo(the_repository, &mi); if (state->utf8) - mi.metainfo_charset = get_commit_output_encoding(); + mi.metainfo_charset = get_commit_output_encoding(the_repository); else mi.metainfo_charset = NULL; @@ -1355,7 +1355,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit) struct ident_split id; buffer = repo_logmsg_reencode(the_repository, commit, NULL, - get_commit_output_encoding()); + get_commit_output_encoding(the_repository)); ident_line = find_commit_header(buffer, "author", &ident_len); if (!ident_line) @@ -1699,7 +1699,7 @@ static void do_commit(const struct am_state *state) : state->author_date, IDENT_STRICT); - if (commit_tree_extended(state->msg, state->msg_len, &tree, parents, + if (commit_tree_extended(the_repository, state->msg, state->msg_len, &tree, parents, &commit, author, committer, state->sign_commit, NULL)) die(_("failed to write commit object")); diff --git a/builtin/backfill.c b/builtin/backfill.c index e80fc1b694df61..9b2ca57b6adec8 100644 --- a/builtin/backfill.c +++ b/builtin/backfill.c @@ -129,6 +129,7 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit N_("Restrict the missing objects to the current sparse-checkout")), OPT_END(), }; + struct repo_config_values *cfg = repo_config_values(the_repository); show_usage_with_options_if_asked(argc, argv, builtin_backfill_usage, options); @@ -139,7 +140,7 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit repo_config(repo, git_default_config, NULL); if (ctx.sparse < 0) - ctx.sparse = core_apply_sparse_checkout; + ctx.sparse = cfg->apply_sparse_checkout; result = do_backfill(&ctx); backfill_context_clear(&ctx); diff --git a/builtin/blame.c b/builtin/blame.c index eac2fe73201ca2..0ad9f2c9f7e398 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -202,7 +202,7 @@ static void get_commit_info(struct commit *commit, struct commit_info *ret) const char *subject, *encoding; const char *message; - encoding = get_log_output_encoding(); + encoding = get_log_output_encoding(the_repository); message = repo_logmsg_reencode(the_repository, commit, NULL, encoding); get_ac_line(message, "\nauthor ", &ret->author, &ret->author_mail, diff --git a/builtin/branch.c b/builtin/branch.c index c577b5d20f2969..a1a43380d0640b 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -724,6 +724,7 @@ int cmd_branch(int argc, static struct ref_sorting *sorting; struct string_list sorting_options = STRING_LIST_INIT_DUP; struct ref_format format = REF_FORMAT_INIT; + struct repo_config_values *cfg = repo_config_values(the_repository); int ret; struct option options[] = { @@ -795,7 +796,7 @@ int cmd_branch(int argc, if (!sorting_options.nr) string_list_append(&sorting_options, "refname"); - track = git_branch_track; + track = cfg->branch_track; head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD", 0, &head_oid, NULL); diff --git a/builtin/checkout.c b/builtin/checkout.c index f7b313816e7708..3b9e3e45f996de 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -689,7 +689,7 @@ static void describe_detached_head(const char *msg, struct commit *commit) struct strbuf sb = STRBUF_INIT; if (!repo_parse_commit(the_repository, commit)) - pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb); + pp_commit_easy(the_repository, CMIT_FMT_ONELINE, commit, &sb); if (print_sha1_ellipsis()) { fprintf(stderr, "%s %s... %s\n", msg, repo_find_unique_abbrev(the_repository, &commit->object.oid, DEFAULT_ABBREV), @@ -1077,7 +1077,7 @@ static void describe_one_orphan(struct strbuf *sb, struct commit *commit) strbuf_add_unique_abbrev(sb, &commit->object.oid, DEFAULT_ABBREV); strbuf_addch(sb, ' '); if (!repo_parse_commit(the_repository, commit)) - pp_commit_easy(CMIT_FMT_ONELINE, commit, sb); + pp_commit_easy(the_repository, CMIT_FMT_ONELINE, commit, sb); strbuf_addch(sb, '\n'); } @@ -1590,6 +1590,7 @@ static void die_if_switching_to_a_branch_in_use(struct checkout_opts *opts, static int checkout_branch(struct checkout_opts *opts, struct branch_info *new_branch_info) { + struct repo_config_values *cfg = repo_config_values(the_repository); int noop_switch = (!new_branch_info->name && !opts->new_branch && !opts->force_detach); @@ -1633,7 +1634,7 @@ static int checkout_branch(struct checkout_opts *opts, if (opts->track != BRANCH_TRACK_UNSPECIFIED) die(_("'%s' cannot be used with '%s'"), "--detach", "-t"); } else if (opts->track == BRANCH_TRACK_UNSPECIFIED) - opts->track = git_branch_track; + opts->track = cfg->branch_track; if (new_branch_info->name && !new_branch_info->commit) die(_("Cannot switch branch to a non-commit '%s'"), diff --git a/builtin/clone.c b/builtin/clone.c index b14a39a687c840..9d4dbd12abef7c 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -617,13 +617,15 @@ static int git_sparse_checkout_init(const char *repo) { struct child_process cmd = CHILD_PROCESS_INIT; int result = 0; + struct repo_config_values *cfg = repo_config_values(the_repository); + strvec_pushl(&cmd.args, "-C", repo, "sparse-checkout", "set", NULL); /* * We must apply the setting in the current process * for the later checkout to use the sparse-checkout file. */ - core_apply_sparse_checkout = 1; + cfg->apply_sparse_checkout = 1; cmd.git_cmd = 1; if (run_command(&cmd)) { diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index 30535db131eaa6..c489749588407c 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -144,7 +144,7 @@ int cmd_commit_tree(int argc, die_errno(_("git commit-tree: failed to read")); } - if (commit_tree(buffer.buf, buffer.len, &tree_oid, parents, &commit_oid, + if (commit_tree(the_repository, buffer.buf, buffer.len, &tree_oid, parents, &commit_oid, NULL, sign_commit)) { ret = 1; goto out; diff --git a/builtin/commit.c b/builtin/commit.c index 9e3a09d532bfce..caf5896d97e116 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -794,7 +794,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, c = lookup_commit_reference_by_name(squash_message); if (!c) die(_("could not lookup commit '%s'"), squash_message); - ctx.output_encoding = get_commit_output_encoding(); + ctx.output_encoding = get_commit_output_encoding(the_repository); repo_format_commit_message(the_repository, c, "squash! %s\n\n", &sb, &ctx); @@ -829,7 +829,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, commit = lookup_commit_reference_by_name(fixup_commit); if (!commit) die(_("could not lookup commit '%s'"), fixup_commit); - ctx.output_encoding = get_commit_output_encoding(); + ctx.output_encoding = get_commit_output_encoding(the_repository); fmt = xstrfmt("%s! %%s\n\n", fixup_prefix); repo_format_commit_message(the_repository, commit, fmt, &sb, &ctx); @@ -1235,7 +1235,7 @@ static const char *read_commit_message(const char *name) commit = lookup_commit_reference_by_name(name); if (!commit) die(_("could not lookup commit '%s'"), name); - out_enc = get_commit_output_encoding(); + out_enc = get_commit_output_encoding(the_repository); return repo_logmsg_reencode(the_repository, commit, NULL, out_enc); } @@ -1931,7 +1931,7 @@ int cmd_commit(int argc, append_merge_tag_headers(parents, &tail); } - if (commit_tree_extended(sb.buf, sb.len, &the_repository->index->cache_tree->oid, + if (commit_tree_extended(the_repository, sb.buf, sb.len, &the_repository->index->cache_tree->oid, parents, &oid, author_ident.buf, NULL, sign_commit, extra)) { rollback_index_files(); diff --git a/builtin/grep.c b/builtin/grep.c index 5b8b87b1ac4d7a..b6cecfd9b60f05 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -482,7 +482,7 @@ static int grep_submodule(struct grep_opt *opt, * "forget" the sparse-index feature switch. As a result, the index * of these submodules are expanded unexpectedly. * - * 2. "core_apply_sparse_checkout" + * 2. "config_values_private_.apply_sparse_checkout" * When running `grep` in the superproject, this setting is * populated using the superproject's configs. However, once * initialized, this config is globally accessible and is read by diff --git a/builtin/history.c b/builtin/history.c index 8dcb9a604665f8..3d83ac021b5493 100644 --- a/builtin/history.c +++ b/builtin/history.c @@ -136,7 +136,7 @@ static int commit_tree_with_edited_message(struct repository *repo, original_extra_headers = read_commit_extra_headers(original, exclude_gpgsig); - ret = commit_tree_extended(commit_message.buf, commit_message.len, &original_tree_oid, + ret = commit_tree_extended(repo, commit_message.buf, commit_message.len, &original_tree_oid, original->parents, &rewritten_commit_oid, original_author, NULL, NULL, original_extra_headers); if (ret < 0) diff --git a/builtin/log.c b/builtin/log.c index 8ab6d3a9439afd..8edb3c54e7089f 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -568,7 +568,7 @@ static void show_tagger(const char *buf, struct rev_info *rev) pp.fmt = rev->commit_format; pp.date_mode = rev->date_mode; - pp_user_info(&pp, "Tagger", &out, buf, get_log_output_encoding()); + pp_user_info(&pp, "Tagger", &out, buf, get_log_output_encoding(the_repository)); fprintf(rev->diffopt.file, "%s", out.buf); strbuf_release(&out); } @@ -2521,7 +2521,7 @@ static void print_commit(char sign, struct commit *commit, int verbose, repo_find_unique_abbrev(the_repository, &commit->object.oid, abbrev)); } else { struct strbuf buf = STRBUF_INIT; - pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf); + pp_commit_easy(the_repository, CMIT_FMT_ONELINE, commit, &buf); fprintf(file, "%c %s %s\n", sign, repo_find_unique_abbrev(the_repository, &commit->object.oid, abbrev), buf.buf); diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index 8de7ba7de1d6aa..4f17cf1598ca41 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -52,7 +52,7 @@ static int parse_opt_quoted_cr(const struct option *opt, const char *arg, int un int cmd_mailinfo(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { struct metainfo_charset meta_charset; struct mailinfo mi; @@ -83,7 +83,7 @@ int cmd_mailinfo(int argc, OPT_END() }; - setup_mailinfo(the_repository, &mi); + setup_mailinfo(repo, &mi); meta_charset.policy = CHARSET_DEFAULT; argc = parse_options(argc, argv, prefix, options, mailinfo_usage, 0); @@ -93,7 +93,7 @@ int cmd_mailinfo(int argc, switch (meta_charset.policy) { case CHARSET_DEFAULT: - mi.metainfo_charset = get_commit_output_encoding(); + mi.metainfo_charset = get_commit_output_encoding(repo); break; case CHARSET_NO_REENCODE: mi.metainfo_charset = NULL; diff --git a/builtin/merge.c b/builtin/merge.c index 4e456a381c192d..dff8185776b303 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -470,7 +470,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead strbuf_addch(&out, '\n'); strbuf_addf(&out, "commit %s\n", oid_to_hex(&commit->object.oid)); - pretty_print_commit(&ctx, commit, &out); + pretty_print_commit(the_repository, &ctx, commit, &out); } write_file_buf(git_path_squash_msg(the_repository), out.buf, out.len); strbuf_release(&out); @@ -1000,7 +1000,7 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads) pptr = commit_list_append(head, pptr); pptr = commit_list_append(remoteheads->item, pptr); prepare_to_commit(remoteheads); - if (commit_tree(merge_msg.buf, merge_msg.len, &result_tree, parents, + if (commit_tree(the_repository, merge_msg.buf, merge_msg.len, &result_tree, parents, &result_commit, NULL, sign_commit)) die(_("failed to write commit object")); finish(head, remoteheads, &result_commit, "In-index merge"); @@ -1027,7 +1027,7 @@ static int finish_automerge(struct commit *head, if (!head_subsumed || fast_forward == FF_NO) commit_list_insert(head, &parents); prepare_to_commit(remoteheads); - if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents, + if (commit_tree(the_repository, merge_msg.buf, merge_msg.len, result_tree, parents, &result_commit, NULL, sign_commit)) die(_("failed to write commit object")); strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy); diff --git a/builtin/mv.c b/builtin/mv.c index d43925097b420f..2215d34e31f29a 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -238,6 +238,7 @@ int cmd_mv(int argc, struct hashmap moved_dirs = HASHMAP_INIT(pathmap_cmp, NULL); struct strbuf pathbuf = STRBUF_INIT; int ret; + struct repo_config_values *cfg = repo_config_values(the_repository); repo_config(the_repository, git_default_config, NULL); @@ -572,7 +573,7 @@ int cmd_mv(int argc, rename_index_entry_at(the_repository->index, pos, dst); if (ignore_sparse && - core_apply_sparse_checkout && + cfg->apply_sparse_checkout && core_sparse_checkout_cone) { /* * NEEDSWORK: we are *not* paying attention to diff --git a/builtin/push.c b/builtin/push.c index 5b6cebbb856cfc..7100ffba5da17e 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -151,6 +151,7 @@ static NORETURN void die_push_simple(struct branch *branch, const char *advice_pushdefault_maybe = ""; const char *advice_automergesimple_maybe = ""; const char *short_upstream = branch->merge[0]->src; + struct repo_config_values *cfg = repo_config_values(the_repository); skip_prefix(short_upstream, "refs/heads/", &short_upstream); @@ -162,7 +163,7 @@ static NORETURN void die_push_simple(struct branch *branch, advice_pushdefault_maybe = _("\n" "To choose either option permanently, " "see push.default in 'git help config'.\n"); - if (git_branch_track != BRANCH_TRACK_SIMPLE) + if (cfg->branch_track != BRANCH_TRACK_SIMPLE) advice_automergesimple_maybe = _("\n" "To avoid automatically configuring " "an upstream branch when its name\n" diff --git a/builtin/rebase.c b/builtin/rebase.c index c487e1090779c2..7b9ab85cc059ca 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1647,7 +1647,7 @@ int cmd_rebase(int argc, options.upstream_arg = options.upstream_name; } else { if (!options.onto_name) { - if (commit_tree("", 0, the_hash_algo->empty_tree, NULL, + if (commit_tree(the_repository, "", 0, the_hash_algo->empty_tree, NULL, &squash_onto, NULL, NULL) < 0) die(_("Could not create new root commit")); options.squash_onto = &squash_onto; diff --git a/builtin/reset.c b/builtin/reset.c index c48d9845f8425e..733f3fa90513ac 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -141,7 +141,7 @@ static void print_new_head_line(struct commit *commit) printf(_("HEAD is now at %s"), repo_find_unique_abbrev(the_repository, &commit->object.oid, DEFAULT_ABBREV)); - pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf); + pp_commit_easy(the_repository, CMIT_FMT_ONELINE, commit, &buf); if (buf.len > 0) printf(" %s", buf.buf); putchar('\n'); diff --git a/builtin/rev-list.c b/builtin/rev-list.c index ddea8aa251a361..3732edae8be713 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -304,10 +304,10 @@ static void show_commit(struct commit *commit, void *data) ctx.date_mode = revs->date_mode; ctx.date_mode_explicit = revs->date_mode_explicit; ctx.fmt = revs->commit_format; - ctx.output_encoding = get_log_output_encoding(); + ctx.output_encoding = get_log_output_encoding(the_repository); ctx.color = revs->diffopt.use_color; ctx.rev = revs; - pretty_print_commit(&ctx, commit, &buf); + pretty_print_commit(the_repository, &ctx, commit, &buf); if (buf.len) { if (revs->commit_format != CMIT_FMT_ONELINE) graph_show_oneline(revs->graph); diff --git a/builtin/shortlog.c b/builtin/shortlog.c index d80bf1a7d055fc..79606e57be8ccf 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -248,11 +248,11 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) ctx.fmt = CMIT_FMT_USERFORMAT; ctx.abbrev = log->abbrev; ctx.date_mode = log->date_mode; - ctx.output_encoding = get_log_output_encoding(); + ctx.output_encoding = get_log_output_encoding(the_repository); if (!log->summary) { if (log->user_format) - pretty_print_commit(&ctx, commit, &oneline); + pretty_print_commit(the_repository, &ctx, commit, &oneline); else repo_format_commit_message(the_repository, commit, "%s", &oneline, &ctx); diff --git a/builtin/show-branch.c b/builtin/show-branch.c index f02831b08500c4..6bfe9e2e96d656 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -310,7 +310,7 @@ static void show_one_commit(struct commit *commit, int no_name) struct commit_name *name = commit_to_name(commit); if (commit->object.parsed) { - pp_commit_easy(CMIT_FMT_ONELINE, commit, &pretty); + pp_commit_easy(the_repository, CMIT_FMT_ONELINE, commit, &pretty); pretty_str = pretty.buf; } skip_prefix(pretty_str, "[PATCH] ", &pretty_str); diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index cccf63033190d2..ab25a916cd5dbd 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -61,9 +61,10 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix, struct pattern_list pl; char *sparse_filename; int res; + struct repo_config_values *cfg = repo_config_values(the_repository); setup_work_tree(); - if (!core_apply_sparse_checkout) + if (!cfg->apply_sparse_checkout) die(_("this worktree is not sparse")); argc = parse_options(argc, argv, prefix, @@ -398,12 +399,14 @@ static int set_config(struct repository *repo, } static enum sparse_checkout_mode update_cone_mode(int *cone_mode) { + struct repo_config_values *cfg = repo_config_values(the_repository); + /* If not specified, use previous definition of cone mode */ - if (*cone_mode == -1 && core_apply_sparse_checkout) + if (*cone_mode == -1 && cfg->apply_sparse_checkout) *cone_mode = core_sparse_checkout_cone; /* Set cone/non-cone mode appropriately */ - core_apply_sparse_checkout = 1; + cfg->apply_sparse_checkout = 1; if (*cone_mode == 1 || *cone_mode == -1) { core_sparse_checkout_cone = 1; return MODE_CONE_PATTERNS; @@ -415,9 +418,10 @@ static enum sparse_checkout_mode update_cone_mode(int *cone_mode) { static int update_modes(struct repository *repo, int *cone_mode, int *sparse_index) { int mode, record_mode; + struct repo_config_values *cfg = repo_config_values(the_repository); /* Determine if we need to record the mode; ensure sparse checkout on */ - record_mode = (*cone_mode != -1) || !core_apply_sparse_checkout; + record_mode = (*cone_mode != -1) || !cfg->apply_sparse_checkout; mode = update_cone_mode(cone_mode); if (record_mode && set_config(repo, mode)) @@ -683,6 +687,7 @@ static int modify_pattern_list(struct repository *repo, int result; int changed_config = 0; struct pattern_list *pl = xcalloc(1, sizeof(*pl)); + struct repo_config_values *cfg = repo_config_values(the_repository); switch (m) { case ADD: @@ -698,9 +703,9 @@ static int modify_pattern_list(struct repository *repo, break; } - if (!core_apply_sparse_checkout) { + if (!cfg->apply_sparse_checkout) { set_config(repo, MODE_ALL_PATTERNS); - core_apply_sparse_checkout = 1; + cfg->apply_sparse_checkout = 1; changed_config = 1; } @@ -795,9 +800,10 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix, }; struct strvec patterns = STRVEC_INIT; int ret; + struct repo_config_values *cfg = repo_config_values(the_repository); setup_work_tree(); - if (!core_apply_sparse_checkout) + if (!cfg->apply_sparse_checkout) die(_("no sparse-checkout to add to")); repo_read_index(repo); @@ -904,9 +910,10 @@ static int sparse_checkout_reapply(int argc, const char **argv, N_("toggle the use of a sparse index")), OPT_END(), }; + struct repo_config_values *cfg = repo_config_values(the_repository); setup_work_tree(); - if (!core_apply_sparse_checkout) + if (!cfg->apply_sparse_checkout) die(_("must be in a sparse-checkout to reapply sparsity patterns")); reapply_opts.cone_mode = -1; @@ -959,6 +966,7 @@ static int sparse_checkout_clean(int argc, const char **argv, size_t worktree_len; int force = 0, dry_run = 0, verbose = 0; int require_force = 1; + struct repo_config_values *cfg = repo_config_values(the_repository); struct option builtin_sparse_checkout_clean_options[] = { OPT__DRY_RUN(&dry_run, N_("dry run")), @@ -968,7 +976,7 @@ static int sparse_checkout_clean(int argc, const char **argv, }; setup_work_tree(); - if (!core_apply_sparse_checkout) + if (!cfg->apply_sparse_checkout) die(_("must be in a sparse-checkout to clean directories")); if (!core_sparse_checkout_cone) die(_("must be in a cone-mode sparse-checkout to clean directories")); @@ -1032,9 +1040,10 @@ static int sparse_checkout_disable(int argc, const char **argv, OPT_END(), }; struct pattern_list pl; + struct repo_config_values *cfg = repo_config_values(the_repository); /* - * We do not exit early if !core_apply_sparse_checkout; due to the + * We do not exit early if !repo->config_values.apply_sparse_checkout; due to the * ability for users to manually muck things up between * direct editing of .git/info/sparse-checkout * running read-tree -m u HEAD or update-index --skip-worktree @@ -1060,7 +1069,7 @@ static int sparse_checkout_disable(int argc, const char **argv, hashmap_init(&pl.recursive_hashmap, pl_hashmap_cmp, NULL, 0); hashmap_init(&pl.parent_hashmap, pl_hashmap_cmp, NULL, 0); pl.use_cone_patterns = 0; - core_apply_sparse_checkout = 1; + cfg->apply_sparse_checkout = 1; add_pattern("/*", empty_base, 0, &pl, 0); diff --git a/builtin/stash.c b/builtin/stash.c index f06cfa79894cae..a522bb6de56732 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1258,7 +1258,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg, goto done; } - if (commit_tree(untracked_msg.buf, untracked_msg.len, + if (commit_tree(the_repository, untracked_msg.buf, untracked_msg.len, &info->u_tree, NULL, &info->u_commit, NULL, NULL)) { ret = -1; goto done; @@ -1480,13 +1480,13 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b &head_commit->object.oid, DEFAULT_ABBREV); strbuf_addf(&msg, "%s: %s ", branch_name, head_short_sha1); - pp_commit_easy(CMIT_FMT_ONELINE, head_commit, &msg); + pp_commit_easy(the_repository, CMIT_FMT_ONELINE, head_commit, &msg); strbuf_addf(&commit_tree_label, "index on %s\n", msg.buf); commit_list_insert(head_commit, &parents); if (write_index_as_tree(&info->i_tree, the_repository->index, repo_get_index_file(the_repository), 0, NULL) || - commit_tree(commit_tree_label.buf, commit_tree_label.len, + commit_tree(the_repository, commit_tree_label.buf, commit_tree_label.len, &info->i_tree, parents, &info->i_commit, NULL, NULL)) { if (!quiet) fprintf_ln(stderr, _("Cannot save the current " @@ -1551,7 +1551,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b &parents); commit_list_insert(head_commit, &parents); - if (commit_tree(stash_msg_buf->buf, stash_msg_buf->len, &info->w_tree, + if (commit_tree(the_repository, stash_msg_buf->buf, stash_msg_buf->len, &info->w_tree, parents, &info->w_commit, NULL, NULL)) { if (!quiet) fprintf_ln(stderr, _("Cannot record " @@ -2035,7 +2035,7 @@ static int write_commit_with_parents(struct repository *r, author = xmemdupz(orig_author, author_len); committer = xmemdupz(orig_committer, committer_len); - if (commit_tree_extended(msg.buf, msg.len, + if (commit_tree_extended(r, msg.buf, msg.len, r->hash_algo->empty_tree, parents, out, author, committer, NULL, NULL)) { @@ -2258,7 +2258,7 @@ static int do_export_stash(struct repository *r, "2001-09-17T00:00:00Z", 0); /* First, we create a single empty commit. */ - if (commit_tree_extended("", 0, r->hash_algo->empty_tree, NULL, + if (commit_tree_extended(the_repository, "", 0, r->hash_algo->empty_tree, NULL, &base, author, committer, NULL, NULL)) return error(_("unable to write base commit")); diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b621d14275c34d..143f7cb3cca7d0 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3300,9 +3300,10 @@ static int module_create_branch(int argc, const char **argv, const char *prefix, N_("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] "), NULL }; + struct repo_config_values *cfg = repo_config_values(the_repository); repo_config(the_repository, git_default_config, NULL); - track = git_branch_track; + track = cfg->branch_track; argc = parse_options(argc, argv, prefix, options, usage, 0); if (argc != 3) diff --git a/builtin/worktree.c b/builtin/worktree.c index 3d6547c23b434f..ea16994c0c3d0b 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -440,6 +440,7 @@ static int add_worktree(const char *path, const char *refname, struct strbuf sb_name = STRBUF_INIT; struct worktree **worktrees, *wt = NULL; struct ref_store *wt_refs; + struct repo_config_values *cfg = repo_config_values(the_repository); worktrees = get_worktrees(); check_candidate_path(path, opts->force, worktrees, "add"); @@ -536,7 +537,7 @@ static int add_worktree(const char *path, const char *refname, * If the current worktree has sparse-checkout enabled, then copy * the sparse-checkout patterns from the current worktree. */ - if (core_apply_sparse_checkout) + if (cfg->apply_sparse_checkout) copy_sparse_checkout(sb_repo.buf); /* diff --git a/bundle.c b/bundle.c index 42327f9739cc54..3b98cdd6fd4dda 100644 --- a/bundle.c +++ b/bundle.c @@ -461,9 +461,9 @@ static void write_bundle_prerequisites(struct commit *commit, void *data) write_or_die(bpi->fd, buf.buf, buf.len); ctx.fmt = CMIT_FMT_ONELINE; - ctx.output_encoding = get_log_output_encoding(); + ctx.output_encoding = get_log_output_encoding(the_repository); strbuf_reset(&buf); - pretty_print_commit(&ctx, commit, &buf); + pretty_print_commit(the_repository, &ctx, commit, &buf); strbuf_trim(&buf); object = (struct object *)commit; diff --git a/commit.c b/commit.c index d16ae7334510e0..cb8ec675d1fe85 100644 --- a/commit.c +++ b/commit.c @@ -1534,7 +1534,7 @@ void free_commit_extra_headers(struct commit_extra_header *extra) } } -int commit_tree(const char *msg, size_t msg_len, const struct object_id *tree, +int commit_tree(struct repository *r, const char *msg, size_t msg_len, const struct object_id *tree, const struct commit_list *parents, struct object_id *ret, const char *author, const char *sign_commit) { @@ -1542,7 +1542,7 @@ int commit_tree(const char *msg, size_t msg_len, const struct object_id *tree, int result; append_merge_tag_headers(parents, &tail); - result = commit_tree_extended(msg, msg_len, tree, parents, ret, author, + result = commit_tree_extended(r, msg, msg_len, tree, parents, ret, author, NULL, sign_commit, extra); free_commit_extra_headers(extra); return result; @@ -1663,7 +1663,8 @@ N_("Warning: commit message did not conform to UTF-8.\n" "You may want to amend it after fixing the message, or set the config\n" "variable i18n.commitEncoding to the encoding your project uses.\n"); -static void write_commit_tree(struct strbuf *buffer, const char *msg, size_t msg_len, +static void write_commit_tree(struct repository *r, struct strbuf *buffer, + const char *msg, size_t msg_len, const struct object_id *tree, const struct object_id *parents, size_t parents_len, const char *author, const char *committer, @@ -1673,7 +1674,7 @@ static void write_commit_tree(struct strbuf *buffer, const char *msg, size_t msg size_t i; /* Not having i18n.commitencoding is the same as having utf-8 */ - encoding_is_utf8 = is_encoding_utf8(git_commit_encoding); + encoding_is_utf8 = is_encoding_utf8(get_commit_output_encoding(r)); strbuf_grow(buffer, 8192); /* should avoid reallocs for the headers */ strbuf_addf(buffer, "tree %s\n", oid_to_hex(tree)); @@ -1694,7 +1695,7 @@ static void write_commit_tree(struct strbuf *buffer, const char *msg, size_t msg committer = git_committer_info(IDENT_STRICT); strbuf_addf(buffer, "committer %s\n", committer); if (!encoding_is_utf8) - strbuf_addf(buffer, "encoding %s\n", git_commit_encoding); + strbuf_addf(buffer, "encoding %s\n", get_commit_output_encoding(r)); while (extra) { add_extra_header(buffer, extra); @@ -1706,14 +1707,13 @@ static void write_commit_tree(struct strbuf *buffer, const char *msg, size_t msg strbuf_add(buffer, msg, msg_len); } -int commit_tree_extended(const char *msg, size_t msg_len, +int commit_tree_extended(struct repository *r, const char *msg, size_t msg_len, const struct object_id *tree, const struct commit_list *parents, struct object_id *ret, const char *author, const char *committer, const char *sign_commit, const struct commit_extra_header *extra) { - struct repository *r = the_repository; int result = 0; int encoding_is_utf8; struct strbuf buffer = STRBUF_INIT, compat_buffer = STRBUF_INIT; @@ -1723,7 +1723,7 @@ int commit_tree_extended(const char *msg, size_t msg_len, size_t i, nparents; /* Not having i18n.commitencoding is the same as having utf-8 */ - encoding_is_utf8 = is_encoding_utf8(git_commit_encoding); + encoding_is_utf8 = is_encoding_utf8(get_commit_output_encoding(r)); odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE); @@ -1736,7 +1736,7 @@ int commit_tree_extended(const char *msg, size_t msg_len, for (const struct commit_list *p = parents; p; p = p->next) oidcpy(&parent_buf[i++], &p->item->object.oid); - write_commit_tree(&buffer, msg, msg_len, tree, parent_buf, nparents, author, committer, extra); + write_commit_tree(r, &buffer, msg, msg_len, tree, parent_buf, nparents, author, committer, extra); if (sign_commit && sign_commit_to_strbuf(&sig, &buffer, sign_commit)) { result = -1; goto out; @@ -1764,7 +1764,7 @@ int commit_tree_extended(const char *msg, size_t msg_len, free(mapped_parents); goto out; } - write_commit_tree(&compat_buffer, msg, msg_len, &mapped_tree, + write_commit_tree(r, &compat_buffer, msg, msg_len, &mapped_tree, mapped_parents, nparents, author, committer, compat_extra); free_commit_extra_headers(compat_extra); free(mapped_parents); diff --git a/commit.h b/commit.h index 1635de418b59e0..d3d664d0ffdc14 100644 --- a/commit.h +++ b/commit.h @@ -289,12 +289,12 @@ struct commit_extra_header { void append_merge_tag_headers(const struct commit_list *parents, struct commit_extra_header ***tail); -int commit_tree(const char *msg, size_t msg_len, +int commit_tree(struct repository *r, const char *msg, size_t msg_len, const struct object_id *tree, const struct commit_list *parents, struct object_id *ret, const char *author, const char *sign_commit); -int commit_tree_extended(const char *msg, size_t msg_len, +int commit_tree_extended(struct repository *r, const char *msg, size_t msg_len, const struct object_id *tree, const struct commit_list *parents, struct object_id *ret, const char *author, const char *committer, diff --git a/dir.c b/dir.c index b00821f294fea2..026d8516a912af 100644 --- a/dir.c +++ b/dir.c @@ -1551,7 +1551,9 @@ enum pattern_match_result path_matches_pattern_list( int init_sparse_checkout_patterns(struct index_state *istate) { - if (!core_apply_sparse_checkout) + struct repo_config_values *cfg = repo_config_values(the_repository); + + if (!cfg->apply_sparse_checkout) return 1; if (istate->sparse_checkout_patterns) return 0; diff --git a/environment.c b/environment.c index 0026eb227487dd..948e22ec26b75e 100644 --- a/environment.c +++ b/environment.c @@ -50,11 +50,8 @@ int ignore_case; int assume_unchanged; int is_bare_repository_cfg = -1; /* unspecified */ int warn_on_object_refname_ambiguity = 1; -char *git_commit_encoding; -char *git_log_output_encoding; char *apply_default_whitespace; char *apply_default_ignorewhitespace; -char *git_attributes_file; int zlib_compression_level = Z_BEST_SPEED; int pack_compression_level = Z_DEFAULT_COMPRESSION; int fsync_object_files = -1; @@ -68,7 +65,6 @@ enum auto_crlf auto_crlf = AUTO_CRLF_FALSE; enum eol core_eol = EOL_UNSET; int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; char *check_roundtrip_encoding; -enum branch_track git_branch_track = BRANCH_TRACK_REMOTE; enum rebase_setup_type autorebase = AUTOREBASE_NEVER; enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; #ifndef OBJECT_CREATION_MODE @@ -76,7 +72,6 @@ enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; #endif enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; int grafts_keep_true_parents; -int core_apply_sparse_checkout; int core_sparse_checkout_cone; int sparse_expect_files_outside_of_patterns; int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ @@ -197,15 +192,22 @@ const char *strip_namespace(const char *namespaced_ref) return NULL; } -const char *get_log_output_encoding(void) +const char *get_log_output_encoding(struct repository *r) { - return git_log_output_encoding ? git_log_output_encoding - : get_commit_output_encoding(); + struct repo_config_values *cfg; + if (r != the_repository) + return get_commit_output_encoding(r); + cfg = repo_config_values(r); + return cfg->log_output_encoding ? cfg->log_output_encoding : get_commit_output_encoding(r); } -const char *get_commit_output_encoding(void) +const char *get_commit_output_encoding(struct repository *r) { - return git_commit_encoding ? git_commit_encoding : "UTF-8"; + struct repo_config_values *cfg; + if (r != the_repository) + return "UTF-8"; + cfg= repo_config_values(r); + return cfg->commit_encoding ? cfg->commit_encoding : "UTF-8"; } int use_optional_locks(void) @@ -304,6 +306,8 @@ static enum fsync_component parse_fsync_components(const char *var, const char * int git_default_core_config(const char *var, const char *value, const struct config_context *ctx, void *cb) { + struct repo_config_values *cfg = repo_config_values(the_repository); + /* This needs a better name */ if (!strcmp(var, "core.filemode")) { trust_executable_bit = git_config_bool(var, value); @@ -341,8 +345,8 @@ int git_default_core_config(const char *var, const char *value, } if (!strcmp(var, "core.attributesfile")) { - FREE_AND_NULL(git_attributes_file); - return git_config_pathname(&git_attributes_file, var, value); + FREE_AND_NULL(cfg->attributes_file); + return git_config_pathname(&cfg->attributes_file, var, value); } if (!strcmp(var, "core.bare")) { @@ -527,7 +531,7 @@ int git_default_core_config(const char *var, const char *value, } if (!strcmp(var, "core.sparsecheckout")) { - core_apply_sparse_checkout = git_config_bool(var, value); + cfg->apply_sparse_checkout = git_config_bool(var, value); return 0; } @@ -568,34 +572,36 @@ static int git_default_sparse_config(const char *var, const char *value) static int git_default_i18n_config(const char *var, const char *value) { + struct repo_config_values *cfg = repo_config_values(the_repository); + if (!strcmp(var, "i18n.commitencoding")) { - FREE_AND_NULL(git_commit_encoding); - return git_config_string(&git_commit_encoding, var, value); + FREE_AND_NULL(cfg->commit_encoding); + return git_config_string(&cfg->commit_encoding, var, value); } - if (!strcmp(var, "i18n.logoutputencoding")) { - FREE_AND_NULL(git_log_output_encoding); - return git_config_string(&git_log_output_encoding, var, value); + FREE_AND_NULL(cfg->log_output_encoding); + return git_config_string(&cfg->log_output_encoding, var, value); } - /* Add other config variables here and to Documentation/config.adoc. */ return 0; } static int git_default_branch_config(const char *var, const char *value) { + struct repo_config_values *cfg = repo_config_values(the_repository); + if (!strcmp(var, "branch.autosetupmerge")) { if (value && !strcmp(value, "always")) { - git_branch_track = BRANCH_TRACK_ALWAYS; + cfg->branch_track = BRANCH_TRACK_ALWAYS; return 0; } else if (value && !strcmp(value, "inherit")) { - git_branch_track = BRANCH_TRACK_INHERIT; + cfg->branch_track = BRANCH_TRACK_INHERIT; return 0; } else if (value && !strcmp(value, "simple")) { - git_branch_track = BRANCH_TRACK_SIMPLE; + cfg->branch_track = BRANCH_TRACK_SIMPLE; return 0; } - git_branch_track = git_config_bool(var, value); + cfg->branch_track = git_config_bool(var, value); return 0; } if (!strcmp(var, "branch.autosetuprebase")) { @@ -733,3 +739,12 @@ int git_default_config(const char *var, const char *value, /* Add other config variables here and to Documentation/config.adoc. */ return 0; } + +void repo_config_values_init(struct repo_config_values *cfg) +{ + cfg->attributes_file = NULL; + cfg->commit_encoding = NULL; + cfg->log_output_encoding = NULL; + cfg->apply_sparse_checkout = 0; + cfg->branch_track = BRANCH_TRACK_REMOTE; +} diff --git a/environment.h b/environment.h index 27f657af046a51..358c7d05e03803 100644 --- a/environment.h +++ b/environment.h @@ -2,6 +2,7 @@ #define ENVIRONMENT_H #include "repo-settings.h" +#include "branch.h" /* Double-check local_repo_env below if you add to this list. */ #define GIT_DIR_ENVIRONMENT "GIT_DIR" @@ -84,6 +85,21 @@ extern const char * const local_repo_env[]; struct strvec; +struct repository; +struct repo_config_values { + /* section "core" config values */ + char *attributes_file; + int apply_sparse_checkout; + + /* section "branch" config values */ + enum branch_track branch_track; + + char *commit_encoding; + char *log_output_encoding; +}; + +struct repo_config_values *repo_config_values(struct repository *repo); + /* * Wrapper of getenv() that returns a strdup value. This value is kept * in argv to be freed later. @@ -109,6 +125,8 @@ int git_default_config(const char *, const char *, int git_default_core_config(const char *var, const char *value, const struct config_context *ctx, void *cb); +void repo_config_values_init(struct repo_config_values *cfg); + /* * TODO: All the below state either explicitly or implicitly relies on * `the_repository`. We should eventually get rid of these and make the @@ -154,7 +172,6 @@ extern int assume_unchanged; extern int warn_on_object_refname_ambiguity; extern char *apply_default_whitespace; extern char *apply_default_ignorewhitespace; -extern char *git_attributes_file; extern int zlib_compression_level; extern int pack_compression_level; extern unsigned long pack_size_limit_cfg; @@ -163,7 +180,6 @@ extern int precomposed_unicode; extern int protect_hfs; extern int protect_ntfs; -extern int core_apply_sparse_checkout; extern int core_sparse_checkout_cone; extern int sparse_expect_files_outside_of_patterns; @@ -193,11 +209,8 @@ extern enum object_creation_mode object_creation_mode; extern int grafts_keep_true_parents; -const char *get_log_output_encoding(void); -const char *get_commit_output_encoding(void); - -extern char *git_commit_encoding; -extern char *git_log_output_encoding; +const char *get_log_output_encoding(struct repository *r); +const char *get_commit_output_encoding(struct repository *r); extern char *editor_program; extern char *askpass_program; diff --git a/log-tree.c b/log-tree.c index 7e048701d0c5b4..364fd015f50705 100644 --- a/log-tree.c +++ b/log-tree.c @@ -859,7 +859,7 @@ void show_log(struct rev_info *opt) raw = (opt->commit_format == CMIT_FMT_USERFORMAT); format_display_notes(&commit->object.oid, ¬ebuf, - get_log_output_encoding(), raw); + get_log_output_encoding(opt->repo), raw); ctx.notes_message = strbuf_detach(¬ebuf, NULL); } @@ -879,13 +879,13 @@ void show_log(struct rev_info *opt) ctx.mailmap = opt->mailmap; ctx.color = opt->diffopt.use_color; ctx.expand_tabs_in_log = opt->expand_tabs_in_log; - ctx.output_encoding = get_log_output_encoding(); + ctx.output_encoding = get_log_output_encoding(opt->repo); ctx.rev = opt; if (opt->from_ident.mail_begin && opt->from_ident.name_begin) ctx.from_ident = &opt->from_ident; if (opt->graph) ctx.graph_width = graph_width(opt->graph); - pretty_print_commit(&ctx, commit, &msgbuf); + pretty_print_commit(opt->repo, &ctx, commit, &msgbuf); if (opt->add_signoff) append_signoff(&msgbuf, 0, APPEND_SIGNOFF_DEDUP); diff --git a/notes-cache.c b/notes-cache.c index bf5bb1f6c13a13..5dbbd94ea31223 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -66,7 +66,7 @@ int notes_cache_write(struct notes_cache *c) if (write_notes_tree(&c->tree, &tree_oid)) return -1; - if (commit_tree(c->validity, strlen(c->validity), &tree_oid, NULL, + if (commit_tree(the_repository, c->validity, strlen(c->validity), &tree_oid, NULL, &commit_oid, NULL, NULL) < 0) return -1; if (refs_update_ref(get_main_ref_store(the_repository), "update notes cache", c->tree.update_ref, &commit_oid, diff --git a/notes-utils.c b/notes-utils.c index 5c1c75d5b8099a..4671a119939eb3 100644 --- a/notes-utils.c +++ b/notes-utils.c @@ -36,7 +36,7 @@ void create_notes_commit(struct repository *r, /* else: t->ref points to nothing, assume root/orphan commit */ } - if (commit_tree(msg, msg_len, &tree_oid, parents, result_oid, NULL, + if (commit_tree(r, msg, msg_len, &tree_oid, parents, result_oid, NULL, NULL)) die("Failed to commit notes tree to database"); diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c index fb8b8787a460f1..59bbb849d1e1c4 100644 --- a/oss-fuzz/fuzz-commit-graph.c +++ b/oss-fuzz/fuzz-commit-graph.c @@ -10,6 +10,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { struct commit_graph *g; + memset(the_repository, 0, sizeof(*the_repository)); initialize_repository(the_repository); /* diff --git a/pretty.c b/pretty.c index e0646bbc5d49cc..6b585e27638ad7 100644 --- a/pretty.c +++ b/pretty.c @@ -2281,7 +2281,7 @@ void pp_remainder(struct pretty_print_context *pp, } } -void pretty_print_commit(struct pretty_print_context *pp, +void pretty_print_commit(struct repository *r, struct pretty_print_context *pp, const struct commit *commit, struct strbuf *sb) { @@ -2298,7 +2298,7 @@ void pretty_print_commit(struct pretty_print_context *pp, return; } - encoding = get_log_output_encoding(); + encoding = get_log_output_encoding(r); msg = reencoded = repo_logmsg_reencode(the_repository, commit, NULL, encoding); @@ -2363,10 +2363,10 @@ void pretty_print_commit(struct pretty_print_context *pp, repo_unuse_commit_buffer(the_repository, commit, reencoded); } -void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit, +void pp_commit_easy(struct repository *r, enum cmit_fmt fmt, const struct commit *commit, struct strbuf *sb) { struct pretty_print_context pp = {0}; pp.fmt = fmt; - pretty_print_commit(&pp, commit, sb); + pretty_print_commit(r, &pp, commit, sb); } diff --git a/pretty.h b/pretty.h index fac699033e943c..13eb0189bdce43 100644 --- a/pretty.h +++ b/pretty.h @@ -82,7 +82,7 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w); * Shortcut for invoking pretty_print_commit if we do not have any context. * Context would be set empty except "fmt". */ -void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit, +void pp_commit_easy(struct repository *r, enum cmit_fmt fmt, const struct commit *commit, struct strbuf *sb); /* @@ -132,7 +132,7 @@ void get_commit_format(const char *arg, struct rev_info *); * and put it into "sb". * Please use this function if you have a context (candidate for "pp"). */ -void pretty_print_commit(struct pretty_print_context *pp, +void pretty_print_commit(struct repository *r, struct pretty_print_context *pp, const struct commit *commit, struct strbuf *sb); diff --git a/range-diff.c b/range-diff.c index 57edff40a85f24..31d38c2318c876 100644 --- a/range-diff.c +++ b/range-diff.c @@ -460,7 +460,7 @@ static void output_pair_header(struct diff_options *diffopt, strbuf_addf(buf, "%s%s", color_reset, color); strbuf_addch(buf, ' '); - pp_commit_easy(CMIT_FMT_ONELINE, commit, buf); + pp_commit_easy(diffopt->repo, CMIT_FMT_ONELINE, commit, buf); } strbuf_addf(buf, "%s\n", color_reset); diff --git a/remote-curl.c b/remote-curl.c index 92e40bb682d34d..146cb8930df7c9 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -379,7 +379,7 @@ static int show_http_message(struct strbuf *type, struct strbuf *charset, if (strcmp(type->buf, "text/plain")) return -1; if (charset->len) - strbuf_reencode(msg, charset->buf, get_log_output_encoding()); + strbuf_reencode(msg, charset->buf, get_log_output_encoding(the_repository)); strbuf_trim(msg); if (!msg->len) diff --git a/replay.c b/replay.c index f97d652f338f1d..0012d3aa1818f3 100644 --- a/replay.c +++ b/replay.c @@ -56,7 +56,7 @@ static struct commit *create_commit(struct repository *repo, char *sign_commit = NULL; /* FIXME: cli users might want to sign again */ struct commit_extra_header *extra = NULL; struct strbuf msg = STRBUF_INIT; - const char *out_enc = get_commit_output_encoding(); + const char *out_enc = get_commit_output_encoding(repo); const char *message = repo_logmsg_reencode(repo, based_on, NULL, out_enc); const char *orig_message = NULL; @@ -68,7 +68,7 @@ static struct commit *create_commit(struct repository *repo, strbuf_addstr(&msg, orig_message); author = get_author(message); reset_ident_date(); - if (commit_tree_extended(msg.buf, msg.len, &tree->object.oid, parents, + if (commit_tree_extended(repo, msg.buf, msg.len, &tree->object.oid, parents, &ret, author, NULL, sign_commit, extra)) { error(_("failed to write commit object")); goto out; diff --git a/repository.c b/repository.c index 46a7c999302a4c..3202d67bf0f98c 100644 --- a/repository.c +++ b/repository.c @@ -50,13 +50,27 @@ static void set_default_hash_algo(struct repository *repo) repo_set_hash_algo(repo, algo); } +struct repo_config_values *repo_config_values(struct repository *repo) +{ + if (repo != the_repository) + BUG("trying to read config from wrong repository instance"); + if(!repo->initialized) + BUG("config values from uninitialized repository"); + return &repo->config_values_private_; +} + void initialize_repository(struct repository *repo) { + if (repo->initialized) + BUG("repository initialized already"); + repo->initialized = true; + repo->remote_state = remote_state_new(); repo->parsed_objects = parsed_object_pool_new(repo); ALLOC_ARRAY(repo->index, 1); index_state_init(repo->index, repo); repo->check_deprecated_config = true; + repo_config_values_init(&repo->config_values_private_); /* * When a command runs inside a repository, it learns what @@ -370,6 +384,8 @@ void repo_clear(struct repository *repo) FREE_AND_NULL(repo->index_file); FREE_AND_NULL(repo->worktree); FREE_AND_NULL(repo->submodule_prefix); + FREE_AND_NULL(repo->config_values_private_.commit_encoding); + FREE_AND_NULL(repo->config_values_private_.log_output_encoding); odb_free(repo->objects); repo->objects = NULL; diff --git a/repository.h b/repository.h index 7141237f97d87d..b1c69acc570429 100644 --- a/repository.h +++ b/repository.h @@ -3,6 +3,7 @@ #include "strmap.h" #include "repo-settings.h" +#include "environment.h" struct config_set; struct git_hash_algo; @@ -148,6 +149,9 @@ struct repository { /* Repository's compatibility hash algorithm. */ const struct git_hash_algo *compat_hash_algo; + /* Repository's config values parsed by git_default_config() */ + struct repo_config_values config_values_private_; + /* Repository's reference storage format, as serialized on disk. */ enum ref_storage_format ref_storage_format; @@ -172,6 +176,9 @@ struct repository { /* Should repo_config() check for deprecated settings */ bool check_deprecated_config; + + /* Has this repository instance been initialized? */ + bool initialized; }; #ifdef USE_THE_REPOSITORY_VARIABLE diff --git a/revision.c b/revision.c index 29972c3a19887a..5fb85c0f1377da 100644 --- a/revision.c +++ b/revision.c @@ -2675,11 +2675,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--invert-grep")) { revs->grep_filter.no_body_match = 1; } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) { - free(git_log_output_encoding); + struct repo_config_values *cfg = repo_config_values(revs->repo); + + free(cfg->log_output_encoding); if (strcmp(optarg, "none")) - git_log_output_encoding = xstrdup(optarg); + cfg->log_output_encoding = xstrdup(optarg); else - git_log_output_encoding = xstrdup(""); + cfg->log_output_encoding = xstrdup(""); return argcount; } else if (!strcmp(arg, "--reverse")) { revs->reverse ^= 1; @@ -3129,7 +3131,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s diff_setup_done(&revs->diffopt); - if (!is_encoding_utf8(get_log_output_encoding())) + if (!is_encoding_utf8(get_log_output_encoding(revs->repo))) revs->grep_filter.ignore_locale = 1; compile_grep_patterns(&revs->grep_filter); @@ -4063,7 +4065,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt) * so we will not end up with a buffer that has two different encodings * in it. */ - encoding = get_log_output_encoding(); + encoding = get_log_output_encoding(opt->repo); message = repo_logmsg_reencode(the_repository, commit, NULL, encoding); /* Copy the commit to temporary if we are using "fake" headers */ diff --git a/sequencer.c b/sequencer.c index a3eb39bb25248a..62717910d25ba2 100644 --- a/sequencer.c +++ b/sequencer.c @@ -480,13 +480,13 @@ static const char *short_commit_name(struct repository *r, struct commit *commit return repo_find_unique_abbrev(r, &commit->object.oid, DEFAULT_ABBREV); } -static int get_message(struct commit *commit, struct commit_message *out) +static int get_message(struct repository *r, struct commit *commit, struct commit_message *out) { const char *abbrev, *subject; int subject_len; out->message = repo_logmsg_reencode(the_repository, commit, NULL, - get_commit_output_encoding()); + get_commit_output_encoding(r)); abbrev = short_commit_name(the_repository, commit); subject_len = find_commit_subject(out->message, &subject); @@ -1539,7 +1539,7 @@ static int try_to_commit(struct repository *r, if (flags & AMEND_MSG) { const char *exclude_gpgsig[] = { "gpgsig", "gpgsig-sha256", NULL }; - const char *out_enc = get_commit_output_encoding(); + const char *out_enc = get_commit_output_encoding(r); const char *message = repo_logmsg_reencode(r, current_head, NULL, out_enc); @@ -1672,7 +1672,7 @@ static int try_to_commit(struct repository *r, free(email); } - if (commit_tree_extended(msg->buf, msg->len, &tree, parents, oid, + if (commit_tree_extended(r, msg->buf, msg->len, &tree, parents, oid, author, committer, opts->gpg_sign, extra)) { res = error(_("failed to write commit object")); goto out; @@ -2054,7 +2054,7 @@ static int update_squash_messages(struct repository *r, struct strbuf buf = STRBUF_INIT; int res = 0; const char *message, *body; - const char *encoding = get_commit_output_encoding(); + const char *encoding = get_commit_output_encoding(r); if (!is_fixup(command)) BUG("not a FIXUP or SQUASH %d", command); @@ -2324,7 +2324,7 @@ static int do_pick_commit(struct repository *r, else parent = commit->parents->item; - if (get_message(commit, &msg) != 0) + if (get_message(r, commit, &msg) != 0) return error(_("cannot get commit message for %s"), oid_to_hex(&commit->object.oid)); @@ -3344,7 +3344,7 @@ static int walk_revs_populate_todo(struct todo_list *todo_list, if (prepare_revs(opts)) return -1; - encoding = get_log_output_encoding(); + encoding = get_log_output_encoding(the_repository); while ((commit = get_revision(opts->revs))) { struct todo_item *item = append_new_todo(todo_list); @@ -3730,7 +3730,7 @@ static int make_patch(struct repository *r, } if (!file_exists(rebase_path_message())) { - const char *encoding = get_commit_output_encoding(); + const char *encoding = get_commit_output_encoding(r); const char *commit_buffer = repo_logmsg_reencode(r, commit, NULL, encoding); @@ -3989,7 +3989,7 @@ static int do_reset(struct repository *r, if (len == 10 && !strncmp("[new root]", name, len)) { if (!opts->have_squash_onto) { const char *hex; - if (commit_tree("", 0, the_hash_algo->empty_tree, + if (commit_tree(r, "", 0, the_hash_algo->empty_tree, NULL, &opts->squash_onto, NULL, NULL)) return error(_("writing fake root commit")); @@ -4187,7 +4187,7 @@ static int do_merge(struct repository *r, } if (commit) { - const char *encoding = get_commit_output_encoding(); + const char *encoding = get_commit_output_encoding(r); const char *message = repo_logmsg_reencode(r, commit, NULL, encoding); const char *body; @@ -4831,7 +4831,7 @@ static int stopped_at_head(struct repository *r) if (repo_get_oid(r, "HEAD", &head) || !(commit = lookup_commit(r, &head)) || - repo_parse_commit(r, commit) || get_message(commit, &message)) + repo_parse_commit(r, commit) || get_message(r, commit, &message)) fprintf(stderr, _("Stopped at HEAD\n")); else { fprintf(stderr, _("Stopped at %s\n"), message.label); @@ -5311,7 +5311,7 @@ static int commit_staged_changes(struct repository *r, struct commit *commit; const char *msg; const char *path = rebase_path_squash_msg(); - const char *encoding = get_commit_output_encoding(); + const char *encoding = get_commit_output_encoding(r); if (parse_head(r, &commit)) { ret = error(_("could not parse HEAD")); @@ -5870,7 +5870,7 @@ static int make_script_with_merges(struct pretty_print_context *pp, continue; strbuf_reset(&oneline); - pretty_print_commit(pp, commit, &oneline); + pretty_print_commit(revs->repo, pp, commit, &oneline); to_merge = commit->parents ? commit->parents->next : NULL; if (!to_merge) { @@ -6012,7 +6012,7 @@ static int make_script_with_merges(struct pretty_print_context *pp, strbuf_addf(out, "%s onto\n", cmd_reset); else { strbuf_reset(&oneline); - pretty_print_commit(pp, commit, &oneline); + pretty_print_commit(revs->repo, pp, commit, &oneline); strbuf_addf(out, "%s %s %s\n", cmd_reset, to, oneline.buf); } @@ -6092,7 +6092,7 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, get_commit_format(format, &revs); free(format); pp.fmt = revs.commit_format; - pp.output_encoding = get_log_output_encoding(); + pp.output_encoding = get_log_output_encoding(r); setup_revisions_from_strvec(argv, &revs, NULL); if (argv->nr > 1) { @@ -6124,7 +6124,7 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, continue; strbuf_addf(out, "%s %s ", insn, oid_to_hex(&commit->object.oid)); - pretty_print_commit(&pp, commit, out); + pretty_print_commit(r, &pp, commit, out); if (is_empty) strbuf_addf(out, " %s empty", comment_line_str); strbuf_addch(out, '\n'); diff --git a/sparse-index.c b/sparse-index.c index 76f90da5f5f41e..386be1d6f171a8 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -152,7 +152,9 @@ static int index_has_unmerged_entries(struct index_state *istate) int is_sparse_index_allowed(struct index_state *istate, int flags) { - if (!core_apply_sparse_checkout || !core_sparse_checkout_cone) + struct repo_config_values *cfg = repo_config_values(the_repository); + + if (!cfg->apply_sparse_checkout || !core_sparse_checkout_cone) return 0; if (!(flags & SPARSE_INDEX_MEMORY_ONLY)) { @@ -670,7 +672,8 @@ static void clear_skip_worktree_from_present_files_full(struct index_state *ista void clear_skip_worktree_from_present_files(struct index_state *istate) { - if (!core_apply_sparse_checkout || + struct repo_config_values *cfg = repo_config_values(the_repository); + if (!cfg->apply_sparse_checkout || sparse_expect_files_outside_of_patterns) return; diff --git a/submodule.c b/submodule.c index 508938e4da5058..a58ed3652c6efc 100644 --- a/submodule.c +++ b/submodule.c @@ -479,7 +479,7 @@ static void print_submodule_diff_summary(struct repository *r, struct rev_info * while ((commit = get_revision(rev))) { struct pretty_print_context ctx = {0}; ctx.date_mode = rev->date_mode; - ctx.output_encoding = get_log_output_encoding(); + ctx.output_encoding = get_log_output_encoding(r); strbuf_setlen(&sb, 0); repo_format_commit_message(r, commit, format, &sb, &ctx); diff --git a/unpack-trees.c b/unpack-trees.c index f38c761ab987a6..998a1e6dc70cae 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1888,6 +1888,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options struct pattern_list pl; int free_pattern_list = 0; struct dir_struct dir = DIR_INIT; + struct repo_config_values *cfg = repo_config_values(the_repository); if (o->reset == UNPACK_RESET_INVALID) BUG("o->reset had a value of 1; should be UNPACK_TREES_*_UNTRACKED"); @@ -1924,7 +1925,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options if (o->prefix) update_sparsity_for_prefix(o->prefix, o->src_index); - if (!core_apply_sparse_checkout || !o->update) + if (!cfg->apply_sparse_checkout || !o->update) o->skip_sparse_checkout = 1; if (!o->skip_sparse_checkout) { memset(&pl, 0, sizeof(pl)); diff --git a/wt-status.c b/wt-status.c index 95942399f8cec6..521fb8a89dce8b 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1787,8 +1787,10 @@ static void wt_status_check_sparse_checkout(struct repository *r, { int skip_worktree = 0; int i; + struct repo_config_values *cfg = repo_config_values(the_repository); - if (!core_apply_sparse_checkout || r->index->cache_nr == 0) { + if (!cfg->apply_sparse_checkout || + r->index->cache_nr == 0) { /* * Don't compute percentage of checked out files if we * aren't in a sparse checkout or would get division by 0.