summaryrefslogtreecommitdiff
path: root/src/remote.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2012-04-25 12:13:20 +0200
committerCarlos Martín Nieto <carlos@cmartin.tk>2012-04-25 13:25:45 +0200
commitf184836bd281efe8a656e3a9c6c2f9c040b88119 (patch)
tree084cf2dc7b85f7f4b43985590d9fff1fce7e469d /src/remote.c
parent2e3a0055d136d13fba365bf2a26638f84bd32d02 (diff)
downloadlibgit2-f184836bd281efe8a656e3a9c6c2f9c040b88119.tar.gz
remote: run a callback when updating the branch tips
This allows the caller to update an internal structure or update the user output with the tips that were updated. While in the area, only try to update the ref if the value is different from its old one.
Diffstat (limited to 'src/remote.c')
-rw-r--r--src/remote.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/remote.c b/src/remote.c
index bbb491dd8..e1937df85 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -309,11 +309,12 @@ int git_remote_download(git_remote *remote, git_off_t *bytes, git_indexer_stats
return git_fetch_download_pack(remote, bytes, stats);
}
-int git_remote_update_tips(git_remote *remote)
+int git_remote_update_tips(git_remote *remote, int (*cb)(const char *refname, const git_oid *a, const git_oid *b))
{
int error = 0;
unsigned int i = 0;
git_buf refname = GIT_BUF_INIT;
+ git_oid old;
git_vector *refs = &remote->refs;
git_remote_head *head;
git_reference *ref;
@@ -338,17 +339,36 @@ int git_remote_update_tips(git_remote *remote)
head = refs->contents[i];
if (git_refspec_transform_r(&refname, spec, head->name) < 0)
- break;
+ goto on_error;
+
+ error = git_reference_name_to_oid(&old, remote->repo, refname.ptr);
+ if (error < 0 && error != GIT_ENOTFOUND)
+ goto on_error;
+
+ if (error == GIT_ENOTFOUND)
+ memset(&old, 0, GIT_OID_RAWSZ);
+
+ if (!git_oid_cmp(&old, &head->oid))
+ continue;
if (git_reference_create_oid(&ref, remote->repo, refname.ptr, &head->oid, 1) < 0)
break;
git_reference_free(ref);
+
+ if (cb != NULL) {
+ if (cb(refname.ptr, &old, &head->oid) < 0)
+ goto on_error;
+ }
}
git_buf_free(&refname);
+ return 0;
+
+on_error:
+ git_buf_free(&refname);
+ return -1;
- return error;
}
int git_remote_connected(git_remote *remote)