SVN.pm::parse_svn_date: allow timestamps with a single-digit hour
[gitweb.git] / builtin / remote.c
index ecedd968d3fba70758b1e437604745322e9c90d6..b3ab4cf8f6517c715845db7e17c67cad5f50d730 100644 (file)
@@ -6,6 +6,7 @@
 #include "strbuf.h"
 #include "run-command.h"
 #include "refs.h"
+#include "argv-array.h"
 
 static const char * const builtin_remote_usage[] = {
        N_("git remote [-v | --verbose]"),
@@ -77,14 +78,6 @@ static const char * const builtin_remote_seturl_usage[] = {
 
 static int verbose;
 
-static inline int postfixcmp(const char *string, const char *postfix)
-{
-       int len1 = strlen(string), len2 = strlen(postfix);
-       if (len1 < len2)
-               return 1;
-       return strcmp(string + len1 - len2, postfix);
-}
-
 static int fetch_remote(const char *name)
 {
        const char *argv[] = { "fetch", name, NULL, NULL };
@@ -266,7 +259,7 @@ static const char *abbrev_ref(const char *name, const char *prefix)
 
 static int config_read_branches(const char *key, const char *value, void *cb)
 {
-       if (!prefixcmp(key, "branch.")) {
+       if (starts_with(key, "branch.")) {
                const char *orig_key = key;
                char *name;
                struct string_list_item *item;
@@ -274,13 +267,13 @@ static int config_read_branches(const char *key, const char *value, void *cb)
                enum { REMOTE, MERGE, REBASE } type;
 
                key += 7;
-               if (!postfixcmp(key, ".remote")) {
+               if (ends_with(key, ".remote")) {
                        name = xstrndup(key, strlen(key) - 7);
                        type = REMOTE;
-               } else if (!postfixcmp(key, ".merge")) {
+               } else if (ends_with(key, ".merge")) {
                        name = xstrndup(key, strlen(key) - 6);
                        type = MERGE;
-               } else if (!postfixcmp(key, ".rebase")) {
+               } else if (ends_with(key, ".rebase")) {
                        name = xstrndup(key, strlen(key) - 7);
                        type = REBASE;
                } else
@@ -306,8 +299,13 @@ static int config_read_branches(const char *key, const char *value, void *cb)
                                space = strchr(value, ' ');
                        }
                        string_list_append(&info->merge, xstrdup(value));
-               } else
-                       info->rebase = git_config_bool(orig_key, value);
+               } else {
+                       int v = git_config_maybe_bool(orig_key, value);
+                       if (v >= 0)
+                               info->rebase = v;
+                       else if (!strcmp(value, "preserve"))
+                               info->rebase = 1;
+               }
        }
        return 0;
 }
@@ -531,9 +529,9 @@ static int add_branch_for_removal(const char *refname,
        }
 
        /* don't delete non-remote-tracking refs */
-       if (prefixcmp(refname, "refs/remotes/")) {
+       if (!starts_with(refname, "refs/remotes/")) {
                /* advise user how to delete local branches */
-               if (!prefixcmp(refname, "refs/heads/"))
+               if (starts_with(refname, "refs/heads/"))
                        string_list_append(branches->skipped,
                                           abbrev_branch(refname));
                /* silently skip over other non-remote refs */
@@ -568,7 +566,7 @@ static int read_remote_branches(const char *refname,
        const char *symref;
 
        strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
-       if (!prefixcmp(refname, buf.buf)) {
+       if (starts_with(refname, buf.buf)) {
                item = string_list_append(rename->remote_branches, xstrdup(refname));
                symref = resolve_ref_unsafe(refname, orig_sha1, 1, &flag);
                if (flag & REF_ISSYMREF)
@@ -1370,42 +1368,42 @@ static int get_remote_default(const char *key, const char *value, void *priv)
 
 static int update(int argc, const char **argv)
 {
-       int i, prune = 0;
+       int i, prune = -1;
        struct option options[] = {
                OPT_BOOL('p', "prune", &prune,
                         N_("prune remotes after fetching")),
                OPT_END()
        };
-       const char **fetch_argv;
-       int fetch_argc = 0;
+       struct argv_array fetch_argv = ARGV_ARRAY_INIT;
        int default_defined = 0;
-
-       fetch_argv = xmalloc(sizeof(char *) * (argc+5));
+       int retval;
 
        argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage,
                             PARSE_OPT_KEEP_ARGV0);
 
-       fetch_argv[fetch_argc++] = "fetch";
+       argv_array_push(&fetch_argv, "fetch");
 
-       if (prune)
-               fetch_argv[fetch_argc++] = "--prune";
+       if (prune != -1)
+               argv_array_push(&fetch_argv, prune ? "--prune" : "--no-prune");
        if (verbose)
-               fetch_argv[fetch_argc++] = "-v";
-       fetch_argv[fetch_argc++] = "--multiple";
+               argv_array_push(&fetch_argv, "-v");
+       argv_array_push(&fetch_argv, "--multiple");
        if (argc < 2)
-               fetch_argv[fetch_argc++] = "default";
+               argv_array_push(&fetch_argv, "default");
        for (i = 1; i < argc; i++)
-               fetch_argv[fetch_argc++] = argv[i];
+               argv_array_push(&fetch_argv, argv[i]);
 
-       if (strcmp(fetch_argv[fetch_argc-1], "default") == 0) {
+       if (strcmp(fetch_argv.argv[fetch_argv.argc-1], "default") == 0) {
                git_config(get_remote_default, &default_defined);
-               if (!default_defined)
-                       fetch_argv[fetch_argc-1] = "--all";
+               if (!default_defined) {
+                       argv_array_pop(&fetch_argv);
+                       argv_array_push(&fetch_argv, "--all");
+               }
        }
 
-       fetch_argv[fetch_argc] = NULL;
-
-       return run_command_v_opt(fetch_argv, RUN_GIT_CMD);
+       retval = run_command_v_opt(fetch_argv.argv, RUN_GIT_CMD);
+       argv_array_clear(&fetch_argv);
+       return retval;
 }
 
 static int remove_all_fetch_refspecs(const char *remote, const char *key)