Git fork

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>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
1e7e4a11 11dbb4ac

+29 -28
+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
-8
config.c
··· 1555 1555 return git_config_string(&check_roundtrip_encoding, var, value); 1556 1556 } 1557 1557 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 - 1566 1558 if (!strcmp(var, "core.editor")) { 1567 1559 FREE_AND_NULL(editor_program); 1568 1560 return git_config_string(&editor_program, var, value);
-1
environment.c
··· 67 67 #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS 68 68 #endif 69 69 enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; 70 - char *notes_ref_name; 71 70 int grafts_keep_true_parents; 72 71 int core_apply_sparse_checkout; 73 72 int core_sparse_checkout_cone;
-2
environment.h
··· 203 203 }; 204 204 extern enum object_creation_mode object_creation_mode; 205 205 206 - extern char *notes_ref_name; 207 - 208 206 extern int grafts_keep_true_parents; 209 207 210 208 extern int repository_format_precious_objects;
+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