diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-04-25 12:13:20 +0200 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-04-25 13:25:45 +0200 |
commit | f184836bd281efe8a656e3a9c6c2f9c040b88119 (patch) | |
tree | 084cf2dc7b85f7f4b43985590d9fff1fce7e469d /examples/network/fetch.c | |
parent | 2e3a0055d136d13fba365bf2a26638f84bd32d02 (diff) | |
download | libgit2-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 'examples/network/fetch.c')
-rw-r--r-- | examples/network/fetch.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/examples/network/fetch.c b/examples/network/fetch.c index f7a60640e..d4a39746f 100644 --- a/examples/network/fetch.c +++ b/examples/network/fetch.c @@ -39,6 +39,25 @@ exit: pthread_exit(&data->ret); } +int update_cb(const char *refname, const git_oid *a, const git_oid *b) +{ + const char *action; + char a_str[GIT_OID_HEXSZ+1], b_str[GIT_OID_HEXSZ+1]; + + git_oid_fmt(b_str, b); + b_str[GIT_OID_HEXSZ] = '\0'; + + if (git_oid_iszero(a)) { + printf("[new] %.20s %s\n", b_str, refname); + } else { + git_oid_fmt(a_str, a); + a_str[GIT_OID_HEXSZ] = '\0'; + printf("[updated] %.10s..%.10s %s\n", a_str, b_str, refname); + } + + return 0; +} + int fetch(git_repository *repo, int argc, char **argv) { git_remote *remote = NULL; @@ -78,7 +97,7 @@ int fetch(git_repository *repo, int argc, char **argv) // right commits. This may be needed even if there was no packfile // to download, which can happen e.g. when the branches have been // changed but all the neede objects are available locally. - if (git_remote_update_tips(remote) < 0) + if (git_remote_update_tips(remote, update_cb) < 0) return -1; git_remote_free(remote); |