Skip to content

Commit 1e7e4a1

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 11dbb4a commit 1e7e4a1

File tree

6 files changed

+29
-28
lines changed

6 files changed

+29
-28
lines changed

builtin/notes.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ static int merge(int argc, const char **argv, const char *prefix)
897897
1, PARSE_OPT_NONEG),
898898
OPT_END()
899899
};
900+
char *notes_ref;
900901

901902
argc = parse_options(argc, argv, prefix, options,
902903
git_notes_merge_usage, 0);
@@ -924,7 +925,8 @@ static int merge(int argc, const char **argv, const char *prefix)
924925
if (do_commit)
925926
return merge_commit(&o);
926927

927-
o.local_ref = default_notes_ref();
928+
notes_ref = default_notes_ref(the_repository);
929+
o.local_ref = notes_ref;
928930
strbuf_addstr(&remote_ref, argv[0]);
929931
expand_loose_notes_ref(&remote_ref);
930932
o.remote_ref = remote_ref.buf;
@@ -953,15 +955,15 @@ static int merge(int argc, const char **argv, const char *prefix)
953955
}
954956

955957
strbuf_addf(&msg, "notes: Merged notes from %s into %s",
956-
remote_ref.buf, default_notes_ref());
958+
remote_ref.buf, notes_ref);
957959
strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */
958960

959961
result = notes_merge(&o, t, &result_oid);
960962

961963
if (result >= 0) /* Merge resulted (trivially) in result_oid */
962964
/* Update default notes ref with new commit */
963965
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,
965967
UPDATE_REFS_DIE_ON_ERR);
966968
else { /* Merge has unresolved conflicts */
967969
struct worktree **worktrees;
@@ -973,21 +975,22 @@ static int merge(int argc, const char **argv, const char *prefix)
973975
/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
974976
worktrees = get_worktrees();
975977
wt = find_shared_symref(worktrees, "NOTES_MERGE_REF",
976-
default_notes_ref());
978+
notes_ref);
977979
if (wt)
978980
die(_("a notes merge into %s is already in-progress at %s"),
979-
default_notes_ref(), wt->path);
981+
notes_ref, wt->path);
980982
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))
982984
die(_("failed to store link to current notes ref (%s)"),
983-
default_notes_ref());
985+
notes_ref);
984986
fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s "
985987
"and commit the result with 'git notes merge --commit', "
986988
"or abort the merge with 'git notes merge --abort'.\n"),
987989
git_path(NOTES_MERGE_WORKTREE));
988990
}
989991

990992
free_notes(t);
993+
free(notes_ref);
991994
strbuf_release(&remote_ref);
992995
strbuf_release(&msg);
993996
return result < 0; /* return non-zero on conflicts */
@@ -1084,6 +1087,7 @@ static int prune(int argc, const char **argv, const char *prefix)
10841087
static int get_ref(int argc, const char **argv, const char *prefix)
10851088
{
10861089
struct option options[] = { OPT_END() };
1090+
char *notes_ref;
10871091
argc = parse_options(argc, argv, prefix, options,
10881092
git_notes_get_ref_usage, 0);
10891093

@@ -1092,7 +1096,9 @@ static int get_ref(int argc, const char **argv, const char *prefix)
10921096
usage_with_options(git_notes_get_ref_usage, options);
10931097
}
10941098

1095-
puts(default_notes_ref());
1099+
notes_ref = default_notes_ref(the_repository);
1100+
puts(notes_ref);
1101+
free(notes_ref);
10961102
return 0;
10971103
}
10981104

config.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,14 +1555,6 @@ static int git_default_core_config(const char *var, const char *value,
15551555
return git_config_string(&check_roundtrip_encoding, var, value);
15561556
}
15571557

1558-
if (!strcmp(var, "core.notesref")) {
1559-
if (!value)
1560-
return config_error_nonbool(var);
1561-
free(notes_ref_name);
1562-
notes_ref_name = xstrdup(value);
1563-
return 0;
1564-
}
1565-
15661558
if (!strcmp(var, "core.editor")) {
15671559
FREE_AND_NULL(editor_program);
15681560
return git_config_string(&editor_program, var, value);

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
6767
#define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
6868
#endif
6969
enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
70-
char *notes_ref_name;
7170
int grafts_keep_true_parents;
7271
int core_apply_sparse_checkout;
7372
int core_sparse_checkout_cone;

environment.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ enum object_creation_mode {
203203
};
204204
extern enum object_creation_mode object_creation_mode;
205205

206-
extern char *notes_ref_name;
207-
208206
extern int grafts_keep_true_parents;
209207

210208
extern int repository_format_precious_objects;

notes.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -992,15 +992,16 @@ static int notes_display_config(const char *k, const char *v,
992992
return 0;
993993
}
994994

995-
const char *default_notes_ref(void)
995+
char *default_notes_ref(struct repository *repo)
996996
{
997-
const char *notes_ref = NULL;
997+
char *notes_ref = NULL;
998+
998999
if (!notes_ref)
999-
notes_ref = getenv(GIT_NOTES_REF_ENVIRONMENT);
1000+
notes_ref = xstrdup_or_null(getenv(GIT_NOTES_REF_ENVIRONMENT));
10001001
if (!notes_ref)
1001-
notes_ref = notes_ref_name; /* value of core.notesRef config */
1002+
repo_config_get_string(repo, "core.notesref", &notes_ref);
10021003
if (!notes_ref)
1003-
notes_ref = GIT_NOTES_DEFAULT_REF;
1004+
notes_ref = xstrdup(GIT_NOTES_DEFAULT_REF);
10041005
return notes_ref;
10051006
}
10061007

@@ -1010,13 +1011,14 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
10101011
struct object_id oid, object_oid;
10111012
unsigned short mode;
10121013
struct leaf_node root_tree;
1014+
char *to_free = NULL;
10131015

10141016
if (!t)
10151017
t = &default_notes_tree;
10161018
assert(!t->initialized);
10171019

10181020
if (!notes_ref)
1019-
notes_ref = default_notes_ref();
1021+
notes_ref = to_free = default_notes_ref(the_repository);
10201022
update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref));
10211023

10221024
if (!combine_notes)
@@ -1033,7 +1035,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
10331035

10341036
if (flags & NOTES_INIT_EMPTY ||
10351037
repo_get_oid_treeish(the_repository, notes_ref, &object_oid))
1036-
return;
1038+
goto out;
10371039
if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(the_repository), notes_ref, &object_oid))
10381040
die("Cannot use notes ref %s", notes_ref);
10391041
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,
10431045
oidclr(&root_tree.key_oid, the_repository->hash_algo);
10441046
oidcpy(&root_tree.val_oid, &oid);
10451047
load_subtree(t, &root_tree, t->root, 0);
1048+
1049+
out:
1050+
free(to_free);
10461051
}
10471052

10481053
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)
11051110

11061111
if (!opt || opt->use_default_notes > 0 ||
11071112
(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));
11091114
display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
11101115
if (display_ref_env) {
11111116
string_list_add_refs_from_colon_sep(&display_notes_refs,

notes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "string-list.h"
55

66
struct object_id;
7+
struct repository;
78
struct strbuf;
89

910
/*
@@ -70,7 +71,7 @@ extern struct notes_tree {
7071
* 3. The value of the core.notesRef config variable, if set
7172
* 4. GIT_NOTES_DEFAULT_REF (i.e. "refs/notes/commits")
7273
*/
73-
const char *default_notes_ref(void);
74+
char *default_notes_ref(struct repository *repo);
7475

7576
/*
7677
* Flags controlling behaviour of notes tree initialization

0 commit comments

Comments
 (0)