1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 04:49:43 +01:00

environment: stop storing "core.notesRef" globally

Stop storing the "core.notesRef" config value globally. Instead,
retrieve the value in `default_notes_ref()`. The code is never called in
a hot loop anyway, so doing this on every invocation should be perfectly
fine.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt 2024-09-12 13:30:26 +02:00 committed by Junio C Hamano
parent 11dbb4ace3
commit 1e7e4a111f
6 changed files with 29 additions and 28 deletions

View file

@ -897,6 +897,7 @@ static int merge(int argc, const char **argv, const char *prefix)
1, PARSE_OPT_NONEG), 1, PARSE_OPT_NONEG),
OPT_END() OPT_END()
}; };
char *notes_ref;
argc = parse_options(argc, argv, prefix, options, argc = parse_options(argc, argv, prefix, options,
git_notes_merge_usage, 0); git_notes_merge_usage, 0);
@ -924,7 +925,8 @@ static int merge(int argc, const char **argv, const char *prefix)
if (do_commit) if (do_commit)
return merge_commit(&o); return merge_commit(&o);
o.local_ref = default_notes_ref(); notes_ref = default_notes_ref(the_repository);
o.local_ref = notes_ref;
strbuf_addstr(&remote_ref, argv[0]); strbuf_addstr(&remote_ref, argv[0]);
expand_loose_notes_ref(&remote_ref); expand_loose_notes_ref(&remote_ref);
o.remote_ref = remote_ref.buf; o.remote_ref = remote_ref.buf;
@ -953,7 +955,7 @@ static int merge(int argc, const char **argv, const char *prefix)
} }
strbuf_addf(&msg, "notes: Merged notes from %s into %s", strbuf_addf(&msg, "notes: Merged notes from %s into %s",
remote_ref.buf, default_notes_ref()); remote_ref.buf, notes_ref);
strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */ strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */
result = notes_merge(&o, t, &result_oid); result = notes_merge(&o, t, &result_oid);
@ -961,7 +963,7 @@ static int merge(int argc, const char **argv, const char *prefix)
if (result >= 0) /* Merge resulted (trivially) in result_oid */ if (result >= 0) /* Merge resulted (trivially) in result_oid */
/* Update default notes ref with new commit */ /* Update default notes ref with new commit */
refs_update_ref(get_main_ref_store(the_repository), msg.buf, refs_update_ref(get_main_ref_store(the_repository), msg.buf,
default_notes_ref(), &result_oid, NULL, 0, notes_ref, &result_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR); UPDATE_REFS_DIE_ON_ERR);
else { /* Merge has unresolved conflicts */ else { /* Merge has unresolved conflicts */
struct worktree **worktrees; struct worktree **worktrees;
@ -973,14 +975,14 @@ static int merge(int argc, const char **argv, const char *prefix)
/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */ /* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
worktrees = get_worktrees(); worktrees = get_worktrees();
wt = find_shared_symref(worktrees, "NOTES_MERGE_REF", wt = find_shared_symref(worktrees, "NOTES_MERGE_REF",
default_notes_ref()); notes_ref);
if (wt) if (wt)
die(_("a notes merge into %s is already in-progress at %s"), die(_("a notes merge into %s is already in-progress at %s"),
default_notes_ref(), wt->path); notes_ref, wt->path);
free_worktrees(worktrees); free_worktrees(worktrees);
if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", default_notes_ref(), NULL)) if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", notes_ref, NULL))
die(_("failed to store link to current notes ref (%s)"), die(_("failed to store link to current notes ref (%s)"),
default_notes_ref()); notes_ref);
fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s " fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s "
"and commit the result with 'git notes merge --commit', " "and commit the result with 'git notes merge --commit', "
"or abort the merge with 'git notes merge --abort'.\n"), "or abort the merge with 'git notes merge --abort'.\n"),
@ -988,6 +990,7 @@ static int merge(int argc, const char **argv, const char *prefix)
} }
free_notes(t); free_notes(t);
free(notes_ref);
strbuf_release(&remote_ref); strbuf_release(&remote_ref);
strbuf_release(&msg); strbuf_release(&msg);
return result < 0; /* return non-zero on conflicts */ return result < 0; /* return non-zero on conflicts */
@ -1084,6 +1087,7 @@ static int prune(int argc, const char **argv, const char *prefix)
static int get_ref(int argc, const char **argv, const char *prefix) static int get_ref(int argc, const char **argv, const char *prefix)
{ {
struct option options[] = { OPT_END() }; struct option options[] = { OPT_END() };
char *notes_ref;
argc = parse_options(argc, argv, prefix, options, argc = parse_options(argc, argv, prefix, options,
git_notes_get_ref_usage, 0); git_notes_get_ref_usage, 0);
@ -1092,7 +1096,9 @@ static int get_ref(int argc, const char **argv, const char *prefix)
usage_with_options(git_notes_get_ref_usage, options); usage_with_options(git_notes_get_ref_usage, options);
} }
puts(default_notes_ref()); notes_ref = default_notes_ref(the_repository);
puts(notes_ref);
free(notes_ref);
return 0; return 0;
} }

