Browse Source

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 <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Derrick Stolee 3 years ago committed by Junio C Hamano
parent
commit
97e61e0f9c
  1. 3
      builtin/replace.c
  2. 1
      cache.h
  3. 3
      environment.c
  4. 1
      log-tree.c
  5. 1
      refs.c

3
builtin/replace.c

@ -106,6 +106,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
size_t base_len; size_t base_len;
int had_error = 0; int had_error = 0;
struct object_id oid; struct object_id oid;
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;


strbuf_addstr(&ref, git_replace_ref_base); strbuf_addstr(&ref, git_replace_ref_base);
base_len = ref.len; base_len = ref.len;
@ -147,6 +148,8 @@ static int check_ref_valid(struct object_id *object,
struct strbuf *ref, struct strbuf *ref,
int force) int force)
{ {
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;

strbuf_reset(ref); strbuf_reset(ref);
strbuf_addf(ref, "%s%s", git_replace_ref_base, oid_to_hex(object)); strbuf_addf(ref, "%s%s", git_replace_ref_base, oid_to_hex(object));
if (check_refname_format(ref->buf, 0)) if (check_refname_format(ref->buf, 0))

1
cache.h

@ -1008,7 +1008,6 @@ void reset_shared_repository(void);
* commands that do not want replace references to be active. * commands that do not want replace references to be active.
*/ */
extern int read_replace_refs; extern int read_replace_refs;
extern char *git_replace_ref_base;


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

3
environment.c

@ -56,7 +56,6 @@ const char *askpass_program;
const char *excludes_file; const char *excludes_file;
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE; enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
int read_replace_refs = 1; int read_replace_refs = 1;
char *git_replace_ref_base;
enum eol core_eol = EOL_UNSET; enum eol core_eol = EOL_UNSET;
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
char *check_roundtrip_encoding = "SHIFT-JIS"; char *check_roundtrip_encoding = "SHIFT-JIS";
@ -162,6 +161,7 @@ const char *getenv_safe(struct strvec *argv, const char *name)


void setup_git_env(const char *git_dir) void setup_git_env(const char *git_dir)
{ {
char *git_replace_ref_base;
const char *shallow_file; const char *shallow_file;
const char *replace_ref_base; const char *replace_ref_base;
struct set_gitdir_args args = { NULL }; struct set_gitdir_args args = { NULL };
@ -182,7 +182,6 @@ void setup_git_env(const char *git_dir)
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
read_replace_refs = 0; read_replace_refs = 0;
replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT); replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
free(git_replace_ref_base);
git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
: "refs/replace/"); : "refs/replace/");
update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base);

1
log-tree.c

@ -141,6 +141,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
enum object_type objtype; enum object_type objtype;
enum decoration_type deco_type = DECORATION_NONE; enum decoration_type deco_type = DECORATION_NONE;
struct decoration_filter *filter = (struct decoration_filter *)cb_data; struct decoration_filter *filter = (struct decoration_filter *)cb_data;
const char *git_replace_ref_base = ref_namespace[NAMESPACE_REPLACE].ref;


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

1
refs.c

@ -1612,6 +1612,7 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,


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

Loading…
Cancel
Save