prune_remote(): iterate using for_each_string_list_item()

Iterate over refs_to_prune using for_each_string_list_item() rather than writing out the loop in longhand. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Nov 25, 2014 at 09:02 UTC 8552943f41373583b5185a9686102251c544c07e
1 file changed +6 -8
builtin/remote.c
+6 -8
@@ -1309,9 +1309,10 @@ static int set_head(int argc, const char **argv)
1309
1310 static int prune_remote(const char *remote, int dry_run)
1311 {
1312 - int result = 0, i;
1312 + int result = 0;
1313 struct ref_states states;
1314 struct string_list refs_to_prune = STRING_LIST_INIT_NODUP;
1315 + struct string_list_item *item;
1316 const char *dangling_msg = dry_run
1317 ? _(" %s will become dangling!")
1318 : _(" %s has become dangling!");
@@ -1330,11 +1331,8 @@ static int prune_remote(const char *remote, int dry_run)
1331 ? states.remote->url[0]
1332 : _("(no URL)"));
1333
1333 - for (i = 0; i < states.stale.nr; i++) {
1334 - const char *refname = states.stale.items[i].util;
1335 -
1336 - string_list_append(&refs_to_prune, refname);
1337 - }
1334 + for_each_string_list_item(item, &states.stale)
1335 + string_list_append(&refs_to_prune, item->util);
1336 sort_string_list(&refs_to_prune);
1337
1338 if (!dry_run) {
@@ -1344,8 +1342,8 @@ static int prune_remote(const char *remote, int dry_run)
1342 strbuf_release(&err);
1343 }
1344
1347 - for (i = 0; i < states.stale.nr; i++) {
1348 - const char *refname = states.stale.items[i].util;
1345 + for_each_string_list_item(item, &states.stale) {
1346 + const char *refname = item->util;
1347
1348 if (!dry_run)
1349 result |= delete_ref(refname, NULL, 0);