mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-07 18:11:43 +00:00
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`.
This commit is contained in:
parent
795eaccd66
commit
d05218b06f
@ -1416,6 +1416,7 @@ static int blob_content_to_file(
|
|||||||
int flags = data->opts.file_open_flags;
|
int flags = data->opts.file_open_flags;
|
||||||
mode_t file_mode = data->opts.file_mode ?
|
mode_t file_mode = data->opts.file_mode ?
|
||||||
data->opts.file_mode : entry_filemode;
|
data->opts.file_mode : entry_filemode;
|
||||||
|
git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
|
||||||
struct checkout_stream writer;
|
struct checkout_stream writer;
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
git_filter_list *fl = NULL;
|
git_filter_list *fl = NULL;
|
||||||
@ -1438,10 +1439,12 @@ static int blob_content_to_file(
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filter_opts.attr_session = &data->attr_session;
|
||||||
|
|
||||||
if (!data->opts.disable_filters &&
|
if (!data->opts.disable_filters &&
|
||||||
(error = git_filter_list__load_with_attr_session(
|
(error = git_filter_list__load_ext(
|
||||||
&fl, data->repo, &data->attr_session, blob, hint_path,
|
&fl, data->repo, blob, hint_path,
|
||||||
GIT_FILTER_TO_WORKTREE, GIT_FILTER_DEFAULT)))
|
GIT_FILTER_TO_WORKTREE, &filter_opts)))
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (fl)
|
if (fl)
|
||||||
@ -2003,6 +2006,7 @@ static int checkout_write_merge(
|
|||||||
git_merge_file_result result = {0};
|
git_merge_file_result result = {0};
|
||||||
git_filebuf output = GIT_FILEBUF_INIT;
|
git_filebuf output = GIT_FILEBUF_INIT;
|
||||||
git_filter_list *fl = NULL;
|
git_filter_list *fl = NULL;
|
||||||
|
git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
if (data->opts.checkout_strategy & GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)
|
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.ptr = (char *)result.ptr;
|
||||||
in_data.size = result.len;
|
in_data.size = result.len;
|
||||||
|
|
||||||
if ((error = git_filter_list__load_with_attr_session(
|
filter_opts.attr_session = &data->attr_session;
|
||||||
&fl, data->repo, &data->attr_session, NULL, git_buf_cstr(&path_workdir),
|
|
||||||
GIT_FILTER_TO_WORKTREE, GIT_FILTER_DEFAULT)) < 0 ||
|
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)
|
(error = git_filter_list_apply_to_data(&out_data, fl, &in_data)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
} else {
|
} else {
|
||||||
|
18
src/filter.c
18
src/filter.c
@ -459,14 +459,13 @@ int git_filter_list_new(
|
|||||||
return filter_list_new(out, &src);
|
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_filter_list **filters,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
git_attr_session *attr_session,
|
|
||||||
git_blob *blob, /* can be NULL */
|
git_blob *blob, /* can be NULL */
|
||||||
const char *path,
|
const char *path,
|
||||||
git_filter_mode_t mode,
|
git_filter_mode_t mode,
|
||||||
uint32_t flags)
|
git_filter_options *filter_opts)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
git_filter_list *fl = NULL;
|
git_filter_list *fl = NULL;
|
||||||
@ -481,7 +480,8 @@ int git_filter_list__load_with_attr_session(
|
|||||||
src.repo = repo;
|
src.repo = repo;
|
||||||
src.path = path;
|
src.path = path;
|
||||||
src.mode = mode;
|
src.mode = mode;
|
||||||
src.flags = flags;
|
src.flags = filter_opts->flags;
|
||||||
|
|
||||||
if (blob)
|
if (blob)
|
||||||
git_oid_cpy(&src.oid, git_blob_id(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) {
|
if (fdef->nattrs > 0) {
|
||||||
error = filter_list_check_attributes(
|
error = filter_list_check_attributes(
|
||||||
&values, repo, attr_session, fdef, &src);
|
&values, repo, filter_opts->attr_session, fdef, &src);
|
||||||
|
|
||||||
if (error == GIT_ENOTFOUND) {
|
if (error == GIT_ENOTFOUND) {
|
||||||
error = 0;
|
error = 0;
|
||||||
@ -545,8 +545,12 @@ int git_filter_list_load(
|
|||||||
git_filter_mode_t mode,
|
git_filter_mode_t mode,
|
||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
return git_filter_list__load_with_attr_session(
|
git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
|
||||||
filters, repo, NULL, blob, path, mode, flags);
|
|
||||||
|
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)
|
void git_filter_list__set_temp_buf(git_filter_list *fl, git_buf *temp_buf)
|
||||||
|
12
src/filter.h
12
src/filter.h
@ -24,19 +24,25 @@ typedef enum {
|
|||||||
GIT_CRLF_AUTO,
|
GIT_CRLF_AUTO,
|
||||||
} git_crlf_t;
|
} 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(
|
extern void git_filter_list__set_temp_buf(
|
||||||
git_filter_list *fl, git_buf *temp_buf);
|
git_filter_list *fl, git_buf *temp_buf);
|
||||||
|
|
||||||
extern void git_filter_free(git_filter *filter);
|
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_filter_list **filters,
|
||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
git_attr_session *attr_session,
|
|
||||||
git_blob *blob, /* can be NULL */
|
git_blob *blob, /* can be NULL */
|
||||||
const char *path,
|
const char *path,
|
||||||
git_filter_mode_t mode,
|
git_filter_mode_t mode,
|
||||||
uint32_t flags);
|
git_filter_options *filter_opts);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Available filters
|
* Available filters
|
||||||
|
Loading…
Reference in New Issue
Block a user