summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2012-09-30 10:56:06 +0200
committerCarlos Martín Nieto <carlos@cmartin.tk>2012-09-30 12:05:28 +0200
commit3230a44f4c951cbaeadfa5ae111f6558298dfc61 (patch)
tree2a07a140b7e6352ab6f97d5ca382eafd4ed96dcd
parenteb0bd77a8892b77b8eaa57da2f827981c62bc161 (diff)
downloadlibgit2-3230a44f4c951cbaeadfa5ae111f6558298dfc61.tar.gz
remote: support downloading all tags
Also honor remote.$name.tagopt = --tags.
-rw-r--r--include/git2/remote.h3
-rw-r--r--src/fetch.c27
-rw-r--r--src/refspec.h2
-rw-r--r--src/remote.c9
-rw-r--r--src/remote.h2
5 files changed, 28 insertions, 15 deletions
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 1bca7a716..c015289e8 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -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
};
/**
diff --git a/src/fetch.c b/src/fetch.c
index 98e1f0b13..f9cc8aae1 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -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;
diff --git a/src/refspec.h b/src/refspec.h
index 83078151b..a5df458c6 100644
--- a/src/refspec.h
+++ b/src/refspec.h
@@ -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,
diff --git a/src/remote.c b/src/remote.c
index f446cfe48..fd78164f3 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -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;
diff --git a/src/remote.h b/src/remote.h
index 51587beb1..b8bb2c55d 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -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;
};