From patchwork Mon Aug 5 16:45:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13753829 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 AF5463E479 for ; Mon, 5 Aug 2024 16:44:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876292; cv=none; b=t0BS1a0t6va46BtUpkMYyaMvXe95G8GS7hTKdt4UNUCcdOrPioSNihbduwI6T7nwGElBd88xn427t2IK3bHUL+XZWcYDi99jNheuPwLoAgoZBI0htEsCMb1p5YqVN3I9MK8UbgRpunCgvvsP2UZDWMBkqqtKlc3OqRnyUNvFo3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876292; c=relaxed/simple; bh=amDj2c5gDZRBhglehafDqExLCk1rzcqUdwLMoGAS4gk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tC/yCv1D5e1ZBBOE8eWiVMkTnqJ/ZJUJmXhJdb1tnf1joZOrTgSV+j+wMZYAwUmC07Q9Uu1buns4fZwjoyyytx6jcFncv0DGkpeImf8Ugi4s7FLKB5sa6sssSvbDbK83xGy+KUsG8D3jGdgYqRu1o5moqat0yVX5BNFBji5UIgU= 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=NufLzusB; arc=none smtp.client-ip=209.85.214.176 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="NufLzusB" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fc6ee64512so80395805ad.0 for ; Mon, 05 Aug 2024 09:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722876289; x=1723481089; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Ijt50yIi5MF0RHPoiFN0m67WlBufRjXujnKRkvfb7lM=; b=NufLzusBA2n3f5xukezg//PdwQUtgouBDhVzPAiaa5MI4uHAN9JnPcFacEJHLUSxmx nFZ7Qfh4WmP9ZupkaXmKnO/Skr6AUWN1ohOEZZjTNiQimXfLxkl9Rb9fHKTt9JNqaqfB Q5nP3P/jwmsHQnVhziuuJnaU+Qy0jKxmL5nn6rhB79BmvkHsI6esArb7YrkXSs5gAIhN MCpw4NTK1drKAGqvBZiOI7IurS2fhEAXQboh8pF06Z0dmFNRr3NnFLu8yT+LHkqKNjzN PjroxqgLgZ8J9T55lC4fZxB89LE/rihKhU3V1AyDmX++b3d5TvK3SCYDvRoWfbXbPghY /iEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722876289; x=1723481089; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Ijt50yIi5MF0RHPoiFN0m67WlBufRjXujnKRkvfb7lM=; b=Yc8P1MeO1yuzaLBbJlVSTkEdI071h5nFlCN7ZfUKr45QtQFd67AUKATT5JGtQbz/+v erG8YllMz2gjLuHz9Ixq0VZtkOCP7Ar3KCfvTaUzlddxNbTrqjBn693oQGEYL0K9r8xN Gj5+YSRbwS5M9f+M98SWRqqoPO+HoyPnMZsu/mpfy7Z8Jqe9HdzkCQe8ZjGvMRpqSYHa TH1m7dThqwq0iQAkHZQmM7u+OHTaiAShbGNVAeT6ykfA0y1by0PTNV6wqs8nWENpOGxt Awyjy3bERB0msrv0pwipZFFOKTB9w3ZXe//qZtdWHNhex39r22KuCWzQ03ObadvkunfP 9lDA== X-Gm-Message-State: AOJu0YzOht9g1j5HrtbN5bPsrQbCUzcYONuT4s1rKBrJ8ME9zi9qdrEc 0XRQTpAAh+wXslGZxyBUfCeQFEBowQ89iZcdy7qJ8tIk/EFFCHyH31Zl8w== X-Google-Smtp-Source: AGHT+IFdodlE5uncTPJPueC+rUwfLd5kBs+bKveIpM4VwxCIbW9Jqvsq6Ls7Un3C6Byvet0NF6T5GQ== X-Received: by 2002:a17:902:ced0:b0:1fd:74ca:df49 with SMTP id d9443c01a7336-1ff5732c9c0mr116315575ad.33.1722876289389; Mon, 05 Aug 2024 09:44:49 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff5929404dsm70180485ad.245.2024.08.05.09.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 09:44:48 -0700 (PDT) Date: Tue, 6 Aug 2024 00:45:17 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v15 1/9] fsck: rename "skiplist" to "skip_oids" Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "skiplist" field in "fsck_options" is related to objects. Because we are going to introduce ref consistency check, the "skiplist" name is too general which will make the caller think "skiplist" is related to both the refs and objects. It may seem that for both refs and objects, we should provide a general "skiplist" here. However, the type for "skiplist" is `struct oidset` which is totally unsuitable for refs. To avoid above ambiguity, rename "skiplist" to "skip_oids". Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 4 ++-- fsck.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fsck.c b/fsck.c index eea7145470..3f32441492 100644 --- a/fsck.c +++ b/fsck.c @@ -205,7 +205,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) if (!strcmp(buf, "skiplist")) { if (equal == len) die("skiplist requires a path"); - oidset_parse_file(&options->skiplist, buf + equal + 1, + oidset_parse_file(&options->skip_oids, buf + equal + 1, the_repository->hash_algo); buf += len + 1; continue; @@ -223,7 +223,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) static int object_on_skiplist(struct fsck_options *opts, const struct object_id *oid) { - return opts && oid && oidset_contains(&opts->skiplist, oid); + return opts && oid && oidset_contains(&opts->skip_oids, oid); } __attribute__((format (printf, 5, 6))) diff --git a/fsck.h b/fsck.h index 6085a384f6..bcfb2e34cd 100644 --- a/fsck.h +++ b/fsck.h @@ -136,7 +136,7 @@ struct fsck_options { fsck_error error_func; unsigned strict:1; enum fsck_msg_type *msg_type; - struct oidset skiplist; + struct oidset skip_oids; struct oidset gitmodules_found; struct oidset gitmodules_done; struct oidset gitattributes_found; @@ -145,7 +145,7 @@ struct fsck_options { }; #define FSCK_OPTIONS_DEFAULT { \ - .skiplist = OIDSET_INIT, \ + .skip_oids = OIDSET_INIT, \ .gitmodules_found = OIDSET_INIT, \ .gitmodules_done = OIDSET_INIT, \ .gitattributes_found = OIDSET_INIT, \ From patchwork Mon Aug 5 16:45:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13753830 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 E6C083E479 for ; Mon, 5 Aug 2024 16:44:59 +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=1722876301; cv=none; b=IJ1lNiQCUzXsRFHB5Z7lE/8UM/h/iYlSNTXhi29y+wYQs0W93AUHQkIvPtRvQFi7cG1XZaStN8GcLeZP+Y+scRMzSKrZ4rGivldqBEerMcIUlUt/ZMc0EA8JB5/KtNjVloHpE+Qb1jNvLBzK3k33hcm56cSp9oy3u6mHAAlyKF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876301; c=relaxed/simple; bh=9Kqz6qIA5CWM5K27vSzkIfcF9uGHTKnddDCHROhEiJ0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Gunbt/9z4ix+K4wzJx/2cFWO4Aw/q1Kkk/QI42R+Ui36hiRVtGOhQUh2cLlvM1YlfdUt2pF37nVivrhvW1ApeZu1BWFhyYuRn2O4QA//0CaGQj5LQ8eow12fVSo0i6eOqMrE9vBNgN/wngcBHmQtYbQyq0gTAbhZT2BjjxrwvYk= 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=IgcWG6d6; 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="IgcWG6d6" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1fc491f9b55so84860665ad.3 for ; Mon, 05 Aug 2024 09:44:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722876299; x=1723481099; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8xe9DP7MzHqznOoiJe++dxb/q6o3x4HRjYqfLrdcmcw=; b=IgcWG6d6YFLs8qXTCKzUHiX3KLn3LauoXmCzZNAWapjXEagSwuQrQTjbkqXPOW7boi daW1AU2yjH/QoetzF3U1iWW8x3RmhRmksarHR1a51iZUlzzdkRmK9U5vNFbBtLnD9tFe sbjaZc1xg0DZ5D0OhXZsFBdN2VN6jzSqkdb5waWA5FSo83qXIDvJ6biAraVezooKcKgs QzvXlEeU9tc3gM9fadreIMO3q8L9TYY2F497NIbALK/Javrj0Y9iBwk5dG6+L4opkB+l knejJf8ETQxl43u0j2ZHvQUeSzg71OLsQh60iOr9nnGA37lceU+G4o94RrIBSHg6qtpv 8gJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722876299; x=1723481099; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8xe9DP7MzHqznOoiJe++dxb/q6o3x4HRjYqfLrdcmcw=; b=UBgCYJcX0XllubfH7jrvEZ4jBRj2GH1Zcu/Y6Vv0pmQ95322lHe8reqHLoRycOftNc YqhWNtOJG7skz+IGDLvu3A2/fbPmdqLD58n2GOR8NYlWwCpkkHxno5dmEFI7iWImq8Ds Smi7IqyOdIBiHgz1iJ9Orj2qACJ01Uu2sOwISMRoqGU7vAo8pV3eJCGHHYAdgZ5WTRRl Be8FpdL/7RjFSvyQOodwsnRIPmtlnTeX6XwdLMpeDCniO5m2lxtXWfLX91UNIhLnf/9O AAKOrXc05qORlVvEGaKqVNlEwy1rtCffnk/TVHFrxogbXgOIDumlz7CzrZzi8v9Qtjm6 g/iw== X-Gm-Message-State: AOJu0Yx/1S8I2lAuTK/+tUzKGi/y2I0U2fJZr+57Tdf3w1GacL+8m9z+ hJYiUZDMh4WYGQNb0MXNnaJYj0r6xNHz9ZRTXykKma4c8aRfoaUF4tH/nw== X-Google-Smtp-Source: AGHT+IHN1EFwLBMx+BtSBnxIyq0Op79OOPUz4t8STDv+u2wRSgy4RH8arrdxLHHtFdwv7HGYRxjneQ== X-Received: by 2002:a17:902:ec83:b0:1fd:9590:6550 with SMTP id d9443c01a7336-1ff574dfe01mr121198095ad.64.1722876298735; Mon, 05 Aug 2024 09:44:58 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff58f219easm70222295ad.58.2024.08.05.09.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 09:44:58 -0700 (PDT) Date: Tue, 6 Aug 2024 00:45:26 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v15 2/9] fsck: rename objects-related fsck error functions Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The names of objects-related fsck error functions are generic. It's OK when there is only object database check. However, we are going to introduce refs database check report function. To avoid ambiguity, rename object-related fsck error functions to explicitly indicate these functions are used to report objects-related messages. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- builtin/fsck.c | 14 +++++++------- fsck.c | 17 +++++++++-------- fsck.h | 26 +++++++++++++------------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index d13a226c2e..6d86bbe1e9 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -89,12 +89,12 @@ static int objerror(struct object *obj, const char *err) return -1; } -static int fsck_error_func(struct fsck_options *o UNUSED, - const struct object_id *oid, - enum object_type object_type, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id UNUSED, - const char *message) +static int fsck_objects_error_func(struct fsck_options *o UNUSED, + const struct object_id *oid, + enum object_type object_type, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id UNUSED, + const char *message) { switch (msg_type) { case FSCK_WARN: @@ -938,7 +938,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) fsck_walk_options.walk = mark_object; fsck_obj_options.walk = mark_used; - fsck_obj_options.error_func = fsck_error_func; + fsck_obj_options.error_func = fsck_objects_error_func; if (check_strict) fsck_obj_options.strict = 1; diff --git a/fsck.c b/fsck.c index 3f32441492..8347842cfb 100644 --- a/fsck.c +++ b/fsck.c @@ -1200,7 +1200,7 @@ int fsck_buffer(const struct object_id *oid, enum object_type type, type); } -int fsck_error_function(struct fsck_options *o, +int fsck_objects_error_function(struct fsck_options *o, const struct object_id *oid, enum object_type object_type UNUSED, enum fsck_msg_type msg_type, @@ -1303,16 +1303,17 @@ int git_fsck_config(const char *var, const char *value, * Custom error callbacks that are used in more than one place. */ -int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id, - const char *message) +int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message) { if (msg_id == FSCK_MSG_GITMODULES_MISSING) { puts(oid_to_hex(oid)); return 0; } - return fsck_error_function(o, oid, object_type, msg_type, msg_id, message); + return fsck_objects_error_function(o, oid, object_type, + msg_type, msg_id, message); } diff --git a/fsck.h b/fsck.h index bcfb2e34cd..41ebebbb59 100644 --- a/fsck.h +++ b/fsck.h @@ -120,16 +120,16 @@ typedef int (*fsck_error)(struct fsck_options *o, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); -int fsck_error_function(struct fsck_options *o, - const struct object_id *oid, enum object_type object_type, - enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, - const char *message); -int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id, - const char *message); +int fsck_objects_error_function(struct fsck_options *o, + const struct object_id *oid, enum object_type object_type, + enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, + const char *message); +int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message); struct fsck_options { fsck_walk_func walk; @@ -150,7 +150,7 @@ struct fsck_options { .gitmodules_done = OIDSET_INIT, \ .gitattributes_found = OIDSET_INIT, \ .gitattributes_done = OIDSET_INIT, \ - .error_func = fsck_error_function \ + .error_func = fsck_objects_error_function \ } #define FSCK_OPTIONS_STRICT { \ .strict = 1, \ @@ -158,7 +158,7 @@ struct fsck_options { .gitmodules_done = OIDSET_INIT, \ .gitattributes_found = OIDSET_INIT, \ .gitattributes_done = OIDSET_INIT, \ - .error_func = fsck_error_function, \ + .error_func = fsck_objects_error_function, \ } #define FSCK_OPTIONS_MISSING_GITMODULES { \ .strict = 1, \ @@ -166,7 +166,7 @@ struct fsck_options { .gitmodules_done = OIDSET_INIT, \ .gitattributes_found = OIDSET_INIT, \ .gitattributes_done = OIDSET_INIT, \ - .error_func = fsck_error_cb_print_missing_gitmodules, \ + .error_func = fsck_objects_error_cb_print_missing_gitmodules, \ } /* descend in all linked child objects From patchwork Mon Aug 5 16:45:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13753831 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 4430413D8A8 for ; Mon, 5 Aug 2024 16:45:13 +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=1722876314; cv=none; b=bRySX3UkRCu1weH8r3BGYK+fkIp2GfoGLqpQ+XvpF2PLVu282AdgUD4x7C9gRUHZesGT2Jc5g/kQTIMmLo3MMZcoEmCzpme6jm3ox35NgXBgGXq10epmrCz/yhdgEtXOFm2RIY2sLKq59C+75/rm2wsFmmJb5qolDYi02xhiIyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876314; c=relaxed/simple; bh=psYfKpqXB2eXs/L/bxb7clK+XkwFWUX9iKB8cb5S3ys=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GIlEzC5lZsZhxMgXC78Qmg3SgoB9P4UYx5+63hI/+sQpNkEk+jFhnrhH3PLAORsFeUW3Z5pteW6Qq87W2GgKR7M0DxlUV1v+K4xYQaUT2v7ceaVTCsCOttALIIPqupD7kGQCBFnxbr6eTwEBzN0wGUfmHJfpRzHX0adnEL/LDr0= 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=TBHfCkN3; 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="TBHfCkN3" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-70d19d768c2so8006206b3a.3 for ; Mon, 05 Aug 2024 09:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722876312; x=1723481112; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=+Hsel6U7BlzkbmKRjoWdla7eaGn2fX2uALHB6F6GIrE=; b=TBHfCkN3374Kuidz9FCg/NJZdQHN/+EkVzSYE8Zv8mL2wqtlrcrP9Wt0B5bwQEQLo+ Mlr+fEJ39rCDloTet6xWO+Xxnmlf1QfQF/Td0skz4zOeeYctJPrOYEi3Idm/OvGjQawO lXUIPBYPjESjvBAHnZBzmJQbPEqYdywERnzUflg9sUeCyq5asdujcie6sFceowTFBg84 MQoigQ+dlX5UAQcTsTMFgjXW4rYPDhVfD6huUGrOBT721KbCNhudtCgxko7ijd6rs16z Y2fV1NeGUJvg2mj+edb1QFzbPJl/KSY6pHtsDiTbloOba+8/hHDzvJBkgU8pbo4KLSbZ J2Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722876312; x=1723481112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+Hsel6U7BlzkbmKRjoWdla7eaGn2fX2uALHB6F6GIrE=; b=rf01J/Sv7dGZNYtKv4M3xzBcnOUOIei5rGQB94wZKVdwqFHMLdpXXndWzwOY+2l4/R sWf9XyvewMV0JIRCkm5R36nIYCLqSuI6EUSEVs+2bJjMAO4VHPIgSnxP9dznPk7ndigd 6sHRMjoQ6r2NK30XWNx9t60xdZR/fa6+psXH2ErQoSCSlVkNnMa2vnVYG8571RjcHSVc XaWvHRd17lOkZh5noqZR21duYtumc9019wACkpNqpwS6KXpw8xZ8gQQqU2fVMgJo/DgA BsmoPoP3H40HczlivFfPlXQeq/H/NVIvVV5+7/DB89Rxvm8ZCkiaQuZAWFoWPb8tnlqP MaDA== X-Gm-Message-State: AOJu0YxAsTVP9tN4UyD3Kun7yGa0Fu13so6hnsZ+VWHnXL+xHLjgC+zR Xn7SvOM04BFyLo2zTUgvZtkVJuxvGx0ZCHnj1WI5IG0O3ZUsd4c3x9KhnA== X-Google-Smtp-Source: AGHT+IEvY+3a2g+y+liY8zmoWCVo0kM5NNvIvxmBAWWRZdoEBHKWQgbn9PYSQTcuixR0Gk9OPUiTOg== X-Received: by 2002:aa7:8890:0:b0:710:50c8:ddcb with SMTP id d2e1a72fcca58-7106cf90809mr11104189b3a.5.1722876311838; Mon, 05 Aug 2024 09:45:11 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ecdfe83sm5589330b3a.122.2024.08.05.09.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 09:45:11 -0700 (PDT) Date: Tue, 6 Aug 2024 00:45:39 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v15 3/9] fsck: make "fsck_error" callback generic Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "fsck_error" callback is designed to report the objects-related error messages. It accepts two parameter "oid" and "object_type" which is not generic. In order to provide a unified callback which can report either objects or refs, remove the objects-related parameters and add the generic parameter "void *fsck_report". Create a new "fsck_object_report" structure which incorporates the removed parameters "oid" and "object_type". Then change the corresponding references to adapt to new "fsck_error" callback. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- builtin/fsck.c | 7 +++++-- builtin/mktag.c | 3 +-- fsck.c | 26 ++++++++++++++++---------- fsck.h | 17 ++++++++++++----- object-file.c | 9 ++++----- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 6d86bbe1e9..766bbd014d 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -90,12 +90,15 @@ static int objerror(struct object *obj, const char *err) } static int fsck_objects_error_func(struct fsck_options *o UNUSED, - const struct object_id *oid, - enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id UNUSED, const char *message) { + struct fsck_object_report *report = fsck_report; + const struct object_id *oid = report->oid; + enum object_type object_type = report->object_type; + switch (msg_type) { case FSCK_WARN: /* TRANSLATORS: e.g. warning in tree 01bfda: */ diff --git a/builtin/mktag.c b/builtin/mktag.c index 4767f1a97e..c6b644219f 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -18,8 +18,7 @@ static int option_strict = 1; static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; static int mktag_fsck_error_func(struct fsck_options *o UNUSED, - const struct object_id *oid UNUSED, - enum object_type object_type UNUSED, + void *fsck_report UNUSED, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id UNUSED, const char *message) diff --git a/fsck.c b/fsck.c index 8347842cfb..cca6ae144f 100644 --- a/fsck.c +++ b/fsck.c @@ -232,6 +232,10 @@ static int report(struct fsck_options *options, enum fsck_msg_id msg_id, const char *fmt, ...) { va_list ap; + struct fsck_object_report report = { + .oid = oid, + .object_type = object_type + }; struct strbuf sb = STRBUF_INIT; enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options); int result; @@ -252,7 +256,7 @@ static int report(struct fsck_options *options, va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); - result = options->error_func(options, oid, object_type, + result = options->error_func(options, &report, msg_type, msg_id, sb.buf); strbuf_release(&sb); va_end(ap); @@ -1201,12 +1205,14 @@ int fsck_buffer(const struct object_id *oid, enum object_type type, } int fsck_objects_error_function(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type UNUSED, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id UNUSED, - const char *message) + void *fsck_report, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id UNUSED, + const char *message) { + struct fsck_object_report *report = fsck_report; + const struct object_id *oid = report->oid; + if (msg_type == FSCK_WARN) { warning("object %s: %s", fsck_describe_object(o, oid), message); return 0; @@ -1304,16 +1310,16 @@ int git_fsck_config(const char *var, const char *value, */ int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message) { if (msg_id == FSCK_MSG_GITMODULES_MISSING) { - puts(oid_to_hex(oid)); + struct fsck_object_report *report = fsck_report; + puts(oid_to_hex(report->oid)); return 0; } - return fsck_objects_error_function(o, oid, object_type, + return fsck_objects_error_function(o, fsck_report, msg_type, msg_id, message); } diff --git a/fsck.h b/fsck.h index 41ebebbb59..3b80d02506 100644 --- a/fsck.h +++ b/fsck.h @@ -114,23 +114,30 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type); typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type, void *data, struct fsck_options *options); -/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ +/* + * Callback for reporting errors either for objects or refs. The "fsck_report" + * is a generic pointer that can be used to pass any information. + */ typedef int (*fsck_error)(struct fsck_options *o, - const struct object_id *oid, enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); int fsck_objects_error_function(struct fsck_options *o, - const struct object_id *oid, enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); +struct fsck_object_report { + const struct object_id *oid; + enum object_type object_type; +}; + struct fsck_options { fsck_walk_func walk; fsck_error error_func; diff --git a/object-file.c b/object-file.c index 065103be3e..05ac6ebed6 100644 --- a/object-file.c +++ b/object-file.c @@ -2470,11 +2470,10 @@ int repo_has_object_file(struct repository *r, * give more context. */ static int hash_format_check_report(struct fsck_options *opts UNUSED, - const struct object_id *oid UNUSED, - enum object_type object_type UNUSED, - enum fsck_msg_type msg_type UNUSED, - enum fsck_msg_id msg_id UNUSED, - const char *message) + void *fsck_report UNUSED, + enum fsck_msg_type msg_type UNUSED, + enum fsck_msg_id msg_id UNUSED, + const char *message) { error(_("object fails fsck: %s"), message); return 1; From patchwork Mon Aug 5 16:45:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13753832 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 E719E13AD26 for ; Mon, 5 Aug 2024 16:45:21 +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=1722876323; cv=none; b=WPkUDT0CJALF9U1lNkO/s4/MeOjNIOgjp9YvPezHL4AwxIUNmTOWOXfm+mJ0awkkc3J5YLVWeoYA28mXD+eKoNFXS9Dg+5jpaZ2YI5Ja4+b3E2aPpKEbuRx2ggnVjVfMoGZXYWHVSpvX6WXVGXxmEvPLo7gFEPzIoZlfq4nm7Sg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876323; c=relaxed/simple; bh=DU5vO1rm0CHVJOHMAWbSWFTuz4d9xtelnmyX7EU2jkY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YFzyQfGlyaqYRAYb+Mfpp/BemyE5CEP6esRuhjlY/SKQInBPEHzrAQjry+8oJJUbuG+p+KTNv1oyuns/5uZ9jv1yNzOTq+Z3oDjqaEu0xlWlvnS+lTvIburQvUVFKFEy58N7Kw57DW4prXmNTLD+pZvnqcofi4oiGENmPoyJMYc= 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=KH7ggt/Z; 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="KH7ggt/Z" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fec34f94abso85774205ad.2 for ; Mon, 05 Aug 2024 09:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722876321; x=1723481121; 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=D3kLHL33M9LOGwT/r4LGJ9nevWsQqK6sbAQ+FttyaPA=; b=KH7ggt/ZZwIHFYfiyqGaF15qyM7amSs8/D4GFVGeTtg/hVKZKt0sDlqO0peKpoNEAP dek9VHUQTiiviISPKBlVHDh9lmMskbm4YnOo/4qffxVEQk0nrfYiWfcaJGikhpvqci4u JS3+6Q0aXG+a+0Mut6WujPB8gogv+EVwBjTQULHkm6pY6qwSMLIEEC7leLBHhWBmUuJe v5fe1aTZUexWYFne0NCFo0x2IxNR/Rtkd8nigjIHsGotYX13w4ixH6tH1Sto8xLbt0hI 938DEhMnSsK+3aCs6KnPFwz/jdUkJxfkqk1gRAFEAfC5TsCl7r5S/R3MEsTEqGtquXdl /seA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722876321; x=1723481121; 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=D3kLHL33M9LOGwT/r4LGJ9nevWsQqK6sbAQ+FttyaPA=; b=YHtxoCpvx6mq5IGUHS+/c6FHHaAwlNHnmoyy/3n1TkB7r11nQ9lJh218Y6uH9m+6V5 31lY8ph/35zGT6VDNeeP7sMZiQvinHqGbp+7qwYSZfC5dNQTvlNr9dCa1cxJ6LU3c8oG 6cvRt9EF3etWd0TtmFP4linfhycbgL0Tu3kD71g7veT5C9ZHmyhUXFqJDHeNrDJwT2RT TjoGP3kWuadeQeu5kMzTsTA94LouYVqerIyA3t06i5rQm6SCbZMZbrJDHdjJnT9hQdSM uv60mMlglByrlu1Vmc8lKktQHRUHk4GTToWkbb+uO2PVE8Cxr7RdMNpQ8zP6omOdMSz7 thJg== X-Gm-Message-State: AOJu0YwMCxH4pfwsX7l7a2y5DbyAXKddeh7/EdCuq2pXwy3O1Qkhvn/v 4925OsKPA9rJaK8UpKnunUo4hTaXCWPXKA/PUVWRsBZ+QrAqCUnKOOUOVg== X-Google-Smtp-Source: AGHT+IF56LnhhQ18mlqn7/Pq5dYqQujXGfd9qzSM5NOPQdvXEfgtKg1WuxC8oASxckTAcBbeFvMeZg== X-Received: by 2002:a17:903:41cc:b0:1fb:46a7:dbda with SMTP id d9443c01a7336-1ff573c0001mr120606615ad.47.1722876320712; Mon, 05 Aug 2024 09:45:20 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff592acd2fsm69933465ad.286.2024.08.05.09.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 09:45:20 -0700 (PDT) Date: Tue, 6 Aug 2024 00:45:48 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v15 4/9] fsck: add a unified interface for reporting fsck messages Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The static function "report" provided by "fsck.c" aims at checking error type and calling the callback "error_func" to report the message. Both refs and objects need to check the error type of the current fsck message. In order to extract this common behavior, create a new function "fsck_vreport". Instead of using "...", provide "va_list" to allow more flexibility. Instead of changing "report" prototype to be algin with the "fsck_vreport" function, we leave the "report" prototype unchanged due to the reason that there are nearly 62 references about "report" function. Simply change "report" function to use "fsck_vreport" to report objects related messages. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/fsck.c b/fsck.c index cca6ae144f..3614aa56a3 100644 --- a/fsck.c +++ b/fsck.c @@ -226,16 +226,15 @@ static int object_on_skiplist(struct fsck_options *opts, return opts && oid && oidset_contains(&opts->skip_oids, oid); } -__attribute__((format (printf, 5, 6))) -static int report(struct fsck_options *options, - const struct object_id *oid, enum object_type object_type, - enum fsck_msg_id msg_id, const char *fmt, ...) +/* + * Provide the common functionality for either fscking refs or objects. + * It will get the current msg error type and call the error_func callback + * which is registered in the "fsck_options" struct. + */ +static int fsck_vreport(struct fsck_options *options, + void *fsck_report, + enum fsck_msg_id msg_id, const char *fmt, va_list ap) { - va_list ap; - struct fsck_object_report report = { - .oid = oid, - .object_type = object_type - }; struct strbuf sb = STRBUF_INIT; enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options); int result; @@ -243,9 +242,6 @@ static int report(struct fsck_options *options, if (msg_type == FSCK_IGNORE) return 0; - if (object_on_skiplist(options, oid)) - return 0; - if (msg_type == FSCK_FATAL) msg_type = FSCK_ERROR; else if (msg_type == FSCK_INFO) @@ -254,11 +250,31 @@ static int report(struct fsck_options *options, prepare_msg_ids(); strbuf_addf(&sb, "%s: ", msg_id_info[msg_id].camelcased); - va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); - result = options->error_func(options, &report, + result = options->error_func(options, fsck_report, msg_type, msg_id, sb.buf); strbuf_release(&sb); + + return result; +} + +__attribute__((format (printf, 5, 6))) +static int report(struct fsck_options *options, + const struct object_id *oid, enum object_type object_type, + enum fsck_msg_id msg_id, const char *fmt, ...) +{ + va_list ap; + struct fsck_object_report report = { + .oid = oid, + .object_type = object_type + }; + int result; + + if (object_on_skiplist(options, oid)) + return 0; + + va_start(ap, fmt); + result = fsck_vreport(options, &report, msg_id, fmt, ap); va_end(ap); return result; From patchwork Mon Aug 5 16:45:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13753833 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.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 456A215DBD5 for ; Mon, 5 Aug 2024 16:45:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876331; cv=none; b=XDKQBkxELXmTfPajpQYO2zAGviXzT6L4SYYRGZFMxFL2JPjtXZ3lFNrb6zG5VQoGiC/gzeQlcVOLnw6T2xLdIzmqS5qiVYJmSIyFKvIFmfqyR32xCSZ3UpeGLUFiBeirakYmmMu/dJ0JShgJgCY58+lLHZLPRuvuNKEbgsOnN5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876331; c=relaxed/simple; bh=R3lgi6f9YZ2Fv+CgFnJqQX/2pLjRLr88tAvX3zh4K7Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dYEfOL2wG1GDXiwt+2y7yZmxMGCkzJXTWVoP+PuwYp15mHaE7PAW1x4VYme9a8g8TzbndLESmbcFKtlNjeQ4WgHqmQY+uZnw3AIHvd4wxwoXa20AyVB6njPfke+GlsVgPWhT6mq9YDyy9RjEdfV9iGT3ZxPq4moeVPbrS65/0EI= 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=ZAaMFV9e; arc=none smtp.client-ip=209.85.214.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="ZAaMFV9e" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1ff4fa918afso30113425ad.1 for ; Mon, 05 Aug 2024 09:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722876329; x=1723481129; 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=g2QmbXhbiit5sMyfK14M78CBQMgETwqJePurU9Qll7Q=; b=ZAaMFV9eLEOYlucyPCcXWzLkriwGTqnW5GlAbmITR8qptIX6KLDZWFLlHiROru+68a /0e72admGZvLGGs71BivuR5OTxXFagPFllagt3vdE06Wa5e/bQ3DUscG4iEmIV/FFbX3 aH080nR0r6nQZZOFLbs1NSCJHMufscxpDq3LP93lnY8Vpv0uPbHiue3QYyLiIEcbbIMm YVK2deZw9DxCT0PXd977r87dbE7GUPYBfb9rPgH6gLPaMbo3N2X++EGEPKv3XCcfFJUn vm5AlSR/ccC5UKxwJB7jbXpilotH5h+9d4Rb4pEXsrewcaiew6k9LzwphAF8I2FhdlMw fmVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722876329; x=1723481129; 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=g2QmbXhbiit5sMyfK14M78CBQMgETwqJePurU9Qll7Q=; b=QRw1mysQTSi954yq9N3O/zDUnKu1WXgQH0m8TWhJkhgGfporz/6KC8e5Ep6N3RMB51 x6omI/vp+RhMShFE6vJN7S/jG5GNiwMStiYNYK/YxJ0YbytvpPGZ4p9gsbClhPv6gtXa WYol9sSBGHB3+/YhEfS3EQ3eTtuiOBzki5x06HayE1/WGq1K8A5bcelTV+WV4FfqeUNg 0vOfYtsV6jmZ1DbWpx1q8Q4J+Ee4M6fVdBnGt7jk3sYDf0ttskgV4Nf+vBlCgHcL0iZa PHxfVH+ZN8EJva7AD0gMzX8HD3P3hmyJUGfGGVHuctutk6T6z8TYlVHoWmukYPhWJyvx wCRg== X-Gm-Message-State: AOJu0YxPYecBa9knUPULtOsm8Vf5UJ9ZI+vDrCE1y+I8n4dBuXR8FeOO RBj1E+aIMwEIcFe9ANPP9LPG9DizTm2RhfehN+cfO8sAs0iUPdMRXnto/A== X-Google-Smtp-Source: AGHT+IEva0CrULfFdtIKoY3ZgZeOZxvrk8a8G4Ca4bg7KQ/1z6l70C4E4wyJZ3tL/2aUZAkntkM1oA== X-Received: by 2002:a17:902:d492:b0:1fb:8419:8384 with SMTP id d9443c01a7336-1ff5722d6e9mr117464455ad.13.1722876329056; Mon, 05 Aug 2024 09:45:29 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59175d2csm70220615ad.212.2024.08.05.09.45.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 09:45:28 -0700 (PDT) Date: Tue, 6 Aug 2024 00:45:57 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v15 5/9] fsck: add refs report function Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Introduce a new struct "fsck_ref_report" to contain the information we need when reporting refs-related messages. With the new "fsck_vreport" function, add a new function "fsck_report_ref" to report refs-related fsck error message. Unlike "report" function uses the exact parameters, we simply pass "struct fsck_ref_report *report" as the parameter. This is because at current we don't know exactly how many fields we need. By passing this parameter, we don't need to change this function prototype when we want to add more information into "fsck_ref_report". We have introduced "fsck_report_ref" function to report the error message for refs. We still need to add the corresponding callback function. Create refs-specific "error_func" callback "fsck_refs_error_function". Last, add "FSCK_REFS_OPTIONS_DEFAULT" macro to create default options when checking ref consistency. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 41 +++++++++++++++++++++++++++++++++++++++++ fsck.h | 25 +++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/fsck.c b/fsck.c index 3614aa56a3..38554b626e 100644 --- a/fsck.c +++ b/fsck.c @@ -280,6 +280,19 @@ static int report(struct fsck_options *options, return result; } +int fsck_report_ref(struct fsck_options *options, + struct fsck_ref_report *report, + enum fsck_msg_id msg_id, + const char *fmt, ...) +{ + va_list ap; + int result; + va_start(ap, fmt); + result = fsck_vreport(options, report, msg_id, fmt, ap); + va_end(ap); + return result; +} + void fsck_enable_object_names(struct fsck_options *options) { if (!options->object_names) @@ -1237,6 +1250,34 @@ int fsck_objects_error_function(struct fsck_options *o, return 1; } +int fsck_refs_error_function(struct fsck_options *options UNUSED, + void *fsck_report, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id UNUSED, + const char *message) +{ + struct fsck_ref_report *report = fsck_report; + + struct strbuf sb = STRBUF_INIT; + int ret = 0; + + strbuf_addstr(&sb, report->path); + + if (report->oid) + strbuf_addf(&sb, " -> (%s)", oid_to_hex(report->oid)); + else if (report->referent) + strbuf_addf(&sb, " -> (%s)", report->referent); + + if (msg_type == FSCK_WARN) + warning("%s: %s", sb.buf, message); + else + ret = error("%s: %s", sb.buf, message); + + strbuf_release(&sb); + return ret; + +} + static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done, enum fsck_msg_id msg_missing, enum fsck_msg_id msg_type, struct fsck_options *options, const char *blob_type) diff --git a/fsck.h b/fsck.h index 3b80d02506..2002590f60 100644 --- a/fsck.h +++ b/fsck.h @@ -133,11 +133,23 @@ int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, enum fsck_msg_id msg_id, const char *message); +int fsck_refs_error_function(struct fsck_options *options, + void *fsck_report, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message); + struct fsck_object_report { const struct object_id *oid; enum object_type object_type; }; +struct fsck_ref_report { + const char *path; + const struct object_id *oid; + const char *referent; +}; + struct fsck_options { fsck_walk_func walk; fsck_error error_func; @@ -175,6 +187,9 @@ struct fsck_options { .gitattributes_done = OIDSET_INIT, \ .error_func = fsck_objects_error_cb_print_missing_gitmodules, \ } +#define FSCK_REFS_OPTIONS_DEFAULT { \ + .error_func = fsck_refs_error_function, \ +} /* descend in all linked child objects * the return value is: @@ -216,6 +231,16 @@ int fsck_tag_standalone(const struct object_id *oid, const char *buffer, */ int fsck_finish(struct fsck_options *options); +/* + * Report an error or warning for refs. + */ +__attribute__((format (printf, 4, 5))) +int fsck_report_ref(struct fsck_options *options, + struct fsck_ref_report *report, + enum fsck_msg_id msg_id, + const char *fmt, ...); + + /* * Subsystem for storing human-readable names for each object. * From patchwork Mon Aug 5 16:46:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13753834 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 B438815B57B for ; Mon, 5 Aug 2024 16:45:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876341; cv=none; b=IuCpZb+Gfs5bFLIzkToPtcpnKxYwT3kiJv0empiDpXceWo4P0VWmGgsjI5i80cfp4gROxHV7GnMhlJKRlPWYpwAc839leQadDxZ5RT1UL34R9Ta2BuM1ntIjYM96Va7Zw9Pyk+5pqO5mHbS3LfsvQeDaXNVyirjNuy1NSgvGd0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876341; c=relaxed/simple; bh=d0U+zfe5Q3f7g3/LK0qr2DuDHFPH6/t3E6P5vC5/Uks=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JFzQJKeHoarLzp/7vNBhzvK0X9Jz5NTbgEcEgSAf0isPWtekB1cHKN/Rr6LACMv4Bvs7KUbkB6ZmySPPVYbsDF52FPsj8ZepjfbyFLmNmsV3rdblidx/zfFow4pJbNWXMV4HwK/UOTqKXQz3RWwCTpdJrvuixsECGE+BXYUdpq4= 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=GxaIoHe/; arc=none smtp.client-ip=209.85.214.176 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="GxaIoHe/" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fd9e6189d5so85097085ad.3 for ; Mon, 05 Aug 2024 09:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722876338; x=1723481138; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=gXSYuUIlc1sLEM0xmW8Sg4+1Dl1cviP9OhmRc0x8Q40=; b=GxaIoHe/7awUx+3RAqnBtnV3c4IUSCIWqDjhHdEo9EdfGgJW1ANPaWKOMYiNKN7X61 feMu/XPIm64GFaDNDPDkNrGWfbZmppagFp4h+t67q5xIr8hXMVAdM+Ne6P/9DSJYJxGz MCjZszlKHgtlrt8AEUnWO3NaDkRz4ytRAM96mCf5H7e3lDMB0TgsWI+zCYzwWFdl965K 6DaQJ7nyqy5k9NrRuUbUDjLDugJjYfDhrYEymYa0qp3fXzxEdfsVpGMdkxxfxmpkt0EW iDSNc1lREQrSR8u+bbcNRiVsDMEvdiWLAGg8EdGP/tjHcJ7b/JtJSX+9QATqid6qYUne NPRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722876338; x=1723481138; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gXSYuUIlc1sLEM0xmW8Sg4+1Dl1cviP9OhmRc0x8Q40=; b=JwhYO8TK+BxHmS9qWNecDF6q8c6tpHOc5NauqrrTt2y4VNIiFiwmuB1yndGBxvpLTA zQs3AzGSZbUKUrZys0siesLmAGcCyTZEH7xTcBxANNJx86bikVYQawreRcT7U2JLmKF6 /8yYZ6RfEcGNuIYfieNRIPoBy39hVxwDIXsNaP3USQyH8R28z5mq0+DbYSuWyyovRN64 8z3CIfvnE6bBpIl3wsv8KZK5wQGsUQe+NtVHEhjkLyCARyH865JzU/z9xTArnkZ/TkE3 s0AvI17hTS6pcYIkBPTFqf+lZAKUzexrNPBeWZ2aXjUpDRk7O72WohyvsCXQauFfXjuV 2vPw== X-Gm-Message-State: AOJu0Yx62a6rkJskVk/REG63Yb8ReClGvdosLthIMd4pyyrROg0qNum6 ueB/XpVB28QrhYLbQCNSFqoGIZv2l5OE2+BvpwKjD6H8+/ZUNJBqQcHVLQ== X-Google-Smtp-Source: AGHT+IFw3yeOuiMNucL6kYdctaHr9azInUcwJJWnZqoVTV3WkNyX+SlTjJMEzHwe9dgn0r7vhiKexg== X-Received: by 2002:a17:902:d4c2:b0:1fd:73e6:83dc with SMTP id d9443c01a7336-1ff571149a9mr145922045ad.0.1722876338521; Mon, 05 Aug 2024 09:45:38 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff5905b52bsm70688345ad.176.2024.08.05.09.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 09:45:38 -0700 (PDT) Date: Tue, 6 Aug 2024 00:46:06 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v15 6/9] refs: set up ref consistency check infrastructure Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "struct ref_store" is the base class which contains the "be" pointer which provides backend-specific functions whose interfaces are defined in the "ref_storage_be". We could reuse this polymorphism to define only one interface. For every backend, we need to provide its own function pointer. The interfaces defined in the `ref_storage_be` are carefully structured in semantic. It's organized as the five parts: 1. The name and the initialization interfaces. 2. The ref transaction interfaces. 3. The ref internal interfaces (pack, rename and copy). 4. The ref filesystem interfaces. 5. The reflog related interfaces. To keep consistent with the git-fsck(1), add a new interface named "fsck_refs_fn" to the end of "ref_storage_be". This semantic cannot be grouped into any above five categories. Explicitly add blank line to make it different from others. Last, implement placeholder functions for each ref backends. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- refs.c | 5 +++++ refs.h | 8 ++++++++ refs/debug.c | 11 +++++++++++ refs/files-backend.c | 13 ++++++++++++- refs/packed-backend.c | 8 ++++++++ refs/refs-internal.h | 6 ++++++ refs/reftable-backend.c | 8 ++++++++ 7 files changed, 58 insertions(+), 1 deletion(-) diff --git a/refs.c b/refs.c index 915aeb4d1d..6f642dc681 100644 --- a/refs.c +++ b/refs.c @@ -318,6 +318,11 @@ int check_refname_format(const char *refname, int flags) return check_or_sanitize_refname(refname, flags, NULL); } +int refs_fsck(struct ref_store *refs, struct fsck_options *o) +{ + return refs->be->fsck(refs, o); +} + void sanitize_refname_component(const char *refname, struct strbuf *out) { if (check_or_sanitize_refname(refname, REFNAME_ALLOW_ONELEVEL, out)) diff --git a/refs.h b/refs.h index b3e39bc257..405073621a 100644 --- a/refs.h +++ b/refs.h @@ -4,6 +4,7 @@ #include "commit.h" #include "repository.h" +struct fsck_options; struct object_id; struct ref_store; struct strbuf; @@ -541,6 +542,13 @@ int refs_for_each_reflog(struct ref_store *refs, each_reflog_fn fn, void *cb_dat */ int check_refname_format(const char *refname, int flags); +/* + * Check the reference database for consistency. Return 0 if refs and + * reflogs are consistent, and non-zero otherwise. The errors will be + * written to stderr. + */ +int refs_fsck(struct ref_store *refs, struct fsck_options *o); + /* * Apply the rules from check_refname_format, but mutate the result until it * is acceptable, and place the result in "out". diff --git a/refs/debug.c b/refs/debug.c index 547d9245b9..45e2e784a0 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -419,6 +419,15 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname, return res; } +static int debug_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store; + int res = drefs->refs->be->fsck(drefs->refs, o); + trace_printf_key(&trace_refs, "fsck: %d\n", res); + return res; +} + struct ref_storage_be refs_be_debug = { .name = "debug", .init = NULL, @@ -451,4 +460,6 @@ struct ref_storage_be refs_be_debug = { .create_reflog = debug_create_reflog, .delete_reflog = debug_delete_reflog, .reflog_expire = debug_reflog_expire, + + .fsck = debug_fsck, }; diff --git a/refs/files-backend.c b/refs/files-backend.c index aa52d9be7c..4630eb1f80 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3408,6 +3408,15 @@ static int files_ref_store_remove_on_disk(struct ref_store *ref_store, return ret; } +static int files_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + struct files_ref_store *refs = + files_downcast(ref_store, REF_STORE_READ, "fsck"); + + return refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); +} + struct ref_storage_be refs_be_files = { .name = "files", .init = files_ref_store_init, @@ -3434,5 +3443,7 @@ struct ref_storage_be refs_be_files = { .reflog_exists = files_reflog_exists, .create_reflog = files_create_reflog, .delete_reflog = files_delete_reflog, - .reflog_expire = files_reflog_expire + .reflog_expire = files_reflog_expire, + + .fsck = files_fsck, }; diff --git a/refs/packed-backend.c b/refs/packed-backend.c index a0666407cd..5209b0b212 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1735,6 +1735,12 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s return empty_ref_iterator_begin(); } +static int packed_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + return 0; +} + struct ref_storage_be refs_be_packed = { .name = "packed", .init = packed_ref_store_init, @@ -1762,4 +1768,6 @@ struct ref_storage_be refs_be_packed = { .create_reflog = NULL, .delete_reflog = NULL, .reflog_expire = NULL, + + .fsck = packed_fsck, }; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index fa975d69aa..a905e187cd 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -4,6 +4,7 @@ #include "refs.h" #include "iterator.h" +struct fsck_options; struct ref_transaction; /* @@ -650,6 +651,9 @@ typedef int read_raw_ref_fn(struct ref_store *ref_store, const char *refname, typedef int read_symbolic_ref_fn(struct ref_store *ref_store, const char *refname, struct strbuf *referent); +typedef int fsck_fn(struct ref_store *ref_store, + struct fsck_options *o); + struct ref_storage_be { const char *name; ref_store_init_fn *init; @@ -677,6 +681,8 @@ struct ref_storage_be { create_reflog_fn *create_reflog; delete_reflog_fn *delete_reflog; reflog_expire_fn *reflog_expire; + + fsck_fn *fsck; }; extern struct ref_storage_be refs_be_files; diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index fbe74c239d..b5a1a526df 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -2303,6 +2303,12 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store, return ret; } +static int reftable_be_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + return 0; +} + struct ref_storage_be refs_be_reftable = { .name = "reftable", .init = reftable_be_init, @@ -2330,4 +2336,6 @@ struct ref_storage_be refs_be_reftable = { .create_reflog = reftable_be_create_reflog, .delete_reflog = reftable_be_delete_reflog, .reflog_expire = reftable_be_reflog_expire, + + .fsck = reftable_be_fsck, }; From patchwork Mon Aug 5 16:46:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13753835 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.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 D90EF15EFAF for ; Mon, 5 Aug 2024 16:45:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876350; cv=none; b=uOOwRTMRYkN5TolXIoYYQr18FkKolxblWqFi1EqyhyQnzn9q3OR4yzuxbaB3KvevzE3ddHnqOZ8vwVHg7TGAKSRtblEd2HxlLd+nfQXvf6WPl0cMvH1w678nZEZ13IP4Tyn0a/ljGX8vyWoppC2nrTJHBEvCuB9InCBhbkQ9kRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876350; c=relaxed/simple; bh=v+Rq14jH54S3uAhHiT7P0b+alMdK5ypEQGdtNA2VIUE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jtrbDe+lpmWbOaarxNYyhs0knoi3cnvRjx49+z1DFe++jrJZgRw1N1/93UNbc0WiRAQF5eB3WGXrn+In1s0DenrExoDkVVQjjKoW5WWhmhtxG0tEkZ6KfZ180wkYb70/Q3rJ9U46Op6bEjyQo7LxG5OLTCz2zA5vwetrRpmg310= 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=J/qXeWFk; arc=none smtp.client-ip=209.85.215.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="J/qXeWFk" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-71871d5e087so8165641a12.1 for ; Mon, 05 Aug 2024 09:45:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722876347; x=1723481147; 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=rn6Jl93ozareS6sNo9PKC2R8rRYCzYW2VxDK0LtyPOQ=; b=J/qXeWFkGiVQ6YgaUcJTIDQSjZmTPQqP9IxqoQAbHFQab7D5uluKU2zgmI6r1Qx8uD hImEu9UtzpfBWZ7YnJ/VmD/c2nJVYBrExFH7/9Wgi3Mf4r30DdzkSHm2vBCgqeSBby1i siePOx2CIJ5u670seZ9sh7BEUaaRoKZqHuv1z5N6VatxvKIIjWZwvqC5RJ/tViQ5YGYr OhwLWzz71I/aE492Z2QJ0GEG/1VVBd8HbTcr8Bi4YWuLZtmdXoSKWr5Q1Z6ZWjqj7XxO IhIcIcx2IeQoRmaXlTG5NF/xwkWl0gytDP7vTkOKtWcwaEy5SHlYrHx0L/1Ha96ZrqqQ aZew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722876347; x=1723481147; 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=rn6Jl93ozareS6sNo9PKC2R8rRYCzYW2VxDK0LtyPOQ=; b=YJn4ILa97bDmE+nB88snbT4oA1CuYcnh71bAua4zRtNea/cu+APbDlFj73k/S2bx33 eTjfBkPaCfrURoDJGe76jDF7pTH/Q7PlRTrGIBLOcqaFhHfP3z+/hHKeDa/LuPOtXsi+ HuHRQQ6RXg6NZb5oxJlmlUsYaLI+VF8lLPEZpx76q8K1I7zX7eRE1YHBJf4C+FPoqbaK aMNIGuXU6LsCrXjcnQFPDMuakDOxB5j4SqznL2jG8qqi5Hy0n/ZPad/tQnHsE24E7qYz utpEr5uL+K6Udpf2BMRWzxTSFeVb2CHub1ThqWy1P7vDDRVtyXq6lksxX07BwXYVmB8A Qpuw== X-Gm-Message-State: AOJu0Yw7Vg9PKFCZZR2ogcQihyN5V51It9tMyu+/t3V+YS3JVo/Zy2e9 wt9xYyopj6HbyH5f6LWNKTImI/M2wCcHNExcRst4Sfh/uq3qaUUooa7OCw== X-Google-Smtp-Source: AGHT+IEU/N4uXgtSSj6fnJBcNc9DIraT5Q6dDHAQd3cSc5tkYfiVNSeqYHzUHguJBjOI1H4m96Jdhg== X-Received: by 2002:a05:6a20:1581:b0:1c4:919f:3677 with SMTP id adf61e73a8af0-1c6996592bdmr17495049637.42.1722876347476; Mon, 05 Aug 2024 09:45:47 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed17c76sm5595957b3a.180.2024.08.05.09.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 09:45:47 -0700 (PDT) Date: Tue, 6 Aug 2024 00:46:15 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v15 7/9] builtin/refs: add verify subcommand Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Introduce a new subcommand "verify" in git-refs(1) to allow the user to check the reference database consistency and also this subcommand will be used as the entry point of checking refs for "git-fsck(1)". Add "verbose" field into "fsck_options" to indicate whether we should print verbose messages when checking refs and objects consistency. Remove bit-field for "strict" field, this is because we cannot take address of a bit-field which makes it unhandy to set member variables when parsing the command line options. The "git-fsck(1)" declares "fsck_options" variable with "static" identifier which avoids complaint by the leak-checker. However, in "git-refs verify", we need to do memory clean manually. Thus add "fsck_options_clear" function in "fsck.c" to provide memory clean operation. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/git-refs.txt | 13 +++++++++++++ builtin/refs.c | 34 ++++++++++++++++++++++++++++++++++ fsck.c | 11 +++++++++++ fsck.h | 8 +++++++- 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Documentation/git-refs.txt b/Documentation/git-refs.txt index 5b99e04385..ce31f93061 100644 --- a/Documentation/git-refs.txt +++ b/Documentation/git-refs.txt @@ -10,6 +10,7 @@ SYNOPSIS -------- [verse] 'git refs migrate' --ref-format= [--dry-run] +'git refs verify' [--strict] [--verbose] DESCRIPTION ----------- @@ -22,6 +23,9 @@ COMMANDS migrate:: Migrate ref store between different formats. +verify:: + Verify reference database consistency. + OPTIONS ------- @@ -39,6 +43,15 @@ include::ref-storage-format.txt[] can be used to double check that the migration works as expected before performing the actual migration. +The following options are specific to 'git refs verify': + +--strict:: + Enable stricter error checking. This will cause warnings to be + reported as errors. See linkgit:git-fsck[1]. + +--verbose:: + When verifying the reference database consistency, be chatty. + KNOWN LIMITATIONS ----------------- diff --git a/builtin/refs.c b/builtin/refs.c index 46dcd150d4..131f98be98 100644 --- a/builtin/refs.c +++ b/builtin/refs.c @@ -1,4 +1,6 @@ #include "builtin.h" +#include "config.h" +#include "fsck.h" #include "parse-options.h" #include "refs.h" #include "repository.h" @@ -7,6 +9,9 @@ #define REFS_MIGRATE_USAGE \ N_("git refs migrate --ref-format= [--dry-run]") +#define REFS_VERIFY_USAGE \ + N_("git refs verify [--strict] [--verbose]") + static int cmd_refs_migrate(int argc, const char **argv, const char *prefix) { const char * const migrate_usage[] = { @@ -58,15 +63,44 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix) return err; } +static int cmd_refs_verify(int argc, const char **argv, const char *prefix) +{ + struct fsck_options fsck_refs_options = FSCK_REFS_OPTIONS_DEFAULT; + const char * const verify_usage[] = { + REFS_VERIFY_USAGE, + NULL, + }; + struct option options[] = { + OPT_BOOL(0, "verbose", &fsck_refs_options.verbose, N_("be verbose")), + OPT_BOOL(0, "strict", &fsck_refs_options.strict, N_("enable strict checking")), + OPT_END(), + }; + int ret; + + argc = parse_options(argc, argv, prefix, options, verify_usage, 0); + if (argc) + usage(_("'git refs verify' takes no arguments")); + + git_config(git_fsck_config, &fsck_refs_options); + prepare_repo_settings(the_repository); + + ret = refs_fsck(get_main_ref_store(the_repository), &fsck_refs_options); + + fsck_options_clear(&fsck_refs_options); + return ret; +} + int cmd_refs(int argc, const char **argv, const char *prefix) { const char * const refs_usage[] = { REFS_MIGRATE_USAGE, + REFS_VERIFY_USAGE, NULL, }; parse_opt_subcommand_fn *fn = NULL; struct option opts[] = { OPT_SUBCOMMAND("migrate", &fn, cmd_refs_migrate), + OPT_SUBCOMMAND("verify", &fn, cmd_refs_verify), OPT_END(), }; diff --git a/fsck.c b/fsck.c index 38554b626e..7eb5cdefdd 100644 --- a/fsck.c +++ b/fsck.c @@ -1333,6 +1333,17 @@ int fsck_finish(struct fsck_options *options) return ret; } +void fsck_options_clear(struct fsck_options *options) +{ + free(options->msg_type); + oidset_clear(&options->skip_oids); + oidset_clear(&options->gitmodules_found); + oidset_clear(&options->gitmodules_done); + oidset_clear(&options->gitattributes_found); + oidset_clear(&options->gitattributes_done); + kh_clear_oid_map(options->object_names); +} + int git_fsck_config(const char *var, const char *value, const struct config_context *ctx, void *cb) { diff --git a/fsck.h b/fsck.h index 2002590f60..d551a9fe86 100644 --- a/fsck.h +++ b/fsck.h @@ -153,7 +153,8 @@ struct fsck_ref_report { struct fsck_options { fsck_walk_func walk; fsck_error error_func; - unsigned strict:1; + unsigned strict; + unsigned verbose; enum fsck_msg_type *msg_type; struct oidset skip_oids; struct oidset gitmodules_found; @@ -231,6 +232,11 @@ int fsck_tag_standalone(const struct object_id *oid, const char *buffer, */ int fsck_finish(struct fsck_options *options); +/* + * Clear the fsck_options struct, freeing any allocated memory. + */ +void fsck_options_clear(struct fsck_options *options); + /* * Report an error or warning for refs. */ From patchwork Mon Aug 5 16:46:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13753836 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A66D115F418 for ; Mon, 5 Aug 2024 16:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876359; cv=none; b=ZhT8ExSrm0Qa0jRmzlgBC9hktxkRF3w6lFK/QQw75TbuVdELvBdvvIMBKYcIp3bqPQMPpwaSkPE4Nk9fhJ8W+cfGwoG17DqRnzw6F+mOg8agyPC96OcfOEMKTXXoJoe0mGfy/e7SZe0gcj7Jenars9W64gJyfpYsluQgmpYr4ZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876359; c=relaxed/simple; bh=KRF/lgkg4nJlvvPhfL5akAM4TFBDzTFv3OEGaP46ij8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WdT3xGf3MXmP1dkEIQzjiWldvidzfzMivWf1aNe7jaDRktLKphzQr8HDV/jPfDaiWbYrQtHyyhcQdoKiOLFKAkffTxwgATudasdFQRymRIidhMU0t5ip2yKyR1aCnyUTQhU7QwMYW5kIJMOCyTuxiX9+O+Eipn6pDbJwmBSbx90= 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=eFIFzXdw; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eFIFzXdw" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1fc4fcbb131so92250755ad.3 for ; Mon, 05 Aug 2024 09:45:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722876356; x=1723481156; 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=blnd6GJmx2eh97pHBI5nYwJsboRd771jhYfXZMmtlQ0=; b=eFIFzXdwngU37vIXl2q5sEhBu5E/2QFX0niUZTnuFxWxzNyDGQ6pKWr2le1k0L1HiR OXCKZZDg16Tz6k+JjZb9KevrRjNRZ9spG6C9gh9imSOc8j5PkchIN/LQXwOikDwrZJA9 Sp8gsjcB5cx3l5Ti6JHmN5N+2E+2Bjp21EtXG0LCNhcW62j1xqKguReyMzShtx62qN17 TfjYkmWE/yI2bcEGPPWgfW9Nk+Y/NhRbJDe65HxyThKyvKqDejH5bCxgH7rzlH+QTLkN IUqeMalTyfX+f8LFnHZ/o4y8SSZS1d8E9DyrHQ0A4cAaimwZpINdokYB1GZVo5/WdAXl MMvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722876356; x=1723481156; 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=blnd6GJmx2eh97pHBI5nYwJsboRd771jhYfXZMmtlQ0=; b=OfGse8t8X3oc4HpvJU48a0DKgh9unNktMttpjePFzjQERv8ldFeTRNg+mg/7r2WAFW lOS6GeBkQI/cjTlPVUhyQVU8n5SPqYbufWvlwAzIfV6puW3tU/shpe6KW9NaIKXlR0Ui rq5xOUKvz79oIlQniRmYmkMVAM93ygm3fJarSHtaNPRylJ16OBHKOdokBQ4s9YLhncKY hqlZkVzURDSoI+HlstvodXxP9gQgXDcS3gnnkYrl2G5a+xh+tE83s7SH9u0syI2CLNTb fvBvbGK/T9FHfCN4QtbvvGEhgzZSOqMDJJ5DGeBjrJdRyGAk8mnpBJxGI0n9jjqJ9NVH Y0hg== X-Gm-Message-State: AOJu0Yy5B1TkEsWifSgpkVUbuT0i1d27TJoOxvbL6aSjggU1fIlHZpyS KF+SHyXNddvZ7UV3nLq+Ql1dhcCAm4RyLaZ6/gcv/1M4MHZ8ydZbOuQxGQ== X-Google-Smtp-Source: AGHT+IGRjDxmuGcysYJWEkbtLIIld8jsois4nGAU0SA8rtqjH4QKPnTpDfubCCIq2WBymw6Nfo5CZg== X-Received: by 2002:a17:902:ea02:b0:1fd:5fa0:e98f with SMTP id d9443c01a7336-1ff5737d3famr149632605ad.44.1722876356375; Mon, 05 Aug 2024 09:45:56 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff5905b43csm70224875ad.146.2024.08.05.09.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 09:45:55 -0700 (PDT) Date: Tue, 6 Aug 2024 00:46:24 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v15 8/9] files-backend: add unified interface for refs scanning Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: For refs and reflogs, we need to scan its corresponding directories to check every regular file or symbolic link which shares the same pattern. Introduce a unified interface for scanning directories for files-backend. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/fsck-msgids.txt | 3 ++ fsck.h | 1 + refs/files-backend.c | 74 ++++++++++++++++++++++++++++++++++- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/Documentation/fsck-msgids.txt b/Documentation/fsck-msgids.txt index f643585a34..7c809fddf1 100644 --- a/Documentation/fsck-msgids.txt +++ b/Documentation/fsck-msgids.txt @@ -19,6 +19,9 @@ `badParentSha1`:: (ERROR) A commit object has a bad parent sha1. +`badRefFiletype`:: + (ERROR) A ref has a bad file type. + `badTagName`:: (INFO) A tag has an invalid format. diff --git a/fsck.h b/fsck.h index d551a9fe86..af02174973 100644 --- a/fsck.h +++ b/fsck.h @@ -31,6 +31,7 @@ enum fsck_msg_type { FUNC(BAD_NAME, ERROR) \ FUNC(BAD_OBJECT_SHA1, ERROR) \ FUNC(BAD_PARENT_SHA1, ERROR) \ + FUNC(BAD_REF_FILETYPE, ERROR) \ FUNC(BAD_TIMEZONE, ERROR) \ FUNC(BAD_TREE, ERROR) \ FUNC(BAD_TREE_SHA1, ERROR) \ diff --git a/refs/files-backend.c b/refs/files-backend.c index 4630eb1f80..f337356860 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -6,6 +6,7 @@ #include "../gettext.h" #include "../hash.h" #include "../hex.h" +#include "../fsck.h" #include "../refs.h" #include "refs-internal.h" #include "ref-cache.h" @@ -3408,13 +3409,84 @@ static int files_ref_store_remove_on_disk(struct ref_store *ref_store, return ret; } +/* + * For refs and reflogs, they share a unified interface when scanning + * the whole directory. This function is used as the callback for each + * regular file or symlink in the directory. + */ +typedef int (*files_fsck_refs_fn)(struct ref_store *ref_store, + struct fsck_options *o, + const char *refs_check_dir, + struct dir_iterator *iter); + +static int files_fsck_refs_dir(struct ref_store *ref_store, + struct fsck_options *o, + const char *refs_check_dir, + files_fsck_refs_fn *fsck_refs_fn) +{ + struct strbuf sb = STRBUF_INIT; + struct dir_iterator *iter; + int iter_status; + int ret = 0; + + strbuf_addf(&sb, "%s/%s", ref_store->gitdir, refs_check_dir); + + iter = dir_iterator_begin(sb.buf, 0); + if (!iter) { + ret = error_errno(_("cannot open directory %s"), sb.buf); + goto out; + } + + while ((iter_status = dir_iterator_advance(iter)) == ITER_OK) { + if (S_ISDIR(iter->st.st_mode)) { + continue; + } else if (S_ISREG(iter->st.st_mode) || + S_ISLNK(iter->st.st_mode)) { + if (o->verbose) + fprintf_ln(stderr, "Checking %s/%s", + refs_check_dir, iter->relative_path); + for (size_t i = 0; fsck_refs_fn[i]; i++) { + if (fsck_refs_fn[i](ref_store, o, refs_check_dir, iter)) + ret = -1; + } + } else { + struct fsck_ref_report report = { .path = iter->basename }; + if (fsck_report_ref(o, &report, + FSCK_MSG_BAD_REF_FILETYPE, + "unexpected file type")) + ret = -1; + } + } + + if (iter_status != ITER_DONE) + ret = error(_("failed to iterate over '%s'"), sb.buf); + +out: + strbuf_release(&sb); + return ret; +} + +static int files_fsck_refs(struct ref_store *ref_store, + struct fsck_options *o) +{ + files_fsck_refs_fn fsck_refs_fn[]= { + NULL, + }; + + if (o->verbose) + fprintf_ln(stderr, _("Checking references consistency")); + return files_fsck_refs_dir(ref_store, o, "refs", fsck_refs_fn); + +} + static int files_fsck(struct ref_store *ref_store, struct fsck_options *o) { struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_READ, "fsck"); - return refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); + return files_fsck_refs(ref_store, o) | + refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); } struct ref_storage_be refs_be_files = { From patchwork Mon Aug 5 16:46:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13753837 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B338150269 for ; Mon, 5 Aug 2024 16:46:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876368; cv=none; b=EIqVO3sssYyZ9nnbwVosC1CwnILeufgCmt0ZVHghUuKx52gqjpchJag+svR2NKgRXC6ihR+zV5M9n4WODMkBcevetGvjxX1S4q10NEj1HWdKCE2UGDpFulxiexM878HTM7GDoq5anvXkLb5gJ80LINE9XpYJdhvZlfJ9NZwmp70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722876368; c=relaxed/simple; bh=x1x0/L17MIv7FWq0nll16j0kP+Ld8pB6mIkv4TCw6FY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ABPf3f7rjJY7jgZqzgtxD8GDc1R0vGgvDgJM/HrDQKZnRo5xsuvXnzKqZKn4WfLBkJjFVnQjCTEFtMu3QfULIxdHZEcf081rb4wP/RgjNG7LSedK9osOMmdag8F00Vas9eWtFJBmiBSqMQQG+a1EzQxojrbdG8+MqSyvTK2wOEs= 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=fLHi3Pyx; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fLHi3Pyx" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7106e2d0ec1so2752358b3a.2 for ; Mon, 05 Aug 2024 09:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722876366; x=1723481166; 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=7GVLAk1nKGAH84IIInM1iVRMLBlvgEqAvSnpkhYWf+o=; b=fLHi3Pyx5Fqtrl1HKlIXZ1xM+5IYycSS+4SxB9gSko0gWMUeMfknZOhAk5K0vJZ4K5 PHABvXmEaTk5FiJqwWbFquNWGdjp0c3xy/MzjIiARPBZMZjjz71jdx8BzaG2E2D2h8i1 pP7RO/l4Z3hMgknTLgwUNwCMj8FPMxfhhXtKBoYIGN3rikq0cgOcPsbJWk3fUl2U9/kF G1hyzlBQuS2Im7AAnF4h3TwvaSjKkE8GAkHfWII28VhLGLj+s/e4DFuX8drA+pPJhgmX RaE645SONEIV7BHgZVyHGhZNt3BTVpQQ/JomMu4rkv8jOHrTIlnFKUXuKGLhFf7daPxZ bKNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722876366; x=1723481166; 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=7GVLAk1nKGAH84IIInM1iVRMLBlvgEqAvSnpkhYWf+o=; b=v2oVvxOzR3IKOYl1e87EQbywkeRKUsHU5kItF/N0sJsc9KGVicwavlRQuun+N/3ffp OO/ZJkVxUPHGRQiRBicTl379nGNwZgd+TaHyrZMgDuxOtnZR6rm0ievtYbVsTsjbgbcI xzR1WAoGcDbTupK9s/uTd09mn7wCYaKM9tu8F86xkOAaNDDKRzmeKvBJ634moBCKtjdd A7wG/EfEBgT34lScp2Xv1Yr3VxfrC5DIBhkmvwz40ZHsW7zIG3+CuCg8UZeXqdI3dnxA v7kc15QEiRvRUbMfPJMDevfvQ0oJkubLp3lE8GiYa6R41Fxq/40n3obBWcJaNdULD2Gn GsjA== X-Gm-Message-State: AOJu0Yzlh86avqRVHFPwo0IdY+O1IRcw2wW0Ik4xxZwPp94uouBlF5Wh tIcEzoNFeMoYkbt1HPQigvyyBwjzjnUYlgXz4hcFTLQfDF/lkPas7WmbUQ== X-Google-Smtp-Source: AGHT+IELABheRQ4rPdOAWzOAUhuB63RBuYA7cZTA8q1qV/Rl0rqumVEVCRHbI0Pt8vGbIlXSqOdknQ== X-Received: by 2002:a05:6a00:9158:b0:70b:20d9:3c2a with SMTP id d2e1a72fcca58-7106d045555mr11466028b3a.28.1722876365480; Mon, 05 Aug 2024 09:46:05 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm5571962b3a.191.2024.08.05.09.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 09:46:04 -0700 (PDT) Date: Tue, 6 Aug 2024 00:46:33 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v15 9/9] fsck: add ref name check for files backend Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The git-fsck(1) only implicitly checks the reference, it does not fully check refs with bad format name such as standalone "@". However, a file ending with ".lock" should not be marked as having a bad ref name. It is expected that concurrent writers may have such lock files. We currently ignore this situation. But for bare ".lock" file, we will report it as error. In order to provide such checks, add a new fsck message id "badRefName" with default ERROR type. Use existing "check_refname_format" to explicit check the ref name. And add a new unit test to verify the functionality. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/fsck-msgids.txt | 3 ++ fsck.h | 1 + refs/files-backend.c | 31 ++++++++++++ t/t0602-reffiles-fsck.sh | 92 +++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100755 t/t0602-reffiles-fsck.sh diff --git a/Documentation/fsck-msgids.txt b/Documentation/fsck-msgids.txt index 7c809fddf1..68a2801f15 100644 --- a/Documentation/fsck-msgids.txt +++ b/Documentation/fsck-msgids.txt @@ -22,6 +22,9 @@ `badRefFiletype`:: (ERROR) A ref has a bad file type. +`badRefName`:: + (ERROR) A ref has an invalid format. + `badTagName`:: (INFO) A tag has an invalid format. diff --git a/fsck.h b/fsck.h index af02174973..500b4c04d2 100644 --- a/fsck.h +++ b/fsck.h @@ -32,6 +32,7 @@ enum fsck_msg_type { FUNC(BAD_OBJECT_SHA1, ERROR) \ FUNC(BAD_PARENT_SHA1, ERROR) \ FUNC(BAD_REF_FILETYPE, ERROR) \ + FUNC(BAD_REF_NAME, ERROR) \ FUNC(BAD_TIMEZONE, ERROR) \ FUNC(BAD_TREE, ERROR) \ FUNC(BAD_TREE_SHA1, ERROR) \ diff --git a/refs/files-backend.c b/refs/files-backend.c index f337356860..6e6b47251d 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3419,6 +3419,36 @@ typedef int (*files_fsck_refs_fn)(struct ref_store *ref_store, const char *refs_check_dir, struct dir_iterator *iter); +static int files_fsck_refs_name(struct ref_store *ref_store UNUSED, + struct fsck_options *o, + const char *refs_check_dir, + struct dir_iterator *iter) +{ + struct strbuf sb = STRBUF_INIT; + int ret = 0; + + /* + * Ignore the files ending with ".lock" as they may be lock files + * However, do not allow bare ".lock" files. + */ + if (iter->basename[0] != '.' && ends_with(iter->basename, ".lock")) + goto cleanup; + + if (check_refname_format(iter->basename, REFNAME_ALLOW_ONELEVEL)) { + struct fsck_ref_report report = { .path = NULL }; + + strbuf_addf(&sb, "%s/%s", refs_check_dir, iter->relative_path); + report.path = sb.buf; + ret = fsck_report_ref(o, &report, + FSCK_MSG_BAD_REF_NAME, + "invalid refname format"); + } + +cleanup: + strbuf_release(&sb); + return ret; +} + static int files_fsck_refs_dir(struct ref_store *ref_store, struct fsck_options *o, const char *refs_check_dir, @@ -3470,6 +3500,7 @@ static int files_fsck_refs(struct ref_store *ref_store, struct fsck_options *o) { files_fsck_refs_fn fsck_refs_fn[]= { + files_fsck_refs_name, NULL, }; diff --git a/t/t0602-reffiles-fsck.sh b/t/t0602-reffiles-fsck.sh new file mode 100755 index 0000000000..71a4d1a5ae --- /dev/null +++ b/t/t0602-reffiles-fsck.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +test_description='Test reffiles backend consistency check' + +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +GIT_TEST_DEFAULT_REF_FORMAT=files +export GIT_TEST_DEFAULT_REF_FORMAT +TEST_PASSES_SANITIZE_LEAK=true + +. ./test-lib.sh + +test_expect_success 'ref name should be checked' ' + test_when_finished "rm -rf repo" && + git init repo && + branch_dir_prefix=.git/refs/heads && + tag_dir_prefix=.git/refs/tags && + cd repo && + + git commit --allow-empty -m initial && + git checkout -b branch-1 && + git tag tag-1 && + git commit --allow-empty -m second && + git checkout -b branch-2 && + git tag tag-2 && + git tag multi_hierarchy/tag-2 && + + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/.branch-1: badRefName: invalid refname format + EOF + rm $branch_dir_prefix/.branch-1 && + test_cmp expect err && + + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/@: badRefName: invalid refname format + EOF + rm $branch_dir_prefix/@ && + test_cmp expect err && + + cp $tag_dir_prefix/multi_hierarchy/tag-2 $tag_dir_prefix/multi_hierarchy/@ && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/tags/multi_hierarchy/@: badRefName: invalid refname format + EOF + rm $tag_dir_prefix/multi_hierarchy/@ && + test_cmp expect err && + + cp $tag_dir_prefix/tag-1 $tag_dir_prefix/tag-1.lock && + git refs verify 2>err && + rm $tag_dir_prefix/tag-1.lock && + test_must_be_empty err && + + cp $tag_dir_prefix/tag-1 $tag_dir_prefix/.lock && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/tags/.lock: badRefName: invalid refname format + EOF + rm $tag_dir_prefix/.lock && + test_cmp expect err +' + +test_expect_success 'ref name check should be adapted into fsck messages' ' + test_when_finished "rm -rf repo" && + git init repo && + branch_dir_prefix=.git/refs/heads && + tag_dir_prefix=.git/refs/tags && + cd repo && + git commit --allow-empty -m initial && + git checkout -b branch-1 && + git tag tag-1 && + git commit --allow-empty -m second && + git checkout -b branch-2 && + git tag tag-2 && + + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && + git -c fsck.badRefName=warn refs verify 2>err && + cat >expect <<-EOF && + warning: refs/heads/.branch-1: badRefName: invalid refname format + EOF + rm $branch_dir_prefix/.branch-1 && + test_cmp expect err && + + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && + git -c fsck.badRefName=ignore refs verify 2>err && + test_must_be_empty err +' + +test_done