View file

@ -1555,14 +1555,6 @@ static int git_default_core_config(const char *var, const char *value,
return git_config_string(&check_roundtrip_encoding, var, value); return git_config_string(&check_roundtrip_encoding, var, value);
} }
if (!strcmp(var, "core.notesref")) {
if (!value)
return config_error_nonbool(var);
free(notes_ref_name);
notes_ref_name = xstrdup(value);
return 0;
}
if (!strcmp(var, "core.editor")) { if (!strcmp(var, "core.editor")) {
FREE_AND_NULL(editor_program); FREE_AND_NULL(editor_program);
return git_config_string(&editor_program, var, value); return git_config_string(&editor_program, var, value);

View file

@ -67,7 +67,6 @@ enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
#define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
#endif #endif
enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
char *notes_ref_name;
int grafts_keep_true_parents; int grafts_keep_true_parents;
int core_apply_sparse_checkout; int core_apply_sparse_checkout;
int core_sparse_checkout_cone; int core_sparse_checkout_cone;

View file

@ -203,8 +203,6 @@ enum object_creation_mode {
}; };
extern enum object_creation_mode object_creation_mode; extern enum object_creation_mode object_creation_mode;
extern char *notes_ref_name;
extern int grafts_keep_true_parents; extern int grafts_keep_true_parents;
extern int repository_format_precious_objects; extern int repository_format_precious_objects;

21
notes.c
View file

@ -992,15 +992,16 @@ static int notes_display_config(const char *k, const char *v,
return 0; 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) if (!notes_ref)
notes_ref = getenv(GIT_NOTES_REF_ENVIRONMENT); notes_ref = xstrdup_or_null(getenv(GIT_NOTES_REF_ENVIRONMENT));
if (!notes_ref) 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) if (!notes_ref)
notes_ref = GIT_NOTES_DEFAULT_REF; notes_ref = xstrdup(GIT_NOTES_DEFAULT_REF);
return notes_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; struct object_id oid, object_oid;
unsigned short mode; unsigned short mode;
struct leaf_node root_tree; struct leaf_node root_tree;
char *to_free = NULL;
if (!t) if (!t)
t = &default_notes_tree; t = &default_notes_tree;
assert(!t->initialized); assert(!t->initialized);
if (!notes_ref) 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)); update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref));
if (!combine_notes) if (!combine_notes)
@ -1033,7 +1035,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
if (flags & NOTES_INIT_EMPTY || if (flags & NOTES_INIT_EMPTY ||
repo_get_oid_treeish(the_repository, notes_ref, &object_oid)) 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)) 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); die("Cannot use notes ref %s", notes_ref);
if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode)) 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); oidclr(&root_tree.key_oid, the_repository->hash_algo);
oidcpy(&root_tree.val_oid, &oid); oidcpy(&root_tree.val_oid, &oid);
load_subtree(t, &root_tree, t->root, 0); load_subtree(t, &root_tree, t->root, 0);
out:
free(to_free);
} }
struct notes_tree **load_notes_trees(struct string_list *refs, int flags) 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 || if (!opt || opt->use_default_notes > 0 ||
(opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) { (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); display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
if (display_ref_env) { if (display_ref_env) {
string_list_add_refs_from_colon_sep(&display_notes_refs, string_list_add_refs_from_colon_sep(&display_notes_refs,

View file

@ -4,6 +4,7 @@
#include "string-list.h" #include "string-list.h"
struct object_id; struct object_id;
struct repository;
struct strbuf; struct strbuf;
/* /*
@ -70,7 +71,7 @@ extern struct notes_tree {
* 3. The value of the core.notesRef config variable, if set * 3. The value of the core.notesRef config variable, if set
* 4. GIT_NOTES_DEFAULT_REF (i.e. "refs/notes/commits") * 4. GIT_NOTES_DEFAULT_REF (i.e. "refs/notes/commits")
*/ */
const char *default_notes_ref(void); char *default_notes_ref(struct repository *repo);
/* /*
* Flags controlling behaviour of notes tree initialization * Flags controlling behaviour of notes tree initialization