From 1c13b0bfdcfb510863a6e5e3238f8a461551aa0f Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Fri, 12 Jul 2013 15:30:05 -0500 Subject: [PATCH 1/2] test that suggests tags arent fully peeled during push --- tests-clar/online/push.c | 12 ++++++++++++ .../36/f79b2846017d3761e0a02d0bccd573e0f90c57 | 2 ++ .../ee/a4f2705eeec2db3813f2430829afce99cd00b5 | Bin 0 -> 141 bytes .../push_src/.gitted/refs/tags/tag-commit-two | 1 + .../resources/push_src/.gitted/refs/tags/tag-tag | 1 + 5 files changed, 16 insertions(+) create mode 100644 tests-clar/resources/push_src/.gitted/objects/36/f79b2846017d3761e0a02d0bccd573e0f90c57 create mode 100644 tests-clar/resources/push_src/.gitted/objects/ee/a4f2705eeec2db3813f2430829afce99cd00b5 create mode 100644 tests-clar/resources/push_src/.gitted/refs/tags/tag-commit-two create mode 100644 tests-clar/resources/push_src/.gitted/refs/tags/tag-tag diff --git a/tests-clar/online/push.c b/tests-clar/online/push.c index 5dc7974c7..321180781 100644 --- a/tests-clar/online/push.c +++ b/tests-clar/online/push.c @@ -29,6 +29,7 @@ static git_oid _tag_commit; static git_oid _tag_tree; static git_oid _tag_blob; static git_oid _tag_lightweight; +static git_oid _tag_tag; static int cred_acquire_cb( git_cred **cred, @@ -272,6 +273,7 @@ void test_online_push__initialize(void) git_oid_fromstr(&_tag_tree, "ff83aa4c5e5d28e3bcba2f5c6e2adc61286a4e5e"); git_oid_fromstr(&_tag_blob, "b483ae7ba66decee9aee971f501221dea84b1498"); git_oid_fromstr(&_tag_lightweight, "951bbbb90e2259a4c8950db78946784fb53fcbce"); + git_oid_fromstr(&_tag_tag, "eea4f2705eeec2db3813f2430829afce99cd00b5"); /* Remote URL environment variable must be set. User and password are optional. */ _remote_url = cl_getenv("GITTEST_REMOTE_URL"); @@ -569,6 +571,16 @@ void test_online_push__tag_lightweight(void) exp_refs, ARRAY_SIZE(exp_refs), 0); } +void test_online_push__tag_to_tag(void) +{ + const char *specs[] = { "refs/tags/tag-tag:refs/tags/tag-tag" }; + push_status exp_stats[] = { { "refs/tags/tag-tag", NULL } }; + expected_ref exp_refs[] = { { "refs/tags/tag-tag", &_tag_tag } }; + do_push(specs, ARRAY_SIZE(specs), + exp_stats, ARRAY_SIZE(exp_stats), + exp_refs, ARRAY_SIZE(exp_refs), 0); +} + void test_online_push__force(void) { const char *specs1[] = {"refs/heads/b3:refs/heads/tgt"}; diff --git a/tests-clar/resources/push_src/.gitted/objects/36/f79b2846017d3761e0a02d0bccd573e0f90c57 b/tests-clar/resources/push_src/.gitted/objects/36/f79b2846017d3761e0a02d0bccd573e0f90c57 new file mode 100644 index 000000000..0bc57f266 --- /dev/null +++ b/tests-clar/resources/push_src/.gitted/objects/36/f79b2846017d3761e0a02d0bccd573e0f90c57 @@ -0,0 +1,2 @@ +x%] +0S͏B)} @bnf`f`>3(nibC0hQ6BMv2&-M0Q)+ tNsE*;}JϲN픹(th@#B˺C?TÅoyk7 \ No newline at end of file diff --git a/tests-clar/resources/push_src/.gitted/objects/ee/a4f2705eeec2db3813f2430829afce99cd00b5 b/tests-clar/resources/push_src/.gitted/objects/ee/a4f2705eeec2db3813f2430829afce99cd00b5 new file mode 100644 index 0000000000000000000000000000000000000000..b7b81d5e33fba17a21de678d5f77bccda5635efa GIT binary patch literal 141 zcmV;80CN9$0WHj33WG2Z1mHgB6ng<>W6Y0GN?&>dFA(#m1-r#8l-|CIg&F318ukUG zb{CqSDKIFL?J#w&Hz;jX*2sh&yNFW=QCpQT4;Zu+{Cy{2U&P*Ho4-ri;1NH5i!jc# vR(ioT@u~Z|gpDd?ZUe11kjg4!uy+GAs1b!2=cU3Pe_R67iB|jobvZJ;wZ%S3 literal 0 HcmV?d00001 diff --git a/tests-clar/resources/push_src/.gitted/refs/tags/tag-commit-two b/tests-clar/resources/push_src/.gitted/refs/tags/tag-commit-two new file mode 100644 index 000000000..abb365080 --- /dev/null +++ b/tests-clar/resources/push_src/.gitted/refs/tags/tag-commit-two @@ -0,0 +1 @@ +36f79b2846017d3761e0a02d0bccd573e0f90c57 diff --git a/tests-clar/resources/push_src/.gitted/refs/tags/tag-tag b/tests-clar/resources/push_src/.gitted/refs/tags/tag-tag new file mode 100644 index 000000000..d6cd74804 --- /dev/null +++ b/tests-clar/resources/push_src/.gitted/refs/tags/tag-tag @@ -0,0 +1 @@ +eea4f2705eeec2db3813f2430829afce99cd00b5 From 5ce6c1e917a4282455fef6c7fd2236a7fb68653a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 12 Aug 2013 16:15:36 +0200 Subject: [PATCH 2/2] push: handle tag chains correctly When dealing with a chain of tags, we need to enqueue each of them individually, which means we can't use `git_tag_peel` as that jumps over the intermediate tags. Do the peeling manually so we can look at each object and take the appropriate action. --- src/push.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/push.c b/src/push.c index 452d71789..eaaa46248 100644 --- a/src/push.c +++ b/src/push.c @@ -233,6 +233,37 @@ on_error: return error; } +/** + * Insert all tags until we find a non-tag object, which is returned + * in `out`. + */ +static int enqueue_tag(git_object **out, git_push *push, git_oid *id) +{ + git_object *obj = NULL, *target = NULL; + int error; + + if ((error = git_object_lookup(&obj, push->repo, id, GIT_OBJ_TAG)) < 0) + return error; + + while (git_object_type(obj) == GIT_OBJ_TAG) { + if ((error = git_packbuilder_insert(push->pb, git_object_id(obj), NULL)) < 0) + break; + + if ((error = git_tag_target(&target, (git_tag *) obj)) < 0) + break; + + git_object_free(obj); + obj = target; + } + + if (error < 0) + git_object_free(obj); + else + *out = obj; + + return error; +} + static int revwalk(git_vector *commits, git_push *push) { git_remote_head *head; @@ -265,21 +296,11 @@ static int revwalk(git_vector *commits, git_push *push) goto on_error; if (type == GIT_OBJ_TAG) { - git_tag *tag; git_object *target; - if (git_packbuilder_insert(push->pb, &spec->loid, NULL) < 0) + if ((error = enqueue_tag(&target, push, &spec->loid)) < 0) goto on_error; - if (git_tag_lookup(&tag, push->repo, &spec->loid) < 0) - goto on_error; - - if (git_tag_peel(&target, tag) < 0) { - git_tag_free(tag); - goto on_error; - } - git_tag_free(tag); - if (git_object_type(target) == GIT_OBJ_COMMIT) { if (git_revwalk_push(rw, git_object_id(target)) < 0) { git_object_free(target);