Commit 3230a44f by Carlos Martín Nieto

remote: support downloading all tags

Also honor remote.$name.tagopt = --tags.
parent eb0bd77a
......@@ -307,7 +307,8 @@ GIT_EXTERN(void) git_remote_set_callbacks(git_remote *remote, git_remote_callbac
enum {
GIT_REMOTE_DOWNLOAD_TAGS_UNSET,
GIT_REMOTE_DOWNLOAD_TAGS_NONE,
GIT_REMOTE_DOWNLOAD_TAGS_AUTO
GIT_REMOTE_DOWNLOAD_TAGS_AUTO,
GIT_REMOTE_DOWNLOAD_TAGS_ALL
};
/**
......
......@@ -21,7 +21,7 @@
struct filter_payload {
git_remote *remote;
const git_refspec *spec;
const git_refspec *spec, *tagspec;
git_odb *odb;
int found_head;
};
......@@ -29,18 +29,21 @@ struct filter_payload {
static int filter_ref__cb(git_remote_head *head, void *payload)
{
struct filter_payload *p = payload;
int match = 0;
if (!p->found_head && strcmp(head->name, GIT_HEAD_FILE) == 0) {
if (!git_reference_is_valid_name(head->name))
return 0;
if (!p->found_head && strcmp(head->name, GIT_HEAD_FILE) == 0)
p->found_head = 1;
} else {
/* If it doesn't match the refpec, we don't want it */
if (!git_refspec_src_matches(p->spec, head->name))
return 0;
else if (git_refspec_src_matches(p->spec, head->name))
match = 1;
else if (p->remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL &&
git_refspec_src_matches(p->tagspec, head->name))
match = 1;
/* Don't even try to ask for the annotation target */
if (!git__suffixcmp(head->name, "^{}"))
return 0;
}
if (!match)
return 0;
/* If we have the object, mark it so we don't ask for it */
if (git_odb_exists(p->odb, &head->oid))
......@@ -54,8 +57,11 @@ static int filter_ref__cb(git_remote_head *head, void *payload)
static int filter_wants(git_remote *remote)
{
struct filter_payload p;
git_refspec tagspec;
git_vector_clear(&remote->refs);
if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0)
return -1;
/*
* The fetch refspec can be NULL, and what this means is that the
......@@ -64,6 +70,7 @@ static int filter_wants(git_remote *remote)
* HEAD, which will be stored in FETCH_HEAD after the fetch.
*/
p.spec = git_remote_fetchspec(remote);
p.tagspec = &tagspec;
p.found_head = 0;
p.remote = remote;
......
......@@ -19,6 +19,8 @@ struct git_refspec {
matching :1;
};
#define GIT_REFSPEC_TAGS "refs/tags/*:refs/tags/*"
int git_refspec_parse(struct git_refspec *refspec, const char *str);
int git_refspec__parse(
struct git_refspec *refspec,
......
......@@ -47,6 +47,8 @@ static int download_tags_value(git_remote *remote, git_config *cfg)
git_buf_free(&buf);
if (!error && !strcmp(val, "--no-tags"))
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_NONE;
else if (!error && !strcmp(val, "--tags"))
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
if (error == GIT_ENOTFOUND)
error = 0;
......@@ -455,7 +457,6 @@ int git_remote_update_tips(git_remote *remote)
git_remote_head *head;
git_reference *ref;
struct git_refspec *spec;
char *tagstr = "refs/tags/*:refs/tags/*";
git_refspec tagspec;
assert(remote);
......@@ -469,7 +470,7 @@ int git_remote_update_tips(git_remote *remote)
if (git_repository_odb(&odb, remote->repo) < 0)
return -1;
if (git_refspec__parse(&tagspec, tagstr, true) < 0)
if (git_refspec__parse(&tagspec, GIT_REFSPEC_TAGS, true) < 0)
return -1;
/* HEAD is only allowed to be the first in the list */
......@@ -500,7 +501,9 @@ int git_remote_update_tips(git_remote *remote)
if (git_refspec_transform_r(&refname, spec, head->name) < 0)
goto on_error;
} else if (remote->download_tags != GIT_REMOTE_DOWNLOAD_TAGS_NONE) {
autotag = 1;
if (remote->download_tags != GIT_REMOTE_DOWNLOAD_TAGS_ALL)
autotag = 1;
if (!git_refspec_src_matches(&tagspec, head->name))
continue;
......
......@@ -24,7 +24,7 @@ struct git_remote {
git_repository *repo;
git_remote_callbacks callbacks;
unsigned int need_pack:1,
download_tags:2, /* There are three possible values */
download_tags:2, /* There are four possible values */
check_cert:1;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment