Hook up filter initialize callback I knew I forgot something
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
diff --git a/include/git2/sys/filter.h b/include/git2/sys/filter.h
index ca1fbfc..dbb086b 100644
--- a/include/git2/sys/filter.h
+++ b/include/git2/sys/filter.h
@@ -139,7 +139,9 @@ typedef void (*git_filter_cleanup_fn)(
*/
struct git_filter {
unsigned int version;
+
const char *attributes;
+
git_filter_init_fn initialize;
git_filter_shutdown_fn shutdown;
git_filter_check_fn check;
diff --git a/src/filter.c b/src/filter.c
index de0d490..0500146 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -39,6 +39,7 @@ typedef struct {
const char *filter_name;
git_filter *filter;
int priority;
+ int initialized;
size_t nattrs, nmatches;
char *attrdata;
const char *attrs[GIT_FLEX_ARRAY];
@@ -178,6 +179,23 @@ static git_filter_def *filter_find_by_name(size_t *pos, const char *name)
return fdef;
}
+static int filter_initialize(git_filter_def *fdef)
+{
+ int error = 0;
+
+ if (!fdef->initialized &&
+ fdef->filter &&
+ fdef->filter->initialize &&
+ (error = fdef->filter->initialize(fdef->filter)) < 0)
+ {
+ git_filter_unregister(fdef->filter_name);
+ return error;
+ }
+
+ fdef->initialized = true;
+ return 0;
+}
+
int git_filter_unregister(const char *name)
{
size_t pos;
@@ -196,8 +214,10 @@ int git_filter_unregister(const char *name)
(void)git_vector_remove(&git__filter_registry, pos);
- if (fdef->filter->shutdown)
+ if (fdef->initialized && fdef->filter && fdef->filter->shutdown) {
fdef->filter->shutdown(fdef->filter);
+ fdef->initialized = false;
+ }
git__free(fdef->attrdata);
git__free(fdef);
@@ -209,7 +229,14 @@ git_filter *git_filter_lookup(const char *name)
{
size_t pos;
git_filter_def *fdef = filter_find_by_name(&pos, name);
- return fdef ? fdef->filter : NULL;
+
+ if (!fdef)
+ return NULL;
+
+ if (!fdef->initialized && filter_initialize(fdef) < 0)
+ return NULL;
+
+ return fdef->filter;
}
static int filter_load_defaults(void)
@@ -341,6 +368,9 @@ int git_filter_list_load(
break;
}
+ if (!fdef->initialized && (error = filter_initialize(fdef)) < 0)
+ break;
+
if (fdef->filter->check)
error = fdef->filter->check(
fdef->filter, &payload, &src, values);