From patchwork Thu Aug 8 11:24:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13757268 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23EFE12C7FD for ; Thu, 8 Aug 2024 11:23:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116227; cv=none; b=Be8A/DzXf35P+uxCxSHif4eBZhmeQNepupdExjzslWMZWLtmpcfn00Doiff83W/LBkqU+F5HMpwi3Nug5xc5/GqecWs50YstKdjPIzZO2RJBFxfhjrGhzd7mHoFmQAVibRToRYBaf4cFeC89vg/PjtcSY7Uld1E0rY4a73GT57E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116227; c=relaxed/simple; bh=amDj2c5gDZRBhglehafDqExLCk1rzcqUdwLMoGAS4gk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rxqCPxznSdX53TT+ydvwEI9km6VT6J4y/GPGgCZBjXx5VYxZN+BFOHKj97IzMQnZfv1rvH8dWPzsR2iXdhTYE2AWxZsCL5NHPqoffNoW053QkX17d1HK2X+D8HMHkVpaIs2DyPpx8E/yRPgJnAz4FyHpT5gJq+zcfVtnLe2X/Aw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NrDzSmZK; arc=none smtp.client-ip=209.85.167.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NrDzSmZK" Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3dc16d00ba6so615485b6e.0 for ; Thu, 08 Aug 2024 04:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723116225; x=1723721025; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Ijt50yIi5MF0RHPoiFN0m67WlBufRjXujnKRkvfb7lM=; b=NrDzSmZKzm4prmBOQ96t8pCSFgJqjgKpZEAGjjdUnklDsu0KYSIG+K/f4KgI6/QzIe SDUStsqOHlgGrahOEvweTuO4u0jP1DXD67/VSLt7DNucqThj8CV3SnHqvoABICumSOR9 yEhz0b/fDxrkP4Zvugn781YiqXVzhzTfIUB2u7PdDDZeXrQzUcXi2ndVWRCN4SR5+M1z cDayoyUmwIyh773NcNdAqZGAg3RxXKs8jQfkcGiHKq06yS1aKnvxGK7xTOyiuHjG/+/t JuChS5Ci2A+oSghDpfNsL6AfhNizpWObI8OBCKt9riPc/RdXUfiXdfhpKtnTnb5o2nXx 0iMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723116225; x=1723721025; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Ijt50yIi5MF0RHPoiFN0m67WlBufRjXujnKRkvfb7lM=; b=m7/A/Ipw73XeC4WbLYmyHsmJb9XpiWfIgQfMjnfKd+PVN5Msc3r6Ryq31AAEGG9avk Dt8oB5+wEBhK3HSzHbpME1jvee6oZ+P/dCVuYj++ceKkDGgLBMvB74HXT0bmgwGflvwK dyaDZJvcrvT2GDmoDG4/p4Q0mR7EV3ejGUwu1+7n2BOA6ixvqkGXTvZr9atm5IRp+4Im PjvdJTgZIKcgH9XCTplAMiV+6T99WrmPPXSQcqpbjgU4Jg6dohK9AXdXIC+yPzSYwopp SaTUt5OxIni8pBdEifR1VkizLKNQgZvG/l8TXpC2g0QssjowYSv6gmHz4NTkV3dawUl7 9DHw== X-Gm-Message-State: AOJu0YzlvLKQdbMJc2QurCAnOIz6LbHCQgwAvzoLWf+b6U1q9NZEgoDP +KpFdoB2At20g/U2DFVHcHn20ayaIcyvvK2OcFzMrD2FxZ9YNSa63EGM2MssJHM= X-Google-Smtp-Source: AGHT+IGFAnho68lKzCre3hfBI2Fw3dkiCjM+w7UJmcD4wh0MTV/mx1qbcF2MXKWHeMCZBIN+vJ6o5A== X-Received: by 2002:a05:6870:f69e:b0:260:f97d:6473 with SMTP id 586e51a60fabf-2692b78b6femr1783315fac.38.1723116224726; Thu, 08 Aug 2024 04:23:44 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb20a08csm950979b3a.31.2024.08.08.04.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 04:23:44 -0700 (PDT) Date: Thu, 8 Aug 2024 19:24:13 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v16 1/9] fsck: rename "skiplist" to "skip_oids" Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "skiplist" field in "fsck_options" is related to objects. Because we are going to introduce ref consistency check, the "skiplist" name is too general which will make the caller think "skiplist" is related to both the refs and objects. It may seem that for both refs and objects, we should provide a general "skiplist" here. However, the type for "skiplist" is `struct oidset` which is totally unsuitable for refs. To avoid above ambiguity, rename "skiplist" to "skip_oids". Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 4 ++-- fsck.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fsck.c b/fsck.c index eea7145470..3f32441492 100644 --- a/fsck.c +++ b/fsck.c @@ -205,7 +205,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) if (!strcmp(buf, "skiplist")) { if (equal == len) die("skiplist requires a path"); - oidset_parse_file(&options->skiplist, buf + equal + 1, + oidset_parse_file(&options->skip_oids, buf + equal + 1, the_repository->hash_algo); buf += len + 1; continue; @@ -223,7 +223,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) static int object_on_skiplist(struct fsck_options *opts, const struct object_id *oid) { - return opts && oid && oidset_contains(&opts->skiplist, oid); + return opts && oid && oidset_contains(&opts->skip_oids, oid); } __attribute__((format (printf, 5, 6))) diff --git a/fsck.h b/fsck.h index 6085a384f6..bcfb2e34cd 100644 --- a/fsck.h +++ b/fsck.h @@ -136,7 +136,7 @@ struct fsck_options { fsck_error error_func; unsigned strict:1; enum fsck_msg_type *msg_type; - struct oidset skiplist; + struct oidset skip_oids; struct oidset gitmodules_found; struct oidset gitmodules_done; struct oidset gitattributes_found; @@ -145,7 +145,7 @@ struct fsck_options { }; #define FSCK_OPTIONS_DEFAULT { \ - .skiplist = OIDSET_INIT, \ + .skip_oids = OIDSET_INIT, \ .gitmodules_found = OIDSET_INIT, \ .gitmodules_done = OIDSET_INIT, \ .gitattributes_found = OIDSET_INIT, \ From patchwork Thu Aug 8 11:24:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13757269 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36C2712C7FD for ; Thu, 8 Aug 2024 11:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116238; cv=none; b=qrsdP2WyMfoG41dZ1HKOuJ3tSnkPLYrdkXeZU8HUPqufgoIXEdw7ryo7a0TNWZfKeIpHsIEwJXoUnokaMGamUqduCFGVLPfVuxefprxE+5w4agXfynZQaSvhZYIh0MUsO+w1/d2cS6NRt8wy6u53fTDNeHOsWUYWgSJAgMVguEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116238; c=relaxed/simple; bh=9Kqz6qIA5CWM5K27vSzkIfcF9uGHTKnddDCHROhEiJ0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=N0ddOt2EgXnDfPBo8zg+BiRKGPwcf76Lsupc1UX6i5CA5nK+EWZ1YLFfIaIt0YIAW/TJ9J16JK523fQz6TayVgqAnfu0aRr4P6DjMiRkY/erjNbcQt/ChjN8rFmzL6C5bXVfrZfOnWfUOHEcWpOwcQQsioPdDgqbTptxE2EL/rM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QfRh1Cq7; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QfRh1Cq7" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-710d1de6e79so60627b3a.0 for ; Thu, 08 Aug 2024 04:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723116236; x=1723721036; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8xe9DP7MzHqznOoiJe++dxb/q6o3x4HRjYqfLrdcmcw=; b=QfRh1Cq7qT57dhsDZ7q1XO/+D6GlP0FogKLZhEiY182VJyIAUndk0uRrTVu/hc1Bj0 YendILiZo+9kK/TJyogXyMYOjF7QKDtz6UJac23x6Kd/7Hl7NTRhEe/yUk3iZyKf/yJ0 hBxSjq4pKXylyTyK4mgDVrNZKyE5RbGEo9GmbJwrtdAsogF21vr/wNkWFFvbSDlY7I/B 3Jt3kbpr8vorw7tsjkOOn8GhBtnNW3aAWdiXJ/uC9dLPIPRIefxEKvz0JE9QIDOF3NzI tYCmEnepIpCG+yPrGRSW3P6TeMPj93QGjC7L1Rbz040r42EmeNYON/vPBpsbCxXfZiEF A2pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723116236; x=1723721036; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8xe9DP7MzHqznOoiJe++dxb/q6o3x4HRjYqfLrdcmcw=; b=uEI/25ykJMVIursLY8TrHx7djfODZJPBPWXTrzkzqjpv6ybc2xKFklBnwHIwumKVCQ mWewO/tP2cJwF7yVlzM9xE5PDjsAIgks+Q4nnDdcYMVedv0cvy2tC9JBOo1SYgymU22U FvslJe3QDi80l6atLMALGeHiBEsggZ9538s/fQwiTE78aVdLXmZ7sY1MNCTDgYu95jMh S7VKKiaybyKnK+VOrVHmztOjVh6SfKZ6Bmi/mnoXxcacRnUFoVpFPdaY/hwApFH9qXxx WJ8CUEnamnh1a6goXxdm2cbcFwHolDsTnOji1i11j7vDSWux0ESV0/zq26Yr+gHXdULq 7yJQ== X-Gm-Message-State: AOJu0YxXwQYRFe2BIbYsd/6Xosgw0A+lXLRllWqRhv2xwYJE4gbcXODc 6wnzktOkdvbPr3u9NCGvjuQWmL/rEvVEt/zkDsIr5M84j0rTQHteRl4KQqcucas= X-Google-Smtp-Source: AGHT+IHMgn9z01n/pnHL895BqZKT8VzCFXQFN5TUG/1YE6lOy4ty/DWrE7+PVl70sNmHJ7Xf/ESXVQ== X-Received: by 2002:a05:6a00:1249:b0:705:a13b:e740 with SMTP id d2e1a72fcca58-710cae20b3bmr1873078b3a.19.1723116235778; Thu, 08 Aug 2024 04:23:55 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59297329sm122585245ad.247.2024.08.08.04.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 04:23:55 -0700 (PDT) Date: Thu, 8 Aug 2024 19:24:25 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v16 2/9] fsck: rename objects-related fsck error functions Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The names of objects-related fsck error functions are generic. It's OK when there is only object database check. However, we are going to introduce refs database check report function. To avoid ambiguity, rename object-related fsck error functions to explicitly indicate these functions are used to report objects-related messages. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- builtin/fsck.c | 14 +++++++------- fsck.c | 17 +++++++++-------- fsck.h | 26 +++++++++++++------------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index d13a226c2e..6d86bbe1e9 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -89,12 +89,12 @@ static int objerror(struct object *obj, const char *err) return -1; } -static int fsck_error_func(struct fsck_options *o UNUSED, - const struct object_id *oid, - enum object_type object_type, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id UNUSED, - const char *message) +static int fsck_objects_error_func(struct fsck_options *o UNUSED, + const struct object_id *oid, + enum object_type object_type, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id UNUSED, + const char *message) { switch (msg_type) { case FSCK_WARN: @@ -938,7 +938,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) fsck_walk_options.walk = mark_object; fsck_obj_options.walk = mark_used; - fsck_obj_options.error_func = fsck_error_func; + fsck_obj_options.error_func = fsck_objects_error_func; if (check_strict) fsck_obj_options.strict = 1; diff --git a/fsck.c b/fsck.c index 3f32441492..8347842cfb 100644 --- a/fsck.c +++ b/fsck.c @@ -1200,7 +1200,7 @@ int fsck_buffer(const struct object_id *oid, enum object_type type, type); } -int fsck_error_function(struct fsck_options *o, +int fsck_objects_error_function(struct fsck_options *o, const struct object_id *oid, enum object_type object_type UNUSED, enum fsck_msg_type msg_type, @@ -1303,16 +1303,17 @@ int git_fsck_config(const char *var, const char *value, * Custom error callbacks that are used in more than one place. */ -int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id, - const char *message) +int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message) { if (msg_id == FSCK_MSG_GITMODULES_MISSING) { puts(oid_to_hex(oid)); return 0; } - return fsck_error_function(o, oid, object_type, msg_type, msg_id, message); + return fsck_objects_error_function(o, oid, object_type, + msg_type, msg_id, message); } diff --git a/fsck.h b/fsck.h index bcfb2e34cd..41ebebbb59 100644 --- a/fsck.h +++ b/fsck.h @@ -120,16 +120,16 @@ typedef int (*fsck_error)(struct fsck_options *o, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); -int fsck_error_function(struct fsck_options *o, - const struct object_id *oid, enum object_type object_type, - enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, - const char *message); -int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id, - const char *message); +int fsck_objects_error_function(struct fsck_options *o, + const struct object_id *oid, enum object_type object_type, + enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, + const char *message); +int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message); struct fsck_options { fsck_walk_func walk; @@ -150,7 +150,7 @@ struct fsck_options { .gitmodules_done = OIDSET_INIT, \ .gitattributes_found = OIDSET_INIT, \ .gitattributes_done = OIDSET_INIT, \ - .error_func = fsck_error_function \ + .error_func = fsck_objects_error_function \ } #define FSCK_OPTIONS_STRICT { \ .strict = 1, \ @@ -158,7 +158,7 @@ struct fsck_options { .gitmodules_done = OIDSET_INIT, \ .gitattributes_found = OIDSET_INIT, \ .gitattributes_done = OIDSET_INIT, \ - .error_func = fsck_error_function, \ + .error_func = fsck_objects_error_function, \ } #define FSCK_OPTIONS_MISSING_GITMODULES { \ .strict = 1, \ @@ -166,7 +166,7 @@ struct fsck_options { .gitmodules_done = OIDSET_INIT, \ .gitattributes_found = OIDSET_INIT, \ .gitattributes_done = OIDSET_INIT, \ - .error_func = fsck_error_cb_print_missing_gitmodules, \ + .error_func = fsck_objects_error_cb_print_missing_gitmodules, \ } /* descend in all linked child objects From patchwork Thu Aug 8 11:26:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13757275 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BDF5149C54 for ; Thu, 8 Aug 2024 11:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116380; cv=none; b=d3ny3siTueWCkA84xKxx7DcZQNt/Kn1GOz4lo2TnLxBJdwUuT4zvI5XN7iSLo9cYJD2yq8BlUMxZ/vWaU6gAR2YlfGTpq34FAM2Oqq1jB2pFUY2Dis5K4+XppgmI95nV+0zzLbfCfM1wJ8VSldK7wnSyUtWhM7OAVfhX4yqFjV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116380; c=relaxed/simple; bh=psYfKpqXB2eXs/L/bxb7clK+XkwFWUX9iKB8cb5S3ys=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eJq4knTyXK2N9y+kXcNP5D4dzjfybEcyn9QuiRFddvW1aP5/WCsZ9Gga3enpWTQcZfLry3nqMs+QJ8R7H4g03wSYzzy3skdGTkZe/nTR4W6zwU1JHYG2P7jdJCU7pVeITOLtGewAJai4L2tgbuBI8MM/jUo+H4caS9SK5QQjbpc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VnYsypFA; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VnYsypFA" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-710d0995e21so136008b3a.1 for ; Thu, 08 Aug 2024 04:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723116378; x=1723721178; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=+Hsel6U7BlzkbmKRjoWdla7eaGn2fX2uALHB6F6GIrE=; b=VnYsypFAuG6x0eaEDELLeMXQdecv58ScGBSEKDlSlQ2UyK8fKsPA8XefdA5GubXfZU sQQuNGuDLNIfmots/hOeU+f+8U500TLi7SHNsLIJBMQiekAsrfNMqqFneLSJTL2OylGF 5Ylkv52MgplW0ezxJk7PTVqfwzvxPhvAC7w/+SitRCKYip+0dfOT8FHHmljQIAEgXCLh KKCosnEUP1N+IFVo9nRsqUXucmW+yUZ/+Wrrr+ljGYwraPHrtMv+sG5T3akuWThNjxls AZGjsYRU50bl+xmvxyWAp2+thgWQiMFxBzKS7TVT24QnK+QN1ygKV8ldumP6QX/N8lbR gyuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723116378; x=1723721178; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+Hsel6U7BlzkbmKRjoWdla7eaGn2fX2uALHB6F6GIrE=; b=ZZ9FYl33luKfHgWvYPjVAvG1N6DB8iMoxmanX+qbRir3K/xNZiPV1z7I5DXcWP//6r Ib2ap1ql8bpKxEFZL42DoMqjW5/Nq/OpojXD2O018wOo3VSqpU+s2v1THXS1l3KM5d3j 6XsgNex0dO4DXefjxJj5sSfJf1FoCjEfj8WjgVJ8r/HPS+lohw6Kw+NBX2HLmLk+WeJL iPk3QyyASHsDnZy7V1LvhhQ09t/itZayTLabF67ZzHYv2AUoLasOpnjtkEc9yjgahgUr VC9au1xwnAI9J2/ZNKmvhMKqroehN/zfXROwaVAhHPt8XUEdb+L+7zJpWxfcSmdH/YYd G2lg== X-Gm-Message-State: AOJu0YxdPOWyLezeO/GRTBj/WFNCeK0RuFvSf0zb/nvDtrpw8EQhLzfX w1rpG/gcLPN7sDUu67cnaYbKx3vKedt3fx3UtmHOzFLrUMYLAxJDV+qZS4W5JBM= X-Google-Smtp-Source: AGHT+IHD1dGUKaOT1dgpYKMuL2Dr73cj6ds4Cj7UC0XM6noih405wjHis4l5BHcaFZ4+mLJNHW4+xA== X-Received: by 2002:a05:6a20:24a5:b0:1c2:5fa8:2de2 with SMTP id adf61e73a8af0-1c6fce7901cmr1332119637.10.1723116377906; Thu, 08 Aug 2024 04:26:17 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d1b3b59ff2sm3196075a91.49.2024.08.08.04.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 04:26:17 -0700 (PDT) Date: Thu, 8 Aug 2024 19:26:47 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v16 3/9] fsck: make "fsck_error" callback generic Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "fsck_error" callback is designed to report the objects-related error messages. It accepts two parameter "oid" and "object_type" which is not generic. In order to provide a unified callback which can report either objects or refs, remove the objects-related parameters and add the generic parameter "void *fsck_report". Create a new "fsck_object_report" structure which incorporates the removed parameters "oid" and "object_type". Then change the corresponding references to adapt to new "fsck_error" callback. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- builtin/fsck.c | 7 +++++-- builtin/mktag.c | 3 +-- fsck.c | 26 ++++++++++++++++---------- fsck.h | 17 ++++++++++++----- object-file.c | 9 ++++----- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 6d86bbe1e9..766bbd014d 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -90,12 +90,15 @@ static int objerror(struct object *obj, const char *err) } static int fsck_objects_error_func(struct fsck_options *o UNUSED, - const struct object_id *oid, - enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id UNUSED, const char *message) { + struct fsck_object_report *report = fsck_report; + const struct object_id *oid = report->oid; + enum object_type object_type = report->object_type; + switch (msg_type) { case FSCK_WARN: /* TRANSLATORS: e.g. warning in tree 01bfda: */ diff --git a/builtin/mktag.c b/builtin/mktag.c index 4767f1a97e..c6b644219f 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -18,8 +18,7 @@ static int option_strict = 1; static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; static int mktag_fsck_error_func(struct fsck_options *o UNUSED, - const struct object_id *oid UNUSED, - enum object_type object_type UNUSED, + void *fsck_report UNUSED, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id UNUSED, const char *message) diff --git a/fsck.c b/fsck.c index 8347842cfb..cca6ae144f 100644 --- a/fsck.c +++ b/fsck.c @@ -232,6 +232,10 @@ static int report(struct fsck_options *options, enum fsck_msg_id msg_id, const char *fmt, ...) { va_list ap; + struct fsck_object_report report = { + .oid = oid, + .object_type = object_type + }; struct strbuf sb = STRBUF_INIT; enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options); int result; @@ -252,7 +256,7 @@ static int report(struct fsck_options *options, va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); - result = options->error_func(options, oid, object_type, + result = options->error_func(options, &report, msg_type, msg_id, sb.buf); strbuf_release(&sb); va_end(ap); @@ -1201,12 +1205,14 @@ int fsck_buffer(const struct object_id *oid, enum object_type type, } int fsck_objects_error_function(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type UNUSED, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id UNUSED, - const char *message) + void *fsck_report, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id UNUSED, + const char *message) { + struct fsck_object_report *report = fsck_report; + const struct object_id *oid = report->oid; + if (msg_type == FSCK_WARN) { warning("object %s: %s", fsck_describe_object(o, oid), message); return 0; @@ -1304,16 +1310,16 @@ int git_fsck_config(const char *var, const char *value, */ int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message) { if (msg_id == FSCK_MSG_GITMODULES_MISSING) { - puts(oid_to_hex(oid)); + struct fsck_object_report *report = fsck_report; + puts(oid_to_hex(report->oid)); return 0; } - return fsck_objects_error_function(o, oid, object_type, + return fsck_objects_error_function(o, fsck_report, msg_type, msg_id, message); } diff --git a/fsck.h b/fsck.h index 41ebebbb59..3b80d02506 100644 --- a/fsck.h +++ b/fsck.h @@ -114,23 +114,30 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type); typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type, void *data, struct fsck_options *options); -/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ +/* + * Callback for reporting errors either for objects or refs. The "fsck_report" + * is a generic pointer that can be used to pass any information. + */ typedef int (*fsck_error)(struct fsck_options *o, - const struct object_id *oid, enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); int fsck_objects_error_function(struct fsck_options *o, - const struct object_id *oid, enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); +struct fsck_object_report { + const struct object_id *oid; + enum object_type object_type; +}; + struct fsck_options { fsck_walk_func walk; fsck_error error_func; diff --git a/object-file.c b/object-file.c index 065103be3e..05ac6ebed6 100644 --- a/object-file.c +++ b/object-file.c @@ -2470,11 +2470,10 @@ int repo_has_object_file(struct repository *r, * give more context. */ static int hash_format_check_report(struct fsck_options *opts UNUSED, - const struct object_id *oid UNUSED, - enum object_type object_type UNUSED, - enum fsck_msg_type msg_type UNUSED, - enum fsck_msg_id msg_id UNUSED, - const char *message) + void *fsck_report UNUSED, + enum fsck_msg_type msg_type UNUSED, + enum fsck_msg_id msg_id UNUSED, + const char *message) { error(_("object fails fsck: %s"), message); return 1; From patchwork Thu Aug 8 11:26:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13757276 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52DA313D265 for ; Thu, 8 Aug 2024 11:26:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116390; cv=none; b=GHIQBqVwhmsen2XXCzyqqHOqucI1xoOtVzL0K2RuXuOcn+4O0OikLGt3L9OPVhGfYaLbuLIZyBcG942LS3YxKjDrG8pdxVSl+SJ/fk8NEQqKhbcEfC6yuT64OVuP+TXep04feixGLS4Ei+WY36m8goxUjqLusdI14FtDRiF3yFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116390; c=relaxed/simple; bh=Wj1rtaGLFY/l7brZFBPulOWSUmwOZ/2ft0Qhe8YUxVU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O7PdCGTvlkqK997SsKwBSmdDRHxT40RATLpExJ58LWFphKNShVWIIAcUyrdAHZbPAa3dUgDiuWlKbr5nvVmDhwR2anf0H6ADBBAuDwA7GM0K6+dswjiSKD8aVs+QkdnW4fcIHAjTqpULjNP4lTm671TgmZjfX5O9GXr/I+bzgr8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kAt2LV7j; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kAt2LV7j" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-6e7e23b42c3so683922a12.1 for ; Thu, 08 Aug 2024 04:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723116388; x=1723721188; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=YkZZIEVS0Fg9cfbQCgODvVKx1GInni4ZjRoAnjEwfsM=; b=kAt2LV7jYqRZBTFaM8mKXGfMWyCRZiedIMs0Xqho2ZrKqDM9W1spgnc0UQiv3aj0eL CbbxaMExfHQ4NEBMxADbsXLwM/AeWI014c/19bcM4g64j6UKS8wLF48hg3DXpf50A0s0 NtfTZ4gY0udAFNuXc6Rn+IjLKEebixG0PBK54md/Ugl0jpeOuY8DkhdAwub5esqvl/d9 JCNi6bdCN0JHuIU7RXkYhMZl+izd+B8/ggLEB5ZMqqYhFUbbLQGXHHB1pDBAuvRkAboG xu/Qa4l7ECo7Y0Q7A2OSkUbImJCFrgAWoKDtt9bkaq2AcGgxM48HxKJGWy5e+/BXZxxs 4/5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723116388; x=1723721188; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YkZZIEVS0Fg9cfbQCgODvVKx1GInni4ZjRoAnjEwfsM=; b=dkHekj8IW7HV5TKZlPkXfe/aJDtPrtVYaCR3t9rGo+fX00ikJuU2kbJMYiLGdB87/G wJT8259xs4t0odr6WzJaS/0QD2JJFmpl7WNiHQzbBpdNVJFbRGmHg0pJyObo0sMV4sYU 5RYwT5H+Ziw68TtoQ2i/q4DIDffTT6NcY2k5dRA/Wzj9GWAHYzKRFW6k+yFF0ISu++P9 OaeYTxYqa+/rF5z5KVnEv7ovDxHc+akjVJsGe8yUdLawngBxN28sUjxarURRYX8j+kw9 PLCylKnD3AUpBeqQU4oMOKJRcWw16tdkw8qsgVEraXxHHn9zljRkSWuPHk+6U8pcdYnx HadA== X-Gm-Message-State: AOJu0YzSZKS91OheRyeuP3oTALxlbM9mJSkBRiLWWsd0YOPppECjn5VI sLKcVrjqE56sCii0V5LXX0oIZ+l8zCHgQgO9QtHO/n3x+GGvEKIjTrmNVWpmE7A= X-Google-Smtp-Source: AGHT+IHSoO/KkZ27UMHEwX+i6E+uEr437RIpUgr189+wVnufohXVMFnmhcrGMCW+dTOsPBqaow+vEQ== X-Received: by 2002:a17:903:22cf:b0:1fc:3dad:25ed with SMTP id d9443c01a7336-20095224ba3mr20288755ad.9.1723116388141; Thu, 08 Aug 2024 04:26:28 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2007d1184d9sm43612915ad.216.2024.08.08.04.26.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 04:26:27 -0700 (PDT) Date: Thu, 8 Aug 2024 19:26:57 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v16 4/9] fsck: add a unified interface for reporting fsck messages Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The static function "report" provided by "fsck.c" aims at checking error type and calling the callback "error_func" to report the message. Both refs and objects need to check the error type of the current fsck message. In order to extract this common behavior, create a new function "fsck_vreport". Instead of using "...", provide "va_list" to allow more flexibility. Instead of changing "report" prototype to be align with the "fsck_vreport" function, we leave the "report" prototype unchanged due to the reason that there are nearly 62 references about "report" function. Simply change "report" function to use "fsck_vreport" to report objects related messages. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/fsck.c b/fsck.c index cca6ae144f..3614aa56a3 100644 --- a/fsck.c +++ b/fsck.c @@ -226,16 +226,15 @@ static int object_on_skiplist(struct fsck_options *opts, return opts && oid && oidset_contains(&opts->skip_oids, oid); } -__attribute__((format (printf, 5, 6))) -static int report(struct fsck_options *options, - const struct object_id *oid, enum object_type object_type, - enum fsck_msg_id msg_id, const char *fmt, ...) +/* + * Provide the common functionality for either fscking refs or objects. + * It will get the current msg error type and call the error_func callback + * which is registered in the "fsck_options" struct. + */ +static int fsck_vreport(struct fsck_options *options, + void *fsck_report, + enum fsck_msg_id msg_id, const char *fmt, va_list ap) { - va_list ap; - struct fsck_object_report report = { - .oid = oid, - .object_type = object_type - }; struct strbuf sb = STRBUF_INIT; enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options); int result; @@ -243,9 +242,6 @@ static int report(struct fsck_options *options, if (msg_type == FSCK_IGNORE) return 0; - if (object_on_skiplist(options, oid)) - return 0; - if (msg_type == FSCK_FATAL) msg_type = FSCK_ERROR; else if (msg_type == FSCK_INFO) @@ -254,11 +250,31 @@ static int report(struct fsck_options *options, prepare_msg_ids(); strbuf_addf(&sb, "%s: ", msg_id_info[msg_id].camelcased); - va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); - result = options->error_func(options, &report, + result = options->error_func(options, fsck_report, msg_type, msg_id, sb.buf); strbuf_release(&sb); + + return result; +} + +__attribute__((format (printf, 5, 6))) +static int report(struct fsck_options *options, + const struct object_id *oid, enum object_type object_type, + enum fsck_msg_id msg_id, const char *fmt, ...) +{ + va_list ap; + struct fsck_object_report report = { + .oid = oid, + .object_type = object_type + }; + int result; + + if (object_on_skiplist(options, oid)) + return 0; + + va_start(ap, fmt); + result = fsck_vreport(options, &report, msg_id, fmt, ap); va_end(ap); return result; From patchwork Thu Aug 8 11:27:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13757277 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B5CE1891AC for ; Thu, 8 Aug 2024 11:26:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116401; cv=none; b=l2tk3TdpToSpsCfEKmE9duifrQ9t+2W/R3xHak7Gjs1bh3/t6+jcaBtwo0SNMjD9ruWsbj24oidyIed6EBJ1y66snxPnAmGuwzhGgG1tca5pDPnejboP0RFG7zpLtCF+Vgz0i7LSqnpDO4MqfQyZrZbZi4/9MV0Yyd5SemIwvO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116401; c=relaxed/simple; bh=Ie40YCl5ccqbp8gITfQbtAEaPujh7QDuHN+DU5lRB0c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sG7ywVKooWBQx3pb4J4hunteMwpE+mqJlvRVfGtUQ96nahSXRDqHCHao5CYmeyrqu3REnsSMDvsuYBG//BZBJekYxmVb+o4cNTl5Ke9saJNv6OHrOAdcRyXYzXn0XBbkxWd9hvGI5tbYet253FR2f0W10i2LS5rhVpGtz/yRq08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RZBYzCx2; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RZBYzCx2" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70d316f0060so1325001b3a.1 for ; Thu, 08 Aug 2024 04:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723116399; x=1723721199; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=oWB02mc2bGG7zgCHT2ZdCXTLKrOB9IdCm8/oCLM85dE=; b=RZBYzCx21Ga93swA9+31tjcCJgH3XkHQA8gzuQto3wIke4fNbmDPWoGniIQTcKo/vp pN8d4O9uvwLeSqS8/2UaUmovG/QfYmq3jTr0EA+SH6H51C9QrWK7kdGRh6PJEoXdozz+ q9g1y3Lr9UH2UJ/1yvyKs+TftX0/AMvbYiSZryJLijJz9NcM+N9l33YOyf+UtLF+SgH6 v05XYKrpJ7rFU7dkYBRb1Fx0mbcR3LIqu+xD8W9LmkbGupjxFO6C3DcCFprXlabPtQPZ eWL4SEp+C0qa4oGhTPB2pdI7S5U2TCAbOx2mByh+zrHCJHOsyqg71BypNGuTLJZa90Ut 8Z1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723116399; x=1723721199; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=oWB02mc2bGG7zgCHT2ZdCXTLKrOB9IdCm8/oCLM85dE=; b=hJF1t+4SnC8Tz5kZMKr9u2aoc+I4iJkXT0E+fkSfvVZwiHsXWAX7bw+75+hLuKYuxj 8YhkFsPiZkYNmxrqj0734ygWKegPsqAGQ1zBWICmJ4B53ZNKqhFkaLadaqJulF/0FnmV Ig0LOexsCQZU6oq94IeIfwBvTf5lR/aNUA5vU4YqhkXsItXAR56vrYv9AAzJFb7DAQDF Z13B4rj9L6+GTRAs+UKlxkMkYttTAq86Srdz0rUk8p0prHKZqiRofY5zWICDVB37eB2g vwOoYN5AkK0l4oRMwu7Rf1ud/RyD9MIJAVcbz0JruAVvlrFYwkzP0AbAgoHVw9rzlAKI KGtw== X-Gm-Message-State: AOJu0YwCdW+4yHhPIui+vXCTBuCSHPdi4TL5Ynluck4SLJYS27LOViNv 0H3OvZkRDV0C0TYasUP/QELIJ7A0b66NWJr8n/0+Xe1IDw3zEGk7MxxW9JAzO3k= X-Google-Smtp-Source: AGHT+IEL4MGZKhu0z65UrYY44hh4gW+GNfdpwv20vThUW0CDctdonIEKl4YOsQuAM2so8NGRHLSmRw== X-Received: by 2002:a05:6a00:244d:b0:70e:98e2:c76e with SMTP id d2e1a72fcca58-710cc811feamr2393938b3a.6.1723116398693; Thu, 08 Aug 2024 04:26:38 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb2d090esm955932b3a.102.2024.08.08.04.26.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 04:26:38 -0700 (PDT) Date: Thu, 8 Aug 2024 19:27:08 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v16 5/9] fsck: add refs report function Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Introduce a new struct "fsck_ref_report" to contain the information we need when reporting refs-related messages. With the new "fsck_vreport" function, add a new function "fsck_report_ref" to report refs-related fsck error message. Unlike "report" function uses the exact parameters, we simply pass "struct fsck_ref_report *report" as the parameter. This is because at current we don't know exactly how many fields we need. By passing this parameter, we don't need to change this function prototype when we want to add more information into "fsck_ref_report". We have introduced "fsck_report_ref" function to report the error message for refs. We still need to add the corresponding callback function. Create refs-specific "error_func" callback "fsck_refs_error_function". Last, add "FSCK_REFS_OPTIONS_DEFAULT" macro to create default options when checking ref consistency. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 39 +++++++++++++++++++++++++++++++++++++++ fsck.h | 25 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/fsck.c b/fsck.c index 3614aa56a3..e16c892f6a 100644 --- a/fsck.c +++ b/fsck.c @@ -280,6 +280,19 @@ static int report(struct fsck_options *options, return result; } +int fsck_report_ref(struct fsck_options *options, + struct fsck_ref_report *report, + enum fsck_msg_id msg_id, + const char *fmt, ...) +{ + va_list ap; + int result; + va_start(ap, fmt); + result = fsck_vreport(options, report, msg_id, fmt, ap); + va_end(ap); + return result; +} + void fsck_enable_object_names(struct fsck_options *options) { if (!options->object_names) @@ -1237,6 +1250,32 @@ int fsck_objects_error_function(struct fsck_options *o, return 1; } +int fsck_refs_error_function(struct fsck_options *options UNUSED, + void *fsck_report, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id UNUSED, + const char *message) +{ + struct fsck_ref_report *report = fsck_report; + struct strbuf sb = STRBUF_INIT; + int ret = 0; + + strbuf_addstr(&sb, report->path); + + if (report->oid) + strbuf_addf(&sb, " -> (%s)", oid_to_hex(report->oid)); + else if (report->referent) + strbuf_addf(&sb, " -> (%s)", report->referent); + + if (msg_type == FSCK_WARN) + warning("%s: %s", sb.buf, message); + else + ret = error("%s: %s", sb.buf, message); + + strbuf_release(&sb); + return ret; +} + static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done, enum fsck_msg_id msg_missing, enum fsck_msg_id msg_type, struct fsck_options *options, const char *blob_type) diff --git a/fsck.h b/fsck.h index 3b80d02506..2002590f60 100644 --- a/fsck.h +++ b/fsck.h @@ -133,11 +133,23 @@ int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, enum fsck_msg_id msg_id, const char *message); +int fsck_refs_error_function(struct fsck_options *options, + void *fsck_report, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message); + struct fsck_object_report { const struct object_id *oid; enum object_type object_type; }; +struct fsck_ref_report { + const char *path; + const struct object_id *oid; + const char *referent; +}; + struct fsck_options { fsck_walk_func walk; fsck_error error_func; @@ -175,6 +187,9 @@ struct fsck_options { .gitattributes_done = OIDSET_INIT, \ .error_func = fsck_objects_error_cb_print_missing_gitmodules, \ } +#define FSCK_REFS_OPTIONS_DEFAULT { \ + .error_func = fsck_refs_error_function, \ +} /* descend in all linked child objects * the return value is: @@ -216,6 +231,16 @@ int fsck_tag_standalone(const struct object_id *oid, const char *buffer, */ int fsck_finish(struct fsck_options *options); +/* + * Report an error or warning for refs. + */ +__attribute__((format (printf, 4, 5))) +int fsck_report_ref(struct fsck_options *options, + struct fsck_ref_report *report, + enum fsck_msg_id msg_id, + const char *fmt, ...); + + /* * Subsystem for storing human-readable names for each object. * From patchwork Thu Aug 8 11:27:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13757278 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 569DA13D265 for ; Thu, 8 Aug 2024 11:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116410; cv=none; b=kef/umRgFTd8nEH428Ahw14X7oOFe/43mMrZ7ebvr1c5RP8qzHUkr9hJVO7Zm+/4hGBWw6zxIJOG9LVh6YLXSCDp4rYGtpPuVA1v3k5AxedqmecfRGmVaZ/XzMKGN1WBa0kKM2G9+beoVjO+fvU0VPjVXTW66R03yvSA7A7grcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116410; c=relaxed/simple; bh=d0U+zfe5Q3f7g3/LK0qr2DuDHFPH6/t3E6P5vC5/Uks=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tsYIIvUsct8TepUQupF6n0XMaWXiikZDTSWwEMsJDYIO9iPYX9GcjLLly3Xlotwh256Bh1G61WlWNGNN6e+RxPCmBVdz+7taf9PRaBQVDJM0hMe7kMNyzFckYAjjH18MTn2Cljl1Y8DgAP2FCuKKTgbcT+Q8ZqesaE52i5+wPDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FKm66L9q; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FKm66L9q" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1fc4fcbb131so6640325ad.3 for ; Thu, 08 Aug 2024 04:26:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723116408; x=1723721208; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=gXSYuUIlc1sLEM0xmW8Sg4+1Dl1cviP9OhmRc0x8Q40=; b=FKm66L9qiR9WwEOCLMA6cC9b2o0TnWMg4Ld0f3FNvQOJqRFyfIiMK0pkSgKZeIhwXH r6bfQS+/USFadQRg8afbgBvuxp5dScHTdyU41+Cv55Y7OCF5MrhAf0HBDojr7X951iuP ci/d+fi0+ghC0CwQNpO31YTUdLnALCSkM+ulB45P8BgIw9P8NKyZnicy6boa37pIuQMM u5dx5+7/La4oVdEEDVD+I7mtaaNp71PSdqkxuOP2O7lK0KS2TFjnfwXHJkZtnak588iz skn+t1CC4oD/cLQ1q2CNvRQtPmI1behr28S1L+CfUI8s29s3r+GGsyaLPHkCh/cVj9OK kS9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723116408; x=1723721208; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gXSYuUIlc1sLEM0xmW8Sg4+1Dl1cviP9OhmRc0x8Q40=; b=qHTtjEDVezCy4U4cITsjGdp9XB7zjwYMJZGzuZFOq7MXMR/whfhpF26LMRRPu3HwWO f9ajRrKZ0bOmdBnUOdxQ5ofdJ4GY0QuiQyhLrmuGaWJ8b9EzXOh6mPvk8wYI0PNGdOT3 0djH36/aneLUbqKXBdrFvNeDAkfy//t67FikTnH1UrNmvVQvv0+YNGErgvBgfC/af/75 Irjh35uMhOjTFYexnftP1h8czApg36HbSdiAFFrF1VdSFjbeBBITcBo36AmdguKPCyc+ piCS3/tQ7Pi7ALsEw1UdrhqFWVRaknr5rxGhio5P3mzCE+psfrbRzfvYuH6TVN6ETx4r F4eA== X-Gm-Message-State: AOJu0YyAFm4QJ59udHtPsg7L2NVhYEBQTSrRsygBQITsUdGAiFnUHjNW OgjuLbyjbAwfQk2SEzArgrpOaXfwLvtlfQ2wrVEVZ5vXTeTBMcJLEL9PFd2uKpw= X-Google-Smtp-Source: AGHT+IHhortMSyNNQo4HOq0cL/ejTZgD0SRAHvIWLNKVH6uWf7hHdQgqxrrH689CRR0DEupLIuN84g== X-Received: by 2002:a17:903:120b:b0:1fc:3daa:52 with SMTP id d9443c01a7336-20095224ad2mr23045425ad.11.1723116408145; Thu, 08 Aug 2024 04:26:48 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff592b54bdsm121996675ad.293.2024.08.08.04.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 04:26:47 -0700 (PDT) Date: Thu, 8 Aug 2024 19:27:17 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v16 6/9] refs: set up ref consistency check infrastructure Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "struct ref_store" is the base class which contains the "be" pointer which provides backend-specific functions whose interfaces are defined in the "ref_storage_be". We could reuse this polymorphism to define only one interface. For every backend, we need to provide its own function pointer. The interfaces defined in the `ref_storage_be` are carefully structured in semantic. It's organized as the five parts: 1. The name and the initialization interfaces. 2. The ref transaction interfaces. 3. The ref internal interfaces (pack, rename and copy). 4. The ref filesystem interfaces. 5. The reflog related interfaces. To keep consistent with the git-fsck(1), add a new interface named "fsck_refs_fn" to the end of "ref_storage_be". This semantic cannot be grouped into any above five categories. Explicitly add blank line to make it different from others. Last, implement placeholder functions for each ref backends. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- refs.c | 5 +++++ refs.h | 8 ++++++++ refs/debug.c | 11 +++++++++++ refs/files-backend.c | 13 ++++++++++++- refs/packed-backend.c | 8 ++++++++ refs/refs-internal.h | 6 ++++++ refs/reftable-backend.c | 8 ++++++++ 7 files changed, 58 insertions(+), 1 deletion(-) diff --git a/refs.c b/refs.c index 915aeb4d1d..6f642dc681 100644 --- a/refs.c +++ b/refs.c @@ -318,6 +318,11 @@ int check_refname_format(const char *refname, int flags) return check_or_sanitize_refname(refname, flags, NULL); } +int refs_fsck(struct ref_store *refs, struct fsck_options *o) +{ + return refs->be->fsck(refs, o); +} + void sanitize_refname_component(const char *refname, struct strbuf *out) { if (check_or_sanitize_refname(refname, REFNAME_ALLOW_ONELEVEL, out)) diff --git a/refs.h b/refs.h index b3e39bc257..405073621a 100644 --- a/refs.h +++ b/refs.h @@ -4,6 +4,7 @@ #include "commit.h" #include "repository.h" +struct fsck_options; struct object_id; struct ref_store; struct strbuf; @@ -541,6 +542,13 @@ int refs_for_each_reflog(struct ref_store *refs, each_reflog_fn fn, void *cb_dat */ int check_refname_format(const char *refname, int flags); +/* + * Check the reference database for consistency. Return 0 if refs and + * reflogs are consistent, and non-zero otherwise. The errors will be + * written to stderr. + */ +int refs_fsck(struct ref_store *refs, struct fsck_options *o); + /* * Apply the rules from check_refname_format, but mutate the result until it * is acceptable, and place the result in "out". diff --git a/refs/debug.c b/refs/debug.c index 547d9245b9..45e2e784a0 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -419,6 +419,15 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname, return res; } +static int debug_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store; + int res = drefs->refs->be->fsck(drefs->refs, o); + trace_printf_key(&trace_refs, "fsck: %d\n", res); + return res; +} + struct ref_storage_be refs_be_debug = { .name = "debug", .init = NULL, @@ -451,4 +460,6 @@ struct ref_storage_be refs_be_debug = { .create_reflog = debug_create_reflog, .delete_reflog = debug_delete_reflog, .reflog_expire = debug_reflog_expire, + + .fsck = debug_fsck, }; diff --git a/refs/files-backend.c b/refs/files-backend.c index aa52d9be7c..4630eb1f80 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3408,6 +3408,15 @@ static int files_ref_store_remove_on_disk(struct ref_store *ref_store, return ret; } +static int files_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + struct files_ref_store *refs = + files_downcast(ref_store, REF_STORE_READ, "fsck"); + + return refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); +} + struct ref_storage_be refs_be_files = { .name = "files", .init = files_ref_store_init, @@ -3434,5 +3443,7 @@ struct ref_storage_be refs_be_files = { .reflog_exists = files_reflog_exists, .create_reflog = files_create_reflog, .delete_reflog = files_delete_reflog, - .reflog_expire = files_reflog_expire + .reflog_expire = files_reflog_expire, + + .fsck = files_fsck, }; diff --git a/refs/packed-backend.c b/refs/packed-backend.c index a0666407cd..5209b0b212 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1735,6 +1735,12 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s return empty_ref_iterator_begin(); } +static int packed_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + return 0; +} + struct ref_storage_be refs_be_packed = { .name = "packed", .init = packed_ref_store_init, @@ -1762,4 +1768,6 @@ struct ref_storage_be refs_be_packed = { .create_reflog = NULL, .delete_reflog = NULL, .reflog_expire = NULL, + + .fsck = packed_fsck, }; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index fa975d69aa..a905e187cd 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -4,6 +4,7 @@ #include "refs.h" #include "iterator.h" +struct fsck_options; struct ref_transaction; /* @@ -650,6 +651,9 @@ typedef int read_raw_ref_fn(struct ref_store *ref_store, const char *refname, typedef int read_symbolic_ref_fn(struct ref_store *ref_store, const char *refname, struct strbuf *referent); +typedef int fsck_fn(struct ref_store *ref_store, + struct fsck_options *o); + struct ref_storage_be { const char *name; ref_store_init_fn *init; @@ -677,6 +681,8 @@ struct ref_storage_be { create_reflog_fn *create_reflog; delete_reflog_fn *delete_reflog; reflog_expire_fn *reflog_expire; + + fsck_fn *fsck; }; extern struct ref_storage_be refs_be_files; diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index fbe74c239d..b5a1a526df 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -2303,6 +2303,12 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store, return ret; } +static int reftable_be_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + return 0; +} + struct ref_storage_be refs_be_reftable = { .name = "reftable", .init = reftable_be_init, @@ -2330,4 +2336,6 @@ struct ref_storage_be refs_be_reftable = { .create_reflog = reftable_be_create_reflog, .delete_reflog = reftable_be_delete_reflog, .reflog_expire = reftable_be_reflog_expire, + + .fsck = reftable_be_fsck, }; From patchwork Thu Aug 8 11:27:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13757279 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 535C913D265 for ; Thu, 8 Aug 2024 11:27:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116421; cv=none; b=NCVFfftU6burzoDcnx9JGVgqzo3uB6+Lzp/7NvlfAdea7AYAaqflC29ICmtMt+U9S49pepG8OX0CseDzaVZtWWQQgLQnkID9pyzEw3pXaHZpJazJBsYftsEYurMXEJpJ1Lp5gnAzuhFlS4L9MmmyBFd1u/nvuwLZQBnS8NJgtxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116421; c=relaxed/simple; bh=N9xRKpjrHbB9tsaEzajlwDt3WHbvwnJxrPemJ5BljeQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oxjWG7YHJOerctlffm1v5gZxDQuZymAVIar0njV62rwtujMmw79F2hOlHBNh9wG8+hg4eppze8eEQW4ny177lQcjT48b4vxBHCCnDTk1FdclRoFqYWl/+NtHLhdmMv5e0SHr28BVfPamzFFy7KM+oJ/p5I/PjecBoRWxmcagMrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m1O0QM50; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m1O0QM50" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-6c5bcb8e8edso634027a12.2 for ; Thu, 08 Aug 2024 04:27:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723116419; x=1723721219; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=U94p9qk0likNuFXerMrbcXs96yvdKsqw/CM63bN9Kr8=; b=m1O0QM50e9uWfn00EMOToB0Jk2Fzu2qrA1NfcYx2IwZZ4bgAZS802cojigyMi6k2in TuKuaCnTxbrneAYGqy0R2+ZEpEHY8Kfi8JpdZDUKNxiKZHwW2+djR2Y7uH2U+shcJ7ub fDOUWs+Kc28jyAL8I1XQAgDmbxLCLy32yBwUexvwuCoaFguiOfsA6NFA3kVCH+sGGoE2 7HZ291qNAxWXZavZUdt9/XYoCUCIdwKuQFwKhkIJcTzeMifFUokzw6zQUEq6wid5dqQE x1mGAzOsuoGw90u2CVI7V7IE3Ih2Rp1bcFUvuwVniEpYzfTN9zmOkhAaXukCCObQv8IC ksUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723116419; x=1723721219; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=U94p9qk0likNuFXerMrbcXs96yvdKsqw/CM63bN9Kr8=; b=R0/ktq47xzxRAl6mzxbz/e5X0d3SqR7+oUdZ08s6HKTYqBDm5SRODqbkagP654q4nz 9xjyeobFwHbOh2tWye7Ajn5rc2dBM0anOEzuXyo/KJUJgQEF5wqp6/AgSk4Xy7sV4ts6 9Nip00NG4WStISa0CHYLk3lOJOx6ERowbQXtTATqcCE++KCNibzhektMlXhA2lKXveEj dA+l/a3XO7ZH7f4adArmoC3OcBym7N39AuisGXihHaAwzmLARzst/lz6h1onnAlnKIlF APpKjLO39/bl93HuWNhggLzcnh5Is+rte0JeVVaexgNkJUMhO8rByVevHoQiz+xP5YT+ RBlw== X-Gm-Message-State: AOJu0YyS4z2oYXn39RAmeDkaK0yfK2Uuh7iQ7LTlPOg6dBqj0rrhwTlT fVoz3KE9jLmRx9V/46rM6VDGe55T697eQYURpUhBYHqGtXSdOe8rQqhHcoATaGA= X-Google-Smtp-Source: AGHT+IFc7oUcpDLEA+bAYYruCb4Ow7V5Us47uZzYXkfw/PAzGRqNNu+4Ys19dmliVeh0bazPuT/66Q== X-Received: by 2002:a05:6a21:6d91:b0:1c4:8291:e94e with SMTP id adf61e73a8af0-1c6fcf8515cmr1834322637.45.1723116418990; Thu, 08 Aug 2024 04:26:58 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59060112sm122186375ad.137.2024.08.08.04.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 04:26:58 -0700 (PDT) Date: Thu, 8 Aug 2024 19:27:28 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v16 7/9] builtin/refs: add verify subcommand Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Introduce a new subcommand "verify" in git-refs(1) to allow the user to check the reference database consistency and also this subcommand will be used as the entry point of checking refs for "git-fsck(1)". Add "verbose" field into "fsck_options" to indicate whether we should print verbose messages when checking refs and objects consistency. Remove bit-field for "strict" field, this is because we cannot take address of a bit-field which makes it unhandy to set member variables when parsing the command line options. The "git-fsck(1)" declares "fsck_options" variable with "static" identifier which avoids complaint by the leak-checker. However, in "git-refs verify", we need to do memory clean manually. Thus add "fsck_options_clear" function in "fsck.c" to provide memory clean operation. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/git-refs.txt | 13 +++++++++++++ builtin/refs.c | 34 ++++++++++++++++++++++++++++++++++ fsck.c | 11 +++++++++++ fsck.h | 8 +++++++- 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Documentation/git-refs.txt b/Documentation/git-refs.txt index 5b99e04385..ce31f93061 100644 --- a/Documentation/git-refs.txt +++ b/Documentation/git-refs.txt @@ -10,6 +10,7 @@ SYNOPSIS -------- [verse] 'git refs migrate' --ref-format= [--dry-run] +'git refs verify' [--strict] [--verbose] DESCRIPTION ----------- @@ -22,6 +23,9 @@ COMMANDS migrate:: Migrate ref store between different formats. +verify:: + Verify reference database consistency. + OPTIONS ------- @@ -39,6 +43,15 @@ include::ref-storage-format.txt[] can be used to double check that the migration works as expected before performing the actual migration. +The following options are specific to 'git refs verify': + +--strict:: + Enable stricter error checking. This will cause warnings to be + reported as errors. See linkgit:git-fsck[1]. + +--verbose:: + When verifying the reference database consistency, be chatty. + KNOWN LIMITATIONS ----------------- diff --git a/builtin/refs.c b/builtin/refs.c index 46dcd150d4..131f98be98 100644 --- a/builtin/refs.c +++ b/builtin/refs.c @@ -1,4 +1,6 @@ #include "builtin.h" +#include "config.h" +#include "fsck.h" #include "parse-options.h" #include "refs.h" #include "repository.h" @@ -7,6 +9,9 @@ #define REFS_MIGRATE_USAGE \ N_("git refs migrate --ref-format= [--dry-run]") +#define REFS_VERIFY_USAGE \ + N_("git refs verify [--strict] [--verbose]") + static int cmd_refs_migrate(int argc, const char **argv, const char *prefix) { const char * const migrate_usage[] = { @@ -58,15 +63,44 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix) return err; } +static int cmd_refs_verify(int argc, const char **argv, const char *prefix) +{ + struct fsck_options fsck_refs_options = FSCK_REFS_OPTIONS_DEFAULT; + const char * const verify_usage[] = { + REFS_VERIFY_USAGE, + NULL, + }; + struct option options[] = { + OPT_BOOL(0, "verbose", &fsck_refs_options.verbose, N_("be verbose")), + OPT_BOOL(0, "strict", &fsck_refs_options.strict, N_("enable strict checking")), + OPT_END(), + }; + int ret; + + argc = parse_options(argc, argv, prefix, options, verify_usage, 0); + if (argc) + usage(_("'git refs verify' takes no arguments")); + + git_config(git_fsck_config, &fsck_refs_options); + prepare_repo_settings(the_repository); + + ret = refs_fsck(get_main_ref_store(the_repository), &fsck_refs_options); + + fsck_options_clear(&fsck_refs_options); + return ret; +} + int cmd_refs(int argc, const char **argv, const char *prefix) { const char * const refs_usage[] = { REFS_MIGRATE_USAGE, + REFS_VERIFY_USAGE, NULL, }; parse_opt_subcommand_fn *fn = NULL; struct option opts[] = { OPT_SUBCOMMAND("migrate", &fn, cmd_refs_migrate), + OPT_SUBCOMMAND("verify", &fn, cmd_refs_verify), OPT_END(), }; diff --git a/fsck.c b/fsck.c index e16c892f6a..3756f52459 100644 --- a/fsck.c +++ b/fsck.c @@ -1331,6 +1331,17 @@ int fsck_finish(struct fsck_options *options) return ret; } +void fsck_options_clear(struct fsck_options *options) +{ + free(options->msg_type); + oidset_clear(&options->skip_oids); + oidset_clear(&options->gitmodules_found); + oidset_clear(&options->gitmodules_done); + oidset_clear(&options->gitattributes_found); + oidset_clear(&options->gitattributes_done); + kh_clear_oid_map(options->object_names); +} + int git_fsck_config(const char *var, const char *value, const struct config_context *ctx, void *cb) { diff --git a/fsck.h b/fsck.h index 2002590f60..d551a9fe86 100644 --- a/fsck.h +++ b/fsck.h @@ -153,7 +153,8 @@ struct fsck_ref_report { struct fsck_options { fsck_walk_func walk; fsck_error error_func; - unsigned strict:1; + unsigned strict; + unsigned verbose; enum fsck_msg_type *msg_type; struct oidset skip_oids; struct oidset gitmodules_found; @@ -231,6 +232,11 @@ int fsck_tag_standalone(const struct object_id *oid, const char *buffer, */ int fsck_finish(struct fsck_options *options); +/* + * Clear the fsck_options struct, freeing any allocated memory. + */ +void fsck_options_clear(struct fsck_options *options); + /* * Report an error or warning for refs. */ From patchwork Thu Aug 8 11:31:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13757283 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1799D18D651 for ; Thu, 8 Aug 2024 11:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116664; cv=none; b=GYwXARq5mTWyaPJGMDWcUh10g7hb6hGT2GEIKnWLX6EvEmXkqVXvwsRQRJJmwe3N2CZkJpgSWLVWjm49jhUvPGKzIi3nkUQI1OWi4qneQhHtxqI7XcKB/MDASBhGdTe2PtjDX3FjgXw2l3EwxVxeUq5IwhQ6+fwbqePQrM4O7Mk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116664; c=relaxed/simple; bh=L5WKcyQYBehw7x/KDP8984hDmycKh7np7STXOvudpSU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nlNxKBU94/q8Dfwsp8F04de+NIOaVe8DtMVtZFc2OHznYblITNtCto6NzPw+BVl+CcOV0pxZrz4/D4nQmn4PZDgSUcf4chc01h4fbl1d1agS9cFuDjIY9qV8UlmeAx5g9/01chchjHQFxqCupc4qFeUvSZyjdUEEvImE1xK0GtM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HxENq1d1; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HxENq1d1" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1fc5296e214so8948435ad.0 for ; Thu, 08 Aug 2024 04:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723116662; x=1723721462; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OilDfyeBDokH26Ok/xTnZCoz9iA942Q7BuRSTwjR2Gs=; b=HxENq1d1/mn0xD3R4BrUOsn10Lke/qYWrGfl0wfmlt9IYm9/n499FO81rGTfaZr2Bi ObbOS9OKRK84iFt8uHS6F/d6CXa8+TAZZ1Ru/CgopPrR9LVsPiBfrvxd8vFJEBgn4fUU ddHfMzN1GqRbUoIQccBy/6cYZpZrmdvQE2tP+ZImZweCojzEARS4vJbiJLp3UnHHsAOk /wjmV0XhYzLTe0TjdMgBUpYGK3jZQa3GOEzlvGdJwL5rkR+ysCiLvfXQiMSUizbQo8Lu RbcE/HFVW/K+RAq7ST0DiIUSukmRdQSrHHzZGCfIl9YQ9nl8m5/cCpxntzG3+T5Y46LS E4yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723116662; x=1723721462; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OilDfyeBDokH26Ok/xTnZCoz9iA942Q7BuRSTwjR2Gs=; b=eVMq4VORLkm+LcrYsTxlt46qpCPx+T3D24rL+LaAh9/l9hOUFg7AXc18kov/UK59PF L5kcDqdsWLImjCUZoRTRNGh9/bcqxHfuzJR6P6H8DLG/sn+V8lm9DBBAyZ/BfG5pknI9 KsdFmWrdAGZLNZ0edUPqGVYdPyVJanq13flMy9EUc5gvb96dOakmpvYbFm1n96Wo8ztj +/J2imXOI1c9R8K0TkggeDqdHXm0lWBiouMuwzaVbc4mFoKKR/N+2pbf7V+gYHedC40I ImC0y0y//pQurNB+doa1Cvzvqf8X5w0V3WhzWygSv15XkRfpLH/4BnXrzA6hGB3+W7nt ring== X-Gm-Message-State: AOJu0Yy6BX/CsqwSyGbYktX+GZUV6zHJ+bjAWIBB2/ZTZRXQd8DHgIKL kIUkp+0/jsQ3BgZrthgpnVs534bdMiFTP/UPgWOxe1HvJGnV1a+KhkMbEuN7A/Y= X-Google-Smtp-Source: AGHT+IFkqAGy6vArrLWCP52cEw/nSl0dO5vTw+/AZc1XvoPC8D8M4cZ/PyUJXS0CMMFK3TGI33LP7g== X-Received: by 2002:a17:902:e743:b0:1fc:58fc:caf7 with SMTP id d9443c01a7336-200952495fbmr18892735ad.14.1723116661781; Thu, 08 Aug 2024 04:31:01 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff592ac89fsm122245215ad.276.2024.08.08.04.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 04:31:01 -0700 (PDT) Date: Thu, 8 Aug 2024 19:31:31 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v16 8/9] files-backend: add unified interface for refs scanning Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: For refs and reflogs, we need to scan its corresponding directories to check every regular file or symbolic link which shares the same pattern. Introduce a unified interface for scanning directories for files-backend. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/fsck-msgids.txt | 3 ++ fsck.h | 1 + refs/files-backend.c | 73 ++++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/Documentation/fsck-msgids.txt b/Documentation/fsck-msgids.txt index f643585a34..7c809fddf1 100644 --- a/Documentation/fsck-msgids.txt +++ b/Documentation/fsck-msgids.txt @@ -19,6 +19,9 @@ `badParentSha1`:: (ERROR) A commit object has a bad parent sha1. +`badRefFiletype`:: + (ERROR) A ref has a bad file type. + `badTagName`:: (INFO) A tag has an invalid format. diff --git a/fsck.h b/fsck.h index d551a9fe86..af02174973 100644 --- a/fsck.h +++ b/fsck.h @@ -31,6 +31,7 @@ enum fsck_msg_type { FUNC(BAD_NAME, ERROR) \ FUNC(BAD_OBJECT_SHA1, ERROR) \ FUNC(BAD_PARENT_SHA1, ERROR) \ + FUNC(BAD_REF_FILETYPE, ERROR) \ FUNC(BAD_TIMEZONE, ERROR) \ FUNC(BAD_TREE, ERROR) \ FUNC(BAD_TREE_SHA1, ERROR) \ diff --git a/refs/files-backend.c b/refs/files-backend.c index 4630eb1f80..e511e1dcce 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -6,6 +6,7 @@ #include "../gettext.h" #include "../hash.h" #include "../hex.h" +#include "../fsck.h" #include "../refs.h" #include "refs-internal.h" #include "ref-cache.h" @@ -3408,13 +3409,83 @@ static int files_ref_store_remove_on_disk(struct ref_store *ref_store, return ret; } +/* + * For refs and reflogs, they share a unified interface when scanning + * the whole directory. This function is used as the callback for each + * regular file or symlink in the directory. + */ +typedef int (*files_fsck_refs_fn)(struct ref_store *ref_store, + struct fsck_options *o, + const char *refs_check_dir, + struct dir_iterator *iter); + +static int files_fsck_refs_dir(struct ref_store *ref_store, + struct fsck_options *o, + const char *refs_check_dir, + files_fsck_refs_fn *fsck_refs_fn) +{ + struct strbuf sb = STRBUF_INIT; + struct dir_iterator *iter; + int iter_status; + int ret = 0; + + strbuf_addf(&sb, "%s/%s", ref_store->gitdir, refs_check_dir); + + iter = dir_iterator_begin(sb.buf, 0); + if (!iter) { + ret = error_errno(_("cannot open directory %s"), sb.buf); + goto out; + } + + while ((iter_status = dir_iterator_advance(iter)) == ITER_OK) { + if (S_ISDIR(iter->st.st_mode)) { + continue; + } else if (S_ISREG(iter->st.st_mode) || + S_ISLNK(iter->st.st_mode)) { + if (o->verbose) + fprintf_ln(stderr, "Checking %s/%s", + refs_check_dir, iter->relative_path); + for (size_t i = 0; fsck_refs_fn[i]; i++) { + if (fsck_refs_fn[i](ref_store, o, refs_check_dir, iter)) + ret = -1; + } + } else { + struct fsck_ref_report report = { .path = iter->basename }; + if (fsck_report_ref(o, &report, + FSCK_MSG_BAD_REF_FILETYPE, + "unexpected file type")) + ret = -1; + } + } + + if (iter_status != ITER_DONE) + ret = error(_("failed to iterate over '%s'"), sb.buf); + +out: + strbuf_release(&sb); + return ret; +} + +static int files_fsck_refs(struct ref_store *ref_store, + struct fsck_options *o) +{ + files_fsck_refs_fn fsck_refs_fn[]= { + NULL, + }; + + if (o->verbose) + fprintf_ln(stderr, _("Checking references consistency")); + return files_fsck_refs_dir(ref_store, o, "refs", fsck_refs_fn); +} + static int files_fsck(struct ref_store *ref_store, struct fsck_options *o) { struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_READ, "fsck"); - return refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); + return files_fsck_refs(ref_store, o) | + refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); } struct ref_storage_be refs_be_files = { From patchwork Thu Aug 8 11:31:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13757284 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BABB15534B for ; Thu, 8 Aug 2024 11:31:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116675; cv=none; b=bkebMe6IKrzmPYmeraLG8kcqBky8xQIv5o08//yNfNl4V5BbShEm9pGCdlN1L96St95DCAMvCOLvh38wnzRGS0O4riWdiEAoKE6gezvPzuag/PucO9DXiLtyHfuiaJgJvCksVH62srj5q/Yb0Xan1DeilfHidt9DWWRDzClg5mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723116675; c=relaxed/simple; bh=3tMP4uEjzZzahc+GKDcyD1gdBG8K5wRKhA5/9LSTuWg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RQZ0B+O8YbHG3e8+UwMW7hc+Otwnz0C8iw0OL0n9JlXFf2T97g6YRXDHKRt9GyQHdP8ipu7PaCBsfapxV0YmC+D9R//nw5F/yqmzOfjGREg/ZLNjT4MMLc7uFchuXrxFSH7IvnWz/lWaR1P5OpSbviWU0Z6tC4cC3iNJm0POvvY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dLlVljbk; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dLlVljbk" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so611822a12.3 for ; Thu, 08 Aug 2024 04:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723116673; x=1723721473; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kxs3Rp1Bn4gj9+ZhnLJZqEXXntL8QK31pnSW5jvtwF4=; b=dLlVljbk+4vpEkaEeaUnsY0MEJGuGCLR0VbimcmaUwKrSGKKv1HjTkIGxCuYjlDW+J 2DjeysiWuIquaTmkuPe/ND8jxwX5beFPCZbIZb3T9971j62ugT6tfb2pPqtbN8/sKlnQ dxT/1GlwgI7ba4l1hFYFQn3W96cErBROnuKXIQWEd6pMNY7kL0yF2ucunIvwaVw4+WUz tg9ByGLnNijhW+vkOqCp3c+kNC0xi9Wuet8laQk4Apy4If+ta6LFoi1nbriHOnGPPZZh 2rTIcO7PXcBYSjC+nzSO44dAsyuHN7nqsAOf1FCumu/36XMDHTBZ+pCcoy/l2/hPafr2 dJIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723116673; x=1723721473; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kxs3Rp1Bn4gj9+ZhnLJZqEXXntL8QK31pnSW5jvtwF4=; b=Pa/Jp8oc+svUQElt8b+M4mpOIa/em96hGg4adN2esxM/4Hc4D3aA6BP4uHs6n6qo22 7OU/U5uof4GJs6uWlP5os2bgi2RxJ+l45N04/n47puZN6tEcoab5kd1mG/mkNaCCSITg Ya5xCdfTIFIoBs/bOwIsiJ0B+49+jf/4Okc1QH9Ggs/dnHq0zU5OSwFRIPLSx9xkv0dR ZRxblHxjL4tQ6+V66AkS0f4mX+BYiKaCPc0b5HnNJ8RipWsy4d5kyKgbkSLSy22IHNXr ACqgQ3HGelptjzSBqfSrCmQAQ6IhvFzdPAssJ5nnSH9u6gPyW2KLf0OVGtv1b1mPrASF HeXg== X-Gm-Message-State: AOJu0YxZ4EVpZSqCux5xZZHzyCvUl2OuikZ3TwWpzdLyB/Ujqc/y0qz+ dAFv7pbr+x5dHFozojp7HifY6Pwyme9RoJQe8XZayK+L20UUKE1BUIkWgWJArFk= X-Google-Smtp-Source: AGHT+IFpuaE36ol3pv2gvAelMG+eEfX3Qgvk04Amawbw3WSQ+bn5VlkKFvMi/MtlmT2UWJD3a0kHZQ== X-Received: by 2002:a05:6a20:9189:b0:1c6:b099:6f89 with SMTP id adf61e73a8af0-1c6fce779c0mr1897478637.4.1723116673047; Thu, 08 Aug 2024 04:31:13 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb22a455sm961077b3a.71.2024.08.08.04.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 04:31:12 -0700 (PDT) Date: Thu, 8 Aug 2024 19:31:42 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v16 9/9] fsck: add ref name check for files backend Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The git-fsck(1) only implicitly checks the reference, it does not fully check refs with bad format name such as standalone "@". However, a file ending with ".lock" should not be marked as having a bad ref name. It is expected that concurrent writers may have such lock files. We currently ignore this situation. But for bare ".lock" file, we will report it as error. In order to provide such checks, add a new fsck message id "badRefName" with default ERROR type. Use existing "check_refname_format" to explicit check the ref name. And add a new unit test to verify the functionality. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/fsck-msgids.txt | 3 ++ fsck.h | 1 + refs/files-backend.c | 31 ++++++++++++ t/t0602-reffiles-fsck.sh | 92 +++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100755 t/t0602-reffiles-fsck.sh diff --git a/Documentation/fsck-msgids.txt b/Documentation/fsck-msgids.txt index 7c809fddf1..68a2801f15 100644 --- a/Documentation/fsck-msgids.txt +++ b/Documentation/fsck-msgids.txt @@ -22,6 +22,9 @@ `badRefFiletype`:: (ERROR) A ref has a bad file type. +`badRefName`:: + (ERROR) A ref has an invalid format. + `badTagName`:: (INFO) A tag has an invalid format. diff --git a/fsck.h b/fsck.h index af02174973..500b4c04d2 100644 --- a/fsck.h +++ b/fsck.h @@ -32,6 +32,7 @@ enum fsck_msg_type { FUNC(BAD_OBJECT_SHA1, ERROR) \ FUNC(BAD_PARENT_SHA1, ERROR) \ FUNC(BAD_REF_FILETYPE, ERROR) \ + FUNC(BAD_REF_NAME, ERROR) \ FUNC(BAD_TIMEZONE, ERROR) \ FUNC(BAD_TREE, ERROR) \ FUNC(BAD_TREE_SHA1, ERROR) \ diff --git a/refs/files-backend.c b/refs/files-backend.c index e511e1dcce..7f6eefa960 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3419,6 +3419,36 @@ typedef int (*files_fsck_refs_fn)(struct ref_store *ref_store, const char *refs_check_dir, struct dir_iterator *iter); +static int files_fsck_refs_name(struct ref_store *ref_store UNUSED, + struct fsck_options *o, + const char *refs_check_dir, + struct dir_iterator *iter) +{ + struct strbuf sb = STRBUF_INIT; + int ret = 0; + + /* + * Ignore the files ending with ".lock" as they may be lock files + * However, do not allow bare ".lock" files. + */ + if (iter->basename[0] != '.' && ends_with(iter->basename, ".lock")) + goto cleanup; + + if (check_refname_format(iter->basename, REFNAME_ALLOW_ONELEVEL)) { + struct fsck_ref_report report = { .path = NULL }; + + strbuf_addf(&sb, "%s/%s", refs_check_dir, iter->relative_path); + report.path = sb.buf; + ret = fsck_report_ref(o, &report, + FSCK_MSG_BAD_REF_NAME, + "invalid refname format"); + } + +cleanup: + strbuf_release(&sb); + return ret; +} + static int files_fsck_refs_dir(struct ref_store *ref_store, struct fsck_options *o, const char *refs_check_dir, @@ -3470,6 +3500,7 @@ static int files_fsck_refs(struct ref_store *ref_store, struct fsck_options *o) { files_fsck_refs_fn fsck_refs_fn[]= { + files_fsck_refs_name, NULL, }; diff --git a/t/t0602-reffiles-fsck.sh b/t/t0602-reffiles-fsck.sh new file mode 100755 index 0000000000..71a4d1a5ae --- /dev/null +++ b/t/t0602-reffiles-fsck.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +test_description='Test reffiles backend consistency check' + +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +GIT_TEST_DEFAULT_REF_FORMAT=files +export GIT_TEST_DEFAULT_REF_FORMAT +TEST_PASSES_SANITIZE_LEAK=true + +. ./test-lib.sh + +test_expect_success 'ref name should be checked' ' + test_when_finished "rm -rf repo" && + git init repo && + branch_dir_prefix=.git/refs/heads && + tag_dir_prefix=.git/refs/tags && + cd repo && + + git commit --allow-empty -m initial && + git checkout -b branch-1 && + git tag tag-1 && + git commit --allow-empty -m second && + git checkout -b branch-2 && + git tag tag-2 && + git tag multi_hierarchy/tag-2 && + + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/.branch-1: badRefName: invalid refname format + EOF + rm $branch_dir_prefix/.branch-1 && + test_cmp expect err && + + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/@: badRefName: invalid refname format + EOF + rm $branch_dir_prefix/@ && + test_cmp expect err && + + cp $tag_dir_prefix/multi_hierarchy/tag-2 $tag_dir_prefix/multi_hierarchy/@ && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/tags/multi_hierarchy/@: badRefName: invalid refname format + EOF + rm $tag_dir_prefix/multi_hierarchy/@ && + test_cmp expect err && + + cp $tag_dir_prefix/tag-1 $tag_dir_prefix/tag-1.lock && + git refs verify 2>err && + rm $tag_dir_prefix/tag-1.lock && + test_must_be_empty err && + + cp $tag_dir_prefix/tag-1 $tag_dir_prefix/.lock && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/tags/.lock: badRefName: invalid refname format + EOF + rm $tag_dir_prefix/.lock && + test_cmp expect err +' + +test_expect_success 'ref name check should be adapted into fsck messages' ' + test_when_finished "rm -rf repo" && + git init repo && + branch_dir_prefix=.git/refs/heads && + tag_dir_prefix=.git/refs/tags && + cd repo && + git commit --allow-empty -m initial && + git checkout -b branch-1 && + git tag tag-1 && + git commit --allow-empty -m second && + git checkout -b branch-2 && + git tag tag-2 && + + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && + git -c fsck.badRefName=warn refs verify 2>err && + cat >expect <<-EOF && + warning: refs/heads/.branch-1: badRefName: invalid refname format + EOF + rm $branch_dir_prefix/.branch-1 && + test_cmp expect err && + + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && + git -c fsck.badRefName=ignore refs verify 2>err && + test_must_be_empty err +' + +test_done