xs/Reflog.xs

filter: Statementstmt 53.5% 30 / 56 Branchbran 50.0% 13 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 52.4% 43 / 82 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« const-xs-stash-progress.inc ↑ Summary xs/Diff/File.xs »
1 MODULE = Git::Raw PACKAGE = Git::Raw::Reflog
2  
3 SV *
4 open(class, reference)
5 SV *class
6 SV *reference
7  
8 PREINIT:
9 int rc;
10  
11 Reference ref;
12 Reflog reflog;
13  
14 CODE:
15 2 ref = GIT_SV_TO_PTR(Reference, reference);
16  
17 2 rc = git_reflog_read(
18 &reflog,
19 git_reference_owner(ref),
20 git_reference_name(ref)
21 );
22 2 git_check_error(rc);
23  
24 4 GIT_NEW_OBJ_WITH_MAGIC(
25 RETVAL, SvPVbyte_nolen(class), reflog, reference
26 );
27  
28 OUTPUT: RETVAL
29  
30 void
31 delete(self)
32 SV *self
33  
34 PREINIT:
35 int rc;
36  
37 Reference ref;
38  
39 CODE:
40 0 ref = GIT_SV_TO_PTR(Reference, GIT_SV_TO_MAGIC(self));
41  
42 0 rc = git_reflog_delete(
43 git_reference_owner(ref), git_reference_name(ref)
44 );
45 0 git_check_error(rc);
46  
47 void
48 append(self, message, ...)
49 SV *self
50 const char *message
51  
52 PROTOTYPE: $$;$
53  
54 PREINIT:
55 int rc;
56  
57 git_oid id;
58 Signature sig;
59 Reference ref;
60 git_repository *ref_owner;
61  
62 CODE:
63 0 ref = GIT_SV_TO_PTR(Reference, GIT_SV_TO_MAGIC(self));
64 0 ref_owner = git_reference_owner(ref);
65  
66 0 rc = git_reference_name_to_id(
67 &id, ref_owner, git_reference_name(ref)
68 );
69 0 git_check_error(rc);
70  
71 0 ▶ if (items == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (items == 3) { 0 0 0
72 0 sig = GIT_SV_TO_PTR(Signature, ST(2));
73 } else {
74 0 rc = git_signature_default(&sig, ref_owner);
75 0 git_check_error(rc);
76 }
77  
78 0 rc = git_reflog_append(
79 0 GIT_SV_TO_PTR(Reflog, self),
80 &id, sig, message
81 );
82  
83 0 ▶ if (items != 3)
Branch: 1 branch
BranchTrueFalseTotal
if (items != 3) 0 0 0
84 0 git_signature_free(sig);
85  
86 0 git_check_error(rc);
87  
88 void
89 drop(self, index)
90 Reflog self
91 size_t index
92  
93 PREINIT:
94 int rc;
95  
96 CODE:
97 0 rc = git_reflog_drop(self, index, 1);
98 0 git_check_error(rc);
99  
100 void
101 write(self)
102 Reflog self
103  
104 PREINIT:
105 int rc;
106  
107 CODE:
108 0 rc = git_reflog_write(self);
109 0 git_check_error(rc);
110  
111 SV *
112 entry_count(self)
113 Reflog self
114  
115 PREINIT:
116 size_t count;
117  
118 CODE:
119 1 count = git_reflog_entrycount (self);
120 1 RETVAL = newSViv ((int) count);
121  
122 OUTPUT: RETVAL
123  
124 void
125 entries(self, ...)
126 SV *self
127  
128 PROTOTYPE: $;$$
129 PREINIT:
130 Reflog reflog;
131 2 size_t start = 0, end, entry_count;
132  
133 PPCODE:
134 2 reflog = GIT_SV_TO_PTR(Reflog, self);
135 2 entry_count = git_reflog_entrycount (reflog);
136  
137 2 ▶ if (items >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items >= 2) { 1 1 2
138 1 SV *index = ST(1);
139  
140 1 ▶ if (!SvIOK(index) || SvIV(index) < 0)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIOK(index) || SvIV(index) < 0) 1 0 1
if (!SvIOK(index) || SvIV(index) < 0) 0 1 1
141 0 croak_usage("Invalid type for 'index'");
142  
143 1 start = SvUV(index);
144 1 ▶ if (start >= entry_count)
Branch: 1 branch
BranchTrueFalseTotal
if (start >= entry_count) 0 1 1
145 0 croak_usage("index %" PRIuZ " out of range", start);
146  
147 1 ▶ if (items >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (items >= 3) { 1 0 1
148 1 SV *count = ST(2);
149 size_t retrieve_count;
150  
151 1 ▶ if (!SvIOK(count) || SvIV(count) < 0)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIOK(count) || SvIV(count) < 0) 1 0 1
if (!SvIOK(count) || SvIV(count) < 0) 0 1 1
152 0 croak_usage("Invalid type for 'count'");
153 1 ▶ if (SvIV(count) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (SvIV(count) == 0) 0 1 1
154 0 croak_usage("Invalid value for 'count'");
155  
156 1 retrieve_count = SvUV(count);
157 1 ▶ if ((start + retrieve_count) > entry_count)
Branch: 1 branch
BranchTrueFalseTotal
if ((start + retrieve_count) > entry_count) 0 1 1
158 0 croak_usage("count %" PRIuZ " out of range", retrieve_count);
159  
160 1 entry_count = retrieve_count;
161 } else
162 0 entry_count -= start;
163 }
164  
165 2 end = start + entry_count;
166  
167 5 ▶ for (; start < end; ++start) {
Branch: 1 branch
BranchTrueFalseTotal
for (; start < end; ++start) { 3 2 5
168 3 SV *entry = NULL;
169  
170 const git_reflog_entry *e =
171 3 git_reflog_entry_byindex(reflog, start);
172  
173 3 GIT_NEW_OBJ_WITH_MAGIC(
174 entry, "Git::Raw::Reflog::Entry",
175 (Reflog_Entry) e, SvRV(self)
176 );
177  
178 3 ▶ mXPUSHs(entry);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(entry); 0 3 3
179 }
180  
181 2 XSRETURN(entry_count);
182  
183 void
184 DESTROY(self)
185 SV *self
186  
187 CODE:
188 2 git_reflog_free(GIT_SV_TO_PTR(Reflog, self));
189 2 SvREFCNT_dec(GIT_SV_TO_MAGIC(self));
« const-xs-stash-progress.inc ↑ Summary xs/Diff/File.xs »