| 1 |
|
| MODULE = Git::Raw PACKAGE = Git::Raw::Reference |
| 2 |
|
| |
| 3 |
|
| SV * |
| 4 |
|
| annotated_commit(self) |
| 5 |
|
| SV *self |
| 6 |
|
| |
| 7 |
|
| PREINIT: |
| 8 |
|
| int rc; |
| 9 |
|
| |
| 10 |
|
| SV *repo; |
| 11 |
|
| AnnotatedCommit commit; |
| 12 |
|
| Repository repo_ptr; |
| 13 |
|
| |
| 14 |
|
| CODE: |
| 15 |
3 |
| repo = GIT_SV_TO_MAGIC(self); |
| 16 |
3 |
| repo_ptr = INT2PTR(Repository, SvIV((SV *) repo)); |
| 17 |
|
| |
| 18 |
3 |
| rc = git_annotated_commit_from_ref(&commit, |
| 19 |
|
| repo_ptr -> repository, |
| 20 |
3 |
| GIT_SV_TO_PTR(Reference, self)); |
| 21 |
3 |
| git_check_error(rc); |
| 22 |
|
| |
| 23 |
3 |
| GIT_NEW_OBJ_WITH_MAGIC( |
| 24 |
|
| RETVAL, "Git::Raw::AnnotatedCommit", |
| 25 |
|
| commit, repo |
| 26 |
|
| ); |
| 27 |
|
| |
| 28 |
|
| OUTPUT: RETVAL |
| 29 |
|
| |
| 30 |
|
| SV * |
| 31 |
|
| create(class, name, repo, object, ...) |
| 32 |
|
| const char *class |
| 33 |
|
| const char *name |
| 34 |
|
| SV *repo |
| 35 |
|
| SV *object |
| 36 |
|
| |
| 37 |
|
| PREINIT: |
| 38 |
14 |
| int rc, force = 0; |
| 39 |
14 |
| int symbolic = 0; |
| 40 |
|
| |
| 41 |
|
| Repository repo_ptr; |
| 42 |
|
| Reference ref; |
| 43 |
|
| const git_oid *oid; |
| 44 |
|
| |
| 45 |
|
| CODE: |
| 46 |
14 |
▶ | if (items > 4) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 4) |
11 |
3 |
14 |
|
| 47 |
11 |
| force = SvTRUE(ST(4)); |
| 48 |
|
| |
| 49 |
14 |
▶ | if (items > 5) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 5) |
7 |
7 |
14 |
|
| 50 |
7 |
| symbolic = SvTRUE(ST(5)); |
| 51 |
|
| |
| 52 |
14 |
| repo_ptr = GIT_SV_TO_PTR(Repository, repo); |
| 53 |
|
| |
| 54 |
14 |
▶ | if (symbolic) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (symbolic) { |
7 |
7 |
14 |
|
| 55 |
|
| const char *target_ref_name; |
| 56 |
|
| |
| 57 |
7 |
▶ | if (sv_isobject(object)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_isobject(object)) |
4 |
3 |
7 |
|
| 58 |
4 |
| target_ref_name = git_reference_name(GIT_SV_TO_PTR(Reference, object)); |
| 59 |
|
| else { |
| 60 |
3 |
| target_ref_name = git_ensure_pv(object, "object"); |
| 61 |
|
| } |
| 62 |
|
| |
| 63 |
4 |
| rc = git_reference_symbolic_create( |
| 64 |
|
| &ref, repo_ptr -> repository, |
| 65 |
|
| name, target_ref_name, force, NULL |
| 66 |
|
| ); |
| 67 |
|
| } |
| 68 |
|
| else { |
| 69 |
14 |
| if (sv_isobject(object) && |
| 70 |
7 |
| sv_derived_from(object, "Git::Raw::Blob")) |
| 71 |
1 |
| oid = git_blob_id(GIT_SV_TO_PTR(Blob, object)); |
| 72 |
12 |
| else if (sv_isobject(object) && |
| 73 |
6 |
| sv_derived_from(object, "Git::Raw::Commit")) |
| 74 |
4 |
| oid = git_commit_id(GIT_SV_TO_PTR(Commit, object)); |
| 75 |
|
| else |
| 76 |
2 |
| oid = git_tree_id(GIT_SV_TO_PTR(Tree, object)); |
| 77 |
|
| |
| 78 |
6 |
| rc = git_reference_create( |
| 79 |
|
| &ref, repo_ptr -> repository, |
| 80 |
|
| name, oid, force, NULL |
| 81 |
|
| ); |
| 82 |
|
| } |
| 83 |
|
| |
| 84 |
10 |
| git_check_error(rc); |
| 85 |
|
| |
| 86 |
8 |
| GIT_NEW_OBJ_WITH_MAGIC(RETVAL, class, ref, SvRV(repo)); |
| 87 |
|
| |
| 88 |
|
| OUTPUT: RETVAL |
| 89 |
|
| |
| 90 |
|
| SV * |
| 91 |
|
| lookup(class, name, repo) |
| 92 |
|
| SV *class |
| 93 |
|
| SV *name |
| 94 |
|
| SV *repo |
| 95 |
|
| |
| 96 |
|
| PREINIT: |
| 97 |
|
| int rc; |
| 98 |
|
| |
| 99 |
|
| Repository repo_ptr; |
| 100 |
|
| Reference ref; |
| 101 |
|
| const char *ref_name; |
| 102 |
|
| |
| 103 |
|
| CODE: |
| 104 |
7 |
| repo_ptr = GIT_SV_TO_PTR(Repository, repo); |
| 105 |
7 |
| ref_name = git_ensure_pv(name, "name"); |
| 106 |
|
| |
| 107 |
7 |
| rc = git_reference_lookup( |
| 108 |
|
| &ref, repo_ptr -> repository, |
| 109 |
|
| ref_name |
| 110 |
|
| ); |
| 111 |
|
| |
| 112 |
7 |
▶ | if (rc == GIT_ENOTFOUND) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc == GIT_ENOTFOUND) { |
1 |
6 |
7 |
|
| 113 |
|
| /* Try to "do what I mean" */ |
| 114 |
1 |
| rc = git_reference_dwim( |
| 115 |
|
| &ref, repo_ptr -> repository, |
| 116 |
|
| ref_name |
| 117 |
|
| ); |
| 118 |
1 |
▶ | if (rc == GIT_ENOTFOUND) |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc == GIT_ENOTFOUND) |
1 |
0 |
1 |
|
| 119 |
1 |
| RETVAL = &PL_sv_undef; |
| 120 |
|
| } |
| 121 |
|
| |
| 122 |
7 |
▶ | if (rc != GIT_ENOTFOUND) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc != GIT_ENOTFOUND) { |
6 |
1 |
7 |
|
| 123 |
6 |
| git_check_error(rc); |
| 124 |
|
| |
| 125 |
12 |
| GIT_NEW_OBJ_WITH_MAGIC( |
| 126 |
|
| RETVAL, SvPVbyte_nolen(class), ref, SvRV(repo) |
| 127 |
|
| ); |
| 128 |
|
| } |
| 129 |
|
| |
| 130 |
|
| OUTPUT: RETVAL |
| 131 |
|
| |
| 132 |
|
| void |
| 133 |
|
| delete(self) |
| 134 |
|
| SV *self |
| 135 |
|
| |
| 136 |
|
| PREINIT: |
| 137 |
|
| int rc; |
| 138 |
|
| |
| 139 |
|
| CODE: |
| 140 |
5 |
| rc = git_reference_delete(GIT_SV_TO_PTR(Reference, self)); |
| 141 |
5 |
| git_check_error(rc); |
| 142 |
|
| |
| 143 |
5 |
| sv_setiv(SvRV(self), 0); |
| 144 |
|
| |
| 145 |
|
| SV * |
| 146 |
|
| name(self) |
| 147 |
|
| Reference self |
| 148 |
|
| |
| 149 |
|
| PREINIT: |
| 150 |
|
| const char *msg; |
| 151 |
|
| |
| 152 |
|
| CODE: |
| 153 |
25 |
| msg = git_reference_name(self); |
| 154 |
25 |
| RETVAL = newSVpv(msg, 0); |
| 155 |
|
| |
| 156 |
|
| OUTPUT: RETVAL |
| 157 |
|
| |
| 158 |
|
| SV * |
| 159 |
|
| type(self) |
| 160 |
|
| Reference self |
| 161 |
|
| |
| 162 |
|
| PREINIT: |
| 163 |
14 |
| SV *type = NULL; |
| 164 |
|
| git_ref_t rt; |
| 165 |
|
| |
| 166 |
|
| CODE: |
| 167 |
14 |
| rt = git_reference_type(self); |
| 168 |
|
| |
| 169 |
14 |
| switch (rt) { |
| 170 |
11 |
| case GIT_REF_OID: |
| 171 |
11 |
| type = newSVpv("direct", 0); |
| 172 |
11 |
| break; |
| 173 |
|
| |
| 174 |
3 |
| case GIT_REF_SYMBOLIC: |
| 175 |
3 |
| type = newSVpv("symbolic", 0); |
| 176 |
3 |
| break; |
| 177 |
|
| |
| 178 |
0 |
| default: |
| 179 |
0 |
| croak_assert("Unexpected reference type: %d", rt); |
| 180 |
0 |
| break; |
| 181 |
|
| } |
| 182 |
|
| |
| 183 |
14 |
| RETVAL = type; |
| 184 |
|
| |
| 185 |
|
| OUTPUT: RETVAL |
| 186 |
|
| |
| 187 |
|
| SV * |
| 188 |
|
| owner(self) |
| 189 |
|
| SV *self |
| 190 |
|
| |
| 191 |
|
| PREINIT: |
| 192 |
|
| SV *repo; |
| 193 |
|
| |
| 194 |
|
| CODE: |
| 195 |
1 |
| repo = GIT_SV_TO_MAGIC(self); |
| 196 |
1 |
| RETVAL = newRV_inc(repo); |
| 197 |
|
| |
| 198 |
|
| OUTPUT: RETVAL |
| 199 |
|
| |
| 200 |
|
| SV * |
| 201 |
|
| target(self, ...) |
| 202 |
|
| SV *self |
| 203 |
|
| |
| 204 |
|
| PROTOTYPE: $;$ |
| 205 |
|
| |
| 206 |
|
| PREINIT: |
| 207 |
|
| int rc; |
| 208 |
|
| Reference ref; |
| 209 |
|
| |
| 210 |
|
| CODE: |
| 211 |
94 |
| ref = GIT_SV_TO_PTR(Reference, self); |
| 212 |
|
| |
| 213 |
94 |
▶ | if (items == 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items == 2) { |
1 |
93 |
94 |
|
| 214 |
|
| Reference new_ref; |
| 215 |
|
| |
| 216 |
1 |
| Commit commit = GIT_SV_TO_PTR(Commit, ST(1)); |
| 217 |
|
| |
| 218 |
1 |
| rc = git_reference_set_target(&new_ref, ref, git_commit_id(commit), NULL); |
| 219 |
1 |
| git_check_error(rc); |
| 220 |
|
| |
| 221 |
1 |
| GIT_NEW_OBJ_WITH_MAGIC( |
| 222 |
|
| RETVAL, "Git::Raw::Reference", |
| 223 |
|
| new_ref, GIT_SV_TO_MAGIC(self) |
| 224 |
|
| ); |
| 225 |
|
| } else { |
| 226 |
93 |
| git_ref_t rt = git_reference_type(ref); |
| 227 |
|
| |
| 228 |
93 |
| RETVAL = &PL_sv_undef; |
| 229 |
93 |
| switch (rt) { |
| 230 |
90 |
| case GIT_REF_OID: { |
| 231 |
|
| git_object *obj; |
| 232 |
|
| const git_oid *oid; |
| 233 |
|
| |
| 234 |
90 |
| oid = git_reference_target(ref); |
| 235 |
|
| |
| 236 |
90 |
| rc = git_object_lookup( |
| 237 |
|
| &obj, git_reference_owner(ref), |
| 238 |
|
| oid, GIT_OBJ_ANY |
| 239 |
|
| ); |
| 240 |
90 |
| git_check_error(rc); |
| 241 |
|
| |
| 242 |
90 |
| RETVAL = git_obj_to_sv( |
| 243 |
90 |
| obj, GIT_SV_TO_MAGIC(self) |
| 244 |
|
| ); |
| 245 |
90 |
| break; |
| 246 |
|
| } |
| 247 |
|
| |
| 248 |
3 |
| case GIT_REF_SYMBOLIC: { |
| 249 |
|
| Reference linked_ref; |
| 250 |
|
| const char *target; |
| 251 |
|
| |
| 252 |
3 |
| target = git_reference_symbolic_target(ref); |
| 253 |
|
| |
| 254 |
3 |
| rc = git_reference_lookup( |
| 255 |
|
| &linked_ref, |
| 256 |
|
| git_reference_owner(ref), |
| 257 |
|
| target |
| 258 |
|
| ); |
| 259 |
3 |
| git_check_error(rc); |
| 260 |
|
| |
| 261 |
3 |
| GIT_NEW_OBJ_WITH_MAGIC( |
| 262 |
|
| RETVAL, "Git::Raw::Reference", |
| 263 |
|
| linked_ref, GIT_SV_TO_MAGIC(self) |
| 264 |
|
| ); |
| 265 |
3 |
| break; |
| 266 |
|
| } |
| 267 |
|
| |
| 268 |
0 |
| default: |
| 269 |
0 |
| croak_assert("Unexpected reference type: %d", rt); |
| 270 |
0 |
| break; |
| 271 |
|
| } |
| 272 |
|
| } |
| 273 |
|
| |
| 274 |
|
| OUTPUT: RETVAL |
| 275 |
|
| |
| 276 |
|
| SV * |
| 277 |
|
| peel(self, type) |
| 278 |
|
| SV *self |
| 279 |
|
| SV *type |
| 280 |
|
| |
| 281 |
|
| PREINIT: |
| 282 |
|
| int rc; |
| 283 |
|
| |
| 284 |
|
| const char *type_str; |
| 285 |
3 |
| git_otype t = GIT_OBJ_ANY; |
| 286 |
3 |
| git_object *obj = NULL; |
| 287 |
|
| |
| 288 |
|
| CODE: |
| 289 |
3 |
| type_str = git_ensure_pv(type, "type"); |
| 290 |
|
| |
| 291 |
3 |
▶ | if (strcmp(type_str, "commit") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(type_str, "commit") == 0) |
1 |
2 |
3 |
|
| 292 |
1 |
| t = GIT_OBJ_COMMIT; |
| 293 |
2 |
▶ | else if (strcmp(type_str, "tree") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strcmp(type_str, "tree") == 0) |
1 |
1 |
2 |
|
| 294 |
1 |
| t = GIT_OBJ_TREE; |
| 295 |
1 |
▶ | else if (strcmp(type_str, "tag") == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strcmp(type_str, "tag") == 0) |
0 |
1 |
1 |
|
| 296 |
0 |
| t = GIT_OBJ_TAG; |
| 297 |
|
| else |
| 298 |
1 |
| croak_usage("Invalid type for 'type'. Expected 'commit', 'tree' or 'tag'"); |
| 299 |
|
| |
| 300 |
2 |
| rc = git_reference_peel(&obj, |
| 301 |
2 |
| GIT_SV_TO_PTR(Reference, self), |
| 302 |
|
| t |
| 303 |
|
| ); |
| 304 |
2 |
| git_check_error(rc); |
| 305 |
|
| |
| 306 |
2 |
| RETVAL = git_obj_to_sv(obj, GIT_SV_TO_MAGIC(self)); |
| 307 |
|
| |
| 308 |
|
| OUTPUT: RETVAL |
| 309 |
|
| |
| 310 |
|
| SV * |
| 311 |
|
| shorthand(self) |
| 312 |
|
| Reference self |
| 313 |
|
| |
| 314 |
|
| CODE: |
| 315 |
4 |
| RETVAL = newSVpv(git_reference_shorthand(self), 0); |
| 316 |
|
| |
| 317 |
|
| OUTPUT: RETVAL |
| 318 |
|
| |
| 319 |
|
| SV * |
| 320 |
|
| is_branch(self) |
| 321 |
|
| Reference self |
| 322 |
|
| |
| 323 |
|
| CODE: |
| 324 |
9 |
| RETVAL = newSViv(git_reference_is_branch(self)); |
| 325 |
|
| |
| 326 |
|
| OUTPUT: RETVAL |
| 327 |
|
| |
| 328 |
|
| SV * |
| 329 |
|
| is_remote(self) |
| 330 |
|
| Reference self |
| 331 |
|
| |
| 332 |
|
| CODE: |
| 333 |
7 |
| RETVAL = newSViv(git_reference_is_remote(self)); |
| 334 |
|
| |
| 335 |
|
| OUTPUT: RETVAL |
| 336 |
|
| |
| 337 |
|
| SV * |
| 338 |
|
| is_tag(self) |
| 339 |
|
| Reference self |
| 340 |
|
| |
| 341 |
|
| PREINIT: |
| 342 |
|
| int rc; |
| 343 |
|
| |
| 344 |
|
| CODE: |
| 345 |
7 |
| RETVAL = newSViv(git_reference_is_tag(self)); |
| 346 |
|
| |
| 347 |
|
| OUTPUT: RETVAL |
| 348 |
|
| |
| 349 |
|
| SV * |
| 350 |
|
| is_note(self) |
| 351 |
|
| Reference self |
| 352 |
|
| |
| 353 |
|
| CODE: |
| 354 |
7 |
| RETVAL = newSViv(git_reference_is_note(self)); |
| 355 |
|
| |
| 356 |
|
| OUTPUT: RETVAL |
| 357 |
|
| |
| 358 |
|
| void |
| 359 |
|
| DESTROY(self) |
| 360 |
|
| SV *self |
| 361 |
|
| |
| 362 |
|
| CODE: |
| 363 |
103 |
| git_reference_free(GIT_SV_TO_PTR(Reference, self)); |
| 364 |
103 |
| SvREFCNT_dec(GIT_SV_TO_MAGIC(self)); |