summaryrefslogtreecommitdiff
path: root/builtin/notes.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-09-12 13:30:26 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-12 10:15:44 -0700
commit1e7e4a111f986088abc9194d55349419e5c110c3 (patch)
tree997f95b3783707241bf2a11ee4f9b72f1c6cb261 /builtin/notes.c
parent11dbb4ace3ac428574fadf6f7895f56aba9dca81 (diff)
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>
Diffstat (limited to 'builtin/notes.c')
-rw-r--r--builtin/notes.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/builtin/notes.c b/builtin/notes.c
index 04f9dfb7fb..5d594a0724 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -897,6 +897,7 @@ static int merge(int argc, const char **argv, const char *prefix)
1, PARSE_OPT_NONEG),
OPT_END()
};
+ char *notes_ref;
argc = parse_options(argc, argv, prefix, options,
git_notes_merge_usage, 0);
@@ -924,7 +925,8 @@ static int merge(int argc, const char **argv, const char *prefix)
if (do_commit)
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]);
expand_loose_notes_ref(&remote_ref);
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",
- remote_ref.buf, default_notes_ref());
+ remote_ref.buf, notes_ref);
strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */
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 */
/* Update default notes ref with new commit */
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);
else { /* Merge has unresolved conflicts */
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 */
worktrees = get_worktrees();
wt = find_shared_symref(worktrees, "NOTES_MERGE_REF",
- default_notes_ref());
+ notes_ref);
if (wt)
die(_("a notes merge into %s is already in-progress at %s"),
- default_notes_ref(), wt->path);
+ notes_ref, wt->path);
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)"),
- default_notes_ref());
+ notes_ref);
fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s "
"and commit the result with 'git notes merge --commit', "
"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_ref);
strbuf_release(&remote_ref);
strbuf_release(&msg);
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)
{
struct option options[] = { OPT_END() };
+ char *notes_ref;
argc = parse_options(argc, argv, prefix, options,
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);
}
- puts(default_notes_ref());
+ notes_ref = default_notes_ref(the_repository);
+ puts(notes_ref);
+ free(notes_ref);
return 0;
}