Skip to content

Commit 7875acb

Browse files
peffgitster
authored andcommitted
wrap shared_repository global in get/set accessors
It would be useful to control access to the global shared_repository, so that we can lazily load its config. The first step to doing so is to make sure all access goes through a set of functions. This step is purely mechanical, and should result in no change of behavior. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4b0d1ee commit 7875acb

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

builtin/init-db.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ static int create_default_files(const char *template_path)
199199

200200
/* reading existing config may have overwrote it */
201201
if (init_shared_repository != -1)
202-
shared_repository = init_shared_repository;
202+
set_shared_repository(init_shared_repository);
203203

204204
/*
205205
* We would have created the above under user's umask -- under
206206
* shared-repository settings, we would need to fix them up.
207207
*/
208-
if (shared_repository) {
208+
if (get_shared_repository()) {
209209
adjust_shared_perm(get_git_dir());
210210
adjust_shared_perm(git_path_buf(&buf, "refs"));
211211
adjust_shared_perm(git_path_buf(&buf, "refs/heads"));
@@ -369,20 +369,20 @@ int init_db(const char *template_dir, unsigned int flags)
369369

370370
create_object_directory();
371371

372-
if (shared_repository) {
372+
if (get_shared_repository()) {
373373
char buf[10];
374374
/* We do not spell "group" and such, so that
375375
* the configuration can be read by older version
376376
* of git. Note, we use octal numbers for new share modes,
377377
* and compatibility values for PERM_GROUP and
378378
* PERM_EVERYBODY.
379379
*/
380-
if (shared_repository < 0)
380+
if (get_shared_repository() < 0)
381381
/* force to the mode value */
382-
xsnprintf(buf, sizeof(buf), "0%o", -shared_repository);
383-
else if (shared_repository == PERM_GROUP)
382+
xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository());
383+
else if (get_shared_repository() == PERM_GROUP)
384384
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
385-
else if (shared_repository == PERM_EVERYBODY)
385+
else if (get_shared_repository() == PERM_EVERYBODY)
386386
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
387387
else
388388
die("BUG: invalid value for shared_repository");
@@ -398,7 +398,7 @@ int init_db(const char *template_dir, unsigned int flags)
398398
"", and the last '%s%s' is the verbatim directory name. */
399399
printf(_("%s%s Git repository in %s%s\n"),
400400
reinit ? _("Reinitialized existing") : _("Initialized empty"),
401-
shared_repository ? _(" shared") : "",
401+
get_shared_repository() ? _(" shared") : "",
402402
git_dir, len && git_dir[len-1] != '/' ? "/" : "");
403403
}
404404

@@ -493,8 +493,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
493493
* and we know shared_repository should always be 0;
494494
* but just in case we play safe.
495495
*/
496-
saved = shared_repository;
497-
shared_repository = 0;
496+
saved = get_shared_repository();
497+
set_shared_repository(0);
498498
switch (safe_create_leading_directories_const(argv[0])) {
499499
case SCLD_OK:
500500
case SCLD_PERMS:
@@ -506,7 +506,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
506506
die_errno(_("cannot mkdir %s"), argv[0]);
507507
break;
508508
}
509-
shared_repository = saved;
509+
set_shared_repository(saved);
510510
if (mkdir(argv[0], 0777) < 0)
511511
die_errno(_("cannot mkdir %s"), argv[0]);
512512
mkdir_tried = 1;
@@ -524,7 +524,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
524524
}
525525

526526
if (init_shared_repository != -1)
527-
shared_repository = init_shared_repository;
527+
set_shared_repository(init_shared_repository);
528528

529529
/*
530530
* GIT_WORK_TREE makes sense only in conjunction with GIT_DIR

cache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,6 @@ extern int prefer_symlink_refs;
651651
extern int log_all_ref_updates;
652652
extern int warn_ambiguous_refs;
653653
extern int warn_on_object_refname_ambiguity;
654-
extern int shared_repository;
655654
extern const char *apply_default_whitespace;
656655
extern const char *apply_default_ignorewhitespace;
657656
extern const char *git_attributes_file;
@@ -664,6 +663,9 @@ extern size_t delta_base_cache_limit;
664663
extern unsigned long big_file_threshold;
665664
extern unsigned long pack_size_limit_cfg;
666665

666+
void set_shared_repository(int value);
667+
int get_shared_repository(void);
668+
667669
/*
668670
* Do replace refs need to be checked this run? This variable is
669671
* initialized to true unless --no-replace-object is used or

environment.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ int repository_format_version;
2929
int repository_format_precious_objects;
3030
const char *git_commit_encoding;
3131
const char *git_log_output_encoding;
32-
int shared_repository = PERM_UMASK;
3332
const char *apply_default_whitespace;
3433
const char *apply_default_ignorewhitespace;
3534
const char *git_attributes_file;
@@ -325,3 +324,15 @@ const char *get_commit_output_encoding(void)
325324
{
326325
return git_commit_encoding ? git_commit_encoding : "UTF-8";
327326
}
327+
328+
static int the_shared_repository = PERM_UMASK;
329+
330+
void set_shared_repository(int value)
331+
{
332+
the_shared_repository = value;
333+
}
334+
335+
int get_shared_repository(void)
336+
{
337+
return the_shared_repository;
338+
}

path.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,17 +699,17 @@ static int calc_shared_perm(int mode)
699699
{
700700
int tweak;
701701

702-
if (shared_repository < 0)
703-
tweak = -shared_repository;
702+
if (get_shared_repository() < 0)
703+
tweak = -get_shared_repository();
704704
else
705-
tweak = shared_repository;
705+
tweak = get_shared_repository();
706706

707707
if (!(mode & S_IWUSR))
708708
tweak &= ~0222;
709709
if (mode & S_IXUSR)
710710
/* Copy read bits to execute bits */
711711
tweak |= (tweak & 0444) >> 2;
712-
if (shared_repository < 0)
712+
if (get_shared_repository() < 0)
713713
mode = (mode & ~0777) | tweak;
714714
else
715715
mode |= tweak;
@@ -722,7 +722,7 @@ int adjust_shared_perm(const char *path)
722722
{
723723
int old_mode, new_mode;
724724

725-
if (!shared_repository)
725+
if (!get_shared_repository())
726726
return 0;
727727
if (get_st_mode_bits(path, &old_mode) < 0)
728728
return -1;

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static int check_repo_format(const char *var, const char *value, void *cb)
377377
if (strcmp(var, "core.repositoryformatversion") == 0)
378378
repository_format_version = git_config_int(var, value);
379379
else if (strcmp(var, "core.sharedrepository") == 0)
380-
shared_repository = git_config_perm(var, value);
380+
set_shared_repository(git_config_perm(var, value));
381381
else if (skip_prefix(var, "extensions.", &ext)) {
382382
/*
383383
* record any known extensions here; otherwise,

0 commit comments

Comments
 (0)