Merge pull request #1451 from nulltoken/topic/support_taggerless_tags Support tags with no tagger nor message
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
diff --git a/include/git2/tag.h b/include/git2/tag.h
index 1ffeb0b..84c954c 100644
--- a/include/git2/tag.h
+++ b/include/git2/tag.h
@@ -121,7 +121,7 @@ GIT_EXTERN(const char *) git_tag_name(const git_tag *tag);
* Get the tagger (author) of a tag
*
* @param tag a previously loaded tag.
- * @return reference to the tag's author
+ * @return reference to the tag's author or NULL when unspecified
*/
GIT_EXTERN(const git_signature *) git_tag_tagger(const git_tag *tag);
@@ -129,7 +129,7 @@ GIT_EXTERN(const git_signature *) git_tag_tagger(const git_tag *tag);
* Get the message of a tag
*
* @param tag a previously loaded tag.
- * @return message of the tag
+ * @return message of the tag or NULL when unspecified
*/
GIT_EXTERN(const char *) git_tag_message(const git_tag *tag);
diff --git a/src/tag.c b/src/tag.c
index e52467f..735ba7e 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -131,7 +131,7 @@ int git_tag__parse_buffer(git_tag *tag, const char *buffer, size_t length)
buffer = search + 1;
tag->tagger = NULL;
- if (*buffer != '\n') {
+ if (buffer < buffer_end && *buffer != '\n') {
tag->tagger = git__malloc(sizeof(git_signature));
GITERR_CHECK_ALLOC(tag->tagger);
diff --git a/tests-clar/network/fetchlocal.c b/tests-clar/network/fetchlocal.c
index e2ba675..bcf298c 100644
--- a/tests-clar/network/fetchlocal.c
+++ b/tests-clar/network/fetchlocal.c
@@ -35,7 +35,7 @@ void test_network_fetchlocal__complete(void)
cl_git_pass(git_remote_update_tips(origin));
cl_git_pass(git_reference_list(&refnames, repo, GIT_REF_LISTALL));
- cl_assert_equal_i(18, (int)refnames.count);
+ cl_assert_equal_i(19, (int)refnames.count);
cl_assert(callcount > 0);
git_strarray_free(&refnames);
@@ -70,7 +70,7 @@ void test_network_fetchlocal__partial(void)
git_strarray_free(&refnames);
cl_git_pass(git_reference_list(&refnames, repo, GIT_REF_LISTALL));
- cl_assert_equal_i(19, (int)refnames.count); /* 18 remote + 1 local */
+ cl_assert_equal_i(20, (int)refnames.count); /* 18 remote + 1 local */
cl_assert(callcount > 0);
git_strarray_free(&refnames);
diff --git a/tests-clar/network/remote/local.c b/tests-clar/network/remote/local.c
index db7d8af..7e847e6 100644
--- a/tests-clar/network/remote/local.c
+++ b/tests-clar/network/remote/local.c
@@ -72,7 +72,7 @@ void test_network_remote_local__retrieve_advertised_references(void)
cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
- cl_assert_equal_i(how_many_refs, 26);
+ cl_assert_equal_i(how_many_refs, 28);
}
void test_network_remote_local__retrieve_advertised_references_from_spaced_repository(void)
@@ -86,7 +86,7 @@ void test_network_remote_local__retrieve_advertised_references_from_spaced_repos
cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
- cl_assert_equal_i(how_many_refs, 26);
+ cl_assert_equal_i(how_many_refs, 28);
git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */
remote = NULL;
diff --git a/tests-clar/object/tag/read.c b/tests-clar/object/tag/read.c
index 16e3e63..c9787a4 100644
--- a/tests-clar/object/tag/read.c
+++ b/tests-clar/object/tag/read.c
@@ -9,111 +9,134 @@ static const char *bad_tag_id = "eda9f45a2a98d4c17a09d681d88569fa4ea91755";
static const char *badly_tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
static const char *short_tag_id = "5da7760512a953e3c7c4e47e4392c7a4338fb729";
static const char *short_tagged_commit = "4a5ed60bafcf4638b7c8356bd4ce1916bfede93c";
+static const char *taggerless = "4a23e2e65ad4e31c4c9db7dc746650bfad082679";
static git_repository *g_repo;
// Fixture setup and teardown
void test_object_tag_read__initialize(void)
{
- g_repo = cl_git_sandbox_init("testrepo");
+ g_repo = cl_git_sandbox_init("testrepo");
}
void test_object_tag_read__cleanup(void)
{
- cl_git_sandbox_cleanup();
+ cl_git_sandbox_cleanup();
}
void test_object_tag_read__parse(void)
{
- // read and parse a tag from the repository
- git_tag *tag1, *tag2;
- git_commit *commit;
- git_oid id1, id2, id_commit;
+ // read and parse a tag from the repository
+ git_tag *tag1, *tag2;
+ git_commit *commit;
+ git_oid id1, id2, id_commit;
- git_oid_fromstr(&id1, tag1_id);
- git_oid_fromstr(&id2, tag2_id);
- git_oid_fromstr(&id_commit, tagged_commit);
+ git_oid_fromstr(&id1, tag1_id);
+ git_oid_fromstr(&id2, tag2_id);
+ git_oid_fromstr(&id_commit, tagged_commit);
- cl_git_pass(git_tag_lookup(&tag1, g_repo, &id1));
+ cl_git_pass(git_tag_lookup(&tag1, g_repo, &id1));
- cl_assert_equal_s(git_tag_name(tag1), "test");
- cl_assert(git_tag_target_type(tag1) == GIT_OBJ_TAG);
+ cl_assert_equal_s(git_tag_name(tag1), "test");
+ cl_assert(git_tag_target_type(tag1) == GIT_OBJ_TAG);
- cl_git_pass(git_tag_target((git_object **)&tag2, tag1));
- cl_assert(tag2 != NULL);
+ cl_git_pass(git_tag_target((git_object **)&tag2, tag1));
+ cl_assert(tag2 != NULL);
- cl_assert(git_oid_cmp(&id2, git_tag_id(tag2)) == 0);
+ cl_assert(git_oid_cmp(&id2, git_tag_id(tag2)) == 0);
- cl_git_pass(git_tag_target((git_object **)&commit, tag2));
- cl_assert(commit != NULL);
+ cl_git_pass(git_tag_target((git_object **)&commit, tag2));
+ cl_assert(commit != NULL);
- cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
+ cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
- git_tag_free(tag1);
- git_tag_free(tag2);
- git_commit_free(commit);
+ git_tag_free(tag1);
+ git_tag_free(tag2);
+ git_commit_free(commit);
}
void test_object_tag_read__parse_without_tagger(void)
{
- // read and parse a tag without a tagger field
- git_repository *bad_tag_repo;
- git_tag *bad_tag;
- git_commit *commit;
- git_oid id, id_commit;
+ // read and parse a tag without a tagger field
+ git_repository *bad_tag_repo;
+ git_tag *bad_tag;
+ git_commit *commit;
+ git_oid id, id_commit;
- // TODO: This is a little messy
- cl_git_pass(git_repository_open(&bad_tag_repo, cl_fixture("bad_tag.git")));
+ // TODO: This is a little messy
+ cl_git_pass(git_repository_open(&bad_tag_repo, cl_fixture("bad_tag.git")));
- git_oid_fromstr(&id, bad_tag_id);
- git_oid_fromstr(&id_commit, badly_tagged_commit);
+ git_oid_fromstr(&id, bad_tag_id);
+ git_oid_fromstr(&id_commit, badly_tagged_commit);
- cl_git_pass(git_tag_lookup(&bad_tag, bad_tag_repo, &id));
- cl_assert(bad_tag != NULL);
+ cl_git_pass(git_tag_lookup(&bad_tag, bad_tag_repo, &id));
+ cl_assert(bad_tag != NULL);
- cl_assert_equal_s(git_tag_name(bad_tag), "e90810b");
- cl_assert(git_oid_cmp(&id, git_tag_id(bad_tag)) == 0);
- cl_assert(bad_tag->tagger == NULL);
+ cl_assert_equal_s(git_tag_name(bad_tag), "e90810b");
+ cl_assert(git_oid_cmp(&id, git_tag_id(bad_tag)) == 0);
+ cl_assert(bad_tag->tagger == NULL);
- cl_git_pass(git_tag_target((git_object **)&commit, bad_tag));
- cl_assert(commit != NULL);
+ cl_git_pass(git_tag_target((git_object **)&commit, bad_tag));
+ cl_assert(commit != NULL);
- cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
+ cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
- git_tag_free(bad_tag);
- git_commit_free(commit);
- git_repository_free(bad_tag_repo);
+ git_tag_free(bad_tag);
+ git_commit_free(commit);
+ git_repository_free(bad_tag_repo);
}
void test_object_tag_read__parse_without_message(void)
{
- // read and parse a tag without a message field
- git_repository *short_tag_repo;
- git_tag *short_tag;
- git_commit *commit;
- git_oid id, id_commit;
+ // read and parse a tag without a message field
+ git_repository *short_tag_repo;
+ git_tag *short_tag;
+ git_commit *commit;
+ git_oid id, id_commit;
- // TODO: This is a little messy
- cl_git_pass(git_repository_open(&short_tag_repo, cl_fixture("short_tag.git")));
+ // TODO: This is a little messy
+ cl_git_pass(git_repository_open(&short_tag_repo, cl_fixture("short_tag.git")));
- git_oid_fromstr(&id, short_tag_id);
- git_oid_fromstr(&id_commit, short_tagged_commit);
+ git_oid_fromstr(&id, short_tag_id);
+ git_oid_fromstr(&id_commit, short_tagged_commit);
- cl_git_pass(git_tag_lookup(&short_tag, short_tag_repo, &id));
- cl_assert(short_tag != NULL);
+ cl_git_pass(git_tag_lookup(&short_tag, short_tag_repo, &id));
+ cl_assert(short_tag != NULL);
- cl_assert_equal_s(git_tag_name(short_tag), "no_description");
- cl_assert(git_oid_cmp(&id, git_tag_id(short_tag)) == 0);
- cl_assert(short_tag->message == NULL);
+ cl_assert_equal_s(git_tag_name(short_tag), "no_description");
+ cl_assert(git_oid_cmp(&id, git_tag_id(short_tag)) == 0);
+ cl_assert(short_tag->message == NULL);
- cl_git_pass(git_tag_target((git_object **)&commit, short_tag));
- cl_assert(commit != NULL);
+ cl_git_pass(git_tag_target((git_object **)&commit, short_tag));
+ cl_assert(commit != NULL);
- cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
+ cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
- git_tag_free(short_tag);
- git_commit_free(commit);
- git_repository_free(short_tag_repo);
+ git_tag_free(short_tag);
+ git_commit_free(commit);
+ git_repository_free(short_tag_repo);
+}
+
+void test_object_tag_read__without_tagger_nor_message(void)
+{
+ git_tag *tag;
+ git_oid id;
+ git_repository *repo;
+
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+
+ cl_git_pass(git_oid_fromstr(&id, taggerless));
+
+ cl_git_pass(git_tag_lookup(&tag, repo, &id));
+
+ cl_assert_equal_s(git_tag_name(tag), "taggerless");
+ cl_assert(git_tag_target_type(tag) == GIT_OBJ_COMMIT);
+
+ cl_assert(tag->message == NULL);
+ cl_assert(tag->tagger == NULL);
+
+ git_tag_free(tag);
+ git_repository_free(repo);
}
diff --git a/tests-clar/odb/foreach.c b/tests-clar/odb/foreach.c
index 37158d4..f643d96 100644
--- a/tests-clar/odb/foreach.c
+++ b/tests-clar/odb/foreach.c
@@ -28,8 +28,8 @@ static int foreach_cb(const git_oid *oid, void *data)
/*
* $ git --git-dir tests-clar/resources/testrepo.git count-objects --verbose
- * count: 43
- * size: 3
+ * count: 47
+ * size: 4
* in-pack: 1640
* packs: 3
* size-pack: 425
@@ -42,7 +42,7 @@ void test_odb_foreach__foreach(void)
git_repository_odb(&_odb, _repo);
cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL));
- cl_assert_equal_i(46 + 1640, nobj); /* count + in-pack */
+ cl_assert_equal_i(47 + 1640, nobj); /* count + in-pack */
}
void test_odb_foreach__one_pack(void)
diff --git a/tests-clar/refs/foreachglob.c b/tests-clar/refs/foreachglob.c
index 88516dd..4da1a15 100644
--- a/tests-clar/refs/foreachglob.c
+++ b/tests-clar/refs/foreachglob.c
@@ -48,8 +48,8 @@ static void assert_retrieval(const char *glob, unsigned int flags, int expected_
void test_refs_foreachglob__retrieve_all_refs(void)
{
- /* 8 heads (including one packed head) + 1 note + 2 remotes + 6 tags */
- assert_retrieval("*", GIT_REF_LISTALL, 21);
+ /* 12 heads (including one packed head) + 1 note + 2 remotes + 7 tags */
+ assert_retrieval("*", GIT_REF_LISTALL, 22);
}
void test_refs_foreachglob__retrieve_remote_branches(void)
diff --git a/tests-clar/resources/testrepo.git/objects/4a/23e2e65ad4e31c4c9db7dc746650bfad082679 b/tests-clar/resources/testrepo.git/objects/4a/23e2e65ad4e31c4c9db7dc746650bfad082679
new file mode 100644
index 0000000..18e3964
Binary files /dev/null and b/tests-clar/resources/testrepo.git/objects/4a/23e2e65ad4e31c4c9db7dc746650bfad082679 differ
diff --git a/tests-clar/resources/testrepo.git/refs/tags/taggerless b/tests-clar/resources/testrepo.git/refs/tags/taggerless
new file mode 100644
index 0000000..f960c7d
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/tags/taggerless
@@ -0,0 +1 @@
+4a23e2e65ad4e31c4c9db7dc746650bfad082679