From patchwork Thu Aug 1 15:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750636 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 CF0F713B5A5 for ; Thu, 1 Aug 2024 15:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525192; cv=none; b=P5L4LDjLhaJ9eORjXIucGa+pz6abOq1ggWzInqF2w2xxgU/FJe6lRAdJalG31VUTdZP3LhbrDxSY4Tzjzmeh0b+Xcfqpq3uYDAD7VJlZBrMa7d6ijWaLZTVY6zcSodWL6QeGcjOYw+QY9P8kby0bjDDqQNyQiMJ9xj5CaGkbC44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525192; 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=SDOLNqywsBRlfWPiNicoAAbgfxw7JMP1ypGt8EgkgFyjLdOvtZU5udnqJW5+o28kxK65Ce6BlWS4o9Y2Dvjfs3jnXXLw9p3LrUT/++h5EwXH5SHc3aBwCyT43/kCdWQnclht6SS1lEazos1ci61hn7VhMc+jsA/OmEdoFtzdmWY= 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=ZS5M/1IK; arc=none smtp.client-ip=209.85.210.177 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="ZS5M/1IK" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70d150e8153so1552732b3a.0 for ; Thu, 01 Aug 2024 08:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525190; x=1723129990; 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=ZS5M/1IKPeo6B6/JOlKPVWL68V3kqgqyOo0OJsaUyPK9von/xPIp9wgxh4aaTC0BUJ Bpev/16BVHj27NZX71qbVyEZPMZqBz2At0Xr4hyBz6oXFriUFj8q5Q0S72ReCslcxwCC 3h1TCz2wnF3kTGvQ35jaFzIdWg+8E5krXcCe5a1QOjdvxJD0q5vAZTlc5OxQEPaoFXgC d5dJoTOn4N54Dl/vmSiM22aTG1ZLOTgU1wJMBDR7nyVzgeZ93mZmUHlGyn++xWuFllSs pKp94IGUVyJR9rHjNV3Z02AJm63ge0dt25e9Si+X34Gy3AA/qOYrIus3QYPzrTvzk85/ 1IyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525190; x=1723129990; 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=uce9fVPc99/0SESt4KRaJhFVFeY01fbT6kgFQeHqbUTbgeKsb4JQsjJ0Zm5p1qLgVd bHVgwR0JA54LV6x7puYet2yLj2XaX2IVmZFai8yq9SNiEh6wmqzP/qNWTXvNy0aAQ3oV JQwXEH/JlvKB4IT+RsKG9kqgpWbPzaBdWQjEs19YsDhyLyqQ+SIHRy7BrE/SrY++isZI 4yZCTboEg5pLRhNOieqp/EW6cZnT6D9xXvmMzirMr9uvzN8r+KfANH6sZPIfVKVhJKJl Ulc67DWzM+a/+pk9Ge5RDljuAk0GH9iNK3jBUT7JasbBe95WVD2yBUPaDhYgLD9G2JIZ L+8Q== X-Gm-Message-State: AOJu0YybfQ9vlm6MqNrgEGfH7G1GFAAODtPKvWaSWJTOOVs8OD3u7l9L tqhhEaj4dcG2xtpftKCCYtuloWnqZZtvvxnoV5RDe/RmArfaZY8xsWXvUw== X-Google-Smtp-Source: AGHT+IGX+BKBUZwbi9IIKRe3lxNQDJnNQ5wLfVRQ4cA6X9fqASpf7mD7nkxs+OIQaFjIs90AmlGFdw== X-Received: by 2002:a05:6a00:8583:b0:706:5daf:efa5 with SMTP id d2e1a72fcca58-71065e9d3d8mr2470000b3a.9.1722525189590; Thu, 01 Aug 2024 08:13:09 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7a9f9ec7acdsm12108329a12.66.2024.08.01.08.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:13:09 -0700 (PDT) Date: Thu, 1 Aug 2024 23:13:32 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 01/11] fsck: rename "skiplist" to "skip_oids" Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "skiplist" field in "fsck_options" is related to objects. Because we are going to introduce ref consistency check, the "skiplist" name is too general which will make the caller think "skiplist" is related to both the refs and objects. It may seem that for both refs and objects, we should provide a general "skiplist" here. However, the type for "skiplist" is `struct oidset` which is totally unsuitable for refs. To avoid above ambiguity, rename "skiplist" to "skip_oids". Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 4 ++-- fsck.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fsck.c b/fsck.c index eea7145470..3f32441492 100644 --- a/fsck.c +++ b/fsck.c @@ -205,7 +205,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) if (!strcmp(buf, "skiplist")) { if (equal == len) die("skiplist requires a path"); - oidset_parse_file(&options->skiplist, buf + equal + 1, + oidset_parse_file(&options->skip_oids, buf + equal + 1, the_repository->hash_algo); buf += len + 1; continue; @@ -223,7 +223,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) static int object_on_skiplist(struct fsck_options *opts, const struct object_id *oid) { - return opts && oid && oidset_contains(&opts->skiplist, oid); + return opts && oid && oidset_contains(&opts->skip_oids, oid); } __attribute__((format (printf, 5, 6))) diff --git a/fsck.h b/fsck.h index 6085a384f6..bcfb2e34cd 100644 --- a/fsck.h +++ b/fsck.h @@ -136,7 +136,7 @@ struct fsck_options { fsck_error error_func; unsigned strict:1; enum fsck_msg_type *msg_type; - struct oidset skiplist; + struct oidset skip_oids; struct oidset gitmodules_found; struct oidset gitmodules_done; struct oidset gitattributes_found; @@ -145,7 +145,7 @@ struct fsck_options { }; #define FSCK_OPTIONS_DEFAULT { \ - .skiplist = OIDSET_INIT, \ + .skip_oids = OIDSET_INIT, \ .gitmodules_found = OIDSET_INIT, \ .gitmodules_done = OIDSET_INIT, \ .gitattributes_found = OIDSET_INIT, \ From patchwork Thu Aug 1 15:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750637 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7408913B5A5 for ; Thu, 1 Aug 2024 15:13:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525209; cv=none; b=vEzhiymtWw4XIxnkBinKtkEjaGuc60DlDPSvpUKVIq50wXvTdBALtkI5051QyehCjI0wCqHx/7nb6phUhLx07JxY3ilAWFxa1Xwz3oyKpqzYFQF/jRAWYupu2Uq1N9kAAgngnh8ZbDhlANs24a853bgB1GDXU33Q+fyv7pQ6eLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525209; c=relaxed/simple; bh=hK2rKftTrWOid2HvkeshtVcyXC4+9HkytjFdZ4GLRUs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m1iDn1ti6FZS3Vw6EEfUq9uoJWfSqB72f19mqzGWU3ee3guF8YPAnDbkeHJGTo9uq7MoaQAL+JJNoafcamYmcCaQpoEguXKvD8m0duzEwCAYqHvgA9LRr5xLubVp3hENCBDE443Ep9h+bh9lIcct9O+dWkK+t30ns8dlOERpKhs= 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=a/uBUeXq; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a/uBUeXq" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fc60c3ead4so51956495ad.0 for ; Thu, 01 Aug 2024 08:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525206; x=1723130006; 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=OEH1VTM2azpMrJWxk7om/YrgqmVLNtPFXWfi2cGKgmM=; b=a/uBUeXqg6wPDmbXbMoSDtBFy+ztFp4skSjys07zk2szxjp9IC7NHSKcOkXDbpZehV mPJqwTXoekIs1XSXUXVno1SqQwhT+ldAsQln4LYH47zwyZ6Qann8wAc7JukUtYPDKKDg vwSxcw/vpwHoV54A1eAh8Y6n4PY+gtkaAF4CX3pw7IMk5NSz4gL1zkXDhZnvEB6XcTof cxH674gEFe7InC68M5iTkuifKVIg95oORZkGRdk3tkjsFCxX1/ISQ70GMYKXS2fFh4Jx 6O11w9fXhjpDVdSgey+T0RbvJO70l1EkG9DdF6wsYyOURW/UWpeu29enkYVQcYR64b7J qa8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525206; x=1723130006; 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=OEH1VTM2azpMrJWxk7om/YrgqmVLNtPFXWfi2cGKgmM=; b=kN5ZJ3mUQ9ja3ouJ0mkrr/+faOkdYLKv6zQIXdeorwSZ/mIG48mr+mpfngpFyYH8bh EWpaAvL+9w0CxqlBSi9R/GF4kxCvm7K4cAoWusioWj0ZctVISFxAhwI8D9JWVmZDY1A0 BRvT5qBUnbYV1d1UzgMETxki/cbn/tGe68R7+bMw9Wn2B30fO567120/rgwdAawiskOH lLmwBrXoytBF6I6aaHiybNt0xhS1FrRTmqnP1z8QGUJgkPCVIlMplSBi3uNd0/yNRKXA jhfBZJ4mK/TuZQD91Zqp9u81AM95WTScBw4RX/AmMfFb6bIKsFrYVIDSoi5+rupQ1gYf vGRA== X-Gm-Message-State: AOJu0YyDg5ovDJmqvz52c3SpQbkG1YlBu/Hm9vru05DJSml9jm2t2pVL CihJBPdgTOmnW3EAFWLH0ipPw3WSAorYHqpwZqSs8vCT/y+eiYAIxO1fww== X-Google-Smtp-Source: AGHT+IFKIvvuGtSAAUp8HqdyvzQJMQ+2QX3Ydp1mbtbDH5P9QrughK6B7nQWrbWr71IOXgu66rC0uA== X-Received: by 2002:a17:903:1245:b0:1fd:88d2:47f6 with SMTP id d9443c01a7336-1ff573e72c6mr5806995ad.38.1722525206262; Thu, 01 Aug 2024 08:13:26 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c88bd1sm140638905ad.12.2024.08.01.08.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:13:25 -0700 (PDT) Date: Thu, 1 Aug 2024 23:13:49 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 02/11] 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 | 20 +++++++++++++------- fsck.h | 17 ++++++++++++----- object-file.c | 9 ++++----- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index d13a226c2e..9673a08286 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_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 3f32441492..4c1f8bc44a 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_error_function(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type UNUSED, + 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,15 +1310,15 @@ int git_fsck_config(const char *var, const char *value, */ int fsck_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_error_function(o, oid, object_type, msg_type, msg_id, message); + return fsck_error_function(o, fsck_report, msg_type, msg_id, message); } diff --git a/fsck.h b/fsck.h index bcfb2e34cd..303174a5d8 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_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_error_cb_print_missing_gitmodules(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type, + void *fsck_report, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); +struct fsck_object_report { + const struct object_id *oid; + enum object_type object_type; +}; + struct fsck_options { fsck_walk_func walk; fsck_error error_func; diff --git a/object-file.c b/object-file.c index 065103be3e..05ac6ebed6 100644 --- a/object-file.c +++ b/object-file.c @@ -2470,11 +2470,10 @@ int repo_has_object_file(struct repository *r, * give more context. */ static int hash_format_check_report(struct fsck_options *opts UNUSED, - const struct object_id *oid UNUSED, - enum object_type object_type UNUSED, - enum fsck_msg_type msg_type UNUSED, - enum fsck_msg_id msg_id UNUSED, - const char *message) + void *fsck_report UNUSED, + enum fsck_msg_type msg_type UNUSED, + enum fsck_msg_id msg_id UNUSED, + const char *message) { error(_("object fails fsck: %s"), message); return 1; From patchwork Thu Aug 1 15:13:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750638 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 23AA33A1DA for ; Thu, 1 Aug 2024 15:13:36 +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=1722525218; cv=none; b=HnUU/5PcjXGM26jL3s2K3DYYG28AtUmEFw68GkvwKeihpwMaO+byDXWh175ux7NzboU6FNeZkCztMy1vib2goatSkBk3nUw81yyXD/fD2aTNjLWDjHW+RH9IIXUKmlX1VTN5mYrwuOBCj+emSuXqT9h6WuAgVT9xkx+z8LFXu7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525218; c=relaxed/simple; bh=um5c9AAeW/wdAvSIUcmrMHrd9z2JtsMO+Ko9AbjVtks=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cMvZRa8zyEp4sh47rBXNUlixuESsRvfw6CTu1xv2Fw8T4aErJQEgGpnV/vMDgBdX81mUBPf2tNIbUW8etd3VE4IAJozchiizR99MyAwEadI4oj9C3xbXz2T0KlHi2K/HXfemtFFDzBx/nUyx6eAKcthZc8S+dLyd1gNe+e2QlQw= 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=TXOcBGwI; 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="TXOcBGwI" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fc491f9b55so57252195ad.3 for ; Thu, 01 Aug 2024 08:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525216; x=1723130016; 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=RLlGp5Upqqr8ky9vVK99rNVEaNiHcQgkZmpa6IH8Ep8=; b=TXOcBGwIR8K1eeaNJff7Czv2Go7zcP12oBfse1vrU4kibMlhD5NsuXoMuqqxm3i9UK yrrCNp8oakMpuDN3fE3N9mxeBk5tnGV9/4ZAGvJteaOHlCYpJU2UJQ9re7gxoghSfHBJ SDCGz6meAekoML3XPV897sB7bxi2Wo7wTKrIsSrSrPcWMOQS5I0wWCm4OS36TtRV+jVt lWN5ZVXZ9FfKLIBkVns8zxB0P39e1xLkpnmMIUqXgvVjkzSWH5BcaWQMaNsfm0x7MkAO H1D5GyEXWCODdV1mFrndJlLAjS77EKzHcEkt7NKuO9yxRnYyLj8usHoZ+t9b2wi8avOP fAqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525216; x=1723130016; 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=RLlGp5Upqqr8ky9vVK99rNVEaNiHcQgkZmpa6IH8Ep8=; b=MTzzFgGjr5IbzdzsHh3qN2IpVLFERpsqBkL4nwqCo3Lm8V/GbGET88v1idRyNW0Apq +gQvOGuLU0ojCLB/5qmBEY89YCQAr/strjOoN6F+L9bIHq8BQWjgXcbMbmsvdMgg9t/4 i8ggYbMZ9iWHDjnpYcwGOHrvoUudl5DvvSq2SBl6TRzXJLoLgA5sscjQKft8eUOf8mQm Tgk4U4IuLW0Y+TXCocLGsBJUddZoFUMI9fWWkMow31PkXsLtfF04BSyQZKhp7IXw3rjn OHGg2JyxkQ/zBtJ3bgad6JHT8iIibKsfMqM+K0DhC5d3U6FPqfMsAYTieD5PzCzJYMJ3 mPUQ== X-Gm-Message-State: AOJu0YxpLWs+40aPRmZ2/iud9ggQxwpn0euW7GjWe1fE52QgkN/gmKJR M31aj7KVjCFebd/jwmdfg0U1YP1QPnx0t/MaCso2CIxB92c7loKW6HpHlA== X-Google-Smtp-Source: AGHT+IHuJvPYGlu/Hl4SSakkbr+MbA9kTqlojjgfi9tw+uWaFATqlekTi9G7U34sJmX9G4/iHNRpBQ== X-Received: by 2002:a17:903:24f:b0:1fa:8f64:8afd with SMTP id d9443c01a7336-1ff5722eb62mr6872345ad.11.1722525215867; Thu, 01 Aug 2024 08:13:35 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7ff3d64sm139967215ad.299.2024.08.01.08.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:13:35 -0700 (PDT) Date: Thu, 1 Aug 2024 23:13:59 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 03/11] 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 | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/fsck.c b/fsck.c index 4c1f8bc44a..b394a9e397 100644 --- a/fsck.c +++ b/fsck.c @@ -226,16 +226,16 @@ 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 - }; + va_list ap_copy; struct strbuf sb = STRBUF_INIT; enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options); int result; @@ -243,9 +243,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,9 +251,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, &report, + va_copy(ap_copy, ap); + strbuf_vaddf(&sb, fmt, ap_copy); + result = options->error_func(options, fsck_report, msg_type, msg_id, sb.buf); strbuf_release(&sb); va_end(ap); @@ -264,6 +261,28 @@ 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; + 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; +} + void fsck_enable_object_names(struct fsck_options *options) { if (!options->object_names) From patchwork Thu Aug 1 15:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750639 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FDD63A1DA for ; Thu, 1 Aug 2024 15:13:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525229; cv=none; b=uNZ/4JzpJgq+SdOTbiu4+agUJMqZwr49fgYrG7B1nRa+xbUAPU3cy84CPElIj+u27EtGwp+C2k/EqR4S+vZVwwIzGOVpK7joxYZV8riE0f52V9hB8st5WbFozysTO8od5thnKH48Tp5h3i9IpTwsbwvh/xK47wtHizKODJ2z8vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525229; c=relaxed/simple; bh=JWA9C/w6/YEmcyu2LVLWTzQ03HSd0hXmPaEh2daC8o8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GvRWMc7ZjQ2RlKPgK2fx4bsVmRLUBXXsDwHBEQ0rA0OC7RpnheOpmOXOK0gdN/0YDfdh0Dgn2O5WH2VmN6qiotU+vsCTjbzHKh8LIxcrNN8CUX3keuB1WTrY2BJmaN+p5xJWsekltxvlg2s6qSH1b9Ovdc2hQtr7BDJfkafHu5U= 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=gUZn6Dam; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gUZn6Dam" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7a211a272c2so1589004a12.1 for ; Thu, 01 Aug 2024 08:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525227; x=1723130027; 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=Ek0KmnveNvhPA0ztSFdEjl/iAZjrx6Y6BTC+LYQIuzs=; b=gUZn6DamvWZrFAUB5awgOhd/1HfJoNoJL5TMKCmT6nuZ72LwxFcn6AfJ2zO++lXeME 7oMwSXyoRPAVnrzj87bOO7pz8dz2LCs6bmKRR7rJMXVjEsF5l2NrMacJxe6GaEPr3xY1 VP4HCLbRJgoppJ0ghjjJ7tRF2sBwynBQqG6l4o7zOWZqHBpzUhvmbL9sMbsMWgy/0hcR jdJ0f88PvyZntrjynp4sf5fvpkD/+1tzyYrCM2rVGu1tUAVA3AgsS0cGOk92ydTSJZhC 0H1G3G76aOBvzTZ3qlpv2EENn+XdfHfID9Msgu/Y45f3wBZ3Gh+IB0I4nTY5R03Olh2O eILQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525227; x=1723130027; 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=Ek0KmnveNvhPA0ztSFdEjl/iAZjrx6Y6BTC+LYQIuzs=; b=DEEvAhwVqL9thSs7NYq/r+jorAhC8d+1Jnn4HDGxniv5AserOtb0cWRbMhc0CRFHz/ kFWvWpszTYnOrEJEt7rvZrUV0rCbqD6BdSy6sgRc7tDdQTQ9bCx0AO13Iqu5lOI5E0JU dzKchrt6oejxmvLjayeyclU9OFXdEG2T8Zo8Df8aAav/89VKvJ5uD417P7KQR4F+QHRI SJ3bsClUMyDzCHLryQhFBrIuGlwrpUeigQChsjLD/bsK4TIkRKywWA0YQBbkmPHv5PBq 2WtiuFaae7e7ca7rWWIUQKjMmiJVwFiMSCRT904s98kTfHJffhv0uTDlY/U38chlOxfr +veA== X-Gm-Message-State: AOJu0YyaIv14tvx5kSM1cB4AIROplVDTxqdu8kiAJqYTNHs9uU0kO5KJ ctc/JFJaX7tzg/9bB1OIzUxTNa5h/QdC9qGBF2yb3x0DcgbYiWBKaaYb+A== X-Google-Smtp-Source: AGHT+IFLq145MnQf5fgzTZVKHOnZ13p3jsYocdZ4qCmWmArF1BP6hZkDAdl3TEGpm7ynVbcobL0F0w== X-Received: by 2002:a17:90a:a413:b0:2c9:75a7:5c25 with SMTP id 98e67ed59e1d1-2cff0b23d54mr2678718a91.15.1722525226975; Thu, 01 Aug 2024 08:13:46 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cfdc432b16sm3449462a91.21.2024.08.01.08.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:13:46 -0700 (PDT) Date: Thu, 1 Aug 2024 23:14:10 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 04/11] 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". Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 13 +++++++++++++ fsck.h | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/fsck.c b/fsck.c index b394a9e397..ee888c1417 100644 --- a/fsck.c +++ b/fsck.c @@ -283,6 +283,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) diff --git a/fsck.h b/fsck.h index 303174a5d8..0918c28d0f 100644 --- a/fsck.h +++ b/fsck.h @@ -138,6 +138,12 @@ struct fsck_object_report { 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; @@ -216,6 +222,16 @@ int fsck_tag_standalone(const struct object_id *oid, const char *buffer, */ int fsck_finish(struct fsck_options *options); +/* + * Report an error or warning for refs. + */ +__attribute__((format (printf, 4, 5))) +int fsck_report_ref(struct fsck_options *options, + struct fsck_ref_report *report, + enum fsck_msg_id msg_id, + const char *fmt, ...); + + /* * Subsystem for storing human-readable names for each object. * From patchwork Thu Aug 1 15:14:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750640 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9549B13C3D3 for ; Thu, 1 Aug 2024 15:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525240; cv=none; b=pLdqPXebGgB3AU6nsXMpNMhUyw4QwMid+sSEPSIBuSNEPzEm+ifIlRQw6K0+0Wg2qyRnOUfkRsKD4Y8Wkf5EQQRUD7k+40NtAfN2FSEn/HPmTyA+jatQTONLwKkxxwd/r/8dnTLbzw3bNSUEVUDBCopltFKTusxy3D5/RSQ4VvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525240; c=relaxed/simple; bh=b9TeBjnI+jum7AEuxDXZ4/MnmzQsGwYWpzi5ak23yco=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m/B3GGCCrp6m4WLMRcbxMMFOLx4j6NfiANkAGuSt6sh4lci20Z4UkNp2grjFoEyi8yo+S34LlZIE8uwxjI/Q7I/nwyGt/whSBGN16xXLImmfpB7wTHWV4nyYd81h3d1gI2lj7LXYlurO2uQdVLdI3SgsUqSNISU/HzbVFCBXIks= 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=BAph++uC; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BAph++uC" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-71871d5e087so5386809a12.1 for ; Thu, 01 Aug 2024 08:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525237; x=1723130037; 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=CyzDdaHjOxmEoIAO34N4rOjR3UvM+wVxuEtNPmA378Q=; b=BAph++uCoFYJnw5O9UMC7FB9+JVV/Kj6M2dFqT/2hUscRFNb/JXG6J9DjKxHL1kek4 A4kVF9wv8F7D0QweHWe5r0WCyDSdl5EznI0JovpPeA9kEfWSirWP+c9LU0bfSM/sER9H VW6NISl69/NmE/NjDFa/vjACsnGSlyVVQizx30bsSVYEqlT3WUq5dxAd/fqGco3GX/Rf 2dGo6gNqwN+0idx1Fwp/l7NvZyqyDbHMBDoyKqYSa27XP+3b0EoRdkIS8MV7u9RGm6ui MjZMM14BN2AD/DfkRCb5SkD0V7uzNUu7eCSsXlS71pSJBm7jCPBc64+4HeNvaoo4mjho R8nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525237; x=1723130037; 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=CyzDdaHjOxmEoIAO34N4rOjR3UvM+wVxuEtNPmA378Q=; b=T40zwX50w+0PoFICiiDkA3KJiEFdBDxBiP4W5N1affFDFWwOKyC9417+wU61tB2F+M WHDPQsA7hMj+XRzQXmeGJxsEDb2kcZOSF97wdqnIZOsbrxVlZlUUBv41nNsjrMEE5/3W l2nGYuWzvNv8QEGN8wHgL+fWlN6y91pLOwniK8QhzOd9BoMsUcv4X37atNKv1JFbrP8F k6OnicPMXp8ItMuod0WY1GjVcwMxWKgrbacw8gksufcvSZT42d+k/VV0oXn+Dijwk2hR sQ+H4lGX4ka7echksxzCkD/DwVO0MEA2afcEQiH1us/mcFYPU+qZL9eJlxxP7cIsSn3T pbbw== X-Gm-Message-State: AOJu0Yzw48NyxJ1R1JWF39eRTVzHd+wK8Mf0/btmc6I59yuMSdwrEv3j ClpU8DgHqpIiGKP/d/WIaTPoQ2o8TgKR2yJOQ623cXO2uhmiP1KF6e+kpw== X-Google-Smtp-Source: AGHT+IH8CwrXYyU2UynF0fJo5WROzi6Q7TsY5UQhUI5vNi3oO3WrOFtxcLkBcUmianEPrUZhyO1tBA== X-Received: by 2002:a17:90a:f02:b0:2cd:ba3e:38a5 with SMTP id 98e67ed59e1d1-2cff9469006mr594546a91.21.1722525236900; Thu, 01 Aug 2024 08:13:56 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cfdc4cf176sm3459372a91.43.2024.08.01.08.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:13:55 -0700 (PDT) Date: Thu, 1 Aug 2024 23:14:19 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 05/11] fsck: add refs-related error callback 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: 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 | 28 ++++++++++++++++++++++++++++ fsck.h | 9 +++++++++ 2 files changed, 37 insertions(+) diff --git a/fsck.c b/fsck.c index ee888c1417..f0ae760c86 100644 --- a/fsck.c +++ b/fsck.c @@ -1253,6 +1253,34 @@ int fsck_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 0918c28d0f..2276ea7e34 100644 --- a/fsck.h +++ b/fsck.h @@ -133,6 +133,12 @@ int fsck_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; @@ -181,6 +187,9 @@ struct fsck_options { .gitattributes_done = OIDSET_INIT, \ .error_func = fsck_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: From patchwork Thu Aug 1 15:14:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750641 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.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 01BD513B5A5 for ; Thu, 1 Aug 2024 15:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525249; cv=none; b=RsdbgraZPwX67JZMjw8hlH6mvxGx/4lT3yg3y0TRnImOik61yhCDiD+RKme7g6BSjkZDrBBVjQgSDTIul0jvaMZuQO76rw/K4RMMQ/fJEXrkNn8RIvVHECfQE31Bn+ekcJTGz1qGb1k8eHZqc7q1f1W3ud8Wwo4gm+J/AvzxUBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525249; c=relaxed/simple; bh=0w40N95UwS3rC1/w4Vwom3FaqlpF0OqwCVE/XHl4y0M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Xlh7S2pwS1nWMXCh/xP6/VkuXJzQCDBajdxffwXp8No6qMK8pFfdonkLUTnbblGamIo+YRCHNTiXmF+Z2c6CkVZSgkx/CHLMwa9FjxGSN5AIZVG7sCryLAo7nmrWC5mECUKDYKpexairzcNwfDukANatLDRjSr6C9D+BosI3TCs= 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=j2FEKG35; arc=none smtp.client-ip=209.85.214.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="j2FEKG35" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1fc56fd4de1so16850955ad.0 for ; Thu, 01 Aug 2024 08:14:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525246; x=1723130046; 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=PgecxP4O0Pj59wqK0X7+wytHBmUi03mK/T6KiVvNudI=; b=j2FEKG35SdvzItOF+LHxM1e/J7bz/GYKjMTLg9BButt3bvp+O2SjDILogW5OuJT5lh rGR7vZKJnKGQb7TRs6PqYCjfa4b9NH8HLGc7kETT6T477VYtB+wQsW6uBaAF/iw5gDja PWdYyNlqAAKgWV3kjQP9m4ZpvdQDKmv5bfP7HKqpaMFf+VFh4uC0ZkE98Z72Nee8wIsw zW7Q6u3YqJrbi4+cgWs8QPU1AWq6LNH3WSoHt9nZUcoCNAgHlAWmh6hagZlG0j8MetOR ZDi0HxJfS0T8kfGCD9GU76FhQ+u9Tv73RpT5KjD+NlVxEn/TC7GSBZOvm392z5Acs5BN 3TdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525246; x=1723130046; 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=PgecxP4O0Pj59wqK0X7+wytHBmUi03mK/T6KiVvNudI=; b=BRAZFAoU5zsCEGtkkt70LpHfoGcoyRnrLNDzTgSsOox797P6O6YQ15/cwX5Uc7aZuB TV2OvCUWpvo+mSFmttwkY93bc18F5QomP/VYd+Ipq4/OCpEIxSTfWQ2XJl6uST1UsIgy 2jPepedmAlafMOKvyvSPMIIO/ssxZIGVTk3rwWm3ng3ADDoUnJrRIwKgyOQoCdHPZ9uo Em6skxlmDK3CB/3qwAF75ip4MoY17lQ/VMRri0e+8scXQZJXYbY3mvzBOZykv1WKex6j UsNTmP7lXaSq1b0Bw+3hV61OQQut/L3y1/23f3n3NyhGk6BsLlrSVh2K9WGXKWuTIvAp PUFw== X-Gm-Message-State: AOJu0YxCqLD87C+Z+uP/xwf2e2haYTnAvDcGl6WUOOHAu+TYC89EBUFv a25O2fviT8FVo9jZqu4ksMRI+gWShqXrQSu5GPssdSrhT4Kk0JnyNlLp3A== X-Google-Smtp-Source: AGHT+IHC8QrZl2YsLlfcLGAs3OEn2mEkT6lN4EDZXqg14JgE8BbLM4na3fYiCs0z6PB+UqECIZmOrg== X-Received: by 2002:a17:902:db0e:b0:1fb:6121:dfc0 with SMTP id d9443c01a7336-1ff57bed363mr3113465ad.19.1722525246400; Thu, 01 Aug 2024 08:14:06 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7f84a03sm141204495ad.243.2024.08.01.08.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:14:05 -0700 (PDT) Date: Thu, 1 Aug 2024 23:14:29 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 06/11] 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 have introduced refs database check report function. To avoid ambiguity, rename object-related fsck error functions to explicitly indicate these functions are used to report objects-related messages. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- builtin/fsck.c | 12 ++++++------ fsck.c | 22 +++++++++++----------- fsck.h | 24 ++++++++++++------------ 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 9673a08286..766bbd014d 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -89,11 +89,11 @@ static int objerror(struct object *obj, const char *err) return -1; } -static int fsck_error_func(struct fsck_options *o UNUSED, - void *fsck_report, - 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, + 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; @@ -941,7 +941,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 f0ae760c86..0a870fcec0 100644 --- a/fsck.c +++ b/fsck.c @@ -1236,11 +1236,11 @@ int fsck_buffer(const struct object_id *oid, enum object_type type, type); } -int fsck_error_function(struct fsck_options *o, - void *fsck_report, - 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, + 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; @@ -1369,16 +1369,16 @@ 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, - 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, + 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) { struct fsck_object_report *report = fsck_report; puts(oid_to_hex(report->oid)); return 0; } - return fsck_error_function(o, fsck_report, msg_type, msg_id, message); + return fsck_objects_error_function(o, fsck_report, msg_type,msg_id, message); } diff --git a/fsck.h b/fsck.h index 2276ea7e34..2002590f60 100644 --- a/fsck.h +++ b/fsck.h @@ -123,15 +123,15 @@ 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, - void *fsck_report, - 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, - 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, + 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, + void *fsck_report, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message); int fsck_refs_error_function(struct fsck_options *options, void *fsck_report, @@ -169,7 +169,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, \ @@ -177,7 +177,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, \ @@ -185,7 +185,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, \ } #define FSCK_REFS_OPTIONS_DEFAULT { \ .error_func = fsck_refs_error_function, \ From patchwork Thu Aug 1 15:14:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750642 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CE8713B79F for ; Thu, 1 Aug 2024 15:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525261; cv=none; b=dDhQYKiDQZohrsFPTHzWjyjs+3slQeZfsC571PYubFC/3VERYUL4dYjE61/Z7GAbeaneQpdcGvIyLIydBaIY0cChAXG+mkmHH2ixjBpZaFlNqpxXrHvJ928kJPZps3dBmz1YIbI9HoOCw0ktvCclT9GayG8F6l7e5fL2M8PUCpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525261; c=relaxed/simple; bh=2ZeX5Vjy/pIkDlnqD9UB026/KyMbIjiOcH+P63CCAaQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nLkFk6R1YTs0ddzKQUDrMmnWe+1/pmYRCi+ErctgPu+jubXqzhGq7bghsCJaNyW7866v3a/ygi+fx0MU61u8txLAmK38NqbLb3mRuX7emPqqMEVVXRnG09/1v4KyyK2lv9ndNUlE31xLv0cPn+ArOW7E5wm1WEJFk9uO0XMZ0pE= 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=d+rZsRBD; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d+rZsRBD" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1fee6435a34so49494305ad.0 for ; Thu, 01 Aug 2024 08:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525258; x=1723130058; 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=GP6lLfen4SJSaCsENdba8KTKES/K0AFEfp+cY9Ump20=; b=d+rZsRBDEKSEgDOXh7/rcENof/C+YgF83yN+kEz93yGzx6Pqm/kn3CcZm9OJhkjZVq gYQeuFMXAl6Y7Z3wcSSMjBqUegDocLIXFU4dZFliu/sU8eqoDx+5kiSl1g4KdHJzLxOC L4rwDbZ2E9kXSEiWYEQ2MFIerrOUP3NZtA5JSLnQVhQSxqCzwKCuIm+/WhLHMqxovR4D uQgNLphI8Ekl3O7u7/C4MGeRqBP7qmPQ2wY7z4NBw8wssuikheuKLutgjJ6KxTlUntBg z28/Qp4Jr8nr8uURUAD/314lQYOmIvTinqcvg9Yi8Vylc/RItqXBzl9EMW6OqB3BVjI6 FwbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525258; x=1723130058; 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=GP6lLfen4SJSaCsENdba8KTKES/K0AFEfp+cY9Ump20=; b=uasYwvQiXcegWWL4Eq6pXilgq6kIleGjGwgI6CUResP8gkinF06GVRtel34j7zuZv0 9cJdAIzZSWXi6JrxnsRaL/FkYnGMPT8T0Dw+wZEV7OjPq1m+V7npRXXfx1FSV8YGBLHM gj5ZKU14ZOSOo8WYMjC553NTZvRpdbPu00uVAAis1d2C9WXQXIqCbNA610zQ69sqOYzy m9jHjPGnp7rrIE772cJFOsKOI/SxMNna3km2T0ycKehGqS9izREy3q6h7Vv3wZ9IX2BF UXphej+5p9hNIdz0mMM/YnsdYfQ5oxrBAyBK8J11B5MJ2vtvComVC1Qnclve2hBGbwmm ez6Q== X-Gm-Message-State: AOJu0YzqpprYjtTLnU9Aqm887vMGWk+XIjEME+IcxFQbSgPmGA7Ar27P hkhSa2MRwwRfJm+AmpQNkdEfyR6YHv5DuHjtBl/H7fOil2W17t9qjsc0yw== X-Google-Smtp-Source: AGHT+IELyryxq0qSoPDoWdlK4vYn1snAZ7bRmtmZ3XE7HvsxMY/d3T7aLaT1IKwCOx3pEwiPy0o4cg== X-Received: by 2002:a17:903:234a:b0:1fd:9e88:e4a9 with SMTP id d9443c01a7336-1ff573d86f9mr6336485ad.46.1722525257867; Thu, 01 Aug 2024 08:14:17 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7f1fb58sm140018645ad.203.2024.08.01.08.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:14:17 -0700 (PDT) Date: Thu, 1 Aug 2024 23:14:38 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 07/11] refs: set up ref consistency check infrastructure Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "struct ref_store" is the base class which contains the "be" pointer which provides backend-specific functions whose interfaces are defined in the "ref_storage_be". We could reuse this polymorphism to define only one interface. For every backend, we need to provide its own function pointer. The interfaces defined in the `ref_storage_be` are carefully structured in semantic. It's organized as the five parts: 1. The name and the initialization interfaces. 2. The ref transaction interfaces. 3. The ref internal interfaces (pack, rename and copy). 4. The ref filesystem interfaces. 5. The reflog related interfaces. To keep consistent with the git-fsck(1), add a new interface named "fsck_refs_fn" to the end of "ref_storage_be". This semantic cannot be grouped into any above five categories. Explicitly add blank line to make it different from others. Last, implement placeholder functions for each ref backends. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- refs.c | 5 +++++ refs.h | 8 ++++++++ refs/debug.c | 11 +++++++++++ refs/files-backend.c | 13 ++++++++++++- refs/packed-backend.c | 8 ++++++++ refs/refs-internal.h | 6 ++++++ refs/reftable-backend.c | 8 ++++++++ 7 files changed, 58 insertions(+), 1 deletion(-) diff --git a/refs.c b/refs.c index 915aeb4d1d..6f642dc681 100644 --- a/refs.c +++ b/refs.c @@ -318,6 +318,11 @@ int check_refname_format(const char *refname, int flags) return check_or_sanitize_refname(refname, flags, NULL); } +int refs_fsck(struct ref_store *refs, struct fsck_options *o) +{ + return refs->be->fsck(refs, o); +} + void sanitize_refname_component(const char *refname, struct strbuf *out) { if (check_or_sanitize_refname(refname, REFNAME_ALLOW_ONELEVEL, out)) diff --git a/refs.h b/refs.h index b3e39bc257..405073621a 100644 --- a/refs.h +++ b/refs.h @@ -4,6 +4,7 @@ #include "commit.h" #include "repository.h" +struct fsck_options; struct object_id; struct ref_store; struct strbuf; @@ -541,6 +542,13 @@ int refs_for_each_reflog(struct ref_store *refs, each_reflog_fn fn, void *cb_dat */ int check_refname_format(const char *refname, int flags); +/* + * Check the reference database for consistency. Return 0 if refs and + * reflogs are consistent, and non-zero otherwise. The errors will be + * written to stderr. + */ +int refs_fsck(struct ref_store *refs, struct fsck_options *o); + /* * Apply the rules from check_refname_format, but mutate the result until it * is acceptable, and place the result in "out". diff --git a/refs/debug.c b/refs/debug.c index 547d9245b9..45e2e784a0 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -419,6 +419,15 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname, return res; } +static int debug_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store; + int res = drefs->refs->be->fsck(drefs->refs, o); + trace_printf_key(&trace_refs, "fsck: %d\n", res); + return res; +} + struct ref_storage_be refs_be_debug = { .name = "debug", .init = NULL, @@ -451,4 +460,6 @@ struct ref_storage_be refs_be_debug = { .create_reflog = debug_create_reflog, .delete_reflog = debug_delete_reflog, .reflog_expire = debug_reflog_expire, + + .fsck = debug_fsck, }; diff --git a/refs/files-backend.c b/refs/files-backend.c index aa52d9be7c..4630eb1f80 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3408,6 +3408,15 @@ static int files_ref_store_remove_on_disk(struct ref_store *ref_store, return ret; } +static int files_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + struct files_ref_store *refs = + files_downcast(ref_store, REF_STORE_READ, "fsck"); + + return refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); +} + struct ref_storage_be refs_be_files = { .name = "files", .init = files_ref_store_init, @@ -3434,5 +3443,7 @@ struct ref_storage_be refs_be_files = { .reflog_exists = files_reflog_exists, .create_reflog = files_create_reflog, .delete_reflog = files_delete_reflog, - .reflog_expire = files_reflog_expire + .reflog_expire = files_reflog_expire, + + .fsck = files_fsck, }; diff --git a/refs/packed-backend.c b/refs/packed-backend.c index a0666407cd..5209b0b212 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1735,6 +1735,12 @@ static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_s return empty_ref_iterator_begin(); } +static int packed_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + return 0; +} + struct ref_storage_be refs_be_packed = { .name = "packed", .init = packed_ref_store_init, @@ -1762,4 +1768,6 @@ struct ref_storage_be refs_be_packed = { .create_reflog = NULL, .delete_reflog = NULL, .reflog_expire = NULL, + + .fsck = packed_fsck, }; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index fa975d69aa..a905e187cd 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -4,6 +4,7 @@ #include "refs.h" #include "iterator.h" +struct fsck_options; struct ref_transaction; /* @@ -650,6 +651,9 @@ typedef int read_raw_ref_fn(struct ref_store *ref_store, const char *refname, typedef int read_symbolic_ref_fn(struct ref_store *ref_store, const char *refname, struct strbuf *referent); +typedef int fsck_fn(struct ref_store *ref_store, + struct fsck_options *o); + struct ref_storage_be { const char *name; ref_store_init_fn *init; @@ -677,6 +681,8 @@ struct ref_storage_be { create_reflog_fn *create_reflog; delete_reflog_fn *delete_reflog; reflog_expire_fn *reflog_expire; + + fsck_fn *fsck; }; extern struct ref_storage_be refs_be_files; diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index fbe74c239d..b5a1a526df 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -2303,6 +2303,12 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store, return ret; } +static int reftable_be_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + return 0; +} + struct ref_storage_be refs_be_reftable = { .name = "reftable", .init = reftable_be_init, @@ -2330,4 +2336,6 @@ struct ref_storage_be refs_be_reftable = { .create_reflog = reftable_be_create_reflog, .delete_reflog = reftable_be_delete_reflog, .reflog_expire = reftable_be_reflog_expire, + + .fsck = reftable_be_fsck, }; From patchwork Thu Aug 1 15:14:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750643 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.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 557FB13B5B4 for ; Thu, 1 Aug 2024 15:14:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525270; cv=none; b=MGjHWbGjJrAR/2yjCJvvB5bE+juSJoGSym+VKXRb5KpnccYag/fPAnndYYt4EQgyjfBQHDk8beR2wo1eTAmTwprvXhfR33q2cqDNMRZxi4NgoVXxEbbO99k2UB6R2uygiZwa4EEmetq657oQmLaSLNHe7bsMvS3/f0SpI8M+1R4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525270; c=relaxed/simple; bh=Jm2pdyQ7I9rvWFaqMSm/tEfHY61bIwDyVRZZlejuAtc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=e8ExSNnGLCUnhbc+SUYWTYB5DBBW8nnNjS+lXR76P8nwL27fCUqfGa0mIGxHKpPJ912YcNQmP6FuPjJbGqq6yY5HV4zJk+PNngNnjz2HD8Uvp/U7aIj6GRCo+/E8ziN1cMCDXv/fEWIvjzCApFeqly+J3U9J0DSSnGMbXGoZjGU= 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=a5udNF5c; arc=none smtp.client-ip=209.85.210.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="a5udNF5c" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-70d162eef54so5048871b3a.3 for ; Thu, 01 Aug 2024 08:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525268; x=1723130068; 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=DyG5FQCLGW11SDTBZMG1MOK2SbJZBc0+KogJHuEE/8U=; b=a5udNF5c2dnMW7EG5y7gytx4IqaCpqRybZOyfPQfLCacCBa2gsrRWbo38RHkqvTUU8 vaVY1XSqNDgVE4HqWtGsaAl1wFyvsRIvKDEViJkZeRbbTd76AgWh8r4tg4sS0jOKVe9o ZtBN6WdDFVpdyFT19E8mKZ/BMLfSw9pBLawASMnaifi6EFnDeazOfOQXZUUxjH94nLLm 0flFPMBCuTKHyZUwvLRzjv1cmijmmAhuzXrZcFvgc0+FN1RriVduzNOp42CpkN+tvHAV EUCCiQYbizcp1qO+O5/w/5m47JGgFdRiVrDSatbBFZcFcB1knu2EDak6c7b3xsXIixIp onMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525268; x=1723130068; 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=DyG5FQCLGW11SDTBZMG1MOK2SbJZBc0+KogJHuEE/8U=; b=VenclVaIRW57Xv87uBlsxfenvWontC/SppzI8EPIzMFDQmRiz/0qjbX9lLrjfW0/lU ZBDIhq4dYO03u5mRCDOuebHkVSPyHtk4xDR4hdzJ4r+EBQc6nQUVNEjowF72dlFeZUjt FxMTMOeOvR6bKzuRJB8j8xZBhYVeG/7Zao0ItL7QQbcPAcLWKa3ErAw0xrOhSF2VEMPl Rc7YvQOu1kQw0RmNfTmU+Ro4x/i1GjAuJawrTs0ULzGNMVteKhtK8dTgaCPHixdr3qGQ Yf3IlADFo2xIFHER+obSFk5r4LfyI1y0TwH4Q34zKb0yPGFDSGz2pFp5eGH/7LqKlJcv ayVw== X-Gm-Message-State: AOJu0Yx8ju3tdSuybFEV44KFBgZs43J7rKh0llnpWqGFe5R9/5ch93en X5JOPVF/X38gtEfNksV9jvq6szlnsFXEQAj6TWRmZeFhtzSxeq12K4+d9g== X-Google-Smtp-Source: AGHT+IG33idTsquYZzy1zF3YsGEPpntA6rK0bc3u7qn+dvQzyhHP2kOhApb6VIB7VTxcKgUXUHJF1A== X-Received: by 2002:a05:6a20:6a24:b0:1c4:b62f:feb2 with SMTP id adf61e73a8af0-1c699559ce2mr815482637.18.1722525267756; Thu, 01 Aug 2024 08:14:27 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead812eaasm11629816b3a.105.2024.08.01.08.14.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:14:26 -0700 (PDT) Date: Thu, 1 Aug 2024 23:14:50 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 08/11] 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 0a870fcec0..d5e7c88eab 100644 --- a/fsck.c +++ b/fsck.c @@ -1336,6 +1336,17 @@ int fsck_finish(struct fsck_options *options) return ret; } +void fsck_options_clear(struct fsck_options *options) +{ + free(options->msg_type); + oidset_clear(&options->skip_oids); + oidset_clear(&options->gitmodules_found); + oidset_clear(&options->gitmodules_done); + oidset_clear(&options->gitattributes_found); + oidset_clear(&options->gitattributes_done); + kh_clear_oid_map(options->object_names); +} + int git_fsck_config(const char *var, const char *value, const struct config_context *ctx, void *cb) { diff --git a/fsck.h b/fsck.h index 2002590f60..d551a9fe86 100644 --- a/fsck.h +++ b/fsck.h @@ -153,7 +153,8 @@ struct fsck_ref_report { struct fsck_options { fsck_walk_func walk; fsck_error error_func; - unsigned strict:1; + unsigned strict; + unsigned verbose; enum fsck_msg_type *msg_type; struct oidset skip_oids; struct oidset gitmodules_found; @@ -231,6 +232,11 @@ int fsck_tag_standalone(const struct object_id *oid, const char *buffer, */ int fsck_finish(struct fsck_options *options); +/* + * Clear the fsck_options struct, freeing any allocated memory. + */ +void fsck_options_clear(struct fsck_options *options); + /* * Report an error or warning for refs. */ From patchwork Thu Aug 1 15:15:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750644 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.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 6104813B5A5 for ; Thu, 1 Aug 2024 15:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525279; cv=none; b=QWat7VjrA+NVCsk4iuBchuFBHj4tWng50uPzFxJYIFPipJRjXIdQ25nLnzKdJw+gh8FVISLfcS1IEyCrFVtHZfEPtWkvdaRyUlQWpYs4UasUTOhrAFHV7RMGwqV8MMxMybNrB4HX52jzTTxriBByW6CjIB4sAUrbVTP9UATJT1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525279; c=relaxed/simple; bh=nGE57sSUhTelT1O81lLGuxqP8EnWXlavHo0hiBrSCq4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fFcq3yL92tf5OYkSF5Pc0NCl47BBSzVYMTDgHSpGf8+JM3E2skxZoCxiwlfwuoowbe81MlcoK6y+WV0hypp7oO3TeV5vYCYQxZazA2xeKF2EFVbDefTm78Gm7kFTdFxCPsOr8YXRk8Z5+FLhddJUkyZwdVb4iy5kk6+Dx7gCZzQ= 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=g5bPCQpR; arc=none smtp.client-ip=209.85.215.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="g5bPCQpR" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7a263f6439eso4200309a12.3 for ; Thu, 01 Aug 2024 08:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525277; x=1723130077; 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=VHF83E3ccLYpbKGMj/UzhWuRAPca4fkz7XAnJMogJ68=; b=g5bPCQpRfhR08tyXzyab0WuCiDMkzYVIGmMnyPL6oFHJCUwpjOkt9oeeeb8uFCFTED VrfIOreVA/JJiAgcxMAca1ztVdNp3DOLnaWFthRmZ1iuWgw3tRyMNu2JwKk8nZv6q1Mf k8S0frxTVNU7SdEk2PoCniiI9kWJ4arlw4208EEfo872krOLVcMfxaZgspm1KAQojV58 6sUakAzDkgNVAiUu04q9LzsU5Zts0Chn9BV6iWf6YIyvIo3M8c4VgQ4F15SesKa7G8Qs 59/WwvFeW2t6nrR+zqZ/voXjrxFrabRnnZymNfnJ7yk/mgwd0DHC7uad2LH14sLF9jZq udIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525277; x=1723130077; 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=VHF83E3ccLYpbKGMj/UzhWuRAPca4fkz7XAnJMogJ68=; b=EkoaaYOfoO3kgIUBJkvHzjMqRPWIdNAXO6F1ns62Fqa7xyEk1xpOMq9rHqk9kSqpJb s49+LAYC2PqMe3HKsy7Be5CwSWYo+T+04p04Ke4FTJrUpUTFROtJdakBxk9tfHrGb4Dz x1A723O817BtbQJ3/MZpUKMbaKOyHC/CddiebU2am5o7LE6mV6lEH3QOP6OlUOZy/IYQ kCJ0g63DGP8+vEd3sG51M1lJ7F8OrDnbLA/YinL5h5WMVxNDOUQMSuSLzWev2JOaYkpZ p+Lt/AC6I1qPfO7iWKGdJQU+iCnGb16Gil/zVVZPx6lgoWbyVeIiA7qQIrI+Nm3d6YgW djkw== X-Gm-Message-State: AOJu0YzybZsPx2rzpuOO2pYh+XC0PjxeCoJL6sFyc9js6UzQu1jHS8jd 1egGFP0HqwT28yuEnjKk8mSQ1fshzHX0bLXBloD3zlkMyeZrH5UANDDq1Q== X-Google-Smtp-Source: AGHT+IHQTtjUJnlq04JOXQ+iJIz6HkHqgPJ2UN4HhtKTvczdU8SdUJI3XzKtlUIT6MdiAnmDKtPjAA== X-Received: by 2002:a17:90a:a00d:b0:2c9:3370:56e3 with SMTP id 98e67ed59e1d1-2cff95148bemr593647a91.34.1722525276777; Thu, 01 Aug 2024 08:14:36 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cffaf69a27sm18800a91.5.2024.08.01.08.14.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:14:35 -0700 (PDT) Date: Thu, 1 Aug 2024 23:15:00 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 09/11] 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 766bbd014d..b6ac878270 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -899,6 +899,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" @@ -1068,6 +1083,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 Thu Aug 1 15:15:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750645 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F058F13B5A5 for ; Thu, 1 Aug 2024 15:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525295; cv=none; b=n8AFrRpvRBeUaGTlZI1M61RktK35DhjpwGjr9RNBYsUSNbhHjJL84Hby1CURKFQk2gDxT1m63l4ZW+qe4YE28eI9r2M8pkgeMoIC+xCEcoB7S6QPoHEi8jedXGofJWkTFfDMyfTN/4fAvUvDIiJmpZ0LjpvnxlECz23pri3cPZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525295; c=relaxed/simple; bh=3/wshvJstV7/vMaFhJbMNrDCQsKwR9qjbWybMEiAmZ8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=F7GVtbIg4lLnPKBRYRwPZ0PlatR14Zy/59bPLa5eDuerWgUOYJ9x7SyHpShEp1G4i/NweISmZP0fEIP5UkS2d7ahOuAUPxqP1ojPL40SOQfZxuyV8axeRRt5rn9nljzvIKM0eqnExW51qINPi/PNZ3COIZg6jtLe+XBFltn7SHg= 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=kVYvoNX5; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kVYvoNX5" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70d23caf8ddso6137485b3a.0 for ; Thu, 01 Aug 2024 08:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525292; x=1723130092; 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=rXNtaTuVg1hU2q5SrhUTVXkyTgBdS6iNLMjlgd76QFg=; b=kVYvoNX5rz7eYv9Il3gNioCJn7lN60papdgaY+n7tEGtQZKd9mCF196IXBgJxOWMZJ PRmQqCEy5kdoOItCjP/ijWCnUZT6dUAfQFVPEMRSdxHwHyzjPyuKs6h9MoHNY5apTdWE B4K9WJEyyPAPfMS9MACsq7qcyFGxYEdG0ljk50OzrsJUNX2kRB++YTIWiKkaM81FhB1Z 2YA4y0Mu47Cdf2l6N2bWJnHnFzUdr3vrbM7+rlHutBMS+/uKyWNadHWKFD7NLfBCRg5q ReuhRYpt3s29QLjQWvGQdz8SLo+PL+ODxHe22fFGrZvceGrepo8QUHk1DbRr0Rqd1dpV QRkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525292; x=1723130092; 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=rXNtaTuVg1hU2q5SrhUTVXkyTgBdS6iNLMjlgd76QFg=; b=XY0jK6Ln5iSxJE3UQTVvMJw4/zEok1LlRvgoaZTTmMtw6XGvKOd0toCFoU0Urzbuh0 tA3IVXJcu03J8L1C3IDvtgQbe3r2pRLZO/BKPxbIHaAsEJga+5sqKAMxhRI5t7arv5PD 3QNC9IbTJm439jyA2ZIocxywpfvSyUQFSpGq5V06/jmyxOXGvXdL/lEj7JOHusWaTP9l NUmaLREwucXQsXhebWkkOuGHa9xcrZ8Vt9uXdXbeTUJa0uA3opIH0ZAp2Fktl3bkgn5m 4XEZN96LOmR3hGFi+FYt0T/qJWicHdCg0fNiec61Qi4Iyxv1GGk8VTglpTQxAcj3ywhM CvZA== X-Gm-Message-State: AOJu0YyGCZ1E20qcNmGwrJ4YlLbhYxcmFB8nSPkvTlSjEYzFSLUoHm5o TrS0KLESbzQ2rXu9TfVNmTA/0cYGqGA+Sbd/Q00qfpU5Bb0r2hv9IlkQHw== X-Google-Smtp-Source: AGHT+IESJK0DRD9Xbsw4sQuvTohGnIEhzVsSwhhp7t9NU5BdrkqU+YKYDOZpYUkUguO7uX+bl33PAg== X-Received: by 2002:a05:6a21:174d:b0:1c0:e997:7081 with SMTP id adf61e73a8af0-1c6995ab39cmr552670637.29.1722525292412; Thu, 01 Aug 2024 08:14:52 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead6e188asm11643305b3a.41.2024.08.01.08.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:14:50 -0700 (PDT) Date: Thu, 1 Aug 2024 23:15:14 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 10/11] 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 | 75 ++++++++++++++++++++++++++++++++++- 3 files changed, 78 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..5574e78656 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,85 @@ 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_fn) +{ + const char *gitdir = ref_store->gitdir; + struct strbuf sb = STRBUF_INIT; + struct dir_iterator *iter; + int iter_status; + int ret = 0; + + strbuf_addf(&sb, "%s/%s", gitdir, refs_check_dir); + + iter = dir_iterator_begin(sb.buf, 0); + if (!iter) { + ret = error_errno(_("cannot open directory %s"), sb.buf); + goto out; + } + + while ((iter_status = dir_iterator_advance(iter)) == ITER_OK) { + if (S_ISDIR(iter->st.st_mode)) { + continue; + } else if (S_ISREG(iter->st.st_mode) || + S_ISLNK(iter->st.st_mode)) { + if (o->verbose) + fprintf_ln(stderr, "Checking %s/%s", + refs_check_dir, iter->relative_path); + for (size_t i = 0; fsck_refs_fn[i]; i++) { + if (fsck_refs_fn[i](o, gitdir, refs_check_dir, iter)) + ret = -1; + } + } else { + struct fsck_ref_report report = { .path = iter->basename }; + if (fsck_report_ref(o, &report, + FSCK_MSG_BAD_REF_FILETYPE, + "unexpected file type")) + ret = -1; + } + } + + if (iter_status != ITER_DONE) + ret = error(_("failed to iterate over '%s'"), sb.buf); + +out: + strbuf_release(&sb); + return ret; +} + +static int files_fsck_refs(struct ref_store *ref_store, + struct fsck_options *o) +{ + files_fsck_refs_fn fsck_refs_fn[]= { + NULL, + }; + + if (o->verbose) + fprintf_ln(stderr, "Checking references consistency"); + return files_fsck_refs_dir(ref_store, o, "refs", fsck_refs_fn); + +} + static int files_fsck(struct ref_store *ref_store, struct fsck_options *o) { struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_READ, "fsck"); - return refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); + return files_fsck_refs(ref_store, o) | + refs->packed_ref_store->be->fsck(refs->packed_ref_store, o); } struct ref_storage_be refs_be_files = { From patchwork Thu Aug 1 15:15:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13750646 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 0FB8913C68E for ; Thu, 1 Aug 2024 15:15:02 +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=1722525304; cv=none; b=P5p1C9EK75CQnY6UbLvkQn2oW7YRO9dDXoGLAy/0iy7fZpPBMQK68d0aZ+DapBLw2txkwmDje6VeZgYDK0sJpd849BuxKpEviLGkPB8ztPzttWvU2lGA6R8T4y+wUgVIIxhUEX2NkE1j2543PcT4WsNYuzL98tl6/VpKBAsI0UY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722525304; c=relaxed/simple; bh=FSwCfY5b2zX+WaHFdomIyhUr+fprPjxXGKBidiCrspE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IxhY9GEaTPeso1ZdeAbtgfbUdUNe/RKN65FIwjEVx3poHyD2ggLNokwjlFJ61g5ULnfvwBV/Cei9rDesIlyiHe565btKeOaEapwKOF/AgrL8371x/Ic2hXqeLoNvQVVmJ31ED69SchLNKjcf+mH4e7OJwKnThpYbiWQkbm4BTuo= 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=Q/qQqd0G; 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="Q/qQqd0G" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-70d333d57cdso5133765b3a.3 for ; Thu, 01 Aug 2024 08:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722525301; x=1723130101; 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=ZGTAi9V7Ce02hF3GVXPtYjyvAo1+9i33Dhi8/Yi5dRk=; b=Q/qQqd0GKDg6Kxu9/6HWlm2YIRjVVABaiqjxRObAvXQJSoGkwQrE+zs8ATWdfEywmR M8fA4pWtfGid3BXY5URzoVyNGExt4s80JVVP9HGAYDrECq0coSKHBc1tMkwLozSPipzj wyg5byHxdlWSAmMSBmMhUHf6sjr9E2NFnH2DJrQZwJNGJZKTrrhTnz6Evh3B3xo1JzyG qtqz9Z42/MXrcFsBUPsdYy3J72rtp8mCgMt8DaVXCbvYz4Z2oGt0JZMTThYNl8zHKqr+ o6hQLnmyeNmm5D5Wxo4ka2YHFZG9YIa8xdiJiKi+hl28w+Qj8XG1yCU2oNrUd7kfDv/b NHzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722525301; x=1723130101; 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=ZGTAi9V7Ce02hF3GVXPtYjyvAo1+9i33Dhi8/Yi5dRk=; b=Dk0FQq86JptygPyeo6rchdwN1fuhXR7XRA2ecbCDBdHpNNNoN5sE7wynv5j8D8lSLk zXimNdCuxda90Eqj3RIi8jwQxB9aAfdyuj2z7G/+qDrVZbp0x37g/+tJ4aNYZZe80j/J mPffqhTWxQdGozg/+p9/3eWetn1UdtdmdFonhA/mZce1HNIc6DxX4nwaRME4lSP7+ovE X9BhWGCG7Q5JmGhSjqcv8ru8SiZv+VA7V6etKuRktmd7lsXR4fz9AO1vZrpmqWEYnV35 BXkN9rvkeW/XZ2IpuL4pyfD/K6SJKDl2y80UynzwMl98nDRNSLg47axaRVgNcFL/kGvE fmqQ== X-Gm-Message-State: AOJu0YxPcddJPZDlvq3oxksRc4ZCnptCGzBJo9gYb2029ziuI7xv6k5s 8YQpK1QJ3LZS62abIiq9u7eJHYT6qjZo12yNbeSuhiRRiVpdYj9Pxc1+SQ== X-Google-Smtp-Source: AGHT+IE0SGQBwBXvsdMs3WksAVTwh/jCf/gWPM/Li6xTR5xcs0l2LiJHl3RDlkLE7O1LkN4+2qU9Vg== X-Received: by 2002:a05:6a21:7896:b0:1c2:8c32:1392 with SMTP id adf61e73a8af0-1c69955f4bamr947668637.22.1722525301572; Thu, 01 Aug 2024 08:15:01 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead715733sm11609067b3a.84.2024.08.01.08.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:15:00 -0700 (PDT) Date: Thu, 1 Aug 2024 23:15:24 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v14 11/11] 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 | 32 ++++++++++++ t/t0602-reffiles-fsck.sh | 94 +++++++++++++++++++++++++++++++++++ 4 files changed, 130 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 5574e78656..1186b6cbb1 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3419,6 +3419,37 @@ 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; + size_t len = 0; + int ret = 0; + + /* + * Ignore the files ending with ".lock" as they may be lock files + * However, do not allow bare ".lock" files. + */ + if (strip_suffix(iter->basename, ".lock", &len) && (len != 0)) + goto clean; + + 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"); + } + +clean: + 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, @@ -3471,6 +3502,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..2be28427ab --- /dev/null +++ b/t/t0602-reffiles-fsck.sh @@ -0,0 +1,94 @@ +#!/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 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 && + + 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 && + + 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 && + + cp $tag_dir_prefix/tag-1 $tag_dir_prefix/tag-1.lock && + git fsck 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 fsck 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 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 && + + + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && + git -c fsck.badRefName=ignore fsck 2>err && + test_must_be_empty err +' + +test_done