Skip to content

Commit

Permalink
Fixed GIT_REMOTE_DOWNLOAD_TAGS_ALL to behave like git
Browse files Browse the repository at this point in the history
  • Loading branch information
swisspol committed Oct 29, 2014
1 parent 264d74f commit 6f2768e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ v0.21 + 1

* The THREADSAFE option to build libgit2 with threading support has
been flipped to be on by default.

* The fetch behavior of remotes with autotag set to GIT_REMOTE_DOWNLOAD_TAGS_ALL
has been changed. In this mode, libgit2 used to only fetch tags and ignore
other requested refspecs. The new behavior is to fetch all tags in addition
to whatever else needs to be fetched, which is the official git behavior.

This comment has been minimized.

Copy link
@linquize

linquize Oct 30, 2014

Currently, libgit2 fetch tag behaviour is based on pre git 1.9.0
since git 1.9.0, git fetch --tags fetches fetch all tags in addition to whatever else.

ref: issue libgit2#2120

14 changes: 8 additions & 6 deletions src/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ static int maybe_want(git_remote *remote, git_remote_head *head, git_odb *odb, g
return 0;

if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {

This comment has been minimized.

Copy link
@linquize

linquize Oct 30, 2014

Don't change whitespace

/*
* If tagopt is --tags, then we only use the default
* tags refspec and ignore the remote's
* If tagopt is --tags, always request tags
* in addition to the remote's refspecs
*/

This comment has been minimized.

Copy link
@linquize

linquize Oct 30, 2014

Don't change whitespace

if (git_refspec_src_matches(tagspec, head->name))
match = 1;
else
return 0;
} else if (git_remote__matching_refspec(remote, head->name))
match = 1;
}

if (!match && git_remote__matching_refspec(remote, head->name))
match = 1;

if (!match)
return 0;
Expand Down
26 changes: 14 additions & 12 deletions src/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,24 +1104,26 @@ static int update_tips_for_spec(
if (!git_reference_is_valid_name(head->name))
continue;

if (git_refspec_src_matches(spec, head->name) && spec->dst) {
if (git_refspec_transform(&refname, spec, head->name) < 0)
goto on_error;
} else if (remote->download_tags != GIT_REMOTE_DOWNLOAD_TAGS_NONE) {
if (git_refspec_src_matches(&tagspec, head->name)) {
if (remote->download_tags != GIT_REMOTE_DOWNLOAD_TAGS_NONE) {

if (remote->download_tags != GIT_REMOTE_DOWNLOAD_TAGS_ALL)
autotag = 1;
if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_AUTO)
autotag = 1;

if (!git_refspec_src_matches(&tagspec, head->name))
git_buf_clear(&refname);
if (git_buf_puts(&refname, head->name) < 0)
goto on_error;
} else {
continue;

git_buf_clear(&refname);
if (git_buf_puts(&refname, head->name) < 0)
}
} else if (git_refspec_src_matches(spec, head->name) && spec->dst) {
if (git_refspec_transform(&refname, spec, head->name) < 0)
goto on_error;
} else {
continue;
}

/* In autotag mode, only create tags for objects already in db */
if (autotag && !git_odb_exists(odb, &head->oid))
continue;

Expand Down Expand Up @@ -1282,8 +1284,8 @@ int git_remote_update_tips(
goto out;

if (remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
error = update_tips_for_spec(remote, &tagspec, &refs, signature, reflog_message);
goto out;
if ((error = update_tips_for_spec(remote, &tagspec, &refs, signature, reflog_message)) < 0)
goto out;
}

git_vector_foreach(&remote->active_refspecs, i, spec) {
Expand Down

1 comment on commit 6f2768e

@swisspol
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you want to land this PR and if so I'll clean up the above.

Please sign in to comment.