mailinfo: do not let handle_boundary() touch global "line" directly
[gitweb.git] / builtin / fetch.c
index 8d5b2dba2bc4251a7c35bc6aa6ff260ea72b7455..9a3869f4ffd81f84f738e54c6405aaedb2514f18 100644 (file)
@@ -11,6 +11,7 @@
 #include "run-command.h"
 #include "parse-options.h"
 #include "sigchain.h"
+#include "submodule-config.h"
 #include "submodule.h"
 #include "connected.h"
 #include "argv-array.h"
@@ -591,7 +592,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
        const char *what, *kind;
        struct ref *rm;
        char *url;
-       const char *filename = dry_run ? "/dev/null" : git_path("FETCH_HEAD");
+       const char *filename = dry_run ? "/dev/null" : git_path_fetch_head();
        int want_status;
 
        fp = fopen(filename, "a");
@@ -790,20 +791,29 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
        if (4 < i && !strncmp(".git", url + i - 3, 4))
                url_len = i - 3;
 
-       for (ref = stale_refs; ref; ref = ref->next) {
-               if (!dry_run)
-                       result |= delete_ref(ref->name, NULL, 0);
-               if (verbosity >= 0 && !shown_url) {
-                       fprintf(stderr, _("From %.*s\n"), url_len, url);
-                       shown_url = 1;
-               }
-               if (verbosity >= 0) {
+       if (!dry_run) {
+               struct string_list refnames = STRING_LIST_INIT_NODUP;
+
+               for (ref = stale_refs; ref; ref = ref->next)
+                       string_list_append(&refnames, ref->name);
+
+               result = delete_refs(&refnames);
+               string_list_clear(&refnames, 0);
+       }
+
+       if (verbosity >= 0) {
+               for (ref = stale_refs; ref; ref = ref->next) {
+                       if (!shown_url) {
+                               fprintf(stderr, _("From %.*s\n"), url_len, url);
+                               shown_url = 1;
+                       }
                        fprintf(stderr, " x %-*s %-*s -> %s\n",
                                TRANSPORT_SUMMARY(_("[deleted]")),
                                REFCOL_WIDTH, _("(none)"), prettify_refname(ref->name));
                        warn_dangling_symref(stderr, dangling_msg, ref->name);
                }
        }
+
        free(url);
        free_refs(stale_refs);
        return result;
@@ -825,7 +835,7 @@ static void check_not_current_branch(struct ref *ref_map)
 
 static int truncate_fetch_head(void)
 {
-       const char *filename = git_path("FETCH_HEAD");
+       const char *filename = git_path_fetch_head();
        FILE *fp = fopen(filename, "w");
 
        if (!fp)
@@ -979,17 +989,15 @@ static int get_remote_group(const char *key, const char *value, void *priv)
 {
        struct remote_group_data *g = priv;
 
-       if (starts_with(key, "remotes.") &&
-                       !strcmp(key + 8, g->name)) {
+       if (skip_prefix(key, "remotes.", &key) && !strcmp(key, g->name)) {
                /* split list by white space */
-               int space = strcspn(value, " \t\n");
                while (*value) {
-                       if (space > 1) {
+                       size_t wordlen = strcspn(value, " \t\n");
+
+                       if (wordlen >= 1)
                                string_list_append(g->list,
-                                                  xstrndup(value, space));
-                       }
-                       value += space + (value[space] != '\0');
-                       space = strcspn(value, " \t\n");
+                                                  xstrndup(value, wordlen));
+                       value += wordlen + (value[wordlen] != '\0');
                }
        }