Code

Add autoconf tests for pthreads
[git.git] / builtin-remote.c
index 01945a8651c9a42f19fba850036ed2a1339675f1..df2be068b69b6d926d4980e6e9eada05d92643e1 100644 (file)
@@ -54,7 +54,7 @@ static int add(int argc, const char **argv)
        struct string_list track = { NULL, 0, 0 };
        const char *master = NULL;
        struct remote *remote;
-       struct strbuf buf, buf2;
+       struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
        const char *name, *url;
        int i;
 
@@ -81,9 +81,6 @@ static int add(int argc, const char **argv)
                        remote->fetch_refspec_nr))
                die("remote %s already exists.", name);
 
-       strbuf_init(&buf, 0);
-       strbuf_init(&buf2, 0);
-
        strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
        if (!valid_fetch_refspec(buf2.buf))
                die("'%s' is not a valid remote name", name);
@@ -352,7 +349,7 @@ static int rm(int argc, const char **argv)
                OPT_END()
        };
        struct remote *remote;
-       struct strbuf buf;
+       struct strbuf buf = STRBUF_INIT;
        struct known_remotes known_remotes = { NULL, NULL };
        struct string_list branches = { NULL, 0, 0, 1 };
        struct branches_for_remote cb_data = { NULL, &branches, &known_remotes };
@@ -368,7 +365,6 @@ static int rm(int argc, const char **argv)
        known_remotes.to_delete = remote;
        for_each_remote(add_known_remote, &known_remotes);
 
-       strbuf_init(&buf, 0);
        strbuf_addf(&buf, "remote.%s", remote->name);
        if (git_config_rename_section(buf.buf, NULL) < 1)
                return error("Could not remove config section '%s'", buf.buf);
@@ -407,18 +403,18 @@ static int rm(int argc, const char **argv)
        return i;
 }
 
-static void show_list(const char *title, struct string_list *list)
+static void show_list(const char *title, struct string_list *list,
+                     const char *extra_arg)
 {
        int i;
 
        if (!list->nr)
                return;
 
-       printf(title, list->nr > 1 ? "es" : "");
-       printf("\n    ");
-       for (i = 0; i < list->nr; i++)
-               printf("%s%s", i ? " " : "", list->items[i].string);
+       printf(title, list->nr > 1 ? "es" : "", extra_arg);
        printf("\n");
+       for (i = 0; i < list->nr; i++)
+               printf("    %s\n", list->items[i].string);
 }
 
 static int get_remote_ref_states(const char *name,
@@ -477,7 +473,6 @@ static int show(int argc, const char **argv)
 
        memset(&states, 0, sizeof(states));
        for (; argc; argc--, argv++) {
-               struct strbuf buf;
                int i;
 
                get_remote_ref_states(*argv, &states, !no_query);
@@ -503,31 +498,29 @@ static int show(int argc, const char **argv)
                }
 
                if (!no_query) {
-                       strbuf_init(&buf, 0);
-                       strbuf_addf(&buf, "  New remote branch%%s (next fetch "
-                               "will store in remotes/%s)", states.remote->name);
-                       show_list(buf.buf, &states.new);
-                       strbuf_release(&buf);
+                       show_list("  New remote branch%s (next fetch "
+                               "will store in remotes/%s)",
+                               &states.new, states.remote->name);
                        show_list("  Stale tracking branch%s (use 'git remote "
-                               "prune')", &states.stale);
+                               "prune')", &states.stale, "");
                }
 
                if (no_query)
                        for_each_ref(append_ref_to_tracked_list, &states);
-               show_list("  Tracked remote branch%s", &states.tracked);
+               show_list("  Tracked remote branch%s", &states.tracked, "");
 
                if (states.remote->push_refspec_nr) {
-                       printf("  Local branch%s pushed with 'git push'\n   ",
+                       printf("  Local branch%s pushed with 'git push'\n",
                                states.remote->push_refspec_nr > 1 ?
                                        "es" : "");
                        for (i = 0; i < states.remote->push_refspec_nr; i++) {
                                struct refspec *spec = states.remote->push + i;
-                               printf(" %s%s%s%s", spec->force ? "+" : "",
+                               printf("    %s%s%s%s\n",
+                                      spec->force ? "+" : "",
                                       abbrev_branch(spec->src),
                                       spec->dst ? ":" : "",
                                       spec->dst ? abbrev_branch(spec->dst) : "");
                        }
-                       printf("\n");
                }
 
                /* NEEDSWORK: free remote */
@@ -652,10 +645,13 @@ static int get_one_entry(struct remote *remote, void *priv)
 {
        struct string_list *list = priv;
 
-       string_list_append(remote->name, list)->util = remote->url_nr ?
-               (void *)remote->url[0] : NULL;
-       if (remote->url_nr > 1)
-               warning("Remote %s has more than one URL", remote->name);
+       if (remote->url_nr > 0) {
+               int i;
+
+               for (i = 0; i < remote->url_nr; i++)
+                       string_list_append(remote->name, list)->util = (void *)remote->url[i];
+       } else
+               string_list_append(remote->name, list)->util = NULL;
 
        return 0;
 }
@@ -671,10 +667,14 @@ static int show_all(void)
                sort_string_list(&list);
                for (i = 0; i < list.nr; i++) {
                        struct string_list_item *item = list.items + i;
-                       printf("%s%s%s\n", item->string,
-                               verbose ? "\t" : "",
-                               verbose && item->util ?
-                                       (const char *)item->util : "");
+                       if (verbose)
+                               printf("%s\t%s\n", item->string,
+                                       item->util ? (const char *)item->util : "");
+                       else {
+                               if (i && !strcmp((item - 1)->string, item->string))
+                                       continue;
+                               printf("%s\n", item->string);
+                       }
                }
        }
        return result;