diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/push.c | 87 |
1 files changed, 70 insertions, 17 deletions
diff --git a/src/push.c b/src/push.c index 634634d84..71223645a 100644 --- a/src/push.c +++ b/src/push.c @@ -68,18 +68,37 @@ static void free_status(push_status *status) git__free(status); } -static int check_ref(char *ref) +static int check_rref(char *ref) { - if (strcmp(ref, "HEAD") && - git__prefixcmp(ref, "refs/heads/") && - git__prefixcmp(ref, "refs/tags/")) { - giterr_set(GITERR_INVALID, "No valid reference '%s'", ref); + if (git__prefixcmp(ref, "refs/")) { + giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref); return -1; } + return 0; } -static int parse_refspec(push_spec **spec, const char *str) +static int check_lref(git_push *push, char *ref) +{ + /* lref must be resolvable to an existing object */ + git_object *obj; + int error = git_revparse_single(&obj, push->repo, ref); + + if (error) { + if (error == GIT_ENOTFOUND) + giterr_set(GITERR_REFERENCE, + "src refspec '%s' does not match any existing object", ref); + else + giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref); + + return -1; + } else + git_object_free(obj); + + return 0; +} + +static int parse_refspec(git_push *push, push_spec **spec, const char *str) { push_spec *s; char *delim; @@ -94,22 +113,22 @@ static int parse_refspec(push_spec **spec, const char *str) str++; } -#define check(ref) \ - if (!ref || check_ref(ref) < 0) goto on_error - delim = strchr(str, ':'); if (delim == NULL) { s->lref = git__strdup(str); - check(s->lref); + if (!s->lref || check_lref(push, s->lref) < 0) + goto on_error; } else { if (delim - str) { s->lref = git__strndup(str, delim - str); - check(s->lref); + if (!s->lref || check_lref(push, s->lref) < 0) + goto on_error; } if (strlen(delim + 1)) { s->rref = git__strdup(delim + 1); - check(s->rref); + if (!s->rref || check_rref(s->rref) < 0) + goto on_error; } } @@ -119,11 +138,10 @@ static int parse_refspec(push_spec **spec, const char *str) /* If rref is ommitted, use the same ref name as lref */ if (!s->rref) { s->rref = git__strdup(s->lref); - check(s->rref); + if (!s->rref || check_rref(s->rref) < 0) + goto on_error; } -#undef check - *spec = s; return 0; @@ -136,7 +154,7 @@ int git_push_add_refspec(git_push *push, const char *refspec) { push_spec *spec; - if (parse_refspec(&spec, refspec) < 0 || + if (parse_refspec(push, &spec, refspec) < 0 || git_vector_insert(&push->specs, spec) < 0) return -1; @@ -158,6 +176,9 @@ static int revwalk(git_vector *commits, git_push *push) git_revwalk_sorting(rw, GIT_SORT_TIME); git_vector_foreach(&push->specs, i, spec) { + git_otype type; + size_t size; + if (git_oid_iszero(&spec->loid)) /* * Delete reference on remote side; @@ -168,7 +189,39 @@ static int revwalk(git_vector *commits, git_push *push) if (git_oid_equal(&spec->loid, &spec->roid)) continue; /* up-to-date */ - if (git_revwalk_push(rw, &spec->loid) < 0) + if (git_odb_read_header(&size, &type, push->repo->_odb, &spec->loid) < 0) + goto on_error; + + if (type == GIT_OBJ_TAG) { + git_tag *tag; + git_object *target; + + if (git_packbuilder_insert(push->pb, &spec->loid, NULL) < 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); + goto on_error; + } + } else { + if (git_packbuilder_insert( + push->pb, git_object_id(target), NULL) < 0) { + git_object_free(target); + goto on_error; + } + } + git_object_free(target); + } else if (git_revwalk_push(rw, &spec->loid) < 0) goto on_error; if (!spec->force) { |
