Merge branch 'nd/lockfile-absolute'
[gitweb.git] / builtin / remote.c
index 7d5c8d2074ba503601f45e3a0100c7f5326340cd..46ecfd9f7b0dd0b28169341d14132df376e509bc 100644 (file)
@@ -352,9 +352,9 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
        free_refs(stale_refs);
        free_refs(fetch_map);
 
-       sort_string_list(&states->new);
-       sort_string_list(&states->tracked);
-       sort_string_list(&states->stale);
+       string_list_sort(&states->new);
+       string_list_sort(&states->tracked);
+       string_list_sort(&states->stale);
 
        return 0;
 }
@@ -750,16 +750,11 @@ static int mv(int argc, const char **argv)
 static int remove_branches(struct string_list *branches)
 {
        struct strbuf err = STRBUF_INIT;
-       const char **branch_names;
        int i, result = 0;
 
-       branch_names = xmalloc(branches->nr * sizeof(*branch_names));
-       for (i = 0; i < branches->nr; i++)
-               branch_names[i] = branches->items[i].string;
-       if (repack_without_refs(branch_names, branches->nr, &err))
+       if (repack_without_refs(branches, &err))
                result |= error("%s", err.buf);
        strbuf_release(&err);
-       free(branch_names);
 
        for (i = 0; i < branches->nr; i++) {
                struct string_list_item *item = branches->items + i;
@@ -914,7 +909,7 @@ static int get_remote_ref_states(const char *name,
                        get_push_ref_states(remote_refs, states);
        } else {
                for_each_ref(append_ref_to_tracked_list, states);
-               sort_string_list(&states->tracked);
+               string_list_sort(&states->tracked);
                get_push_ref_states_noquery(states);
        }
 
@@ -1133,7 +1128,7 @@ static int show_all(void)
        if (!result) {
                int i;
 
-               sort_string_list(&list);
+               string_list_sort(&list);
                for (i = 0; i < list.nr; i++) {
                        struct string_list_item *item = list.items + i;
                        if (verbose)
@@ -1314,10 +1309,10 @@ static int set_head(int argc, const char **argv)
 
 static int prune_remote(const char *remote, int dry_run)
 {
-       int result = 0, i;
+       int result = 0;
        struct ref_states states;
-       struct string_list delete_refs_list = STRING_LIST_INIT_NODUP;
-       const char **delete_refs;
+       struct string_list refs_to_prune = STRING_LIST_INIT_NODUP;
+       struct string_list_item *item;
        const char *dangling_msg = dry_run
                ? _(" %s will become dangling!")
                : _(" %s has become dangling!");
@@ -1336,25 +1331,19 @@ static int prune_remote(const char *remote, int dry_run)
                  ? states.remote->url[0]
                  : _("(no URL)"));
 
-       delete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs));
-       for (i = 0; i < states.stale.nr; i++) {
-               const char *refname = states.stale.items[i].util;
-
-               delete_refs[i] = refname;
-               string_list_append(&delete_refs_list, refname);
-       }
-       sort_string_list(&delete_refs_list);
+       for_each_string_list_item(item, &states.stale)
+               string_list_append(&refs_to_prune, item->util);
+       string_list_sort(&refs_to_prune);
 
        if (!dry_run) {
                struct strbuf err = STRBUF_INIT;
-               if (repack_without_refs(delete_refs, states.stale.nr,
-                                       &err))
+               if (repack_without_refs(&refs_to_prune, &err))
                        result |= error("%s", err.buf);
                strbuf_release(&err);
        }
 
-       for (i = 0; i < states.stale.nr; i++) {
-               const char *refname = states.stale.items[i].util;
+       for_each_string_list_item(item, &states.stale) {
+               const char *refname = item->util;
 
                if (!dry_run)
                        result |= delete_ref(refname, NULL, 0);
@@ -1367,10 +1356,9 @@ static int prune_remote(const char *remote, int dry_run)
                               abbrev_ref(refname, "refs/remotes/"));
        }
 
-       warn_dangling_symrefs(stdout, dangling_msg, &delete_refs_list);
+       warn_dangling_symrefs(stdout, dangling_msg, &refs_to_prune);
 
-       free(delete_refs);
-       string_list_clear(&delete_refs_list, 0);
+       string_list_clear(&refs_to_prune, 0);
        free_remote_ref_states(&states);
        return result;
 }