Skip to content

Commit 093d579

Browse files
committed
attr: cache nonexistent attr files from commits
When looking up an attribute file in a commit, we can cache a nonexistent attribute file indefinitely (since a commit could not somehow later contain an attribute file). Cache an empty buffer when an attribute file does not exist in a given commit.
1 parent d7e8b93 commit 093d579

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/attr_file.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,24 @@ int git_attr_file__load(
163163
break;
164164
}
165165
case GIT_ATTR_FILE_SOURCE_COMMIT: {
166-
if ((error = git_repository_head_tree(&tree, repo)) < 0 ||
167-
(error = git_tree_entry_bypath(&tree_entry, tree, entry->path)) < 0 ||
168-
(error = git_blob_lookup(&blob, repo, git_tree_entry_id(tree_entry))) < 0)
166+
if ((error = git_repository_head_tree(&tree, repo)) < 0)
167+
goto cleanup;
168+
169+
if ((error = git_tree_entry_bypath(&tree_entry, tree, entry->path)) < 0) {
170+
/*
171+
* If the attributes file does not exist, we can
172+
* cache an empty file for this commit to prevent
173+
* needless future lookups.
174+
*/
175+
if (error == GIT_ENOTFOUND) {
176+
error = 0;
177+
break;
178+
}
179+
180+
goto cleanup;
181+
}
182+
183+
if ((error = git_blob_lookup(&blob, repo, git_tree_entry_id(tree_entry))) < 0)
169184
goto cleanup;
170185

171186
/*

0 commit comments

Comments
 (0)