Commit 1db5b219 by Edward Thomson

filter: filter options are now "filter sessions"

Filters use a short-lived structure to keep state during an operation to
allow for caching and avoid unnecessary reallocations.  This was
previously called the "filter options", despite the fact that they
contain no configurable options.  Rename them to a "filter session" in
keeping with an "attribute session", which more accurately describes
their use (and allows us to create "filter options" in the future).
parent 3779a047
......@@ -1513,7 +1513,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;
git_filter_session filter_session = GIT_FILTER_SESSION_INIT;
struct checkout_stream writer;
mode_t mode;
git_filter_list *fl = NULL;
......@@ -1536,13 +1536,13 @@ static int blob_content_to_file(
return fd;
}
filter_opts.attr_session = &data->attr_session;
filter_opts.temp_buf = &data->tmp;
filter_session.attr_session = &data->attr_session;
filter_session.temp_buf = &data->tmp;
if (!data->opts.disable_filters &&
(error = git_filter_list__load_ext(
(error = git_filter_list__load(
&fl, data->repo, blob, hint_path,
GIT_FILTER_TO_WORKTREE, &filter_opts))) {
GIT_FILTER_TO_WORKTREE, &filter_session))) {
p_close(fd);
return error;
}
......@@ -2064,7 +2064,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;
git_filter_session filter_session = GIT_FILTER_SESSION_INIT;
int error = 0;
if (data->opts.checkout_strategy & GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)
......@@ -2114,12 +2114,12 @@ static int checkout_write_merge(
in_data.ptr = (char *)result.ptr;
in_data.size = result.len;
filter_opts.attr_session = &data->attr_session;
filter_opts.temp_buf = &data->tmp;
filter_session.attr_session = &data->attr_session;
filter_session.temp_buf = &data->tmp;
if ((error = git_filter_list__load_ext(
if ((error = git_filter_list__load(
&fl, data->repo, NULL, git_buf_cstr(&path_workdir),
GIT_FILTER_TO_WORKTREE, &filter_opts)) < 0 ||
GIT_FILTER_TO_WORKTREE, &filter_session)) < 0 ||
(error = git_filter_list__convert_buf(&out_data, fl, &in_data)) < 0)
goto done;
} else {
......
......@@ -425,7 +425,7 @@ static int filter_list_new(
static int filter_list_check_attributes(
const char ***out,
git_repository *repo,
git_attr_session *attr_session,
git_filter_session *filter_session,
git_filter_def *fdef,
const git_filter_source *src)
{
......@@ -443,7 +443,7 @@ static int filter_list_check_attributes(
attr_opts.flags |= GIT_ATTR_CHECK_INCLUDE_HEAD;
error = git_attr_get_many_with_session(
strs, repo, attr_session, &attr_opts, src->path, fdef->nattrs, fdef->attrs);
strs, repo, filter_session->attr_session, &attr_opts, src->path, fdef->nattrs, fdef->attrs);
/* if no values were found but no matches are needed, it's okay! */
if (error == GIT_ENOTFOUND && !fdef->nmatches) {
......@@ -492,13 +492,13 @@ int git_filter_list_new(
return filter_list_new(out, &src);
}
int git_filter_list__load_ext(
int git_filter_list__load(
git_filter_list **filters,
git_repository *repo,
git_blob *blob, /* can be NULL */
const char *path,
git_filter_mode_t mode,
git_filter_options *filter_opts)
git_filter_session *filter_session)
{
int error = 0;
git_filter_list *fl = NULL;
......@@ -515,7 +515,7 @@ int git_filter_list__load_ext(
src.repo = repo;
src.path = path;
src.mode = mode;
src.flags = filter_opts->flags;
src.flags = filter_session->flags;
if (blob)
git_oid_cpy(&src.oid, git_blob_id(blob));
......@@ -529,7 +529,8 @@ int git_filter_list__load_ext(
if (fdef->nattrs > 0) {
error = filter_list_check_attributes(
&values, repo, filter_opts->attr_session, fdef, &src);
&values, repo,
filter_session, fdef, &src);
if (error == GIT_ENOTFOUND) {
error = 0;
......@@ -556,7 +557,7 @@ int git_filter_list__load_ext(
if ((error = filter_list_new(&fl, &src)) < 0)
break;
fl->temp_buf = filter_opts->temp_buf;
fl->temp_buf = filter_session->temp_buf;
}
fe = git_array_alloc(fl->filters);
......@@ -588,12 +589,12 @@ int git_filter_list_load(
git_filter_mode_t mode,
uint32_t flags)
{
git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
git_filter_session filter_session = GIT_FILTER_SESSION_INIT;
filter_opts.flags = flags;
filter_session.flags = flags;
return git_filter_list__load_ext(
filters, repo, blob, path, mode, &filter_opts);
return git_filter_list__load(
filters, repo, blob, path, mode, &filter_session);
}
void git_filter_list_free(git_filter_list *fl)
......
......@@ -16,24 +16,24 @@
#define GIT_FILTER_BYTES_TO_CHECK_NUL 8000
typedef struct {
uint32_t flags;
git_attr_session *attr_session;
git_buf *temp_buf;
uint32_t flags;
} git_filter_options;
} git_filter_session;
#define GIT_FILTER_OPTIONS_INIT {0}
#define GIT_FILTER_SESSION_INIT {0}
extern int git_filter_global_init(void);
extern void git_filter_free(git_filter *filter);
extern int git_filter_list__load_ext(
extern int git_filter_list__load(
git_filter_list **filters,
git_repository *repo,
git_blob *blob, /* can be NULL */
const char *path,
git_filter_mode_t mode,
git_filter_options *filter_opts);
git_filter_session *filter_session);
/*
* The given input buffer will be converted to the given output buffer.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment