Skip to content

Commit 028f618

Browse files
pks-tgitster
authored andcommitted
path: adjust last remaining users of the_repository
With the preceding refactorings we now only have a couple of implicit users of `the_repository` left in the "path" subsystem, all of which depend on global state via `calc_shared_perm()`. Make the dependency on `the_repository` explicit by passing the repo as a parameter instead and adjust callers accordingly. Note that this change bubbles up into a couple of subsystems that were previously declared as free from `the_repository`. Instead of marking all of them as `the_repository`-dependent again, we instead use the repository that is available in the calling context. There are three exceptions though with "copy.c", "pack-write.c" and "tempfile.c". Adjusting these would require us to adapt callsites all over the place, so this is left for a future iteration. Mark "path.c" as free from `the_repository`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1ce861 commit 028f618

17 files changed

+64
-56
lines changed

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ int cmd_clone(int argc,
12201220

12211221
strbuf_reset(&buf);
12221222
strbuf_addf(&buf, "%s/refs", git_dir);
1223-
safe_create_dir(buf.buf, 1);
1223+
safe_create_dir(the_repository, buf.buf, 1);
12241224

12251225
/*
12261226
* additional config can be injected with -c, make sure it's included

commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
20842084
return -1;
20852085
}
20862086

2087-
if (adjust_shared_perm(get_tempfile_path(graph_layer))) {
2087+
if (adjust_shared_perm(the_repository, get_tempfile_path(graph_layer))) {
20882088
error(_("unable to adjust shared permissions for '%s'"),
20892089
get_tempfile_path(graph_layer));
20902090
return -1;

copy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "copy.h"
35
#include "path.h"
@@ -57,7 +59,7 @@ int copy_file(const char *dst, const char *src, int mode)
5759
if (close(fdo) != 0)
5860
return error_errno("%s: close error", dst);
5961

60-
if (!status && adjust_shared_perm(dst))
62+
if (!status && adjust_shared_perm(the_repository, dst))
6163
return -1;
6264

6365
return status;

loose.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static int write_one_object(struct repository *repo, const struct object_id *oid
190190
goto errout;
191191
if (close(fd))
192192
goto errout;
193-
adjust_shared_perm(path.buf);
193+
adjust_shared_perm(repo, path.buf);
194194
rollback_lock_file(&lock);
195195
strbuf_release(&buf);
196196
strbuf_release(&path);

midx-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
13361336
return -1;
13371337
}
13381338

1339-
if (adjust_shared_perm(get_tempfile_path(incr))) {
1339+
if (adjust_shared_perm(r, get_tempfile_path(incr))) {
13401340
error(_("unable to adjust shared permissions for '%s'"),
13411341
get_tempfile_path(incr));
13421342
return -1;

object-file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ int mkdir_in_gitdir(const char *path)
388388
}
389389
strbuf_release(&sb);
390390
}
391-
return adjust_shared_perm(path);
391+
return adjust_shared_perm(the_repository, path);
392392
}
393393

394394
static enum scld_error safe_create_leading_directories_1(char *path, int share)
@@ -437,7 +437,7 @@ static enum scld_error safe_create_leading_directories_1(char *path, int share)
437437
ret = SCLD_VANISHED;
438438
else
439439
ret = SCLD_FAILED;
440-
} else if (share && adjust_shared_perm(path)) {
440+
} else if (share && adjust_shared_perm(the_repository, path)) {
441441
ret = SCLD_PERMS;
442442
}
443443
*slash = slash_character;
@@ -2105,7 +2105,7 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
21052105
}
21062106

21072107
out:
2108-
if (adjust_shared_perm(filename))
2108+
if (adjust_shared_perm(the_repository, filename))
21092109
return error(_("unable to set permission to '%s'"), filename);
21102110
return 0;
21112111
}
@@ -2181,7 +2181,7 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename)
21812181
strbuf_add(tmp, filename, dirlen - 1);
21822182
if (mkdir(tmp->buf, 0777) && errno != EEXIST)
21832183
return -1;
2184-
if (adjust_shared_perm(tmp->buf))
2184+
if (adjust_shared_perm(the_repository, tmp->buf))
21852185
return -1;
21862186

21872187
/* Try again */

pack-bitmap-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
10721072
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
10731073
CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
10741074

1075-
if (adjust_shared_perm(tmp_file.buf))
1075+
if (adjust_shared_perm(the_repository, tmp_file.buf))
10761076
die_errno("unable to make temporary bitmap file readable");
10771077

10781078
if (rename(tmp_file.buf, filename))

pack-write.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "environment.h"
35
#include "gettext.h"
@@ -287,7 +289,7 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
287289
write_rev_index_positions(f, pack_order, nr_objects);
288290
write_rev_trailer(hash_algo, f, hash);
289291

290-
if (adjust_shared_perm(path) < 0)
292+
if (adjust_shared_perm(the_repository, path) < 0)
291293
die(_("failed to make %s readable"), path);
292294

293295
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
@@ -350,7 +352,7 @@ static char *write_mtimes_file(const struct git_hash_algo *hash_algo,
350352
write_mtimes_objects(f, to_pack, objects, nr_objects);
351353
write_mtimes_trailer(hash_algo, f, hash);
352354

353-
if (adjust_shared_perm(mtimes_name) < 0)
355+
if (adjust_shared_perm(the_repository, mtimes_name) < 0)
354356
die(_("failed to make %s readable"), mtimes_name);
355357

356358
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
@@ -565,12 +567,12 @@ void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
565567
char *rev_tmp_name = NULL;
566568
char *mtimes_tmp_name = NULL;
567569

568-
if (adjust_shared_perm(pack_tmp_name))
570+
if (adjust_shared_perm(the_repository, pack_tmp_name))
569571
die_errno("unable to make temporary pack file readable");
570572

571573
*idx_tmp_name = (char *)write_idx_file(hash_algo, NULL, written_list,
572574
nr_written, pack_idx_opts, hash);
573-
if (adjust_shared_perm(*idx_tmp_name))
575+
if (adjust_shared_perm(the_repository, *idx_tmp_name))
574576
die_errno("unable to make temporary index file readable");
575577

576578
rev_tmp_name = write_rev_file(hash_algo, NULL, written_list, nr_written,

path.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* Utilities for paths and pathnames
33
*/
44

5-
#define USE_THE_REPOSITORY_VARIABLE
6-
75
#include "git-compat-util.h"
86
#include "abspath.h"
97
#include "environment.h"
@@ -840,39 +838,40 @@ const char *enter_repo(const char *path, unsigned flags)
840838
return NULL;
841839
}
842840

843-
int calc_shared_perm(int mode)
841+
int calc_shared_perm(struct repository *repo,
842+
int mode)
844843
{
845844
int tweak;
846845

847-
if (repo_settings_get_shared_repository(the_repository) < 0)
848-
tweak = -repo_settings_get_shared_repository(the_repository);
846+
if (repo_settings_get_shared_repository(repo) < 0)
847+
tweak = -repo_settings_get_shared_repository(repo);
849848
else
850-
tweak = repo_settings_get_shared_repository(the_repository);
849+
tweak = repo_settings_get_shared_repository(repo);
851850

852851
if (!(mode & S_IWUSR))
853852
tweak &= ~0222;
854853
if (mode & S_IXUSR)
855854
/* Copy read bits to execute bits */
856855
tweak |= (tweak & 0444) >> 2;
857-
if (repo_settings_get_shared_repository(the_repository) < 0)
856+
if (repo_settings_get_shared_repository(repo) < 0)
858857
mode = (mode & ~0777) | tweak;
859858
else
860859
mode |= tweak;
861860

862861
return mode;
863862
}
864863

865-
866-
int adjust_shared_perm(const char *path)
864+
int adjust_shared_perm(struct repository *repo,
865+
const char *path)
867866
{
868867
int old_mode, new_mode;
869868

870-
if (!repo_settings_get_shared_repository(the_repository))
869+
if (!repo_settings_get_shared_repository(repo))
871870
return 0;
872871
if (get_st_mode_bits(path, &old_mode) < 0)
873872
return -1;
874873

875-
new_mode = calc_shared_perm(old_mode);
874+
new_mode = calc_shared_perm(repo, old_mode);
876875
if (S_ISDIR(old_mode)) {
877876
/* Copy read bits to execute bits */
878877
new_mode |= (new_mode & 0444) >> 2;
@@ -891,15 +890,15 @@ int adjust_shared_perm(const char *path)
891890
return 0;
892891
}
893892

894-
void safe_create_dir(const char *dir, int share)
893+
void safe_create_dir(struct repository *repo, const char *dir, int share)
895894
{
896895
if (mkdir(dir, 0777) < 0) {
897896
if (errno != EEXIST) {
898897
perror(dir);
899898
exit(1);
900899
}
901900
}
902-
else if (share && adjust_shared_perm(dir))
901+
else if (share && adjust_shared_perm(repo, dir))
903902
die(_("Could not make %s writable by group"), dir);
904903
}
905904

path.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ const char *git_path_shallow(struct repository *r);
141141

142142
int ends_with_path_components(const char *path, const char *components);
143143

144-
int calc_shared_perm(int mode);
145-
int adjust_shared_perm(const char *path);
144+
int calc_shared_perm(struct repository *repo, int mode);
145+
int adjust_shared_perm(struct repository *repo, const char *path);
146146

147147
char *interpolate_path(const char *path, int real_home);
148148

@@ -219,7 +219,7 @@ char *xdg_cache_home(const char *filename);
219219
* directories under $GIT_DIR. Don't use it for working tree
220220
* directories.
221221
*/
222-
void safe_create_dir(const char *dir, int share);
222+
void safe_create_dir(struct repository *repo, const char *dir, int share);
223223

224224
# ifdef USE_THE_REPOSITORY_VARIABLE
225225
# include "strbuf.h"

0 commit comments

Comments
 (0)