Skip to content

Commit 97e61e0

Browse files
derrickstoleegitster
authored andcommitted
refs: use ref_namespaces for replace refs base
The git_replace_ref_base global is used to store the value of the GIT_REPLACE_REF_BASE environment variable or the default of "refs/replace/". This is initialized within setup_git_env(). The ref_namespaces array is a new centralized location for information such as the ref namespace used for replace refs. Instead of having this namespace stored in two places, use the ref_namespaces array instead. For simplicity, create a local git_replace_ref_base variable wherever the global was previously used. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b9342b3 commit 97e61e0

File tree

5 files changed

+6
-3
lines changed

5 files changed

+6
-3
lines changed

builtin/replace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
106106
size_t base_len;
107107
int had_error = 0;
108108
struct object_id oid;
109+
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
109110

110111
strbuf_addstr(&ref, git_replace_ref_base);
111112
base_len = ref.len;
@@ -147,6 +148,8 @@ static int check_ref_valid(struct object_id *object,
147148
struct strbuf *ref,
148149
int force)
149150
{
151+
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
152+
150153
strbuf_reset(ref);
151154
strbuf_addf(ref, "%s%s", git_replace_ref_base, oid_to_hex(object));
152155
if (check_refname_format(ref->buf, 0))

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,6 @@ void reset_shared_repository(void);
10081008
* commands that do not want replace references to be active.
10091009
*/
10101010
extern int read_replace_refs;
1011-
extern char *git_replace_ref_base;
10121011

10131012
/*
10141013
* These values are used to help identify parts of a repository to fsync.

environment.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const char *askpass_program;
5656
const char *excludes_file;
5757
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
5858
int read_replace_refs = 1;
59-
char *git_replace_ref_base;
6059
enum eol core_eol = EOL_UNSET;
6160
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
6261
char *check_roundtrip_encoding = "SHIFT-JIS";
@@ -162,6 +161,7 @@ const char *getenv_safe(struct strvec *argv, const char *name)
162161

163162
void setup_git_env(const char *git_dir)
164163
{
164+
char *git_replace_ref_base;
165165
const char *shallow_file;
166166
const char *replace_ref_base;
167167
struct set_gitdir_args args = { NULL };
@@ -182,7 +182,6 @@ void setup_git_env(const char *git_dir)
182182
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
183183
read_replace_refs = 0;
184184
replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
185-
free(git_replace_ref_base);
186185
git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
187186
: "refs/replace/");
188187
update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base);

log-tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
141141
enum object_type objtype;
142142
enum decoration_type deco_type = DECORATION_NONE;
143143
struct decoration_filter *filter = (struct decoration_filter *)cb_data;
144+
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
144145

145146
if (filter && !ref_filter_match(refname, filter))
146147
return 0;

refs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,7 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
16121612

16131613
int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data)
16141614
{
1615+
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;
16151616
return do_for_each_repo_ref(r, git_replace_ref_base, fn,
16161617
strlen(git_replace_ref_base),
16171618
DO_FOR_EACH_INCLUDE_BROKEN, cb_data);

0 commit comments

Comments
 (0)