From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: Stefan Beller <sbeller@google.com>,
Jonathan Nieder <jrnieder@gmail.com>,
Ronnie Sahlberg <sahlberg@google.com>,
git@vger.kernel.org, Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH v2 6/7] prune_remote(): iterate using for_each_string_list_item()
Date: Tue, 25 Nov 2014 09:02:34 +0100 [thread overview]
Message-ID: <1416902555-10748-7-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1416902555-10748-1-git-send-email-mhagger@alum.mit.edu>
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>
---
builtin/remote.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index efbf5fb..7fec170 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1309,9 +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 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!");
@@ -1330,11 +1331,8 @@ static int prune_remote(const char *remote, int dry_run)
? states.remote->url[0]
: _("(no URL)"));
- for (i = 0; i < states.stale.nr; i++) {
- const char *refname = states.stale.items[i].util;
-
- string_list_append(&refs_to_prune, refname);
- }
+ for_each_string_list_item(item, &states.stale)
+ string_list_append(&refs_to_prune, item->util);
sort_string_list(&refs_to_prune);
if (!dry_run) {
@@ -1344,8 +1342,8 @@ static int prune_remote(const char *remote, int dry_run)
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);
--
2.1.3
next prev parent reply other threads:[~2014-11-25 8:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-25 8:02 [PATCH v2 0/7] repack_without_refs(): convert to string_list Michael Haggerty
2014-11-25 8:02 ` [PATCH v2 1/7] prune_remote(): exit early if there are no stale references Michael Haggerty
2014-11-25 18:09 ` Junio C Hamano
2014-11-25 8:02 ` [PATCH v2 2/7] prune_remote(): initialize both delete_refs lists in a single loop Michael Haggerty
2014-11-25 8:02 ` [PATCH v2 3/7] prune_remote(): sort delete_refs_list references en masse Michael Haggerty
2014-11-25 8:02 ` [PATCH v2 4/7] repack_without_refs(): make the refnames argument a string_list Michael Haggerty
2014-11-25 8:02 ` [PATCH v2 5/7] prune_remote(): rename local variable Michael Haggerty
2014-11-25 8:02 ` Michael Haggerty [this message]
2014-11-25 8:02 ` [PATCH v2 7/7] Rename sort_string_list() to string_list_sort() Michael Haggerty
2014-11-25 18:17 ` Junio C Hamano
2014-11-26 1:15 ` [PATCH v2 0/7] repack_without_refs(): convert to string_list Stefan Beller
2014-11-26 17:55 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1416902555-10748-7-git-send-email-mhagger@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=sahlberg@google.com \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).