From patchwork Wed Jul 10 14:46:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13729428 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.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 C666B20312 for ; Wed, 10 Jul 2024 14:46:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622800; cv=none; b=TMcsURgWmL6B/XxuZZ1JAVGfwKkCThNO3O8xmyxqLmcnUKa/jBgNDxwPZez7sfakUKjDlrSiwKH55w9Viz9RRCI9RgtKw01MtVDmm6xSyymBJ7Kr0HKUsGMahmfdtFCuexe9vVsmvb8BBBfZzteSM9jfjmBF4BUleeW4FliZyOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622800; 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=Eq/I1sueAvnyfGQTTbksOShB5tNSxnMYA4oFoHrSorsmpY+iFA6kLu0PzbJ2kLW7Rw0EE7MApreGEz3Ih3v/F08t2l+evLBHBJsa/yn6m0jjQEfxI+4pEdL71IS5GN4iB0TV1cGJMMfWMSKqYiSilZybXBrk8EvqiSx6n8Ne2Hs= 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=VAMtWTe5; arc=none smtp.client-ip=209.85.210.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="VAMtWTe5" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70b42250526so2045183b3a.1 for ; Wed, 10 Jul 2024 07:46:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720622797; x=1721227597; 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=VAMtWTe5DiSvfPQ2SgA9eIl8guTAWbLjTvmluXdyCBkoX7NN6rlhS+js+qwPNmUj22 miy0mULUgcsH3LNQ/KPaed/lIch31gNgKOWLhzeJ/fH0f5/kYxZwcrd+iuEOj2izsnoy KT47NHJTKVsSCbRhB6SuSzKMG/hBxHg4UTSKJPznKlWVB9yF7zRal3vAfCpYCZd+WZD0 VB2fN26GWnEQ4eWYkeBvgvR4bejLd2cQ6ivrXPhkoCWZjqdGnWj2cYh2aSwDZljq35YA 5xDnsbRQjRayW8uWNRL5/46V5crV/lkybn9puDHxuZvlJzU/Vh4SyOOJHOrxgYhyBU1o UHjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720622797; x=1721227597; 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=nbWufsFHqDyb97S+Td4LpBXEYGjC4UYBGSudpQGxPJDXR4fyDETKDvjb/je+5pbF8m FrgOTsKIZoYKkWAezo6ZfQEyoN01U8e9D3Ibsa4j/FQOHFUVaP/kvI9g3GwthQwBIWRW P5qtbf0vdcMItp7Yeg8XgBIxyFrVkr/5d6/K8ODqqITNOo/zECbl6xGqcwJcSGKU/CkM +ZDTA1GlWdnvM/AN6/TbWYJeOCodxDPoEBJ29XPM5qGrnVspIhvCWOKOmh3qly9D7+Gh LxpAuV6i21Eq5bpkEOj7AjkuHQk9FvzFCGH33moi9+HwChLuTBdKHtZlK+z55CDIrIWU km8w== X-Gm-Message-State: AOJu0YwqGsRK7+K2qbPb1HuU0VXQLE5y7EcRHlSyMdBg0WOq4fBu+VF0 XsvQBhgnLjdhpUFHIqdR7bNv3O7sr3Be0S+NPI1c7O0WWT6RVjrNfIW8Uw== X-Google-Smtp-Source: AGHT+IF2HU/pK4TQMIOSnlkcehQGnoC+vugU90GtlmP8uE+vNNToZolLdZa+Tqq+IV7nkr9rAnI8yw== X-Received: by 2002:a05:6a00:1748:b0:706:8066:5cdf with SMTP id d2e1a72fcca58-70b435e9912mr5742722b3a.21.1720622797175; Wed, 10 Jul 2024 07:46:37 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b4389bc22sm3876550b3a.44.2024.07.10.07.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 07:46:36 -0700 (PDT) Date: Wed, 10 Jul 2024 22:46:37 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v10 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 Wed Jul 10 14:46:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13729429 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.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 5793FBE4E for ; Wed, 10 Jul 2024 14:46:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622815; cv=none; b=sNjkO8bW59guPe70QSInC4HwaMEU2KFg90kboRWb5xCycNEKtInbJWNXzwLiXxVevuONY+FlZtMej2j0xl6WFm02N4981hDLHDNHzAlVyrg64/wDueiQitZ73W7mcf2fF2QLBFYUcJJhkrz1tWJRpJWUjW5nWuDOt+DI6bz2+jc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622815; c=relaxed/simple; bh=IBr4NobRpuFMjVd1HoOD9dYC8M+4JV9Zog46fOPjZrg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Q3aGFRLx3MwtmHXG12jdUlCwgLLIhUGd4a9imVRmMi1IxyEKUJnQkWDIDBC4pd1ttcX+8IORuJ3iPeMBd/FH6wSakcj8J/69LLF4tmIw4yYaLSCCCZi7YLFtSU8+OAbw+I+rj7mtJ0qxDQZV/EyhX6aVfJ91R1vmna2XTumLmGc= 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=AHZrbzlF; arc=none smtp.client-ip=209.85.214.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="AHZrbzlF" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1fb1ff21748so35242845ad.3 for ; Wed, 10 Jul 2024 07:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720622813; x=1721227613; 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=TBvBSuUQTn5VA33azNMPlZF/fcfIqgux26YadIbziCs=; b=AHZrbzlF9XEym4f+Ux79f7Q/50DIoFwBuOmgRZiaNS3t6gwzqCcS4mbzjIaq6erS/4 /31Sig0aSBXMMGTxgsgPMCF1EW+cxuME6rnUVVh6AVsUFd6XzQPCZxsh3cj9VnDg6hMn sMSoYJYhvBg0mb0F2ytLvwQ0MxUbw5YDu3tK+3/VkDHZnb6bTuOLoxNYTN03XKSYGwTr xUhSbZXUEQ4XuCJbs0CQ0VQIWpRxO/U2kNM1eOb3yFe3eDnZnuT3bOOv9XP7eZRdTH99 18+gGekKM/2tHNAsxMjpAQV/pbNfycgVD9XsnqCY0lKVaScBJ1WgjifGNT+8QIs/Acn2 4K5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720622813; x=1721227613; 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=TBvBSuUQTn5VA33azNMPlZF/fcfIqgux26YadIbziCs=; b=B4yDoRBt8hS6xDqefBFAWPHKYpde1MfRs45wcnchRqo6VZYZ8LfqY3mf23/L9FyNTL efEf6PG9S6XNU2/9rkOgpDZr32pW/y8SFFER5n6zhlWnOxZsND+lVDg4WvJbcYCWw64j IWgcce0uqO12ofHXjjpQeY84sU4Ff6dbIgFl1ek+oX/rrGc2USYAPkwI5+xekuub3tyr 5YOzNrj9qqpeN3EL0MGQttZF/B5aeIsildqfw2GEfGkkeSdP9KdR0Lh11hacqFWZuNop zalypdttyhUcr3xLva5+VsMeaSfkoQdblzHqDIBjr6ikosjYi+z4oOCOwbJ5q/dWcRxa 7wMA== X-Gm-Message-State: AOJu0Yyb+lEThwrVH9/B4WdrDMNW2LjhDTzqg70DiG3Y0ckiWK3dwjUW CqlF3Aw1wWAhxFMuqujdlYulsHg4mRG1oKgYNWxU2wtkMeNKvnOQE79+og== X-Google-Smtp-Source: AGHT+IGdneZ5R240PN5AHe1Kf1P08zT9AjZS9QTFNPL5dZHLBMcLHQh72bvKFfXrNNzyy/c4IjzpCA== X-Received: by 2002:a17:902:ec8a:b0:1fb:9b91:d7db with SMTP id d9443c01a7336-1fbb6d3d3b6mr56920075ad.19.1720622813114; Wed, 10 Jul 2024 07:46:53 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6ac4812sm34642705ad.226.2024.07.10.07.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 07:46:52 -0700 (PDT) Date: Wed, 10 Jul 2024 22:46:53 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v10 02/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 are going to introduce refs database check. In order to avoid ambiguity, rename objects-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 3f32441492..0aaff7f635 100644 --- a/fsck.c +++ b/fsck.c @@ -1200,12 +1200,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); @@ -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 Wed Jul 10 14:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13729430 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 DCC1E20312 for ; Wed, 10 Jul 2024 14:47:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622829; cv=none; b=ebtelvA8/pUXYUQum7OTLbR5V0LCyUkv5LnXekHxFV9I+24Jx7QndcJunFQkFUOKd6cEKw6KhdzAWyWwej60ubi0aFKAKUwSNii7UE5V52SK6dW5OqCSYK3eLensSvqME6YZhwOw+X4DqFQ9Irhfh7CW7DZbTzU8AwPN9GE0uk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622829; c=relaxed/simple; bh=BKzhepDcYVwoFgmS2FyQgAmUFL24H9/LTkXDKtYwQ0w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=K92mO8YS3vSiO4SJTfiOeZdZLTFh4y4ukeuPeiVl6u+zorsTdxh6RJn1G0GKe7Cr075WWXahBKmmNs8vwoNaOvQqoOGJE/PHWOw6hs8mN0aHDScrrcB9sxgywDNvqPHJlQQLq6uTn/bSnt2qQWOr5pHUR2qZln7/Cpq6EMRDy5Q= 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=Emho79Ck; arc=none smtp.client-ip=209.85.214.171 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="Emho79Ck" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fb64d627b0so22121205ad.0 for ; Wed, 10 Jul 2024 07:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720622827; x=1721227627; 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=ae8m2EBfWBW2Zzi/3R7qemJxNOx8Gz9LCWYj9bXbtTw=; b=Emho79CkEuGZf+CjyQ26yX+Yz9s9ft6fL1Pl4d4QmZbEACnnTdN6jfRpreon/uVmvX CRMPwrRy4yqpw6yeA9d6A4SToc+PLLmcLmHX1+LnfAxWOXflB+oSubKMTT1iqq4novtY S0R/6dQyLQ+rV/J0F3yYZ3oA6kinVdVoHPSJC+uA3kXvw2eKyYuqSFyVJixkWj4ig7Qd UgzsGgDg5KC8RHXs5ISN5rPk8exU6efK5hYdehLXki2WEGpYlkm81GrbrevKeahAaLS4 HcvjdvACU5c/4kM1yN5UE2U/mP1GKjr6TORmLi54h+5bdH+xJvIMnBASux+rkYBhqI6b 9saw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720622827; x=1721227627; 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=ae8m2EBfWBW2Zzi/3R7qemJxNOx8Gz9LCWYj9bXbtTw=; b=SPjvI35iHhXw6TzZpg7KF3ZJ61a0YlnaY5eWPFwi1zzJd3Hor/yv44b5SccPUOq1/Q 4z2CXiCkWA4+GaMMo8eJBjELlmuWYSbq4yUGRnVIWuSY+27qVBq3amma48wKWAQwXC4S ieZZ9C1KxXzKLhuhCI8RBT4UrsCmce9HX5CruRs0xJHsWZO7dWUWbaHX1snh8+jBgimO hHgHB5xCG5fuY7zlhLCbNDxcIig1EZStLYVMt6W5HL9zMnx0zmrT1vqHxS5fK/72nIR0 X7De4+m+3wVnVyoliHCDNVcjD1NqILmOSPvbpH/bG41diB71dMeqMvTo/+G44qHClxa8 OYcA== X-Gm-Message-State: AOJu0Yx9yus71m2NQcR8OcwoJIJow4nMjCbksOvscHl3xvLG7wslfAcq SUhmaA9vxi6TBFb0VQXyOYrDcL2kZpL0KXxwuLaicDoyizvsY8oL3SHuCA== X-Google-Smtp-Source: AGHT+IFxBVbwCSqdNIfOpOi212qYAbqz9x/N29O2+WX6zFww2TbPT4dcpZVfcPWfxcqBtjj+CqeSfg== X-Received: by 2002:a17:902:d552:b0:1fb:90bd:afc2 with SMTP id d9443c01a7336-1fbb6d2516emr40383665ad.36.1720622826637; Wed, 10 Jul 2024 07:47:06 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6acf63fsm34394795ad.268.2024.07.10.07.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 07:47:06 -0700 (PDT) Date: Wed, 10 Jul 2024 22:47:07 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v10 03/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 "vfsck_report" by adding "checked_ref_name" parameter following the "report" prototype. Instead of using "...", provide "va_list" to allow more flexibility. Like "report", the "vfsck_report" function will use "error_func" registered in "fsck_options" to report customized messages. Change "error_func" prototype to align with the new "vfsck_report". Then, change "report" function to use "vfsck_report" to report objects related messages. Add a new function called "fsck_refs_report" to use "vfsck_report" to report refs related messages. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- builtin/fsck.c | 1 + builtin/mktag.c | 1 + fsck.c | 56 +++++++++++++++++++++++++++++++++++++++++-------- fsck.h | 17 ++++++++++++++- object-file.c | 11 +++++----- 5 files changed, 71 insertions(+), 15 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 6d86bbe1e9..de34538c4f 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -92,6 +92,7 @@ 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, + const char *checked_ref_name UNUSED, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id UNUSED, const char *message) diff --git a/builtin/mktag.c b/builtin/mktag.c index 4767f1a97e..42f945c584 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -20,6 +20,7 @@ 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, + const char *checked_ref_name 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 0aaff7f635..e1819964e3 100644 --- a/fsck.c +++ b/fsck.c @@ -226,12 +226,18 @@ 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 vfsck_report(struct fsck_options *options, + const struct object_id *oid, + enum object_type object_type, + const char *checked_ref_name, + 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,9 +256,9 @@ 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, oid, object_type, + va_copy(ap_copy, ap); + strbuf_vaddf(&sb, fmt, ap_copy); + result = options->error_func(options, oid, object_type, checked_ref_name, msg_type, msg_id, sb.buf); strbuf_release(&sb); va_end(ap); @@ -260,6 +266,36 @@ 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 = vfsck_report(options, oid, object_type, NULL, + msg_id, fmt, ap); + va_end(ap); + return result; +} + + + +int fsck_refs_report(struct fsck_options *options, + const struct object_id *oid, + const char *checked_ref_name, + enum fsck_msg_id msg_id, const char *fmt, ...) +{ + va_list ap; + int result; + va_start(ap, fmt); + result = vfsck_report(options, oid, OBJ_NONE, + checked_ref_name, msg_id, fmt, ap); + va_end(ap); + return result; +} + void fsck_enable_object_names(struct fsck_options *options) { if (!options->object_names) @@ -1203,6 +1239,7 @@ 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, + const char *checked_ref_name UNUSED, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id UNUSED, const char *message) @@ -1306,6 +1343,7 @@ 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, + const char *checked_ref_name, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message) @@ -1314,6 +1352,6 @@ int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, puts(oid_to_hex(oid)); return 0; } - return fsck_objects_error_function(o, oid, object_type, + return fsck_objects_error_function(o, oid, object_type, checked_ref_name, msg_type, msg_id, message); } diff --git a/fsck.h b/fsck.h index 41ebebbb59..f88e5faa94 100644 --- a/fsck.h +++ b/fsck.h @@ -114,19 +114,24 @@ 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, + const char *checked_ref_name, 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, + const char *checked_ref_name, 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, + const char *checked_ref_name, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); @@ -209,6 +214,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, 5, 6))) +int fsck_refs_report(struct fsck_options *options, + const struct object_id *oid, + const char *checked_ref_name, + enum fsck_msg_id msg_id, + const char *fmt, ...); + /* * Subsystem for storing human-readable names for each object. * diff --git a/object-file.c b/object-file.c index 065103be3e..d2c6427935 100644 --- a/object-file.c +++ b/object-file.c @@ -2470,11 +2470,12 @@ 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) + const struct object_id *oid UNUSED, + enum object_type object_type UNUSED, + const char *ref_checked_name 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 Wed Jul 10 14:47:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13729431 Received: from mail-io1-f48.google.com (mail-io1-f48.google.com [209.85.166.48]) (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 9A7AC15E97 for ; Wed, 10 Jul 2024 14:47:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622843; cv=none; b=BWclkgkKJTa2usXvUeRMA5lW2UKhrEst48jVZWwMrT2q5Aa4hqh40WgQoMq9SwRNRhK649BVCOkuCgt107XmXNGZ5/J0KYYQXEWiRSasKSalfqKuJ1iwdQTodVQWcuegB8Py26yJ4du0BFZV7k+0+trepSwNtch7WTgNGuI8kro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622843; c=relaxed/simple; bh=d22MuLqwwGwy4T1ex88Ppxiz9N5B9QWDXhD3St/OXYo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kLY32mPAbujIT/Y4fEXiQuzKBSAK/i7kcj9bGCMa6GfxlvjI68p41YLoDjaZCn+c4WFC84WkRfXwhBzOf+5+tJZfZ41UGamDD/kRygTDxp5V13ybuB3SYMCfhJhM21WWL9A7W5PdyTiV1SMVYKJy9M5EMDC76gLfBocan57+y3M= 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=K5dUeFhM; arc=none smtp.client-ip=209.85.166.48 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="K5dUeFhM" Received: by mail-io1-f48.google.com with SMTP id ca18e2360f4ac-7f70a708f8aso194351539f.2 for ; Wed, 10 Jul 2024 07:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720622840; x=1721227640; 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=huRw9gOLam/UdXn7OYApFuO/P191l4s0XsIrfqxFHxg=; b=K5dUeFhMmvTWIg8sslMRW+ZDD+FGW79omdySRqjoZyqS20MxF1UIJ3HgzH/t1NFaR7 6W2DZoX4mQEwhXT1qx9EKqvSJ6gwwZToSuyfEEnUEAOR0Phf4T4+ui+fHch+oiKNwmz+ 23c+RSu/hTgqQZnoQp9wTuh7j9AHFqyM9pzqfZVF+zvvm89Q9diVGy2/fWvU8LTKmLWG 3Fl36cuh9HjMANGUgndaX/saVp3N/V7L8zfqID1ZMHermiCIA3Gujish08C/+J4t2HGD oMUG3ISDGLx8//H5x8p4zmFQ+lkepc8n7feprn9KpWS3LM2F0I2/Lo66TkJqOye7KeJ6 yARA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720622840; x=1721227640; 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=huRw9gOLam/UdXn7OYApFuO/P191l4s0XsIrfqxFHxg=; b=fH3m9KFwCTqMoo5rVRGZkvtTBDNnjll/ggASpMQ3sVwExO/HJSskpvOAd5TX+4o93t 8NgmPcAx66s2CwZqWMT8R2f56tvYIz/vvq+4HVin9cijfK0U2V4YDKLZE2gRay7lJIXn sV1sHXd1mUhcPG8dq1l8XqiEgX6dBTHLvPjqYOAQhrrRI1fJVEQOJkF8o2Heo1zvckfS eE6HEv4YebGuRGJhMnYrwKHZCIrmwZ1qdRsDSNjYlPjvubQOudtEWxDtkc7/XzfVqvOv X5eS0IxDaTRjqPnszBNN5RSF85hHDEIQuj9IBU3TYhdBM/plO+OD8ECvTtrvJlQ4+0vx 8PBw== X-Gm-Message-State: AOJu0YyLrZU7jl5OVU2hd74GIQsPICuND3Bp0b3WwHAEqBg7DgR3vR1o VIq8mOh34BZoXImGTbTRFZaIk84GfdPtNDYI8OV6kUIKuWbnXKnWA61I4w== X-Google-Smtp-Source: AGHT+IHzgOJ9+HC/IOMXLmsS+fmuBSHQnRHf7G2U1GHdI4L7V9AcUWFQCIjKKX6WXJJ50fpU7jXCkw== X-Received: by 2002:a05:6602:1581:b0:7fb:86c:321 with SMTP id ca18e2360f4ac-7fffe62c346mr813851539f.1.1720622840288; Wed, 10 Jul 2024 07:47:20 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-77d60117b61sm3024581a12.22.2024.07.10.07.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 07:47:19 -0700 (PDT) Date: Wed, 10 Jul 2024 22:47:21 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v10 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: Add refs-related options to the "fsck_options", create refs-specific "error_func" callback "fsck_refs_error_function". "fsck_refs_error_function" will use the "oid" parameter. When 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 | 24 ++++++++++++++++++++++++ fsck.h | 14 ++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/fsck.c b/fsck.c index e1819964e3..f14ac533b0 100644 --- a/fsck.c +++ b/fsck.c @@ -1252,6 +1252,30 @@ int fsck_objects_error_function(struct fsck_options *o, return 1; } +int fsck_refs_error_function(struct fsck_options *options UNUSED, + const struct object_id *oid, + enum object_type object_type UNUSED, + const char *checked_ref_name, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id UNUSED, + const char *message) +{ + struct strbuf sb = STRBUF_INIT; + int ret = 0; + + strbuf_addstr(&sb, checked_ref_name); + 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 f88e5faa94..fe5d4d2ad9 100644 --- a/fsck.h +++ b/fsck.h @@ -135,6 +135,13 @@ 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, + const char *checked_ref_name, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message); struct fsck_options { fsck_walk_func walk; @@ -173,6 +180,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 Wed Jul 10 14:47:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13729432 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.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 BD30FBE4E for ; Wed, 10 Jul 2024 14:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622857; cv=none; b=jqU58vJYnOoXooneKn3uZYQTTl6F8IM6E5y9tM8RTEHBBG92BRuxVkaRwoq+MCW1ZjcMyhMwDYdY8A6AyGQeLM3bsopfG8DnXu5taf7sbA/zM4IhWrPAgm1EWbcla3AWrJSqc5DTRGOVZoYaqJYuDe7Ra+/Lq+W0+3WBqQ9ITwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622857; c=relaxed/simple; bh=Xaf9riBzozmCKz1H0udrYwbdPauR82bQALqKOtzPJvU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rUISicZFnPqcFrZP4X1NcfjudUuucPkLNs+hIFBTTjA+Gg8CL6gPH9qahTIF/yyIXJXi+w8l32hVv5vRsXaZaqi3tbxjkhEtMidYO9XiFB6qT+QPEuoZRYgAqK40Ye0rqmFqSU1+8aBFNbk/1G1okbxrKbZK2PAN/YUYDwOWuts= 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=BqXRtXmS; arc=none smtp.client-ip=209.85.214.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="BqXRtXmS" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1fb1ff21748so35250025ad.3 for ; Wed, 10 Jul 2024 07:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720622854; x=1721227654; 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=BqXRtXmStgt5VB/jo+QKvj7lM70iathztv45Jk6lIatqJf75F5//k7wahR3Bx41rzU mzEfRGLema1ps5A/UePtgewyrUeIwqIHLrm/eHjw9CU2EFUoL8rr5zeTYbc8HdZ69ubL SjTtnZKDYEb/T/DhmQlP0p7juJsnZUgZmGdBbYeCZ2/poqw/2WRBjP9sY5p3H9M4z9MV /69Vn71HqV0BVYAeS445SD5z0n9wF2kjx9JS8nSMLYaXskbRxM4kBDlB+Bm/wqIDKs3l 14r979LYDRHTQWEmKFQLjmWeXDHPpvT6ya5auuK+OQ8BDsT4dF2b8DG55RcSQN3PelxV vl3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720622854; x=1721227654; 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=abYOiP1y/6f2rx5ZEAdtlfsRKviKcvRk28Xlcjv9xDFlwaVw2QkFRw8di3GYhzhQWE 4cdW4pq0twJoqVqN6oMGFf8PTVCn/R9drJ1u5eIpDh40I0prvd0+nJflU/Xp2LFH/zFh WdEeUwRx2UnWbHy1Hr3soeehy7+iQtjENvlUtzkxs5t45wLPxBL3JiTFbGFVoTs593/f 0ZbjpRaseR06UIxYjUUgsbzRzieV+LFFnvRXWVM+nzKQeJPSA9Cxdt91R9c+jMGaZF5M wHICs4D8yPIzVJQuaJ3xAGbUQa7uw/ez4eQjZEuFxNKSYJgZpnEu/KWDbO+ec1ivd4Au JJUA== X-Gm-Message-State: AOJu0YyndGbkIqqptxqaBYrV5UfxSwc+Udegok84yEvEZAYk6PsVp/Wu LmBG2cpP0FWllGwldut31IlChtcjEm+Ys2KtFe6hoGi7YgmicmcvFccwEA== X-Google-Smtp-Source: AGHT+IGJjlxZOVcJALpSZeYUGUZsWB9BwufpyuefQ04/W1nQ/XRoBQ+5KuQ9iprSeWjqXr1CxanWuQ== X-Received: by 2002:a17:902:f790:b0:1fa:13fc:33ea with SMTP id d9443c01a7336-1fbb6d3d10cmr48874065ad.16.1720622854517; Wed, 10 Jul 2024 07:47:34 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6acef4asm34556875ad.237.2024.07.10.07.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 07:47:34 -0700 (PDT) Date: Wed, 10 Jul 2024 22:47:35 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v10 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 Wed Jul 10 14:47:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13729433 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.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 BCBF3BE4E for ; Wed, 10 Jul 2024 14:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622871; cv=none; b=S/yOBYYhHOetyhqmI+QJZ8S7QYmLAIadxT7GkKvwh2T9GymQs598wFzZIxg0A4p438lDtUm2fDcWo/25Ged3fbv2LCoyhj6FU/NUrwJTIUhLkFfiGfnr4d/Uqq0JESALQDYaklZ9VOQQ+Isxp8YU2vuckUdaa/z1YD1TqN+pU1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622871; c=relaxed/simple; bh=UiyeBYt6HIoYnScaprDPupBgl+1w70TSkJMqhjZHSSE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HO6SnUeUdnHm79tkGK+W9/0A+yshnLOnmXGj3FKDecztV8D3x9yrsQOpoOd20OGzNiwV106SGzpBewAPoARpHEndvfiX9BREJIEy38uR22lbSHaYsWtiWflsOzlkJax7xmZTfjwM+2rukaXr2KqxFM/M10vvQo68fLmW69AE9hQ= 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=cMFAe8tR; arc=none smtp.client-ip=209.85.215.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="cMFAe8tR" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-765590154b4so3273435a12.0 for ; Wed, 10 Jul 2024 07:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720622868; x=1721227668; 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=CTffXF7c2AB4J9IzNq+H9eDFxDONI3crm2A7XjDHAlY=; b=cMFAe8tRv/+TttecqM8B9Kpi+lYoGRsL8mECpuczspdlRzx6zvzwjZXEqseEiHNhp+ 9lriwpIxc6mV17DW3Udvdq4azkyDcE4O/2BJBPleXZp0OUzNQN9chnsz10OOTamnnZ4S fMaQxttvL7/HJGPOsnrcOSeLtCARNSXiE4nZi/KH8F75NgXTVj7QrUXyvbT0L09EXkHg gnWgtdwBlN5G6c0YIx8R1NqXGKLvP4MzSvchlKca8/ke9cBAwDyOTcZfuWYFo2jftKhV +hywFuB6qFynOVkl7nxHHfPNtumL8KNVUWRywTge4H8Rv/CQEOsshdUUcEZtCIyKlr2R jYqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720622868; x=1721227668; 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=CTffXF7c2AB4J9IzNq+H9eDFxDONI3crm2A7XjDHAlY=; b=ntLcDA7RqUmR6KvEPJMNs8xT63W2nZvLsl6WFlu9XKCgxEhr8snl8bbnetp/cpiEhH /bhxQ5KRc8RuCzdf67+Lk/7rTp5WqXYatq85hnKhTGrRKhVCUWCiiUKdne5BrYqPNY2t rE66/3yCzt4ZLT0kfnN9/4aD5ZyhHz0+69v1QXQm6Iu2ZYFJcGCrXnGphOKqYoPt10IL VeWMdsqejxjScUslfyxa+f1QoXB3aI3IXl6ScwG6fMoleeznJe6wU0iJ9jWAsrVlybbB +Yq/y6C1FJf+PLXfBFciUMaQhdHB+Gp5A8XgyUxVzKwXRYpMAORCjFGAjFfio+6FL7ot Irlw== X-Gm-Message-State: AOJu0YzT1d1bciqIaG5eI3C6IRE7mtWh1gRVyXV6KC2ZlsfEcb+ZupF+ Ndmx8rSy8imBSPmknsQYkXuNDVj2BaqzUXcOE4aWJNuMUAEEZaujwuWvPQ== X-Google-Smtp-Source: AGHT+IF0K9XrMsaY0Xru5U0rgPZ/BNXNtRP1uav1fHSB0uTCqnqCOYCK51MKpoX0Elj9gJt3fggXaw== X-Received: by 2002:a17:90b:d97:b0:2c9:73ff:6a0c with SMTP id 98e67ed59e1d1-2ca35c4ef5emr4572385a91.20.1720622868479; Wed, 10 Jul 2024 07:47:48 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ca344c250esm3873275a91.3.2024.07.10.07.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 07:47:48 -0700 (PDT) Date: Wed, 10 Jul 2024 22:47:49 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v10 06/10] builtin/refs: add verify subcommand and verbose_refs for "fsck_options" 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_refs" field into "fsck_options" to indicate whether we should print verbose messages when checking refs 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..599b526786 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(_("too many arguments")); + + if (verbose) + fsck_refs_options.verbose_refs = 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 fe5d4d2ad9..ef1f1ed15e 100644 --- a/fsck.h +++ b/fsck.h @@ -147,6 +147,7 @@ struct fsck_options { fsck_walk_func walk; fsck_error error_func; unsigned strict:1; + unsigned verbose_refs:1; enum fsck_msg_type *msg_type; struct oidset skip_oids; struct oidset gitmodules_found; From patchwork Wed Jul 10 14:48:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13729434 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.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 DCEA1BE4E for ; Wed, 10 Jul 2024 14:48:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622886; cv=none; b=Upe0R4KptM17xKNHdZDhaM1g9PABbEX3lOHdVBRYWlDRVZiK7Jq6x6r26W/ppMg3Bxu+aPVb2gcGKpsbb02xI4lhVWfAbiRtkiPW80RZvi9mrPQsseqYUhhGOD4Ld7nYeqr82BoJSqKsfPSu7zz6g9s0PpX5ke43to0r2EFqXZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622886; c=relaxed/simple; bh=GPo+wJphr/bQOMx/lM4LzA7A2cyA6HvGGdXEE2sIFAw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QR4U3SlC6TKcxZQcuJaI/fjjKgsyfTCNhuYFE3GJSkzvZPAw1gLMyGgs2wK6+r9FLarkRa1o7cb6wfLFYOvfZLWAl+AUzcCRih7vpXFRFTAWPQq0vzV/tapsbWf0zPun3qjJZPIXi2d7TBcCJoGeudmGJT0kIR0ZTSY/RdEQfyE= 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=k2F5dX/r; arc=none smtp.client-ip=209.85.214.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="k2F5dX/r" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1fbc0a1494dso11747575ad.3 for ; Wed, 10 Jul 2024 07:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720622884; x=1721227684; 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=4RAjRwOw8tT55AuT39YuPxyEG/zw/RdiUBjfj6NkTC4=; b=k2F5dX/rb1LCK5xNshVn2hQulupWH6G4dDvJ5uc8YshKKVj7yUikzKS+euMnDdQI7+ cE/T/FjYD+gqH+yOGDVWnAHSAEiV5UIWpVkRa+mXBIeweah5DzA+EVAZSwWUK9E8EBak xMKZmmnYJ5GdB6QTiJFx7yLeGzG51IluiiAUD3NmH7FG5GfAyfeOYG4M5VizehMXlRic yxe5TNUK5RzGsogVYQsKJCBLnlIij+2/62iDfzGubJxYWTUiTXG6esyffoDgXRPAVVS/ woX6KMuDMKgpJMBmbSMwY4PR5M+KO+Qao5HhX7fbfgHuzwIPNkabwK+BgCKMfwUCRfPC vDUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720622884; x=1721227684; 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=4RAjRwOw8tT55AuT39YuPxyEG/zw/RdiUBjfj6NkTC4=; b=IznXKCp9g5ZSmIf0MZQfzTlP8GA5a9XXSc5sgCcktfBTiNt7FGTL4KSp+sXWLPgH2c OHF0llnvlD+ddrofXxDFYAgcqSgh4jD3PwIHmfkqy9AyR0gOuhcHHn6QQN3ZqJqf1o8e CnkN5xu5tV0WMDxa7tfeFW7dazRWhHttfRWn283RgMR5dcsiACcxWKHPoeRtLgCYjcOV Z0TfZgFMaIKZrh+OVK8W4SPc1ey7OB0QFzQ5fpiUDb9w3hXeskpeuGI/hogv7WRHD+82 NkXbXZEk5VCj+OxTZkYAgxCOk3zgKD6EnGcITuF/20dVEpOq2FUZ+XzdFsIL8F+cKfot EJng== X-Gm-Message-State: AOJu0YyvhjkJLWGGhGlFwO36cHXMJejbVHT4cuUeNXCHWK7fUJA3x2ci SgmuNR3A7xKUxD5rKiID4dZu69cM65KeQqmOyk7X3znpam/wFAPKyZO6JA== X-Google-Smtp-Source: AGHT+IHMBP7JUYPxM9kqlz6cLNRndhe36h6TR7C70/tNm+HOLTLJnJNfwvKhg2inROarB9gnOvct0g== X-Received: by 2002:a17:903:2442:b0:1fb:9115:bb61 with SMTP id d9443c01a7336-1fbb6d0b6aamr54655885ad.21.1720622883836; Wed, 10 Jul 2024 07:48:03 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6a26d72sm34767735ad.63.2024.07.10.07.48.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 07:48:03 -0700 (PDT) Date: Wed, 10 Jul 2024 22:48:04 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v10 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 de34538c4f..ec3357722c 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -897,6 +897,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" @@ -1066,6 +1081,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 Wed Jul 10 14:48:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13729435 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.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 0665215E97 for ; Wed, 10 Jul 2024 14:48:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622900; cv=none; b=F8VQ9FiY42DJF7XNG3pbjUaovgoIq30quEBpC4g1O5q8G3XjG6A8/uqqUvUC6XiCnzqr6yN0b6hf6UbdYCNk4Thh0WwXW2G9tpTFma5PTeHGfymjr97dIgb6QuudSRC0X+6YRlIGoA1tDD4TMz+T1dUvGxq/qYPsSDHXwwuAaWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622900; c=relaxed/simple; bh=S0bP3/AX3MX3DxFnCOPiXKJrLhQV20Me5gL9Jqq5Gbo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bObQNG/rSsAhdlT3LWwNGPdG29sZMNl6msanrDkPU3CT5TXggxkj4ceeEgf4/p72mDiokKpwdftZF+x8uPkXgV5ibpwv6Qe/y22oD2o1tj+NEGvp1SpxxanE41E0xh6NZjF1UZ88Ej9TBNGZZeRlTWd+GUctnPbL09zJFLSOjEk= 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=UQ2DS7SX; arc=none smtp.client-ip=209.85.210.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="UQ2DS7SX" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-70af5fbf0d5so624951b3a.1 for ; Wed, 10 Jul 2024 07:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720622898; x=1721227698; 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=57TGoVIpBiCRGE1WDkAeGjYn5Dq+phJkTaZrEfb0Ta0=; b=UQ2DS7SXsUvE2VyGK0ZWbBwv8jnuBkZwtKIyqmjmdvUg48bne8FDNq8AkhhoB/HK9V ZU265zAUKJaFoXOEYxPuKkAVPsylKAtc6DGwT9XUhlqz00auJqBnCQzGuKpnbmpCAJ/o +/Vhwtouu8ZadD5svmKSGQ34HUGgepi2AKIbirZcizRYqgQ2d/LCkdx5rZeExR8imLxJ 9mnHOWpN7UZWgg63GkgeiosB3lnjN1lsW4lm2iiPenR7xwWKmQI8wiIDBuiEBqiIUO5Z oj+qqyjrrGatnHj50qSLQwCInDcQkY4UFEX8VZSFyYrHTaSBxj7n/9XOMuwdKQiSA8zp Lxdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720622898; x=1721227698; 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=57TGoVIpBiCRGE1WDkAeGjYn5Dq+phJkTaZrEfb0Ta0=; b=fdYETSWRfkLbk+/xbsHCdsBGEfTyqMElv7cMuQiS730v89vYENsp9dJVjl/OVv2Kwt hF852MXfqP4VKN0oUV9IC4JmK9MaUFJilBTiiE73L6+YAV4rmV/YxpmVdZSmfUS6Tr9s i1pCy8aafra8EDJ+ceM2nejK3Hxq8WPVExd/hEPJBmLS+FH8skuOELLsCJnpuwi926go oyglPfnPn3KoDGKxx+y7aWix9dzxCgRY5dmS+RQxMMuGwm5AehQOHVkD8iag2ALN5vH6 niojmLSaUNMpen/8YaDggSHo+r76AIhYvr1GQvOLzveksFlXz9NGqBWWW3OXVrfAjTMG NaFQ== X-Gm-Message-State: AOJu0YwKyFzKF1hqQDssZQnsmuU1dyr4hWO2GpIg0D7Tw5cFHEdVRaTO z3xNYqkys2i0qKEIVFMl1OXWFV7q2Nwk14BOXzlbVJ4sCoUjgUrFZACPZw== X-Google-Smtp-Source: AGHT+IFjSd8rsEEPmpgUVoA7Xk38FftjTH7TXJqGFyw3ktCENhmk69gzYWUXf0zCzgzySLG7DxD3VQ== X-Received: by 2002:a05:6a00:3cd6:b0:706:1ff1:c5ff with SMTP id d2e1a72fcca58-70b44d49d0bmr8509869b3a.1.1720622897675; Wed, 10 Jul 2024 07:48:17 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b4397c1e5sm3983004b3a.145.2024.07.10.07.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 07:48:17 -0700 (PDT) Date: Wed, 10 Jul 2024 22:48:18 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v10 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..84acb58782 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_refs) + 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_refs) + 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 Wed Jul 10 14:48:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13729436 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.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 CE0DC15E97 for ; Wed, 10 Jul 2024 14:48:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622914; cv=none; b=Zvz/RcOZ0boUxhA7husxqLfcRJdBY/fMPv/9HSFxAAff6agdEoPR6aLVc9fA2VRflPG32VUO4w2gXQt8I7UKR7/8B5gqx87euDjM70NDK3dQGjyYLg3uQe1wAivQOYL9jvKIBGS8H2jVoEcXFoQW3wjhLuu9bHjIblNOUnCT/5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622914; c=relaxed/simple; bh=fbfeoJfAByVgMoH+JvXBcYph/vU427zkAAKHaM56PL4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bMFgdU/G0CqeosFhPwIUDuVHlREguqoc+RTnPYaFdfA5BsUOFCdKfUeieOQa0FtWEV5wHuqVLLCy8Yq939++NW7OqBAdGsy0JV/xaIQ+BQHxSGUjUA7wxVV+Rf1jPXl2ypiVYCOpgMqBnZB4UI7gkVTOc21JkIVpypdkFhLnnGA= 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=PX5gqUm1; arc=none smtp.client-ip=209.85.210.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="PX5gqUm1" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-70b03ffbb3aso5081642b3a.0 for ; Wed, 10 Jul 2024 07:48:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720622912; x=1721227712; 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=luLpBm2E/RD4NWyfpW0ujaF1ocfuQODuc/lwcYuSuo8=; b=PX5gqUm1bRn2HPaaM4lcTK8eq2QQLIy6oGVYSqIe3uyUfbpnL/YwvuAaTp89V6xe0m g/Tk4QSzgDDWPdvu/bnSVzeKqb9aIiwuswznD7TcYa02SaPtzeHM6kK1z5XgTqnAw0Or JCm60FlIJctKROSnmsy/SLCorV3RoX4pjW8AKzU1WjSoGkq+GszyWFNK8zphtDgBc/9s GiTwBG7ATjtA34rtRP/EpQ+7jTOxd3C24jDQkh1ONAkvgsW9Ymf0I+XwR00mOEVqEtRw kQ9V6ENTHZR08S/d6PKzyO6CO4X5vcEVvtcet9dKwEtZm8YHfis5cbboxPpXOn7RSAKw w6fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720622912; x=1721227712; 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=luLpBm2E/RD4NWyfpW0ujaF1ocfuQODuc/lwcYuSuo8=; b=o/kgm6J8Rk8GS/0e91KFyeagkYR7+2ATQpQ8q3Wv6DWZtfEFVFjrczpRRuT+EhZNkv 3WO7VgIFGDjzXSf0zi/V7Hd/EM+4uvSgRiSdi9cQozQOblR1M8OJuJsWiRCPBSRXmDhZ AZBlmnmEbo3uk9FlN+nSSFpZIAV2qsug++r0xI3Tj9V6kfOe1R/p5F8iN5Mqm1DDN92B SnAEHsbp7klX1oo2DRzu4va1OsM4QwLYNoKKqL9L3Uv/QH8aDiu1gD98O+YklfdTUqaN ayAFqGEgF8DKPCSxvkYnkO0bslWWfoyZnGM9aduxNsDnPnpVBgUNV9kGGj+Q3A3I3AnH jcPg== X-Gm-Message-State: AOJu0YzFk5UQ2xfujrFPb0qSJ89HI7PbqdqPbp3b10Jh0HHo0XbTuhDg T25lhaHxSOoocdupwz8/4l8ui81ENKQ6zw+v2AKj38d7qCRBOKnWKd6u6Q== X-Google-Smtp-Source: AGHT+IGjteg2PWs0Q4q8K0Y1KIM1J6AH3SLrIY1nNgWuL0b8eQt7A8mFY6hiQENipvpq2GO27hGslg== X-Received: by 2002:a05:6a21:999f:b0:1bd:24f9:1124 with SMTP id adf61e73a8af0-1c298242411mr7268553637.27.1720622911604; Wed, 10 Jul 2024 07:48:31 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b4397c50csm3974939b3a.147.2024.07.10.07.48.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 07:48:31 -0700 (PDT) Date: Wed, 10 Jul 2024 22:48:32 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v10 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 | 20 +++++++ t/t0602-reffiles-fsck.sh | 101 ++++++++++++++++++++++++++++++++++ 4 files changed, 125 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 ef1f1ed15e..5fcb249735 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 84acb58782..69a76048d3 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3419,6 +3419,25 @@ 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); + ret = fsck_refs_report(o, NULL, sb.buf, + 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 +3489,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 Wed Jul 10 14:48:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13729437 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 CFD35383A2 for ; Wed, 10 Jul 2024 14:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622928; cv=none; b=gDPclznK+37MLjhonRo6bcraj6AcB08V9TF4ByVKbcKSVP02xtfipGPog8cDuKSObNED/ghd84pxnm+lylEJYDxqCZPrXa5aUCLPSqu/z3l8CgIvjdM/GIN+zhUcgdKGlQhb3UVov5s8FMsmxds9ok3+yP9dojpKEYikoBU9f7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720622928; c=relaxed/simple; bh=LOhHKh5KsBmtmG6sq8A+GG0E9vQ/hniBFGxe7Mwr2o0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Bipf43frO8qU/BwNerlJhaPdFAoMr7PA1f1MholjV3/+MxLzbVMRqR+bJ9ANMrBZjGSMNCbrBOpG0yqF1ycOwrNkPDReifFund87slEB35OOQ7yvs7xOCJUWkxXlvisYeXjbH+zcGDW9E/jUV1AtuWkFKuvvijBfI10xVwTN7Ug= 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=hWCKHZUP; arc=none smtp.client-ip=209.85.210.171 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="hWCKHZUP" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-70b0e7f6f8bso4679540b3a.3 for ; Wed, 10 Jul 2024 07:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720622926; x=1721227726; 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=PmL75pP3+XA1E/GtvW5n6sjvKajVD4syRRBMdTpDpCI=; b=hWCKHZUPauUfDB+9ejFkLeqvqgzaLW+Pm+muvQb2i03EJk6uDswKj+HJ5oDbd8uS67 nX3giQnErYjnIKAR8/frfL2dY/XO4fOL//8h+dJ2Oxf2PTJ0gwochWHm/DmsP7ySeqW4 A1k879BMlAc+1RoVXjRsttIunDWZ/vDrPXN9rCWtIpTQwAuib+7K6zSMIgqqAbfPq8HH EPEiu3c25YaB8pgJHZIHRbKO1t/CwKc5IQWA2V1xKFAKhOsiG/hjREOFR8zIVObIv90t p4hCDtdflxiNxNV4Vx7SxfVvpni/vslufgwALkg5k9/Axyzoha/4JsLoFSR8+ya9Aojl I8Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720622926; x=1721227726; 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=PmL75pP3+XA1E/GtvW5n6sjvKajVD4syRRBMdTpDpCI=; b=KRylB2FfQz+9ppY46urfBtnTGC70BIQ+aTBWAyuK2w84+Smck0MR5hGGszT7xW08Zj xULa1sanKqLwI3YwkJzlzihpCA0RIxZKbuqShn3WBzHmq71dg3PttL8RleFiwpMR6qUj p3jrIUSp3uBjqERqCxUDID25PKZ1PDkFkny0xuUpW23/M9TWwkMqh7KvnQUj7BFseHca wdf5NpInlBBRtflt2utPye7qIYkke6guFkYAr+e/UE7EAr/BVL4Kyi4a4DPTp4BrjCov 1TcsZ61qwMZjrmeEImrdDg4EhAjM31cULGycNFaU0cLqwTdawOj5ASt6kdE+hfG6GTsJ B01Q== X-Gm-Message-State: AOJu0YxL/3TxM7ZB0u6jVjPQMTnjU+Em5RpYm2MYdhFkVDXAmimJbTae LG1DWYc6CIVNro24FrcqE2wSHW+bjY5x9X/PeUFoFKB6jVoL6eMgddulhQ== X-Google-Smtp-Source: AGHT+IGoJdSvRSVk0hOitmCQM2/HHeOQo+Fre3BvuiAwQaHuGyt99spqWe36jUxbzc3y/lhvcfDtqQ== X-Received: by 2002:a05:6a20:244e:b0:1c2:8d59:d14c with SMTP id adf61e73a8af0-1c29820c62bmr6455068637.21.1720622925328; Wed, 10 Jul 2024 07:48:45 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fbb6a2b2b0sm34679805ad.84.2024.07.10.07.48.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 07:48:44 -0700 (PDT) Date: Wed, 10 Jul 2024 22:48:46 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v10 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 | 145 +++++++++++++++++++++++++++++++++- refs/refs-internal.h | 5 +- t/t0602-reffiles-fsck.sh | 110 ++++++++++++++++++++++++++ 6 files changed, 269 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 5fcb249735..3ad2cc86c9 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 69a76048d3..d98ef45403 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; } @@ -3438,6 +3443,141 @@ 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, refname, + 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, refname, + 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, refname, + 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); + + /* + * 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, refname.buf, + 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, refname.buf, + 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 { + /* + * Only regular refs could have a trailing garbage. Should + * be reported as a warning. + */ + if (trailing && (*trailing != '\0' && *trailing != '\n')) { + ret = fsck_refs_report(o, NULL, refname.buf, + 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, @@ -3490,6 +3630,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