From patchwork Sat Jul 20 09:27:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13737754 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 9297040847 for ; Sat, 20 Jul 2024 09:27:17 +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=1721467639; cv=none; b=VfiHb6pUcSrquaplOk7M10ArlJVV8MahANMkKrVj7VUlEEImXO2Zbgzo5woIsYoU7cJgwEXgVXvTMs6Tbe3L6OApu27duoKUypP0T5LTAQrsqnVyjy2X528bYQ68CHnWdLSY+nvmaCsUjbqbEXi5rc0/unmPkl3xK21q+Sfl5NY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467639; c=relaxed/simple; bh=4S/eeYa3WSAOASAvQOCp2KZZaz7om+5BeG3DmzjcW/Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d59rI4aYUodM0O9w7XoG/7pQ15xlTNflMTBJAksqGBVlvA/qW90JN1HCuraUUuN0b1peonZGGJepJyWZlqlATRgzXyRDhZ7QuFYOMyPUrqohFS5Bxwh7uINPFkafkjJmD7rRW8F7IdryWnWOUmG8pzONZE6DF4EXNguQNG5+C8M= 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=NWm0SBbr; 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="NWm0SBbr" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70d138e06e3so113101b3a.2 for ; Sat, 20 Jul 2024 02:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721467636; x=1722072436; 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=9UDRGCnen2eMRIWeoclWfDlQnsmaMv5ILJOERPNxlb4=; b=NWm0SBbrfTmq2ibuQNY2joP5n9hZNWwvoD+0nq5fdeqe+BQFOQL1y3/U//UaxNuvmy FJSsx1alfVD4z/71Rds0edTcYmgIjJSrM++3vglMfXEQD8wF5Zmg6pdKhSIzDHaEqytN 8756teibpxBpSLo9dAEyGghc3EPd447AZbbgyQnWdNtx52ODSLjuSQUyNG7HwCu2wB0Y 4Ol+JJ8Gi/rB8yS3P1MTeKRKFnqa0Ewe3ZyqRfyLulrgQT98CHLtZXgalffFVEMjNX1F NjFp+ExQ5LNN77J04ihxXM79gSPMSSpuML7g7URhYgSRhVTSAyGWwuoLZDXxjf/yCTVk RsAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721467636; x=1722072436; 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=9UDRGCnen2eMRIWeoclWfDlQnsmaMv5ILJOERPNxlb4=; b=oUeeFgK7bMJM/AJzcfhv/WTG1HB1J77Su/KtvZZe8iqcvZq9zFOuouoDpEiUFQcafC iUMWdpS6mKr/vOlYpqKI0J23ptCX8TGtcXIfYjajwJQdEqBw9BkGjCaDqJ1ZPS6zsIUS qite/98I+xFK13M5r2AL3XxHq9cqidnHDlhK4RBUMny/lQaZeE6n5A7ItfhCny/FUDFC 9tIrW+TwUtgSrgp2NlhkIAtjqnAZG2sDzb7eDbk1b2n+lIAgITBkwp5sV4Q6faz3H4n4 9ABW67aPofC4Ey/sV0PXT7/5vXOPD4SM3TBSikplNMRd9pYtkHj+He4R7Vsfl2mGXbeR /KKw== X-Gm-Message-State: AOJu0YzUvsWnpjgshEYUvG+TcaTj/UHaCu3ERD0CsN3Cv6nI/TVfeYEX Q4QQTGvrL/RVININRk5azKeNwV3ukKE2ksaxlaMZQId8io+QO1bHCpcjYQ== X-Google-Smtp-Source: AGHT+IErD9zuXppNxQ3884OYJRe+gS/uapF5z/hQlfnhRJ3rGJSBkDD2dYsAMzQ/1B68gzUAEH4bvA== X-Received: by 2002:a05:6a00:cc7:b0:706:62b6:cbd3 with SMTP id d2e1a72fcca58-70d08643bf0mr3088752b3a.26.1721467635815; Sat, 20 Jul 2024 02:27:15 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70cff552d8asm2335670b3a.132.2024.07.20.02.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 02:27:15 -0700 (PDT) Date: Sat, 20 Jul 2024 17:27:26 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v12 01/10] 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 Sat Jul 20 09:27:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13737755 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 9240B40847 for ; Sat, 20 Jul 2024 09:27:28 +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=1721467650; cv=none; b=UKe3vp7Ya1OgBH94o37NloPaFJT3+V7arF9xrJGvNH1y9Ym0cruB7gkrH+YZqPfM193ELSs/CZ05xuWMnM0djD9hhPkKx2I6pADZ0i5D6slvEMsr7EgqI+2wXBWxIu1PPnPIg6USQa/70nVtD6o8eli4RZWCGgeOTmo0Owkf3W0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467650; c=relaxed/simple; bh=2K43dd5rEmasNVcu6xwJS3VCgAha6jgNXgCFk9fBt5Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=t9Wn4wNPGo/D+NQ7yUHhJ2Yqy5YI1QOXag7UW6Lrjkl13EJOsgEk2oc3hm8Tx39etG06mnfcTy7WvopdS2C1/gAkPjybLEiftOPp8tbuJp6SV29BMOXmQq3QkWjiy23lGHgL00AOOeWJvrhjyizFs+JqDOi9/jiwuuL80v5XEhQ= 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=dUk7THXI; 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="dUk7THXI" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1fc5549788eso22541835ad.1 for ; Sat, 20 Jul 2024 02:27:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721467647; x=1722072447; 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=wA7QKi1pRPqFmkz/Qq7E1tMSFQtE6VXXKSSfcRH62ew=; b=dUk7THXImINIWifmXFSIWzNM1CWJ3TIIZaKxjuwWIRYDDdkZkMex9niwv0jinkAiz8 Otcu+NE6qKlrIEddOkihlWPWYPvGknByDJMWne2Xd9PmVMDfWvgc1BlAPwdlMRl9Ca2F jdUl6OuiEoZb7uk9p3RoBKmFNpQ8kp2ov/2EAS60SwIGmPJsfUKk9v1hYH5AQVp+h5OL aMnSEc4bOhKvyqOh9SGuYu3yJY6mdmT1Ky4rncZKvA6h8sLFZlNvKgg/MkctJPUnERyw SnvW3KdCVNbDdoLlY39CPjzHJ+Qrwhyo6Rnk/7gM+nYiHXf7HxB/8cnwgh1lI/Ij6idC 0IZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721467647; x=1722072447; 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=wA7QKi1pRPqFmkz/Qq7E1tMSFQtE6VXXKSSfcRH62ew=; b=eLg4Z3CdNWp+h79rLmfYTDcie372JFz5HX9oVaGwZhcMI5zGI+8VQYFkfzzK+YIAI8 nPQ3Jumou1AWxHx9Adlhu3Czv1VZTk5HBqZTyRY1+leMoDj20WPFlirIEhOdWEIKJp2R XUTjXhwKC7Q5NEDLQDolkKHC2wKFZpfBKliD7zbkahBfYYYbkVJEujnpD1beIaL0TubU l0XYnpMUJFuvzkLljztWenBNiLGGReFu67bJnK4Oc8+4ayUjetKtxCF2WM5/1TwwfCMR WoCtoVuRYQLosT6Bzp3U8xOi/bZ/iB2wqsiwvGhC4mumO1Pnsmw/Z78zc0vbLgy7d6/E CsyQ== X-Gm-Message-State: AOJu0YxuBoUWfqvfz3UjE7FO8mBozXL64pbpeGDD/rsksxheuKL6XWrB P/Xq7RE9wfOXVpi+0UVkHLryf2BzpAjReJE/2kdO2ktbInL3ffarzOEV2g== X-Google-Smtp-Source: AGHT+IEkjtyW+8BkFaacKJdMywWMiqVyUrWuniGKuXKcd+Xn/t/RusJWqyF2qUxBkp8v1wqLoRj0Yw== X-Received: by 2002:a17:902:d489:b0:1fd:7c8a:be3e with SMTP id d9443c01a7336-1fd7c8ad873mr9654535ad.36.1721467647272; Sat, 20 Jul 2024 02:27:27 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f4548ffsm17999135ad.236.2024.07.20.02.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 02:27:26 -0700 (PDT) Date: Sat, 20 Jul 2024 17:27:37 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v12 02/10] 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 fsck error type and calling the callback "error_func" to report the message. However, "report" function is only related to object database which cannot be reused for refs. In order to provide a unified interface which can report either objects or refs, create a new function "fsck_vreport" following the "report" prototype. Instead of using "...", provide "va_list" to allow more flexibility. In order to provide an extensible error report for refs, add a new "fsck_refs_info" structure to incorporate an union for supporting different checks for files backend and reftable backend. Then incorporate this structure into the "fsck_options" to reuse the "error_func" callback. Then, change "report" function to use "fsck_vreport" to report objects related messages. Add a new function called "fsck_refs_report" to use "fsck_vreport" to report refs related messages. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 46 +++++++++++++++++++++++++++++++++++++++------- fsck.h | 26 +++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/fsck.c b/fsck.c index 3f32441492..f2417e65fd 100644 --- a/fsck.c +++ b/fsck.c @@ -226,12 +226,17 @@ 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 a unified interface 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, + const struct object_id *oid, + enum object_type object_type, + enum fsck_msg_id msg_id, const char *fmt, va_list ap) { - va_list ap; + va_list ap_copy; struct strbuf sb = STRBUF_INIT; enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options); int result; @@ -250,8 +255,8 @@ 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); + va_copy(ap_copy, ap); + strbuf_vaddf(&sb, fmt, ap_copy); result = options->error_func(options, oid, object_type, msg_type, msg_id, sb.buf); strbuf_release(&sb); @@ -260,6 +265,33 @@ static int report(struct fsck_options *options, 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; + int result; + + va_start(ap, fmt); + result = fsck_vreport(options, oid, object_type, msg_id, fmt, ap); + va_end(ap); + + return result; +} + +int fsck_refs_report(struct fsck_options *options, + const struct object_id *oid, + enum fsck_msg_id msg_id, const char *fmt, ...) +{ + va_list ap; + int result; + va_start(ap, fmt); + result = fsck_vreport(options, oid, OBJ_NONE, msg_id, fmt, ap); + va_end(ap); + return result; +} + void fsck_enable_object_names(struct fsck_options *options) { if (!options->object_names) diff --git a/fsck.h b/fsck.h index bcfb2e34cd..a2ecb39b51 100644 --- a/fsck.h +++ b/fsck.h @@ -114,7 +114,9 @@ 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 function for reporting errors when checking either objects or refs + */ typedef int (*fsck_error)(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, @@ -131,11 +133,24 @@ int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, enum fsck_msg_id msg_id, const char *message); +/* + * The information for reporting refs-related error message + */ +struct fsck_refs_info { + char *ref_checkee; + union { + struct { + char *sub_ref_checkee; + } files; + } u; +}; + struct fsck_options { fsck_walk_func walk; fsck_error error_func; unsigned strict:1; enum fsck_msg_type *msg_type; + struct fsck_refs_info refs_info; struct oidset skip_oids; struct oidset gitmodules_found; struct oidset gitmodules_done; @@ -209,6 +224,15 @@ 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_refs_report(struct fsck_options *options, + const struct object_id *oid, + enum fsck_msg_id msg_id, + const char *fmt, ...); + /* * Subsystem for storing human-readable names for each object. * From patchwork Sat Jul 20 09:27:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13737756 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 9A5DB40847 for ; Sat, 20 Jul 2024 09:27:40 +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=1721467662; cv=none; b=BUvPOMovV/iMsOd4CI7s9hlIbYbkK4ts14YyhIZJh1Xr0tGEJDeUHJKYLO7IdRXkkJmMQuhmwn5ouXM58QX8aKzKkA0UyhS8tRR+QhkaJJCnxHFA9v8BNnFxiO7YZFPNL+OTdCJsxVhKitKc9cjCYjVGqlGCikZa4sWGmrsLtog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467662; c=relaxed/simple; bh=/8gPCmRaiPNQlMEZUwNHkzf6KWxbg72phA1Tk2bdMDA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JLZakodGlGpxH7RqfLwzGFmcD3jgtxBinn/ppKM2hA2gcmjmXzPjAUIwLd4rPqHqY0evDgjElwl3P1cCuQiY/if30ZPb48fTvO+KFRdo/2BkgYtJStdCDV007OfltuY56R/5jVSXXcwONEn+9HzI8YAbpUGPe4AQV43JmsevsrU= 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=UDff17mZ; 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="UDff17mZ" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1fb8781ef1bso22140055ad.3 for ; Sat, 20 Jul 2024 02:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721467659; x=1722072459; 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=v36/1gT1sTivk2ZeIYYkaW9wHb7A7rKQJpHvYGuc83s=; b=UDff17mZIpKB4w03xQvLfwiYmKX5DhHWnFD8MQcc8Wn21LXN0fkMdSPJkRuMEqKHxc cn8fq+6I8dvsPswnTwVp1pvriQFeCk9ASCC0Pw+uuVtCktE4Xz/JWKJxTaJAguecB9yb tA7Mv6De6EPPW6G8dAyUFNbwfoVGXF4O4wRyDedI6rhyHnQCXvMtlygOagOhtjieug8i 7Y4QaxNQGKlM7Mpn/MRV2zgc6c4a/K3BFJCRrRQ/gPkEWnM5ur/pc9e5FgkRIENPBvXF Yheqscc+eywLFGdjLl24sqoJN0CYr06FOHPcQMXzNl0kkWq7kQWyV1WKkhm63goEOfeG 3yAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721467659; x=1722072459; 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=v36/1gT1sTivk2ZeIYYkaW9wHb7A7rKQJpHvYGuc83s=; b=Rpxc4ia6jdzSzQKcZQIlY1QOfXWyScdVoi8SDn3D9IoYAzGVY7RdQ7xfgGKrMiUMDp nJIOBBPsivfqdg/d8/1MMLCJZFuE9Gym+0sn3yh0otFv2vlP3LKy0ByQYUXA2JotXmrH zjjO949q3yHpKEM1Gpto1U72J+RCVxwLxTE5i2Z3RKVra4wqfwStSNE4KwsOb65b6OYw MC0aBNdGM1Mm2khRzXikLB9ShlhvkkGhPlEvzZkxOd2pEX1jaeeRNs563tR6vUpGiqlS c7YF8xvKgEA211xprBgz8dL6NkLTCRlFbPUsU83cUc+c0CZNhjPgWl2FKZsTxyK8eM/m tjbw== X-Gm-Message-State: AOJu0Yx6kInwRbvr7M70DMl55dO6LetzlnOQNC/x2M6l2lRcF7FQVgZN M5UyaG/uagNx5G70GFUigtPGTNVZePcF9q1Y9c/Q+KfwoBNQwhPnC414Qg== X-Google-Smtp-Source: AGHT+IHLzj8OAMufgQDLp1pc1U1HGySnrrnmIAJTPr0aG+x2XIb5PZeJ39FzVeWguFc+Thdzjl/IGw== X-Received: by 2002:a17:902:e547:b0:1fc:72f5:43b6 with SMTP id d9443c01a7336-1fd74554a16mr15116665ad.20.1721467659459; Sat, 20 Jul 2024 02:27:39 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f4530cbsm18038885ad.221.2024.07.20.02.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 02:27:38 -0700 (PDT) Date: Sat, 20 Jul 2024 17:27:49 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v12 03/10] 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 general. It's OK when there is only object database check. However, we have introduced 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 | 27 ++++++++++++++------------- fsck.h | 26 +++++++++++++------------- 3 files changed, 34 insertions(+), 33 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 f2417e65fd..9a7e3d8679 100644 --- a/fsck.c +++ b/fsck.c @@ -1232,12 +1232,12 @@ int fsck_buffer(const struct object_id *oid, enum object_type type, type); } -int fsck_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) +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) { if (msg_type == FSCK_WARN) { warning("object %s: %s", fsck_describe_object(o, oid), message); @@ -1335,16 +1335,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 a2ecb39b51..6411437334 100644 --- a/fsck.h +++ b/fsck.h @@ -122,16 +122,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); /* * The information for reporting refs-related error message @@ -165,7 +165,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, \ @@ -173,7 +173,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, \ @@ -181,7 +181,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 Sat Jul 20 09:28:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13737757 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 78E6940847 for ; Sat, 20 Jul 2024 09:27:50 +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=1721467671; cv=none; b=RFPkpd7S9+wXpgW2zCfyKydj2mi178EQy0tW+A82UXa31kujAeQaQL5tPDi/JXNzSbe7yOd9ozEpo38fXdETU/OEPwJvc22PUTh0RbRg/LNJuhqipplmRJc7i2OA1wuW5uzzesvmK/BBXT7SKXZwXGfg5b+Vlt+qvvJS35uci8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467671; c=relaxed/simple; bh=Z2BbhBVeUKXRMN4iyitxtU0FNaDv3kizlZWJUjEcu8Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=M1IXKajdBEAIudMwZM3gOu7qD+146C+PQ+wqf92xszkNbZik6iFNOi3Irt1sujMQqWpd6ODm8iYgx3YOs5pgL4UrRCIl/AguatYKkKAu6ssDncuaW+f2EmU5cft3bhIKwbK67abaUMj+NgNyoTAksl3Wjt3gWbUb2bm4TQ5zKoM= 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=SlGW+Xjg; 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="SlGW+Xjg" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1fd6ed7688cso8812375ad.3 for ; Sat, 20 Jul 2024 02:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721467669; x=1722072469; 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=GkX743KsJODa2s7UXmorzi4228aW7WaxboyE7KRIgUw=; b=SlGW+XjgmB7qCpJ5yj4/uKhMNqv5DvV2vK780YGb9nmbNQIo1f4y4bOZDA6HpBlFPS 5fXkJT6KqcwJ2dJ6T4VZBiHGbWaEveSgp6Jb9d9fIBuGJLMEYseEUzFYPSe0IiOBO53B ADEF9Pn7L3Sz3tUWAP4vl1uORTbuaBLPZ737UaOra5v47Ft1M6PQaVQxSuNPNXiyGVfJ r3hdajkY0GzBCkjZlCxF38jNxm1uTug/CB4CV4KZn03N0uEuZ8Tp+ZsRsIHmRT2ViWYa /4sAhpGh5vkJ1ZkwxW1w7nXS4G4HyPAhLHtiTUGtqoZa44o5rOTQ7PNzf429r+r5MVop pWtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721467669; x=1722072469; 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=GkX743KsJODa2s7UXmorzi4228aW7WaxboyE7KRIgUw=; b=DAd8NjC6rT7H85T5I31GezOuci9tUgHY2JMXac9eZylQR5WKXL377yWkKxV8g9h+Tt IUg1CL8hLy1mfx3GlLXjB2GIjHPPCN1+S3X4UUfhRf7uaHBOo8FtsQwlnosMhQNt0372 vHfERvBXS70+VGsZqYKxz06XYRj0j8cVxsry0HhVzvrzMoEdVOI22XWnH5gzX4/0bAwT Xnxly5wGTWYjuzHQDYHSrhatJF0KhSRvGQ2Re45F1Ce710oXdmkpnJQ/X7zt1BHxIf2M J1wWD7048fibxcMQYlpN8UxSV1PHjMdpDzSzv/8TlE1uvbLn1cp+vCKRdHH+ph6IvHsf F0xA== X-Gm-Message-State: AOJu0YwwtQ7DcCV82F9xYnbq6E6YB03qZd4i72ARv19YRAmhBr1s7iHp pVfX+dGqydP5oJepuF/uQz/kBL15CuIa+Gg6CU1r44YQ4L6rUHSRdr/DBw== X-Google-Smtp-Source: AGHT+IF5YJwy05PowMTKLVWTAryU+2IaLKgT28ES6PRnYAhZlpPGSHs2P9C/1Iuh4eHywe5inIgvpw== X-Received: by 2002:a17:902:ea04:b0:1fd:7e56:e108 with SMTP id d9443c01a7336-1fd7e56e494mr5106405ad.25.1721467669287; Sat, 20 Jul 2024 02:27:49 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f47895asm17936965ad.270.2024.07.20.02.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 02:27:48 -0700 (PDT) Date: Sat, 20 Jul 2024 17:28:00 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v12 04/10] fsck: add refs-related error 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: Create refs-specific "error_func" callback "fsck_refs_error_function" which could provide the following report messages for files backend 1. "ref_checkee": "fsck error name": "user message". 2. "ref_checkee.sub_ref_checkee": "fsck error name": "user message". 3. "ref_checkee -> (oid hex)": "fsck error name": "user message". 4. "ref_checkee.sub_ref_checkee -> (oid hex)": "fsck error name": "user message". "fsck_refs_error_function" uses the "ref_checkee" and "sub_ref_checkee" in the "fsck_refs_info" to indicate the information of the checked refs. For loose ref and reflog, it only uses the "ref_checkee". For packed refs and reftable refs, when checking the consistency of the file itself, it still only uses "ref_checkee". However, when checking the consistency of the ref or reflog contained in the file ,it will use the "sub_ref_checkee" to indicate that we are not checking the file but the incorporated ref or reflog. "fsck_refs_error_function" will use the "oid" parameter if the caller passes the oid, it will use "oid_to_hex" to get the corresponding hex value to report to the caller. Last, add "FSCK_REFS_OPTIONS_DEFAULT" and "FSCK_REFS_OPTIONS_STRICT" macros to create refs options easily. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 29 +++++++++++++++++++++++++++++ fsck.h | 13 +++++++++++++ 2 files changed, 42 insertions(+) diff --git a/fsck.c b/fsck.c index 9a7e3d8679..e87b13fdc3 100644 --- a/fsck.c +++ b/fsck.c @@ -1247,6 +1247,35 @@ int fsck_objects_error_function(struct fsck_options *o, return 1; } +int fsck_refs_error_function(struct fsck_options *options, + 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) +{ + struct strbuf sb = STRBUF_INIT; + struct fsck_refs_info *refs_info = &options->refs_info; + int ret = 0; + + if (the_repository->ref_storage_format == REF_STORAGE_FORMAT_FILES) { + strbuf_addstr(&sb, refs_info->ref_checkee); + if (refs_info->u.files.sub_ref_checkee) + strbuf_addf(&sb, ".%s", refs_info->u.files.sub_ref_checkee); + + if (oid) + strbuf_addf(&sb, " -> (%s)", oid_to_hex(oid)); + } + + 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 6411437334..a3870ffe2b 100644 --- a/fsck.h +++ b/fsck.h @@ -132,6 +132,12 @@ int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); +int fsck_refs_error_function(struct fsck_options *options, + 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); /* * The information for reporting refs-related error message @@ -183,6 +189,13 @@ 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, \ +} +#define FSCK_REFS_OPTIONS_STRICT { \ + .strict = 1, \ + .error_func = fsck_refs_error_function, \ +} /* descend in all linked child objects * the return value is: From patchwork Sat Jul 20 09:28:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13737758 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.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 7462D40847 for ; Sat, 20 Jul 2024 09:28:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467682; cv=none; b=ah6tFVXm9j4SECtLM+Mb4axVbHfi7XXUH58AsVHCQjLD/3Y5dhzudNa9T6X8vrZzZAAio4fU8+z33914fk1h6x+RSd1GIHmJrrvWQMx8jiW1tReUiH1hS2Gsqq9ZJWqoRO/gTTOmoSupYinbothxrmaGjfP6UmWD4TJqn22MtzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467682; c=relaxed/simple; bh=Xaf9riBzozmCKz1H0udrYwbdPauR82bQALqKOtzPJvU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dlFsCK2r/yz1iyRL7JYrOrfM4Y2CYJIO59LcWvjI/NCkatr0N8+o9C1ESpFzlEQeHa195aEuNMioNfFiQQmYDt1FaaGK9tBfC7H3lYGv4LZnXWFk04Oj0UUxaicCgd420zi6jJiK0JeoCQS6lVammfPB7MkwhVmTCd7xPWkcQnM= 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=Lt1Ihquu; arc=none smtp.client-ip=209.85.214.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="Lt1Ihquu" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1fc491f9b55so25264715ad.3 for ; Sat, 20 Jul 2024 02:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721467680; x=1722072480; 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=laa4K3fMvS0I93jB3AnHiR4n7++3zAPc3WP2RAf/kko=; b=Lt1IhquuDaWRw8KLeaanqRRPzLnnJRtrMXGl6OjkDegzmQaBLHoIzSeMQZD/vVdftx jHk3xZh3gY2fKyNOU4lerAPAqpqAplqIgEPEhjKAV+6Z3h6/RdUGNi3qsqN0skfw8PzQ KHDDiMwfx+CtOlLRv6DtcHDx1uLV3LC7AaqlZacdY6yBCfr/GcBP8OD1oIhtwXEBJI1R EiZr/BVd2JU4cU1lXMJilWtuJz1gdXL/9zjpsqZ7RwRitNpaIQrhMKhhsx+4pEPYRgZH h/P4osS6VQhTFnw00t3/OWNbWIL8A8Nso/qFhvbVN3sbIYWlMKgjt21wsWa1PfzCBZdm vYKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721467680; x=1722072480; 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=laa4K3fMvS0I93jB3AnHiR4n7++3zAPc3WP2RAf/kko=; b=jO04NyeDjlng4h/sjKNHNkahJhyV2T97UEBa62d3DTwjXfZAW8/4fzJarXNI2zVyv3 ygc+laxPjQwr22YdMonSYZP0RQmT/EPYIIlgPr8c0z2Gtv41tDI7AkX15yAN5IJLNNYX I63tuXdtgGcy8r7cXpGozuDFIG05454+lryNQDjv/Yglc6c7WhXprcPIKdD28rD04qMF mkdBHMfH49lYH4J7UR/XadOw6TywCyXPmr3KDi7dGOw6QqYu6IdyUh1UDErbA6e/fp8f 6PI7InA5gW4INMhFdZtYOz8TyMsZ9h9Wt4kAncM+K8Dz5QK5gfpuxLvOqeo3xPW6keBp 5Vaw== X-Gm-Message-State: AOJu0Yw2cRqdxtfUlCaaXTZb10fj+9+3+m3dYSQzFhS62DvicCiTxttF W5StUxVMY9UFcNCBQkgLcuXou56bY8vkxmQBxvYA1IDRwagLlxs9TfZZhA== X-Google-Smtp-Source: AGHT+IGby7F0VRZWW04XSJNB8LGRSoW5Z78FaWoeEvHh++Mc8XtDSyofhun2gvnJE7CfoxMf2jiXYA== X-Received: by 2002:a17:902:cec7:b0:1fa:7e0:d69a with SMTP id d9443c01a7336-1fd745e4ec1mr14324385ad.46.1721467680252; Sat, 20 Jul 2024 02:28:00 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f434943sm18099735ad.200.2024.07.20.02.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 02:27:59 -0700 (PDT) Date: Sat, 20 Jul 2024 17:28:10 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v12 05/10] 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 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 | 15 ++++++++++++++- refs/packed-backend.c | 8 ++++++++ refs/refs-internal.h | 6 ++++++ refs/reftable-backend.c | 8 ++++++++ 7 files changed, 60 insertions(+), 1 deletion(-) diff --git a/refs.c b/refs.c index bb90a18875..410919246b 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 0ecba21b4a..804d6a7fce 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..d89eeda8ef 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3408,6 +3408,17 @@ 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) +{ + int ret; + struct files_ref_store *refs = + files_downcast(ref_store, REF_STORE_READ, "fsck"); + + ret = refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); + return ret; +} + struct ref_storage_be refs_be_files = { .name = "files", .init = files_ref_store_init, @@ -3434,5 +3445,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 Sat Jul 20 09:28:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13737759 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 C53B8347C2 for ; Sat, 20 Jul 2024 09:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467705; cv=none; b=jr0ZEEKddDsknfxx7+bcdWQqYhMBTamTIg47Smipa8hWF7T95dABOCF5lc5tMqM86YIGMXYDcjVGt5gTGJvfegxqnFGdGJWIKlkcQCWPquqS3FEHCKzYhyu0H9dmtFTbYbzm+zxHD6aS+Wweu3Z4vy4BheLMq8KQ79RIbbAQuuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467705; c=relaxed/simple; bh=KWGftTZWltnyHv7KprcRsyIleLZPGChVbAUL5MpiC4Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KVmKghuxgbKIdfuhjXFHYbrH/90S1I98tEytPZV4CYI4jzjTO5QX2uLFs16qGtSes0JyGgF9+tO4Zj2Myw0ImcZID4+mrw/MrsMf+nEe7aOTQ+yMH8kTiZt9Wr3ITfBcKXwVBjrj0LHVTcRG7dLNbTpjRCvjSaYlm1oUYtibsV4= 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=NOnghfFh; arc=none smtp.client-ip=209.85.210.175 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="NOnghfFh" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-70b1207bc22so1313350b3a.3 for ; Sat, 20 Jul 2024 02:28:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721467702; x=1722072502; 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=HyRvKV3x3NyIXBZ8uXWHSMiQZ+VUHeCHGOW28QSyNzw=; b=NOnghfFh7tRwT2m27QHy5PuEw8E1wc3WBaozhlZt19SlLZ6Zja+VIMzbtplEnqsq49 IqFnzie+d75PahcsjkO64e82JNP3L+M8N4tO3GP726x0mhmu5wnIMNGyzL2qzalpbpa5 3KtM1EhzHbF7hjZ484c9j1fOKpcxJD9sR+QdD32zPke2VTTeA8Jq3SIDBt9n+4HhNCE1 rrayuGdFPRY0lTeg6VtuDoy88BqgbbHgg2v/hXgvf88Y2vjcOfAIdWKRNPlqWCyPN7Cy Jvpc83qZaOrBMBGY23leFsYHWveuZY/96zfhUIeL2CQgBbvlq1OuPkjQCowhZcQzu++d eLYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721467702; x=1722072502; 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=HyRvKV3x3NyIXBZ8uXWHSMiQZ+VUHeCHGOW28QSyNzw=; b=dnCgMqZDGUZ5SKEVjglaKTDaceHGJbPfRljMzuPlDiNQbn2AttCyGOcitmv2N8zHLa ETNqjbQS881M10zOjq8jVQ4b/KVhUcPhsF+86I0hah7QsEZ0woqYrL636lbmw6GqeQPh hh59CPt5japHE1NNZO/Hm3bBTicbJs2nLUXG69yu582j0VkxJD5ML10dagvrPZJTXtqu LI996+q3FQxEAaOXabCzxHwEqeuiIzGpYWPVqB9fEwPKihRX7SYPtw/bkv5fOpOpeiqX vNlKZvuLVlxzss9yXLwj+0n5dBinRle3LCHbp22QIXEcfEhb0nA93xUouBpLX+6HMFJN eUPQ== X-Gm-Message-State: AOJu0Yzw5Dp4DlEjHaWxC/otRi+96R6GRE09Ji+T9+TrG7EGGe4WFXZv QRvlPqXpqcpvQz/Rra/w+Q221BDTW8DvJZdL4xM+qh98ihOuicFDmWLLJQ== X-Google-Smtp-Source: AGHT+IGJB2lhj2rppWNnDn5w61LPLaXbzHq7G/MW2Hjelh0C2CsR277KVHF1xhb3V6QzatmSgMcj8A== X-Received: by 2002:a05:6a00:1250:b0:70b:29bf:bbde with SMTP id d2e1a72fcca58-70d084b4cf9mr3214028b3a.12.1721467702086; Sat, 20 Jul 2024 02:28:22 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-79f0a3ded37sm1324309a12.11.2024.07.20.02.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 02:28:21 -0700 (PDT) Date: Sat, 20 Jul 2024 17:28:32 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v12 06/10] git 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)". Last, add "verbose" field into "fsck_options" to indicate whether we should print verbose messages when checking refs and objects consistency. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/git-refs.txt | 13 +++++++++++ builtin/refs.c | 44 ++++++++++++++++++++++++++++++++++++++ fsck.h | 1 + 3 files changed, 58 insertions(+) diff --git a/Documentation/git-refs.txt b/Documentation/git-refs.txt index 5b99e04385..1244a85b64 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 more strict checking, every WARN severity for the `Fsck Messages` + be seen as ERROR. 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..4831c9e28e 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,54 @@ 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, + }; + unsigned int verbose = 0, strict = 0; + struct option options[] = { + OPT__VERBOSE(&verbose, N_("be verbose")), + OPT_BOOL(0, "strict", &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")); + + if (verbose) + fsck_refs_options.verbose = 1; + if (strict) + fsck_refs_options.strict = 1; + + 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); + + /* + * Explicitly free the allocated array and "skip_oids" set + */ + free(fsck_refs_options.msg_type); + oidset_clear(&fsck_refs_options.skip_oids); + 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.h b/fsck.h index a3870ffe2b..98e2225593 100644 --- a/fsck.h +++ b/fsck.h @@ -155,6 +155,7 @@ struct fsck_options { fsck_walk_func walk; fsck_error error_func; unsigned strict:1; + unsigned verbose:1; enum fsck_msg_type *msg_type; struct fsck_refs_info refs_info; struct oidset skip_oids; From patchwork Sat Jul 20 09:28:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13737760 Received: from mail-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) (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 DE2F11B86FD for ; Sat, 20 Jul 2024 09:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467715; cv=none; b=EEoyj6xjNCIyf0yam1jYxgEwdxy34/6o4mN9FbvjXjMROX5chScsIOwbDStjreJGV49/ZZ1hDreI077YHbatEmg9EmPhM275tFN95Qe9us0BhZ467Srf9FpBJzYFlLaJJstrcMIbbXisGcj5gF8cgWYTMtP2fmTyhcSss6XKuI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467715; c=relaxed/simple; bh=uXLiWDdQ4TXYINN7nYIcVgAYU9gKtYEEvtiLFFLTrEw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=B0u8DYGF7uS7c6HIAvv4ZZiYIiUMNp6zuXU4TTFQyKB9nMSqhaaeWEhWDTFg3JD/ucGmXezs6EV7cYGM5xe8kq0sC4qTpcrYUaR7LrMUwtGgz46mRP6jtwQIL8fuOs+k6lhwzNomZiXBFlH/WWVL44/Ze9+tVX5C2bAKuDe+1xE= 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=Pd70yTNK; arc=none smtp.client-ip=209.85.166.173 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="Pd70yTNK" Received: by mail-il1-f173.google.com with SMTP id e9e14a558f8ab-381f24d6bc4so10921255ab.2 for ; Sat, 20 Jul 2024 02:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721467712; x=1722072512; 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=GR8gSKe1hyeDj1f5ziXrf6+stAoMjezZja4QTgJnPs0=; b=Pd70yTNKTx82ZNUyffxYdBWLoA5KVa3ooSfPJhdyU5ni8FVMBeG+L0iyeKh8jVSYV9 xAZxQoH4I/E4iNjcbu2l1q3+WekBA4xpnYWUtixvA6j3EfGd6Ke9r+KY2jeyfcqa/sZ/ /gN7K6XC29Xr2GwfK7XML4WHcSOb5TSmBYkJ6xfMX7AzNslEEDcoi+RvJKSflWfLnvn3 dwUGErUMq9YbSxisA/ttZ1Bds01jW70dR7Br+SxHECl8+IoDkFd0rKEhSSQgLQnQFHy8 Wf4mnRJlNwgzHeYOv7r2e+NFHeI7UEUpwPNkZEuRBrk5eq6LMXyLTNFQksfjVyWoavoQ EVvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721467712; x=1722072512; 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=GR8gSKe1hyeDj1f5ziXrf6+stAoMjezZja4QTgJnPs0=; b=CtSb5OyPK8W0T5tkEYcL5RTyH6rocImZr+WkZ4+5ZiUMCPoVSxlR+XqYqunKnAyxTs JhQLeZV/eCnWjm4VphvH26ktZhdMp3UrIC5R8AvG6d8yUJ1H1otfdwxy6YngAXqRl7X8 N/iIw82wJUyRXABszaHDGKH2JWmXN0AgHOuywjPRa9AN3+5Wma7nmdQ1wN32tI/PQUOe dPruFA+aHNdHdcd+O2gOF8htE4BtKTdE+1Z5wUqU1XgVSLMMarobTL9qJoDfDpVmv7MP Fp2NzXLD/Zk3B9zlx9qDWM4HgCJrNISOkanVCIULqTyvqjU7f6lv+Y0uLmmqw7kE16s+ pPmQ== X-Gm-Message-State: AOJu0Yxz1Aftc/xUUaWVpHcgZP1nVETkgMODdHbPCl+thBvzwgFwaCJz 9LWBWfZvcyJa3JXdkoX+YTP15MDMAmLPzBMXpS4ntPNrDxSSpAuSJXtlIg== X-Google-Smtp-Source: AGHT+IELAngAxz7Mmb5CdkadJG7TJDhE/3RISSbdLhJfQuGgG5r13Jylnca1/0Cj1Hh3ufvefrgB6g== X-Received: by 2002:a92:cd88:0:b0:374:aa60:a5c3 with SMTP id e9e14a558f8ab-399404d20e6mr9538895ab.28.1721467712566; Sat, 20 Jul 2024 02:28:32 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70cff4b5ccbsm2349305b3a.68.2024.07.20.02.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 02:28:32 -0700 (PDT) Date: Sat, 20 Jul 2024 17:28:43 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v12 07/10] builtin/fsck: add `git-refs verify` child process 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 function "fsck_refs" that initializes and runs a child process to execute the "git-refs verify" command. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- builtin/fsck.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/builtin/fsck.c b/builtin/fsck.c index 6d86bbe1e9..6cdff55fd6 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -896,6 +896,21 @@ static int check_pack_rev_indexes(struct repository *r, int show_progress) return res; } +static void fsck_refs(void) +{ + struct child_process refs_verify = CHILD_PROCESS_INIT; + child_process_init(&refs_verify); + refs_verify.git_cmd = 1; + strvec_pushl(&refs_verify.args, "refs", "verify", NULL); + if (verbose) + strvec_push(&refs_verify.args, "--verbose"); + if (check_strict) + strvec_push(&refs_verify.args, "--strict"); + + if (run_command(&refs_verify)) + errors_found |= ERROR_REFS; +} + static char const * const fsck_usage[] = { N_("git fsck [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]\n" " [--[no-]full] [--strict] [--verbose] [--lost-found]\n" @@ -1065,6 +1080,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) check_connectivity(); + fsck_refs(); + if (the_repository->settings.core_commit_graph) { struct child_process commit_graph_verify = CHILD_PROCESS_INIT; From patchwork Sat Jul 20 09:28:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13737761 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 408541B86FD for ; Sat, 20 Jul 2024 09:28:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467725; cv=none; b=WXLbmcSi4abDqDcjurnWdQrhgC5lAHIOUDiVT4NbPLQd+0jwZwZXU5y8+zdYWZ2klv7Bj6+hWioh1u67LUdvdhtWCqyJVjOrSs/h93WA1LGcC/sCI6m3Mv6Qxl1Zo8RuYAgjZ0nOFXQmpvIYOK+Nu5Jsn82OQjj1KK9c2UtbnRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467725; c=relaxed/simple; bh=74LojJWDbW9OcMNx9RyPKjMV5xMTrr3rTVDU9xheogw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QHg14NHCEszK0TzmKHElNvr1yXUBrqQ4M6M4ZtvwQTl7GjFL3yRr8f0C4xbSx8dlKICf19KtTkJ6+jyBNzoZtM2lmgj1N+mN1kCLpGqqYAKcn2kaAydbgYMDVITC8d4roQswYRrb+xPmWe85xkKhlK8gT9YFVK3vRGqh1SezGUM= 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=khWu6mGL; arc=none smtp.client-ip=209.85.210.174 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="khWu6mGL" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-70d150e8153so49410b3a.0 for ; Sat, 20 Jul 2024 02:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721467723; x=1722072523; 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=OS2CkskgLXdpVTeUgcsIyFkMp5SUUYLcibIkpuXSC38=; b=khWu6mGLZ3U556B1JxB/AYU+EvRi69WYiFba1ifM6rZzw4t0HnAdOYf5SHnHUYyhOU qdguT2sB4VG/bPdQi1fTjRcUdm4qdCSvV8uTKE5XAQpsKP55jrbXsSSii+DCBg92Wr1c duVFvTWH7Q4X3UK7spbuc8VBoWHzb3nkB6x2qfPp+0MYiYSOG9uXR9jFH3ROndYIbE/P cXiyZRcGeUa5xe+wwTdiDbv04NTdXZA0/ECnR2lrvJOOqduQCMXBSeIBINxFG2/kYR0e 0bxE1lCN53476CfCWiMg4LSLzsbXjIMiPImz6mNsEOMMO8Lll/IK8EhAbOhtfZ3Qv+Xw EzJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721467723; x=1722072523; 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=OS2CkskgLXdpVTeUgcsIyFkMp5SUUYLcibIkpuXSC38=; b=C6KUcwbc0FfNsY1OdkGtMLEmU6iyyGeOWXF2iAhqEnt0yiNEOOGnlet6XJEzNASr7J q8z1AowRCepVcTCXiH5R2qkqg7BB+uY6pTWX8UUx60vZe9EVIjmXGy8R/Van01jIgTAI vSiBv2iCQ819OYhgjB3ZlqHmeALPCTMEHxloe4dCLl9QwFm/8uX5LVCsOAh4njtSmOHD 4Wm5ZsFPNCkQUumQd2M7c4LbZa2DSMXVtpaS9mahb+eh+Wa0LDg46JI2J8RVVvl5Qrc7 2FDbLCy8Icp8laNtAPyEUFjvshVP31j8mn2dInTbJQH98MREg/Sa9QIkNsc0T6wNHTDZ 0sYQ== X-Gm-Message-State: AOJu0Ywp1ih2bMaTW6PVa5elt/5090gfYqW8t8Sd8vmRcw/nfxeZpTcM BzANPL1v2ONq87CLvhNBCxzvQN7EOn+NVWiVEwhOztjyb8ThBCWakFw0xg== X-Google-Smtp-Source: AGHT+IHbu06Y/gzZg1/ZRYe1dODw4Ox2lm2d2PFb80Zj3xYeKq/O+rmZvYePShI606OxX6zRcrRi/A== X-Received: by 2002:aa7:8e05:0:b0:70c:e1ec:4233 with SMTP id d2e1a72fcca58-70cfd4e83d9mr6578014b3a.6.1721467722627; Sat, 20 Jul 2024 02:28:42 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70cff4b2e31sm2349190b3a.78.2024.07.20.02.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 02:28:42 -0700 (PDT) Date: Sat, 20 Jul 2024 17:28:53 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v12 08/10] 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 --- refs/files-backend.c | 77 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index d89eeda8ef..794e9f3f2e 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,6 +3409,78 @@ 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 fsck_options *o, + const char *gitdir, + 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_fns) +{ + const char *gitdir = ref_store->gitdir; + struct strbuf sb = STRBUF_INIT; + struct dir_iterator *iter; + int iter_status; + int ret = 0; + + strbuf_addf(&sb, "%s/%s", 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_fns[i]; i++) { + if (fsck_refs_fns[i](o, gitdir, refs_check_dir, iter)) + ret = -1; + } + } else { + ret = error(_("unexpected file type for '%s'"), + iter->basename); + } + } + + 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) +{ + int ret; + files_fsck_refs_fn fsck_refs_fns[]= { + NULL + }; + + if (o->verbose) + fprintf_ln(stderr, "Checking references consistency"); + + ret = files_fsck_refs_dir(ref_store, o, "refs", fsck_refs_fns); + + return ret; +} + static int files_fsck(struct ref_store *ref_store, struct fsck_options *o) { @@ -3415,7 +3488,9 @@ static int files_fsck(struct ref_store *ref_store, struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_READ, "fsck"); - ret = refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); + ret = refs->packed_ref_store->be->fsck(refs->packed_ref_store, o) + | files_fsck_refs(ref_store, o); + return ret; } From patchwork Sat Jul 20 09:29:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13737762 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 38B151B86FD for ; Sat, 20 Jul 2024 09:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467734; cv=none; b=M3EJxajkr/bfpOyIedjNxSThtgWnvpBqNBQvoA11TEMn6EeIWhQ7DOuSthtD6XzwiY1E9HhM72mWtMNbtuP7eDF7gFrlUrNJlmLoEpHnuBSUpd/pQutQsia/jV4U6IRkzTG2cLSJKu0HVjg5TP44IipnA8WZ3UmJAo2tCIL6kr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467734; c=relaxed/simple; bh=ItctcTAlm4Qeq0fEDyOsp2oQssNALOJYNHxWpwq6KmI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ctLIbjsWB2HKhydfyhjtMgbsBURB+Le58/vjpzdbmyKBzrClnmjS4nlnnnJWQq1IghH8EiEo3nPGboJAS2lRmzPDTOAICJiMfyd5PE//MW6csnmC9KJJ2QHfLpWkgoFcQoARjq9MV3A6Ke/mPVYBGhXedRkfbklVCmtKxyG10HM= 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=CnRUIMTl; arc=none smtp.client-ip=209.85.214.173 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="CnRUIMTl" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1fc56fd4de1so20360395ad.0 for ; Sat, 20 Jul 2024 02:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721467732; x=1722072532; 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=B5kHxxGKk1+5n5peuJEVysHe9LDxchpuRy3QHWJes0I=; b=CnRUIMTlqmI5XKFHcF5Qx8uZjMLzHx/kzqT0V/cngmK0t08gBqMg0b28sugkHNdNjD vmSRz4qXFp6obAiH0NmxayBobaIN13kDBr2l3dX7ZTnEhuoXukAgobLeVxx4v97Bj7b9 3ZsY43M23elpREV4tOxg1mZe9BQMWM1T7LYRxflzsItIGm8aEbH4wg2Zf2v7ZFEYsNHN XnaXFuQqRlCDOjySghdS/I9j8FzhNnFQjDSXaNTTCvIqTQeAJAbp5x+vZ6Qbq+Jw6J/d dCCTgI0LfowMq4xNFNsoHbFXhLpJTE0wM1+RJlgyrSKLSV/5MmWyWcRJW29x+qCCTlIR zDvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721467732; x=1722072532; 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=B5kHxxGKk1+5n5peuJEVysHe9LDxchpuRy3QHWJes0I=; b=FUliXSv4C7K1W5K5kj9k8WVe5vp4mEzNGVY4JmzOe7puL1+4yppY2Qmfln1G1Bwgg4 N9/+8AjtocpCAx6OZ+KKK17Q3N2N01zvsbmHrB0EvNTV9d5axqRU4WORRyk7EDsvr5tr odPI3hUZmnwe4C8YuPpFALxno1k2AaD+4jLHxUFzSM+JDan/FVySuJ3KK219rk4V8YJD H+1vsNwTYRg2QB4GMrQ5UmTMsFNsVnmbRD71GHMuhoE0d5mkHYXpV7lcy3jdd9/Zydje mRKHbtl+dhEAwKbvQr4r1DLCRCPW0E23ZoPMtvCBP8tymMuCFXEjnaE4gSWjHkS/P25f ORnQ== X-Gm-Message-State: AOJu0YzkYM8+yNfwPmVVkGkff4dK3Z+XCY1NHOJg7TnrUMVDfaoT/DSi Gl1bElPqhYZbLJ4xetx37Iha5tYciCPZQ0YMM2ukgDfRmsS06LBuDspbrA== X-Google-Smtp-Source: AGHT+IGiT8qvmX+tN0RO/GpS5X779xnCgy6dOOqXJI+wOUz2goY3jlntW0mS0xRJ6sUXvVAWNsD7dg== X-Received: by 2002:a17:903:2b06:b0:1f9:a69d:4e05 with SMTP id d9443c01a7336-1fc5b5ccf67mr131492235ad.19.1721467731853; Sat, 20 Jul 2024 02:28:51 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f290b0esm18251805ad.78.2024.07.20.02.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 02:28:51 -0700 (PDT) Date: Sat, 20 Jul 2024 17:29:02 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v12 09/10] 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 "@" and name ending with ".lock". 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 | 21 +++++++ t/t0602-reffiles-fsck.sh | 101 ++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100755 t/t0602-reffiles-fsck.sh diff --git a/Documentation/fsck-msgids.txt b/Documentation/fsck-msgids.txt index f643585a34..dab4012246 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. +`badRefName`:: + (ERROR) A ref has a bad name. + `badTagName`:: (INFO) A tag has an invalid format. diff --git a/fsck.h b/fsck.h index 98e2225593..421ec62b8f 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_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 794e9f3f2e..f93c44c4d1 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3419,6 +3419,26 @@ typedef int (*files_fsck_refs_fn)(struct fsck_options *o, const char *refs_check_dir, struct dir_iterator *iter); +static int files_fsck_refs_name(struct fsck_options *o, + const char *gitdir UNUSED, + const char *refs_check_dir, + struct dir_iterator *iter) +{ + struct strbuf sb = STRBUF_INIT; + int ret = 0; + + if (check_refname_format(iter->basename, REFNAME_ALLOW_ONELEVEL)) { + strbuf_addf(&sb, "%s/%s", refs_check_dir, iter->relative_path); + o->refs_info.ref_checkee = sb.buf; + ret = fsck_refs_report(o, NULL, + FSCK_MSG_BAD_REF_NAME, + "invalid refname format"); + } + + 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 +3490,7 @@ static int files_fsck_refs(struct ref_store *ref_store, { int ret; files_fsck_refs_fn fsck_refs_fns[]= { + 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..b2db58d2c6 --- /dev/null +++ b/t/t0602-reffiles-fsck.sh @@ -0,0 +1,101 @@ +#!/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-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 + ) && + ( + cd repo && + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && + test_must_fail git fsck 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 + ) && + ( + cd repo && + cp $tag_dir_prefix/tag-1 $tag_dir_prefix/tag-1.lock && + test_must_fail git fsck 2>err && + cat >expect <<-EOF && + error: refs/tags/tag-1.lock: badRefName: invalid refname format + EOF + rm $tag_dir_prefix/tag-1.lock && + test_cmp expect err + ) && + ( + cd repo && + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && + test_must_fail git fsck 2>err && + cat >expect <<-EOF && + error: refs/heads/@: badRefName: invalid refname format + EOF + rm $branch_dir_prefix/@ && + test_cmp expect err + ) && + ( + cd repo && + cp $tag_dir_prefix/multi_hierarchy/tag-2 $tag_dir_prefix/multi_hierarchy/@ && + test_must_fail git fsck 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 + ) +' + +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 + ) && + ( + cd repo && + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && + git -c fsck.badRefName=warn fsck 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 + ) && + ( + cd repo && + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && + git -c fsck.badRefName=ignore fsck 2>err && + test_must_be_empty err + ) +' + +test_done From patchwork Sat Jul 20 09:29:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13737763 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 D883F9449 for ; Sat, 20 Jul 2024 09:29:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467744; cv=none; b=qCQR/UOQCKQ8iWUh6WzDC4984AukZoTEEOaUJ0LLf5i5VBFITOvl5G1E4LCjcal5T8zkLIYRSJd9ATbKNX71WrEqyjofn5lEtDl4NPyAjVlwW0NRDqYb7EyCdKCbDmDn140hk6lxW7W2c+Mb42Ka9dPJJhAfa45QFkL4/I40RgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721467744; c=relaxed/simple; bh=zEIqZ8QuMn/eTEqeB5gt/m2UnOQVKir4zfh0g7CCWBc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TnGk3LKWO+pllnZl+ypV87BQ84siFJz7R+BLziQfokzXUNbe6wCXukl2OhecyCYJaPj0wbeU1KL+CJ3BL/12RMQ7xOKNuLqa7lYY7cVHcFnJDCQ1JSjnL6FxvNSwWAmi3bfcOcqjzRrMt2w2QNDSMA00G4ylEzma3bRBxbSWSBQ= 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=MMkv/RYa; arc=none smtp.client-ip=209.85.214.169 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="MMkv/RYa" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1fc658b6b2eso19419035ad.0 for ; Sat, 20 Jul 2024 02:29:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721467742; x=1722072542; 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=IeRuaLf+zIpMSwM7SJnbNcpQx01UU9MiODMtkNFpbu0=; b=MMkv/RYatuyg/q//fJA1i2D9A6PscqwavukwV+t3y0Trcj/qKuNnYQJUNMpNkF11NR tBK+LYBRUqvXLIblTyRdCVDyJCZO48gZr0zg0LULWbbEGEkZFwpAfZiT2QaoQ1UspRKO DPcIRD/iyJFQ4fB57o6WGEo519tVoFtzaSdS1FKqoTrEazl+jdA9jubAgTocmgbxTekk QPhrqYKtZcWNcwH8US+iGIQUaj9BL5bS0vVY4LKTy4SlAzpCRFs063qX5oIGEgM4EsWu sXLpGXjEEz7mmCqJ0bByF5tTFWUbThXy1aez9avb5NC4TFB4KezCBValQjyZ1xFdyBga ZA9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721467742; x=1722072542; 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=IeRuaLf+zIpMSwM7SJnbNcpQx01UU9MiODMtkNFpbu0=; b=A+sOKMDSTZ16Q5AjgGwvAYLBKgrNoMhgtB9FUr8IVt7usSqxrNLrMTQSW5xw1jHh+c mO3Awctwy5YKo6Ts63sYugD0qbMUXE5BEL0UNjUL2dEbIXrd5xE0dkbqiqReUE4m5OQX 3SecPGU+bEEMkpRGAhk4wxqcw/snzsgBbYB+0+9GktieOCbdvGYKEzSNAZTc6mCoAyop wrcFw7Ho1uIfphhvI6iIOvwa31Sd5VYaD76HVGQkE3DIZ4zE5LNNCnUgGRGKuGhFoj9N dPDkyoXHIsOCb/wDvLOV1Gb8dVBasDkb4z36igmdnvOX8yN1+hMKce0dHEvsFxdML577 bovQ== X-Gm-Message-State: AOJu0YzF0aggv8UCaVNPJrgMTkB2jbMql9WiDBuXDIPYzHNLM9A9bHIG fd1cq178Pkd7jX/eTv4jUY9UyKuv2qgjyeR6nkk0wwNGmsaupviaEjbGIQ== X-Google-Smtp-Source: AGHT+IFwrPcpJq2CaZVecWujtikhXeQO6ovIR3bXVt6F7uY4eAqGADAemPqqVI1bPPuuJWxxtLdupQ== X-Received: by 2002:a17:903:2286:b0:1fb:7e13:a7c5 with SMTP id d9443c01a7336-1fd7461fa40mr18536195ad.45.1721467741496; Sat, 20 Jul 2024 02:29:01 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fd6f25de80sm18229325ad.51.2024.07.20.02.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 02:29:01 -0700 (PDT) Date: Sat, 20 Jul 2024 17:29:12 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v12 10/10] fsck: add ref content 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: Enhance the git-fsck(1) command by adding a check for reference content in the files backend. The new functionality ensures that symrefs, real symbolic link and regular refs are validated correctly. In order to check the trailing content of the regular refs, add a new parameter `trailing` to `parse_loose_ref_contents`. For symrefs, `parse_loose_ref_contents` will set the "referent". However, symbolic link could be either absolute or relative. Use "strbuf_add_real_path" to read the symbolic link and convert the relative path to absolute path. Then use "skip_prefix" to make it align with symref "referent". Thus, the symrefs and symbolic links could share the same interface. Add a new function "files_fsck_symref_target" which aims at checking the following things: 1. whether the pointee is under the `refs/` directory. 2. whether the pointee name is correct. 3. whether the pointee path is a wrong type in filesystem. Last, add the following FSCK MESSAGEs: 1. "badRefContent(ERROR)": A ref has a bad content 2. "badSymrefPointee(ERROR)": The pointee of a symref is bad. 3. "trailingRefContent(WARN)": A ref content has trailing contents. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/fsck-msgids.txt | 9 +++ fsck.h | 3 + refs.c | 2 +- refs/files-backend.c | 142 +++++++++++++++++++++++++++++++++- refs/refs-internal.h | 5 +- t/t0602-reffiles-fsck.sh | 110 ++++++++++++++++++++++++++ 6 files changed, 266 insertions(+), 5 deletions(-) diff --git a/Documentation/fsck-msgids.txt b/Documentation/fsck-msgids.txt index dab4012246..b1630a478b 100644 --- a/Documentation/fsck-msgids.txt +++ b/Documentation/fsck-msgids.txt @@ -19,9 +19,15 @@ `badParentSha1`:: (ERROR) A commit object has a bad parent sha1. +`badRefContent`:: + (ERROR) A ref has a bad content. + `badRefName`:: (ERROR) A ref has a bad name. +`badSymrefPointee`:: + (ERROR) The pointee of a symref is bad. + `badTagName`:: (INFO) A tag has an invalid format. @@ -167,6 +173,9 @@ `nullSha1`:: (WARN) Tree contains entries pointing to a null sha1. +`trailingRefContent`:: + (WARN) A ref content has trailing contents. + `treeNotSorted`:: (ERROR) A tree is not properly sorted. diff --git a/fsck.h b/fsck.h index 421ec62b8f..adc88e01c7 100644 --- a/fsck.h +++ b/fsck.h @@ -32,6 +32,8 @@ enum fsck_msg_type { FUNC(BAD_OBJECT_SHA1, ERROR) \ FUNC(BAD_PARENT_SHA1, ERROR) \ FUNC(BAD_REF_NAME, ERROR) \ + FUNC(BAD_REF_CONTENT, ERROR) \ + FUNC(BAD_SYMREF_POINTEE, ERROR) \ FUNC(BAD_TIMEZONE, ERROR) \ FUNC(BAD_TREE, ERROR) \ FUNC(BAD_TREE_SHA1, ERROR) \ @@ -72,6 +74,7 @@ enum fsck_msg_type { FUNC(HAS_DOTDOT, WARN) \ FUNC(HAS_DOTGIT, WARN) \ FUNC(NULL_SHA1, WARN) \ + FUNC(TRAILING_REF_CONTENT, WARN) \ FUNC(ZERO_PADDED_FILEMODE, WARN) \ FUNC(NUL_IN_COMMIT, WARN) \ FUNC(LARGE_PATHNAME, WARN) \ diff --git a/refs.c b/refs.c index 410919246b..eb82fb7d4e 100644 --- a/refs.c +++ b/refs.c @@ -1760,7 +1760,7 @@ static int refs_read_special_head(struct ref_store *ref_store, } result = parse_loose_ref_contents(content.buf, oid, referent, type, - failure_errno); + failure_errno, NULL); done: strbuf_release(&full_path); diff --git a/refs/files-backend.c b/refs/files-backend.c index f93c44c4d1..d8712269f1 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1,6 +1,7 @@ #define USE_THE_REPOSITORY_VARIABLE #include "../git-compat-util.h" +#include "../abspath.h" #include "../copy.h" #include "../environment.h" #include "../gettext.h" @@ -553,7 +554,7 @@ static int read_ref_internal(struct ref_store *ref_store, const char *refname, strbuf_rtrim(&sb_contents); buf = sb_contents.buf; - ret = parse_loose_ref_contents(buf, oid, referent, type, &myerr); + ret = parse_loose_ref_contents(buf, oid, referent, type, &myerr, NULL); out: if (ret && !myerr) @@ -589,7 +590,7 @@ static int files_read_symbolic_ref(struct ref_store *ref_store, const char *refn int parse_loose_ref_contents(const char *buf, struct object_id *oid, struct strbuf *referent, unsigned int *type, - int *failure_errno) + int *failure_errno, const char **trailing) { const char *p; if (skip_prefix(buf, "ref:", &buf)) { @@ -611,6 +612,10 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid, *failure_errno = EINVAL; return -1; } + + if (trailing) + *trailing = p; + return 0; } @@ -3439,6 +3444,138 @@ static int files_fsck_refs_name(struct fsck_options *o, return ret; } +/* + * Check the symref "pointee_name" and "pointee_path". The caller should + * make sure that "pointee_path" is absolute. For symbolic ref, "pointee_name" + * would be the content after "refs:". For symblic link, "pointee_name" would + * be the relative path agaignst "gitdir". + */ +static int files_fsck_symref_target(struct fsck_options *o, + const char *refname, + const char *pointee_name, + const char *pointee_path) +{ + const char *p = NULL; + struct stat st; + int ret = 0; + + if (!skip_prefix(pointee_name, "refs/", &p)) { + + ret = fsck_refs_report(o, NULL, + FSCK_MSG_BAD_SYMREF_POINTEE, + "point to target out of refs hierarchy"); + goto out; + } + + if (check_refname_format(pointee_name, 0)) { + ret = fsck_refs_report(o, NULL, + FSCK_MSG_BAD_SYMREF_POINTEE, + "point to invalid refname"); + } + + if (lstat(pointee_path, &st) < 0) + goto out; + + if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) { + ret = fsck_refs_report(o, NULL, + FSCK_MSG_BAD_SYMREF_POINTEE, + "point to invalid target"); + goto out; + } +out: + return ret; +} + +static int files_fsck_refs_content(struct fsck_options *o, + const char *gitdir, + const char *refs_check_dir, + struct dir_iterator *iter) +{ + struct strbuf pointee_path = STRBUF_INIT, + ref_content = STRBUF_INIT, + abs_gitdir = STRBUF_INIT, + referent = STRBUF_INIT, + refname = STRBUF_INIT; + const char *trailing = NULL; + int failure_errno = 0; + unsigned int type = 0; + struct object_id oid; + int ret = 0; + + strbuf_addf(&refname, "%s/%s", refs_check_dir, iter->relative_path); + o->refs_info.ref_checkee = refname.buf; + + /* + * If the file is a symlink, we need to only check the connectivity + * of the destination object. + */ + if (S_ISLNK(iter->st.st_mode)) { + const char *pointee_name = NULL; + + strbuf_add_real_path(&pointee_path, iter->path.buf); + + strbuf_add_absolute_path(&abs_gitdir, gitdir); + strbuf_normalize_path(&abs_gitdir); + if (!is_dir_sep(abs_gitdir.buf[abs_gitdir.len - 1])) + strbuf_addch(&abs_gitdir, '/'); + + if (!skip_prefix(pointee_path.buf, + abs_gitdir.buf, &pointee_name)) { + ret = fsck_refs_report(o, NULL, + FSCK_MSG_BAD_SYMREF_POINTEE, + "point to target outside gitdir"); + goto clean; + } + + ret = files_fsck_symref_target(o, refname.buf, pointee_name, + pointee_path.buf); + goto clean; + } + + if (strbuf_read_file(&ref_content, iter->path.buf, 0) < 0) { + ret = error_errno(_("%s/%s: unable to read the ref"), + refs_check_dir, iter->relative_path); + goto clean; + } + + if (parse_loose_ref_contents(ref_content.buf, &oid, + &referent, &type, + &failure_errno, &trailing)) { + ret = fsck_refs_report(o, NULL, + FSCK_MSG_BAD_REF_CONTENT, + "invalid ref content"); + goto clean; + } + + /* + * If the ref is a symref, we need to check the destination name and + * connectivity. + */ + if (referent.len && (type & REF_ISSYMREF)) { + strbuf_addf(&pointee_path, "%s/%s", gitdir, referent.buf); + strbuf_rtrim(&referent); + + ret = files_fsck_symref_target(o, refname.buf, referent.buf, + pointee_path.buf); + goto clean; + } else { + if (trailing && (*trailing != '\0' && *trailing != '\n')) { + ret = fsck_refs_report(o, NULL, + FSCK_MSG_TRAILING_REF_CONTENT, + "trailing garbage in ref"); + goto clean; + } + } + +clean: + strbuf_release(&abs_gitdir); + strbuf_release(&pointee_path); + strbuf_release(&refname); + strbuf_release(&ref_content); + strbuf_release(&referent); + return ret; +} + static int files_fsck_refs_dir(struct ref_store *ref_store, struct fsck_options *o, const char *refs_check_dir, @@ -3491,6 +3628,7 @@ static int files_fsck_refs(struct ref_store *ref_store, int ret; files_fsck_refs_fn fsck_refs_fns[]= { files_fsck_refs_name, + files_fsck_refs_content, NULL }; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index a905e187cd..2fabf41d14 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -709,11 +709,12 @@ struct ref_store { /* * Parse contents of a loose ref file. *failure_errno maybe be set to EINVAL for - * invalid contents. + * invalid contents. Also *trailing is set to the first character after the + * refname or NULL if the referent is not empty. */ int parse_loose_ref_contents(const char *buf, struct object_id *oid, struct strbuf *referent, unsigned int *type, - int *failure_errno); + int *failure_errno, const char **trailing); /* * Fill in the generic part of refs and add it to our collection of diff --git a/t/t0602-reffiles-fsck.sh b/t/t0602-reffiles-fsck.sh index b2db58d2c6..35bf40ee64 100755 --- a/t/t0602-reffiles-fsck.sh +++ b/t/t0602-reffiles-fsck.sh @@ -98,4 +98,114 @@ test_expect_success 'ref name check should be adapted into fsck messages' ' ) ' +test_expect_success 'regular ref content 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 checkout -b a/b/tag-2 + ) && + ( + cd repo && + printf "%s garbage" "$(git rev-parse branch-1)" > $branch_dir_prefix/branch-1-garbage && + git fsck 2>err && + cat >expect <<-EOF && + warning: refs/heads/branch-1-garbage: trailingRefContent: trailing garbage in ref + EOF + rm $branch_dir_prefix/branch-1-garbage && + test_cmp expect err + ) && + ( + cd repo && + printf "%s garbage" "$(git rev-parse tag-1)" > $tag_dir_prefix/tag-1-garbage && + test_must_fail git -c fsck.trailingRefContent=error fsck 2>err && + cat >expect <<-EOF && + error: refs/tags/tag-1-garbage: trailingRefContent: trailing garbage in ref + EOF + rm $tag_dir_prefix/tag-1-garbage && + test_cmp expect err + ) && + ( + cd repo && + printf "%s " "$(git rev-parse tag-2)" > $tag_dir_prefix/tag-2-garbage && + git fsck 2>err && + cat >expect <<-EOF && + warning: refs/tags/tag-2-garbage: trailingRefContent: trailing garbage in ref + EOF + rm $tag_dir_prefix/tag-2-garbage && + test_cmp expect err + ) && + ( + cd repo && + printf "xfsazqfxcadas" > $tag_dir_prefix/tag-2-bad && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/tags/tag-2-bad: badRefContent: invalid ref content + EOF + rm $tag_dir_prefix/tag-2-bad && + test_cmp expect err + ) && + ( + cd repo && + printf "xfsazqfxcadas" > $branch_dir_prefix/a/b/branch-2-bad && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/a/b/branch-2-bad: badRefContent: invalid ref content + EOF + rm $branch_dir_prefix/a/b/branch-2-bad && + test_cmp expect err + ) +' + +test_expect_success 'symbolic ref content 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 + ) && + ( + cd repo && + printf "ref: refs/heads/.branch" > $branch_dir_prefix/branch-2-bad && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/branch-2-bad: badSymrefPointee: point to invalid refname + EOF + rm $branch_dir_prefix/branch-2-bad && + test_cmp expect err + ) && + ( + cd repo && + printf "ref: refs/heads" > $branch_dir_prefix/branch-2-bad && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/branch-2-bad: badSymrefPointee: point to invalid target + EOF + rm $branch_dir_prefix/branch-2-bad && + test_cmp expect err + ) && + ( + cd repo && + printf "ref: logs/maint-v2.45" > $branch_dir_prefix/branch-2-bad && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/branch-2-bad: badSymrefPointee: point to target out of refs hierarchy + EOF + rm $branch_dir_prefix/branch-2-bad && + test_cmp expect err + ) +' + test_done