filter: add `git_filter_list__load_ext` Refactor `git_filter_list__load_with_attr_reader` into `git_filter_list__load_ext`, which takes a `git_filter_options`.
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
diff --git a/src/checkout.c b/src/checkout.c
index a4dd209..2c47147 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -1416,6 +1416,7 @@ static int blob_content_to_file(
int flags = data->opts.file_open_flags;
mode_t file_mode = data->opts.file_mode ?
data->opts.file_mode : entry_filemode;
+ git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
struct checkout_stream writer;
mode_t mode;
git_filter_list *fl = NULL;
@@ -1438,10 +1439,12 @@ static int blob_content_to_file(
return fd;
}
+ filter_opts.attr_session = &data->attr_session;
+
if (!data->opts.disable_filters &&
- (error = git_filter_list__load_with_attr_session(
- &fl, data->repo, &data->attr_session, blob, hint_path,
- GIT_FILTER_TO_WORKTREE, GIT_FILTER_DEFAULT)))
+ (error = git_filter_list__load_ext(
+ &fl, data->repo, blob, hint_path,
+ GIT_FILTER_TO_WORKTREE, &filter_opts)))
return error;
if (fl)
@@ -2003,6 +2006,7 @@ static int checkout_write_merge(
git_merge_file_result result = {0};
git_filebuf output = GIT_FILEBUF_INIT;
git_filter_list *fl = NULL;
+ git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
int error = 0;
if (data->opts.checkout_strategy & GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)
@@ -2052,9 +2056,11 @@ static int checkout_write_merge(
in_data.ptr = (char *)result.ptr;
in_data.size = result.len;
- if ((error = git_filter_list__load_with_attr_session(
- &fl, data->repo, &data->attr_session, NULL, git_buf_cstr(&path_workdir),
- GIT_FILTER_TO_WORKTREE, GIT_FILTER_DEFAULT)) < 0 ||
+ filter_opts.attr_session = &data->attr_session;
+
+ if ((error = git_filter_list__load_ext(
+ &fl, data->repo, NULL, git_buf_cstr(&path_workdir),
+ GIT_FILTER_TO_WORKTREE, &filter_opts)) < 0 ||
(error = git_filter_list_apply_to_data(&out_data, fl, &in_data)) < 0)
goto done;
} else {
diff --git a/src/filter.c b/src/filter.c
index 88877fe..646f1bc 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -459,14 +459,13 @@ int git_filter_list_new(
return filter_list_new(out, &src);
}
-int git_filter_list__load_with_attr_session(
+int git_filter_list__load_ext(
git_filter_list **filters,
git_repository *repo,
- git_attr_session *attr_session,
git_blob *blob, /* can be NULL */
const char *path,
git_filter_mode_t mode,
- uint32_t flags)
+ git_filter_options *filter_opts)
{
int error = 0;
git_filter_list *fl = NULL;
@@ -481,7 +480,8 @@ int git_filter_list__load_with_attr_session(
src.repo = repo;
src.path = path;
src.mode = mode;
- src.flags = flags;
+ src.flags = filter_opts->flags;
+
if (blob)
git_oid_cpy(&src.oid, git_blob_id(blob));
@@ -494,7 +494,7 @@ int git_filter_list__load_with_attr_session(
if (fdef->nattrs > 0) {
error = filter_list_check_attributes(
- &values, repo, attr_session, fdef, &src);
+ &values, repo, filter_opts->attr_session, fdef, &src);
if (error == GIT_ENOTFOUND) {
error = 0;
@@ -545,8 +545,12 @@ int git_filter_list_load(
git_filter_mode_t mode,
uint32_t flags)
{
- return git_filter_list__load_with_attr_session(
- filters, repo, NULL, blob, path, mode, flags);
+ git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
+
+ filter_opts.flags = flags;
+
+ return git_filter_list__load_ext(
+ filters, repo, blob, path, mode, &filter_opts);
}
void git_filter_list__set_temp_buf(git_filter_list *fl, git_buf *temp_buf)
diff --git a/src/filter.h b/src/filter.h
index a38c6c8..85ef4a6 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -24,19 +24,25 @@ typedef enum {
GIT_CRLF_AUTO,
} git_crlf_t;
+typedef struct {
+ git_attr_session *attr_session;
+ uint32_t flags;
+} git_filter_options;
+
+#define GIT_FILTER_OPTIONS_INIT {0}
+
extern void git_filter_list__set_temp_buf(
git_filter_list *fl, git_buf *temp_buf);
extern void git_filter_free(git_filter *filter);
-extern int git_filter_list__load_with_attr_session(
+extern int git_filter_list__load_ext(
git_filter_list **filters,
git_repository *repo,
- git_attr_session *attr_session,
git_blob *blob, /* can be NULL */
const char *path,
git_filter_mode_t mode,
- uint32_t flags);
+ git_filter_options *filter_opts);
/*
* Available filters