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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/src/reader.c b/src/reader.c
index 94faff7..2cdd0a1 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;
}