| 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 "tag.h" |
| 9 |
|
| |
| 10 |
|
| #include "commit.h" |
| 11 |
|
| #include "signature.h" |
| 12 |
|
| #include "wildmatch.h" |
| 13 |
|
| #include "git2/object.h" |
| 14 |
|
| #include "git2/repository.h" |
| 15 |
|
| #include "git2/signature.h" |
| 16 |
|
| #include "git2/odb_backend.h" |
| 17 |
|
| |
| 18 |
0 |
| void git_tag__free(void *_tag) |
| 19 |
|
| { |
| 20 |
0 |
| git_tag *tag = _tag; |
| 21 |
0 |
| git_signature_free(tag->tagger); |
| 22 |
0 |
| git__free(tag->message); |
| 23 |
0 |
| git__free(tag->tag_name); |
| 24 |
0 |
| git__free(tag); |
| 25 |
0 |
| } |
| 26 |
|
| |
| 27 |
1 |
| int git_tag_target(git_object **target, const git_tag *t) |
| 28 |
|
| { |
| 29 |
1 |
▶ | GIT_ASSERT_ARG(t); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(t); |
0 |
1 |
1 |
|
| 30 |
1 |
| return git_object_lookup(target, t->object.repo, &t->target, t->type); |
| 31 |
|
| } |
| 32 |
|
| |
| 33 |
0 |
| const git_oid *git_tag_target_id(const git_tag *t) |
| 34 |
|
| { |
| 35 |
0 |
▶ | GIT_ASSERT_ARG_WITH_RETVAL(t, NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG_WITH_RETVAL(t, NULL); |
0 |
0 |
0 |
|
| 36 |
0 |
| return &t->target; |
| 37 |
|
| } |
| 38 |
|
| |
| 39 |
0 |
| git_object_t git_tag_target_type(const git_tag *t) |
| 40 |
|
| { |
| 41 |
0 |
▶ | GIT_ASSERT_ARG_WITH_RETVAL(t, GIT_OBJECT_INVALID); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG_WITH_RETVAL(t, GIT_OBJECT_INVALID); |
0 |
0 |
0 |
|
| 42 |
0 |
| return t->type; |
| 43 |
|
| } |
| 44 |
|
| |
| 45 |
3 |
| const char *git_tag_name(const git_tag *t) |
| 46 |
|
| { |
| 47 |
3 |
▶ | GIT_ASSERT_ARG_WITH_RETVAL(t, NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG_WITH_RETVAL(t, NULL); |
0 |
3 |
3 |
|
| 48 |
3 |
| return t->tag_name; |
| 49 |
|
| } |
| 50 |
|
| |
| 51 |
4 |
| const git_signature *git_tag_tagger(const git_tag *t) |
| 52 |
|
| { |
| 53 |
4 |
| return t->tagger; |
| 54 |
|
| } |
| 55 |
|
| |
| 56 |
2 |
| const char *git_tag_message(const git_tag *t) |
| 57 |
|
| { |
| 58 |
2 |
▶ | GIT_ASSERT_ARG_WITH_RETVAL(t, NULL); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG_WITH_RETVAL(t, NULL); |
0 |
2 |
2 |
|
| 59 |
2 |
| return t->message; |
| 60 |
|
| } |
| 61 |
|
| |
| 62 |
0 |
| static int tag_error(const char *str) |
| 63 |
|
| { |
| 64 |
0 |
| git_error_set(GIT_ERROR_TAG, "failed to parse tag: %s", str); |
| 65 |
0 |
| return GIT_EINVALID; |
| 66 |
|
| } |
| 67 |
|
| |
| 68 |
1 |
| static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end) |
| 69 |
|
| { |
| 70 |
|
| static const char *tag_types[] = { |
| 71 |
|
| NULL, "commit\n", "tree\n", "blob\n", "tag\n" |
| 72 |
|
| }; |
| 73 |
|
| size_t text_len, alloc_len; |
| 74 |
|
| const char *search; |
| 75 |
|
| unsigned int i; |
| 76 |
|
| int error; |
| 77 |
|
| |
| 78 |
1 |
▶ | if (git_oid__parse(&tag->target, &buffer, buffer_end, "object ") < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (git_oid__parse(&tag->target, &buffer, buffer_end, "object ") < 0) |
0 |
1 |
1 |
|
| 79 |
0 |
| return tag_error("object field invalid"); |
| 80 |
|
| |
| 81 |
1 |
▶ | if (buffer + 5 >= buffer_end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (buffer + 5 >= buffer_end) |
0 |
1 |
1 |
|
| 82 |
0 |
| return tag_error("object too short"); |
| 83 |
|
| |
| 84 |
1 |
▶ | if (memcmp(buffer, "type ", 5) != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (memcmp(buffer, "type ", 5) != 0) |
0 |
1 |
1 |
|
| 85 |
0 |
| return tag_error("type field not found"); |
| 86 |
1 |
| buffer += 5; |
| 87 |
|
| |
| 88 |
1 |
| tag->type = GIT_OBJECT_INVALID; |
| 89 |
|
| |
| 90 |
1 |
▶ | for (i = 1; i < ARRAY_SIZE(tag_types); ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < ARRAY_SIZE(tag_types); ++i) { |
1 |
0 |
1 |
|
| 91 |
1 |
| size_t type_length = strlen(tag_types[i]); |
| 92 |
|
| |
| 93 |
1 |
▶ | if (buffer + type_length >= buffer_end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (buffer + type_length >= buffer_end) |
0 |
1 |
1 |
|
| 94 |
0 |
| return tag_error("object too short"); |
| 95 |
|
| |
| 96 |
1 |
▶ | if (memcmp(buffer, tag_types[i], type_length) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (memcmp(buffer, tag_types[i], type_length) == 0) { |
1 |
0 |
1 |
|
| 97 |
1 |
| tag->type = i; |
| 98 |
1 |
| buffer += type_length; |
| 99 |
1 |
| break; |
| 100 |
|
| } |
| 101 |
|
| } |
| 102 |
|
| |
| 103 |
1 |
▶ | if (tag->type == GIT_OBJECT_INVALID) |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag->type == GIT_OBJECT_INVALID) |
0 |
1 |
1 |
|
| 104 |
0 |
| return tag_error("invalid object type"); |
| 105 |
|
| |
| 106 |
1 |
▶ | if (buffer + 4 >= buffer_end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (buffer + 4 >= buffer_end) |
0 |
1 |
1 |
|
| 107 |
0 |
| return tag_error("object too short"); |
| 108 |
|
| |
| 109 |
1 |
▶ | if (memcmp(buffer, "tag ", 4) != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (memcmp(buffer, "tag ", 4) != 0) |
0 |
1 |
1 |
|
| 110 |
0 |
| return tag_error("tag field not found"); |
| 111 |
|
| |
| 112 |
1 |
| buffer += 4; |
| 113 |
|
| |
| 114 |
1 |
| search = memchr(buffer, '\n', buffer_end - buffer); |
| 115 |
1 |
▶ | if (search == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (search == NULL) |
0 |
1 |
1 |
|
| 116 |
0 |
| return tag_error("object too short"); |
| 117 |
|
| |
| 118 |
1 |
| text_len = search - buffer; |
| 119 |
|
| |
| 120 |
1 |
▶ | GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); |
Branch: 2 branches
| Branch | True | False | Total |
| GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); |
0 |
1 |
1 |
| GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); |
0 |
1 |
1 |
|
| 121 |
1 |
| tag->tag_name = git__malloc(alloc_len); |
| 122 |
1 |
▶ | GIT_ERROR_CHECK_ALLOC(tag->tag_name); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ERROR_CHECK_ALLOC(tag->tag_name); |
0 |
1 |
1 |
|
| 123 |
|
| |
| 124 |
1 |
| memcpy(tag->tag_name, buffer, text_len); |
| 125 |
1 |
| tag->tag_name[text_len] = '\0'; |
| 126 |
|
| |
| 127 |
1 |
| buffer = search + 1; |
| 128 |
|
| |
| 129 |
1 |
| tag->tagger = NULL; |
| 130 |
1 |
▶ | if (buffer < buffer_end && *buffer != '\n') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (buffer < buffer_end && *buffer != '\n') { |
1 |
0 |
1 |
| if (buffer < buffer_end && *buffer != '\n') { |
1 |
0 |
1 |
|
| 131 |
1 |
| tag->tagger = git__malloc(sizeof(git_signature)); |
| 132 |
1 |
▶ | GIT_ERROR_CHECK_ALLOC(tag->tagger); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ERROR_CHECK_ALLOC(tag->tagger); |
0 |
1 |
1 |
|
| 133 |
|
| |
| 134 |
1 |
▶ | if ((error = git_signature__parse(tag->tagger, &buffer, buffer_end, "tagger ", '\n')) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((error = git_signature__parse(tag->tagger, &buffer, buffer_end, "tagger ", '\n')) < 0) |
0 |
1 |
1 |
|
| 135 |
0 |
| return error; |
| 136 |
|
| } |
| 137 |
|
| |
| 138 |
1 |
| tag->message = NULL; |
| 139 |
1 |
▶ | if (buffer < buffer_end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (buffer < buffer_end) { |
1 |
0 |
1 |
|
| 140 |
|
| /* If we're not at the end of the header, search for it */ |
| 141 |
1 |
▶ | if(*buffer != '\n') { |
Branch: 1 branch
| Branch | True | False | Total |
| if(*buffer != '\n') { |
0 |
1 |
1 |
|
| 142 |
0 |
| search = git__memmem(buffer, buffer_end - buffer, |
| 143 |
|
| "\n\n", 2); |
| 144 |
0 |
▶ | if (search) |
Branch: 1 branch
| Branch | True | False | Total |
| if (search) |
0 |
0 |
0 |
|
| 145 |
0 |
| buffer = search + 1; |
| 146 |
|
| else |
| 147 |
0 |
| return tag_error("tag contains no message"); |
| 148 |
|
| } |
| 149 |
|
| |
| 150 |
1 |
| text_len = buffer_end - ++buffer; |
| 151 |
|
| |
| 152 |
1 |
▶ | GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); |
Branch: 2 branches
| Branch | True | False | Total |
| GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); |
0 |
1 |
1 |
| GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, text_len, 1); |
0 |
1 |
1 |
|
| 153 |
1 |
| tag->message = git__malloc(alloc_len); |
| 154 |
1 |
▶ | GIT_ERROR_CHECK_ALLOC(tag->message); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ERROR_CHECK_ALLOC(tag->message); |
0 |
1 |
1 |
|
| 155 |
|
| |
| 156 |
1 |
| memcpy(tag->message, buffer, text_len); |
| 157 |
1 |
| tag->message[text_len] = '\0'; |
| 158 |
|
| } |
| 159 |
|
| |
| 160 |
1 |
| return 0; |
| 161 |
|
| } |
| 162 |
|
| |
| 163 |
0 |
| int git_tag__parse_raw(void *_tag, const char *data, size_t size) |
| 164 |
|
| { |
| 165 |
0 |
| return tag_parse(_tag, data, data + size); |
| 166 |
|
| } |
| 167 |
|
| |
| 168 |
1 |
| int git_tag__parse(void *_tag, git_odb_object *odb_obj) |
| 169 |
|
| { |
| 170 |
1 |
| git_tag *tag = _tag; |
| 171 |
1 |
| const char *buffer = git_odb_object_data(odb_obj); |
| 172 |
1 |
| const char *buffer_end = buffer + git_odb_object_size(odb_obj); |
| 173 |
|
| |
| 174 |
1 |
| return tag_parse(tag, buffer, buffer_end); |
| 175 |
|
| } |
| 176 |
|
| |
| 177 |
1 |
| static int retrieve_tag_reference( |
| 178 |
|
| git_reference **tag_reference_out, |
| 179 |
|
| git_str *ref_name_out, |
| 180 |
|
| git_repository *repo, |
| 181 |
|
| const char *tag_name) |
| 182 |
|
| { |
| 183 |
|
| git_reference *tag_ref; |
| 184 |
|
| int error; |
| 185 |
|
| |
| 186 |
1 |
| *tag_reference_out = NULL; |
| 187 |
|
| |
| 188 |
1 |
▶ | if (git_str_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (git_str_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0) |
0 |
1 |
1 |
|
| 189 |
0 |
| return -1; |
| 190 |
|
| |
| 191 |
1 |
| error = git_reference_lookup(&tag_ref, repo, ref_name_out->ptr); |
| 192 |
1 |
▶ | if (error < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (error < 0) |
0 |
1 |
1 |
|
| 193 |
0 |
| return error; /* Be it not foundo or corrupted */ |
| 194 |
|
| |
| 195 |
1 |
| *tag_reference_out = tag_ref; |
| 196 |
|
| |
| 197 |
1 |
| return 0; |
| 198 |
|
| } |
| 199 |
|
| |
| 200 |
1 |
| static int retrieve_tag_reference_oid( |
| 201 |
|
| git_oid *oid, |
| 202 |
|
| git_str *ref_name_out, |
| 203 |
|
| git_repository *repo, |
| 204 |
|
| const char *tag_name) |
| 205 |
|
| { |
| 206 |
1 |
▶ | if (git_str_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (git_str_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0) |
0 |
1 |
1 |
|
| 207 |
0 |
| return -1; |
| 208 |
|
| |
| 209 |
1 |
| return git_reference_name_to_id(oid, repo, ref_name_out->ptr); |
| 210 |
|
| } |
| 211 |
|
| |
| 212 |
1 |
| static int write_tag_annotation( |
| 213 |
|
| git_oid *oid, |
| 214 |
|
| git_repository *repo, |
| 215 |
|
| const char *tag_name, |
| 216 |
|
| const git_object *target, |
| 217 |
|
| const git_signature *tagger, |
| 218 |
|
| const char *message) |
| 219 |
|
| { |
| 220 |
1 |
| git_str tag = GIT_STR_INIT; |
| 221 |
|
| git_odb *odb; |
| 222 |
|
| |
| 223 |
1 |
| git_oid__writebuf(&tag, "object ", git_object_id(target)); |
| 224 |
1 |
| git_str_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target))); |
| 225 |
1 |
| git_str_printf(&tag, "tag %s\n", tag_name); |
| 226 |
1 |
| git_signature__writebuf(&tag, "tagger ", tagger); |
| 227 |
1 |
| git_str_putc(&tag, '\n'); |
| 228 |
|
| |
| 229 |
1 |
▶ | if (git_str_puts(&tag, message) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (git_str_puts(&tag, message) < 0) |
0 |
1 |
1 |
|
| 230 |
0 |
| goto on_error; |
| 231 |
|
| |
| 232 |
1 |
▶ | if (git_repository_odb__weakptr(&odb, repo) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (git_repository_odb__weakptr(&odb, repo) < 0) |
0 |
1 |
1 |
|
| 233 |
0 |
| goto on_error; |
| 234 |
|
| |
| 235 |
1 |
▶ | if (git_odb_write(oid, odb, tag.ptr, tag.size, GIT_OBJECT_TAG) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (git_odb_write(oid, odb, tag.ptr, tag.size, GIT_OBJECT_TAG) < 0) |
0 |
1 |
1 |
|
| 236 |
0 |
| goto on_error; |
| 237 |
|
| |
| 238 |
1 |
| git_str_dispose(&tag); |
| 239 |
1 |
| return 0; |
| 240 |
|
| |
| 241 |
0 |
| on_error: |
| 242 |
0 |
| git_str_dispose(&tag); |
| 243 |
0 |
| git_error_set(GIT_ERROR_OBJECT, "failed to create tag annotation"); |
| 244 |
0 |
| return -1; |
| 245 |
|
| } |
| 246 |
|
| |
| 247 |
1 |
| static bool tag_name_is_valid(const char *tag_name) |
| 248 |
|
| { |
| 249 |
|
| /* |
| 250 |
|
| * Discourage tag name starting with dash, |
| 251 |
|
| * https://github.com/git/git/commit/4f0accd638b8d2 |
| 252 |
|
| */ |
| 253 |
1 |
| return tag_name[0] != '-'; |
| 254 |
|
| } |
| 255 |
|
| |
| 256 |
1 |
| static int git_tag_create__internal( |
| 257 |
|
| git_oid *oid, |
| 258 |
|
| git_repository *repo, |
| 259 |
|
| const char *tag_name, |
| 260 |
|
| const git_object *target, |
| 261 |
|
| const git_signature *tagger, |
| 262 |
|
| const char *message, |
| 263 |
|
| int allow_ref_overwrite, |
| 264 |
|
| int create_tag_annotation) |
| 265 |
|
| { |
| 266 |
1 |
| git_reference *new_ref = NULL; |
| 267 |
1 |
| git_str ref_name = GIT_STR_INIT; |
| 268 |
|
| |
| 269 |
|
| int error; |
| 270 |
|
| |
| 271 |
1 |
▶ | GIT_ASSERT_ARG(repo); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(repo); |
0 |
1 |
1 |
|
| 272 |
1 |
▶ | GIT_ASSERT_ARG(tag_name); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(tag_name); |
0 |
1 |
1 |
|
| 273 |
1 |
▶ | GIT_ASSERT_ARG(target); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(target); |
0 |
1 |
1 |
|
| 274 |
1 |
▶ | GIT_ASSERT_ARG(!create_tag_annotation || (tagger && message)); |
Branch: 3 branches
| Branch | True | False | Total |
| GIT_ASSERT_ARG(!create_tag_annotation || (tagger && message)); |
1 |
0 |
1 |
| GIT_ASSERT_ARG(!create_tag_annotation || (tagger && message)); |
1 |
0 |
1 |
| GIT_ASSERT_ARG(!create_tag_annotation || (tagger && message)); |
0 |
1 |
1 |
|
| 275 |
|
| |
| 276 |
1 |
▶ | if (git_object_owner(target) != repo) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (git_object_owner(target) != repo) { |
0 |
1 |
1 |
|
| 277 |
0 |
| git_error_set(GIT_ERROR_INVALID, "the given target does not belong to this repository"); |
| 278 |
0 |
| return -1; |
| 279 |
|
| } |
| 280 |
|
| |
| 281 |
1 |
▶ | if (!tag_name_is_valid(tag_name)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!tag_name_is_valid(tag_name)) { |
0 |
1 |
1 |
|
| 282 |
0 |
| git_error_set(GIT_ERROR_TAG, "'%s' is not a valid tag name", tag_name); |
| 283 |
0 |
| return -1; |
| 284 |
|
| } |
| 285 |
|
| |
| 286 |
1 |
| error = retrieve_tag_reference_oid(oid, &ref_name, repo, tag_name); |
| 287 |
1 |
▶ | if (error < 0 && error != GIT_ENOTFOUND) |
Branch: 2 branches
| Branch | True | False | Total |
| if (error < 0 && error != GIT_ENOTFOUND) |
1 |
0 |
1 |
| if (error < 0 && error != GIT_ENOTFOUND) |
0 |
1 |
1 |
|
| 288 |
0 |
| goto cleanup; |
| 289 |
|
| |
| 290 |
|
| /** Ensure the tag name doesn't conflict with an already existing |
| 291 |
|
| * reference unless overwriting has explicitly been requested **/ |
| 292 |
1 |
▶ | if (error == 0 && !allow_ref_overwrite) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (error == 0 && !allow_ref_overwrite) { |
0 |
1 |
1 |
| if (error == 0 && !allow_ref_overwrite) { |
0 |
0 |
0 |
|
| 293 |
0 |
| git_str_dispose(&ref_name); |
| 294 |
0 |
| git_error_set(GIT_ERROR_TAG, "tag already exists"); |
| 295 |
0 |
| return GIT_EEXISTS; |
| 296 |
|
| } |
| 297 |
|
| |
| 298 |
1 |
▶ | if (create_tag_annotation) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (create_tag_annotation) { |
1 |
0 |
1 |
|
| 299 |
1 |
▶ | if (write_tag_annotation(oid, repo, tag_name, target, tagger, message) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (write_tag_annotation(oid, repo, tag_name, target, tagger, message) < 0) |
0 |
1 |
1 |
|
| 300 |
0 |
| return -1; |
| 301 |
|
| } else |
| 302 |
0 |
| git_oid_cpy(oid, git_object_id(target)); |
| 303 |
|
| |
| 304 |
1 |
| error = git_reference_create(&new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL); |
| 305 |
|
| |
| 306 |
1 |
| cleanup: |
| 307 |
1 |
| git_reference_free(new_ref); |
| 308 |
1 |
| git_str_dispose(&ref_name); |
| 309 |
1 |
| return error; |
| 310 |
|
| } |
| 311 |
|
| |
| 312 |
1 |
| int git_tag_create( |
| 313 |
|
| git_oid *oid, |
| 314 |
|
| git_repository *repo, |
| 315 |
|
| const char *tag_name, |
| 316 |
|
| const git_object *target, |
| 317 |
|
| const git_signature *tagger, |
| 318 |
|
| const char *message, |
| 319 |
|
| int allow_ref_overwrite) |
| 320 |
|
| { |
| 321 |
1 |
| return git_tag_create__internal(oid, repo, tag_name, target, tagger, message, allow_ref_overwrite, 1); |
| 322 |
|
| } |
| 323 |
|
| |
| 324 |
0 |
| int git_tag_annotation_create( |
| 325 |
|
| git_oid *oid, |
| 326 |
|
| git_repository *repo, |
| 327 |
|
| const char *tag_name, |
| 328 |
|
| const git_object *target, |
| 329 |
|
| const git_signature *tagger, |
| 330 |
|
| const char *message) |
| 331 |
|
| { |
| 332 |
0 |
▶ | GIT_ASSERT_ARG(oid); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(oid); |
0 |
0 |
0 |
|
| 333 |
0 |
▶ | GIT_ASSERT_ARG(repo); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(repo); |
0 |
0 |
0 |
|
| 334 |
0 |
▶ | GIT_ASSERT_ARG(tag_name); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(tag_name); |
0 |
0 |
0 |
|
| 335 |
0 |
▶ | GIT_ASSERT_ARG(target); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(target); |
0 |
0 |
0 |
|
| 336 |
0 |
▶ | GIT_ASSERT_ARG(tagger); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(tagger); |
0 |
0 |
0 |
|
| 337 |
0 |
▶ | GIT_ASSERT_ARG(message); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(message); |
0 |
0 |
0 |
|
| 338 |
|
| |
| 339 |
0 |
| return write_tag_annotation(oid, repo, tag_name, target, tagger, message); |
| 340 |
|
| } |
| 341 |
|
| |
| 342 |
0 |
| int git_tag_create_lightweight( |
| 343 |
|
| git_oid *oid, |
| 344 |
|
| git_repository *repo, |
| 345 |
|
| const char *tag_name, |
| 346 |
|
| const git_object *target, |
| 347 |
|
| int allow_ref_overwrite) |
| 348 |
|
| { |
| 349 |
0 |
| return git_tag_create__internal(oid, repo, tag_name, target, NULL, NULL, allow_ref_overwrite, 0); |
| 350 |
|
| } |
| 351 |
|
| |
| 352 |
0 |
| int git_tag_create_from_buffer(git_oid *oid, git_repository *repo, const char *buffer, int allow_ref_overwrite) |
| 353 |
|
| { |
| 354 |
|
| git_tag tag; |
| 355 |
|
| int error; |
| 356 |
|
| git_odb *odb; |
| 357 |
|
| git_odb_stream *stream; |
| 358 |
|
| git_odb_object *target_obj; |
| 359 |
|
| |
| 360 |
0 |
| git_reference *new_ref = NULL; |
| 361 |
0 |
| git_str ref_name = GIT_STR_INIT; |
| 362 |
|
| |
| 363 |
0 |
▶ | GIT_ASSERT_ARG(oid); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(oid); |
0 |
0 |
0 |
|
| 364 |
0 |
▶ | GIT_ASSERT_ARG(buffer); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(buffer); |
0 |
0 |
0 |
|
| 365 |
|
| |
| 366 |
0 |
| memset(&tag, 0, sizeof(tag)); |
| 367 |
|
| |
| 368 |
0 |
▶ | if (git_repository_odb__weakptr(&odb, repo) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (git_repository_odb__weakptr(&odb, repo) < 0) |
0 |
0 |
0 |
|
| 369 |
0 |
| return -1; |
| 370 |
|
| |
| 371 |
|
| /* validate the buffer */ |
| 372 |
0 |
▶ | if (tag_parse(&tag, buffer, buffer + strlen(buffer)) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag_parse(&tag, buffer, buffer + strlen(buffer)) < 0) |
0 |
0 |
0 |
|
| 373 |
0 |
| return -1; |
| 374 |
|
| |
| 375 |
|
| /* validate the target */ |
| 376 |
0 |
▶ | if (git_odb_read(&target_obj, odb, &tag.target) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (git_odb_read(&target_obj, odb, &tag.target) < 0) |
0 |
0 |
0 |
|
| 377 |
0 |
| goto on_error; |
| 378 |
|
| |
| 379 |
0 |
▶ | if (tag.type != target_obj->cached.type) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag.type != target_obj->cached.type) { |
0 |
0 |
0 |
|
| 380 |
0 |
| git_error_set(GIT_ERROR_TAG, "the type for the given target is invalid"); |
| 381 |
0 |
| goto on_error; |
| 382 |
|
| } |
| 383 |
|
| |
| 384 |
0 |
| error = retrieve_tag_reference_oid(oid, &ref_name, repo, tag.tag_name); |
| 385 |
0 |
▶ | if (error < 0 && error != GIT_ENOTFOUND) |
Branch: 2 branches
| Branch | True | False | Total |
| if (error < 0 && error != GIT_ENOTFOUND) |
0 |
0 |
0 |
| if (error < 0 && error != GIT_ENOTFOUND) |
0 |
0 |
0 |
|
| 386 |
0 |
| goto on_error; |
| 387 |
|
| |
| 388 |
|
| /* We don't need these objects after this */ |
| 389 |
0 |
| git_signature_free(tag.tagger); |
| 390 |
0 |
| git__free(tag.tag_name); |
| 391 |
0 |
| git__free(tag.message); |
| 392 |
0 |
| git_odb_object_free(target_obj); |
| 393 |
|
| |
| 394 |
|
| /** Ensure the tag name doesn't conflict with an already existing |
| 395 |
|
| * reference unless overwriting has explicitly been requested **/ |
| 396 |
0 |
▶ | if (error == 0 && !allow_ref_overwrite) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (error == 0 && !allow_ref_overwrite) { |
0 |
0 |
0 |
| if (error == 0 && !allow_ref_overwrite) { |
0 |
0 |
0 |
|
| 397 |
0 |
| git_error_set(GIT_ERROR_TAG, "tag already exists"); |
| 398 |
0 |
| return GIT_EEXISTS; |
| 399 |
|
| } |
| 400 |
|
| |
| 401 |
|
| /* write the buffer */ |
| 402 |
0 |
▶ | if ((error = git_odb_open_wstream( |
Branch: 1 branch
| Branch | True | False | Total |
| if ((error = git_odb_open_wstream( |
0 |
0 |
0 |
|
| 403 |
|
| &stream, odb, strlen(buffer), GIT_OBJECT_TAG)) < 0) |
| 404 |
0 |
| return error; |
| 405 |
|
| |
| 406 |
0 |
▶ | if (!(error = git_odb_stream_write(stream, buffer, strlen(buffer)))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(error = git_odb_stream_write(stream, buffer, strlen(buffer)))) |
0 |
0 |
0 |
|
| 407 |
0 |
| error = git_odb_stream_finalize_write(oid, stream); |
| 408 |
|
| |
| 409 |
0 |
| git_odb_stream_free(stream); |
| 410 |
|
| |
| 411 |
0 |
▶ | if (error < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (error < 0) { |
0 |
0 |
0 |
|
| 412 |
0 |
| git_str_dispose(&ref_name); |
| 413 |
0 |
| return error; |
| 414 |
|
| } |
| 415 |
|
| |
| 416 |
0 |
| error = git_reference_create( |
| 417 |
0 |
| &new_ref, repo, ref_name.ptr, oid, allow_ref_overwrite, NULL); |
| 418 |
|
| |
| 419 |
0 |
| git_reference_free(new_ref); |
| 420 |
0 |
| git_str_dispose(&ref_name); |
| 421 |
|
| |
| 422 |
0 |
| return error; |
| 423 |
|
| |
| 424 |
0 |
| on_error: |
| 425 |
0 |
| git_signature_free(tag.tagger); |
| 426 |
0 |
| git__free(tag.tag_name); |
| 427 |
0 |
| git__free(tag.message); |
| 428 |
0 |
| git_odb_object_free(target_obj); |
| 429 |
0 |
| return -1; |
| 430 |
|
| } |
| 431 |
|
| |
| 432 |
1 |
| int git_tag_delete(git_repository *repo, const char *tag_name) |
| 433 |
|
| { |
| 434 |
|
| git_reference *tag_ref; |
| 435 |
1 |
| git_str ref_name = GIT_STR_INIT; |
| 436 |
|
| int error; |
| 437 |
|
| |
| 438 |
1 |
| error = retrieve_tag_reference(&tag_ref, &ref_name, repo, tag_name); |
| 439 |
|
| |
| 440 |
1 |
| git_str_dispose(&ref_name); |
| 441 |
|
| |
| 442 |
1 |
▶ | if (error < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (error < 0) |
0 |
1 |
1 |
|
| 443 |
0 |
| return error; |
| 444 |
|
| |
| 445 |
1 |
| error = git_reference_delete(tag_ref); |
| 446 |
|
| |
| 447 |
1 |
| git_reference_free(tag_ref); |
| 448 |
|
| |
| 449 |
1 |
| return error; |
| 450 |
|
| } |
| 451 |
|
| |
| 452 |
|
| typedef struct { |
| 453 |
|
| git_repository *repo; |
| 454 |
|
| git_tag_foreach_cb cb; |
| 455 |
|
| void *cb_data; |
| 456 |
|
| } tag_cb_data; |
| 457 |
|
| |
| 458 |
99 |
| static int tags_cb(const char *ref, void *data) |
| 459 |
|
| { |
| 460 |
|
| int error; |
| 461 |
|
| git_oid oid; |
| 462 |
99 |
| tag_cb_data *d = (tag_cb_data *)data; |
| 463 |
|
| |
| 464 |
99 |
▶ | if (git__prefixcmp(ref, GIT_REFS_TAGS_DIR) != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (git__prefixcmp(ref, GIT_REFS_TAGS_DIR) != 0) |
90 |
9 |
99 |
|
| 465 |
90 |
| return 0; /* no tag */ |
| 466 |
|
| |
| 467 |
9 |
▶ | if (!(error = git_reference_name_to_id(&oid, d->repo, ref))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(error = git_reference_name_to_id(&oid, d->repo, ref))) { |
9 |
0 |
9 |
|
| 468 |
9 |
▶ | if ((error = d->cb(ref, &oid, d->cb_data)) != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((error = d->cb(ref, &oid, d->cb_data)) != 0) |
1 |
8 |
9 |
|
| 469 |
1 |
| git_error_set_after_callback_function(error, "git_tag_foreach"); |
| 470 |
|
| } |
| 471 |
|
| |
| 472 |
9 |
| return error; |
| 473 |
|
| } |
| 474 |
|
| |
| 475 |
16 |
| int git_tag_foreach(git_repository *repo, git_tag_foreach_cb cb, void *cb_data) |
| 476 |
|
| { |
| 477 |
|
| tag_cb_data data; |
| 478 |
|
| |
| 479 |
16 |
▶ | GIT_ASSERT_ARG(repo); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(repo); |
0 |
16 |
16 |
|
| 480 |
16 |
▶ | GIT_ASSERT_ARG(cb); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(cb); |
0 |
16 |
16 |
|
| 481 |
|
| |
| 482 |
16 |
| data.cb = cb; |
| 483 |
16 |
| data.cb_data = cb_data; |
| 484 |
16 |
| data.repo = repo; |
| 485 |
|
| |
| 486 |
16 |
| return git_reference_foreach_name(repo, &tags_cb, &data); |
| 487 |
|
| } |
| 488 |
|
| |
| 489 |
|
| typedef struct { |
| 490 |
|
| git_vector *taglist; |
| 491 |
|
| const char *pattern; |
| 492 |
|
| } tag_filter_data; |
| 493 |
|
| |
| 494 |
|
| #define GIT_REFS_TAGS_DIR_LEN strlen(GIT_REFS_TAGS_DIR) |
| 495 |
|
| |
| 496 |
0 |
| static int tag_list_cb(const char *tag_name, git_oid *oid, void *data) |
| 497 |
|
| { |
| 498 |
0 |
| tag_filter_data *filter = (tag_filter_data *)data; |
| 499 |
0 |
| GIT_UNUSED(oid); |
| 500 |
|
| |
| 501 |
0 |
| if (!*filter->pattern || |
| 502 |
0 |
| wildmatch(filter->pattern, tag_name + GIT_REFS_TAGS_DIR_LEN, 0) == 0) |
| 503 |
|
| { |
| 504 |
0 |
| char *matched = git__strdup(tag_name + GIT_REFS_TAGS_DIR_LEN); |
| 505 |
0 |
▶ | GIT_ERROR_CHECK_ALLOC(matched); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ERROR_CHECK_ALLOC(matched); |
0 |
0 |
0 |
|
| 506 |
|
| |
| 507 |
0 |
| return git_vector_insert(filter->taglist, matched); |
| 508 |
|
| } |
| 509 |
|
| |
| 510 |
0 |
| return 0; |
| 511 |
|
| } |
| 512 |
|
| |
| 513 |
0 |
| int git_tag_list_match(git_strarray *tag_names, const char *pattern, git_repository *repo) |
| 514 |
|
| { |
| 515 |
|
| int error; |
| 516 |
|
| tag_filter_data filter; |
| 517 |
|
| git_vector taglist; |
| 518 |
|
| |
| 519 |
0 |
▶ | GIT_ASSERT_ARG(tag_names); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(tag_names); |
0 |
0 |
0 |
|
| 520 |
0 |
▶ | GIT_ASSERT_ARG(repo); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(repo); |
0 |
0 |
0 |
|
| 521 |
0 |
▶ | GIT_ASSERT_ARG(pattern); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT_ARG(pattern); |
0 |
0 |
0 |
|
| 522 |
|
| |
| 523 |
0 |
▶ | if ((error = git_vector_init(&taglist, 8, NULL)) < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((error = git_vector_init(&taglist, 8, NULL)) < 0) |
0 |
0 |
0 |
|
| 524 |
0 |
| return error; |
| 525 |
|
| |
| 526 |
0 |
| filter.taglist = &taglist; |
| 527 |
0 |
| filter.pattern = pattern; |
| 528 |
|
| |
| 529 |
0 |
| error = git_tag_foreach(repo, &tag_list_cb, (void *)&filter); |
| 530 |
|
| |
| 531 |
0 |
▶ | if (error < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (error < 0) |
0 |
0 |
0 |
|
| 532 |
0 |
| git_vector_free(&taglist); |
| 533 |
|
| |
| 534 |
0 |
| tag_names->strings = |
| 535 |
0 |
| (char **)git_vector_detach(&tag_names->count, NULL, &taglist); |
| 536 |
|
| |
| 537 |
0 |
| return 0; |
| 538 |
|
| } |
| 539 |
|
| |
| 540 |
0 |
| int git_tag_list(git_strarray *tag_names, git_repository *repo) |
| 541 |
|
| { |
| 542 |
0 |
| return git_tag_list_match(tag_names, "", repo); |
| 543 |
|
| } |
| 544 |
|
| |
| 545 |
0 |
| int git_tag_peel(git_object **tag_target, const git_tag *tag) |
| 546 |
|
| { |
| 547 |
0 |
| return git_object_peel(tag_target, (const git_object *)tag, GIT_OBJECT_ANY); |
| 548 |
|
| } |
| 549 |
|
| |
| 550 |
0 |
| int git_tag_name_is_valid(int *valid, const char *name) |
| 551 |
|
| { |
| 552 |
0 |
| git_str ref_name = GIT_STR_INIT; |
| 553 |
0 |
| int error = 0; |
| 554 |
|
| |
| 555 |
0 |
▶ | GIT_ASSERT(valid); |
Branch: 1 branch
| Branch | True | False | Total |
| GIT_ASSERT(valid); |
0 |
0 |
0 |
|
| 556 |
|
| |
| 557 |
0 |
| *valid = 0; |
| 558 |
|
| |
| 559 |
0 |
▶ | if (!name || !tag_name_is_valid(name)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name || !tag_name_is_valid(name)) |
0 |
0 |
0 |
| if (!name || !tag_name_is_valid(name)) |
0 |
0 |
0 |
|
| 560 |
0 |
| goto done; |
| 561 |
|
| |
| 562 |
0 |
| if ((error = git_str_puts(&ref_name, GIT_REFS_TAGS_DIR)) < 0 || |
| 563 |
0 |
| (error = git_str_puts(&ref_name, name)) < 0) |
| 564 |
0 |
| goto done; |
| 565 |
|
| |
| 566 |
0 |
| error = git_reference_name_is_valid(valid, ref_name.ptr); |
| 567 |
|
| |
| 568 |
0 |
| done: |
| 569 |
0 |
| git_str_dispose(&ref_name); |
| 570 |
0 |
| return error; |
| 571 |
|
| } |
| 572 |
|
| |
| 573 |
|
| /* Deprecated Functions */ |
| 574 |
|
| |
| 575 |
|
| #ifndef GIT_DEPRECATE_HARD |
| 576 |
0 |
| int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *buffer, int allow_ref_overwrite) |
| 577 |
|
| { |
| 578 |
0 |
| return git_tag_create_from_buffer(oid, repo, buffer, allow_ref_overwrite); |
| 579 |
|
| } |
| 580 |
|
| #endif |