Skip to content

Commit 1db5b21

Browse files
committed
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).
1 parent 3779a04 commit 1db5b21

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

src/checkout.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ static int blob_content_to_file(
15131513
int flags = data->opts.file_open_flags;
15141514
mode_t file_mode = data->opts.file_mode ?
15151515
data->opts.file_mode : entry_filemode;
1516-
git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
1516+
git_filter_session filter_session = GIT_FILTER_SESSION_INIT;
15171517
struct checkout_stream writer;
15181518
mode_t mode;
15191519
git_filter_list *fl = NULL;
@@ -1536,13 +1536,13 @@ static int blob_content_to_file(
15361536
return fd;
15371537
}
15381538

1539-
filter_opts.attr_session = &data->attr_session;
1540-
filter_opts.temp_buf = &data->tmp;
1539+
filter_session.attr_session = &data->attr_session;
1540+
filter_session.temp_buf = &data->tmp;
15411541

15421542
if (!data->opts.disable_filters &&
1543-
(error = git_filter_list__load_ext(
1543+
(error = git_filter_list__load(
15441544
&fl, data->repo, blob, hint_path,
1545-
GIT_FILTER_TO_WORKTREE, &filter_opts))) {
1545+
GIT_FILTER_TO_WORKTREE, &filter_session))) {
15461546
p_close(fd);
15471547
return error;
15481548
}
@@ -2064,7 +2064,7 @@ static int checkout_write_merge(
20642064
git_merge_file_result result = {0};
20652065
git_filebuf output = GIT_FILEBUF_INIT;
20662066
git_filter_list *fl = NULL;
2067-
git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
2067+
git_filter_session filter_session = GIT_FILTER_SESSION_INIT;
20682068
int error = 0;
20692069

20702070
if (data->opts.checkout_strategy & GIT_CHECKOUT_CONFLICT_STYLE_DIFF3)
@@ -2114,12 +2114,12 @@ static int checkout_write_merge(
21142114
in_data.ptr = (char *)result.ptr;
21152115
in_data.size = result.len;
21162116

2117-
filter_opts.attr_session = &data->attr_session;
2118-
filter_opts.temp_buf = &data->tmp;
2117+
filter_session.attr_session = &data->attr_session;
2118+
filter_session.temp_buf = &data->tmp;
21192119

2120-
if ((error = git_filter_list__load_ext(
2120+
if ((error = git_filter_list__load(
21212121
&fl, data->repo, NULL, git_buf_cstr(&path_workdir),
2122-
GIT_FILTER_TO_WORKTREE, &filter_opts)) < 0 ||
2122+
GIT_FILTER_TO_WORKTREE, &filter_session)) < 0 ||
21232123
(error = git_filter_list__convert_buf(&out_data, fl, &in_data)) < 0)
21242124
goto done;
21252125
} else {

src/filter.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ static int filter_list_new(
425425
static int filter_list_check_attributes(
426426
const char ***out,
427427
git_repository *repo,
428-
git_attr_session *attr_session,
428+
git_filter_session *filter_session,
429429
git_filter_def *fdef,
430430
const git_filter_source *src)
431431
{
@@ -443,7 +443,7 @@ static int filter_list_check_attributes(
443443
attr_opts.flags |= GIT_ATTR_CHECK_INCLUDE_HEAD;
444444

445445
error = git_attr_get_many_with_session(
446-
strs, repo, attr_session, &attr_opts, src->path, fdef->nattrs, fdef->attrs);
446+
strs, repo, filter_session->attr_session, &attr_opts, src->path, fdef->nattrs, fdef->attrs);
447447

448448
/* if no values were found but no matches are needed, it's okay! */
449449
if (error == GIT_ENOTFOUND && !fdef->nmatches) {
@@ -492,13 +492,13 @@ int git_filter_list_new(
492492
return filter_list_new(out, &src);
493493
}
494494

495-
int git_filter_list__load_ext(
495+
int git_filter_list__load(
496496
git_filter_list **filters,
497497
git_repository *repo,
498498
git_blob *blob, /* can be NULL */
499499
const char *path,
500500
git_filter_mode_t mode,
501-
git_filter_options *filter_opts)
501+
git_filter_session *filter_session)
502502
{
503503
int error = 0;
504504
git_filter_list *fl = NULL;
@@ -515,7 +515,7 @@ int git_filter_list__load_ext(
515515
src.repo = repo;
516516
src.path = path;
517517
src.mode = mode;
518-
src.flags = filter_opts->flags;
518+
src.flags = filter_session->flags;
519519

520520
if (blob)
521521
git_oid_cpy(&src.oid, git_blob_id(blob));
@@ -529,7 +529,8 @@ int git_filter_list__load_ext(
529529

530530
if (fdef->nattrs > 0) {
531531
error = filter_list_check_attributes(
532-
&values, repo, filter_opts->attr_session, fdef, &src);
532+
&values, repo,
533+
filter_session, fdef, &src);
533534

534535
if (error == GIT_ENOTFOUND) {
535536
error = 0;
@@ -556,7 +557,7 @@ int git_filter_list__load_ext(
556557
if ((error = filter_list_new(&fl, &src)) < 0)
557558
break;
558559

559-
fl->temp_buf = filter_opts->temp_buf;
560+
fl->temp_buf = filter_session->temp_buf;
560561
}
561562

562563
fe = git_array_alloc(fl->filters);
@@ -588,12 +589,12 @@ int git_filter_list_load(
588589
git_filter_mode_t mode,
589590
uint32_t flags)
590591
{
591-
git_filter_options filter_opts = GIT_FILTER_OPTIONS_INIT;
592+
git_filter_session filter_session = GIT_FILTER_SESSION_INIT;
592593

593-
filter_opts.flags = flags;
594+
filter_session.flags = flags;
594595

595-
return git_filter_list__load_ext(
596-
filters, repo, blob, path, mode, &filter_opts);
596+
return git_filter_list__load(
597+
filters, repo, blob, path, mode, &filter_session);
597598
}
598599

599600
void git_filter_list_free(git_filter_list *fl)

src/filter.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@
1616
#define GIT_FILTER_BYTES_TO_CHECK_NUL 8000
1717

1818
typedef struct {
19+
uint32_t flags;
1920
git_attr_session *attr_session;
2021
git_buf *temp_buf;
21-
uint32_t flags;
22-
} git_filter_options;
22+
} git_filter_session;
2323

24-
#define GIT_FILTER_OPTIONS_INIT {0}
24+
#define GIT_FILTER_SESSION_INIT {0}
2525

2626
extern int git_filter_global_init(void);
2727

2828
extern void git_filter_free(git_filter *filter);
2929

30-
extern int git_filter_list__load_ext(
30+
extern int git_filter_list__load(
3131
git_filter_list **filters,
3232
git_repository *repo,
3333
git_blob *blob, /* can be NULL */
3434
const char *path,
3535
git_filter_mode_t mode,
36-
git_filter_options *filter_opts);
36+
git_filter_session *filter_session);
3737

3838
/*
3939
* The given input buffer will be converted to the given output buffer.

0 commit comments

Comments
 (0)