forked from RogerGee/php-git2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob.h
355 lines (318 loc) · 10.1 KB
/
blob.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*
* blob.h
*
* Copyright (C) Roger P. Gee
*/
#ifndef PHPGIT2_BLOB_H
#define PHPGIT2_BLOB_H
namespace php_git2
{
// Explicitly specialize git2_resource destructor for git_blob.
template<> php_git_blob::~git2_resource()
{
git_blob_free(handle);
}
// Provide a rethandler for git_blob_rawcontent().
class php_git_blob_rawcontent_rethandler
{
using PackType = local_pack<php_resource<php_git_blob> >;
public:
bool ret(const void* retval,zval* return_value,PackType& pack)
{
if (retval != nullptr) {
// Make a binary string for the return value. The length is
// obtained from the blob attached to the local_pack.
size_t length;
const git_blob* blob = pack.get<0>().get_object()->get_handle();
length = git_blob_rawsize(blob);
RETVAL_STRINGL((const char*)retval,length);
}
else {
RETVAL_NULL();
}
return true;
}
};
// Provide types for getting/returning git_writestream objects.
class php_git_writestream_byval:
public php_object<php_writestream_object>
{
public:
git_writestream* byval_git2()
{
php_writestream_object* object = get_storage();
if (object->ws == nullptr) {
throw php_git2_exception("The writestream has already been closed");
}
return object->ws;
}
};
class php_git_writestream_byref
{
public:
php_git_writestream_byref():
ws(nullptr)
{
}
git_writestream** byval_git2()
{
return &ws;
}
void ret(zval* return_value)
{
// Wrap the git_writestream in an object zval.
php_git2_make_writestream(return_value,ws);
}
private:
git_writestream* ws;
};
// Provide a git_writestream type that releases the git_writestream after
// passing it to git2.
class php_git_writestream_release:
public php_git_writestream_byval
{
public:
git_writestream* byval_git2()
{
php_writestream_object* object = get_storage();
if (object->ws == nullptr) {
throw php_git2_exception("The writestream has already been closed");
}
auto ws = object->ws;
object->ws = nullptr;
return ws;
}
};
} // namespace php_git2
#endif
static constexpr auto ZIF_GIT_BLOB_CREATE_FROMBUFFER = zif_php_git2_function<
php_git2::func_wrapper<
int,
git_oid*,
git_repository*,
const void*,
size_t
>::func<git_blob_create_frombuffer>,
php_git2::local_pack<
php_git2::php_git_oid,
php_git2::php_resource<php_git2::php_git_repository>,
php_git2::connector_wrapper<php_git2::php_string_length_connector<size_t> >,
php_git2::php_string
>,
1,
php_git2::sequence<1,3>,
php_git2::sequence<0,1,3,2>
>;
static constexpr auto ZIF_GIT_BLOB_CREATE_FROMDISK = zif_php_git2_function<
php_git2::func_wrapper<
int,
git_oid*,
git_repository*,
const char*
>::func<git_blob_create_fromdisk>,
php_git2::local_pack<
php_git2::php_git_oid,
php_git2::php_resource<php_git2::php_git_repository>,
php_git2::php_string
>,
1,
php_git2::sequence<1,2>,
php_git2::sequence<0,1,2>
>;
static constexpr auto ZIF_GIT_BLOB_CREATE_FROMWORKDIR = zif_php_git2_function<
php_git2::func_wrapper<
int,
git_oid*,
git_repository*,
const char*
>::func<git_blob_create_fromworkdir>,
php_git2::local_pack<
php_git2::php_git_oid,
php_git2::php_resource<php_git2::php_git_repository>,
php_git2::php_string
>,
1,
php_git2::sequence<1,2>,
php_git2::sequence<0,1,2>
>;
static constexpr auto ZIF_GIT_BLOB_FILTERED_CONTENT = zif_php_git2_function<
php_git2::func_wrapper<
int,
git_buf*,
git_blob*,
const char*,
int
>::func<git_blob_filtered_content>,
php_git2::local_pack<
php_git2::php_git_buf,
php_git2::php_resource<php_git2::php_git_blob>,
php_git2::php_string,
php_git2::php_bool
>,
1,
php_git2::sequence<1,2,3>,
php_git2::sequence<0,1,2,3>
>;
static constexpr auto ZIF_GIT_BLOB_FREE = zif_php_git2_function_free<
php_git2::local_pack<
php_git2::php_resource_cleanup<php_git2::php_git_blob>
>
>;
static constexpr auto ZIF_GIT_BLOB_ID = zif_php_git2_function<
php_git2::func_wrapper<
const git_oid*,
const git_blob*
>::func<git_blob_id>,
php_git2::local_pack<
php_git2::php_resource<php_git2::php_git_blob>
>,
0
>;
static constexpr auto ZIF_GIT_BLOB_IS_BINARY = zif_php_git2_function_rethandler<
php_git2::func_wrapper<
int,
const git_blob*
>::func<git_blob_is_binary>,
php_git2::local_pack<
php_git2::php_resource<php_git2::php_git_blob>
>,
php_git2::php_boolean_rethandler<int>
>;
static constexpr auto ZIF_GIT_BLOB_LOOKUP = zif_php_git2_function_setdeps<
php_git2::func_wrapper<
int,
git_blob**,
git_repository*,
const git_oid*
>::func<git_blob_lookup>,
php_git2::local_pack<
php_git2::php_resource_ref<php_git2::php_git_blob>,
php_git2::php_resource<php_git2::php_git_repository>,
php_git2::php_git_oid_fromstr
>,
php_git2::sequence<0,1>,
1,
php_git2::sequence<1,2>,
php_git2::sequence<0,1,2>
>;
static constexpr auto ZIF_GIT_BLOB_LOOKUP_PREFIX = zif_php_git2_function_setdeps<
php_git2::func_wrapper<
int,
git_blob**,
git_repository*,
const git_oid*,
size_t
>::func<git_blob_lookup_prefix>,
php_git2::local_pack<
php_git2::php_resource_ref<php_git2::php_git_blob>,
php_git2::php_resource<php_git2::php_git_repository>,
php_git2::connector_wrapper<php_git2::php_string_length_connector<
size_t,php_git2::php_git_oid_fromstr> >,
php_git2::php_git_oid_fromstr
>,
php_git2::sequence<0,1>,
1,
php_git2::sequence<1,3>,
php_git2::sequence<0,1,3,2>
>;
static constexpr auto ZIF_GIT_BLOB_OWNER = zif_php_git2_function_rethandler<
php_git2::func_wrapper<
git_repository*,
const git_blob*
>::func<git_blob_owner>,
php_git2::local_pack<
php_git2::php_resource<php_git2::php_git_blob>,
php_git2::php_resource_ref<php_git2::php_git_repository_nofree>
>,
php_git2::php_owner_rethandler<php_git2::php_git_blob>,
php_git2::sequence<0>,
php_git2::sequence<0>
>;
static constexpr auto ZIF_GIT_BLOB_RAWCONTENT = zif_php_git2_function_rethandler<
php_git2::func_wrapper<
const void*,
const git_blob*
>::func<git_blob_rawcontent>,
php_git2::local_pack<
php_git2::php_resource<php_git2::php_git_blob>
>,
php_git2::php_git_blob_rawcontent_rethandler
>;
static constexpr auto ZIF_GIT_BLOB_RAWSIZE = zif_php_git2_function<
php_git2::func_wrapper<
git_object_size_t,
const git_blob*
>::func<git_blob_rawsize>,
php_git2::local_pack<
php_git2::php_resource<php_git2::php_git_blob>
>,
0
>;
static constexpr auto ZIF_GIT_BLOB_DUP = zif_php_git2_function_setdeps<
php_git2::func_wrapper<
int,
git_blob**,
git_blob*
>::func<git_blob_dup>,
php_git2::local_pack<
php_git2::php_resource_ref<php_git2::php_git_blob>,
php_git2::php_resource<php_git2::php_git_blob>
>,
php_git2::sequence<0,1>,
1,
php_git2::sequence<1>,
php_git2::sequence<0,1>
>;
static constexpr auto ZIF_GIT_BLOB_CREATE_FROMSTREAM = zif_php_git2_function<
php_git2::func_wrapper<
int,
git_writestream**,
git_repository*,
const char*
>::func<git_blob_create_fromstream>,
php_git2::local_pack<
php_git2::php_git_writestream_byref,
php_git2::php_resource<php_git2::php_git_repository>,
php_git2::php_string_nullable
>,
1,
php_git2::sequence<1,2>,
php_git2::sequence<0,1,2>
>;
static constexpr auto ZIF_GIT_BLOB_CREATE_FROMSTREAM_COMMIT = zif_php_git2_function<
php_git2::func_wrapper<
int,
git_oid*,
git_writestream*
>::func<git_blob_create_fromstream_commit>,
php_git2::local_pack<
php_git2::php_git_oid,
php_git2::php_git_writestream_release
>,
1,
php_git2::sequence<1>,
php_git2::sequence<0,1>
>;
#define GIT_BLOB_FE \
PHP_GIT2_FE(git_blob_create_frombuffer,ZIF_GIT_BLOB_CREATE_FROMBUFFER,NULL) \
PHP_GIT2_FE(git_blob_create_fromdisk,ZIF_GIT_BLOB_CREATE_FROMDISK,NULL) \
PHP_GIT2_FE(git_blob_create_fromworkdir,ZIF_GIT_BLOB_CREATE_FROMWORKDIR,NULL) \
PHP_GIT2_FE(git_blob_filtered_content,ZIF_GIT_BLOB_FILTERED_CONTENT,NULL) \
PHP_GIT2_FE(git_blob_free,ZIF_GIT_BLOB_FREE,NULL) \
PHP_GIT2_FE(git_blob_id,ZIF_GIT_BLOB_ID,NULL) \
PHP_GIT2_FE(git_blob_is_binary,ZIF_GIT_BLOB_IS_BINARY,NULL) \
PHP_GIT2_FE(git_blob_lookup,ZIF_GIT_BLOB_LOOKUP,NULL) \
PHP_GIT2_FE(git_blob_lookup_prefix,ZIF_GIT_BLOB_LOOKUP_PREFIX,NULL) \
PHP_GIT2_FE(git_blob_owner,ZIF_GIT_BLOB_OWNER,NULL) \
PHP_GIT2_FE(git_blob_rawcontent,ZIF_GIT_BLOB_RAWCONTENT,NULL) \
PHP_GIT2_FE(git_blob_rawsize,ZIF_GIT_BLOB_RAWSIZE,NULL) \
PHP_GIT2_FE(git_blob_dup,ZIF_GIT_BLOB_DUP,NULL) \
PHP_GIT2_FE(git_blob_create_fromstream,ZIF_GIT_BLOB_CREATE_FROMSTREAM,NULL) \
PHP_GIT2_FE(git_blob_create_fromstream_commit,ZIF_GIT_BLOB_CREATE_FROMSTREAM_COMMIT,NULL)
/*
* Local Variables:
* mode:c++
* indent-tabs-mode:nil
* tab-width:4
* End:
*/