deps/libgit2/src/libgit2/refs.c

filter: Statementstmt 74.0% 463 / 625 Branchbran 53.9% 244 / 452 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 65.6% 707 / 1077 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« const-xs-error.inc ↑ Summary deps/libgit2/src/libgit2/trailer.c »
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7  
8 #include "refs.h"
9  
10 #include "hash.h"
11 #include "repository.h"
12 #include "futils.h"
13 #include "filebuf.h"
14 #include "pack.h"
15 #include "reflog.h"
16 #include "refdb.h"
17  
18 #include <git2/tag.h>
19 #include <git2/object.h>
20 #include <git2/oid.h>
21 #include <git2/branch.h>
22 #include <git2/refs.h>
23 #include <git2/refdb.h>
24 #include <git2/sys/refs.h>
25 #include <git2/signature.h>
26 #include <git2/commit.h>
27  
28 bool git_reference__enable_symbolic_ref_target_validation = true;
29  
30 enum {
31 GIT_PACKREF_HAS_PEEL = 1,
32 GIT_PACKREF_WAS_LOOSE = 2
33 };
34  
35 1270 static git_reference *alloc_ref(const char *name)
36 {
37 1270 git_reference *ref = NULL;
38 1270 size_t namelen = strlen(name), reflen;
39  
40 2540 ▶ if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) &&
Branch: 3 branches
BranchTrueFalseTotal
if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) && 0 1270 1270
if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) && 1270 0 1270
if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) && 1270 0 1270
41 2540 ▶ !GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) &&
Branch: 2 branches
BranchTrueFalseTotal
!GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) && 0 1270 1270
!GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) && 1270 0 1270
42 1270 (ref = git__calloc(1, reflen)) != NULL)
43 1270 memcpy(ref->name, name, namelen + 1);
44  
45 1270 return ref;
46 }
47  
48 507 git_reference *git_reference__alloc_symbolic(
49 const char *name, const char *target)
50 {
51 git_reference *ref;
52  
53 507 ▶ GIT_ASSERT_ARG_WITH_RETVAL(name, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(name, NULL); 0 507 507
54 507 ▶ GIT_ASSERT_ARG_WITH_RETVAL(target, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(target, NULL); 0 507 507
55  
56 507 ref = alloc_ref(name);
57 507 ▶ if (!ref)
Branch: 1 branch
BranchTrueFalseTotal
if (!ref) 0 507 507
58 0 return NULL;
59  
60 507 ref->type = GIT_REFERENCE_SYMBOLIC;
61  
62 507 ▶ if ((ref->target.symbolic = git__strdup(target)) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref->target.symbolic = git__strdup(target)) == NULL) { 0 507 507
63 0 git__free(ref);
64 0 return NULL;
65 }
66  
67 507 return ref;
68 }
69  
70 763 git_reference *git_reference__alloc(
71 const char *name,
72 const git_oid *oid,
73 const git_oid *peel)
74 {
75 git_reference *ref;
76  
77 763 ▶ GIT_ASSERT_ARG_WITH_RETVAL(name, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(name, NULL); 0 763 763
78 763 ▶ GIT_ASSERT_ARG_WITH_RETVAL(oid, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(oid, NULL); 0 763 763
79  
80 763 ref = alloc_ref(name);
81 763 ▶ if (!ref)
Branch: 1 branch
BranchTrueFalseTotal
if (!ref) 0 763 763
82 0 return NULL;
83  
84 763 ref->type = GIT_REFERENCE_DIRECT;
85 763 git_oid_cpy(&ref->target.oid, oid);
86  
87 763 ▶ if (peel != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (peel != NULL) 0 763 763
88 0 git_oid_cpy(&ref->peel, peel);
89  
90 763 return ref;
91 }
92  
93 1 git_reference *git_reference__realloc(
94 git_reference **ptr_to_ref, const char *name)
95 {
96 size_t namelen, reflen;
97 1 git_reference *rewrite = NULL;
98  
99 1 ▶ GIT_ASSERT_ARG_WITH_RETVAL(ptr_to_ref, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(ptr_to_ref, NULL); 0 1 1
100 1 ▶ GIT_ASSERT_ARG_WITH_RETVAL(name, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(name, NULL); 0 1 1
101  
102 1 namelen = strlen(name);
103  
104 2 ▶ if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) &&
Branch: 3 branches
BranchTrueFalseTotal
if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) && 0 1 1
if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) && 1 0 1
if (!GIT_ADD_SIZET_OVERFLOW(&reflen, sizeof(git_reference), namelen) && 1 0 1
105 2 ▶ !GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) &&
Branch: 2 branches
BranchTrueFalseTotal
!GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) && 0 1 1
!GIT_ADD_SIZET_OVERFLOW(&reflen, reflen, 1) && 1 0 1
106 1 (rewrite = git__realloc(*ptr_to_ref, reflen)) != NULL)
107 1 memcpy(rewrite->name, name, namelen + 1);
108  
109 1 *ptr_to_ref = NULL;
110  
111 1 return rewrite;
112 }
113  
114 0 int git_reference_dup(git_reference **dest, git_reference *source)
115 {
116 0 ▶ if (source->type == GIT_REFERENCE_SYMBOLIC)
Branch: 1 branch
BranchTrueFalseTotal
if (source->type == GIT_REFERENCE_SYMBOLIC) 0 0 0
117 0 *dest = git_reference__alloc_symbolic(source->name, source->target.symbolic);
118 else
119 0 *dest = git_reference__alloc(source->name, &source->target.oid, &source->peel);
120  
121 0 ▶ GIT_ERROR_CHECK_ALLOC(*dest);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(*dest); 0 0 0
122  
123 0 (*dest)->db = source->db;
124 0 GIT_REFCOUNT_INC((*dest)->db);
125  
126 0 return 0;
127 }
128  
129 2814 void git_reference_free(git_reference *reference)
130 {
131 2814 ▶ if (reference == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (reference == NULL) 1550 1264 2814
132 1550 return;
133  
134 1264 ▶ if (reference->type == GIT_REFERENCE_SYMBOLIC)
Branch: 1 branch
BranchTrueFalseTotal
if (reference->type == GIT_REFERENCE_SYMBOLIC) 505 759 1264
135 505 git__free(reference->target.symbolic);
136  
137 1264 ▶ if (reference->db)
Branch: 1 branch
BranchTrueFalseTotal
if (reference->db) 1155 109 1264
138 1155 ▶ GIT_REFCOUNT_DEC(reference->db, git_refdb__free);
Branch: 2 branches
BranchTrueFalseTotal
GIT_REFCOUNT_DEC(reference->db, git_refdb__free); 1 1154 1155
GIT_REFCOUNT_DEC(reference->db, git_refdb__free); 1 0 1
139  
140 1264 git__free(reference);
141 }
142  
143 6 int git_reference_delete(git_reference *ref)
144 {
145 6 const git_oid *old_id = NULL;
146 6 const char *old_target = NULL;
147  
148 6 ▶ if (!strcmp(ref->name, "HEAD")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!strcmp(ref->name, "HEAD")) { 0 6 6
149 0 git_error_set(GIT_ERROR_REFERENCE, "cannot delete HEAD");
150 0 return GIT_ERROR;
151 }
152  
153 6 ▶ if (ref->type == GIT_REFERENCE_DIRECT)
Branch: 1 branch
BranchTrueFalseTotal
if (ref->type == GIT_REFERENCE_DIRECT) 4 2 6
154 4 old_id = &ref->target.oid;
155 else
156 2 old_target = ref->target.symbolic;
157  
158 6 return git_refdb_delete(ref->db, ref->name, old_id, old_target);
159 }
160  
161 0 int git_reference_remove(git_repository *repo, const char *name)
162 {
163 git_refdb *db;
164 int error;
165  
166 0 ▶ if ((error = git_repository_refdb__weakptr(&db, repo)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_repository_refdb__weakptr(&db, repo)) < 0) 0 0 0
167 0 return error;
168  
169 0 return git_refdb_delete(db, name, NULL, NULL);
170 }
171  
172 437 int git_reference_lookup(git_reference **ref_out,
173 git_repository *repo, const char *name)
174 {
175 437 return git_reference_lookup_resolved(ref_out, repo, name, 0);
176 }
177  
178 173 int git_reference_name_to_id(
179 git_oid *out, git_repository *repo, const char *name)
180 {
181 int error;
182 git_reference *ref;
183  
184 173 ▶ if ((error = git_reference_lookup_resolved(&ref, repo, name, -1)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_reference_lookup_resolved(&ref, repo, name, -1)) < 0) 30 143 173
185 30 return error;
186  
187 143 git_oid_cpy(out, git_reference_target(ref));
188 143 git_reference_free(ref);
189 143 return 0;
190 }
191  
192 1114 static int reference_normalize_for_repo(
193 git_refname_t out,
194 git_repository *repo,
195 const char *name,
196 bool validate)
197 {
198 int precompose;
199 1114 unsigned int flags = GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL;
200  
201 1114 ▶ if (!git_repository__configmap_lookup(&precompose, repo, GIT_CONFIGMAP_PRECOMPOSE) &&
Branch: 2 branches
BranchTrueFalseTotal
if (!git_repository__configmap_lookup(&precompose, repo, GIT_CONFIGMAP_PRECOMPOSE) && 1114 0 1114
if (!git_repository__configmap_lookup(&precompose, repo, GIT_CONFIGMAP_PRECOMPOSE) && 0 1114 1114
202 precompose)
203 0 flags |= GIT_REFERENCE_FORMAT__PRECOMPOSE_UNICODE;
204  
205 1114 ▶ if (!validate)
Branch: 1 branch
BranchTrueFalseTotal
if (!validate) 0 1114 1114
206 0 flags |= GIT_REFERENCE_FORMAT__VALIDATION_DISABLE;
207  
208 1114 return git_reference_normalize_name(out, GIT_REFNAME_MAX, name, flags);
209 }
210  
211 991 int git_reference_lookup_resolved(
212 git_reference **ref_out,
213 git_repository *repo,
214 const char *name,
215 int max_nesting)
216 {
217 git_refname_t normalized;
218 git_refdb *refdb;
219 991 int error = 0;
220  
221 991 ▶ GIT_ASSERT_ARG(ref_out);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref_out); 0 991 991
222 991 ▶ GIT_ASSERT_ARG(repo);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(repo); 0 991 991
223 991 ▶ GIT_ASSERT_ARG(name);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(name); 0 991 991
224  
225 1972 if ((error = reference_normalize_for_repo(normalized, repo, name, true)) < 0 ||
226 1962 ▶ (error = git_repository_refdb__weakptr(&refdb, repo)) < 0 ||
Branch: 1 branch
BranchTrueFalseTotal
(error = git_repository_refdb__weakptr(&refdb, repo)) < 0 || 125 856 981
227 981 (error = git_refdb_resolve(ref_out, refdb, normalized, max_nesting)) < 0)
228 135 return error;
229  
230 /*
231 * The resolved reference may be a symbolic reference in case its
232 * target doesn't exist. If the user asked us to resolve (e.g.
233 * `max_nesting != 0`), then we need to return an error in case we got
234 * a symbolic reference back.
235 */
236 856 ▶ if (max_nesting && git_reference_type(*ref_out) == GIT_REFERENCE_SYMBOLIC) {
Branch: 2 branches
BranchTrueFalseTotal
if (max_nesting && git_reference_type(*ref_out) == GIT_REFERENCE_SYMBOLIC) { 434 422 856
if (max_nesting && git_reference_type(*ref_out) == GIT_REFERENCE_SYMBOLIC) { 3 431 434
237 3 git_reference_free(*ref_out);
238 3 *ref_out = NULL;
239 3 return GIT_ENOTFOUND;
240 }
241  
242 853 return 0;
243 }
244  
245 29 int git_reference_dwim(git_reference **out, git_repository *repo, const char *refname)
246 {
247 29 int error = 0, i, valid;
248 29 bool fallbackmode = true, foundvalid = false;
249 git_reference *ref;
250 29 git_str refnamebuf = GIT_STR_INIT, name = GIT_STR_INIT;
251  
252 static const char *formatters[] = {
253 "%s",
254 GIT_REFS_DIR "%s",
255 GIT_REFS_TAGS_DIR "%s",
256 GIT_REFS_HEADS_DIR "%s",
257 GIT_REFS_REMOTES_DIR "%s",
258 GIT_REFS_REMOTES_DIR "%s/" GIT_HEAD_FILE,
259 NULL
260 };
261  
262 29 ▶ if (*refname)
Branch: 1 branch
BranchTrueFalseTotal
if (*refname) 28 1 29
263 28 git_str_puts(&name, refname);
264 else {
265 1 git_str_puts(&name, GIT_HEAD_FILE);
266 1 fallbackmode = false;
267 }
268  
269 119 ▶ for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) {
Branch: 3 branches
BranchTrueFalseTotal
for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) { 12 107 119
for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) { 106 1 107
for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) { 1 0 1
270  
271 107 git_str_clear(&refnamebuf);
272  
273 214 if ((error = git_str_printf(&refnamebuf, formatters[i], git_str_cstr(&name))) < 0 ||
274 107 (error = git_reference_name_is_valid(&valid, git_str_cstr(&refnamebuf))) < 0)
275 0 goto cleanup;
276  
277 107 ▶ if (!valid) {
Branch: 1 branch
BranchTrueFalseTotal
if (!valid) { 16 91 107
278 16 error = GIT_EINVALIDSPEC;
279 16 continue;
280 }
281 91 foundvalid = true;
282  
283 91 error = git_reference_lookup_resolved(&ref, repo, git_str_cstr(&refnamebuf), -1);
284  
285 91 ▶ if (!error) {
Branch: 1 branch
BranchTrueFalseTotal
if (!error) { 17 74 91
286 17 *out = ref;
287 17 error = 0;
288 17 goto cleanup;
289 }
290  
291 74 ▶ if (error != GIT_ENOTFOUND)
Branch: 1 branch
BranchTrueFalseTotal
if (error != GIT_ENOTFOUND) 0 74 74
292 0 goto cleanup;
293 }
294  
295 12 cleanup:
296 29 ▶ if (error && !foundvalid) {
Branch: 2 branches
BranchTrueFalseTotal
if (error && !foundvalid) { 12 17 29
if (error && !foundvalid) { 0 12 12
297 /* never found a valid reference name */
298 0 git_error_set(GIT_ERROR_REFERENCE,
299 "could not use '%s' as valid reference name", git_str_cstr(&name));
300 }
301  
302 29 ▶ if (error == GIT_ENOTFOUND)
Branch: 1 branch
BranchTrueFalseTotal
if (error == GIT_ENOTFOUND) 12 17 29
303 12 git_error_set(GIT_ERROR_REFERENCE, "no reference found for shorthand '%s'", refname);
304  
305 29 git_str_dispose(&name);
306 29 git_str_dispose(&refnamebuf);
307 29 return error;
308 }
309  
310 /**
311 * Getters
312 */
313 992 git_reference_t git_reference_type(const git_reference *ref)
314 {
315 992 ▶ GIT_ASSERT_ARG(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref); 0 992 992
316 992 return ref->type;
317 }
318  
319 207 const char *git_reference_name(const git_reference *ref)
320 {
321 207 ▶ GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL); 0 207 207
322 207 return ref->name;
323 }
324  
325 338 git_repository *git_reference_owner(const git_reference *ref)
326 {
327 338 ▶ GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL); 0 338 338
328 338 return ref->db->repo;
329 }
330  
331 381 const git_oid *git_reference_target(const git_reference *ref)
332 {
333 381 ▶ GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL); 0 381 381
334  
335 381 ▶ if (ref->type != GIT_REFERENCE_DIRECT)
Branch: 1 branch
BranchTrueFalseTotal
if (ref->type != GIT_REFERENCE_DIRECT) 0 381 381
336 0 return NULL;
337  
338 381 return &ref->target.oid;
339 }
340  
341 0 const git_oid *git_reference_target_peel(const git_reference *ref)
342 {
343 0 ▶ GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL); 0 0 0
344  
345 0 ▶ if (ref->type != GIT_REFERENCE_DIRECT || git_oid_is_zero(&ref->peel))
Branch: 2 branches
BranchTrueFalseTotal
if (ref->type != GIT_REFERENCE_DIRECT || git_oid_is_zero(&ref->peel)) 0 0 0
if (ref->type != GIT_REFERENCE_DIRECT || git_oid_is_zero(&ref->peel)) 0 0 0
346 0 return NULL;
347  
348 0 return &ref->peel;
349 }
350  
351 424 const char *git_reference_symbolic_target(const git_reference *ref)
352 {
353 424 ▶ GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG_WITH_RETVAL(ref, NULL); 0 424 424
354  
355 424 ▶ if (ref->type != GIT_REFERENCE_SYMBOLIC)
Branch: 1 branch
BranchTrueFalseTotal
if (ref->type != GIT_REFERENCE_SYMBOLIC) 0 424 424
356 0 return NULL;
357  
358 424 return ref->target.symbolic;
359 }
360  
361 99 static int reference__create(
362 git_reference **ref_out,
363 git_repository *repo,
364 const char *name,
365 const git_oid *oid,
366 const char *symbolic,
367 int force,
368 const git_signature *signature,
369 const char *log_message,
370 const git_oid *old_id,
371 const char *old_target)
372 {
373 git_refname_t normalized;
374 git_refdb *refdb;
375 99 git_reference *ref = NULL;
376 99 int error = 0;
377  
378 99 ▶ GIT_ASSERT_ARG(repo);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(repo); 0 99 99
379 99 ▶ GIT_ASSERT_ARG(name);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(name); 0 99 99
380 99 ▶ GIT_ASSERT_ARG(symbolic || signature);
Branch: 2 branches
BranchTrueFalseTotal
GIT_ASSERT_ARG(symbolic || signature); 76 23 99
GIT_ASSERT_ARG(symbolic || signature); 0 76 76
381  
382 99 ▶ if (ref_out)
Branch: 1 branch
BranchTrueFalseTotal
if (ref_out) 97 2 99
383 97 *ref_out = NULL;
384  
385 99 error = reference_normalize_for_repo(normalized, repo, name, true);
386 99 ▶ if (error < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (error < 0) 0 99 99
387 0 return error;
388  
389 99 error = git_repository_refdb__weakptr(&refdb, repo);
390 99 ▶ if (error < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (error < 0) 0 99 99
391 0 return error;
392  
393 99 ▶ if (oid != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (oid != NULL) { 76 23 99
394 76 ▶ GIT_ASSERT(symbolic == NULL);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT(symbolic == NULL); 0 76 76
395  
396 76 ▶ if (!git_object__is_valid(repo, oid, GIT_OBJECT_ANY)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!git_object__is_valid(repo, oid, GIT_OBJECT_ANY)) { 0 76 76
397 0 git_error_set(GIT_ERROR_REFERENCE,
398 "target OID for the reference doesn't exist on the repository");
399 0 return -1;
400 }
401  
402 76 ref = git_reference__alloc(normalized, oid, NULL);
403 } else {
404 git_refname_t normalized_target;
405  
406 23 error = reference_normalize_for_repo(normalized_target, repo,
407 symbolic, git_reference__enable_symbolic_ref_target_validation);
408  
409 23 ▶ if (error < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (error < 0) 0 23 23
410 0 return error;
411  
412 23 ref = git_reference__alloc_symbolic(normalized, normalized_target);
413 }
414  
415 99 ▶ GIT_ERROR_CHECK_ALLOC(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(ref); 0 99 99
416  
417 99 ▶ if ((error = git_refdb_write(refdb, ref, force, signature, log_message, old_id, old_target)) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_refdb_write(refdb, ref, force, signature, log_message, old_id, old_target)) < 0) { 2 97 99
418 2 git_reference_free(ref);
419 2 return error;
420 }
421  
422 97 ▶ if (ref_out == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (ref_out == NULL) 2 95 97
423 2 git_reference_free(ref);
424 else
425 95 *ref_out = ref;
426  
427 97 return 0;
428 }
429  
430 69 static int refs_configured_ident(git_signature **out, const git_repository *repo)
431 {
432 69 ▶ if (repo->ident_name && repo->ident_email)
Branch: 2 branches
BranchTrueFalseTotal
if (repo->ident_name && repo->ident_email) 0 69 69
if (repo->ident_name && repo->ident_email) 0 0 0
433 0 return git_signature_now(out, repo->ident_name, repo->ident_email);
434  
435 /* if not configured let us fall-through to the next method */
436 69 return -1;
437 }
438  
439 69 int git_reference__log_signature(git_signature **out, git_repository *repo)
440 {
441 int error;
442 git_signature *who;
443  
444 138 if(((error = refs_configured_ident(&who, repo)) < 0) &&
445 76 ▶ ((error = git_signature_default(&who, repo)) < 0) &&
Branch: 1 branch
BranchTrueFalseTotal
((error = git_signature_default(&who, repo)) < 0) && 0 7 7
446 7 ((error = git_signature_now(&who, "unknown", "unknown")) < 0))
447 0 return error;
448  
449 69 *out = who;
450 69 return 0;
451 }
452  
453 41 int git_reference_create_matching(
454 git_reference **ref_out,
455 git_repository *repo,
456 const char *name,
457 const git_oid *id,
458 int force,
459 const git_oid *old_id,
460 const char *log_message)
461  
462 {
463 int error;
464 41 git_signature *who = NULL;
465  
466 41 ▶ GIT_ASSERT_ARG(id);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(id); 0 41 41
467  
468 41 ▶ if ((error = git_reference__log_signature(&who, repo)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_reference__log_signature(&who, repo)) < 0) 0 41 41
469 0 return error;
470  
471 41 error = reference__create(
472 ref_out, repo, name, id, NULL, force, who, log_message, old_id, NULL);
473  
474 41 git_signature_free(who);
475 41 return error;
476 }
477  
478 40 int git_reference_create(
479 git_reference **ref_out,
480 git_repository *repo,
481 const char *name,
482 const git_oid *id,
483 int force,
484 const char *log_message)
485 {
486 40 return git_reference_create_matching(ref_out, repo, name, id, force, NULL, log_message);
487 }
488  
489 23 int git_reference_symbolic_create_matching(
490 git_reference **ref_out,
491 git_repository *repo,
492 const char *name,
493 const char *target,
494 int force,
495 const char *old_target,
496 const char *log_message)
497 {
498 int error;
499 23 git_signature *who = NULL;
500  
501 23 ▶ GIT_ASSERT_ARG(target);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(target); 0 23 23
502  
503 23 ▶ if ((error = git_reference__log_signature(&who, repo)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_reference__log_signature(&who, repo)) < 0) 0 23 23
504 0 return error;
505  
506 23 error = reference__create(
507 ref_out, repo, name, NULL, target, force, who, log_message, NULL, old_target);
508  
509 23 git_signature_free(who);
510 23 return error;
511 }
512  
513 23 int git_reference_symbolic_create(
514 git_reference **ref_out,
515 git_repository *repo,
516 const char *name,
517 const char *target,
518 int force,
519 const char *log_message)
520 {
521 23 return git_reference_symbolic_create_matching(ref_out, repo, name, target, force, NULL, log_message);
522 }
523  
524 27 static int ensure_is_an_updatable_direct_reference(git_reference *ref)
525 {
526 27 ▶ if (ref->type == GIT_REFERENCE_DIRECT)
Branch: 1 branch
BranchTrueFalseTotal
if (ref->type == GIT_REFERENCE_DIRECT) 27 0 27
527 27 return 0;
528  
529 0 git_error_set(GIT_ERROR_REFERENCE, "cannot set OID on symbolic reference");
530 0 return -1;
531 }
532  
533 1 int git_reference_set_target(
534 git_reference **out,
535 git_reference *ref,
536 const git_oid *id,
537 const char *log_message)
538 {
539 int error;
540 git_repository *repo;
541  
542 1 ▶ GIT_ASSERT_ARG(out);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(out); 0 1 1
543 1 ▶ GIT_ASSERT_ARG(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref); 0 1 1
544 1 ▶ GIT_ASSERT_ARG(id);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(id); 0 1 1
545  
546 1 repo = ref->db->repo;
547  
548 1 ▶ if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0) 0 1 1
549 0 return error;
550  
551 1 return git_reference_create_matching(out, repo, ref->name, id, 1, &ref->target.oid, log_message);
552 }
553  
554 0 static int ensure_is_an_updatable_symbolic_reference(git_reference *ref)
555 {
556 0 ▶ if (ref->type == GIT_REFERENCE_SYMBOLIC)
Branch: 1 branch
BranchTrueFalseTotal
if (ref->type == GIT_REFERENCE_SYMBOLIC) 0 0 0
557 0 return 0;
558  
559 0 git_error_set(GIT_ERROR_REFERENCE, "cannot set symbolic target on a direct reference");
560 0 return -1;
561 }
562  
563 0 int git_reference_symbolic_set_target(
564 git_reference **out,
565 git_reference *ref,
566 const char *target,
567 const char *log_message)
568 {
569 int error;
570  
571 0 ▶ GIT_ASSERT_ARG(out);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(out); 0 0 0
572 0 ▶ GIT_ASSERT_ARG(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref); 0 0 0
573 0 ▶ GIT_ASSERT_ARG(target);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(target); 0 0 0
574  
575 0 ▶ if ((error = ensure_is_an_updatable_symbolic_reference(ref)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = ensure_is_an_updatable_symbolic_reference(ref)) < 0) 0 0 0
576 0 return error;
577  
578 0 return git_reference_symbolic_create_matching(
579 0 out, ref->db->repo, ref->name, target, 1, ref->target.symbolic, log_message);
580 }
581  
582 typedef struct {
583 const char *old_name;
584 git_refname_t new_name;
585 } refs_update_head_payload;
586  
587 1 static int refs_update_head(git_repository *worktree, void *_payload)
588 {
589 1 refs_update_head_payload *payload = (refs_update_head_payload *)_payload;
590 1 git_reference *head = NULL, *updated = NULL;
591 int error;
592  
593 1 ▶ if ((error = git_reference_lookup(&head, worktree, GIT_HEAD_FILE)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_reference_lookup(&head, worktree, GIT_HEAD_FILE)) < 0) 0 1 1
594 0 goto out;
595  
596 1 ▶ if (git_reference_type(head) != GIT_REFERENCE_SYMBOLIC ||
Branch: 1 branch
BranchTrueFalseTotal
if (git_reference_type(head) != GIT_REFERENCE_SYMBOLIC || 1 0 1
597 1 ▶ git__strcmp(git_reference_symbolic_target(head), payload->old_name) != 0)
Branch: 1 branch
BranchTrueFalseTotal
git__strcmp(git_reference_symbolic_target(head), payload->old_name) != 0) 1 0 1
598 1 goto out;
599  
600 /* Update HEAD if it was pointing to the reference being renamed */
601 0 ▶ if ((error = git_reference_symbolic_set_target(&updated, head, payload->new_name, NULL)) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_reference_symbolic_set_target(&updated, head, payload->new_name, NULL)) < 0) { 0 0 0
602 0 git_error_set(GIT_ERROR_REFERENCE, "failed to update HEAD after renaming reference");
603 0 goto out;
604 }
605  
606 0 out:
607 1 git_reference_free(updated);
608 1 git_reference_free(head);
609 1 return error;
610 }
611  
612 1 int git_reference_rename(
613 git_reference **out,
614 git_reference *ref,
615 const char *new_name,
616 int force,
617 const char *log_message)
618 {
619 refs_update_head_payload payload;
620 1 git_signature *signature = NULL;
621 git_repository *repo;
622 int error;
623  
624 1 ▶ GIT_ASSERT_ARG(out);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(out); 0 1 1
625 1 ▶ GIT_ASSERT_ARG(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref); 0 1 1
626  
627 1 repo = git_reference_owner(ref);
628  
629 2 if ((error = git_reference__log_signature(&signature, repo)) < 0 ||
630 2 ▶ (error = reference_normalize_for_repo(payload.new_name, repo, new_name, true)) < 0 ||
Branch: 1 branch
BranchTrueFalseTotal
(error = reference_normalize_for_repo(payload.new_name, repo, new_name, true)) < 0 || 0 1 1
631 1 (error = git_refdb_rename(out, ref->db, ref->name, payload.new_name, force, signature, log_message)) < 0)
632 0 goto out;
633  
634 1 payload.old_name = ref->name;
635  
636 /* We may have to update any HEAD that was pointing to the renamed reference. */
637 1 ▶ if ((error = git_repository_foreach_worktree(repo, refs_update_head, &payload)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_repository_foreach_worktree(repo, refs_update_head, &payload)) < 0) 1 0 1
638 0 goto out;
639  
640 1 out:
641 1 git_signature_free(signature);
642 1 return error;
643 }
644  
645 12 int git_reference_resolve(git_reference **ref_out, const git_reference *ref)
646 {
647 12 switch (git_reference_type(ref)) {
648 2 case GIT_REFERENCE_DIRECT:
649 2 return git_reference_lookup(ref_out, ref->db->repo, ref->name);
650  
651 10 case GIT_REFERENCE_SYMBOLIC:
652 10 return git_reference_lookup_resolved(ref_out, ref->db->repo, ref->target.symbolic, -1);
653  
654 0 default:
655 0 git_error_set(GIT_ERROR_REFERENCE, "invalid reference");
656 0 return -1;
657 }
658 }
659  
660 0 int git_reference_foreach(
661 git_repository *repo,
662 git_reference_foreach_cb callback,
663 void *payload)
664 {
665 git_reference_iterator *iter;
666 git_reference *ref;
667 int error;
668  
669 0 ▶ if ((error = git_reference_iterator_new(&iter, repo)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_reference_iterator_new(&iter, repo)) < 0) 0 0 0
670 0 return error;
671  
672 0 ▶ while (!(error = git_reference_next(&ref, iter))) {
Branch: 1 branch
BranchTrueFalseTotal
while (!(error = git_reference_next(&ref, iter))) { 0 0 0
673 0 ▶ if ((error = callback(ref, payload)) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((error = callback(ref, payload)) != 0) { 0 0 0
674 0 git_error_set_after_callback(error);
675 0 break;
676 }
677 }
678  
679 0 ▶ if (error == GIT_ITEROVER)
Branch: 1 branch
BranchTrueFalseTotal
if (error == GIT_ITEROVER) 0 0 0
680 0 error = 0;
681  
682 0 git_reference_iterator_free(iter);
683 0 return error;
684 }
685  
686 20 int git_reference_foreach_name(
687 git_repository *repo,
688 git_reference_foreach_name_cb callback,
689 void *payload)
690 {
691 git_reference_iterator *iter;
692 const char *refname;
693 int error;
694  
695 20 ▶ if ((error = git_reference_iterator_new(&iter, repo)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_reference_iterator_new(&iter, repo)) < 0) 0 20 20
696 0 return error;
697  
698 120 ▶ while (!(error = git_reference_next_name(&refname, iter))) {
Branch: 1 branch
BranchTrueFalseTotal
while (!(error = git_reference_next_name(&refname, iter))) { 101 19 120
699 101 ▶ if ((error = callback(refname, payload)) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((error = callback(refname, payload)) != 0) { 1 100 101
700 1 git_error_set_after_callback(error);
701 1 break;
702 }
703 }
704  
705 20 ▶ if (error == GIT_ITEROVER)
Branch: 1 branch
BranchTrueFalseTotal
if (error == GIT_ITEROVER) 19 1 20
706 19 error = 0;
707  
708 20 git_reference_iterator_free(iter);
709 20 return error;
710 }
711  
712 0 int git_reference_foreach_glob(
713 git_repository *repo,
714 const char *glob,
715 git_reference_foreach_name_cb callback,
716 void *payload)
717 {
718 git_reference_iterator *iter;
719 const char *refname;
720 int error;
721  
722 0 ▶ if ((error = git_reference_iterator_glob_new(&iter, repo, glob)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_reference_iterator_glob_new(&iter, repo, glob)) < 0) 0 0 0
723 0 return error;
724  
725 0 ▶ while (!(error = git_reference_next_name(&refname, iter))) {
Branch: 1 branch
BranchTrueFalseTotal
while (!(error = git_reference_next_name(&refname, iter))) { 0 0 0
726 0 ▶ if ((error = callback(refname, payload)) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((error = callback(refname, payload)) != 0) { 0 0 0
727 0 git_error_set_after_callback(error);
728 0 break;
729 }
730 }
731  
732 0 ▶ if (error == GIT_ITEROVER)
Branch: 1 branch
BranchTrueFalseTotal
if (error == GIT_ITEROVER) 0 0 0
733 0 error = 0;
734  
735 0 git_reference_iterator_free(iter);
736 0 return error;
737 }
738  
739 28 int git_reference_iterator_new(git_reference_iterator **out, git_repository *repo)
740 {
741 git_refdb *refdb;
742  
743 28 ▶ if (git_repository_refdb__weakptr(&refdb, repo) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (git_repository_refdb__weakptr(&refdb, repo) < 0) 0 28 28
744 0 return -1;
745  
746 28 return git_refdb_iterator(out, refdb, NULL);
747 }
748  
749 3 int git_reference_iterator_glob_new(
750 git_reference_iterator **out, git_repository *repo, const char *glob)
751 {
752 git_refdb *refdb;
753  
754 3 ▶ if (git_repository_refdb__weakptr(&refdb, repo) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (git_repository_refdb__weakptr(&refdb, repo) < 0) 0 3 3
755 0 return -1;
756  
757 3 return git_refdb_iterator(out, refdb, glob);
758 }
759  
760 19 int git_reference_next(git_reference **out, git_reference_iterator *iter)
761 {
762 19 return git_refdb_iterator_next(out, iter);
763 }
764  
765 125 int git_reference_next_name(const char **out, git_reference_iterator *iter)
766 {
767 125 return git_refdb_iterator_next_name(out, iter);
768 }
769  
770 31 void git_reference_iterator_free(git_reference_iterator *iter)
771 {
772 31 ▶ if (iter == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (iter == NULL) 0 31 31
773 0 return;
774  
775 31 git_refdb_iterator_free(iter);
776 }
777  
778 2 static int cb__reflist_add(const char *ref, void *data)
779 {
780 2 char *name = git__strdup(ref);
781 2 ▶ GIT_ERROR_CHECK_ALLOC(name);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(name); 0 2 2
782 2 return git_vector_insert((git_vector *)data, name);
783 }
784  
785 4 int git_reference_list(
786 git_strarray *array,
787 git_repository *repo)
788 {
789 git_vector ref_list;
790  
791 4 ▶ GIT_ASSERT_ARG(array);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(array); 0 4 4
792 4 ▶ GIT_ASSERT_ARG(repo);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(repo); 0 4 4
793  
794 4 array->strings = NULL;
795 4 array->count = 0;
796  
797 4 ▶ if (git_vector_init(&ref_list, 8, NULL) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (git_vector_init(&ref_list, 8, NULL) < 0) 0 4 4
798 0 return -1;
799  
800 4 ▶ if (git_reference_foreach_name(
Branch: 1 branch
BranchTrueFalseTotal
if (git_reference_foreach_name( 0 4 4
801 repo, &cb__reflist_add, (void *)&ref_list) < 0) {
802 0 git_vector_free(&ref_list);
803 0 return -1;
804 }
805  
806 4 array->strings = (char **)git_vector_detach(&array->count, NULL, &ref_list);
807  
808 4 return 0;
809 }
810  
811 16291 static int is_valid_ref_char(char ch)
812 {
813 16291 ▶ if ((unsigned) ch <= ' ')
Branch: 1 branch
BranchTrueFalseTotal
if ((unsigned) ch <= ' ') 0 16291 16291
814 0 return 0;
815  
816 16291 ▶ switch (ch) {
Branch: 1 branch
BranchTrueFalseTotal
switch (ch) { 0 16291 16291
817 0 case '~':
818 case '^':
819 case ':':
820 case '\\':
821 case '?':
822 case '[':
823 0 return 0;
824 16291 default:
825 16291 return 1;
826 }
827 }
828  
829 2983 static int ensure_segment_validity(const char *name, char may_contain_glob)
830 {
831 2983 const char *current = name;
832 2983 char prev = '\0';
833 2983 const int lock_len = (int)strlen(GIT_FILELOCK_EXTENSION);
834 int segment_len;
835  
836 2983 ▶ if (*current == '.')
Branch: 1 branch
BranchTrueFalseTotal
if (*current == '.') 0 2983 2983
837 0 return -1; /* Refname starts with "." */
838  
839 2983 for (current = name; ; current++) {
840 19274 ▶ if (*current == '\0' || *current == '/')
Branch: 2 branches
BranchTrueFalseTotal
if (*current == '\0' || *current == '/') 17962 1312 19274
if (*current == '\0' || *current == '/') 16291 1671 17962
841 break;
842  
843 16291 ▶ if (!is_valid_ref_char(*current))
Branch: 1 branch
BranchTrueFalseTotal
if (!is_valid_ref_char(*current)) 0 16291 16291
844 0 return -1; /* Illegal character in refname */
845  
846 16291 ▶ if (prev == '.' && *current == '.')
Branch: 2 branches
BranchTrueFalseTotal
if (prev == '.' && *current == '.') 36 16255 16291
if (prev == '.' && *current == '.') 0 36 36
847 0 return -1; /* Refname contains ".." */
848  
849 16291 ▶ if (prev == '@' && *current == '{')
Branch: 2 branches
BranchTrueFalseTotal
if (prev == '@' && *current == '{') 0 16291 16291
if (prev == '@' && *current == '{') 0 0 0
850 0 return -1; /* Refname contains "@{" */
851  
852 16291 ▶ if (*current == '*') {
Branch: 1 branch
BranchTrueFalseTotal
if (*current == '*') { 26 16265 16291
853 26 ▶ if (!may_contain_glob)
Branch: 1 branch
BranchTrueFalseTotal
if (!may_contain_glob) 0 26 26
854 0 return -1;
855 26 may_contain_glob = 0;
856 }
857  
858 16291 prev = *current;
859 }
860  
861 2983 segment_len = (int)(current - name);
862  
863 /* A refname component can not end with ".lock" */
864 2983 ▶ if (segment_len >= lock_len &&
Branch: 1 branch
BranchTrueFalseTotal
if (segment_len >= lock_len && 1096 1887 2983
865 1096 ▶ !memcmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len))
Branch: 1 branch
BranchTrueFalseTotal
!memcmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len)) 0 1096 1096
866 0 return -1;
867  
868 2983 return segment_len;
869 }
870  
871 1312 static bool is_all_caps_and_underscore(const char *name, size_t len)
872 {
873 size_t i;
874 char c;
875  
876 1312 ▶ GIT_ASSERT_ARG(name);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(name); 0 1312 1312
877 1312 ▶ GIT_ASSERT_ARG(len > 0);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(len > 0); 0 1312 1312
878  
879 3172 ▶ for (i = 0; i < len; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) 2707 465 3172
880 {
881 2707 c = name[i];
882 2707 ▶ if ((c < 'A' || c > 'Z') && c != '_')
Branch: 3 branches
BranchTrueFalseTotal
if ((c < 'A' || c > 'Z') && c != '_') 2706 1 2707
if ((c < 'A' || c > 'Z') && c != '_') 846 1860 2706
if ((c < 'A' || c > 'Z') && c != '_') 847 0 847
883 847 return false;
884 }
885  
886 465 ▶ if (*name == '_' || name[len - 1] == '_')
Branch: 2 branches
BranchTrueFalseTotal
if (*name == '_' || name[len - 1] == '_') 465 0 465
if (*name == '_' || name[len - 1] == '_') 0 465 465
887 0 return false;
888  
889 465 return true;
890 }
891  
892 /* Inspired from https://github.com/git/git/blob/f06d47e7e0d9db709ee204ed13a8a7486149f494/refs.c#L36-100 */
893 1312 int git_reference__normalize_name(
894 git_str *buf,
895 const char *name,
896 unsigned int flags)
897 {
898 const char *current;
899 1312 int segment_len, segments_count = 0, error = GIT_EINVALIDSPEC;
900 unsigned int process_flags;
901 1312 bool normalize = (buf != NULL);
902 1312 bool validate = (flags & GIT_REFERENCE_FORMAT__VALIDATION_DISABLE) == 0;
903  
904 #ifdef GIT_USE_ICONV
905 git_fs_path_iconv_t ic = GIT_PATH_ICONV_INIT;
906 #endif
907  
908 1312 ▶ GIT_ASSERT_ARG(name);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(name); 0 1312 1312
909  
910 1312 process_flags = flags;
911 1312 current = (char *)name;
912  
913 1312 ▶ if (validate && *current == '/')
Branch: 2 branches
BranchTrueFalseTotal
if (validate && *current == '/') 1312 0 1312
if (validate && *current == '/') 0 1312 1312
914 0 goto cleanup;
915  
916 1312 ▶ if (normalize)
Branch: 1 branch
BranchTrueFalseTotal
if (normalize) 1115 197 1312
917 1115 git_str_clear(buf);
918  
919 #ifdef GIT_USE_ICONV
920 if ((flags & GIT_REFERENCE_FORMAT__PRECOMPOSE_UNICODE) != 0) {
921 size_t namelen = strlen(current);
922 if ((error = git_fs_path_iconv_init_precompose(&ic)) < 0 ||
923 (error = git_fs_path_iconv(&ic, &current, &namelen)) < 0)
924 goto cleanup;
925 error = GIT_EINVALIDSPEC;
926 }
927 #endif
928  
929 1312 ▶ if (!validate) {
Branch: 1 branch
BranchTrueFalseTotal
if (!validate) { 0 1312 1312
930 0 git_str_sets(buf, current);
931  
932 0 ▶ error = git_str_oom(buf) ? -1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
error = git_str_oom(buf) ? -1 : 0; 0 0 0
933 0 goto cleanup;
934 }
935  
936 1671 while (true) {
937 2983 char may_contain_glob = process_flags & GIT_REFERENCE_FORMAT_REFSPEC_PATTERN;
938  
939 2983 segment_len = ensure_segment_validity(current, may_contain_glob);
940 2983 ▶ if (segment_len < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (segment_len < 0) 0 2983 2983
941 0 goto cleanup;
942  
943 2983 ▶ if (segment_len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (segment_len > 0) { 2983 0 2983
944 /*
945 * There may only be one glob in a pattern, thus we reset
946 * the pattern-flag in case the current segment has one.
947 */
948 2983 ▶ if (memchr(current, '*', segment_len))
Branch: 1 branch
BranchTrueFalseTotal
if (memchr(current, '*', segment_len)) 26 2957 2983
949 26 process_flags &= ~GIT_REFERENCE_FORMAT_REFSPEC_PATTERN;
950  
951 2983 ▶ if (normalize) {
Branch: 1 branch
BranchTrueFalseTotal
if (normalize) { 2389 594 2983
952 2389 size_t cur_len = git_str_len(buf);
953  
954 2389 git_str_joinpath(buf, git_str_cstr(buf), current);
955 2389 git_str_truncate(buf,
956 2389 ▶ cur_len + segment_len + (segments_count ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
cur_len + segment_len + (segments_count ? 1 : 0)); 1274 1115 2389
957  
958 2389 ▶ if (git_str_oom(buf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (git_str_oom(buf)) { 0 2389 2389
959 0 error = -1;
960 0 goto cleanup;
961 }
962 }
963  
964 2983 segments_count++;
965 }
966  
967 /* No empty segment is allowed when not normalizing */
968 2983 ▶ if (segment_len == 0 && !normalize)
Branch: 2 branches
BranchTrueFalseTotal
if (segment_len == 0 && !normalize) 0 2983 2983
if (segment_len == 0 && !normalize) 0 0 0
969 0 goto cleanup;
970  
971 2983 ▶ if (current[segment_len] == '\0')
Branch: 1 branch
BranchTrueFalseTotal
if (current[segment_len] == '\0') 1312 1671 2983
972 1312 break;
973  
974 1671 current += segment_len + 1;
975 }
976  
977 /* A refname can not be empty */
978 1312 ▶ if (segment_len == 0 && segments_count == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (segment_len == 0 && segments_count == 0) 0 1312 1312
if (segment_len == 0 && segments_count == 0) 0 0 0
979 0 goto cleanup;
980  
981 /* A refname can not end with "." */
982 1312 ▶ if (current[segment_len - 1] == '.')
Branch: 1 branch
BranchTrueFalseTotal
if (current[segment_len - 1] == '.') 0 1312 1312
983 0 goto cleanup;
984  
985 /* A refname can not end with "/" */
986 1312 ▶ if (current[segment_len - 1] == '/')
Branch: 1 branch
BranchTrueFalseTotal
if (current[segment_len - 1] == '/') 0 1312 1312
987 0 goto cleanup;
988  
989 1312 ▶ if ((segments_count == 1 ) && !(flags & GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL))
Branch: 2 branches
BranchTrueFalseTotal
if ((segments_count == 1 ) && !(flags & GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL)) 491 821 1312
if ((segments_count == 1 ) && !(flags & GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL)) 0 491 491
990 0 goto cleanup;
991  
992 1312 ▶ if ((segments_count == 1 ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ((segments_count == 1 ) && 491 821 1312
993 491 ▶ !(flags & GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND) &&
Branch: 1 branch
BranchTrueFalseTotal
!(flags & GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND) && 491 0 491
994 491 ▶ !(is_all_caps_and_underscore(name, (size_t)segment_len) ||
Branch: 1 branch
BranchTrueFalseTotal
!(is_all_caps_and_underscore(name, (size_t)segment_len) || 26 465 491
995 26 ▶ ((flags & GIT_REFERENCE_FORMAT_REFSPEC_PATTERN) && !strcmp("*", name))))
Branch: 2 branches
BranchTrueFalseTotal
((flags & GIT_REFERENCE_FORMAT_REFSPEC_PATTERN) && !strcmp("*", name)))) 0 26 26
((flags & GIT_REFERENCE_FORMAT_REFSPEC_PATTERN) && !strcmp("*", name)))) 0 0 0
996 26 goto cleanup;
997  
998 1286 ▶ if ((segments_count > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ((segments_count > 1) 821 465 1286
999 821 ▶ && (is_all_caps_and_underscore(name, strchr(name, '/') - name)))
Branch: 1 branch
BranchTrueFalseTotal
&& (is_all_caps_and_underscore(name, strchr(name, '/') - name))) 0 821 821
1000 0 goto cleanup;
1001  
1002 1286 error = 0;
1003  
1004 1312 cleanup:
1005 1312 ▶ if (error == GIT_EINVALIDSPEC)
Branch: 1 branch
BranchTrueFalseTotal
if (error == GIT_EINVALIDSPEC) 26 1286 1312
1006 26 git_error_set(
1007 GIT_ERROR_REFERENCE,
1008 "the given reference name '%s' is not valid", name);
1009  
1010 1312 ▶ if (error && normalize)
Branch: 2 branches
BranchTrueFalseTotal
if (error && normalize) 26 1286 1312
if (error && normalize) 10 16 26
1011 10 git_str_dispose(buf);
1012  
1013 #ifdef GIT_USE_ICONV
1014 git_fs_path_iconv_clear(&ic);
1015 #endif
1016  
1017 1312 return error;
1018 }
1019  
1020 1114 int git_reference_normalize_name(
1021 char *buffer_out,
1022 size_t buffer_size,
1023 const char *name,
1024 unsigned int flags)
1025 {
1026 1114 git_str buf = GIT_STR_INIT;
1027 int error;
1028  
1029 1114 ▶ if ((error = git_reference__normalize_name(&buf, name, flags)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_reference__normalize_name(&buf, name, flags)) < 0) 10 1104 1114
1030 10 goto cleanup;
1031  
1032 1104 ▶ if (git_str_len(&buf) > buffer_size - 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (git_str_len(&buf) > buffer_size - 1) { 0 1104 1104
1033 0 git_error_set(
1034 GIT_ERROR_REFERENCE,
1035 "the provided buffer is too short to hold the normalization of '%s'", name);
1036 0 error = GIT_EBUFS;
1037 0 goto cleanup;
1038 }
1039  
1040 1104 ▶ if ((error = git_str_copy_cstr(buffer_out, buffer_size, &buf)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_str_copy_cstr(buffer_out, buffer_size, &buf)) < 0) 0 1104 1104
1041 0 goto cleanup;
1042  
1043 1104 error = 0;
1044  
1045 1114 cleanup:
1046 1114 git_str_dispose(&buf);
1047 1114 return error;
1048 }
1049  
1050 #define GIT_REFERENCE_TYPEMASK (GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC)
1051  
1052 0 int git_reference_cmp(
1053 const git_reference *ref1,
1054 const git_reference *ref2)
1055 {
1056 git_reference_t type1, type2;
1057  
1058 0 ▶ GIT_ASSERT_ARG(ref1);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref1); 0 0 0
1059 0 ▶ GIT_ASSERT_ARG(ref2);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref2); 0 0 0
1060  
1061 0 type1 = git_reference_type(ref1);
1062 0 type2 = git_reference_type(ref2);
1063  
1064 /* let's put symbolic refs before OIDs */
1065 0 ▶ if (type1 != type2)
Branch: 1 branch
BranchTrueFalseTotal
if (type1 != type2) 0 0 0
1066 0 ▶ return (type1 == GIT_REFERENCE_SYMBOLIC) ? -1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
return (type1 == GIT_REFERENCE_SYMBOLIC) ? -1 : 1; 0 0 0
1067  
1068 0 ▶ if (type1 == GIT_REFERENCE_SYMBOLIC)
Branch: 1 branch
BranchTrueFalseTotal
if (type1 == GIT_REFERENCE_SYMBOLIC) 0 0 0
1069 0 return strcmp(ref1->target.symbolic, ref2->target.symbolic);
1070  
1071 0 return git_oid__cmp(&ref1->target.oid, &ref2->target.oid);
1072 }
1073  
1074 /*
1075 * Starting with the reference given by `ref_name`, follows symbolic
1076 * references until a direct reference is found and updated the OID
1077 * on that direct reference to `oid`.
1078 */
1079 9 int git_reference__update_terminal(
1080 git_repository *repo,
1081 const char *ref_name,
1082 const git_oid *oid,
1083 const git_signature *sig,
1084 const char *log_message)
1085 {
1086 9 git_reference *ref = NULL, *ref2 = NULL;
1087 9 git_signature *who = NULL;
1088 9 git_refdb *refdb = NULL;
1089 const git_signature *to_use;
1090 9 int error = 0;
1091  
1092 9 ▶ if (!sig && (error = git_reference__log_signature(&who, repo)) < 0)
Branch: 2 branches
BranchTrueFalseTotal
if (!sig && (error = git_reference__log_signature(&who, repo)) < 0) 2 7 9
if (!sig && (error = git_reference__log_signature(&who, repo)) < 0) 0 2 2
1093 0 goto out;
1094  
1095 9 ▶ to_use = sig ? sig : who;
Branch: 1 branch
BranchTrueFalseTotal
to_use = sig ? sig : who; 7 2 9
1096  
1097 9 ▶ if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) 0 9 9
1098 0 goto out;
1099  
1100 9 ▶ if ((error = git_refdb_resolve(&ref, refdb, ref_name, -1)) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_refdb_resolve(&ref, refdb, ref_name, -1)) < 0) { 1 8 9
1101 1 ▶ if (error == GIT_ENOTFOUND) {
Branch: 1 branch
BranchTrueFalseTotal
if (error == GIT_ENOTFOUND) { 1 0 1
1102 1 git_error_clear();
1103 1 error = reference__create(&ref2, repo, ref_name, oid, NULL, 0, to_use,
1104 log_message, NULL, NULL);
1105 }
1106 1 goto out;
1107 }
1108  
1109 /* In case the resolved reference is symbolic, then it's a dangling symref. */
1110 8 ▶ if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC) {
Branch: 1 branch
BranchTrueFalseTotal
if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC) { 3 5 8
1111 3 error = reference__create(&ref2, repo, ref->target.symbolic, oid, NULL, 0, to_use,
1112 log_message, NULL, NULL);
1113 } else {
1114 5 error = reference__create(&ref2, repo, ref->name, oid, NULL, 1, to_use,
1115 5 log_message, &ref->target.oid, NULL);
1116 }
1117  
1118 9 out:
1119 9 git_reference_free(ref2);
1120 9 git_reference_free(ref);
1121 9 git_signature_free(who);
1122 9 return error;
1123 }
1124  
1125 33 static const char *commit_type(const git_commit *commit)
1126 {
1127 33 unsigned int count = git_commit_parentcount(commit);
1128  
1129 33 ▶ if (count >= 2)
Branch: 1 branch
BranchTrueFalseTotal
if (count >= 2) 1 32 33
1130 1 return " (merge)";
1131 32 ▶ else if (count == 0)
Branch: 1 branch
BranchTrueFalseTotal
else if (count == 0) 4 28 32
1132 4 return " (initial)";
1133 else
1134 28 return "";
1135 }
1136  
1137 33 int git_reference__update_for_commit(
1138 git_repository *repo,
1139 git_reference *ref,
1140 const char *ref_name,
1141 const git_oid *id,
1142 const char *operation)
1143 {
1144 33 git_reference *ref_new = NULL;
1145 33 git_commit *commit = NULL;
1146 33 git_str reflog_msg = GIT_STR_INIT;
1147 const git_signature *who;
1148 int error;
1149  
1150 66 if ((error = git_commit_lookup(&commit, repo, id)) < 0 ||
1151 33 ▶ (error = git_str_printf(&reflog_msg, "%s%s: %s",
Branch: 1 branch
BranchTrueFalseTotal
(error = git_str_printf(&reflog_msg, "%s%s: %s", 33 0 33
1152 operation ? operation : "commit",
1153 commit_type(commit),
1154 git_commit_summary(commit))) < 0)
1155 0 goto done;
1156  
1157 33 who = git_commit_committer(commit);
1158  
1159 33 ▶ if (ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref) { 26 7 33
1160 26 ▶ if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0) 0 26 26
1161 0 return error;
1162  
1163 26 error = reference__create(&ref_new, repo, ref->name, id, NULL, 1, who,
1164 26 git_str_cstr(&reflog_msg), &ref->target.oid, NULL);
1165 }
1166 else
1167 7 error = git_reference__update_terminal(
1168 repo, ref_name, id, who, git_str_cstr(&reflog_msg));
1169  
1170 33 done:
1171 33 git_reference_free(ref_new);
1172 33 git_str_dispose(&reflog_msg);
1173 33 git_commit_free(commit);
1174 33 return error;
1175 }
1176  
1177 0 int git_reference_has_log(git_repository *repo, const char *refname)
1178 {
1179 int error;
1180 git_refdb *refdb;
1181  
1182 0 ▶ GIT_ASSERT_ARG(repo);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(repo); 0 0 0
1183 0 ▶ GIT_ASSERT_ARG(refname);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(refname); 0 0 0
1184  
1185 0 ▶ if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) 0 0 0
1186 0 return error;
1187  
1188 0 return git_refdb_has_log(refdb, refname);
1189 }
1190  
1191 6 int git_reference_ensure_log(git_repository *repo, const char *refname)
1192 {
1193 int error;
1194 git_refdb *refdb;
1195  
1196 6 ▶ GIT_ASSERT_ARG(repo);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(repo); 0 6 6
1197 6 ▶ GIT_ASSERT_ARG(refname);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(refname); 0 6 6
1198  
1199 6 ▶ if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) 0 6 6
1200 0 return error;
1201  
1202 6 return git_refdb_ensure_log(refdb, refname);
1203 }
1204  
1205 88 int git_reference__is_branch(const char *ref_name)
1206 {
1207 88 return git__prefixcmp(ref_name, GIT_REFS_HEADS_DIR) == 0;
1208 }
1209  
1210 64 int git_reference_is_branch(const git_reference *ref)
1211 {
1212 64 ▶ GIT_ASSERT_ARG(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref); 0 64 64
1213 64 return git_reference__is_branch(ref->name);
1214 }
1215  
1216 8 int git_reference__is_remote(const char *ref_name)
1217 {
1218 8 return git__prefixcmp(ref_name, GIT_REFS_REMOTES_DIR) == 0;
1219 }
1220  
1221 7 int git_reference_is_remote(const git_reference *ref)
1222 {
1223 7 ▶ GIT_ASSERT_ARG(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref); 0 7 7
1224 7 return git_reference__is_remote(ref->name);
1225 }
1226  
1227 8 int git_reference__is_tag(const char *ref_name)
1228 {
1229 8 return git__prefixcmp(ref_name, GIT_REFS_TAGS_DIR) == 0;
1230 }
1231  
1232 7 int git_reference_is_tag(const git_reference *ref)
1233 {
1234 7 ▶ GIT_ASSERT_ARG(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref); 0 7 7
1235 7 return git_reference__is_tag(ref->name);
1236 }
1237  
1238 7 int git_reference__is_note(const char *ref_name)
1239 {
1240 7 return git__prefixcmp(ref_name, GIT_REFS_NOTES_DIR) == 0;
1241 }
1242  
1243 7 int git_reference_is_note(const git_reference *ref)
1244 {
1245 7 ▶ GIT_ASSERT_ARG(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref); 0 7 7
1246 7 return git_reference__is_note(ref->name);
1247 }
1248  
1249 0 static int peel_error(int error, const git_reference *ref, const char *msg)
1250 {
1251 0 git_error_set(
1252 GIT_ERROR_INVALID,
1253 "the reference '%s' cannot be peeled - %s", git_reference_name(ref), msg);
1254 0 return error;
1255 }
1256  
1257 210 int git_reference_peel(
1258 git_object **peeled,
1259 const git_reference *ref,
1260 git_object_t target_type)
1261 {
1262 210 const git_reference *resolved = NULL;
1263 210 git_reference *allocated = NULL;
1264 210 git_object *target = NULL;
1265 int error;
1266  
1267 210 ▶ GIT_ASSERT_ARG(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref); 0 210 210
1268  
1269 210 ▶ if (ref->type == GIT_REFERENCE_DIRECT) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref->type == GIT_REFERENCE_DIRECT) { 200 10 210
1270 200 resolved = ref;
1271 } else {
1272 10 ▶ if ((error = git_reference_resolve(&allocated, ref)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_reference_resolve(&allocated, ref)) < 0) 0 10 10
1273 0 return peel_error(error, ref, "Cannot resolve reference");
1274  
1275 10 resolved = allocated;
1276 }
1277  
1278 /*
1279 * If we try to peel an object to a tag, we cannot use
1280 * the fully peeled object, as that will always resolve
1281 * to a commit. So we only want to use the peeled value
1282 * if it is not zero and the target is not a tag.
1283 */
1284 210 ▶ if (target_type != GIT_OBJECT_TAG && !git_oid_is_zero(&resolved->peel)) {
Branch: 2 branches
BranchTrueFalseTotal
if (target_type != GIT_OBJECT_TAG && !git_oid_is_zero(&resolved->peel)) { 210 0 210
if (target_type != GIT_OBJECT_TAG && !git_oid_is_zero(&resolved->peel)) { 0 210 210
1285 0 error = git_object_lookup(&target,
1286 git_reference_owner(ref), &resolved->peel, GIT_OBJECT_ANY);
1287 } else {
1288 210 error = git_object_lookup(&target,
1289 git_reference_owner(ref), &resolved->target.oid, GIT_OBJECT_ANY);
1290 }
1291  
1292 210 ▶ if (error < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (error < 0) { 0 210 210
1293 0 peel_error(error, ref, "Cannot retrieve reference target");
1294 0 goto cleanup;
1295 }
1296  
1297 210 ▶ if (target_type == GIT_OBJECT_ANY && git_object_type(target) != GIT_OBJECT_TAG)
Branch: 2 branches
BranchTrueFalseTotal
if (target_type == GIT_OBJECT_ANY && git_object_type(target) != GIT_OBJECT_TAG) 0 210 210
if (target_type == GIT_OBJECT_ANY && git_object_type(target) != GIT_OBJECT_TAG) 0 0 0
1298 0 error = git_object_dup(peeled, target);
1299 else
1300 210 error = git_object_peel(peeled, target, target_type);
1301  
1302 210 cleanup:
1303 210 git_object_free(target);
1304 210 git_reference_free(allocated);
1305  
1306 210 return error;
1307 }
1308  
1309 197 int git_reference__name_is_valid(
1310 int *valid,
1311 const char *refname,
1312 unsigned int flags)
1313 {
1314 int error;
1315  
1316 197 ▶ GIT_ASSERT(valid && refname);
Branch: 2 branches
BranchTrueFalseTotal
GIT_ASSERT(valid && refname); 197 0 197
GIT_ASSERT(valid && refname); 0 197 197
1317  
1318 197 *valid = 0;
1319  
1320 197 error = git_reference__normalize_name(NULL, refname, flags);
1321  
1322 197 ▶ if (!error)
Branch: 1 branch
BranchTrueFalseTotal
if (!error) 181 16 197
1323 181 *valid = 1;
1324 16 ▶ else if (error == GIT_EINVALIDSPEC)
Branch: 1 branch
BranchTrueFalseTotal
else if (error == GIT_EINVALIDSPEC) 16 0 16
1325 16 error = 0;
1326  
1327 197 return error;
1328 }
1329  
1330 109 int git_reference_name_is_valid(int *valid, const char *refname)
1331 {
1332 109 return git_reference__name_is_valid(valid, refname, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL);
1333 }
1334  
1335 42 const char *git_reference__shorthand(const char *name)
1336 {
1337 42 ▶ if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR))
Branch: 1 branch
BranchTrueFalseTotal
if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR)) 41 1 42
1338 41 return name + strlen(GIT_REFS_HEADS_DIR);
1339 1 ▶ else if (!git__prefixcmp(name, GIT_REFS_TAGS_DIR))
Branch: 1 branch
BranchTrueFalseTotal
else if (!git__prefixcmp(name, GIT_REFS_TAGS_DIR)) 0 1 1
1340 0 return name + strlen(GIT_REFS_TAGS_DIR);
1341 1 ▶ else if (!git__prefixcmp(name, GIT_REFS_REMOTES_DIR))
Branch: 1 branch
BranchTrueFalseTotal
else if (!git__prefixcmp(name, GIT_REFS_REMOTES_DIR)) 0 1 1
1342 0 return name + strlen(GIT_REFS_REMOTES_DIR);
1343 1 ▶ else if (!git__prefixcmp(name, GIT_REFS_DIR))
Branch: 1 branch
BranchTrueFalseTotal
else if (!git__prefixcmp(name, GIT_REFS_DIR)) 1 0 1
1344 1 return name + strlen(GIT_REFS_DIR);
1345  
1346 /* No shorthands are available, so just return the name. */
1347 0 return name;
1348 }
1349  
1350 4 const char *git_reference_shorthand(const git_reference *ref)
1351 {
1352 4 return git_reference__shorthand(ref->name);
1353 }
1354  
1355 5 int git_reference__is_unborn_head(bool *unborn, const git_reference *ref, git_repository *repo)
1356 {
1357 int error;
1358 git_reference *tmp_ref;
1359  
1360 5 ▶ GIT_ASSERT_ARG(unborn);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(unborn); 0 5 5
1361 5 ▶ GIT_ASSERT_ARG(ref);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(ref); 0 5 5
1362 5 ▶ GIT_ASSERT_ARG(repo);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT_ARG(repo); 0 5 5
1363  
1364 5 ▶ if (ref->type == GIT_REFERENCE_DIRECT) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref->type == GIT_REFERENCE_DIRECT) { 0 5 5
1365 0 *unborn = 0;
1366 0 return 0;
1367 }
1368  
1369 5 error = git_reference_lookup_resolved(&tmp_ref, repo, ref->name, -1);
1370 5 git_reference_free(tmp_ref);
1371  
1372 5 ▶ if (error != 0 && error != GIT_ENOTFOUND)
Branch: 2 branches
BranchTrueFalseTotal
if (error != 0 && error != GIT_ENOTFOUND) 0 5 5
if (error != 0 && error != GIT_ENOTFOUND) 0 0 0
1373 0 return error;
1374 5 ▶ else if (error == GIT_ENOTFOUND && git__strcmp(ref->name, GIT_HEAD_FILE) == 0)
Branch: 2 branches
BranchTrueFalseTotal
else if (error == GIT_ENOTFOUND && git__strcmp(ref->name, GIT_HEAD_FILE) == 0) 0 5 5
else if (error == GIT_ENOTFOUND && git__strcmp(ref->name, GIT_HEAD_FILE) == 0) 0 0 0
1375 0 *unborn = true;
1376 else
1377 5 *unborn = false;
1378  
1379 5 return 0;
1380 }
1381  
1382 /* Deprecated functions */
1383  
1384 #ifndef GIT_DEPRECATE_HARD
1385  
1386 0 int git_reference_is_valid_name(const char *refname)
1387 {
1388 0 int valid = 0;
1389  
1390 0 git_reference__name_is_valid(&valid, refname, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL);
1391  
1392 0 return valid;
1393 }
1394  
1395 #endif
« const-xs-error.inc ↑ Summary deps/libgit2/src/libgit2/trailer.c »