File: Odb.xs

package info (click to toggle)
libgit-raw-perl 0.90%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,540 kB
  • sloc: perl: 5,432; ansic: 182; makefile: 6
file content (216 lines) | stat: -rw-r--r-- 3,022 bytes parent folder | download | duplicates (4)
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
MODULE = Git::Raw			PACKAGE = Git::Raw::Odb

Odb
new(class)
	SV *class

	PREINIT:
		int rc;
		Odb out;
		git_odb *odb;

	CODE:
		rc = git_odb_new(&odb);
		git_check_error(rc);

		Newxz(out, 1, git_raw_odb);
		out -> odb = odb;
		RETVAL = out;

	OUTPUT: RETVAL

Odb
open(class, directory)
	SV *class
	SV *directory

	PREINIT:
		int rc;
		Odb out;
		git_odb *odb;

	CODE:
		rc = git_odb_open(&odb,
			git_ensure_pv(directory, "directory")
		);
		git_check_error(rc);

		Newxz(out, 1, git_raw_odb);
		out -> odb = odb;
		RETVAL = out;

	OUTPUT: RETVAL

void
add_backend(self, backend, priority)
	Odb self
	SV *backend
	int priority

	PREINIT:
		int rc;

	CODE:
		rc = git_odb_add_backend(self -> odb,
			GIT_SV_TO_PTR(Odb::Backend, backend),
			priority
		);
		git_check_error(rc);

		if (!self -> backends)
			self -> backends = newAV();

		av_push(self -> backends, SvRV(backend));
		SvREFCNT_inc_NN(SvRV(backend));

void
add_alternate(self, backend, priority)
	Odb self
	SV *backend
	int priority

	PREINIT:
		int rc;

	CODE:
		rc = git_odb_add_alternate(self -> odb,
			GIT_SV_TO_PTR(Odb::Backend, backend),
			priority
		);
		git_check_error(rc);

		if (!self -> backends)
			self -> backends = newAV();

		av_push(self -> backends, SvRV(backend));
		SvREFCNT_inc_NN(SvRV(backend));

SV *
backend_count(self)
	Odb self

	CODE:
		RETVAL = newSVuv(git_odb_num_backends(self -> odb));

	OUTPUT: RETVAL

void
foreach(self, cb)
	Odb self
	SV *cb

	PREINIT:
		int rc;

	CODE:
		rc = git_odb_foreach(self -> odb,
			git_odb_foreach_cbb,
			git_ensure_cv(cb, "callback")
		);
		if (rc != GIT_EUSER)
			git_check_error(rc);

Odb_Object
read(self, id)
	Odb self
	SV *id

	PREINIT:
		int rc;

		git_oid oid;

		STRLEN len;
		const char *id_str;

		Odb_Object obj;

	INIT:
		id_str = git_ensure_pv_with_len(id, "id", &len);

	CODE:
		rc = git_oid_fromstrn(&oid, id_str, len);
		git_check_error(rc);

		rc = git_odb_read_prefix(&obj, self -> odb, &oid, len);
		if (rc == GIT_ENOTFOUND)
			XSRETURN_UNDEF;
		git_check_error(rc);

		RETVAL = obj;

	OUTPUT: RETVAL

SV *
write(self, data, type)
	Odb self
	SV *data
	SV *type

	PREINIT:
		int rc;
		git_oid id;

		STRLEN len;
		const char *d;

	CODE:
		d = git_ensure_pv_with_len(data, "data", &len);

		rc = git_odb_write(&id, self -> odb, d, len,
			git_ensure_iv(type, "type")
		);
		git_check_error(rc);

		RETVAL = git_oid_to_sv(&id);

	OUTPUT: RETVAL

void
refresh(self)
	Odb self

	CODE:
		git_odb_refresh(self -> odb);

SV *
hash (self, data, type)
	SV *self
	SV *data
	SV *type

	PREINIT:
		int rc;
		git_oid id;

		STRLEN len;
		const char *d;

	CODE:
		d = git_ensure_pv_with_len(data, "data", &len);

		rc = git_odb_hash(&id, d, len,
			git_ensure_iv(type, "type")
		);
		git_check_error(rc);

		RETVAL = git_oid_to_sv(&id);

	OUTPUT: RETVAL

void
DESTROY(self)
	SV* self

	PREINIT:
		Odb odb;

	CODE:
		odb = GIT_SV_TO_PTR(Odb, self);
		git_odb_free(odb -> odb);

		if (odb -> backends)
			av_undef(odb -> backends);

		Safefree(odb);
		SvREFCNT_dec(GIT_SV_TO_MAGIC(self));