From: Chuck Lever Date: Mon, 12 Sep 2005 14:55:47 GMT Subject: [PATCH 02/22] use cache iterator in checkout-index.c Message-ID: <20050912145547.28120.22685.stgit@dexter.citi.umich.edu> In-Reply-To: <20050912145543.28120.7086.stgit@dexter.citi.umich.edu> Signed-off-by: Chuck Lever --- checkout-index.c | 16 +++++----------- 1 files changed, 5 insertions(+), 11 deletions(-) diff --git a/checkout-index.c b/checkout-index.c --- a/checkout-index.c +++ b/checkout-index.c @@ -61,17 +61,12 @@ static int checkout_file(const char *nam return checkout_entry(active_cache[pos], &state); } -static int checkout_all(void) +static int checkout_one(struct cache_cursor *cc, struct cache_entry *ce) { - int i; - - for (i = 0; i < active_nr ; i++) { - struct cache_entry *ce = active_cache[i]; - if (ce_stage(ce)) - continue; + if (!ce_stage(ce)) if (checkout_entry(ce, &state) < 0) return -1; - } + next_cc(cc); return 0; } @@ -85,15 +80,14 @@ int main(int argc, char **argv) int i, force_filename = 0; int newfd = -1; - if (read_cache() < 0) { + if (read_cache() < 0) die("invalid cache"); - } for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (!force_filename) { if (!strcmp(arg, "-a")) { - checkout_all(); + walk_cache(checkout_one); continue; } if (!strcmp(arg, "--")) {