Skip to content

Commit dbf2669

Browse files
committed
environment: move trust_executable_bit into repo_settings
The `core.filemode` setting is stored in a global variable and populated via `repo_cfg_bool()`. This may cause issues when handling more than one repository in a single process with diffrent values for that config key. Refactor the code to store the value in `struct repo-settings`. This help the path towards the libification of Git Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com>
1 parent 76fde7d commit dbf2669

File tree

7 files changed

+11
-15
lines changed

7 files changed

+11
-15
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3818,7 +3818,7 @@ static int check_preimage(struct apply_state *state,
38183818
if (*ce && !(*ce)->ce_mode)
38193819
BUG("ce_mode == 0 for path '%s'", old_name);
38203820

3821-
if (trust_executable_bit || !S_ISREG(st->st_mode))
3821+
if (state->repo->settings.trust_executable_bit || !S_ISREG(st->st_mode))
38223822
st_mode = ce_mode_from_stat(*ce, st->st_mode, state->repo);
38233823
else if (*ce)
38243824
st_mode = (*ce)->ce_mode;

environment.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
static int pack_compression_seen;
4141
static int zlib_compression_seen;
4242

43-
int trust_executable_bit = 1;
4443
int trust_ctime = 1;
4544
int check_stat = 1;
4645
int has_symlinks = 1;
@@ -327,11 +326,7 @@ static enum fsync_component parse_fsync_components(const char *var, const char *
327326
static int git_default_core_config(const char *var, const char *value,
328327
const struct config_context *ctx, void *cb)
329328
{
330-
/* This needs a better name */
331-
if (!strcmp(var, "core.filemode")) {
332-
trust_executable_bit = git_config_bool(var, value);
333-
return 0;
334-
}
329+
335330
if (!strcmp(var, "core.trustctime")) {
336331
trust_ctime = git_config_bool(var, value);
337332
return 0;

environment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ int is_bare_repository(void);
142142
extern char *git_work_tree_cfg;
143143

144144
/* Environment bits from configuration mechanism */
145-
extern int trust_executable_bit;
146145
extern int trust_ctime;
147146
extern int check_stat;
148147
extern int has_symlinks;

read-cache.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st
201201

202202
static unsigned int st_mode_from_ce(const struct cache_entry *ce)
203203
{
204-
extern int trust_executable_bit, has_symlinks;
204+
extern int has_symlinks;
205205

206206
switch (ce->ce_mode & S_IFMT) {
207207
case S_IFLNK:
208208
return has_symlinks ? S_IFLNK : (S_IFREG | 0644);
209209
case S_IFREG:
210-
return (ce->ce_mode & (trust_executable_bit ? 0755 : 0644)) | S_IFREG;
210+
return (ce->ce_mode & (the_repository->settings.trust_executable_bit ? 0755 : 0644)) | S_IFREG;
211211
case S_IFGITLINK:
212212
return S_IFDIR | 0755;
213213
case S_IFDIR:
@@ -317,7 +317,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
317317
/* We consider only the owner x bit to be relevant for
318318
* "mode changes"
319319
*/
320-
if (trust_executable_bit &&
320+
if (the_repository->settings.trust_executable_bit &&
321321
(0100 & (ce->ce_mode ^ st->st_mode)))
322322
changed |= MODE_CHANGED;
323323
break;
@@ -727,7 +727,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
727727
ce->ce_flags |= CE_INTENT_TO_ADD;
728728

729729

730-
if (trust_executable_bit && has_symlinks) {
730+
if (the_repository->settings.trust_executable_bit && has_symlinks) {
731731
ce->ce_mode = create_ce_mode(st_mode);
732732
} else {
733733
/* If there is an existing entry, pick the mode bits and type

read-cache.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
#include "repository.h"
88

99
static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
10-
unsigned int mode, struct repository *repo UNUSED)
10+
unsigned int mode, struct repository *repo)
1111
{
12-
extern int trust_executable_bit, has_symlinks;
12+
extern int has_symlinks;
1313
if (!has_symlinks && S_ISREG(mode) &&
1414
ce && S_ISLNK(ce->ce_mode))
1515
return ce->ce_mode;
16-
if (!trust_executable_bit && S_ISREG(mode)) {
16+
if (!repo->settings.trust_executable_bit && S_ISREG(mode)) {
1717
if (ce && S_ISREG(ce->ce_mode))
1818
return ce->ce_mode;
1919
return create_ce_mode(0666);

repo-settings.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void prepare_repo_settings(struct repository *r)
7777
repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
7878
repo_cfg_bool(r, "pack.usepathwalk", &r->settings.pack_use_path_walk, 0);
7979
repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
80+
repo_cfg_bool(r, "core.filemode", &r->settings.trust_executable_bit, 1);
8081
repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
8182
repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash);
8283
repo_cfg_bool(r, "pack.readreverseindex", &r->settings.pack_read_reverse_index, 1);

repo-settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct repo_settings {
3636
int pack_read_reverse_index;
3737
int pack_use_bitmap_boundary_traversal;
3838
int pack_use_multi_pack_reuse;
39+
int trust_executable_bit;
3940

4041
int shared_repository;
4142
int shared_repository_initialized;

0 commit comments

Comments
 (0)