xs/Graph.xs

filter: Statementstmt 8.0% 9 / 112 Branchbran 12.0% 6 / 50 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 9.2% 15 / 162 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/Cert/HostKey.xs ↑ Summary xs/Remote.xs »
1 MODULE = Git::Raw PACKAGE = Git::Raw::Graph
2  
3 void
4 ahead(class, repo, local, upstream)
5 SV *class
6 SV *repo
7 SV *local
8 SV *upstream
9  
10 PREINIT:
11 int ctx;
12  
13 Repository repo_ptr;
14  
15 size_t ahead, behind;
16 git_oid local_id, upstream_id;
17  
18 PPCODE:
19 0 ctx = GIMME_V;
20  
21 0 ▶ if (ctx != G_VOID) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx != G_VOID) { 0 0 0
22 int rc;
23  
24 0 repo_ptr = GIT_SV_TO_PTR(Repository, repo);
25 0 ▶ if (git_sv_to_commitish(repo_ptr -> repository, local, &local_id) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (git_sv_to_commitish(repo_ptr -> repository, local, &local_id) == NULL) 0 0 0
26 0 croak_resolve("Could not resolve 'local' to a commit id");
27  
28 0 ▶ if (git_sv_to_commitish(repo_ptr -> repository, upstream, &upstream_id) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (git_sv_to_commitish(repo_ptr -> repository, upstream, &upstream_id) == NULL) 0 0 0
29 0 croak_resolve("Could not resolve 'upstream' to a commit id");
30  
31 0 rc = git_graph_ahead_behind(
32 &ahead, &behind,
33 repo_ptr -> repository,
34 &local_id, &upstream_id
35 );
36 0 git_check_error(rc);
37  
38 0 ▶ if (ctx == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx == G_ARRAY) { 0 0 0
39 0 git_revwalk *walker = NULL;
40 size_t i;
41  
42 0 rc = git_revwalk_new(&walker, repo_ptr -> repository);
43 0 git_check_error(rc);
44  
45 0 rc = git_revwalk_push(walker, &local_id);
46 0 git_check_error(rc);
47  
48 0 git_revwalk_sorting(walker, GIT_SORT_TOPOLOGICAL);
49 0 ▶ for (i = 0; i < ahead; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ahead; ++i) { 0 0 0
50 git_oid commit_id;
51 Commit commit;
52 0 SV *c = NULL;
53  
54 0 rc = git_revwalk_next(&commit_id, walker);
55 0 git_check_error(rc);
56  
57 0 rc = git_commit_lookup(
58 &commit, repo_ptr -> repository,
59 &commit_id
60 );
61 0 git_check_error(rc);
62  
63 0 GIT_NEW_OBJ_WITH_MAGIC(
64 c, "Git::Raw::Commit", commit, SvRV(repo)
65 );
66  
67 0 ▶ mXPUSHs(c);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(c); 0 0 0
68 }
69  
70 0 git_revwalk_free(walker);
71 0 XSRETURN((int) ahead);
72 } else {
73 0 ▶ mXPUSHs(newSViv((int) ahead));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSViv((int) ahead)); 0 0 0
74 0 XSRETURN(1);
75 }
76 } else
77 0 XSRETURN_EMPTY;
78  
79 void
80 behind(class, repo, local, upstream)
81 SV *class
82 SV *repo
83 SV *local
84 SV *upstream
85  
86 PREINIT:
87 int ctx;
88  
89 Repository repo_ptr;
90  
91 size_t ahead, behind;
92 git_oid local_id, upstream_id;
93  
94 PPCODE:
95 0 ctx = GIMME_V;
96  
97 0 ▶ if (ctx != G_VOID) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx != G_VOID) { 0 0 0
98 int rc;
99  
100 0 repo_ptr = GIT_SV_TO_PTR(Repository, repo);
101 0 ▶ if (git_sv_to_commitish(repo_ptr -> repository, local, &local_id) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (git_sv_to_commitish(repo_ptr -> repository, local, &local_id) == NULL) 0 0 0
102 0 croak_resolve("Could not resolve 'local' to a commit id");
103  
104 0 ▶ if (git_sv_to_commitish(repo_ptr -> repository, upstream, &upstream_id) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (git_sv_to_commitish(repo_ptr -> repository, upstream, &upstream_id) == NULL) 0 0 0
105 0 croak_resolve("Could not resolve 'upstream' to a commit id");
106  
107 0 rc = git_graph_ahead_behind(
108 &ahead, &behind,
109 repo_ptr -> repository,
110 &local_id, &upstream_id
111 );
112 0 git_check_error(rc);
113  
114 0 ▶ if (ctx == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx == G_ARRAY) { 0 0 0
115 0 git_revwalk *walker = NULL;
116 size_t i;
117  
118 0 rc = git_revwalk_new(&walker, repo_ptr -> repository);
119 0 git_check_error(rc);
120  
121 0 rc = git_revwalk_push(walker, &upstream_id);
122 0 git_check_error(rc);
123  
124 0 git_revwalk_sorting(walker, GIT_SORT_TOPOLOGICAL);
125 0 ▶ for (i = 0; i < behind; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < behind; ++i) { 0 0 0
126 git_oid commit_id;
127 Commit commit;
128 0 SV *c = NULL;
129  
130 0 rc = git_revwalk_next(&commit_id, walker);
131 0 git_check_error(rc);
132  
133 0 rc = git_commit_lookup(
134 &commit, repo_ptr -> repository,
135 &commit_id
136 );
137 0 git_check_error(rc);
138  
139 0 GIT_NEW_OBJ_WITH_MAGIC(
140 c, "Git::Raw::Commit", commit, SvRV(repo)
141 );
142  
143 0 ▶ mXPUSHs(c);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(c); 0 0 0
144 }
145  
146 0 git_revwalk_free(walker);
147 0 XSRETURN((int) behind);
148 } else {
149 0 ▶ mXPUSHs(newSViv((int) behind));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSViv((int) behind)); 0 0 0
150 0 XSRETURN(1);
151 }
152 } else
153 0 XSRETURN_EMPTY;
154  
155 SV *
156 ahead_behind(class, repo, local, upstream)
157 SV *class
158 SV *repo
159 SV *local
160 SV *upstream
161  
162 PREINIT:
163 int rc;
164  
165 Repository repo_ptr;
166  
167 size_t i, ahead, behind;
168 git_oid local_id, upstream_id;
169  
170 0 git_revwalk *walker = NULL;
171 0 HV *r = NULL;
172 0 AV *a = NULL, *b = NULL;
173  
174 CODE:
175 0 repo_ptr = GIT_SV_TO_PTR(Repository, repo);
176 0 ▶ if (git_sv_to_commitish(repo_ptr -> repository, local, &local_id) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (git_sv_to_commitish(repo_ptr -> repository, local, &local_id) == NULL) 0 0 0
177 0 croak_resolve("Could not resolve 'local' to a commit id");
178  
179 0 ▶ if (git_sv_to_commitish(repo_ptr -> repository, upstream, &upstream_id) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (git_sv_to_commitish(repo_ptr -> repository, upstream, &upstream_id) == NULL) 0 0 0
180 0 croak_resolve("Could not resolve 'upstream' to a commit id");
181  
182 0 rc = git_graph_ahead_behind(
183 &ahead, &behind,
184 repo_ptr -> repository,
185 &local_id, &upstream_id
186 );
187 0 git_check_error(rc);
188  
189 0 r = newHV();
190 0 ▶ if (ahead > 0 || behind > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (ahead > 0 || behind > 0) { 0 0 0
if (ahead > 0 || behind > 0) { 0 0 0
191 git_oid commit_id;
192 Commit commit;
193 0 SV *c = NULL;
194  
195 0 rc = git_revwalk_new(&walker, repo_ptr -> repository);
196 0 git_check_error(rc);
197  
198 0 ▶ if (ahead > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ahead > 0) { 0 0 0
199 0 git_revwalk_reset(walker);
200 0 git_revwalk_sorting(walker, GIT_SORT_TOPOLOGICAL);
201 0 rc = git_revwalk_push(walker, &local_id);
202 0 git_check_error(rc);
203  
204 0 a = newAV();
205 0 ▶ for (i = 0; i < ahead; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ahead; ++i) { 0 0 0
206 0 rc = git_revwalk_next(&commit_id, walker);
207 0 git_check_error(rc);
208  
209 0 rc = git_commit_lookup(
210 &commit, repo_ptr -> repository,
211 &commit_id
212 );
213 0 git_check_error(rc);
214  
215 0 GIT_NEW_OBJ_WITH_MAGIC(
216 c, "Git::Raw::Commit", commit, SvRV(repo)
217 );
218 0 av_push(a, c);
219 }
220  
221 0 hv_stores(r, "ahead", newRV_noinc((SV *) a));
222 }
223  
224 0 ▶ if (behind > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (behind > 0) { 0 0 0
225 0 git_revwalk_reset(walker);
226 0 git_revwalk_sorting(walker, GIT_SORT_TOPOLOGICAL);
227 0 rc = git_revwalk_push(walker, &upstream_id);
228 0 git_check_error(rc);
229  
230 0 b = newAV();
231 0 ▶ for (i = 0; i < behind; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < behind; ++i) { 0 0 0
232 0 rc = git_revwalk_next(&commit_id, walker);
233 0 git_check_error(rc);
234  
235 0 rc = git_commit_lookup(
236 &commit, repo_ptr -> repository,
237 &commit_id
238 );
239 0 git_check_error(rc);
240  
241 0 GIT_NEW_OBJ_WITH_MAGIC(
242 c, "Git::Raw::Commit", commit, SvRV(repo)
243 );
244 0 av_push(b, c);
245 }
246  
247 0 hv_stores(r, "behind", newRV_noinc((SV *) b));
248 }
249 }
250  
251 0 git_revwalk_free(walker);
252 0 RETVAL = newRV_noinc((SV *) r);
253  
254 OUTPUT: RETVAL
255  
256 SV *
257 is_descendant_of(class, repo, commitish, ancestor)
258 SV *class
259 Repository repo
260 SV *commitish
261 SV *ancestor
262  
263 PREINIT:
264 13 int result = 0;
265  
266 git_oid commitish_id, ancestor_id;
267  
268 CODE:
269 13 ▶ if (git_sv_to_commitish(repo -> repository, commitish, &commitish_id) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (git_sv_to_commitish(repo -> repository, commitish, &commitish_id) == NULL) 1 12 13
270 1 croak_resolve("Could not resolve 'commitish' to a commit id");
271  
272 12 ▶ if (git_sv_to_commitish(repo -> repository, ancestor, &ancestor_id) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (git_sv_to_commitish(repo -> repository, ancestor, &ancestor_id) == NULL) 1 11 12
273 1 croak_resolve("Could not resolve 'ancestor' to a commit id");
274  
275 11 result = git_graph_descendant_of(repo -> repository, &commitish_id, &ancestor_id);
276 11 ▶ if (result < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (result < 0) 1 10 11
277 {
278 1 git_check_error(result);
279 }
280  
281 10 RETVAL = newSViv(result);
282  
283 OUTPUT: RETVAL
« xs/Cert/HostKey.xs ↑ Summary xs/Remote.xs »