diff options
author | Russell Belfer <rb@github.com> | 2013-03-22 10:44:45 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-03-25 14:03:16 -0700 |
commit | 9733e80c2ae7517f44c658cd2914d99454470dd1 (patch) | |
tree | 200c1a4c7805056c67344afbd03e3c803916c5a0 /src/blob.c | |
parent | 13640d1bb8376e3f07f66498a5b9bdde9ff3d7d6 (diff) | |
download | libgit2-9733e80c2ae7517f44c658cd2914d99454470dd1.tar.gz |
Add has_cr_in_index check to CRLF filter
This adds a check to the drop_crlf filter path to check it the
file in the index already has a CR in it, in which case this will
not drop the CRs from the workdir file contents.
This uncovered a "bug" in `git_blob_create_fromworkdir` where the
full path to the file was passed to look up the attributes instead
of the relative path from the working directory root. This meant
that the check in the index for a pre-existing entry of the same
name was failing.
Diffstat (limited to 'src/blob.c')
-rw-r--r-- | src/blob.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/blob.c b/src/blob.c index bcb6ac96b..3ff141c7f 100644 --- a/src/blob.c +++ b/src/blob.c @@ -221,7 +221,9 @@ int git_blob_create_fromworkdir(git_oid *oid, git_repository *repo, const char * return -1; } - error = blob_create_internal(oid, repo, git_buf_cstr(&full_path), git_buf_cstr(&full_path), true); + error = blob_create_internal( + oid, repo, git_buf_cstr(&full_path), + git_buf_cstr(&full_path) + strlen(workdir), true); git_buf_free(&full_path); return error; @@ -231,13 +233,21 @@ int git_blob_create_fromdisk(git_oid *oid, git_repository *repo, const char *pat { int error; git_buf full_path = GIT_BUF_INIT; + const char *workdir, *hintpath; if ((error = git_path_prettify(&full_path, path, NULL)) < 0) { git_buf_free(&full_path); return error; } - error = blob_create_internal(oid, repo, git_buf_cstr(&full_path), git_buf_cstr(&full_path), true); + hintpath = git_buf_cstr(&full_path); + workdir = git_repository_workdir(repo); + + if (workdir && !git__prefixcmp(hintpath, workdir)) + hintpath += strlen(workdir); + + error = blob_create_internal( + oid, repo, git_buf_cstr(&full_path), hintpath, true); git_buf_free(&full_path); return error; |