diff options
author | Vicent Martà <vicent@github.com> | 2013-01-02 13:50:41 -0800 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2013-01-02 13:50:41 -0800 |
commit | cd5ca5b97fe2b9f87800adc7cfbb7088ac0c3ab7 (patch) | |
tree | 0fb2cdacb9be3a41101406f6151bc31561e8ff1c /examples | |
parent | 2e40c616c7ef3dc4f34ab445e4cba2c127e7522c (diff) | |
parent | 730df6d0f70a343ade75ef9411fe0435b0afd5a9 (diff) | |
download | libgit2-cd5ca5b97fe2b9f87800adc7cfbb7088ac0c3ab7.tar.gz |
Merge pull request #1152 from ben/clone-api-structification
Segregate in-memory and persisted remotes
Diffstat (limited to 'examples')
-rw-r--r-- | examples/network/clone.c | 39 | ||||
-rw-r--r-- | examples/network/fetch.c | 2 | ||||
-rw-r--r-- | examples/network/ls-remote.c | 2 |
3 files changed, 22 insertions, 21 deletions
diff --git a/examples/network/clone.c b/examples/network/clone.c index 8d598de41..9b323ff73 100644 --- a/examples/network/clone.c +++ b/examples/network/clone.c @@ -7,6 +7,16 @@ #include <pthread.h> #include <unistd.h> +/* Shamelessly borrowed from http://stackoverflow.com/questions/3417837/ */ +#ifdef UNUSED +#elif defined(__GNUC__) +# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) +#elif defined(__LCLINT__) +# define UNUSED(x) /*@unused@*/ x +#else +# define UNUSED(x) x +#endif + typedef struct progress_data { git_transfer_progress fetch_progress; size_t completed_steps; @@ -47,7 +57,10 @@ static void checkout_progress(const char *path, size_t cur, size_t tot, void *pa print_progress(pd); } -static int cred_acquire(git_cred **out, const char *url, unsigned int allowed_types, void *payload) +static int cred_acquire(git_cred **out, + const char * UNUSED(url), + unsigned int UNUSED(allowed_types), + void * UNUSED(payload)) { char username[128] = {0}; char password[128] = {0}; @@ -64,9 +77,8 @@ static int cred_acquire(git_cred **out, const char *url, unsigned int allowed_ty int do_clone(git_repository *repo, int argc, char **argv) { - progress_data pd; + progress_data pd = {{0}}; git_repository *cloned_repo = NULL; - git_remote *origin; git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; git_checkout_opts checkout_opts = GIT_CHECKOUT_OPTS_INIT; const char *url = argv[1]; @@ -84,25 +96,14 @@ int do_clone(git_repository *repo, int argc, char **argv) // Set up options checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; checkout_opts.progress_cb = checkout_progress; - memset(&pd, 0, sizeof(pd)); checkout_opts.progress_payload = &pd; - - // Create the origin remote, and set up for auth - error = git_remote_new(&origin, NULL, "origin", url, GIT_REMOTE_DEFAULT_FETCH); - if (error != 0) { - const git_error *err = giterr_last(); - if (err) printf("ERROR %d: %s\n", err->klass, err->message); - else printf("ERROR %d: no detailed info\n", error); - return error; - } - git_remote_set_cred_acquire_cb(origin, cred_acquire, NULL); - - // Do the clone - clone_opts.checkout_opts = &checkout_opts; + clone_opts.checkout_opts = checkout_opts; clone_opts.fetch_progress_cb = &fetch_progress; clone_opts.fetch_progress_payload = &pd; - error = git_clone(&cloned_repo, origin, path, &clone_opts); - git_remote_free(origin); + clone_opts.cred_acquire_cb = cred_acquire; + + // Do the clone + error = git_clone(&cloned_repo, url, path, &clone_opts); printf("\n"); if (error != 0) { const git_error *err = giterr_last(); diff --git a/examples/network/fetch.c b/examples/network/fetch.c index 8048fd67a..437b137d3 100644 --- a/examples/network/fetch.c +++ b/examples/network/fetch.c @@ -76,7 +76,7 @@ int fetch(git_repository *repo, int argc, char **argv) // Figure out whether it's a named remote or a URL printf("Fetching %s for repo %p\n", argv[1], repo); if (git_remote_load(&remote, repo, argv[1]) < 0) { - if (git_remote_new(&remote, repo, NULL, argv[1], NULL) < 0) + if (git_remote_create_inmemory(&remote, repo, NULL, argv[1]) < 0) return -1; } diff --git a/examples/network/ls-remote.c b/examples/network/ls-remote.c index 62131d4ba..737eeacd3 100644 --- a/examples/network/ls-remote.c +++ b/examples/network/ls-remote.c @@ -21,7 +21,7 @@ static int use_unnamed(git_repository *repo, const char *url) // Create an instance of a remote from the URL. The transport to use // is detected from the URL - error = git_remote_new(&remote, repo, NULL, url, NULL); + error = git_remote_create_inmemory(&remote, repo, NULL, url); if (error < 0) goto cleanup; |