Code

builtin-remote: Make "remote -v" display push urls
authorMichael J Gruber <git@drmicha.warpmail.net>
Sat, 13 Jun 2009 16:29:11 +0000 (18:29 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 13 Jun 2009 17:38:11 +0000 (10:38 -0700)
Currently, "remote -v" simply lists all urls so that one has to remember
that only the first one is used for fetches, and all are used for
pushes.

Change this so that the role of an url is displayed in parentheses, and
also display push urls.

Example with "one" having one url, "two" two urls, "three" one url and
one pushurl:

one     hostone.com:/somepath/repoone.git (fetch)
one     hostone.com:/somepath/repoone.git (push)
three   http://hostthree.com/otherpath/repothree.git (fetch)
three   hostthree.com:/pathforpushes/repothree.git (push)
two     hosttwo.com:/somepath/repotwo.git (fetch)
two     hosttwo.com:/somepath/repotwo.git (push)
two     hosttwobackup.com:/somewheresafe/repotwo.git (push)

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-remote.c

index 8dcc6a4bf904f743dfacdc4a6ae6edb0ae0f1bb5..3f6f5c2318d49fe05df78e7dfd8338383c4b39a1 100644 (file)
@@ -1279,14 +1279,31 @@ static int update(int argc, const char **argv)
 static int get_one_entry(struct remote *remote, void *priv)
 {
        struct string_list *list = priv;
+       const char **url;
+       int i, url_nr;
+       void **utilp;
 
        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];
+               utilp = &(string_list_append(remote->name, list)->util);
+               *utilp = malloc(strlen(remote->url[0])+strlen(" (fetch)")+1);
+               strcpy((char *) *utilp, remote->url[0]);
+               strcat((char *) *utilp, " (fetch)");
        } else
                string_list_append(remote->name, list)->util = NULL;
+       if (remote->pushurl_nr) {
+               url = remote->pushurl;
+               url_nr = remote->pushurl_nr;
+       } else {
+               url = remote->url;
+               url_nr = remote->url_nr;
+       }
+       for (i = 0; i < url_nr; i++)
+       {
+               utilp = &(string_list_append(remote->name, list)->util);
+               *utilp = malloc(strlen(url[i])+strlen(" (push)")+1);
+               strcpy((char *) *utilp, url[i]);
+               strcat((char *) *utilp, " (push)");
+       }
 
        return 0;
 }
@@ -1294,7 +1311,10 @@ static int get_one_entry(struct remote *remote, void *priv)
 static int show_all(void)
 {
        struct string_list list = { NULL, 0, 0 };
-       int result = for_each_remote(get_one_entry, &list);
+       int result;
+
+       list.strdup_strings = 1;
+       result = for_each_remote(get_one_entry, &list);
 
        if (!result) {
                int i;
@@ -1312,6 +1332,7 @@ static int show_all(void)
                        }
                }
        }
+       string_list_clear(&list, 1);
        return result;
 }