Skip to content

Commit 848bd00

Browse files
committed
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.
1 parent 0f4256b commit 848bd00

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/blob.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,20 @@ int git_blob_create_from_disk(
277277
{
278278
int error;
279279
git_buf full_path = GIT_BUF_INIT;
280-
const char *workdir, *hintpath;
280+
const char *workdir, *hintpath = NULL;
281281

282282
if ((error = git_path_prettify(&full_path, path, NULL)) < 0) {
283283
git_buf_dispose(&full_path);
284284
return error;
285285
}
286286

287-
hintpath = git_buf_cstr(&full_path);
288287
workdir = git_repository_workdir(repo);
289288

290-
if (workdir && !git__prefixcmp(hintpath, workdir))
291-
hintpath += strlen(workdir);
289+
if (workdir && !git__prefixcmp(full_path.ptr, workdir))
290+
hintpath = full_path.ptr + strlen(workdir);
292291

293292
error = git_blob__create_from_paths(
294-
id, NULL, repo, git_buf_cstr(&full_path), hintpath, 0, true);
293+
id, NULL, repo, git_buf_cstr(&full_path), hintpath, 0, !!hintpath);
295294

296295
git_buf_dispose(&full_path);
297296
return error;

0 commit comments

Comments
 (0)