Removing unneeded code duplication in ls-remote.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/examples/network/ls-remote.c b/examples/network/ls-remote.c
index 2520118..e837654 100644
--- a/examples/network/ls-remote.c
+++ b/examples/network/ls-remote.c
@@ -14,31 +14,6 @@ static int show_ref__cb(git_remote_head *head, void *payload)
return 0;
}
-static int use_unnamed(git_repository *repo, const char *url)
-{
- git_remote *remote = NULL;
- int error;
-
- // Create an instance of a remote from the URL. The transport to use
- // is detected from the URL
- error = git_remote_create_inmemory(&remote, repo, NULL, url);
- if (error < 0)
- goto cleanup;
-
- // When connecting, the underlying code needs to know wether we
- // want to push or fetch
- error = git_remote_connect(remote, GIT_DIRECTION_FETCH);
- if (error < 0)
- goto cleanup;
-
- // With git_remote_ls we can retrieve the advertised heads
- error = git_remote_ls(remote, &show_ref__cb, NULL);
-
-cleanup:
- git_remote_free(remote);
- return error;
-}
-
static int use_remote(git_repository *repo, char *name)
{
git_remote *remote = NULL;
@@ -46,8 +21,12 @@ static int use_remote(git_repository *repo, char *name)
// Find the remote by name
error = git_remote_load(&remote, repo, name);
- if (error < 0)
- goto cleanup;
+ if (error < 0) {
+ error = git_remote_create_inmemory(&remote, repo, NULL, name);
+ if (error < 0)
+ goto cleanup;
+ }
+
error = git_remote_connect(remote, GIT_DIRECTION_FETCH);
if (error < 0)
@@ -72,12 +51,7 @@ int ls_remote(git_repository *repo, int argc, char **argv)
return EXIT_FAILURE;
}
- /* If there's a ':' in the name, assume it's an URL */
- if (strchr(argv[1], ':') != NULL) {
- error = use_unnamed(repo, argv[1]);
- } else {
- error = use_remote(repo, argv[1]);
- }
+ error = use_remote(repo, argv[1]);
return error;
}