summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-07-01 11:08:26 -0700
committerEdward Thomson <ethomson@edwardthomson.com>2018-11-05 15:53:34 +0000
commit9be89bbde77cb704c2bf1dcb0fc0aa64f4697596 (patch)
tree1141f0c939e67f9fc1e7bc4d9f54bf34ce060330
parent813f08029727f7d07989f63bb16dc798c5db7027 (diff)
downloadlibgit2-9be89bbde77cb704c2bf1dcb0fc0aa64f4697596.tar.gz
reader: apply working directory filters
When reading a file from the working directory, ensure that we apply any necessary filters to the item. This ensures that we get the repository-normalized data as the preimage, and further ensures that we can accurately compare the working directory contents to the index contents for accurate safety validation in the `BOTH` case.
-rw-r--r--src/reader.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/reader.c b/src/reader.c
index 94faff701..2cdd0a131 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -85,6 +85,7 @@ static int workdir_reader_read(
{
workdir_reader *reader = (workdir_reader *)_reader;
git_buf path = GIT_BUF_INIT;
+ git_filter_list *filters = NULL;
const git_index_entry *idx_entry;
git_oid id;
int error;
@@ -93,8 +94,17 @@ static int workdir_reader_read(
git_repository_workdir(reader->repo), filename)) < 0)
goto done;
- /* TODO: should we read the filtered data? */
- if ((error = git_futils_readbuffer(out, path.ptr)) < 0)
+ /*
+ * Patch application - for example - uses the filtered version of
+ * the working directory data to match git. So we will run the
+ * workdir -> ODB filter on the contents in this workdir reader.
+ */
+ if ((error = git_filter_list_load(&filters, reader->repo, NULL, filename,
+ GIT_FILTER_TO_ODB, GIT_FILTER_DEFAULT)) < 0)
+ goto done;
+
+ if ((error = git_filter_list_apply_to_file(out,
+ filters, reader->repo, path.ptr)) < 0)
goto done;
if (out_id || reader->index) {
@@ -114,6 +124,7 @@ static int workdir_reader_read(
git_oid_cpy(out_id, &id);
done:
+ git_filter_list_free(filters);
git_buf_dispose(&path);
return error;
}