mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 21:44:58 +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;
|
||||
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 {
|
||||
|
18
src/filter.c
18
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)
|
||||
|
12
src/filter.h
12
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
|
||||
|
Loading…
Reference in New Issue
Block a user