8000 Streaming filters by ethomson · Pull Request #2911 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

Streaming filters #2911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 19, 2015
Prev Previous commit
Next Next commit
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`.
  • Loading branch information
Edward Thomson committed Feb 19, 2015
commit d05218b06ff201cd373fc764e0d87af67f7932c7
18 changes: 12 additions & 6 deletions src/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 11 additions & 7 deletions src/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));

Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
0