[PATCH 10/22] teach update-index.c about cache cursors
Signed-off-by: Chuck Lever <cel@netapp.com>
---
update-index.c | 62 +++++++++++++++++++++++++-------------------------------
1 files changed, 28 insertions(+), 34 deletions(-)
diff --git a/update-index.c b/update-index.c
--- a/update-index.c
+++ b/update-index.c
@@ -13,7 +13,7 @@
* files be revision controlled.
*/
static int allow_add = 0, allow_remove = 0, allow_replace = 0, not_new = 0, quiet = 0, info_only = 0;
-static int force_remove;
+static int force_remove, has_errors = 0;
/* Three functions to allow overloaded pointer return; see linux/err.h */
static inline void *ERR_PTR(long error)
@@ -190,41 +190,35 @@ static struct cache_entry *refresh_entry
return updated;
}
-static int refresh_cache(void)
+static int refresh_one(struct cache_cursor *cc, struct cache_entry *ce)
{
- int i;
- int has_errors = 0;
+ struct cache_entry *new;
- for (i = 0; i < active_nr; i++) {
- struct cache_entry *ce, *new;
- ce = active_cache[i];
- if (ce_stage(ce)) {
- printf("%s: needs merge\n", ce->name);
- has_errors = 1;
- while ((i < active_nr) &&
- ! strcmp(active_cache[i]->name, ce->name))
- i++;
- i--;
- continue;
- }
+ if (ce_stage(ce)) {
+ printf("%s: needs merge\n", ce->name);
+ has_errors = 1;
+ next_name(cc, ce);
+ return 0;
+ }
- new = refresh_entry(ce);
- if (IS_ERR(new)) {
- if (not_new && PTR_ERR(new) == -ENOENT)
- continue;
- if (quiet)
- continue;
- printf("%s: needs update\n", ce->name);
- has_errors = 1;
- continue;
- }
- active_cache_changed = 1;
- /* You can NOT just free active_cache[i] here, since it
- * might not be necessarily malloc()ed but can also come
- * from mmap(). */
- active_cache[i] = new;
+ new = refresh_entry(ce);
+ if (IS_ERR(new)) {
+ if (not_new && PTR_ERR(new) == -ENOENT)
+ return 0;
+ if (quiet)
+ return 0;
+ printf("%s: needs update\n", ce->name);
+ has_errors = 1;
+ next_cc(cc);
+ return 0;
}
- return has_errors;
+
+ /* You can NOT just free active_cache[i] here, since it
+ * might not be necessarily malloc()ed but can also come
+ * from mmap(). */
+ set_ce_at_cursor(cc, new);
+ next_cc(cc);
+ return 0;
}
/*
@@ -323,7 +317,7 @@ static struct cache_file cache_file;
int main(int argc, char **argv)
{
- int i, newfd, entries, has_errors = 0;
+ int i, newfd, entries;
int allow_options = 1;
const char *prefix = setup_git_directory();
@@ -360,7 +354,7 @@ int main(int argc, char **argv)
continue;
}
if (!strcmp(path, "--refresh")) {
- has_errors |= refresh_cache();
+ walk_cache(refresh_one);
continue;
}
if (!strcmp(path, "--cacheinfo")) {