Skip to content

Commit 8552943

Browse files
mhaggergitster
authored andcommitted
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>
1 parent fcce0da commit 8552943

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

builtin/remote.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,9 +1309,10 @@ static int set_head(int argc, const char **argv)
13091309

13101310
static int prune_remote(const char *remote, int dry_run)
13111311
{
1312-
int result = 0, i;
1312+
int result = 0;
13131313
struct ref_states states;
13141314
struct string_list refs_to_prune = STRING_LIST_INIT_NODUP;
1315+
struct string_list_item *item;
13151316
const char *dangling_msg = dry_run
13161317
? _(" %s will become dangling!")
13171318
: _(" %s has become dangling!");
@@ -1330,11 +1331,8 @@ static int prune_remote(const char *remote, int dry_run)
13301331
? states.remote->url[0]
13311332
: _("(no URL)"));
13321333

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);
13381336
sort_string_list(&refs_to_prune);
13391337

13401338
if (!dry_run) {
@@ -1344,8 +1342,8 @@ static int prune_remote(const char *remote, int dry_run)
13441342
strbuf_release(&err);
13451343
}
13461344

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;
13491347

13501348
if (!dry_run)
13511349
result |= delete_ref(refname, NULL, 0);

0 commit comments

Comments
 (0)