precompose_utf8: drop unused variable
[gitweb.git] / remote.c
index 22a60fcc0bbd82bcc7649a550921758ba73d140f..a01f13a211c74900e65b40e16406402cf8cf41f7 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -54,9 +54,6 @@ static const char *pushremote_name;
 static struct rewrites rewrites;
 static struct rewrites rewrites_push;
 
-#define BUF_SIZE (2048)
-static char buffer[BUF_SIZE];
-
 static int valid_remote(const struct remote *remote)
 {
        return (!!remote->url) || (!!remote->foreign_vcs);
@@ -243,50 +240,34 @@ static void add_instead_of(struct rewrite *rewrite, const char *instead_of)
        rewrite->instead_of_nr++;
 }
 
+static const char *skip_spaces(const char *s)
+{
+       while (isspace(*s))
+               s++;
+       return s;
+}
+
 static void read_remotes_file(struct remote *remote)
 {
+       struct strbuf buf = STRBUF_INIT;
        FILE *f = fopen(git_path("remotes/%s", remote->name), "r");
 
        if (!f)
                return;
        remote->origin = REMOTE_REMOTES;
-       while (fgets(buffer, BUF_SIZE, f)) {
-               int value_list;
-               char *s, *p;
-
-               if (starts_with(buffer, "URL:")) {
-                       value_list = 0;
-                       s = buffer + 4;
-               } else if (starts_with(buffer, "Push:")) {
-                       value_list = 1;
-                       s = buffer + 5;
-               } else if (starts_with(buffer, "Pull:")) {
-                       value_list = 2;
-                       s = buffer + 5;
-               } else
-                       continue;
-
-               while (isspace(*s))
-                       s++;
-               if (!*s)
-                       continue;
+       while (strbuf_getline(&buf, f, '\n') != EOF) {
+               const char *v;
 
-               p = s + strlen(s);
-               while (isspace(p[-1]))
-                       *--p = 0;
+               strbuf_rtrim(&buf);
 
-               switch (value_list) {
-               case 0:
-                       add_url_alias(remote, xstrdup(s));
-                       break;
-               case 1:
-                       add_push_refspec(remote, xstrdup(s));
-                       break;
-               case 2:
-                       add_fetch_refspec(remote, xstrdup(s));
-                       break;
-               }
+               if (skip_prefix(buf.buf, "URL:", &v))
+                       add_url_alias(remote, xstrdup(skip_spaces(v)));
+               else if (skip_prefix(buf.buf, "Push:", &v))
+                       add_push_refspec(remote, xstrdup(skip_spaces(v)));
+               else if (skip_prefix(buf.buf, "Pull:", &v))
+                       add_fetch_refspec(remote, xstrdup(skip_spaces(v)));
        }
+       strbuf_release(&buf);
        fclose(f);
 }