mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
refs/reftable: add fsck check for checking the table name
Add glue code in 'refs/reftable-backend.c' which calls the reftable
library to perform the fsck checks. Here we also map the reftable errors
to Git' fsck errors.
Introduce a check to validate table names for a given reftable stack.
Also add 'badReftableTableName' as a corresponding error within Git. The
reftable specification mentions:
It suggested to use
${min_update_index}-${max_update_index}-${random}.ref as a naming
convention.
So treat non-conformant file names as warnings.
While adding the fsck header to 'refs/reftable-backend.c', modify the
list to maintain lexicographical ordering.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
9051638519
commit
466a3a1afd
@@ -6,6 +6,7 @@
|
||||
#include "../config.h"
|
||||
#include "../dir.h"
|
||||
#include "../environment.h"
|
||||
#include "../fsck.h"
|
||||
#include "../gettext.h"
|
||||
#include "../hash.h"
|
||||
#include "../hex.h"
|
||||
@@ -15,10 +16,11 @@
|
||||
#include "../path.h"
|
||||
#include "../refs.h"
|
||||
#include "../reftable/reftable-basics.h"
|
||||
#include "../reftable/reftable-stack.h"
|
||||
#include "../reftable/reftable-record.h"
|
||||
#include "../reftable/reftable-error.h"
|
||||
#include "../reftable/reftable-fsck.h"
|
||||
#include "../reftable/reftable-iterator.h"
|
||||
#include "../reftable/reftable-record.h"
|
||||
#include "../reftable/reftable-stack.h"
|
||||
#include "../repo-settings.h"
|
||||
#include "../setup.h"
|
||||
#include "../strmap.h"
|
||||
@@ -2674,11 +2676,56 @@ done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int reftable_be_fsck(struct ref_store *ref_store UNUSED,
|
||||
struct fsck_options *o UNUSED,
|
||||
static void reftable_fsck_verbose_handler(const char *msg, void *cb_data)
|
||||
{
|
||||
struct fsck_options *o = cb_data;
|
||||
|
||||
if (o->verbose)
|
||||
fprintf_ln(stderr, "%s", msg);
|
||||
}
|
||||
|
||||
static const enum fsck_msg_id fsck_msg_id_map[] = {
|
||||
[REFTABLE_FSCK_ERROR_TABLE_NAME] = FSCK_MSG_BAD_REFTABLE_TABLE_NAME,
|
||||
};
|
||||
|
||||
static int reftable_fsck_error_handler(struct reftable_fsck_info *info,
|
||||
void *cb_data)
|
||||
{
|
||||
struct fsck_ref_report report = { .path = info->path };
|
||||
struct fsck_options *o = cb_data;
|
||||
enum fsck_msg_id msg_id;
|
||||
|
||||
if (info->error < 0 || info->error >= REFTABLE_FSCK_MAX_VALUE)
|
||||
BUG("unknown fsck error: %d", (int)info->error);
|
||||
|
||||
msg_id = fsck_msg_id_map[info->error];
|
||||
|
||||
if (!msg_id)
|
||||
BUG("fsck_msg_id value missing for reftable error: %d", (int)info->error);
|
||||
|
||||
return fsck_report_ref(o, &report, msg_id, "%s", info->msg);
|
||||
}
|
||||
|
||||
static int reftable_be_fsck(struct ref_store *ref_store, struct fsck_options *o,
|
||||
struct worktree *wt UNUSED)
|
||||
{
|
||||
return 0;
|
||||
struct reftable_ref_store *refs;
|
||||
struct strmap_entry *entry;
|
||||
struct hashmap_iter iter;
|
||||
int ret = 0;
|
||||
|
||||
refs = reftable_be_downcast(ref_store, REF_STORE_READ, "fsck");
|
||||
|
||||
ret |= reftable_fsck_check(refs->main_backend.stack, reftable_fsck_error_handler,
|
||||
reftable_fsck_verbose_handler, o);
|
||||
|
||||
strmap_for_each_entry(&refs->worktree_backends, &iter, entry) {
|
||||
struct reftable_backend *b = (struct reftable_backend *)entry->value;
|
||||
ret |= reftable_fsck_check(b->stack, reftable_fsck_error_handler,
|
||||
reftable_fsck_verbose_handler, o);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct ref_storage_be refs_be_reftable = {
|
||||
|
||||
Reference in New Issue
Block a user