Skip to content

Commit 53454b6

Browse files
authored
Merge pull request libgit2#4510 from pks-t/pks/attr-file-bare-stat
attr: avoid stat'ting files for bare repositories
2 parents f55accc + e28e17e commit 53454b6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/attr.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ int git_attr_get(
5656
git_attr_file *file;
5757
git_attr_name attr;
5858
git_attr_rule *rule;
59+
git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN;
5960

6061
assert(value && repo && name);
6162

6263
*value = NULL;
6364

64-
if (git_attr_path__init(&path, pathname, git_repository_workdir(repo), GIT_DIR_FLAG_UNKNOWN) < 0)
65+
if (git_repository_is_bare(repo))
66+
dir_flag = GIT_DIR_FLAG_FALSE;
67+
68+
if (git_attr_path__init(&path, pathname, git_repository_workdir(repo), dir_flag) < 0)
6569
return -1;
6670

6771
if ((error = collect_attr_files(repo, NULL, flags, pathname, &files)) < 0)
@@ -114,13 +118,17 @@ int git_attr_get_many_with_session(
114118
git_attr_rule *rule;
115119
attr_get_many_info *info = NULL;
116120
size_t num_found = 0;
121+
git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN;
117122

118123
if (!num_attr)
119124
return 0;
120125

121126
assert(values && repo && names);
122127

123-
if (git_attr_path__init(&path, pathname, git_repository_workdir(repo), GIT_DIR_FLAG_UNKNOWN) < 0)
128+
if (git_repository_is_bare(repo))
129+
dir_flag = GIT_DIR_FLAG_FALSE;
130+
131+
if (git_attr_path__init(&path, pathname, git_repository_workdir(repo), dir_flag) < 0)
124132
return -1;
125133

126134
if ((error = collect_attr_files(repo, attr_session, flags, pathname, &files)) < 0)
@@ -196,10 +204,14 @@ int git_attr_foreach(
196204
git_attr_rule *rule;
197205
git_attr_assignment *assign;
198206
git_strmap *seen = NULL;
207+
git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN;
199208

200209
assert(repo && callback);
201210

202-
if (git_attr_path__init(&path, pathname, git_repository_workdir(repo), GIT_DIR_FLAG_UNKNOWN) < 0)
211+
if (git_repository_is_bare(repo))
212+
dir_flag = GIT_DIR_FLAG_FALSE;
213+
214+
if (git_attr_path__init(&path, pathname, git_repository_workdir(repo), dir_flag) < 0)
203215
return -1;
204216

205217
if ((error = collect_attr_files(repo, NULL, flags, pathname, &files)) < 0 ||

src/ignore.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ int git_ignore_path_is_ignored(
540540
git_ignores ignores;
541541
unsigned int i;
542542
git_attr_file *file;
543+
git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN;
543544

544545
assert(repo && ignored && pathname);
545546

@@ -548,7 +549,10 @@ int git_ignore_path_is_ignored(
548549
memset(&path, 0, sizeof(path));
549550
memset(&ignores, 0, sizeof(ignores));
550551

551-
if ((error = git_attr_path__init(&path, pathname, workdir, GIT_DIR_FLAG_UNKNOWN)) < 0 ||
552+
if (git_repository_is_bare(repo))
553+
dir_flag = GIT_DIR_FLAG_FALSE;
554+
555+
if ((error = git_attr_path__init(&path, pathname, workdir, dir_flag)) < 0 ||
552556
(error = git_ignore__for_path(repo, path.path, &ignores)) < 0)
553557
goto cleanup;
554558

0 commit comments

Comments
 (0)