|
6 | 6 | #include "../config.h"
|
7 | 7 | #include "../dir.h"
|
8 | 8 | #include "../environment.h"
|
| 9 | +#include "../fsck.h" |
9 | 10 | #include "../gettext.h"
|
10 | 11 | #include "../hash.h"
|
11 | 12 | #include "../hex.h"
|
|
15 | 16 | #include "../path.h"
|
16 | 17 | #include "../refs.h"
|
17 | 18 | #include "../reftable/reftable-basics.h"
|
18 |
| -#include "../reftable/reftable-stack.h" |
19 |
| -#include "../reftable/reftable-record.h" |
20 | 19 | #include "../reftable/reftable-error.h"
|
| 20 | +#include "../reftable/reftable-fsck.h" |
21 | 21 | #include "../reftable/reftable-iterator.h"
|
| 22 | +#include "../reftable/reftable-record.h" |
| 23 | +#include "../reftable/reftable-stack.h" |
22 | 24 | #include "../repo-settings.h"
|
23 | 25 | #include "../setup.h"
|
24 | 26 | #include "../strmap.h"
|
@@ -2674,11 +2676,56 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
|
2674 | 2676 | return ret;
|
2675 | 2677 | }
|
2676 | 2678 |
|
2677 |
| -static int reftable_be_fsck(struct ref_store *ref_store UNUSED, |
2678 |
| - struct fsck_options *o UNUSED, |
| 2679 | +static void reftable_fsck_verbose_handler(const char *msg, void *cb_data) |
| 2680 | +{ |
| 2681 | + struct fsck_options *o = cb_data; |
| 2682 | + |
| 2683 | + if (o->verbose) |
| 2684 | + fprintf_ln(stderr, "%s", msg); |
| 2685 | +} |
| 2686 | + |
| 2687 | +static const enum fsck_msg_id fsck_msg_id_map[] = { |
| 2688 | + [REFTABLE_FSCK_ERROR_TABLE_NAME] = FSCK_MSG_BAD_REFTABLE_TABLE_NAME, |
| 2689 | +}; |
| 2690 | + |
| 2691 | +static int reftable_fsck_error_handler(struct reftable_fsck_info *info, |
| 2692 | + void *cb_data) |
| 2693 | +{ |
| 2694 | + struct fsck_ref_report report = { .path = info->path }; |
| 2695 | + struct fsck_options *o = cb_data; |
| 2696 | + enum fsck_msg_id msg_id; |
| 2697 | + |
| 2698 | + if (info->error < 0 || info->error >= REFTABLE_FSCK_MAX_VALUE) |
| 2699 | + BUG("unknown fsck error: %d", (int)info->error); |
| 2700 | + |
| 2701 | + msg_id = fsck_msg_id_map[info->error]; |
| 2702 | + |
| 2703 | + if (!msg_id) |
| 2704 | + BUG("fsck_msg_id value missing for reftable error: %d", (int)info->error); |
| 2705 | + |
| 2706 | + return fsck_report_ref(o, &report, msg_id, "%s", info->msg); |
| 2707 | +} |
| 2708 | + |
| 2709 | +static int reftable_be_fsck(struct ref_store *ref_store, struct fsck_options *o, |
2679 | 2710 | struct worktree *wt UNUSED)
|
2680 | 2711 | {
|
2681 |
| - return 0; |
| 2712 | + struct reftable_ref_store *refs; |
| 2713 | + struct strmap_entry *entry; |
| 2714 | + struct hashmap_iter iter; |
| 2715 | + int ret = 0; |
| 2716 | + |
| 2717 | + refs = reftable_be_downcast(ref_store, REF_STORE_READ, "fsck"); |
| 2718 | + |
| 2719 | + ret |= reftable_fsck_check(refs->main_backend.stack, reftable_fsck_error_handler, |
| 2720 | + reftable_fsck_verbose_handler, o); |
| 2721 | + |
| 2722 | + strmap_for_each_entry(&refs->worktree_backends, &iter, entry) { |
| 2723 | + struct reftable_backend *b = (struct reftable_backend *)entry->value; |
| 2724 | + ret |= reftable_fsck_check(b->stack, reftable_fsck_error_handler, |
| 2725 | + reftable_fsck_verbose_handler, o); |
| 2726 | + } |
| 2727 | + |
| 2728 | + return ret; |
2682 | 2729 | }
|
2683 | 2730 |
|
2684 | 2731 | struct ref_storage_be refs_be_reftable = {
|
|
0 commit comments