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