summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-07-22 15:07:35 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-07-22 16:22:28 -0400
commit093d579f7be5636c52290a517eee1eebb7471e31 (patch)
tree6744be33768ae0b3057132cadf59ca68505cbbe0
parentd7e8b9348cab441184b82c57cb2c847c11ffa5d8 (diff)
downloadlibgit2-093d579f7be5636c52290a517eee1eebb7471e31.tar.gz
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.
-rw-r--r--src/attr_file.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index b5860238c..3b8965a10 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -163,9 +163,24 @@ int git_attr_file__load(
break;
}
case GIT_ATTR_FILE_SOURCE_COMMIT: {
- if ((error = git_repository_head_tree(&tree, repo)) < 0 ||
- (error = git_tree_entry_bypath(&tree_entry, tree, entry->path)) < 0 ||
- (error = git_blob_lookup(&blob, repo, git_tree_entry_id(tree_entry))) < 0)
+ if ((error = git_repository_head_tree(&tree, repo)) < 0)
+ goto cleanup;
+
+ if ((error = git_tree_entry_bypath(&tree_entry, tree, entry->path)) < 0) {
+ /*
+ * If the attributes file does not exist, we can
+ * cache an empty file for this commit to prevent
+ * needless future lookups.
+ */
+ if (error == GIT_ENOTFOUND) {
+ error = 0;
+ break;
+ }
+
+ goto cleanup;
+ }
+
+ if ((error = git_blob_lookup(&blob, repo, git_tree_entry_id(tree_entry))) < 0)
goto cleanup;
/*