Git fork

Merge branch 'ps/environ-wo-the-repository'

Code clean-up.

* ps/environ-wo-the-repository: (21 commits)
environment: stop storing "core.notesRef" globally
environment: stop storing "core.warnAmbiguousRefs" globally
environment: stop storing "core.preferSymlinkRefs" globally
environment: stop storing "core.logAllRefUpdates" globally
refs: stop modifying global `log_all_ref_updates` variable
branch: stop modifying `log_all_ref_updates` variable
repo-settings: track defaults close to `struct repo_settings`
repo-settings: split out declarations into a standalone header
environment: guard state depending on a repository
environment: reorder header to split out `the_repository`-free section
environment: move `set_git_dir()` and related into setup layer
environment: make `get_git_namespace()` self-contained
environment: move object database functions into object layer
config: make dependency on repo in `read_early_config()` explicit
config: document `read_early_config()` and `read_very_early_config()`
environment: make `get_git_work_tree()` accept a repository
environment: make `get_graft_file()` accept a repository
environment: make `get_index_file()` accept a repository
environment: make `get_object_directory()` accept a repository
environment: make `get_git_common_dir()` accept a repository
...

+698 -560
+4 -2
alias.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "alias.h" 3 5 #include "config.h" ··· 37 39 { 38 40 struct config_alias_data data = { alias, NULL }; 39 41 40 - read_early_config(config_alias_cb, &data); 42 + read_early_config(the_repository, config_alias_cb, &data); 41 43 42 44 return data.v; 43 45 } ··· 46 48 { 47 49 struct config_alias_data data = { NULL, NULL, list }; 48 50 49 - read_early_config(config_alias_cb, &data); 51 + read_early_config(the_repository, config_alias_cb, &data); 50 52 } 51 53 52 54 void quote_cmdline(struct strbuf *buf, const char **argv)
+2 -1
apply.c
··· 30 30 #include "path.h" 31 31 #include "quote.h" 32 32 #include "read-cache.h" 33 + #include "repository.h" 33 34 #include "rerere.h" 34 35 #include "apply.h" 35 36 #include "entry.h" ··· 4113 4114 { 4114 4115 if (state->index_file) 4115 4116 return read_index_from(state->repo->index, state->index_file, 4116 - get_git_dir()); 4117 + repo_get_git_dir(the_repository)); 4117 4118 else 4118 4119 return repo_read_index(state->repo); 4119 4120 }
+3 -2
branch.c
··· 601 601 int forcing = 0; 602 602 struct ref_transaction *transaction; 603 603 struct strbuf err = STRBUF_INIT; 604 + int flags = 0; 604 605 char *msg; 605 606 606 607 if (track == BRANCH_TRACK_OVERRIDE) ··· 619 620 goto cleanup; 620 621 621 622 if (reflog) 622 - log_all_ref_updates = LOG_REFS_NORMAL; 623 + flags |= REF_FORCE_CREATE_REFLOG; 623 624 624 625 if (forcing) 625 626 msg = xstrfmt("branch: Reset to %s", start_name); ··· 630 631 if (!transaction || 631 632 ref_transaction_update(transaction, ref.buf, 632 633 &oid, forcing ? NULL : null_oid(), 633 - NULL, NULL, 0, msg, &err) || 634 + NULL, NULL, flags, msg, &err) || 634 635 ref_transaction_commit(transaction, &err)) 635 636 die("%s", err.buf); 636 637 ref_transaction_free(transaction);
+9 -4
builtin/am.c
··· 1544 1544 if (index_file) { 1545 1545 /* Reload index as apply_all_patches() will have modified it. */ 1546 1546 discard_index(the_repository->index); 1547 - read_index_from(the_repository->index, index_file, get_git_dir()); 1547 + read_index_from(the_repository->index, index_file, 1548 + repo_get_git_dir(the_repository)); 1548 1549 } 1549 1550 1550 1551 return 0; ··· 1587 1588 return error("could not build fake ancestor"); 1588 1589 1589 1590 discard_index(the_repository->index); 1590 - read_index_from(the_repository->index, index_path, get_git_dir()); 1591 + read_index_from(the_repository->index, index_path, repo_get_git_dir(the_repository)); 1591 1592 1592 1593 if (write_index_as_tree(&bases[0], the_repository->index, index_path, 0, NULL)) 1593 1594 return error(_("Repository lacks necessary blobs to fall back on 3-way merge.")); ··· 1667 1668 if (!state->no_verify && run_hooks(the_repository, "pre-applypatch")) 1668 1669 exit(1); 1669 1670 1670 - if (write_index_as_tree(&tree, the_repository->index, get_index_file(), 0, NULL)) 1671 + if (write_index_as_tree(&tree, the_repository->index, 1672 + repo_get_index_file(the_repository), 1673 + 0, NULL)) 1671 1674 die(_("git write-tree failed to write a tree")); 1672 1675 1673 1676 if (!repo_get_oid_commit(the_repository, "HEAD", &parent)) { ··· 2077 2080 if (fast_forward_to(head_tree, head_tree, 1)) 2078 2081 return -1; 2079 2082 2080 - if (write_index_as_tree(&index, the_repository->index, get_index_file(), 0, NULL)) 2083 + if (write_index_as_tree(&index, the_repository->index, 2084 + repo_get_index_file(the_repository), 2085 + 0, NULL)) 2081 2086 return -1; 2082 2087 2083 2088 index_tree = parse_tree_indirect(&index);
+1 -1
builtin/blame.c
··· 1081 1081 path = add_prefix(prefix, argv[1]); 1082 1082 argv[1] = argv[2]; 1083 1083 } else { /* (2a) */ 1084 - if (argc == 2 && is_a_rev(argv[1]) && !get_git_work_tree()) 1084 + if (argc == 2 && is_a_rev(argv[1]) && !repo_get_work_tree(the_repository)) 1085 1085 die("missing <path> to blame"); 1086 1086 path = add_prefix(prefix, argv[argc - 1]); 1087 1087 }
+4 -1
builtin/checkout.c
··· 23 23 #include "read-cache.h" 24 24 #include "refs.h" 25 25 #include "remote.h" 26 + #include "repo-settings.h" 26 27 #include "resolve-undo.h" 27 28 #include "revision.h" 28 29 #include "setup.h" ··· 950 951 const char *old_desc, *reflog_msg; 951 952 if (opts->new_branch) { 952 953 if (opts->new_orphan_branch) { 954 + enum log_refs_config log_all_ref_updates = 955 + repo_settings_get_log_all_ref_updates(the_repository); 953 956 char *refname; 954 957 955 958 refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch); 956 959 if (opts->new_branch_log && 957 - !should_autocreate_reflog(refname)) { 960 + !should_autocreate_reflog(log_all_ref_updates, refname)) { 958 961 int ret; 959 962 struct strbuf err = STRBUF_INIT; 960 963
+2 -3
builtin/commit-graph.c
··· 1 1 #include "builtin.h" 2 2 #include "commit.h" 3 3 #include "config.h" 4 - #include "environment.h" 5 4 #include "gettext.h" 6 5 #include "hex.h" 7 6 #include "parse-options.h" ··· 95 94 usage_with_options(builtin_commit_graph_verify_usage, options); 96 95 97 96 if (!opts.obj_dir) 98 - opts.obj_dir = get_object_directory(); 97 + opts.obj_dir = repo_get_object_directory(the_repository); 99 98 if (opts.shallow) 100 99 flags |= COMMIT_GRAPH_VERIFY_SHALLOW; 101 100 if (opts.progress) ··· 275 274 if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1) 276 275 die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs")); 277 276 if (!opts.obj_dir) 278 - opts.obj_dir = get_object_directory(); 277 + opts.obj_dir = repo_get_object_directory(the_repository); 279 278 if (opts.append) 280 279 flags |= COMMIT_GRAPH_WRITE_APPEND; 281 280 if (opts.split)
+7 -6
builtin/commit.c
··· 26 26 #include "path.h" 27 27 #include "preload-index.h" 28 28 #include "read-cache.h" 29 + #include "repository.h" 29 30 #include "string-list.h" 30 31 #include "rerere.h" 31 32 #include "unpack-trees.h" ··· 407 408 408 409 discard_index(the_repository->index); 409 410 read_index_from(the_repository->index, get_lock_file_path(&index_lock), 410 - get_git_dir()); 411 + repo_get_git_dir(the_repository)); 411 412 if (cache_tree_update(the_repository->index, WRITE_TREE_SILENT) == 0) { 412 413 if (reopen_lock_file(&index_lock) < 0) 413 414 die(_("unable to write index file")); ··· 472 473 COMMIT_LOCK | SKIP_IF_UNCHANGED)) 473 474 die(_("unable to write new index file")); 474 475 commit_style = COMMIT_AS_IS; 475 - ret = get_index_file(); 476 + ret = repo_get_index_file(the_repository); 476 477 goto out; 477 478 } 478 479 ··· 534 535 535 536 discard_index(the_repository->index); 536 537 ret = get_lock_file_path(&false_lock); 537 - read_index_from(the_repository->index, ret, get_git_dir()); 538 + read_index_from(the_repository->index, ret, repo_get_git_dir(the_repository)); 538 539 out: 539 540 string_list_clear(&partial, 0); 540 541 clear_pathspec(&pathspec); ··· 1072 1073 */ 1073 1074 discard_index(the_repository->index); 1074 1075 } 1075 - read_index_from(the_repository->index, index_file, get_git_dir()); 1076 + read_index_from(the_repository->index, index_file, repo_get_git_dir(the_repository)); 1076 1077 1077 1078 if (cache_tree_update(the_repository->index, 0)) { 1078 1079 error(_("Error building trees")); ··· 1873 1874 1874 1875 repo_rerere(the_repository, 0); 1875 1876 run_auto_maintenance(quiet); 1876 - run_commit_hook(use_editor, get_index_file(), NULL, "post-commit", 1877 - NULL); 1877 + run_commit_hook(use_editor, repo_get_index_file(the_repository), 1878 + NULL, "post-commit", NULL); 1878 1879 if (amend && !no_post_rewrite) { 1879 1880 commit_post_rewrite(the_repository, current_head, &oid); 1880 1881 }
+2 -2
builtin/config.c
··· 807 807 else 808 808 opts->options.respect_includes = opts->respect_includes_opt; 809 809 if (startup_info->have_repository) { 810 - opts->options.commondir = get_git_common_dir(); 811 - opts->options.git_dir = get_git_dir(); 810 + opts->options.commondir = repo_get_common_dir(the_repository); 811 + opts->options.git_dir = repo_get_git_dir(the_repository); 812 812 } 813 813 } 814 814
+1 -2
builtin/count-objects.c
··· 7 7 #include "builtin.h" 8 8 #include "config.h" 9 9 #include "dir.h" 10 - #include "environment.h" 11 10 #include "gettext.h" 12 11 #include "path.h" 13 12 #include "repository.h" ··· 116 115 report_linked_checkout_garbage(the_repository); 117 116 } 118 117 119 - for_each_loose_file_in_objdir(get_object_directory(), 118 + for_each_loose_file_in_objdir(repo_get_object_directory(the_repository), 120 119 count_loose, count_cruft, NULL, NULL); 121 120 122 121 if (verbose) {
+5 -4
builtin/difftool.c
··· 22 22 #include "hex.h" 23 23 #include "parse-options.h" 24 24 #include "read-cache-ll.h" 25 + #include "repository.h" 25 26 #include "sparse-index.h" 26 27 #include "strvec.h" 27 28 #include "strbuf.h" ··· 214 215 struct child_process update_index = CHILD_PROCESS_INIT; 215 216 struct child_process diff_files = CHILD_PROCESS_INIT; 216 217 struct strbuf buf = STRBUF_INIT; 217 - const char *git_dir = absolute_path(get_git_dir()); 218 + const char *git_dir = absolute_path(repo_get_git_dir(the_repository)); 218 219 FILE *fp; 219 220 220 221 strvec_pushl(&update_index.args, ··· 377 378 struct hashmap wt_modified, tmp_modified; 378 379 int indices_loaded = 0; 379 380 380 - workdir = get_git_work_tree(); 381 + workdir = repo_get_work_tree(the_repository); 381 382 382 383 /* Setup temp directories */ 383 384 tmp = getenv("TMPDIR"); ··· 737 738 738 739 if (!no_index){ 739 740 setup_work_tree(); 740 - setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1); 741 - setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1); 741 + setenv(GIT_DIR_ENVIRONMENT, absolute_path(repo_get_git_dir(the_repository)), 1); 742 + setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(repo_get_work_tree(the_repository)), 1); 742 743 } else if (dir_diff) 743 744 die(_("options '%s' and '%s' cannot be used together"), "--dir-diff", "--no-index"); 744 745
+4 -3
builtin/fsmonitor--daemon.c
··· 2 2 #include "abspath.h" 3 3 #include "config.h" 4 4 #include "dir.h" 5 - #include "environment.h" 6 5 #include "gettext.h" 7 6 #include "parse-options.h" 8 7 #include "fsmonitor-ll.h" ··· 1291 1290 1292 1291 /* Prepare to (recursively) watch the <worktree-root> directory. */ 1293 1292 strbuf_init(&state.path_worktree_watch, 0); 1294 - strbuf_addstr(&state.path_worktree_watch, absolute_path(get_git_work_tree())); 1293 + strbuf_addstr(&state.path_worktree_watch, 1294 + absolute_path(repo_get_work_tree(the_repository))); 1295 1295 state.nr_paths_watching = 1; 1296 1296 1297 1297 strbuf_init(&state.alias.alias, 0); ··· 1311 1311 strbuf_addstr(&state.path_gitdir_watch, "/.git"); 1312 1312 if (!is_directory(state.path_gitdir_watch.buf)) { 1313 1313 strbuf_reset(&state.path_gitdir_watch); 1314 - strbuf_addstr(&state.path_gitdir_watch, absolute_path(get_git_dir())); 1314 + strbuf_addstr(&state.path_gitdir_watch, 1315 + absolute_path(repo_get_git_dir(the_repository))); 1315 1316 state.nr_paths_watching = 2; 1316 1317 } 1317 1318
+1 -1
builtin/gc.c
··· 2132 2132 get_schedule_cmd(&cmd, NULL); 2133 2133 2134 2134 strbuf_addf(&tfilename, "%s/schedule_%s_XXXXXX", 2135 - get_git_common_dir(), frequency); 2135 + repo_get_common_dir(the_repository), frequency); 2136 2136 tfile = xmks_tempfile(tfilename.buf); 2137 2137 strbuf_release(&tfilename); 2138 2138
+2 -2
builtin/init-db.c
··· 231 231 set_git_work_tree(work_tree); 232 232 else 233 233 set_git_work_tree(git_work_tree_cfg); 234 - if (access(get_git_work_tree(), X_OK)) 234 + if (access(repo_get_work_tree(the_repository), X_OK)) 235 235 die_errno (_("Cannot access work tree '%s'"), 236 - get_git_work_tree()); 236 + repo_get_work_tree(the_repository)); 237 237 } 238 238 else { 239 239 if (real_git_dir)
+11 -7
builtin/merge.c
··· 17 17 #include "object-name.h" 18 18 #include "parse-options.h" 19 19 #include "lockfile.h" 20 + #include "repository.h" 20 21 #include "run-command.h" 21 22 #include "hook.h" 22 23 #include "diff.h" ··· 695 696 696 697 static void write_tree_trivial(struct object_id *oid) 697 698 { 698 - if (write_index_as_tree(oid, the_repository->index, get_index_file(), 0, NULL)) 699 + if (write_index_as_tree(oid, the_repository->index, 700 + repo_get_index_file(the_repository), 701 + 0, NULL)) 699 702 die(_("git write-tree failed to write a tree")); 700 703 } 701 704 ··· 757 760 } 758 761 if (write_locked_index(the_repository->index, &lock, 759 762 COMMIT_LOCK | SKIP_IF_UNCHANGED)) 760 - die(_("unable to write %s"), get_index_file()); 763 + die(_("unable to write %s"), repo_get_index_file(the_repository)); 761 764 return clean ? 0 : 1; 762 765 } else { 763 766 return try_merge_command(the_repository, ··· 839 842 static void prepare_to_commit(struct commit_list *remoteheads) 840 843 { 841 844 struct strbuf msg = STRBUF_INIT; 842 - const char *index_file = get_index_file(); 845 + const char *index_file = repo_get_index_file(the_repository); 843 846 844 847 if (!no_verify) { 845 848 int invoked_hook; ··· 855 858 if (invoked_hook) 856 859 discard_index(the_repository->index); 857 860 } 858 - read_index_from(the_repository->index, index_file, get_git_dir()); 861 + read_index_from(the_repository->index, index_file, 862 + repo_get_git_dir(the_repository)); 859 863 strbuf_addbuf(&msg, &merge_msg); 860 864 if (squash) 861 865 BUG("the control must not reach here under --squash"); ··· 878 882 append_signoff(&msg, ignored_log_message_bytes(msg.buf, msg.len), 0); 879 883 write_merge_heads(remoteheads); 880 884 write_file_buf(git_path_merge_msg(the_repository), msg.buf, msg.len); 881 - if (run_commit_hook(0 < option_edit, get_index_file(), NULL, 882 - "prepare-commit-msg", 885 + if (run_commit_hook(0 < option_edit, repo_get_index_file(the_repository), 886 + NULL, "prepare-commit-msg", 883 887 git_path_merge_msg(the_repository), "merge", NULL)) 884 888 abort_commit(remoteheads, NULL); 885 889 if (0 < option_edit) { ··· 887 891 abort_commit(remoteheads, NULL); 888 892 } 889 893 890 - if (!no_verify && run_commit_hook(0 < option_edit, get_index_file(), 894 + if (!no_verify && run_commit_hook(0 < option_edit, repo_get_index_file(the_repository), 891 895 NULL, "commit-msg", 892 896 git_path_merge_msg(the_repository), NULL)) 893 897 abort_commit(remoteheads, NULL);
+2 -2
builtin/multi-pack-index.c
··· 1 1 #include "builtin.h" 2 2 #include "abspath.h" 3 3 #include "config.h" 4 - #include "environment.h" 5 4 #include "gettext.h" 6 5 #include "parse-options.h" 7 6 #include "midx.h" ··· 9 8 #include "trace2.h" 10 9 #include "object-store-ll.h" 11 10 #include "replace-object.h" 11 + #include "repository.h" 12 12 13 13 #define BUILTIN_MIDX_WRITE_USAGE \ 14 14 N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \ ··· 63 63 char **value = opt->value; 64 64 free(*value); 65 65 if (unset) 66 - *value = xstrdup(get_object_directory()); 66 + *value = xstrdup(repo_get_object_directory(the_repository)); 67 67 else 68 68 *value = real_pathdup(arg, 1); 69 69 return 0;
+14 -8
builtin/notes.c
··· 897 897 1, PARSE_OPT_NONEG), 898 898 OPT_END() 899 899 }; 900 + char *notes_ref; 900 901 901 902 argc = parse_options(argc, argv, prefix, options, 902 903 git_notes_merge_usage, 0); ··· 924 925 if (do_commit) 925 926 return merge_commit(&o); 926 927 927 - o.local_ref = default_notes_ref(); 928 + notes_ref = default_notes_ref(the_repository); 929 + o.local_ref = notes_ref; 928 930 strbuf_addstr(&remote_ref, argv[0]); 929 931 expand_loose_notes_ref(&remote_ref); 930 932 o.remote_ref = remote_ref.buf; ··· 953 955 } 954 956 955 957 strbuf_addf(&msg, "notes: Merged notes from %s into %s", 956 - remote_ref.buf, default_notes_ref()); 958 + remote_ref.buf, notes_ref); 957 959 strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */ 958 960 959 961 result = notes_merge(&o, t, &result_oid); ··· 961 963 if (result >= 0) /* Merge resulted (trivially) in result_oid */ 962 964 /* Update default notes ref with new commit */ 963 965 refs_update_ref(get_main_ref_store(the_repository), msg.buf, 964 - default_notes_ref(), &result_oid, NULL, 0, 966 + notes_ref, &result_oid, NULL, 0, 965 967 UPDATE_REFS_DIE_ON_ERR); 966 968 else { /* Merge has unresolved conflicts */ 967 969 struct worktree **worktrees; ··· 973 975 /* Store ref-to-be-updated into .git/NOTES_MERGE_REF */ 974 976 worktrees = get_worktrees(); 975 977 wt = find_shared_symref(worktrees, "NOTES_MERGE_REF", 976 - default_notes_ref()); 978 + notes_ref); 977 979 if (wt) 978 980 die(_("a notes merge into %s is already in-progress at %s"), 979 - default_notes_ref(), wt->path); 981 + notes_ref, wt->path); 980 982 free_worktrees(worktrees); 981 - if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", default_notes_ref(), NULL)) 983 + if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", notes_ref, NULL)) 982 984 die(_("failed to store link to current notes ref (%s)"), 983 - default_notes_ref()); 985 + notes_ref); 984 986 fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s " 985 987 "and commit the result with 'git notes merge --commit', " 986 988 "or abort the merge with 'git notes merge --abort'.\n"), ··· 988 990 } 989 991 990 992 free_notes(t); 993 + free(notes_ref); 991 994 strbuf_release(&remote_ref); 992 995 strbuf_release(&msg); 993 996 return result < 0; /* return non-zero on conflicts */ ··· 1084 1087 static int get_ref(int argc, const char **argv, const char *prefix) 1085 1088 { 1086 1089 struct option options[] = { OPT_END() }; 1090 + char *notes_ref; 1087 1091 argc = parse_options(argc, argv, prefix, options, 1088 1092 git_notes_get_ref_usage, 0); 1089 1093 ··· 1092 1096 usage_with_options(git_notes_get_ref_usage, options); 1093 1097 } 1094 1098 1095 - puts(default_notes_ref()); 1099 + notes_ref = default_notes_ref(the_repository); 1100 + puts(notes_ref); 1101 + free(notes_ref); 1096 1102 return 0; 1097 1103 } 1098 1104
+1 -1
builtin/pack-objects.c
··· 3968 3968 */ 3969 3969 static void add_unreachable_loose_objects(void) 3970 3970 { 3971 - for_each_loose_file_in_objdir(get_object_directory(), 3971 + for_each_loose_file_in_objdir(repo_get_object_directory(the_repository), 3972 3972 add_loose_object, 3973 3973 NULL, NULL, NULL); 3974 3974 }
+4 -4
builtin/prune.c
··· 193 193 revs.exclude_promisor_objects = 1; 194 194 } 195 195 196 - for_each_loose_file_in_objdir(get_object_directory(), prune_object, 197 - prune_cruft, prune_subdir, &revs); 196 + for_each_loose_file_in_objdir(repo_get_object_directory(the_repository), 197 + prune_object, prune_cruft, prune_subdir, &revs); 198 198 199 199 prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0); 200 - remove_temporary_files(get_object_directory()); 201 - s = mkpathdup("%s/pack", get_object_directory()); 200 + remove_temporary_files(repo_get_object_directory(the_repository)); 201 + s = mkpathdup("%s/pack", repo_get_object_directory(the_repository)); 202 202 remove_temporary_files(s); 203 203 free(s); 204 204
+4 -3
builtin/repack.c
··· 1260 1260 if (write_midx && write_bitmaps) { 1261 1261 struct strbuf path = STRBUF_INIT; 1262 1262 1263 - strbuf_addf(&path, "%s/%s_XXXXXX", get_object_directory(), 1263 + strbuf_addf(&path, "%s/%s_XXXXXX", repo_get_object_directory(the_repository), 1264 1264 "bitmap-ref-tips"); 1265 1265 1266 1266 refs_snapshot = xmks_tempfile(path.buf); ··· 1269 1269 strbuf_release(&path); 1270 1270 } 1271 1271 1272 - packdir = mkpathdup("%s/pack", get_object_directory()); 1272 + packdir = mkpathdup("%s/pack", repo_get_object_directory(the_repository)); 1273 1273 packtmp_name = xstrfmt(".tmp-%d-pack", (int)getpid()); 1274 1274 packtmp = mkpathdup("%s/%s", packdir, packtmp_name); 1275 1275 ··· 1539 1539 unsigned flags = 0; 1540 1540 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0)) 1541 1541 flags |= MIDX_WRITE_INCREMENTAL; 1542 - write_midx_file(get_object_directory(), NULL, NULL, flags); 1542 + write_midx_file(repo_get_object_directory(the_repository), 1543 + NULL, NULL, flags); 1543 1544 } 1544 1545 1545 1546 cleanup:
+1 -2
builtin/replace.c
··· 11 11 #include "builtin.h" 12 12 #include "config.h" 13 13 #include "editor.h" 14 - #include "environment.h" 15 14 #include "gettext.h" 16 15 #include "hex.h" 17 16 #include "refs.h" ··· 514 513 515 514 static int convert_graft_file(int force) 516 515 { 517 - const char *graft_file = get_graft_file(the_repository); 516 + const char *graft_file = repo_get_graft_file(the_repository); 518 517 FILE *fp = fopen_or_warn(graft_file, "r"); 519 518 struct strbuf buf = STRBUF_INIT, err = STRBUF_INIT; 520 519 struct strvec args = STRVEC_INIT;
+3 -2
builtin/reset.c
··· 26 26 #include "object-name.h" 27 27 #include "parse-options.h" 28 28 #include "path.h" 29 + #include "repository.h" 29 30 #include "unpack-trees.h" 30 31 #include "cache-tree.h" 31 32 #include "setup.h" ··· 441 442 else 442 443 trace2_cmd_mode(reset_type_names[reset_type]); 443 444 444 - if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree())) 445 + if (reset_type != SOFT && (reset_type != MIXED || repo_get_work_tree(the_repository))) 445 446 setup_work_tree(); 446 447 447 448 if (reset_type == MIXED && is_bare_repository()) ··· 474 475 goto cleanup; 475 476 } 476 477 the_repository->index->updated_skipworktree = 1; 477 - if (!no_refresh && get_git_work_tree()) { 478 + if (!no_refresh && repo_get_work_tree(the_repository)) { 478 479 uint64_t t_begin, t_delta_in_ms; 479 480 480 481 t_begin = getnanotime();
+7 -4
builtin/rev-parse.c
··· 19 19 #include "path.h" 20 20 #include "diff.h" 21 21 #include "read-cache-ll.h" 22 + #include "repo-settings.h" 23 + #include "repository.h" 22 24 #include "revision.h" 23 25 #include "setup.h" 24 26 #include "split-index.h" ··· 898 900 } 899 901 if (opt_with_value(arg, "--abbrev-ref", &arg)) { 900 902 abbrev_ref = 1; 901 - abbrev_ref_strict = warn_ambiguous_refs; 903 + abbrev_ref_strict = 904 + repo_settings_get_warn_ambiguous_refs(the_repository); 902 905 if (arg) { 903 906 if (!strcmp(arg, "strict")) 904 907 abbrev_ref_strict = 1; ··· 966 969 continue; 967 970 } 968 971 if (!strcmp(arg, "--show-toplevel")) { 969 - const char *work_tree = get_git_work_tree(); 972 + const char *work_tree = repo_get_work_tree(the_repository); 970 973 if (work_tree) 971 974 print_path(work_tree, prefix, format, DEFAULT_UNMODIFIED); 972 975 else ··· 991 994 const char *pfx = prefix; 992 995 if (!is_inside_work_tree()) { 993 996 const char *work_tree = 994 - get_git_work_tree(); 997 + repo_get_work_tree(the_repository); 995 998 if (work_tree) 996 999 printf("%s\n", work_tree); 997 1000 continue; ··· 1042 1045 continue; 1043 1046 } 1044 1047 if (!strcmp(arg, "--git-common-dir")) { 1045 - print_path(get_git_common_dir(), prefix, format, DEFAULT_RELATIVE_IF_SHARED); 1048 + print_path(repo_get_common_dir(the_repository), prefix, format, DEFAULT_RELATIVE_IF_SHARED); 1046 1049 continue; 1047 1050 } 1048 1051 if (!strcmp(arg, "--is-inside-git-dir")) {
+9 -8
builtin/stash.c
··· 19 19 #include "entry.h" 20 20 #include "preload-index.h" 21 21 #include "read-cache.h" 22 + #include "repository.h" 22 23 #include "rerere.h" 23 24 #include "revision.h" 24 25 #include "setup.h" ··· 539 540 NULL, NULL, NULL)) 540 541 return error(_("could not write index")); 541 542 542 - if (write_index_as_tree(&c_tree, the_repository->index, get_index_file(), 0, 543 - NULL)) 543 + if (write_index_as_tree(&c_tree, the_repository->index, 544 + repo_get_index_file(the_repository), 0, NULL)) 544 545 return error(_("cannot apply a stash in the middle of a merge")); 545 546 546 547 if (index) { ··· 565 566 discard_index(the_repository->index); 566 567 repo_read_index(the_repository); 567 568 if (write_index_as_tree(&index_tree, the_repository->index, 568 - get_index_file(), 0, NULL)) 569 + repo_get_index_file(the_repository), 0, NULL)) 569 570 return error(_("could not save index tree")); 570 571 571 572 reset_head(); ··· 640 641 cp.git_cmd = 1; 641 642 cp.dir = prefix; 642 643 strvec_pushf(&cp.env, GIT_WORK_TREE_ENVIRONMENT"=%s", 643 - absolute_path(get_git_work_tree())); 644 + absolute_path(repo_get_work_tree(the_repository))); 644 645 strvec_pushf(&cp.env, GIT_DIR_ENVIRONMENT"=%s", 645 - absolute_path(get_git_dir())); 646 + absolute_path(repo_get_git_dir(the_repository))); 646 647 strvec_push(&cp.args, "status"); 647 648 run_command(&cp); 648 649 } ··· 1405 1406 1406 1407 strbuf_addf(&commit_tree_label, "index on %s\n", msg.buf); 1407 1408 commit_list_insert(head_commit, &parents); 1408 - if (write_index_as_tree(&info->i_tree, the_repository->index, get_index_file(), 0, 1409 - NULL) || 1409 + if (write_index_as_tree(&info->i_tree, the_repository->index, 1410 + repo_get_index_file(the_repository), 0, NULL) || 1410 1411 commit_tree(commit_tree_label.buf, commit_tree_label.len, 1411 1412 &info->i_tree, parents, &info->i_commit, NULL, NULL)) { 1412 1413 if (!quiet) ··· 1904 1905 prepare_repo_settings(the_repository); 1905 1906 the_repository->settings.command_requires_full_index = 0; 1906 1907 1907 - index_file = get_index_file(); 1908 + index_file = repo_get_index_file(the_repository); 1908 1909 strbuf_addf(&stash_index_path, "%s.stash.%" PRIuMAX, index_file, 1909 1910 (uintmax_t)pid); 1910 1911
+1 -1
builtin/submodule--helper.c
··· 1709 1709 exit(128); 1710 1710 1711 1711 if (!is_absolute_path(clone_data->path)) 1712 - clone_data_path = to_free = xstrfmt("%s/%s", get_git_work_tree(), 1712 + clone_data_path = to_free = xstrfmt("%s/%s", repo_get_work_tree(the_repository), 1713 1713 clone_data->path); 1714 1714 1715 1715 if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0)
+2 -2
builtin/update-index.c
··· 1194 1194 "remove or change it, if you really want to " 1195 1195 "enable the untracked cache")); 1196 1196 add_untracked_cache(the_repository->index); 1197 - report(_("Untracked cache enabled for '%s'"), get_git_work_tree()); 1197 + report(_("Untracked cache enabled for '%s'"), repo_get_work_tree(the_repository)); 1198 1198 break; 1199 1199 default: 1200 1200 BUG("bad untracked_cache value: %d", untracked_cache); ··· 1239 1239 if (newfd < 0) { 1240 1240 if (refresh_args.flags & REFRESH_QUIET) 1241 1241 exit(128); 1242 - unable_to_lock_die(get_index_file(), lock_error); 1242 + unable_to_lock_die(repo_get_index_file(the_repository), lock_error); 1243 1243 } 1244 1244 if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK)) 1245 1245 die("Unable to write new index file");
+2 -2
builtin/worktree.c
··· 219 219 } 220 220 closedir(dir); 221 221 222 - strbuf_add_absolute_path(&main_path, get_git_common_dir()); 222 + strbuf_add_absolute_path(&main_path, repo_get_common_dir(the_repository)); 223 223 /* massage main worktree absolute path to match 'gitdir' content */ 224 224 strbuf_strip_suffix(&main_path, "/."); 225 225 string_list_append_nodup(&kept, strbuf_detach(&main_path, NULL)); ··· 492 492 strbuf_addf(&sb, "%s/gitdir", sb_repo.buf); 493 493 strbuf_realpath(&realpath, sb_git.buf, 1); 494 494 write_file(sb.buf, "%s", realpath.buf); 495 - strbuf_realpath(&realpath, get_git_common_dir(), 1); 495 + strbuf_realpath(&realpath, repo_get_common_dir(the_repository), 1); 496 496 write_file(sb_git.buf, "gitdir: %s/worktrees/%s", 497 497 realpath.buf, name); 498 498 strbuf_reset(&sb);
+2 -2
builtin/write-tree.c
··· 6 6 7 7 #include "builtin.h" 8 8 #include "config.h" 9 - #include "environment.h" 10 9 #include "gettext.h" 11 10 #include "hex.h" 12 11 #include "tree.h" ··· 44 43 prepare_repo_settings(the_repository); 45 44 the_repository->settings.command_requires_full_index = 0; 46 45 47 - ret = write_index_as_tree(&oid, the_repository->index, get_index_file(), 46 + ret = write_index_as_tree(&oid, the_repository->index, 47 + repo_get_index_file(the_repository), 48 48 flags, tree_prefix); 49 49 switch (ret) { 50 50 case 0:
+2 -2
bulk-checkin.c
··· 75 75 close(fd); 76 76 } 77 77 78 - strbuf_addf(&packname, "%s/pack/pack-%s.", get_object_directory(), 78 + strbuf_addf(&packname, "%s/pack/pack-%s.", repo_get_object_directory(the_repository), 79 79 hash_to_hex(hash)); 80 80 finish_tmp_packfile(&packname, state->pack_tmp_name, 81 81 state->written, state->nr_written, ··· 113 113 * to ensure that the data in each new object file is durable before 114 114 * the final name is visible. 115 115 */ 116 - strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX", get_object_directory()); 116 + strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX", repo_get_object_directory(the_repository)); 117 117 temp = xmks_tempfile(temp_path.buf); 118 118 fsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp)); 119 119 delete_tempfile(&temp);
+1 -1
bundle-uri.c
··· 4 4 #include "bundle-uri.h" 5 5 #include "bundle.h" 6 6 #include "copy.h" 7 - #include "environment.h" 8 7 #include "gettext.h" 9 8 #include "refs.h" 10 9 #include "run-command.h" ··· 14 13 #include "fetch-pack.h" 15 14 #include "remote.h" 16 15 #include "trace2.h" 16 + #include "object-store-ll.h" 17 17 18 18 static struct { 19 19 enum bundle_list_heuristic heuristic;
+3 -2
cache-tree.c
··· 1 1 #define USE_THE_REPOSITORY_VARIABLE 2 2 3 3 #include "git-compat-util.h" 4 - #include "environment.h" 5 4 #include "hex.h" 6 5 #include "lockfile.h" 7 6 #include "tree.h" ··· 12 11 #include "object-store-ll.h" 13 12 #include "read-cache-ll.h" 14 13 #include "replace-object.h" 14 + #include "repository.h" 15 15 #include "promisor-remote.h" 16 16 #include "trace.h" 17 17 #include "trace2.h" ··· 725 725 726 726 hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR); 727 727 728 - entries = read_index_from(index_state, index_path, get_git_dir()); 728 + entries = read_index_from(index_state, index_path, 729 + repo_get_git_dir(the_repository)); 729 730 if (entries < 0) { 730 731 ret = WRITE_TREE_UNREADABLE_INDEX; 731 732 goto out;
+2 -2
commit.c
··· 292 292 293 293 void prepare_commit_graft(struct repository *r) 294 294 { 295 - char *graft_file; 295 + const char *graft_file; 296 296 297 297 if (r->parsed_objects->commit_graft_prepared) 298 298 return; 299 299 if (!startup_info->have_repository) 300 300 return; 301 301 302 - graft_file = get_graft_file(r); 302 + graft_file = repo_get_graft_file(r); 303 303 read_graft_file(r, graft_file); 304 304 /* make sure shallows are read */ 305 305 is_repository_shallow(r);
+2
compat/mingw.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "../git-compat-util.h" 2 4 #include "win32.h" 3 5 #include <aclapi.h>
+2
compat/win32/path-utils.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "../../git-compat-util.h" 2 4 #include "../../environment.h" 3 5
+6 -36
config.c
··· 6 6 * 7 7 */ 8 8 9 + #define USE_THE_REPOSITORY_VARIABLE 10 + 9 11 #include "git-compat-util.h" 10 12 #include "abspath.h" 11 13 #include "advice.h" ··· 1445 1447 return 0; 1446 1448 } 1447 1449 1448 - if (!strcmp(var, "core.prefersymlinkrefs")) { 1449 - prefer_symlink_refs = git_config_bool(var, value); 1450 - return 0; 1451 - } 1452 - 1453 - if (!strcmp(var, "core.logallrefupdates")) { 1454 - if (value && !strcasecmp(value, "always")) 1455 - log_all_ref_updates = LOG_REFS_ALWAYS; 1456 - else if (git_config_bool(var, value)) 1457 - log_all_ref_updates = LOG_REFS_NORMAL; 1458 - else 1459 - log_all_ref_updates = LOG_REFS_NONE; 1460 - return 0; 1461 - } 1462 - 1463 - if (!strcmp(var, "core.warnambiguousrefs")) { 1464 - warn_ambiguous_refs = git_config_bool(var, value); 1465 - return 0; 1466 - } 1467 - 1468 1450 if (!strcmp(var, "core.abbrev")) { 1469 1451 if (!value) 1470 1452 return config_error_nonbool(var); ··· 1571 1553 if (!strcmp(var, "core.checkroundtripencoding")) { 1572 1554 FREE_AND_NULL(check_roundtrip_encoding); 1573 1555 return git_config_string(&check_roundtrip_encoding, var, value); 1574 - } 1575 - 1576 - if (!strcmp(var, "core.notesref")) { 1577 - if (!value) 1578 - return config_error_nonbool(var); 1579 - free(notes_ref_name); 1580 - notes_ref_name = xstrdup(value); 1581 - return 0; 1582 1556 } 1583 1557 1584 1558 if (!strcmp(var, "core.editor")) { ··· 2202 2176 } 2203 2177 } 2204 2178 2205 - void read_early_config(config_fn_t cb, void *data) 2179 + void read_early_config(struct repository *repo, config_fn_t cb, void *data) 2206 2180 { 2207 2181 struct config_options opts = {0}; 2208 2182 struct strbuf commondir = STRBUF_INIT; ··· 2210 2184 2211 2185 opts.respect_includes = 1; 2212 2186 2213 - if (have_git_dir()) { 2214 - opts.commondir = get_git_common_dir(); 2215 - opts.git_dir = get_git_dir(); 2187 + if (repo && repo->gitdir) { 2188 + opts.commondir = repo_get_common_dir(repo); 2189 + opts.git_dir = repo_get_git_dir(repo); 2216 2190 /* 2217 2191 * When setup_git_directory() was not yet asked to discover the 2218 2192 * GIT_DIR, we ask discover_git_directory() to figure out whether there ··· 2232 2206 strbuf_release(&gitdir); 2233 2207 } 2234 2208 2235 - /* 2236 - * Read config but only enumerate system and global settings. 2237 - * Omit any repo-local, worktree-local, or command-line settings. 2238 - */ 2239 2209 void read_very_early_config(config_fn_t cb, void *data) 2240 2210 { 2241 2211 struct config_options opts = { 0 };
+12 -1
config.h
··· 192 192 void git_config_push_parameter(const char *text); 193 193 void git_config_push_env(const char *spec); 194 194 int git_config_from_parameters(config_fn_t fn, void *data); 195 - void read_early_config(config_fn_t cb, void *data); 195 + 196 + /* 197 + * Read config when the Git directory has not yet been set up. In case 198 + * `the_repository` has not yet been set up, try to discover the Git 199 + * directory to read the configuration from. 200 + */ 201 + void read_early_config(struct repository *repo, config_fn_t cb, void *data); 202 + 203 + /* 204 + * Read config but only enumerate system and global settings. 205 + * Omit any repo-local, worktree-local, or command-line settings. 206 + */ 196 207 void read_very_early_config(config_fn_t cb, void *data); 197 208 198 209 /**
+2 -1
dir.c
··· 20 20 #include "object-store-ll.h" 21 21 #include "path.h" 22 22 #include "refs.h" 23 + #include "repository.h" 23 24 #include "wildmatch.h" 24 25 #include "pathspec.h" 25 26 #include "utf8.h" ··· 2838 2839 return sb.buf; 2839 2840 if (uname(&uts) < 0) 2840 2841 die_errno(_("failed to get kernel name and information")); 2841 - strbuf_addf(&sb, "Location %s, system %s", get_git_work_tree(), 2842 + strbuf_addf(&sb, "Location %s, system %s", repo_get_work_tree(the_repository), 2842 2843 uts.sysname); 2843 2844 return sb.buf; 2844 2845 }
+28 -209
environment.c
··· 22 22 #include "fmt-merge-msg.h" 23 23 #include "commit.h" 24 24 #include "strvec.h" 25 - #include "object-file.h" 26 - #include "object-store-ll.h" 27 25 #include "path.h" 28 - #include "replace-object.h" 29 - #include "tmp-objdir.h" 30 26 #include "chdir-notify.h" 31 27 #include "setup.h" 32 - #include "shallow.h" 33 - #include "trace.h" 34 28 #include "write-or-die.h" 35 29 36 30 int trust_executable_bit = 1; ··· 40 34 int minimum_abbrev = 4, default_abbrev = -1; 41 35 int ignore_case; 42 36 int assume_unchanged; 43 - int prefer_symlink_refs; 44 37 int is_bare_repository_cfg = -1; /* unspecified */ 45 - int warn_ambiguous_refs = 1; 46 38 int warn_on_object_refname_ambiguity = 1; 47 39 int repository_format_precious_objects; 48 40 char *git_commit_encoding; ··· 75 67 #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS 76 68 #endif 77 69 enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; 78 - char *notes_ref_name; 79 70 int grafts_keep_true_parents; 80 71 int core_apply_sparse_checkout; 81 72 int core_sparse_checkout_cone; ··· 83 74 int merge_log_config = -1; 84 75 int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ 85 76 unsigned long pack_size_limit_cfg; 86 - enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET; 87 77 int max_allowed_tree_depth = 88 78 #ifdef _MSC_VER 89 79 /* ··· 123 113 /* This is set by setup_git_dir_gently() and/or git_default_config() */ 124 114 char *git_work_tree_cfg; 125 115 126 - static char *git_namespace; 127 - 128 116 /* 129 117 * Repository-local GIT_* environment variables; see environment.h for details. 130 118 */ ··· 147 135 NULL 148 136 }; 149 137 150 - static char *expand_namespace(const char *raw_namespace) 151 - { 152 - struct strbuf buf = STRBUF_INIT; 153 - struct strbuf **components, **c; 154 - 155 - if (!raw_namespace || !*raw_namespace) 156 - return xstrdup(""); 157 - 158 - strbuf_addstr(&buf, raw_namespace); 159 - components = strbuf_split(&buf, '/'); 160 - strbuf_reset(&buf); 161 - for (c = components; *c; c++) 162 - if (strcmp((*c)->buf, "/") != 0) 163 - strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf); 164 - strbuf_list_free(components); 165 - if (check_refname_format(buf.buf, 0)) 166 - die(_("bad git namespace path \"%s\""), raw_namespace); 167 - strbuf_addch(&buf, '/'); 168 - return strbuf_detach(&buf, NULL); 169 - } 170 - 171 138 const char *getenv_safe(struct strvec *argv, const char *name) 172 139 { 173 140 const char *value = getenv(name); ··· 179 146 return argv->v[argv->nr - 1]; 180 147 } 181 148 182 - void setup_git_env(const char *git_dir) 183 - { 184 - char *git_replace_ref_base; 185 - const char *shallow_file; 186 - const char *replace_ref_base; 187 - struct set_gitdir_args args = { NULL }; 188 - struct strvec to_free = STRVEC_INIT; 189 - 190 - args.commondir = getenv_safe(&to_free, GIT_COMMON_DIR_ENVIRONMENT); 191 - args.object_dir = getenv_safe(&to_free, DB_ENVIRONMENT); 192 - args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT); 193 - args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT); 194 - args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT); 195 - if (getenv(GIT_QUARANTINE_ENVIRONMENT)) { 196 - args.disable_ref_updates = 1; 197 - } 198 - 199 - repo_set_gitdir(the_repository, git_dir, &args); 200 - strvec_clear(&to_free); 201 - 202 - if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) 203 - disable_replace_refs(); 204 - replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT); 205 - git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base 206 - : "refs/replace/"); 207 - update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); 208 - 209 - free(git_namespace); 210 - git_namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT)); 211 - shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); 212 - if (shallow_file) 213 - set_alternate_shallow_file(the_repository, shallow_file, 0); 214 - 215 - if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) 216 - fetch_if_missing = 0; 217 - } 218 - 219 149 int is_bare_repository(void) 220 150 { 221 151 /* if core.bare is not 'false', let's see if there is a work tree */ 222 - return is_bare_repository_cfg && !get_git_work_tree(); 152 + return is_bare_repository_cfg && !repo_get_work_tree(the_repository); 223 153 } 224 154 225 155 int have_git_dir(void) ··· 228 158 || the_repository->gitdir; 229 159 } 230 160 231 - const char *get_git_dir(void) 232 - { 233 - if (!the_repository->gitdir) 234 - BUG("git environment hasn't been setup"); 235 - return the_repository->gitdir; 236 - } 237 - 238 - const char *get_git_common_dir(void) 239 - { 240 - if (!the_repository->commondir) 241 - BUG("git environment hasn't been setup"); 242 - return the_repository->commondir; 243 - } 244 - 245 161 const char *get_git_namespace(void) 246 162 { 247 - if (!git_namespace) 248 - BUG("git environment hasn't been setup"); 249 - return git_namespace; 250 - } 163 + static const char *namespace; 251 164 252 - const char *strip_namespace(const char *namespaced_ref) 253 - { 254 - const char *out; 255 - if (skip_prefix(namespaced_ref, get_git_namespace(), &out)) 256 - return out; 257 - return NULL; 258 - } 165 + struct strbuf buf = STRBUF_INIT; 166 + struct strbuf **components, **c; 167 + const char *raw_namespace; 259 168 260 - static int git_work_tree_initialized; 169 + if (namespace) 170 + return namespace; 261 171 262 - /* 263 - * Note. This works only before you used a work tree. This was added 264 - * primarily to support git-clone to work in a new repository it just 265 - * created, and is not meant to flip between different work trees. 266 - */ 267 - void set_git_work_tree(const char *new_work_tree) 268 - { 269 - if (git_work_tree_initialized) { 270 - struct strbuf realpath = STRBUF_INIT; 271 - 272 - strbuf_realpath(&realpath, new_work_tree, 1); 273 - new_work_tree = realpath.buf; 274 - if (strcmp(new_work_tree, the_repository->worktree)) 275 - die("internal error: work tree has already been set\n" 276 - "Current worktree: %s\nNew worktree: %s", 277 - the_repository->worktree, new_work_tree); 278 - strbuf_release(&realpath); 279 - return; 172 + raw_namespace = getenv(GIT_NAMESPACE_ENVIRONMENT); 173 + if (!raw_namespace || !*raw_namespace) { 174 + namespace = ""; 175 + return namespace; 280 176 } 281 - git_work_tree_initialized = 1; 282 - repo_set_worktree(the_repository, new_work_tree); 283 - } 284 - 285 - const char *get_git_work_tree(void) 286 - { 287 - return the_repository->worktree; 288 - } 289 177 290 - const char *get_object_directory(void) 291 - { 292 - if (!the_repository->objects->odb) 293 - BUG("git environment hasn't been setup"); 294 - return the_repository->objects->odb->path; 295 - } 296 - 297 - int odb_mkstemp(struct strbuf *temp_filename, const char *pattern) 298 - { 299 - int fd; 300 - /* 301 - * we let the umask do its job, don't try to be more 302 - * restrictive except to remove write permission. 303 - */ 304 - int mode = 0444; 305 - git_path_buf(temp_filename, "objects/%s", pattern); 306 - fd = git_mkstemp_mode(temp_filename->buf, mode); 307 - if (0 <= fd) 308 - return fd; 309 - 310 - /* slow path */ 311 - /* some mkstemp implementations erase temp_filename on failure */ 312 - git_path_buf(temp_filename, "objects/%s", pattern); 313 - safe_create_leading_directories(temp_filename->buf); 314 - return xmkstemp_mode(temp_filename->buf, mode); 315 - } 316 - 317 - int odb_pack_keep(const char *name) 318 - { 319 - int fd; 320 - 321 - fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600); 322 - if (0 <= fd) 323 - return fd; 324 - 325 - /* slow path */ 326 - safe_create_leading_directories_const(name); 327 - return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); 328 - } 329 - 330 - char *get_index_file(void) 331 - { 332 - if (!the_repository->index_file) 333 - BUG("git environment hasn't been setup"); 334 - return the_repository->index_file; 335 - } 178 + strbuf_addstr(&buf, raw_namespace); 179 + components = strbuf_split(&buf, '/'); 180 + strbuf_reset(&buf); 181 + for (c = components; *c; c++) 182 + if (strcmp((*c)->buf, "/") != 0) 183 + strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf); 184 + strbuf_list_free(components); 185 + if (check_refname_format(buf.buf, 0)) 186 + die(_("bad git namespace path \"%s\""), raw_namespace); 187 + strbuf_addch(&buf, '/'); 336 188 337 - char *get_graft_file(struct repository *r) 338 - { 339 - if (!r->graft_file) 340 - BUG("git environment hasn't been setup"); 341 - return r->graft_file; 342 - } 189 + namespace = strbuf_detach(&buf, NULL); 343 190 344 - static void set_git_dir_1(const char *path) 345 - { 346 - xsetenv(GIT_DIR_ENVIRONMENT, path, 1); 347 - setup_git_env(path); 191 + return namespace; 348 192 } 349 193 350 - static void update_relative_gitdir(const char *name UNUSED, 351 - const char *old_cwd, 352 - const char *new_cwd, 353 - void *data UNUSED) 194 + const char *strip_namespace(const char *namespaced_ref) 354 195 { 355 - char *path = reparent_relative_path(old_cwd, new_cwd, get_git_dir()); 356 - struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb(); 357 - 358 - trace_printf_key(&trace_setup_key, 359 - "setup: move $GIT_DIR to '%s'", 360 - path); 361 - set_git_dir_1(path); 362 - if (tmp_objdir) 363 - tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd); 364 - free(path); 365 - } 366 - 367 - void set_git_dir(const char *path, int make_realpath) 368 - { 369 - struct strbuf realpath = STRBUF_INIT; 370 - 371 - if (make_realpath) { 372 - strbuf_realpath(&realpath, path, 1); 373 - path = realpath.buf; 374 - } 375 - 376 - set_git_dir_1(path); 377 - if (!is_absolute_path(path)) 378 - chdir_notify_register(NULL, update_relative_gitdir, NULL); 379 - 380 - strbuf_release(&realpath); 196 + const char *out; 197 + if (skip_prefix(namespaced_ref, get_git_namespace(), &out)) 198 + return out; 199 + return NULL; 381 200 } 382 201 383 202 const char *get_log_output_encoding(void)
+65 -77
environment.h
··· 1 1 #ifndef ENVIRONMENT_H 2 2 #define ENVIRONMENT_H 3 3 4 - struct repository; 5 - struct strvec; 6 - 7 - /* 8 - * The character that begins a commented line in user-editable file 9 - * that is subject to stripspace. 10 - */ 11 - extern const char *comment_line_str; 12 - extern char *comment_line_str_to_free; 13 - extern int auto_comment_line_char; 14 - 15 - /* 16 - * Wrapper of getenv() that returns a strdup value. This value is kept 17 - * in argv to be freed later. 18 - */ 19 - const char *getenv_safe(struct strvec *argv, const char *name); 4 + #include "repo-settings.h" 20 5 21 6 /* Double-check local_repo_env below if you add to this list. */ 22 7 #define GIT_DIR_ENVIRONMENT "GIT_DIR" ··· 87 72 */ 88 73 #define GIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE" 89 74 75 + #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" 76 + 90 77 /* 91 78 * Repository-local GIT_* environment variables; these will be cleared 92 79 * when git spawns a sub-process that runs inside another repository. ··· 95 82 */ 96 83 extern const char * const local_repo_env[]; 97 84 85 + struct strvec; 86 + 87 + /* 88 + * Wrapper of getenv() that returns a strdup value. This value is kept 89 + * in argv to be freed later. 90 + */ 91 + const char *getenv_safe(struct strvec *argv, const char *name); 92 + 93 + /* 94 + * Should we print an ellipsis after an abbreviated SHA-1 value 95 + * when doing diff-raw output or indicating a detached HEAD? 96 + */ 97 + int print_sha1_ellipsis(void); 98 + 99 + /* 100 + * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value). 101 + */ 102 + int use_optional_locks(void); 103 + 104 + const char *get_git_namespace(void); 105 + const char *strip_namespace(const char *namespaced_ref); 106 + 107 + /* 108 + * TODO: All the below state either explicitly or implicitly relies on 109 + * `the_repository`. We should eventually get rid of these and make the 110 + * dependency on a repository explicit: 111 + * 112 + * - `setup_git_env()` ideally shouldn't exist as it modifies global state, 113 + * namely the environment. The current process shouldn't ever access that 114 + * state via envvars though, but should instead consult a `struct 115 + * repository`. When spawning new processes, we would ideally also pass a 116 + * `struct repository` and then set up the environment variables for the 117 + * child process, only. 118 + * 119 + * - `have_git_dir()` should not have to exist at all. Instead, we should 120 + * decide on whether or not we have a `struct repository`. 121 + * 122 + * - All the global config variables should become tied to a repository. Like 123 + * this, we'd correctly honor repository-local configuration and be able to 124 + * distinguish configuration values from different repositories. 125 + * 126 + * Please do not add new global config variables here. 127 + */ 128 + # ifdef USE_THE_REPOSITORY_VARIABLE 98 129 void setup_git_env(const char *git_dir); 99 130 100 131 /* ··· 103 134 */ 104 135 int have_git_dir(void); 105 136 137 + /* 138 + * Accessors for the core.sharedrepository config which lazy-load the value 139 + * from the config (if not already set). The "reset" function can be 140 + * used to unset "set" or cached value, meaning that the value will be loaded 141 + * fresh from the config file on the next call to get_shared_repository(). 142 + */ 143 + void set_shared_repository(int value); 144 + int get_shared_repository(void); 145 + void reset_shared_repository(void); 146 + 106 147 extern int is_bare_repository_cfg; 107 148 int is_bare_repository(void); 108 149 extern char *git_work_tree_cfg; 109 - const char *get_git_dir(void); 110 - const char *get_git_common_dir(void); 111 - const char *get_object_directory(void); 112 - char *get_index_file(void); 113 - char *get_graft_file(struct repository *r); 114 - void set_git_dir(const char *path, int make_realpath); 115 - const char *get_git_namespace(void); 116 - const char *strip_namespace(const char *namespaced_ref); 117 - const char *get_git_work_tree(void); 118 - void set_git_work_tree(const char *tree); 119 - 120 - #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" 121 150 122 151 /* Environment bits from configuration mechanism */ 123 152 extern int trust_executable_bit; ··· 127 156 extern int minimum_abbrev, default_abbrev; 128 157 extern int ignore_case; 129 158 extern int assume_unchanged; 130 - extern int prefer_symlink_refs; 131 - extern int warn_ambiguous_refs; 132 159 extern int warn_on_object_refname_ambiguity; 133 160 extern char *apply_default_whitespace; 134 161 extern char *apply_default_ignorewhitespace; ··· 143 170 extern unsigned long pack_size_limit_cfg; 144 171 extern int max_allowed_tree_depth; 145 172 146 - /* 147 - * Accessors for the core.sharedrepository config which lazy-load the value 148 - * from the config (if not already set). The "reset" function can be 149 - * used to unset "set" or cached value, meaning that the value will be loaded 150 - * fresh from the config file on the next call to get_shared_repository(). 151 - */ 152 - void set_shared_repository(int value); 153 - int get_shared_repository(void); 154 - void reset_shared_repository(void); 155 - 156 173 extern int core_preload_index; 157 174 extern int precomposed_unicode; 158 175 extern int protect_hfs; ··· 162 179 extern int core_sparse_checkout_cone; 163 180 extern int sparse_expect_files_outside_of_patterns; 164 181 165 - /* 166 - * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value). 167 - */ 168 - int use_optional_locks(void); 169 - 170 - enum log_refs_config { 171 - LOG_REFS_UNSET = -1, 172 - LOG_REFS_NONE = 0, 173 - LOG_REFS_NORMAL, 174 - LOG_REFS_ALWAYS 175 - }; 176 - extern enum log_refs_config log_all_ref_updates; 177 - 178 182 enum rebase_setup_type { 179 183 AUTOREBASE_NEVER = 0, 180 184 AUTOREBASE_LOCAL, 181 185 AUTOREBASE_REMOTE, 182 186 AUTOREBASE_ALWAYS 183 187 }; 188 + extern enum rebase_setup_type autorebase; 184 189 185 190 enum push_default_type { 186 191 PUSH_DEFAULT_NOTHING = 0, ··· 190 195 PUSH_DEFAULT_CURRENT, 191 196 PUSH_DEFAULT_UNSPECIFIED 192 197 }; 193 - 194 - extern enum rebase_setup_type autorebase; 195 198 extern enum push_default_type push_default; 196 199 197 200 enum object_creation_mode { 198 201 OBJECT_CREATION_USES_HARDLINKS = 0, 199 202 OBJECT_CREATION_USES_RENAMES = 1 200 203 }; 201 - 202 204 extern enum object_creation_mode object_creation_mode; 203 - 204 - extern char *notes_ref_name; 205 205 206 206 extern int grafts_keep_true_parents; 207 207 208 208 extern int repository_format_precious_objects; 209 209 210 - /* 211 - * Create a temporary file rooted in the object database directory, or 212 - * die on failure. The filename is taken from "pattern", which should have the 213 - * usual "XXXXXX" trailer, and the resulting filename is written into the 214 - * "template" buffer. Returns the open descriptor. 215 - */ 216 - int odb_mkstemp(struct strbuf *temp_filename, const char *pattern); 217 - 218 - /* 219 - * Create a pack .keep file named "name" (which should generally be the output 220 - * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on 221 - * error. 222 - */ 223 - int odb_pack_keep(const char *name); 224 - 225 210 const char *get_log_output_encoding(void); 226 211 const char *get_commit_output_encoding(void); 227 212 ··· 233 218 extern char *excludes_file; 234 219 235 220 /* 236 - * Should we print an ellipsis after an abbreviated SHA-1 value 237 - * when doing diff-raw output or indicating a detached HEAD? 221 + * The character that begins a commented line in user-editable file 222 + * that is subject to stripspace. 238 223 */ 239 - int print_sha1_ellipsis(void); 224 + extern const char *comment_line_str; 225 + extern char *comment_line_str_to_free; 226 + extern int auto_comment_line_char; 240 227 241 - #endif 228 + # endif /* USE_THE_REPOSITORY_VARIABLE */ 229 + #endif /* ENVIRONMENT_H */
+1 -1
fetch-pack.c
··· 1839 1839 1840 1840 string_list_append_nodup(pack_lockfiles, 1841 1841 xstrfmt("%s/pack/pack-%s.keep", 1842 - get_object_directory(), 1842 + repo_get_object_directory(the_repository), 1843 1843 packname)); 1844 1844 } 1845 1845 string_list_clear(&packfile_uris, 0);
+2 -1
fsmonitor.c
··· 8 8 #include "fsmonitor.h" 9 9 #include "fsmonitor-ipc.h" 10 10 #include "name-hash.h" 11 + #include "repository.h" 11 12 #include "run-command.h" 12 13 #include "strbuf.h" 13 14 #include "trace2.h" ··· 169 170 strvec_pushf(&cp.args, "%d", version); 170 171 strvec_pushf(&cp.args, "%s", last_update); 171 172 cp.use_shell = 1; 172 - cp.dir = get_git_work_tree(); 173 + cp.dir = repo_get_work_tree(the_repository); 173 174 174 175 trace2_region_enter("fsm_hook", "query", NULL); 175 176
+1 -1
help.c
··· 618 618 memset(&other_cmds, 0, sizeof(other_cmds)); 619 619 memset(&aliases, 0, sizeof(aliases)); 620 620 621 - read_early_config(git_unknown_cmd_config, NULL); 621 + read_early_config(the_repository, git_unknown_cmd_config, NULL); 622 622 623 623 /* 624 624 * Disable autocorrection prompt in a non-interactive session
+1 -1
http-backend.c
··· 601 601 602 602 static void get_info_packs(struct strbuf *hdr, char *arg UNUSED) 603 603 { 604 - size_t objdirlen = strlen(get_object_directory()); 604 + size_t objdirlen = strlen(repo_get_object_directory(the_repository)); 605 605 struct strbuf buf = STRBUF_INIT; 606 606 struct packed_git *p; 607 607 size_t cnt = 0;
+3
name-hash.c
··· 5 5 * 6 6 * Copyright (C) 2008 Linus Torvalds 7 7 */ 8 + 9 + #define USE_THE_REPOSITORY_VARIABLE 10 + 8 11 #include "git-compat-util.h" 9 12 #include "environment.h" 10 13 #include "gettext.h"
+13 -8
notes.c
··· 992 992 return 0; 993 993 } 994 994 995 - const char *default_notes_ref(void) 995 + char *default_notes_ref(struct repository *repo) 996 996 { 997 - const char *notes_ref = NULL; 997 + char *notes_ref = NULL; 998 + 998 999 if (!notes_ref) 999 - notes_ref = getenv(GIT_NOTES_REF_ENVIRONMENT); 1000 + notes_ref = xstrdup_or_null(getenv(GIT_NOTES_REF_ENVIRONMENT)); 1000 1001 if (!notes_ref) 1001 - notes_ref = notes_ref_name; /* value of core.notesRef config */ 1002 + repo_config_get_string(repo, "core.notesref", &notes_ref); 1002 1003 if (!notes_ref) 1003 - notes_ref = GIT_NOTES_DEFAULT_REF; 1004 + notes_ref = xstrdup(GIT_NOTES_DEFAULT_REF); 1004 1005 return notes_ref; 1005 1006 } 1006 1007 ··· 1010 1011 struct object_id oid, object_oid; 1011 1012 unsigned short mode; 1012 1013 struct leaf_node root_tree; 1014 + char *to_free = NULL; 1013 1015 1014 1016 if (!t) 1015 1017 t = &default_notes_tree; 1016 1018 assert(!t->initialized); 1017 1019 1018 1020 if (!notes_ref) 1019 - notes_ref = default_notes_ref(); 1021 + notes_ref = to_free = default_notes_ref(the_repository); 1020 1022 update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref)); 1021 1023 1022 1024 if (!combine_notes) ··· 1033 1035 1034 1036 if (flags & NOTES_INIT_EMPTY || 1035 1037 repo_get_oid_treeish(the_repository, notes_ref, &object_oid)) 1036 - return; 1038 + goto out; 1037 1039 if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(the_repository), notes_ref, &object_oid)) 1038 1040 die("Cannot use notes ref %s", notes_ref); 1039 1041 if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode)) ··· 1043 1045 oidclr(&root_tree.key_oid, the_repository->hash_algo); 1044 1046 oidcpy(&root_tree.val_oid, &oid); 1045 1047 load_subtree(t, &root_tree, t->root, 0); 1048 + 1049 + out: 1050 + free(to_free); 1046 1051 } 1047 1052 1048 1053 struct notes_tree **load_notes_trees(struct string_list *refs, int flags) ··· 1105 1110 1106 1111 if (!opt || opt->use_default_notes > 0 || 1107 1112 (opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) { 1108 - string_list_append(&display_notes_refs, default_notes_ref()); 1113 + string_list_append_nodup(&display_notes_refs, default_notes_ref(the_repository)); 1109 1114 display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT); 1110 1115 if (display_ref_env) { 1111 1116 string_list_add_refs_from_colon_sep(&display_notes_refs,
+2 -1
notes.h
··· 4 4 #include "string-list.h" 5 5 6 6 struct object_id; 7 + struct repository; 7 8 struct strbuf; 8 9 9 10 /* ··· 70 71 * 3. The value of the core.notesRef config variable, if set 71 72 * 4. GIT_NOTES_DEFAULT_REF (i.e. "refs/notes/commits") 72 73 */ 73 - const char *default_notes_ref(void); 74 + char *default_notes_ref(struct repository *repo); 74 75 75 76 /* 76 77 * Flags controlling behaviour of notes tree initialization
+35 -2
object-file.c
··· 419 419 return result; 420 420 } 421 421 422 + int odb_mkstemp(struct strbuf *temp_filename, const char *pattern) 423 + { 424 + int fd; 425 + /* 426 + * we let the umask do its job, don't try to be more 427 + * restrictive except to remove write permission. 428 + */ 429 + int mode = 0444; 430 + git_path_buf(temp_filename, "objects/%s", pattern); 431 + fd = git_mkstemp_mode(temp_filename->buf, mode); 432 + if (0 <= fd) 433 + return fd; 434 + 435 + /* slow path */ 436 + /* some mkstemp implementations erase temp_filename on failure */ 437 + git_path_buf(temp_filename, "objects/%s", pattern); 438 + safe_create_leading_directories(temp_filename->buf); 439 + return xmkstemp_mode(temp_filename->buf, mode); 440 + } 441 + 442 + int odb_pack_keep(const char *name) 443 + { 444 + int fd; 445 + 446 + fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600); 447 + if (0 <= fd) 448 + return fd; 449 + 450 + /* slow path */ 451 + safe_create_leading_directories_const(name); 452 + return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); 453 + } 454 + 422 455 static void fill_loose_path(struct strbuf *buf, const struct object_id *oid) 423 456 { 424 457 int i; ··· 2053 2086 else if (errno == EACCES) 2054 2087 return error(_("insufficient permission for adding " 2055 2088 "an object to repository database %s"), 2056 - get_object_directory()); 2089 + repo_get_object_directory(the_repository)); 2057 2090 else 2058 2091 return error_errno( 2059 2092 _("unable to create temporary file")); ··· 2228 2261 prepare_loose_object_bulk_checkin(); 2229 2262 2230 2263 /* Since oid is not determined, save tmp file to odb path. */ 2231 - strbuf_addf(&filename, "%s/", get_object_directory()); 2264 + strbuf_addf(&filename, "%s/", repo_get_object_directory(the_repository)); 2232 2265 hdrlen = format_object_header(hdr, sizeof(hdr), OBJ_BLOB, len); 2233 2266 2234 2267 /*
+3 -2
object-name.c
··· 20 20 #include "pretty.h" 21 21 #include "object-store-ll.h" 22 22 #include "read-cache-ll.h" 23 + #include "repo-settings.h" 23 24 #include "repository.h" 24 25 #include "setup.h" 25 26 #include "midx.h" ··· 959 960 int fatal = !(flags & GET_OID_QUIETLY); 960 961 961 962 if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) { 962 - if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) { 963 + if (repo_settings_get_warn_ambiguous_refs(r) && warn_on_object_refname_ambiguity) { 963 964 refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref, 0); 964 965 if (refs_found > 0) { 965 966 warning(warn_msg, len, str); ··· 1020 1021 if (!refs_found) 1021 1022 return -1; 1022 1023 1023 - if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) && 1024 + if (repo_settings_get_warn_ambiguous_refs(r) && !(flags & GET_OID_QUIETLY) && 1024 1025 (refs_found > 1 || 1025 1026 !get_short_oid(r, str, len, &tmp_oid, GET_OID_QUIETLY))) 1026 1027 warning(warn_msg, len, str);
+15
object-store-ll.h
··· 232 232 void raw_object_store_clear(struct raw_object_store *o); 233 233 234 234 /* 235 + * Create a temporary file rooted in the object database directory, or 236 + * die on failure. The filename is taken from "pattern", which should have the 237 + * usual "XXXXXX" trailer, and the resulting filename is written into the 238 + * "template" buffer. Returns the open descriptor. 239 + */ 240 + int odb_mkstemp(struct strbuf *temp_filename, const char *pattern); 241 + 242 + /* 243 + * Create a pack .keep file named "name" (which should generally be the output 244 + * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on 245 + * error. 246 + */ 247 + int odb_pack_keep(const char *name); 248 + 249 + /* 235 250 * Put in `buf` the name of the file in the local object database that 236 251 * would be used to store a loose object with the specified oid. 237 252 */
+2 -1
pack-write.c
··· 12 12 #include "pack-objects.h" 13 13 #include "pack-revindex.h" 14 14 #include "path.h" 15 + #include "repository.h" 15 16 #include "strbuf.h" 16 17 17 18 void reset_pack_idx_option(struct pack_idx_option *opts) ··· 473 474 packname[len-1] = 0; 474 475 if (skip_prefix(packname, "keep\t", &name)) 475 476 return xstrfmt("%s/pack/pack-%s.keep", 476 - get_object_directory(), name); 477 + repo_get_object_directory(the_repository), name); 477 478 return NULL; 478 479 } 479 480 if (is_well_formed)
+1 -1
packfile.c
··· 30 30 const char *ext) 31 31 { 32 32 strbuf_reset(buf); 33 - strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(), 33 + strbuf_addf(buf, "%s/pack/pack-%s.%s", repo_get_object_directory(the_repository), 34 34 hash_to_hex(hash), ext); 35 35 return buf->buf; 36 36 }
+5 -2
pager.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "config.h" 3 5 #include "editor.h" ··· 92 94 pager = getenv("GIT_PAGER"); 93 95 if (!pager) { 94 96 if (!pager_program) 95 - read_early_config(core_pager_config, NULL); 97 + read_early_config(the_repository, 98 + core_pager_config, NULL); 96 99 pager = pager_program; 97 100 } 98 101 if (!pager) ··· 298 301 data.want = -1; 299 302 data.value = NULL; 300 303 301 - read_early_config(pager_command_config, &data); 304 + read_early_config(the_repository, pager_command_config, &data); 302 305 303 306 if (data.value) 304 307 pager_program = data.value;
+2
path.c
··· 2 2 * Utilities for paths and pathnames 3 3 */ 4 4 5 + #define USE_THE_REPOSITORY_VARIABLE 6 + 5 7 #include "git-compat-util.h" 6 8 #include "abspath.h" 7 9 #include "environment.h"
+2 -2
pathspec.c
··· 495 495 if (!have_git_dir()) 496 496 die(_("'%s' is outside the directory tree"), 497 497 copyfrom); 498 - hint_path = get_git_work_tree(); 498 + hint_path = repo_get_work_tree(the_repository); 499 499 if (!hint_path) 500 - hint_path = get_git_dir(); 500 + hint_path = repo_get_git_dir(the_repository); 501 501 die(_("%s: '%s' is outside repository at '%s'"), elt, 502 502 copyfrom, absolute_path(hint_path)); 503 503 }
+3
preload-index.c
··· 1 1 /* 2 2 * Copyright (C) 2008 Linus Torvalds 3 3 */ 4 + 5 + #define USE_THE_REPOSITORY_VARIABLE 6 + 4 7 #include "git-compat-util.h" 5 8 #include "pathspec.h" 6 9 #include "dir.h"
+2
prompt.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "parse.h" 3 5 #include "environment.h"
+4 -2
prune-packed.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 - #include "environment.h" 3 4 #include "gettext.h" 4 5 #include "object-store-ll.h" 5 6 #include "packfile.h" 6 7 #include "progress.h" 7 8 #include "prune-packed.h" 9 + #include "repository.h" 8 10 9 11 static struct progress *progress; 10 12 ··· 37 39 if (opts & PRUNE_PACKED_VERBOSE) 38 40 progress = start_delayed_progress(_("Removing duplicate objects"), 256); 39 41 40 - for_each_loose_file_in_objdir(get_object_directory(), 42 + for_each_loose_file_in_objdir(repo_get_object_directory(the_repository), 41 43 prune_object, NULL, prune_subdir, &opts); 42 44 43 45 /* Ensure we show 100% before finishing progress */
+4 -2
read-cache.c
··· 31 31 #include "path.h" 32 32 #include "preload-index.h" 33 33 #include "read-cache.h" 34 + #include "repository.h" 34 35 #include "resolve-undo.h" 35 36 #include "revision.h" 36 37 #include "strbuf.h" ··· 3238 3239 static int clean_shared_index_files(const char *current_hex) 3239 3240 { 3240 3241 struct dirent *de; 3241 - DIR *dir = opendir(get_git_dir()); 3242 + DIR *dir = opendir(repo_get_git_dir(the_repository)); 3242 3243 3243 3244 if (!dir) 3244 - return error_errno(_("unable to open git dir: %s"), get_git_dir()); 3245 + return error_errno(_("unable to open git dir: %s"), 3246 + repo_get_git_dir(the_repository)); 3245 3247 3246 3248 while ((de = readdir(dir)) != NULL) { 3247 3249 const char *sha1_hex;
+2 -1
ref-filter.c
··· 13 13 #include "object-name.h" 14 14 #include "object-store-ll.h" 15 15 #include "oid-array.h" 16 + #include "repo-settings.h" 16 17 #include "repository.h" 17 18 #include "commit.h" 18 19 #include "mailmap.h" ··· 2180 2181 if (atom->option == R_SHORT) 2181 2182 return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository), 2182 2183 refname, 2183 - warn_ambiguous_refs); 2184 + repo_settings_get_warn_ambiguous_refs(the_repository)); 2184 2185 else if (atom->option == R_LSTRIP) 2185 2186 return lstrip_ref_components(refname, atom->lstrip); 2186 2187 else if (atom->option == R_RSTRIP)
+5 -4
refs.c
··· 24 24 #include "submodule.h" 25 25 #include "worktree.h" 26 26 #include "strvec.h" 27 - #include "repository.h" 27 + #include "repo-settings.h" 28 28 #include "setup.h" 29 29 #include "sigchain.h" 30 30 #include "date.h" ··· 730 730 if (r) { 731 731 if (!refs_found++) 732 732 *ref = xstrdup(r); 733 - if (!warn_ambiguous_refs) 733 + if (!repo_settings_get_warn_ambiguous_refs(repo)) 734 734 break; 735 735 } else if ((flag & REF_ISSYMREF) && strcmp(fullref.buf, "HEAD")) { 736 736 warning(_("ignoring dangling symref %s"), fullref.buf); ··· 775 775 if (oid) 776 776 oidcpy(oid, &hash); 777 777 } 778 - if (!warn_ambiguous_refs) 778 + if (!repo_settings_get_warn_ambiguous_refs(r)) 779 779 break; 780 780 } 781 781 strbuf_release(&path); ··· 958 958 return strbuf_detach(&sb, NULL); 959 959 } 960 960 961 - int should_autocreate_reflog(const char *refname) 961 + int should_autocreate_reflog(enum log_refs_config log_all_ref_updates, 962 + const char *refname) 962 963 { 963 964 switch (log_all_ref_updates) { 964 965 case LOG_REFS_ALWAYS:
+3 -1
refs.h
··· 3 3 4 4 #include "commit.h" 5 5 #include "repository.h" 6 + #include "repo-settings.h" 6 7 7 8 struct fsck_options; 8 9 struct object_id; ··· 111 112 112 113 int refs_ref_exists(struct ref_store *refs, const char *refname); 113 114 114 - int should_autocreate_reflog(const char *refname); 115 + int should_autocreate_reflog(enum log_refs_config log_all_ref_updates, 116 + const char *refname); 115 117 116 118 int is_branch(const char *refname); 117 119
+20 -12
refs/files-backend.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "../git-compat-util.h" 4 + #include "../config.h" 2 5 #include "../copy.h" 3 6 #include "../environment.h" 4 7 #include "../gettext.h" ··· 6 9 #include "../hex.h" 7 10 #include "../fsck.h" 8 11 #include "../refs.h" 12 + #include "../repo-settings.h" 9 13 #include "refs-internal.h" 10 14 #include "ref-cache.h" 11 15 #include "packed-backend.h" ··· 72 76 unsigned int store_flags; 73 77 74 78 char *gitcommondir; 79 + enum log_refs_config log_all_ref_updates; 80 + int prefer_symlink_refs; 75 81 76 82 struct ref_cache *loose; 77 83 ··· 104 110 refs->gitcommondir = strbuf_detach(&sb, NULL); 105 111 refs->packed_ref_store = 106 112 packed_ref_store_init(repo, refs->gitcommondir, flags); 113 + refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo); 114 + repo_config_get_bool(repo, "core.prefersymlinkrefs", &refs->prefer_symlink_refs); 107 115 108 116 chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir); 109 117 chdir_notify_reparent("files-backend $GIT_COMMONDIR", ··· 1506 1514 static int commit_ref_update(struct files_ref_store *refs, 1507 1515 struct ref_lock *lock, 1508 1516 const struct object_id *oid, const char *logmsg, 1517 + int flags, 1509 1518 struct strbuf *err); 1510 1519 1511 1520 /* ··· 1649 1658 oidcpy(&lock->old_oid, &orig_oid); 1650 1659 1651 1660 if (write_ref_to_lockfile(refs, lock, &orig_oid, 0, &err) || 1652 - commit_ref_update(refs, lock, &orig_oid, logmsg, &err)) { 1661 + commit_ref_update(refs, lock, &orig_oid, logmsg, 0, &err)) { 1653 1662 error("unable to write current sha1 into %s: %s", newrefname, err.buf); 1654 1663 strbuf_release(&err); 1655 1664 goto rollback; ··· 1666 1675 goto rollbacklog; 1667 1676 } 1668 1677 1669 - flag = log_all_ref_updates; 1670 - log_all_ref_updates = LOG_REFS_NONE; 1671 1678 if (write_ref_to_lockfile(refs, lock, &orig_oid, 0, &err) || 1672 - commit_ref_update(refs, lock, &orig_oid, NULL, &err)) { 1679 + commit_ref_update(refs, lock, &orig_oid, NULL, REF_SKIP_CREATE_REFLOG, &err)) { 1673 1680 error("unable to write current sha1 into %s: %s", oldrefname, err.buf); 1674 1681 strbuf_release(&err); 1675 1682 } 1676 - log_all_ref_updates = flag; 1677 1683 1678 1684 rollbacklog: 1679 1685 if (logmoved && rename(sb_newref.buf, sb_oldref.buf)) ··· 1768 1774 const char *refname, int force_create, 1769 1775 int *logfd, struct strbuf *err) 1770 1776 { 1777 + enum log_refs_config log_refs_cfg = refs->log_all_ref_updates; 1771 1778 struct strbuf logfile_sb = STRBUF_INIT; 1772 1779 char *logfile; 1773 1780 1781 + if (log_refs_cfg == LOG_REFS_UNSET) 1782 + log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL; 1783 + 1774 1784 files_reflog_path(refs, &logfile_sb, refname); 1775 1785 logfile = strbuf_detach(&logfile_sb, NULL); 1776 1786 1777 - if (force_create || should_autocreate_reflog(refname)) { 1787 + if (force_create || should_autocreate_reflog(log_refs_cfg, refname)) { 1778 1788 if (raceproof_create_file(logfile, open_or_create_logfile, logfd)) { 1779 1789 if (errno == ENOENT) 1780 1790 strbuf_addf(err, "unable to create directory for '%s': " ··· 1863 1873 if (flags & REF_SKIP_CREATE_REFLOG) 1864 1874 return 0; 1865 1875 1866 - if (log_all_ref_updates == LOG_REFS_UNSET) 1867 - log_all_ref_updates = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL; 1868 - 1869 1876 result = log_ref_setup(refs, refname, 1870 1877 flags & REF_FORCE_CREATE_REFLOG, 1871 1878 &logfd, err); ··· 1954 1961 static int commit_ref_update(struct files_ref_store *refs, 1955 1962 struct ref_lock *lock, 1956 1963 const struct object_id *oid, const char *logmsg, 1964 + int flags, 1957 1965 struct strbuf *err) 1958 1966 { 1959 1967 files_assert_main_repository(refs, "commit_ref_update"); ··· 1961 1969 clear_loose_ref_cache(refs); 1962 1970 if (files_log_ref_write(refs, lock->ref_name, 1963 1971 &lock->old_oid, oid, 1964 - logmsg, 0, err)) { 1972 + logmsg, flags, err)) { 1965 1973 char *old_msg = strbuf_detach(err, NULL); 1966 1974 strbuf_addf(err, "cannot update the ref '%s': %s", 1967 1975 lock->ref_name, old_msg); ··· 1994 2002 struct strbuf log_err = STRBUF_INIT; 1995 2003 if (files_log_ref_write(refs, "HEAD", 1996 2004 &lock->old_oid, oid, 1997 - logmsg, 0, &log_err)) { 2005 + logmsg, flags, &log_err)) { 1998 2006 error("%s", log_err.buf); 1999 2007 strbuf_release(&log_err); 2000 2008 } ··· 3005 3013 * We try creating a symlink, if that succeeds we continue to the 3006 3014 * next update. If not, we try and create a regular symref. 3007 3015 */ 3008 - if (update->new_target && prefer_symlink_refs) 3016 + if (update->new_target && refs->prefer_symlink_refs) 3009 3017 if (!create_ref_symlink(lock, update->new_target)) 3010 3018 continue; 3011 3019
+13 -9
refs/reftable-backend.c
··· 19 19 #include "../reftable/reftable-record.h" 20 20 #include "../reftable/reftable-error.h" 21 21 #include "../reftable/reftable-iterator.h" 22 + #include "../repo-settings.h" 22 23 #include "../setup.h" 23 24 #include "../strmap.h" 24 25 #include "parse.h" ··· 51 52 struct reftable_write_options write_options; 52 53 53 54 unsigned int store_flags; 55 + enum log_refs_config log_all_ref_updates; 54 56 int err; 55 57 }; 56 58 ··· 156 158 } 157 159 } 158 160 159 - static int should_write_log(struct ref_store *refs, const char *refname) 161 + static int should_write_log(struct reftable_ref_store *refs, const char *refname) 160 162 { 161 - if (log_all_ref_updates == LOG_REFS_UNSET) 162 - log_all_ref_updates = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL; 163 + enum log_refs_config log_refs_cfg = refs->log_all_ref_updates; 164 + if (log_refs_cfg == LOG_REFS_UNSET) 165 + log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL; 163 166 164 - switch (log_all_ref_updates) { 167 + switch (log_refs_cfg) { 165 168 case LOG_REFS_NONE: 166 - return refs_reflog_exists(refs, refname); 169 + return refs_reflog_exists(&refs->base, refname); 167 170 case LOG_REFS_ALWAYS: 168 171 return 1; 169 172 case LOG_REFS_NORMAL: 170 - if (should_autocreate_reflog(refname)) 173 + if (should_autocreate_reflog(log_refs_cfg, refname)) 171 174 return 1; 172 - return refs_reflog_exists(refs, refname); 175 + return refs_reflog_exists(&refs->base, refname); 173 176 default: 174 - BUG("unhandled core.logAllRefUpdates value %d", log_all_ref_updates); 177 + BUG("unhandled core.logAllRefUpdates value %d", log_refs_cfg); 175 178 } 176 179 } 177 180 ··· 276 279 base_ref_store_init(&refs->base, repo, gitdir, &refs_be_reftable); 277 280 strmap_init(&refs->worktree_stacks); 278 281 refs->store_flags = store_flags; 282 + refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo); 279 283 280 284 refs->write_options.hash_id = repo->hash_algo->format_id; 281 285 refs->write_options.default_permissions = calc_shared_perm(0666 & ~mask); ··· 1218 1222 } else if (!(u->flags & REF_SKIP_CREATE_REFLOG) && 1219 1223 (u->flags & REF_HAVE_NEW) && 1220 1224 (u->flags & REF_FORCE_CREATE_REFLOG || 1221 - should_write_log(&arg->refs->base, u->refname))) { 1225 + should_write_log(arg->refs, u->refname))) { 1222 1226 struct reftable_log_record *log; 1223 1227 int create_reflog = 1; 1224 1228
+30 -5
repo-settings.c
··· 1 1 #include "git-compat-util.h" 2 2 #include "config.h" 3 + #include "repo-settings.h" 3 4 #include "repository.h" 4 5 #include "midx.h" 5 6 ··· 19 20 20 21 void prepare_repo_settings(struct repository *r) 21 22 { 23 + const struct repo_settings defaults = REPO_SETTINGS_INIT; 22 24 int experimental; 23 25 int value; 24 26 const char *strval; ··· 28 30 if (!r->gitdir) 29 31 BUG("Cannot add settings for uninitialized repository"); 30 32 31 - if (r->settings.initialized++) 33 + if (r->settings.initialized) 32 34 return; 33 35 34 - /* Defaults */ 35 - r->settings.index_version = -1; 36 - r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP; 37 - r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE; 36 + memcpy(&r->settings, &defaults, sizeof(defaults)); 37 + r->settings.initialized++; 38 38 39 39 /* Booleans config or default, cascades to other settings */ 40 40 repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0); ··· 124 124 */ 125 125 r->settings.command_requires_full_index = 1; 126 126 } 127 + 128 + enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo) 129 + { 130 + const char *value; 131 + 132 + if (!repo_config_get_string_tmp(repo, "core.logallrefupdates", &value)) { 133 + if (value && !strcasecmp(value, "always")) 134 + return LOG_REFS_ALWAYS; 135 + else if (git_config_bool("core.logallrefupdates", value)) 136 + return LOG_REFS_NORMAL; 137 + else 138 + return LOG_REFS_NONE; 139 + } 140 + 141 + return LOG_REFS_UNSET; 142 + } 143 + 144 + int repo_settings_get_warn_ambiguous_refs(struct repository *repo) 145 + { 146 + prepare_repo_settings(repo); 147 + if (repo->settings.warn_ambiguous_refs < 0) 148 + repo_cfg_bool(repo, "core.warnambiguousrefs", 149 + &repo->settings.warn_ambiguous_refs, 1); 150 + return repo->settings.warn_ambiguous_refs; 151 + }
+75
repo-settings.h
··· 1 + #ifndef REPO_SETTINGS_H 2 + #define REPO_SETTINGS_H 3 + 4 + struct fsmonitor_settings; 5 + struct repository; 6 + 7 + enum untracked_cache_setting { 8 + UNTRACKED_CACHE_KEEP, 9 + UNTRACKED_CACHE_REMOVE, 10 + UNTRACKED_CACHE_WRITE, 11 + }; 12 + 13 + enum fetch_negotiation_setting { 14 + FETCH_NEGOTIATION_CONSECUTIVE, 15 + FETCH_NEGOTIATION_SKIPPING, 16 + FETCH_NEGOTIATION_NOOP, 17 + }; 18 + 19 + enum log_refs_config { 20 + LOG_REFS_UNSET = -1, 21 + LOG_REFS_NONE = 0, 22 + LOG_REFS_NORMAL, 23 + LOG_REFS_ALWAYS 24 + }; 25 + 26 + struct repo_settings { 27 + int initialized; 28 + 29 + int core_commit_graph; 30 + int commit_graph_generation_version; 31 + int commit_graph_changed_paths_version; 32 + int gc_write_commit_graph; 33 + int fetch_write_commit_graph; 34 + int command_requires_full_index; 35 + int sparse_index; 36 + int pack_read_reverse_index; 37 + int pack_use_bitmap_boundary_traversal; 38 + int pack_use_multi_pack_reuse; 39 + 40 + /* 41 + * Does this repository have core.useReplaceRefs=true (on by 42 + * default)? This provides a repository-scoped version of this 43 + * config, though it could be disabled process-wide via some Git 44 + * builtins or the --no-replace-objects option. See 45 + * replace_refs_enabled() for more details. 46 + */ 47 + int read_replace_refs; 48 + 49 + struct fsmonitor_settings *fsmonitor; /* lazily loaded */ 50 + 51 + int index_version; 52 + int index_skip_hash; 53 + enum untracked_cache_setting core_untracked_cache; 54 + 55 + int pack_use_sparse; 56 + enum fetch_negotiation_setting fetch_negotiation_algorithm; 57 + 58 + int core_multi_pack_index; 59 + int warn_ambiguous_refs; /* lazily loaded via accessor */ 60 + }; 61 + #define REPO_SETTINGS_INIT { \ 62 + .index_version = -1, \ 63 + .core_untracked_cache = UNTRACKED_CACHE_KEEP, \ 64 + .fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \ 65 + .warn_ambiguous_refs = -1, \ 66 + } 67 + 68 + void prepare_repo_settings(struct repository *r); 69 + 70 + /* Read the value for "core.logAllRefUpdates". */ 71 + enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo); 72 + /* Read the value for "core.warnAmbiguousRefs". */ 73 + int repo_settings_get_warn_ambiguous_refs(struct repository *repo); 74 + 75 + #endif /* REPO_SETTINGS_H */
+40
repository.c
··· 91 91 *out = xstrfmt("%s/%s", base_dir, def_in); 92 92 } 93 93 94 + const char *repo_get_git_dir(struct repository *repo) 95 + { 96 + if (!repo->gitdir) 97 + BUG("repository hasn't been set up"); 98 + return repo->gitdir; 99 + } 100 + 101 + const char *repo_get_common_dir(struct repository *repo) 102 + { 103 + if (!repo->commondir) 104 + BUG("repository hasn't been set up"); 105 + return repo->commondir; 106 + } 107 + 108 + const char *repo_get_object_directory(struct repository *repo) 109 + { 110 + if (!repo->objects->odb) 111 + BUG("repository hasn't been set up"); 112 + return repo->objects->odb->path; 113 + } 114 + 115 + const char *repo_get_index_file(struct repository *repo) 116 + { 117 + if (!repo->index_file) 118 + BUG("repository hasn't been set up"); 119 + return repo->index_file; 120 + } 121 + 122 + const char *repo_get_graft_file(struct repository *repo) 123 + { 124 + if (!repo->graft_file) 125 + BUG("repository hasn't been set up"); 126 + return repo->graft_file; 127 + } 128 + 129 + const char *repo_get_work_tree(struct repository *repo) 130 + { 131 + return repo->worktree; 132 + } 133 + 94 134 static void repo_set_commondir(struct repository *repo, 95 135 const char *commondir) 96 136 {
+8 -50
repository.h
··· 2 2 #define REPOSITORY_H 3 3 4 4 #include "strmap.h" 5 + #include "repo-settings.h" 5 6 6 7 struct config_set; 7 - struct fsmonitor_settings; 8 8 struct git_hash_algo; 9 9 struct index_state; 10 10 struct lock_file; ··· 14 14 struct promisor_remote_config; 15 15 struct remote_state; 16 16 17 - enum untracked_cache_setting { 18 - UNTRACKED_CACHE_KEEP, 19 - UNTRACKED_CACHE_REMOVE, 20 - UNTRACKED_CACHE_WRITE, 21 - }; 22 - 23 - enum fetch_negotiation_setting { 24 - FETCH_NEGOTIATION_CONSECUTIVE, 25 - FETCH_NEGOTIATION_SKIPPING, 26 - FETCH_NEGOTIATION_NOOP, 27 - }; 28 - 29 17 enum ref_storage_format { 30 18 REF_STORAGE_FORMAT_UNKNOWN, 31 19 REF_STORAGE_FORMAT_FILES, 32 20 REF_STORAGE_FORMAT_REFTABLE, 33 - }; 34 - 35 - struct repo_settings { 36 - int initialized; 37 - 38 - int core_commit_graph; 39 - int commit_graph_generation_version; 40 - int commit_graph_changed_paths_version; 41 - int gc_write_commit_graph; 42 - int fetch_write_commit_graph; 43 - int command_requires_full_index; 44 - int sparse_index; 45 - int pack_read_reverse_index; 46 - int pack_use_bitmap_boundary_traversal; 47 - int pack_use_multi_pack_reuse; 48 - 49 - /* 50 - * Does this repository have core.useReplaceRefs=true (on by 51 - * default)? This provides a repository-scoped version of this 52 - * config, though it could be disabled process-wide via some Git 53 - * builtins or the --no-replace-objects option. See 54 - * replace_refs_enabled() for more details. 55 - */ 56 - int read_replace_refs; 57 - 58 - struct fsmonitor_settings *fsmonitor; /* lazily loaded */ 59 - 60 - int index_version; 61 - int index_skip_hash; 62 - enum untracked_cache_setting core_untracked_cache; 63 - 64 - int pack_use_sparse; 65 - enum fetch_negotiation_setting fetch_negotiation_algorithm; 66 - 67 - int core_multi_pack_index; 68 21 }; 69 22 70 23 struct repo_path_cache { ··· 206 159 extern struct repository *the_repository; 207 160 #endif 208 161 162 + const char *repo_get_git_dir(struct repository *repo); 163 + const char *repo_get_common_dir(struct repository *repo); 164 + const char *repo_get_object_directory(struct repository *repo); 165 + const char *repo_get_index_file(struct repository *repo); 166 + const char *repo_get_graft_file(struct repository *repo); 167 + const char *repo_get_work_tree(struct repository *repo); 168 + 209 169 /* 210 170 * Define a custom repository layout. Any field can be NULL, which 211 171 * will default back to the path according to the default layout. ··· 265 225 * The lockfile is always committed or rolled back. 266 226 */ 267 227 void repo_update_index_if_able(struct repository *, struct lock_file *); 268 - 269 - void prepare_repo_settings(struct repository *r); 270 228 271 229 /* 272 230 * Return 1 if upgrade repository format to target_version succeeded,
+2 -2
server-info.c
··· 2 2 3 3 #include "git-compat-util.h" 4 4 #include "dir.h" 5 - #include "environment.h" 6 5 #include "hex.h" 7 6 #include "repository.h" 8 7 #include "refs.h" ··· 342 341 343 342 static int update_info_packs(int force) 344 343 { 345 - char *infofile = mkpathdup("%s/info/packs", get_object_directory()); 344 + char *infofile = mkpathdup("%s/info/packs", 345 + repo_get_object_directory(the_repository)); 346 346 int ret; 347 347 348 348 init_pack_info(infofile, force);
+123 -17
setup.c
··· 7 7 #include "exec-cmd.h" 8 8 #include "gettext.h" 9 9 #include "hex.h" 10 + #include "object-file.h" 10 11 #include "object-name.h" 11 12 #include "refs.h" 13 + #include "replace-object.h" 12 14 #include "repository.h" 13 15 #include "config.h" 14 16 #include "dir.h" 15 17 #include "setup.h" 18 + #include "shallow.h" 16 19 #include "string-list.h" 20 + #include "strvec.h" 17 21 #include "chdir-notify.h" 18 22 #include "path.h" 19 23 #include "quote.h" 24 + #include "tmp-objdir.h" 25 + #include "trace.h" 20 26 #include "trace2.h" 21 27 #include "worktree.h" 22 28 #include "exec-cmd.h" ··· 51 57 size_t wtlen; 52 58 char *path0; 53 59 int off; 54 - const char *work_tree = precompose_string_if_needed(get_git_work_tree()); 60 + const char *work_tree = precompose_string_if_needed(repo_get_work_tree(the_repository)); 55 61 struct strbuf realpath = STRBUF_INIT; 56 62 57 63 if (!work_tree) ··· 147 153 { 148 154 char *r = prefix_path_gently(prefix, len, NULL, path); 149 155 if (!r) { 150 - const char *hint_path = get_git_work_tree(); 156 + const char *hint_path = repo_get_work_tree(the_repository); 151 157 if (!hint_path) 152 - hint_path = get_git_dir(); 158 + hint_path = repo_get_git_dir(the_repository); 153 159 die(_("'%s' is outside repository at '%s'"), path, 154 160 absolute_path(hint_path)); 155 161 } ··· 468 474 int is_inside_git_dir(void) 469 475 { 470 476 if (inside_git_dir < 0) 471 - inside_git_dir = is_inside_dir(get_git_dir()); 477 + inside_git_dir = is_inside_dir(repo_get_git_dir(the_repository)); 472 478 return inside_git_dir; 473 479 } 474 480 475 481 int is_inside_work_tree(void) 476 482 { 477 483 if (inside_work_tree < 0) 478 - inside_work_tree = is_inside_dir(get_git_work_tree()); 484 + inside_work_tree = is_inside_dir(repo_get_work_tree(the_repository)); 479 485 return inside_work_tree; 480 486 } 481 487 ··· 490 496 if (work_tree_config_is_bogus) 491 497 die(_("unable to set up work tree using invalid config")); 492 498 493 - work_tree = get_git_work_tree(); 499 + work_tree = repo_get_work_tree(the_repository); 494 500 if (!work_tree || chdir_notify(work_tree)) 495 501 die(_("this operation must be run in a work tree")); 496 502 ··· 547 553 * Get our worktree; we only protect the current working directory 548 554 * if it's in the worktree. 549 555 */ 550 - worktree = get_git_work_tree(); 556 + worktree = repo_get_work_tree(the_repository); 551 557 if (!worktree) 552 558 goto no_prevention_needed; 553 559 ··· 1062 1068 set_git_work_tree("."); 1063 1069 1064 1070 /* set_git_work_tree() must have been called by now */ 1065 - worktree = get_git_work_tree(); 1071 + worktree = repo_get_work_tree(the_repository); 1066 1072 1067 - /* both get_git_work_tree() and cwd are already normalized */ 1073 + /* both repo_get_work_tree() and cwd are already normalized */ 1068 1074 if (!strcmp(cwd->buf, worktree)) { /* cwd == worktree */ 1069 1075 set_git_dir(gitdirenv, 0); 1070 1076 free(gitfile); ··· 1613 1619 return result; 1614 1620 } 1615 1621 1622 + void setup_git_env(const char *git_dir) 1623 + { 1624 + char *git_replace_ref_base; 1625 + const char *shallow_file; 1626 + const char *replace_ref_base; 1627 + struct set_gitdir_args args = { NULL }; 1628 + struct strvec to_free = STRVEC_INIT; 1629 + 1630 + args.commondir = getenv_safe(&to_free, GIT_COMMON_DIR_ENVIRONMENT); 1631 + args.object_dir = getenv_safe(&to_free, DB_ENVIRONMENT); 1632 + args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT); 1633 + args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT); 1634 + args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT); 1635 + if (getenv(GIT_QUARANTINE_ENVIRONMENT)) { 1636 + args.disable_ref_updates = 1; 1637 + } 1638 + 1639 + repo_set_gitdir(the_repository, git_dir, &args); 1640 + strvec_clear(&to_free); 1641 + 1642 + if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) 1643 + disable_replace_refs(); 1644 + replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT); 1645 + git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base 1646 + : "refs/replace/"); 1647 + update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); 1648 + 1649 + shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); 1650 + if (shallow_file) 1651 + set_alternate_shallow_file(the_repository, shallow_file, 0); 1652 + 1653 + if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) 1654 + fetch_if_missing = 0; 1655 + } 1656 + 1657 + static void set_git_dir_1(const char *path) 1658 + { 1659 + xsetenv(GIT_DIR_ENVIRONMENT, path, 1); 1660 + setup_git_env(path); 1661 + } 1662 + 1663 + static void update_relative_gitdir(const char *name UNUSED, 1664 + const char *old_cwd, 1665 + const char *new_cwd, 1666 + void *data UNUSED) 1667 + { 1668 + char *path = reparent_relative_path(old_cwd, new_cwd, 1669 + repo_get_git_dir(the_repository)); 1670 + struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb(); 1671 + 1672 + trace_printf_key(&trace_setup_key, 1673 + "setup: move $GIT_DIR to '%s'", 1674 + path); 1675 + set_git_dir_1(path); 1676 + if (tmp_objdir) 1677 + tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd); 1678 + free(path); 1679 + } 1680 + 1681 + void set_git_dir(const char *path, int make_realpath) 1682 + { 1683 + struct strbuf realpath = STRBUF_INIT; 1684 + 1685 + if (make_realpath) { 1686 + strbuf_realpath(&realpath, path, 1); 1687 + path = realpath.buf; 1688 + } 1689 + 1690 + set_git_dir_1(path); 1691 + if (!is_absolute_path(path)) 1692 + chdir_notify_register(NULL, update_relative_gitdir, NULL); 1693 + 1694 + strbuf_release(&realpath); 1695 + } 1696 + 1697 + static int git_work_tree_initialized; 1698 + 1699 + /* 1700 + * Note. This works only before you used a work tree. This was added 1701 + * primarily to support git-clone to work in a new repository it just 1702 + * created, and is not meant to flip between different work trees. 1703 + */ 1704 + void set_git_work_tree(const char *new_work_tree) 1705 + { 1706 + if (git_work_tree_initialized) { 1707 + struct strbuf realpath = STRBUF_INIT; 1708 + 1709 + strbuf_realpath(&realpath, new_work_tree, 1); 1710 + new_work_tree = realpath.buf; 1711 + if (strcmp(new_work_tree, the_repository->worktree)) 1712 + die("internal error: work tree has already been set\n" 1713 + "Current worktree: %s\nNew worktree: %s", 1714 + the_repository->worktree, new_work_tree); 1715 + strbuf_release(&realpath); 1716 + return; 1717 + } 1718 + git_work_tree_initialized = 1; 1719 + repo_set_worktree(the_repository, new_work_tree); 1720 + } 1721 + 1616 1722 const char *setup_git_directory_gently(int *nongit_ok) 1617 1723 { 1618 1724 static struct strbuf cwd = STRBUF_INIT; ··· 1836 1942 struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT; 1837 1943 if (!fmt) 1838 1944 fmt = &repo_fmt; 1839 - check_repository_format_gently(get_git_dir(), fmt, NULL); 1945 + check_repository_format_gently(repo_get_git_dir(the_repository), fmt, NULL); 1840 1946 startup_info->have_repository = 1; 1841 1947 repo_set_hash_algo(the_repository, fmt->hash_algo); 1842 1948 repo_set_compat_hash_algo(the_repository, fmt->compat_hash_algo); ··· 2068 2174 goto close_free_return; 2069 2175 } 2070 2176 2071 - strbuf_addstr(&path, get_git_common_dir()); 2177 + strbuf_addstr(&path, repo_get_common_dir(the_repository)); 2072 2178 strbuf_complete(&path, '/'); 2073 2179 copy_templates_1(&path, &template_path, dir); 2074 2180 close_free_return: ··· 2192 2298 char *path; 2193 2299 int reinit; 2194 2300 int filemode; 2195 - const char *work_tree = get_git_work_tree(); 2301 + const char *work_tree = repo_get_work_tree(the_repository); 2196 2302 2197 2303 /* 2198 2304 * First copy the templates -- we might have the default ··· 2224 2330 * shared-repository settings, we would need to fix them up. 2225 2331 */ 2226 2332 if (get_shared_repository()) { 2227 - adjust_shared_perm(get_git_dir()); 2333 + adjust_shared_perm(repo_get_git_dir(the_repository)); 2228 2334 } 2229 2335 2230 2336 initialize_repository_version(fmt->hash_algo, fmt->ref_storage_format, 0); ··· 2248 2354 else { 2249 2355 git_config_set("core.bare", "false"); 2250 2356 /* allow template config file to override the default */ 2251 - if (log_all_ref_updates == LOG_REFS_UNSET) 2357 + if (repo_settings_get_log_all_ref_updates(the_repository) == LOG_REFS_UNSET) 2252 2358 git_config_set("core.logallrefupdates", "true"); 2253 2359 if (needs_work_tree_config(original_git_dir, work_tree)) 2254 2360 git_config_set("core.worktree", work_tree); ··· 2282 2388 struct strbuf path = STRBUF_INIT; 2283 2389 size_t baselen; 2284 2390 2285 - strbuf_addstr(&path, get_object_directory()); 2391 + strbuf_addstr(&path, repo_get_object_directory(the_repository)); 2286 2392 baselen = path.len; 2287 2393 2288 2394 safe_create_dir(path.buf, 1); ··· 2434 2540 die(_("%s already exists"), real_git_dir); 2435 2541 2436 2542 set_git_dir(real_git_dir, 1); 2437 - git_dir = get_git_dir(); 2543 + git_dir = repo_get_git_dir(the_repository); 2438 2544 separate_git_dir(git_dir, original_git_dir); 2439 2545 } 2440 2546 else { 2441 2547 set_git_dir(git_dir, 1); 2442 - git_dir = get_git_dir(); 2548 + git_dir = repo_get_git_dir(the_repository); 2443 2549 } 2444 2550 startup_info->have_repository = 1; 2445 2551
+4 -1
setup.h
··· 94 94 return 0; 95 95 } 96 96 97 + void set_git_dir(const char *path, int make_realpath); 98 + void set_git_work_tree(const char *tree); 99 + 97 100 const char *setup_git_directory_gently(int *); 98 101 const char *setup_git_directory(void); 99 102 char *prefix_path(const char *prefix, int len, const char *path); ··· 176 179 struct strbuf *err); 177 180 178 181 /* 179 - * Check the repository format version in the path found in get_git_dir(), 182 + * Check the repository format version in the path found in repo_get_git_dir(the_repository), 180 183 * and die if it is a version we don't understand. Generally one would 181 184 * set_git_dir() before calling this, and use it only for "are we in a valid 182 185 * repo?".
+2
sparse-index.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "environment.h" 3 5 #include "gettext.h"
+2
statinfo.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "environment.h" 3 5 #include "statinfo.h"
+1 -1
submodule.c
··· 2464 2464 } else { 2465 2465 /* Is it already absorbed into the superprojects git dir? */ 2466 2466 char *real_sub_git_dir = real_pathdup(sub_git_dir, 1); 2467 - char *real_common_git_dir = real_pathdup(get_git_common_dir(), 1); 2467 + char *real_common_git_dir = real_pathdup(repo_get_common_dir(the_repository), 1); 2468 2468 2469 2469 if (!starts_with(real_sub_git_dir, real_common_git_dir)) 2470 2470 relocate_single_git_dir_into_superproject(path, super_prefix);
+2 -1
t/helper/test-config.c
··· 96 96 struct config_set cs; 97 97 98 98 if (argc == 3 && !strcmp(argv[1], "read_early_config")) { 99 - read_early_config(early_config_cb, (void *)argv[2]); 99 + read_early_config(the_repository, early_config_cb, 100 + (void *)argv[2]); 100 101 return 0; 101 102 } 102 103
+2
t/helper/test-path-utils.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "test-tool.h" 2 4 #include "abspath.h" 3 5 #include "environment.h"
+5 -3
tmp-objdir.c
··· 13 13 #include "strvec.h" 14 14 #include "quote.h" 15 15 #include "object-store-ll.h" 16 + #include "repository.h" 16 17 17 18 struct tmp_objdir { 18 19 struct strbuf path; ··· 132 133 * can recognize any stale objdirs left behind by a crash and delete 133 134 * them. 134 135 */ 135 - strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX", get_object_directory(), prefix); 136 + strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX", 137 + repo_get_object_directory(the_repository), prefix); 136 138 137 139 if (!mkdtemp(t->path.buf)) { 138 140 /* free, not destroy, as we never touched the filesystem */ ··· 152 154 } 153 155 154 156 env_append(&t->env, ALTERNATE_DB_ENVIRONMENT, 155 - absolute_path(get_object_directory())); 157 + absolute_path(repo_get_object_directory(the_repository))); 156 158 env_replace(&t->env, DB_ENVIRONMENT, absolute_path(t->path.buf)); 157 159 env_replace(&t->env, GIT_QUARANTINE_ENVIRONMENT, 158 160 absolute_path(t->path.buf)); ··· 267 269 } 268 270 269 271 strbuf_addbuf(&src, &t->path); 270 - strbuf_addstr(&dst, get_object_directory()); 272 + strbuf_addstr(&dst, repo_get_object_directory(the_repository)); 271 273 272 274 ret = migrate_paths(&src, &dst); 273 275
+6 -4
trace.c
··· 21 21 * along with this program; if not, see <https://www.gnu.org/licenses/>. 22 22 */ 23 23 24 + #define USE_THE_REPOSITORY_VARIABLE 25 + 24 26 #include "git-compat-util.h" 25 27 #include "abspath.h" 26 - #include "environment.h" 28 + #include "repository.h" 27 29 #include "quote.h" 28 30 #include "setup.h" 29 31 #include "trace.h" ··· 305 307 306 308 cwd = xgetcwd(); 307 309 308 - if (!(git_work_tree = get_git_work_tree())) 310 + if (!(git_work_tree = repo_get_work_tree(the_repository))) 309 311 git_work_tree = "(null)"; 310 312 311 313 if (!startup_info->prefix) 312 314 prefix = "(null)"; 313 315 314 - trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(get_git_dir())); 315 - trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(get_git_common_dir())); 316 + trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(repo_get_git_dir(the_repository))); 317 + trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(repo_get_common_dir(the_repository))); 316 318 trace_printf_key(&trace_setup_key, "setup: worktree: %s\n", quote_crnl(git_work_tree)); 317 319 trace_printf_key(&trace_setup_key, "setup: cwd: %s\n", quote_crnl(cwd)); 318 320 trace_printf_key(&trace_setup_key, "setup: prefix: %s\n", quote_crnl(prefix));
+3 -1
trace2/tr2_cfg.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "config.h" 3 5 #include "strbuf.h" ··· 124 126 struct tr2_cfg_data data = { file, line }; 125 127 126 128 if (tr2_cfg_load_patterns() > 0) 127 - read_early_config(tr2_cfg_cb, &data); 129 + read_early_config(the_repository, tr2_cfg_cb, &data); 128 130 } 129 131 130 132 void tr2_list_env_vars_fl(const char *file, int line)
+1 -1
transport-helper.c
··· 143 143 144 144 if (have_git_dir()) 145 145 strvec_pushf(&helper->env, "%s=%s", 146 - GIT_DIR_ENVIRONMENT, get_git_dir()); 146 + GIT_DIR_ENVIRONMENT, repo_get_git_dir(the_repository)); 147 147 148 148 helper->trace2_child_class = helper->args.v[0]; /* "remote-<name>" */ 149 149
+3
tree-diff.c
··· 1 1 /* 2 2 * Helper functions for tree diff generation 3 3 */ 4 + 5 + #define USE_THE_REPOSITORY_VARIABLE 6 + 4 7 #include "git-compat-util.h" 5 8 #include "diff.h" 6 9 #include "diffcore.h"
+2
userdiff.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "config.h" 3 5 #include "userdiff.h"
+6 -6
worktree.c
··· 57 57 58 58 static int is_current_worktree(struct worktree *wt) 59 59 { 60 - char *git_dir = absolute_pathdup(get_git_dir()); 60 + char *git_dir = absolute_pathdup(repo_get_git_dir(the_repository)); 61 61 const char *wt_git_dir = get_worktree_git_dir(wt); 62 62 int is_current = !fspathcmp(git_dir, absolute_path(wt_git_dir)); 63 63 free(git_dir); ··· 72 72 struct worktree *worktree = NULL; 73 73 struct strbuf worktree_path = STRBUF_INIT; 74 74 75 - strbuf_add_real_path(&worktree_path, get_git_common_dir()); 75 + strbuf_add_real_path(&worktree_path, repo_get_common_dir(the_repository)); 76 76 strbuf_strip_suffix(&worktree_path, "/.git"); 77 77 78 78 CALLOC_ARRAY(worktree, 1); ··· 143 143 144 144 list[counter++] = get_main_worktree(skip_reading_head); 145 145 146 - strbuf_addf(&path, "%s/worktrees", get_git_common_dir()); 146 + strbuf_addf(&path, "%s/worktrees", repo_get_common_dir(the_repository)); 147 147 dir = opendir(path.buf); 148 148 strbuf_release(&path); 149 149 if (dir) { ··· 171 171 const char *get_worktree_git_dir(const struct worktree *wt) 172 172 { 173 173 if (!wt) 174 - return get_git_dir(); 174 + return repo_get_git_dir(the_repository); 175 175 else if (!wt->id) 176 - return get_git_common_dir(); 176 + return repo_get_common_dir(the_repository); 177 177 else 178 178 return git_common_path("worktrees/%s", wt->id); 179 179 } ··· 626 626 627 627 strbuf_add_real_path(&target, path); 628 628 strbuf_strip_suffix(&target, "/.git"); 629 - strbuf_add_real_path(&maindir, get_git_common_dir()); 629 + strbuf_add_real_path(&maindir, repo_get_common_dir(the_repository)); 630 630 strbuf_strip_suffix(&maindir, "/.git"); 631 631 cmp = fspathcmp(maindir.buf, target.buf); 632 632
+2 -1
wt-status.c
··· 16 16 #include "revision.h" 17 17 #include "diffcore.h" 18 18 #include "quote.h" 19 + #include "repository.h" 19 20 #include "run-command.h" 20 21 #include "strvec.h" 21 22 #include "remote.h" ··· 152 153 "HEAD", 0, NULL, NULL); 153 154 s->reference = "HEAD"; 154 155 s->fp = stdout; 155 - s->index_file = get_index_file(); 156 + s->index_file = repo_get_index_file(the_repository); 156 157 s->change.strdup_strings = 1; 157 158 s->untracked.strdup_strings = 1; 158 159 s->ignored.strdup_strings = 1;