summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-09-24 16:05:23 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-09-25 14:39:01 +0100
commit848bd0098a0dfa2c0502691bf76d3dbb0a00526d (patch)
tree489be846f7ce0e146e901a18f68aaf1fe04cd010
parent0f4256b8d78cf602192e0546d185953ee1b30fd5 (diff)
downloadlibgit2-848bd0098a0dfa2c0502691bf76d3dbb0a00526d.tar.gz
blob: improve `create_from_disk` attribute lookups
Resolve absolute paths to be working directory relative when looking up attributes. Importantly, now we will _never_ pass an absolute path down to attribute lookup functions.
-rw-r--r--src/blob.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/blob.c b/src/blob.c
index 06a4a0026..09b5b5d91 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -277,21 +277,20 @@ int git_blob_create_from_disk(
{
int error;
git_buf full_path = GIT_BUF_INIT;
- const char *workdir, *hintpath;
+ const char *workdir, *hintpath = NULL;
if ((error = git_path_prettify(&full_path, path, NULL)) < 0) {
git_buf_dispose(&full_path);
return error;
}
- hintpath = git_buf_cstr(&full_path);
workdir = git_repository_workdir(repo);
- if (workdir && !git__prefixcmp(hintpath, workdir))
- hintpath += strlen(workdir);
+ if (workdir && !git__prefixcmp(full_path.ptr, workdir))
+ hintpath = full_path.ptr + strlen(workdir);
error = git_blob__create_from_paths(
- id, NULL, repo, git_buf_cstr(&full_path), hintpath, 0, true);
+ id, NULL, repo, git_buf_cstr(&full_path), hintpath, 0, !!hintpath);
git_buf_dispose(&full_path);
return error;