aboutsummaryrefslogtreecommitdiffstats
path: root/notes.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-09-23 10:35:04 -0700
committerJunio C Hamano <gitster@pobox.com>2024-09-23 10:35:05 -0700
commit3eb66799593f3676d85ca66f9e3192a7db603805 (patch)
treea381a41f1696931f064f41ae256f284fd70fc221 /notes.c
parentSync with Git 2.46.2 (diff)
parentenvironment: stop storing "core.notesRef" globally (diff)
downloadgit-3eb66799593f3676d85ca66f9e3192a7db603805.tar.gz
git-3eb66799593f3676d85ca66f9e3192a7db603805.zip
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 ...
Diffstat (limited to 'notes.c')
-rw-r--r--notes.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/notes.c b/notes.c
index da42df282d..f4f18daf07 100644
--- a/notes.c
+++ b/notes.c
@@ -992,15 +992,16 @@ static int notes_display_config(const char *k, const char *v,
return 0;
}
-const char *default_notes_ref(void)
+char *default_notes_ref(struct repository *repo)
{
- const char *notes_ref = NULL;
+ char *notes_ref = NULL;
+
if (!notes_ref)
- notes_ref = getenv(GIT_NOTES_REF_ENVIRONMENT);
+ notes_ref = xstrdup_or_null(getenv(GIT_NOTES_REF_ENVIRONMENT));
if (!notes_ref)
- notes_ref = notes_ref_name; /* value of core.notesRef config */
+ repo_config_get_string(repo, "core.notesref", &notes_ref);
if (!notes_ref)
- notes_ref = GIT_NOTES_DEFAULT_REF;
+ notes_ref = xstrdup(GIT_NOTES_DEFAULT_REF);
return notes_ref;
}
@@ -1010,13 +1011,14 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
struct object_id oid, object_oid;
unsigned short mode;
struct leaf_node root_tree;
+ char *to_free = NULL;
if (!t)
t = &default_notes_tree;
assert(!t->initialized);
if (!notes_ref)
- notes_ref = default_notes_ref();
+ notes_ref = to_free = default_notes_ref(the_repository);
update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref));
if (!combine_notes)
@@ -1033,7 +1035,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
if (flags & NOTES_INIT_EMPTY ||
repo_get_oid_treeish(the_repository, notes_ref, &object_oid))
- return;
+ goto out;
if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(the_repository), notes_ref, &object_oid))
die("Cannot use notes ref %s", notes_ref);
if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode))
@@ -1043,6 +1045,9 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
oidclr(&root_tree.key_oid, the_repository->hash_algo);
oidcpy(&root_tree.val_oid, &oid);
load_subtree(t, &root_tree, t->root, 0);
+
+out:
+ free(to_free);
}
struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
@@ -1105,7 +1110,7 @@ void load_display_notes(struct display_notes_opt *opt)
if (!opt || opt->use_default_notes > 0 ||
(opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) {
- string_list_append(&display_notes_refs, default_notes_ref());
+ string_list_append_nodup(&display_notes_refs, default_notes_ref(the_repository));
display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
if (display_ref_env) {
string_list_add_refs_from_colon_sep(&display_notes_refs,