summaryrefslogtreecommitdiff
path: root/builtin/fsck.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/fsck.c')
-rw-r--r--builtin/fsck.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 1affdd5e92..e55f0803a2 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -624,6 +624,29 @@ static struct option fsck_opts[] = {
OPT_END(),
};
+struct verify_packs_data {
+ struct progress *progress;
+ uint32_t total;
+ uint32_t count;
+};
+
+static int count_packs(struct packed_git *p, void *data)
+{
+ struct verify_packs_data *vpd = (struct verify_packs_data *) data;
+ if (!open_pack_index(p))
+ vpd->total++;
+ return 0;
+}
+
+static int verify_packs(struct packed_git *p, void *data)
+{
+ struct verify_packs_data *vpd = (struct verify_packs_data *) data;
+ if (verify_pack(p, fsck_obj_buffer, vpd->progress, vpd->count))
+ errors_found |= ERROR_PACK;
+ vpd->count += p->num_objects;
+ return 0;
+}
+
int cmd_fsck(int argc, const char **argv, const char *prefix)
{
int i, heads;
@@ -657,29 +680,16 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
}
if (check_full) {
- struct packed_git *p;
- uint32_t total = 0, count = 0;
- struct progress *progress = NULL;
+ struct verify_packs_data vpd = {0, 0, 0};
prepare_packed_git();
if (show_progress) {
- for (p = packed_git; p; p = p->next) {
- if (open_pack_index(p))
- continue;
- total += p->num_objects;
- }
-
- progress = start_progress("Checking objects", total);
- }
- for (p = packed_git; p; p = p->next) {
- /* verify gives error messages itself */
- if (verify_pack(p, fsck_obj_buffer,
- progress, count))
- errors_found |= ERROR_PACK;
- count += p->num_objects;
+ foreach_packed_git(count_packs, NULL, &vpd);
+ vpd.progress = start_progress("Checking objects", vpd.total);
}
- stop_progress(&progress);
+ foreach_packed_git(verify_packs, NULL, &vpd);
+ stop_progress(&vpd.progress);
}
heads = 0;