forked from RogerGee/php-git2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refdb.h
186 lines (157 loc) · 5.15 KB
/
refdb.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* refdb.h
*
* Copyright (C) Roger P. Gee
*/
#ifndef PHPGIT2_REFDB_H
#define PHPGIT2_REFDB_H
namespace php_git2
{
// Explicitly specialize git2_resource destructor for git_repository.
template<> php_git_refdb::~git2_resource()
{
git_refdb_free(handle);
}
// Provide type for passing/returning git_refdb_backends.
class php_git_refdb_backend:
public php_object<php_refdb_backend_object>
{
public:
// Make this object a connector to a php_resource that looks up a
// php_git_refdb resource wrapper object.
using connect_t = php_resource<php_git_refdb>;
using target_t = git_refdb_backend*;
php_git_refdb_backend(connect_t& conn):
ownerWrapper(conn)
{
}
git_refdb_backend* byval_git2()
{
php_refdb_backend_object* object = get_storage();
// If the object doesn't have a backing, then we create a custom
// one.
if (object->backend == nullptr) {
object->create_custom_backend(get_value());
}
// If the object has a custom backing then it is (presumably)
// already set on a refdb. (The same is true if the owner is already
// set.)
else if (object->kind != php_refdb_backend_object::user
|| object->owner != nullptr)
{
throw php_git2_exception("The refdb backend is already set on a refdb");
}
// Otherwise the object is a user backend and we make it into a
// conventional backend.
else {
object->create_conventional_backend(ownerWrapper.get_object());
}
return object->backend;
}
private:
connect_t& ownerWrapper;
};
class php_git_refdb_backend_ref
{
public:
php_git_refdb_backend_ref():
backend(nullptr)
{
}
git_refdb_backend** byval_git2()
{
return &backend;
}
void ret(zval* return_value)
{
php_git2_make_refdb_backend(return_value,backend,nullptr);
}
private:
git_refdb_backend* backend;
};
using php_git_refdb_backend_connector = connector_wrapper<php_git_refdb_backend>;
} // namespace php_git2
// Function templates:
static constexpr auto ZIF_GIT_REFDB_BACKEND_FS = zif_php_git2_function<
php_git2::func_wrapper<
int,
git_refdb_backend**,
git_repository*>::func<git_refdb_backend_fs>,
php_git2::local_pack<
php_git2::php_git_refdb_backend_ref,
php_git2::php_resource<php_git2::php_git_repository>
>,
1,
php_git2::sequence<1>,
php_git2::sequence<0,1>
>;
static constexpr auto ZIF_GIT_REFDB_COMPRESS = zif_php_git2_function<
php_git2::func_wrapper<
int,
git_refdb*>::func<git_refdb_compress>,
php_git2::local_pack<
php_git2::php_resource<php_git2::php_git_refdb>
>
>;
static constexpr auto ZIF_GIT_REFDB_FREE = zif_php_git2_function_free<
php_git2::local_pack<
php_git2::php_resource_cleanup<php_git2::php_git_refdb>
>
>;
static constexpr auto ZIF_GIT_REFDB_NEW = zif_php_git2_function_setdeps<
php_git2::func_wrapper<
int,
git_refdb**,
git_repository*>::func<git_refdb_new>,
php_git2::local_pack<
php_git2::php_resource_ref<php_git2::php_git_refdb>,
php_git2::php_resource<php_git2::php_git_repository>
>,
php_git2::sequence<0,1>, // Make the git_refdb dependent on the repository.
1,
php_git2::sequence<1>,
php_git2::sequence<0,1>
>;
static constexpr auto ZIF_GIT_REFDB_OPEN = zif_php_git2_function_setdeps<
php_git2::func_wrapper<
int,
git_refdb**,
git_repository*>::func<git_refdb_open>,
php_git2::local_pack<
php_git2::php_resource_ref<php_git2::php_git_refdb>,
php_git2::php_resource<php_git2::php_git_repository>
>,
php_git2::sequence<0,1>, // Make the git_refdb dependent on the repository.
1,
php_git2::sequence<1>,
php_git2::sequence<0,1>
>;
static constexpr auto ZIF_GIT_REFDB_SET_BACKEND = zif_php_git2_function<
php_git2::func_wrapper<
int,
git_refdb*,
git_refdb_backend*>::func<git_refdb_set_backend>,
php_git2::local_pack<
php_git2::php_git_refdb_backend_connector,
php_git2::php_resource<php_git2::php_git_refdb>
>,
-1,
php_git2::sequence<1,0>,
php_git2::sequence<1,0>
>;
// Function entries:
#define GIT_REFDB_FE \
PHP_GIT2_FE(git_refdb_backend_fs,ZIF_GIT_REFDB_BACKEND_FS,NULL) \
PHP_GIT2_FE(git_refdb_compress,ZIF_GIT_REFDB_COMPRESS,NULL) \
PHP_GIT2_FE(git_refdb_free,ZIF_GIT_REFDB_FREE,NULL) \
PHP_GIT2_FE(git_refdb_new,ZIF_GIT_REFDB_NEW,NULL) \
PHP_GIT2_FE(git_refdb_open,ZIF_GIT_REFDB_OPEN,NULL) \
PHP_GIT2_FE(git_refdb_set_backend,ZIF_GIT_REFDB_SET_BACKEND,NULL)
#endif
/*
* Local Variables:
* mode:c++
* indent-tabs-mode:nil
* tab-width:4
* End:
*/