summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0ecfcb3)
raw | patch | inline | side by side (parent: 0ecfcb3)
author | Olivier Marin <dkr@freesurf.fr> | |
Tue, 10 Jun 2008 14:51:21 +0000 (16:51 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 11 Jun 2008 05:43:05 +0000 (22:43 -0700) |
This allow us to add different features to each of them and keep the
code simple at the same time. Also create a get_remote_ref_states()
to avoid duplicated code.
Signed-off-by: Olivier Marin <dkr@freesurf.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
code simple at the same time. Also create a get_remote_ref_states()
to avoid duplicated code.
Signed-off-by: Olivier Marin <dkr@freesurf.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-remote.c | patch | blob | history |
diff --git a/builtin-remote.c b/builtin-remote.c
index efe74c7d5d9e48428b4f46b7d85aaf1a19664954..745a4ee6c503666bf763327d845c4210a728261f 100644 (file)
--- a/builtin-remote.c
+++ b/builtin-remote.c
printf("\n");
}
-static int show_or_prune(int argc, const char **argv, int prune)
+static int get_remote_ref_states(const char *name,
+ struct ref_states *states,
+ int query)
+{
+ struct transport *transport;
+ const struct ref *ref;
+
+ states->remote = remote_get(name);
+ if (!states->remote)
+ return error("No such remote: %s", name);
+
+ read_branches();
+
+ if (query) {
+ transport = transport_get(NULL, states->remote->url_nr > 0 ?
+ states->remote->url[0] : NULL);
+ ref = transport_get_remote_refs(transport);
+ transport_disconnect(transport);
+
+ get_ref_states(ref, states);
+ }
+
+ return 0;
+}
+
+static int show(int argc, const char **argv)
{
int no_query = 0, result = 0;
struct option options[] = {
argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
- if (argc < 1) {
- if (!prune)
- return show_all();
- usage_with_options(builtin_remote_usage, options);
- }
+ if (argc < 1)
+ return show_all();
memset(&states, 0, sizeof(states));
for (; argc; argc--, argv++) {
- struct transport *transport;
- const struct ref *ref;
struct strbuf buf;
int i;
- states.remote = remote_get(*argv);
- if (!states.remote)
- return error("No such remote: %s", *argv);
-
- read_branches();
-
- if (!no_query) {
- transport = transport_get(NULL,
- states.remote->url_nr > 0 ?
- states.remote->url[0] : NULL);
- ref = transport_get_remote_refs(transport);
- transport_disconnect(transport);
-
- get_ref_states(ref, &states);
- }
-
- if (prune) {
- for (i = 0; i < states.stale.nr; i++) {
- const char *refname = states.stale.items[i].util;
- result |= delete_ref(refname, NULL);
- }
- goto cleanup_states;
- }
+ get_remote_ref_states(*argv, &states, !no_query);
printf("* remote %s\n URL: %s\n", *argv,
states.remote->url_nr > 0 ?
}
printf("\n");
}
-cleanup_states:
+
+ /* NEEDSWORK: free remote */
+ path_list_clear(&states.new, 0);
+ path_list_clear(&states.stale, 0);
+ path_list_clear(&states.tracked, 0);
+ }
+
+ return result;
+}
+
+static int prune(int argc, const char **argv)
+{
+ int no_query = 0, result = 0;
+ struct option options[] = {
+ OPT_GROUP("prune specific options"),
+ OPT_BOOLEAN('n', NULL, &no_query, "do not query remotes"),
+ OPT_END()
+ };
+ struct ref_states states;
+
+ argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
+
+ if (argc < 1)
+ usage_with_options(builtin_remote_usage, options);
+
+ memset(&states, 0, sizeof(states));
+ for (; argc; argc--, argv++) {
+ int i;
+
+ get_remote_ref_states(*argv, &states, !no_query);
+
+ for (i = 0; i < states.stale.nr; i++) {
+ const char *refname = states.stale.items[i].util;
+ result |= delete_ref(refname, NULL);
+ }
+
/* NEEDSWORK: free remote */
path_list_clear(&states.new, 0);
path_list_clear(&states.stale, 0);
else if (!strcmp(argv[0], "rm"))
result = rm(argc, argv);
else if (!strcmp(argv[0], "show"))
- result = show_or_prune(argc, argv, 0);
+ result = show(argc, argv);
else if (!strcmp(argv[0], "prune"))
- result = show_or_prune(argc, argv, 1);
+ result = prune(argc, argv);
else if (!strcmp(argv[0], "update"))
result = update(argc, argv);
else {