From patchwork Mon Jul 29 13:26:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13744944 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (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 63FAD3C24 for ; Mon, 29 Jul 2024 13:26:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259562; cv=none; b=V3TLHZWGrx6O8WXNNAKb4WbNibGMyIKCWnMZaH8/zZlTxSiyEOkyQXbWrNf97OlPhKPWr3XJPui4MBsN6+INxWD8Zl3hzh9ZerR5M3TPcmqeFaubuYqFg4Q9wjUbZdpDR0HfQVG4CfIEomU1X394Br1cPKRatcBDgGzSEMjzWB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259562; 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=IHVbMJmdpBmWpmMCZTZjoTAQ28T9O/ufXAqmGszfAvUU9IzXjkz96UV2sYiS+LLdFR7JNxDfEusp7v0dk5fiTCWGwMzWcdbxqXfFfOQQClYiH4PG1XNUdRAykN8E16W+cwI8tqwHiJNC+zQGurYiHotN6o2gMeA/9zg3zfyYkqw= 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=ATL/BnyL; arc=none smtp.client-ip=209.85.210.42 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="ATL/BnyL" Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-70930972e19so747375a34.3 for ; Mon, 29 Jul 2024 06:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722259560; x=1722864360; 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=ATL/BnyLrAQIbxXEW6HEI/+Qlq2DRCUMLPC9jACfBLZabnWBv0u96BJfOx8cHjxvEj Tre1FJkpK3iapyg4FiGRbwIThsb8DLQEowttYXFOB8w23LQSk4b4ysGdiyfwuhlcR5tM ws6pOXi7/KkMHEVo9/0M8xyzeV81Eaylpq/WqRlrdNyMeelg/WOVP+nC/welVEegj4UJ YGsmH+YF+jwqvhKNRsbqZUfiwCsPfVIQ98TN3gl2EMxo1RGuMinz55XquY8I3Io36mpb PR2q2IoWLeWL/smftgRelO0zPArJMOqCF98lhVlKoSZRdp32K6pRo8H4b0MYYRCrXEXj F56A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722259560; x=1722864360; 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=Dt1YxVqFoKKXcWDo2zJ9OX6R1/VIFILmsG7gLWz5KJl7cBReH4mIsYez4+993/SO0K MFoj9i3SLsB4wLQw6hLt8KWSJcbM2wryXWXVEc8KR0Z+TvN/l7sVTvY+Bdanm/ROxA0j RJAdLNUBE05AvLX4ztWI5ffyWdDq5G5S4VDQHwgNDdgmmxE7mmedphoydk0e87puOTu7 IoAbFFw9glaohw+20TwswFCrVFfltT1+X4oaQMfwaFyhRvHEJRzdm72Sciv5VwPIEtxY DjZdHAB/dh8HhqITmHpQX5CjPo/h3zLTJNVs+HvrUu7nl6IQZYLHqNRuwik5dP9jmkDJ IP6w== X-Gm-Message-State: AOJu0YwxIiVVJ4RJ417vT3+RuXeFWORKXcCav1o3fgy7/tQtIKHtCHkT g5ik3xrNg6V5HKNyrfLvRmSDVjCU6Se+K30Jfqvzc2D7Xf8g5+4eNzJPDg== X-Google-Smtp-Source: AGHT+IGdt2RxScNE5xWqvCUSN+92F3pzBysr5f2Lf64zen4QXMBPRbQrMUvkMBdwH7YAYCw1+RUH5w== X-Received: by 2002:a05:6870:392b:b0:24f:c715:a4d4 with SMTP id 586e51a60fabf-267d4eebaf4mr10817872fac.40.1722259559560; Mon, 29 Jul 2024 06:25:59 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead6e13f9sm6800576b3a.21.2024.07.29.06.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 06:25:59 -0700 (PDT) Date: Mon, 29 Jul 2024 21:26:20 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v13 01/10] fsck: rename "skiplist" to "skip_oids" Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The "skiplist" field in "fsck_options" is related to objects. Because we are going to introduce ref consistency check, the "skiplist" name is too general which will make the caller think "skiplist" is related to both the refs and objects. It may seem that for both refs and objects, we should provide a general "skiplist" here. However, the type for "skiplist" is `struct oidset` which is totally unsuitable for refs. To avoid above ambiguity, rename "skiplist" to "skip_oids". Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 4 ++-- fsck.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fsck.c b/fsck.c index eea7145470..3f32441492 100644 --- a/fsck.c +++ b/fsck.c @@ -205,7 +205,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) if (!strcmp(buf, "skiplist")) { if (equal == len) die("skiplist requires a path"); - oidset_parse_file(&options->skiplist, buf + equal + 1, + oidset_parse_file(&options->skip_oids, buf + equal + 1, the_repository->hash_algo); buf += len + 1; continue; @@ -223,7 +223,7 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) static int object_on_skiplist(struct fsck_options *opts, const struct object_id *oid) { - return opts && oid && oidset_contains(&opts->skiplist, oid); + return opts && oid && oidset_contains(&opts->skip_oids, oid); } __attribute__((format (printf, 5, 6))) diff --git a/fsck.h b/fsck.h index 6085a384f6..bcfb2e34cd 100644 --- a/fsck.h +++ b/fsck.h @@ -136,7 +136,7 @@ struct fsck_options { fsck_error error_func; unsigned strict:1; enum fsck_msg_type *msg_type; - struct oidset skiplist; + struct oidset skip_oids; struct oidset gitmodules_found; struct oidset gitmodules_done; struct oidset gitattributes_found; @@ -145,7 +145,7 @@ struct fsck_options { }; #define FSCK_OPTIONS_DEFAULT { \ - .skiplist = OIDSET_INIT, \ + .skip_oids = OIDSET_INIT, \ .gitmodules_found = OIDSET_INIT, \ .gitmodules_done = OIDSET_INIT, \ .gitattributes_found = OIDSET_INIT, \ From patchwork Mon Jul 29 13:26:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13744945 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C20AD3C24 for ; Mon, 29 Jul 2024 13:26:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259573; cv=none; b=IBiqt4v849zkv0VsifGrILGeqPv5r6T+JzsEUbnBci/iLD9pTN83kqh1FOA0/usl5qrLVoAjwY7Ju34oq/6JAiLPCXvONf+iTbAuBficcfZ7WgxamDIsUoNVLqrEyAPG/R6bl7k9nAmAxiJt95FOyVYcmsF6LNMnZ30t1eJUz6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259573; c=relaxed/simple; bh=T/u4woMXYiptZFsUNUJptsaLd657VkrybvcIDW+tgso=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X89QugBvjLU1Vvy90sL1fI7fc2UzW8mbbxy4WrDDVqYLWK3kMJKZgs7dZLV5cFgpqfzp8vmHX6Zn3tRR9cWeZ/7ihMKyCRMlXr0lyrtwlOBJcro73QxSkkIpFOoDoMCMO+Li3N+QWaCxmPJxFUOnWTOD0rA2ROlb4NDUm8BVlvE= 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=Us7hD+7l; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Us7hD+7l" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-70d18112b60so2292347b3a.1 for ; Mon, 29 Jul 2024 06:26:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722259570; x=1722864370; 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=PDd8yrvBilTJ2Hg8IO0Rsc5tZtUtgMkB6weQ3gTiLO4=; b=Us7hD+7lQ3MgFPdUoyRCM4K/KNdJBPUnwOPgQXEDq/i5tF30bcLucD/GsJ7/4vUyqH z6VGeB81GaxTVdFzhcF+NRouJjhnnxDOryy5C9gKSwdycYnwtx00QIQJJCw7G5Rw8vfT GVWh9swo2nTUuSxc713+hPQxYVH2rki2fDZG3THTwOnt5zQHB1/t05prwDTVqgt+DnAg ygN+ZImECWaAq0vWsV3t09A9rSsgKbu1+viSBmmBdCgMgy2mgxC3DvglFDotbhAxDkPU X26xwzQtVUfk0PxFS3wn0cu+EMk2b0Leltq2B0vV9pVc/YJRfnSc23ZKQbm/YLALbyUs LEIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722259570; x=1722864370; 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=PDd8yrvBilTJ2Hg8IO0Rsc5tZtUtgMkB6weQ3gTiLO4=; b=N2E7/ZgvNKj1C9iJpLxsHmgwLRxo0T8Z+aZLa0YVblHTGt6KhGp1r9O6rYMRFaSf8M R7qPwBihAKWLftz7pzZ1tx9SjIJ9/VuMfrts13dCKnAIsifLxYQkwmQbEIjxdPJMVvta lp46FHcudl2wjeZatJLi1rnxyraY0vsdG4UWFPqTsrE2FfQrFtVkfv44xt34KfX/KYRq JgPhtuiw8KBviHy7WyJykkFdXbx//V2O42mOoMkkBackWhPXs97Ga5EHv5x+Q0nOXobu sMW1GnXIpOU8T2GK0g9XG6MjNU9N/T8gf5WWdqIvpz8CggB367VKV6370/PjidmMBl5U jszw== X-Gm-Message-State: AOJu0YyJfiMkJiALkpCC2D+jteLM0eLn7DuLiH5HM/kny23/zqL7q72P ymgXMOF718j6iaBqOvvU68K3JM3aNQY9b7XrD/+vHt+W6p9KP8Zyey/SVA== X-Google-Smtp-Source: AGHT+IGK+KSAx4emqZoSOv+aKVvOeM5Xh3dE4kXiF6ztuj5hRwL3SBCqhIKMIN1YVhAaDbIRhWgZPQ== X-Received: by 2002:a05:6a00:3d0d:b0:70e:cee8:264a with SMTP id d2e1a72fcca58-70ecee82ceemr13216220b3a.1.1722259570337; Mon, 29 Jul 2024 06:26:10 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7a9f816db18sm6213964a12.33.2024.07.29.06.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 06:26:09 -0700 (PDT) Date: Mon, 29 Jul 2024 21:26:30 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v13 02/10] fsck: add a unified interface for reporting fsck messages Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The static function "report" provided by "fsck.c" aims at checking fsck error type and calling the callback "error_func" to report the message. However, "report" function is only related to object database which cannot be reused for refs. In order to provide a unified interface which can report either objects or refs, create a new function "fsck_vreport" following the "report" prototype. Instead of using "...", provide "va_list" to allow more flexibility. In order to provide an extensible error report for refs, add a new "fsck_refs_info" structure and add parameter "const struct *fsck_refs_info" into "fsck_vreport" function. Like "report", the "fsck_vreport" function will use "error_func" registered in "fsck_options" to report customized messages. Change "error_func" prototype to align with the new "fsck_vreport". Then, change "report" function to use "fsck_vreport" to report objects related messages. Add a new function called "fsck_refs_report" to use "fsck_vreport" to report refs related messages. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- builtin/fsck.c | 1 + builtin/mktag.c | 1 + fsck.c | 56 +++++++++++++++++++++++++++++++++++++++++-------- fsck.h | 25 +++++++++++++++++++++- object-file.c | 11 +++++----- 5 files changed, 79 insertions(+), 15 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index d13a226c2e..6abad60e7e 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -92,6 +92,7 @@ static int objerror(struct object *obj, const char *err) static int fsck_error_func(struct fsck_options *o UNUSED, const struct object_id *oid, enum object_type object_type, + const struct fsck_refs_info *refs_info UNUSED, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id UNUSED, const char *message) diff --git a/builtin/mktag.c b/builtin/mktag.c index 4767f1a97e..6496deca0a 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -20,6 +20,7 @@ static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; static int mktag_fsck_error_func(struct fsck_options *o UNUSED, const struct object_id *oid UNUSED, enum object_type object_type UNUSED, + const struct fsck_refs_info *refs_info 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..1185e9a8ad 100644 --- a/fsck.c +++ b/fsck.c @@ -226,12 +226,18 @@ static int object_on_skiplist(struct fsck_options *opts, return opts && oid && oidset_contains(&opts->skip_oids, oid); } -__attribute__((format (printf, 5, 6))) -static int report(struct fsck_options *options, - const struct object_id *oid, enum object_type object_type, - enum fsck_msg_id msg_id, const char *fmt, ...) +/* + * Provide a unified interface for either fscking refs or objects. + * It will get the current msg error type and call the error_func callback + * which is registered in the "fsck_options" struct. + */ +static int fsck_vreport(struct fsck_options *options, + const struct object_id *oid, + enum object_type object_type, + const struct fsck_refs_info *refs_info, + enum fsck_msg_id msg_id, const char *fmt, va_list ap) { - va_list ap; + va_list ap_copy; struct strbuf sb = STRBUF_INIT; enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options); int result; @@ -250,9 +256,9 @@ static int report(struct fsck_options *options, prepare_msg_ids(); strbuf_addf(&sb, "%s: ", msg_id_info[msg_id].camelcased); - va_start(ap, fmt); - strbuf_vaddf(&sb, fmt, ap); - result = options->error_func(options, oid, object_type, + va_copy(ap_copy, ap); + strbuf_vaddf(&sb, fmt, ap_copy); + result = options->error_func(options, oid, object_type, refs_info, msg_type, msg_id, sb.buf); strbuf_release(&sb); va_end(ap); @@ -260,6 +266,35 @@ static int report(struct fsck_options *options, return result; } +__attribute__((format (printf, 5, 6))) +static int report(struct fsck_options *options, + const struct object_id *oid, enum object_type object_type, + enum fsck_msg_id msg_id, const char *fmt, ...) +{ + va_list ap; + int result; + + va_start(ap, fmt); + result = fsck_vreport(options, oid, object_type, NULL, msg_id, fmt, ap); + va_end(ap); + + return result; +} + +int fsck_refs_report(struct fsck_options *options, + const struct object_id *oid, + const struct fsck_refs_info *refs_info, + enum fsck_msg_id msg_id, const char *fmt, ...) +{ + va_list ap; + int result; + va_start(ap, fmt); + result = fsck_vreport(options, oid, OBJ_NONE, refs_info, + msg_id, fmt, ap); + va_end(ap); + return result; +} + void fsck_enable_object_names(struct fsck_options *options) { if (!options->object_names) @@ -1203,6 +1238,7 @@ 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, + const struct fsck_refs_info *refs_info UNUSED, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id UNUSED, const char *message) @@ -1306,6 +1342,7 @@ 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, + const struct fsck_refs_info *refs_info, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message) @@ -1314,5 +1351,6 @@ int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, puts(oid_to_hex(oid)); return 0; } - return fsck_error_function(o, oid, object_type, msg_type, msg_id, message); + return fsck_error_function(o, oid, object_type, refs_info, + msg_type, msg_id, message); } diff --git a/fsck.h b/fsck.h index bcfb2e34cd..4f01a46cc7 100644 --- a/fsck.h +++ b/fsck.h @@ -92,6 +92,7 @@ enum fsck_msg_id { }; #undef MSG_ID +struct fsck_refs_info; struct fsck_options; struct object; @@ -114,23 +115,35 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type); typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type, void *data, struct fsck_options *options); -/* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ +/* + * callback function for reporting errors when checking either objects or refs + */ typedef int (*fsck_error)(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, + const struct fsck_refs_info *refs_info, 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, + const struct fsck_refs_info *refs_info, 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, + const struct fsck_refs_info *refs_info, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); +/* + * The information for reporting refs-related error message + */ +struct fsck_refs_info { + const char *path; +}; + struct fsck_options { fsck_walk_func walk; fsck_error error_func; @@ -209,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, 5, 6))) +int fsck_refs_report(struct fsck_options *options, + const struct object_id *oid, + const struct fsck_refs_info *refs_info, + enum fsck_msg_id msg_id, + const char *fmt, ...); + /* * Subsystem for storing human-readable names for each object. * diff --git a/object-file.c b/object-file.c index 065103be3e..91ddab2696 100644 --- a/object-file.c +++ b/object-file.c @@ -2470,11 +2470,12 @@ int repo_has_object_file(struct repository *r, * give more context. */ static int hash_format_check_report(struct fsck_options *opts UNUSED, - const struct object_id *oid UNUSED, - enum object_type object_type UNUSED, - enum fsck_msg_type msg_type UNUSED, - enum fsck_msg_id msg_id UNUSED, - const char *message) + const struct object_id *oid UNUSED, + enum object_type object_type UNUSED, + const struct fsck_refs_info *refs_info 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 Jul 29 13:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13744946 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 DBB693C24 for ; Mon, 29 Jul 2024 13:26:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259583; cv=none; b=sUmKrE9Wmf9tpoMWGnrDNH1gRL9w3AsXEciUttz/PpIJ8BQkYIs3yVf6myjWThuF/cG84sw6i/R1eHcYb/XlDmyKjFRHPwqOqatyDLKx/RK7R0eqkCwq45oyecW3o0lfXQT4dqO6KxmYmYPxFHeAJ3QQR4HwNZnM7kJRo1rOzyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259583; c=relaxed/simple; bh=7ZDa7ZWnNCzQ5A6GUj1Dh3ymoB/Fqh971++EPpuvJkc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QsQscf/orxDJtBQptev0aZCQgPqRV6B/iuRs+wSqLcxpArpkkS5tsEcPx0w2hgpuMe0U9Uyb8095SMXG8DN+fKN0KBR89+b1qxjWAE5QkhlVcTfbMpBxyEGEW5O14nKw4asML/lCAFsqPOTyzllAxnulwcy4jUPLEUfyu+St/rc= 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=W9kjzJr3; arc=none smtp.client-ip=209.85.216.43 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="W9kjzJr3" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2caff99b1c9so1879874a91.3 for ; Mon, 29 Jul 2024 06:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722259581; x=1722864381; 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=bD8c7gQ6DRUtbm73bhNDHnUk3N3GhZN60HOPY+jX8iI=; b=W9kjzJr3wyzCuwZGWB1Aw+85iWZxX2Klb3ZmYWMOchj9Wp4gSUd9InH298mrxQ8v5F T588jBXHVGL3UEsD5uNGHbMIQ0pyk/7UZAXqP84hdNK3w6gzE4i2ZvEuxljWZJjAtTA+ TIcxF1yNcAbPZj/zvKK+yUO/+D9v2xkDnEGiVccWaIKYb9us2L9bYjRGB78LChOxUBWh lQDGmqIgUlCieifx869HClu74RnFfKKjS0GePGnQlvxd8/dXziiYKYNOqWs3T2EHlGGN 8/rAQ/2gCe/hgc5vNrqnPYbglQeNl3KQhhiRm5t1uPMY2IVCMzrIpeVRLNR48cGEN8hg yxdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722259581; x=1722864381; 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=bD8c7gQ6DRUtbm73bhNDHnUk3N3GhZN60HOPY+jX8iI=; b=TMR7+GrzDlMM5LgNLBQLs2qIft+VDNKI9Rqrcd0KnY7IaftIAZQiZmDHqmu5jh646T lp+soCBHW/Oagk6cwNmSTsgCsnshZpWrLx9VQq1pvRJv2uCFRuyMdRv4tFLcFtgRgzcz 40lbxjMVYv4A0UEmm51aYnWplVBVYpemq0GotdIgFbvVv2P7CwWcJKt/oxt4sHMu/b23 cIPidisPEhuGieKQu32F8asKuvmXpvlw+ByxoKAe7Auvptp3N24klpUwNKbUAd4p9PZJ w3U7kVt6vHXPbZk5b+vjjn8+3Hj6a+MnZGfxeyr/KF+Z+LX4KiomXjniWgnklo76Q/nM EZMQ== X-Gm-Message-State: AOJu0YyVrsU/aihOcvnHZv1dmdD0tIiQ/CiQfF9v5wQQTucXmXzqs9zi J14jk4ELxjeEjBa4w6EVQX1OTZ2itdkwz5bDow4csBNY4vXndqIGUPR6Xw== X-Google-Smtp-Source: AGHT+IFEzjDW3oDJAKZmm4m+c5uQKg7yeIeKSZfsmxvsWB6sFB0tStDnobYRRaU0oFLB8WHakD0bDA== X-Received: by 2002:a17:90b:1b44:b0:2cb:4c4f:3280 with SMTP id 98e67ed59e1d1-2cf7e5c15e2mr5268698a91.26.1722259580531; Mon, 29 Jul 2024 06:26:20 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c565besm8497321a91.8.2024.07.29.06.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 06:26:20 -0700 (PDT) Date: Mon, 29 Jul 2024 21:26:40 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v13 03/10] fsck: rename objects-related fsck error functions Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The names of objects-related fsck error functions are general. It's OK when there is only object database check. However, we have introduced refs database check report function. To avoid ambiguity, rename object-related fsck error functions to explicitly indicate these functions are used to report objects-related messages. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- builtin/fsck.c | 16 ++++++++-------- fsck.c | 32 ++++++++++++++++---------------- fsck.h | 30 +++++++++++++++--------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 6abad60e7e..8553e2bc1b 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -89,13 +89,13 @@ 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, - const struct fsck_refs_info *refs_info UNUSED, - 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, + const struct fsck_refs_info *refs_info UNUSED, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id UNUSED, + const char *message) { switch (msg_type) { case FSCK_WARN: @@ -939,7 +939,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 1185e9a8ad..af61fa90ba 100644 --- a/fsck.c +++ b/fsck.c @@ -1235,13 +1235,13 @@ int fsck_buffer(const struct object_id *oid, enum object_type type, type); } -int fsck_error_function(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type UNUSED, - const struct fsck_refs_info *refs_info UNUSED, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id UNUSED, - const char *message) +int fsck_objects_error_function(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type UNUSED, + const struct fsck_refs_info *refs_info UNUSED, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id UNUSED, + const char *message) { if (msg_type == FSCK_WARN) { warning("object %s: %s", fsck_describe_object(o, oid), message); @@ -1339,18 +1339,18 @@ 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, - const struct fsck_refs_info *refs_info, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id, - const char *message) +int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type, + const struct fsck_refs_info *refs_info, + 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, refs_info, - msg_type, msg_id, message); + return fsck_objects_error_function(o, oid, object_type, refs_info, + msg_type, msg_id, message); } diff --git a/fsck.h b/fsck.h index 4f01a46cc7..f53ac339d2 100644 --- a/fsck.h +++ b/fsck.h @@ -124,18 +124,18 @@ 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, - const struct fsck_refs_info *refs_info, - 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, - const struct fsck_refs_info *refs_info, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id, - const char *message); +int fsck_objects_error_function(struct fsck_options *o, + const struct object_id *oid, enum object_type object_type, + const struct fsck_refs_info *refs_info, + enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, + const char *message); +int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type, + const struct fsck_refs_info *refs_info, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message); /* * The information for reporting refs-related error message @@ -163,7 +163,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, \ @@ -171,7 +171,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, \ @@ -179,7 +179,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 Jul 29 13:26:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13744947 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 539C03C24 for ; Mon, 29 Jul 2024 13:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259593; cv=none; b=pwvA8LzXMps2pv9OnNaWDscht5+6BrNzeildORhZAZSWAkjbjtq4mt3rJwYmLML8gjjXiqLT24FwjTuYv0FR2xOkVCGERuUZE/14Tzk1ToM39U5vhM5K37L9sidSWljtg2PeC6lb/z69xSdvnqfTcUCABuoRJmWijGfXaXyInQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259593; c=relaxed/simple; bh=wWP8bF/sPQDvbcCm4CeSTZLhRKkQj3XHJddpsuoY1Qw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Q3ecK0JKxZjGHjSnFx39VtO32pKcqajykq0uh/Pj1sOeEYyf/gjiUfUtdMwD0QE4x1pHg00XUG60aMImUoIKG1okQoQPVVSh/mhaypuxEB6aP1UUa7jxsBd37IQP+t06qBvoqyDQTMNsG/wU8LEWKNe9FiXyP0uGjetTiAvGvJg= 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=cA9BLMwD; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cA9BLMwD" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1fc4fcbb131so27085815ad.3 for ; Mon, 29 Jul 2024 06:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722259591; x=1722864391; 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=ynFHmapFj/WoKo3fn4fpxKUdKIY4lUbbqjHuoihCLYY=; b=cA9BLMwDiSPlOJ0qTxiB91q6bSCuWXQ3PPT/W50q5gJNR5H2Eb49ba5YLVT+JegZGN nhf31L9t9buBzgBD7cuuXJGGYE4xNsaYCacVCl8s+yEjAWiGl1P1ZnrSD2ZOaYbyONww SxzoMv8ZqStbbZPED/C/03yFMyuPkunHL84CsH4ytD+/O+/C7Hnql460E5Od+jtoi2pG sZbEPhpFMIYw5fU9Jw6EuOPS7ZuIhHkd0YnyRDx8aiZhSBtI6Y5GgVJ2UQUhzJHWnBxK va1H4B3hYF1JvFIylqdv5LJdTFCeslnjfItyQFAY/E08rTAWVKgTgd401LlJn98kU7Zv g1Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722259591; x=1722864391; 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=ynFHmapFj/WoKo3fn4fpxKUdKIY4lUbbqjHuoihCLYY=; b=eAO/qh5a2ltDzUyd4iDMQK4WoFbMSYQ9Hu9kaPrIQCdm1WGvPLHuHvKDPCY77JbnmW 9VE4c1z+s11sxFzdmdwoVU9anLOSb3wpin41rRjn+BANWmkI6Y5qyNGFZNZIil7nVEhL DK9IbpCfug8ckdpDy2F9vTDqlrc7yQBjeA3KASh5OkBD1Xg69Dsvsvq3wjugwX047M8r OOLPGd6Yj52zcR8WFChcM+ulG2tohDB2yHFRWJfxM4RghvaXdifQnSOLopVnu+mjG//M 6ITspCSXllzZnmlNZ+t14c+HwYnlGhebEJf0FSiceX5g2JOioCerIoYJ1leBTeL/iNvY tuSA== X-Gm-Message-State: AOJu0YxqTJKLPabYPMvq+qv7h7h56PVpLrE0nmmz1inKp1DJWiIlk0aO CiLtSYuqjLngmT20/vtfiy1m+ubUoxW0F+ATGygFb6YPXYTaZoi1yE9EVw== X-Google-Smtp-Source: AGHT+IHqFwvJG5hnwOOcEO9F174sfxJfLKrWr9v0IJrP5FOm+1rvE8mB/VyrOo6cfPZTD++9iptxpg== X-Received: by 2002:a17:902:dace:b0:1fa:b7ea:9f0f with SMTP id d9443c01a7336-1ff047fed8fmr108336565ad.7.1722259590779; Mon, 29 Jul 2024 06:26:30 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7f3e28csm82461015ad.216.2024.07.29.06.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 06:26:30 -0700 (PDT) Date: Mon, 29 Jul 2024 21:26:51 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v13 04/10] fsck: add refs-related error report function Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Add refs-related options to the "fsck_options", create refs-specific "error_func" callback "fsck_refs_error_function". "fsck_refs_error_function" will use the "oid" parameter. When the caller passes the oid, it will use "oid_to_hex" to get the corresponding hex value to report to the caller. Last, add "FSCK_REFS_OPTIONS_DEFAULT" and "FSCK_REFS_OPTIONS_STRICT" macros to create refs options easily. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- fsck.c | 25 +++++++++++++++++++++++++ fsck.h | 14 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/fsck.c b/fsck.c index af61fa90ba..56de29b4c0 100644 --- a/fsck.c +++ b/fsck.c @@ -1251,6 +1251,31 @@ int fsck_objects_error_function(struct fsck_options *o, return 1; } +int fsck_refs_error_function(struct fsck_options *options, + const struct object_id *oid, + enum object_type object_type UNUSED, + const struct fsck_refs_info *refs_info, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id UNUSED, + const char *message) +{ + struct strbuf sb = STRBUF_INIT; + int ret = 0; + + strbuf_addstr(&sb, refs_info->path); + + if (oid) + strbuf_addf(&sb, " -> (%s)", oid_to_hex(oid)); + + if (msg_type == FSCK_WARN) + warning("%s: %s", sb.buf, message); + else + ret = error("%s: %s", sb.buf, message); + + strbuf_release(&sb); + return ret; +} + static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done, enum fsck_msg_id msg_missing, enum fsck_msg_id msg_type, struct fsck_options *options, const char *blob_type) diff --git a/fsck.h b/fsck.h index f53ac339d2..a4a4ba88ee 100644 --- a/fsck.h +++ b/fsck.h @@ -136,6 +136,13 @@ int fsck_objects_error_cb_print_missing_gitmodules(struct fsck_options *o, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); +int fsck_refs_error_function(struct fsck_options *options, + const struct object_id *oid, + enum object_type object_type, + const struct fsck_refs_info *refs_info, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message); /* * The information for reporting refs-related error message @@ -181,6 +188,13 @@ struct fsck_options { .gitattributes_done = OIDSET_INIT, \ .error_func = fsck_objects_error_cb_print_missing_gitmodules, \ } +#define FSCK_REFS_OPTIONS_DEFAULT { \ + .error_func = fsck_refs_error_function, \ +} +#define FSCK_REFS_OPTIONS_STRICT { \ + .strict = 1, \ + .error_func = fsck_refs_error_function, \ +} /* descend in all linked child objects * the return value is: From patchwork Mon Jul 29 13:27:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13744948 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3B303C24 for ; Mon, 29 Jul 2024 13:26:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259605; cv=none; b=A+sdiHgOwRlz/hzS+cKa93spnDcsLnSlBp8bBzeY/0dP8zY/Xgo1q34cCriTLkx3bVDYk9ovk/G1YViSltckevfOxbJomAoywrR/H0Axlah8T5Jjef10k+LniudoxQW+el0p2v1BwCoZZliG2cBfeNkejJ75au6p+Cyz8Sks13M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259605; c=relaxed/simple; bh=gdzZtUiMMAv+cCptMUQh+15Vau+Cph2TgYYmOfgisrs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i33DkpxGLx821Xx+LrZp0Wf99Sks55u2BzERXuxrYMm2ZIJ5VfWiINFKqP0Kkeoyvznsydyp8obahHOtmCz+o1rel/eU3zd3QfwOvElyivqUZ4nqJRhOgDl9G5ys6ATssI5TW4P/r5VXPKEMHqGf4mrzmj2SJ7A3CG/Y1/Dk9BQ= 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=W+60s5Vt; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W+60s5Vt" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1fc587361b6so18689545ad.2 for ; Mon, 29 Jul 2024 06:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722259602; x=1722864402; 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=y10sf6B7a2IwqU6aPXXETwrwnXta6iUfh3l1cZgDfso=; b=W+60s5Vt8J9AufvBL87gWB7OYLoOSJ/Fd66ie478/cI838bcZa0c9b311hnpjB5+j1 lZgij2emS1q+Ro/9a7kdUvVPwnyrU2BkHpxFRWWSnPTERJimBDyzk+/suKrMq1cyX3h4 F5qy8+YDsZNpiiehJ9xW1KfMmgUCCDPCFqe6q1f570nR1B6Coyh3n76Fzic2rUVp/E2H TbwfsqToHjuo4kSWKYRfZdz9VFY+4DQO5iPsUPbGhFOLIlzqvfnLBsTvhzGm1L+qCVuZ 7ElOY09UtOf7M1mgrwIolENf3iCw5XudOzSSaqpr8bgvaVyzHI3fYQe+CnSfPJL2MIEg ko+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722259602; x=1722864402; 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=y10sf6B7a2IwqU6aPXXETwrwnXta6iUfh3l1cZgDfso=; b=FDGK/fIASVxmcL7qjo0yHWeoozS4OAVj2pMMucHMJmMkGXFdL4O4KA84kMrVBg2ijs 9UkHvKeuTprnrkRWf9Mp4+1nUsqq/59IqgFo29qXanroH9rVHxcUkBjEkdyM/qlAHNk/ 0R0l1l/1T/KlQGvqvj9f6UE/h5dzzC+CIiGLyNXF0u6I1JjigzYaUpE++AxwfMR8tWjT E9EjhNWb6VN42h72dqlZP4i91iTE51dPGeiPiL3NdNRpm7tj05UdzdR0Rpfb5IoG8+AI DbS85OKytTcCpaOTTbAG8zjOqrEYI5aGZPInlyjzuh6qDLMWRQTlGB0jjO+rZzOkVPin helw== X-Gm-Message-State: AOJu0Yx+lmMKU+K2u3cXQzQaKDoxBxohE6BmmNc8lntC8t2Bm4aaXuJS mqFW7QafGDTxajfNGYi6FHHKE/YWYKkbqcBUgM6N3lN9US1mfL9hXHlWMA== X-Google-Smtp-Source: AGHT+IH0LslYHGKz128yxDdNk/fKuOw2dR9yyyDkHWzAn0X5fFEHbXDO8cKnwmWM8YfX5I1bLcFUXA== X-Received: by 2002:a17:903:1211:b0:1fb:8c35:602f with SMTP id d9443c01a7336-1ff047e4629mr64791935ad.6.1722259602414; Mon, 29 Jul 2024 06:26:42 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7fcd252sm82525285ad.285.2024.07.29.06.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 06:26:41 -0700 (PDT) Date: Mon, 29 Jul 2024 21:27:02 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v13 05/10] refs: set up ref consistency check infrastructure Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The interfaces defined in the `ref_storage_be` are carefully structured in semantic. It's organized as the five parts: 1. The name and the initialization interfaces. 2. The ref transaction interfaces. 3. The ref internal interfaces (pack, rename and copy). 4. The ref filesystem interfaces. 5. The reflog related interfaces. To keep consistent with the git-fsck(1), add a new interface named "fsck_refs_fn" to the end of "ref_storage_be". This semantic cannot be grouped into any above five categories. Explicitly add blank line to make it different from others. Last, implement placeholder functions for each ref backends. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- refs.c | 5 +++++ refs.h | 8 ++++++++ refs/debug.c | 11 +++++++++++ refs/files-backend.c | 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 bb90a18875..410919246b 100644 --- a/refs.c +++ b/refs.c @@ -318,6 +318,11 @@ int check_refname_format(const char *refname, int flags) return check_or_sanitize_refname(refname, flags, NULL); } +int refs_fsck(struct ref_store *refs, struct fsck_options *o) +{ + return refs->be->fsck(refs, o); +} + void sanitize_refname_component(const char *refname, struct strbuf *out) { if (check_or_sanitize_refname(refname, REFNAME_ALLOW_ONELEVEL, out)) diff --git a/refs.h b/refs.h index 0ecba21b4a..804d6a7fce 100644 --- a/refs.h +++ b/refs.h @@ -4,6 +4,7 @@ #include "commit.h" #include "repository.h" +struct fsck_options; struct object_id; struct ref_store; struct strbuf; @@ -541,6 +542,13 @@ int refs_for_each_reflog(struct ref_store *refs, each_reflog_fn fn, void *cb_dat */ int check_refname_format(const char *refname, int flags); +/* + * Check the reference database for consistency. Return 0 if refs and + * reflogs are consistent, and non-zero otherwise. The errors will be + * written to stderr. + */ +int refs_fsck(struct ref_store *refs, struct fsck_options *o); + /* * Apply the rules from check_refname_format, but mutate the result until it * is acceptable, and place the result in "out". diff --git a/refs/debug.c b/refs/debug.c index 547d9245b9..45e2e784a0 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -419,6 +419,15 @@ static int debug_reflog_expire(struct ref_store *ref_store, const char *refname, return res; } +static int debug_fsck(struct ref_store *ref_store, + struct fsck_options *o) +{ + struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store; + int res = drefs->refs->be->fsck(drefs->refs, o); + trace_printf_key(&trace_refs, "fsck: %d\n", res); + return res; +} + struct ref_storage_be refs_be_debug = { .name = "debug", .init = NULL, @@ -451,4 +460,6 @@ struct ref_storage_be refs_be_debug = { .create_reflog = debug_create_reflog, .delete_reflog = debug_delete_reflog, .reflog_expire = debug_reflog_expire, + + .fsck = debug_fsck, }; diff --git a/refs/files-backend.c b/refs/files-backend.c index aa52d9be7c..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 Jul 29 13:27:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13744949 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 EBA533C24 for ; Mon, 29 Jul 2024 13:26:53 +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=1722259615; cv=none; b=hZ0h3OlIW8E2u04C9yHZDvvBYzVpXxk5yruJrfVaEcrqbUsAz8ZttEJ5vs2q+B5MKaoMhwbNqzoC3Paweov5uelRoFW08tTuk0LAJ1ok2SQdEK/KC3zsQs5X4mX0Oz3n/mpK0JnaTSQzP2wYjjsW6GWN/tlw8ri96iAwVHgBseM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259615; c=relaxed/simple; bh=2DuRd7FQzyKCWqT7nnB5wpt5BwLILAM0oGKgRm9Czls=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Jmm7Zq320C75yaKpFiX7xkZDY22FgQEKkgQfeZ93hpFHGzZaatc9gg/l5cgKfXFmEGSbX/PdYgPel6teGXUjj694G+2aOcUTVyUTvApY2V0R9UAlv8LtsjETH/4xgO9f03m3kJ7tnYVZ6//fXYXWFueRNPymBpUgFTw308fsk4k= 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=H2QM2nsT; 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="H2QM2nsT" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1ff1cd07f56so13332915ad.2 for ; Mon, 29 Jul 2024 06:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722259612; x=1722864412; 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=8TzRbnkNxH+PXwm2oTg2CJHt6kIiw+he4/q1ZQq7Ru4=; b=H2QM2nsTQzUwtynyGpnC3lC7PUXG5abuFxKhwVt7JDAMblDp92IZbzWMU4sm/DxydZ 3McLyRVV6r+M4FWlBeoRLExnrCfa+KwJAPLhIKBzckOU98nIt4T3fWzcL9W3K5e+7Pta MALRGFUmLgFiU8GWGE39BCrxsukz50cYL7eSjRUN9JIwOj4GxMA0PZPAlNkUAmqBGIMe LfdnkX+86FIFNhUHvyvjyN71gSKUAU/xUJxDcaqWydp7h2FzKG2muL3g3+w5KUIYrqY8 7ADem5p6Yu8S9TgccP5GX+c/DfdWsbjpfALiSIhBz9HfOPqtWhQ55PUFONBLrq787h42 JAXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722259612; x=1722864412; 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=8TzRbnkNxH+PXwm2oTg2CJHt6kIiw+he4/q1ZQq7Ru4=; b=KXMtDbZMnl6L/cqG5zK95UEOwIr/q/43eR+YkOnCqxYnGbcQxZZ8b9XKDwjH3rWyR+ QDifmNoFXHuFzyhbr15P1b1f1G4gTkx8aVy62cMKNKvfcNMZezvzppJ1hq4PDFdH1XOs 0fzS/dt4tdabsM+K/R1uTrFneh0SlCUtVEqbptRlLEcwBopG6LeorFsAeK/CQpG5NDCi kcxiu+a0AgiscKoNcW4ika4ih6+2kZ17XeJ5Xa2B4grI6X2LzrX4IifbAU9ZNEarQlsP V3vBDdpgORpBwXtAlAugG8fYqHpTgxzs0E737J+yT8ZM/libHSKpho82aFtzGdLYvUUx VptA== X-Gm-Message-State: AOJu0Yysa8q5UoU7WRKGwybw5Zbi+BVKvmynxJdh6JTmEr3hwxIVIUJ7 zOuNOWoKMC63kwB79qmQd6IudsjzpgI3mSF/hj/hUlltYLyYAnAmjTKONQ== X-Google-Smtp-Source: AGHT+IEEIBX91Mqf85rlajN/HGu0Eb7ax3q0aWJ3bXwnUmBsprF6pwHjuRq2lg2ogVAXd4ZU57X4CQ== X-Received: by 2002:a17:902:fd4c:b0:1fb:8864:e20 with SMTP id d9443c01a7336-1ff048384a4mr77523115ad.23.1722259612383; Mon, 29 Jul 2024 06:26:52 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7ee1258sm82689165ad.147.2024.07.29.06.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 06:26:51 -0700 (PDT) Date: Mon, 29 Jul 2024 21:27:12 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v13 06/10] git refs: add verify subcommand Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Introduce a new subcommand "verify" in git-refs(1) to allow the user to check the reference database consistency and also this subcommand will be used as the entry point of checking refs for "git-fsck(1)". Last, add "verbose" field into "fsck_options" to indicate whether we should print verbose messages when checking refs and objects consistency. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/git-refs.txt | 13 +++++++++++ builtin/refs.c | 44 ++++++++++++++++++++++++++++++++++++++ fsck.h | 1 + 3 files changed, 58 insertions(+) diff --git a/Documentation/git-refs.txt b/Documentation/git-refs.txt index 5b99e04385..1244a85b64 100644 --- a/Documentation/git-refs.txt +++ b/Documentation/git-refs.txt @@ -10,6 +10,7 @@ SYNOPSIS -------- [verse] 'git refs migrate' --ref-format= [--dry-run] +'git refs verify' [--strict] [--verbose] DESCRIPTION ----------- @@ -22,6 +23,9 @@ COMMANDS migrate:: Migrate ref store between different formats. +verify:: + Verify reference database consistency. + OPTIONS ------- @@ -39,6 +43,15 @@ include::ref-storage-format.txt[] can be used to double check that the migration works as expected before performing the actual migration. +The following options are specific to 'git refs verify': + +--strict:: + Enable more strict checking, every WARN severity for the `Fsck Messages` + be seen as ERROR. See linkgit:git-fsck[1]. + +--verbose:: + When verifying the reference database consistency, be chatty. + KNOWN LIMITATIONS ----------------- diff --git a/builtin/refs.c b/builtin/refs.c index 46dcd150d4..4831c9e28e 100644 --- a/builtin/refs.c +++ b/builtin/refs.c @@ -1,4 +1,6 @@ #include "builtin.h" +#include "config.h" +#include "fsck.h" #include "parse-options.h" #include "refs.h" #include "repository.h" @@ -7,6 +9,9 @@ #define REFS_MIGRATE_USAGE \ N_("git refs migrate --ref-format= [--dry-run]") +#define REFS_VERIFY_USAGE \ + N_("git refs verify [--strict] [--verbose]") + static int cmd_refs_migrate(int argc, const char **argv, const char *prefix) { const char * const migrate_usage[] = { @@ -58,15 +63,54 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix) return err; } +static int cmd_refs_verify(int argc, const char **argv, const char *prefix) +{ + struct fsck_options fsck_refs_options = FSCK_REFS_OPTIONS_DEFAULT; + const char * const verify_usage[] = { + REFS_VERIFY_USAGE, + NULL, + }; + unsigned int verbose = 0, strict = 0; + struct option options[] = { + OPT__VERBOSE(&verbose, N_("be verbose")), + OPT_BOOL(0, "strict", &strict, N_("enable strict checking")), + OPT_END(), + }; + int ret; + + argc = parse_options(argc, argv, prefix, options, verify_usage, 0); + if (argc) + usage(_("'git refs verify' takes no arguments")); + + if (verbose) + fsck_refs_options.verbose = 1; + if (strict) + fsck_refs_options.strict = 1; + + git_config(git_fsck_config, &fsck_refs_options); + prepare_repo_settings(the_repository); + + ret = refs_fsck(get_main_ref_store(the_repository), &fsck_refs_options); + + /* + * Explicitly free the allocated array and "skip_oids" set + */ + free(fsck_refs_options.msg_type); + oidset_clear(&fsck_refs_options.skip_oids); + return ret; +} + int cmd_refs(int argc, const char **argv, const char *prefix) { const char * const refs_usage[] = { REFS_MIGRATE_USAGE, + REFS_VERIFY_USAGE, NULL, }; parse_opt_subcommand_fn *fn = NULL; struct option opts[] = { OPT_SUBCOMMAND("migrate", &fn, cmd_refs_migrate), + OPT_SUBCOMMAND("verify", &fn, cmd_refs_verify), OPT_END(), }; diff --git a/fsck.h b/fsck.h index a4a4ba88ee..b03dba442e 100644 --- a/fsck.h +++ b/fsck.h @@ -155,6 +155,7 @@ struct fsck_options { fsck_walk_func walk; fsck_error error_func; unsigned strict:1; + unsigned verbose:1; enum fsck_msg_type *msg_type; struct oidset skip_oids; struct oidset gitmodules_found; From patchwork Mon Jul 29 13:27:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13744950 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 EF4DF3C24 for ; Mon, 29 Jul 2024 13:27:02 +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=1722259624; cv=none; b=q42dqw1x/pLP6Yig/nuK/6+7c+PCje+bEoSGDPG0nDTxFhJhc4oWmdrgORp4+WjDZSTcq9KPiuU6Muw+/qJC7vcJswMzYRKn/bsL1hFYM/Ny9S7lvrc6nzmoTWTavtLnmLLIRQ6+4XMuJ/DNNAHwLchF9TMCYdSt/wxYLy+Q4vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259624; c=relaxed/simple; bh=oax5/mdMia1wwui+zWhHZFMJU1RQQUU4ACCyNwi5t3g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LXSYSaR8JDEOFofxyoGRxY7bRY+oEAG1TVfchZHRKEVV3nq6v7zjZhg+sfsRccs8LyjS8KbqD/+gzKBp055fGrOSukg8oXaylXq5wmi/0bA8b0AUY1mSE849LproRg3bkYYyzLTnTitLoZAI9dkYX+j2gV6E/AcppB65JjIpbGY= 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=WlDxf5nn; 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="WlDxf5nn" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1fbc3a9d23bso17386345ad.1 for ; Mon, 29 Jul 2024 06:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722259621; x=1722864421; 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=7IR9haSBQCofcS8AJE48/2fbkLIAod6GEFRFzV3dFIc=; b=WlDxf5nn2R9my49jzHFc3QZgR2utl2BPBPAWSQzcfHf10lEmtwUed2Z+bB+qP+JVKY i22PlJFwFLFcPT94uzFayQ2I/sBYQ0rW/xCE5ky1I14elmgwwboWbM2HXQ4mm7haHMGj A9XRzWDw7mbYRtzu/3TIH80Ohs20zdy4065g96UDWC0m8Q/FIP6vCcWw1Y4DiJ2BVvjI kgl1ezlFNjOjJHLjLkSypAPmmtOEjSOCALqGaFbftO02PQYzz3bFcojDiyiVInDCp5PQ QWfwcHLjKNre+sgDbXpNDfjqEa434gfKgcKdMgHaLM026l16qGg6sWbzoyzBaWXPMqJT F3OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722259621; x=1722864421; 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=7IR9haSBQCofcS8AJE48/2fbkLIAod6GEFRFzV3dFIc=; b=NNVrwDSQ+7fY9K0seFnqOg3yDjrpja3OQi/BDa2PSQnoNfoX58D+lDB4GrgsDVK2eT 7/vIoGJd47FwfL8kQUUtFpeF8QZGu4c+wSUU2iWPsCX6uY5HDL6QB9vNOsnjU+mEN8Gm znX/5tjTo1vbdfTE6ZmP0WgE3HwOMzOwlGV1ec1gToOQYnbAvVg77Ers5OvbR6gpThgX jN3kQ6pyfVIZ0ol8yBezoDNMBqS440DyQ2kLNDQ0G0PSDCL8srskMPH4dEs51s/7lP7g UPvZv7IGGNq3zSsSfrl+2wmtxt3MmH1rPydrov16fM1lr5/N+9gQAbrJq6Wz8/NGnnn/ vwcw== X-Gm-Message-State: AOJu0YyOPfVvwKjbRSVmSyG7MFZpoMYk+Tpc0x+ptSEynF44hcuN+vDn 5GXKSyILxSiKn4f7Q/1/wPBRm1cEwdU2RoACfHycSQcMjN9dpQd2E83wdQ== X-Google-Smtp-Source: AGHT+IFt5gLosEoIXBYfDaoJ0S/j6i8RjrfAjX9JUHJ4PR9HGwfBfwrXTOM+nXh7fn6sLvuvn2QwVg== X-Received: by 2002:a17:902:e804:b0:1fd:672f:2b34 with SMTP id d9443c01a7336-1ff04858af4mr59209325ad.33.1722259621483; Mon, 29 Jul 2024 06:27:01 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c7f593sm82718965ad.36.2024.07.29.06.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 06:27:00 -0700 (PDT) Date: Mon, 29 Jul 2024 21:27:21 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v13 07/10] builtin/fsck: add `git-refs verify` child process Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Introduce a new function "fsck_refs" that initializes and runs a child process to execute the "git-refs verify" command. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- builtin/fsck.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/builtin/fsck.c b/builtin/fsck.c index 8553e2bc1b..7ca1628ba5 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -897,6 +897,21 @@ static int check_pack_rev_indexes(struct repository *r, int show_progress) return res; } +static void fsck_refs(void) +{ + struct child_process refs_verify = CHILD_PROCESS_INIT; + child_process_init(&refs_verify); + refs_verify.git_cmd = 1; + strvec_pushl(&refs_verify.args, "refs", "verify", NULL); + if (verbose) + strvec_push(&refs_verify.args, "--verbose"); + if (check_strict) + strvec_push(&refs_verify.args, "--strict"); + + if (run_command(&refs_verify)) + errors_found |= ERROR_REFS; +} + static char const * const fsck_usage[] = { N_("git fsck [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]\n" " [--[no-]full] [--strict] [--verbose] [--lost-found]\n" @@ -1066,6 +1081,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) check_connectivity(); + fsck_refs(); + if (the_repository->settings.core_commit_graph) { struct child_process commit_graph_verify = CHILD_PROCESS_INIT; From patchwork Mon Jul 29 13:27:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13744951 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 A09853C24 for ; Mon, 29 Jul 2024 13:27:13 +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=1722259635; cv=none; b=jIRZhC0ZyQpVX/mUWIhpa1jWoHXZ7I37iS6fxL2TbSwhS+DrYQ5dHXPq2y+XUl3wYmHqqr0bZDH2y3tmyG0uxYkyhKhdv1jXZgOe2Mh5DNXVYha1ss05jIKnKaTP4P/kz2KVLHn2XYGmkvdY1kIsFxlCXeFddLO7cwLti2wYH3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259635; c=relaxed/simple; bh=TE8NwQjzKd/O58pspBRA4ktfrmwk6VvxZtCQa0mIB44=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z/Zhj08VezAPXwGFz6j/XxtS0uMq97Q7usVnV8sTMrpNIQMFnXbGJTFOjKE2QMAMjvtK7pl43JMg/vUd0H94gUp3uYd/iPGyWIppv0Yjf8G0XA10B8AgwLb/FGj4sQZ0smHPlsFzas0S+tr3Gv/8vURFxDEj0UqriCyn/csen48= 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=mD+V+HBU; 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="mD+V+HBU" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7ab34117cc2so2253724a12.0 for ; Mon, 29 Jul 2024 06:27:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722259632; x=1722864432; 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=XWbdsMOjOn7D48XySucSjLbWZNhjLeRNinKbtQiQV1Y=; b=mD+V+HBUxw4yMesZ9qqkyI6R2ODelP+DrU8P4pxs/Z6svc8tDKbNrQPAa6FFeE2Glj 0F5OgwOxaWGFjZ2w9LfJESyYfdxr9L49Oy/53ATWQcY4qTZ2APeyJYB8FhYPwlvv1Uad +3fXx8CDfsGJ5jrYkhfUBX76fmjbpXFWOMZ1kNa/TkYfB18bINAh3qqGiCKyihwOtOQ3 9+Ua7AFI4Tzbph+nUoC3ZEpBtInt4gMVW6wxI0jRqpJvkzzULY/FtzGT1wxJbLJjLDy5 Qd/V8ojCOgs9cb9FFaBpdbG7KVAKbMIBIfY7y8Pamf8IcWOJ7QdRTupnLshnmQUbDHHV nqdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722259632; x=1722864432; 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=XWbdsMOjOn7D48XySucSjLbWZNhjLeRNinKbtQiQV1Y=; b=Tl4uCV9nlJ9FUqYleiOf2AtzjGONy5Wj5eTXIAthEqtleM4ezlOQ+it0pT5A4JVda2 OkOKbdLoofKvZNVdrdugWjqmMJqaPCrx9GQ2WN9E/sJ07hESSlQy72UbmrboutDh9Tt4 TFEbgBe1ytX8p3yhkK2i1tZNxIVRugxgk7JZ0mx3lfrdSpILBCo23OZrm1q7tSQVqIG8 ReJMK5R4YesDOV1y1YsRNq/Lht5/kJ0NAkvqy2BWhBKaiyiwXZhaf13lH8YgSSQHu2uC GjdKIz2xLziIlaYAkzo0fIlM9e4752QZ6+njLANpqA8UdsjT9NkXf/HDvTTkfBjq4OTr nzcA== X-Gm-Message-State: AOJu0YwOud+Hh2deynHKocRSjyMsWLma8hoqYYUanHQa+SjhK781VDSU XnDeVLD4whjvDEl1zvDJabAb0ZWC8PXqRGY8A1S597pzsb1agEy8Cm9CSw== X-Google-Smtp-Source: AGHT+IHqazEYZvE9KiRZWKTqw/R8q4Tihx7jK0PR5S8ZuzVu0VUIvl8lZBUHYiuYF+zSk/CwCW/3AA== X-Received: by 2002:a05:6a20:9146:b0:1c0:eabc:86a8 with SMTP id adf61e73a8af0-1c4a1183fddmr10884498637.5.1722259631894; Mon, 29 Jul 2024 06:27:11 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7c8cd90sm83083115ad.44.2024.07.29.06.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 06:27:11 -0700 (PDT) Date: Mon, 29 Jul 2024 21:27:31 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v13 08/10] files-backend: add unified interface for refs scanning Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: For refs and reflogs, we need to scan its corresponding directories to check every regular file or symbolic link which shares the same pattern. Introduce a unified interface for scanning directories for files-backend. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- refs/files-backend.c | 74 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 4630eb1f80..cb184953c1 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 fsck_options *o, + const char *gitdir, + const char *refs_check_dir, + struct dir_iterator *iter); + +static int files_fsck_refs_dir(struct ref_store *ref_store, + struct fsck_options *o, + const char *refs_check_dir, + files_fsck_refs_fn *fsck_refs_fns) +{ + const char *gitdir = ref_store->gitdir; + struct strbuf sb = STRBUF_INIT; + struct dir_iterator *iter; + int iter_status; + int ret = 0; + + strbuf_addf(&sb, "%s/%s", gitdir, refs_check_dir); + + iter = dir_iterator_begin(sb.buf, 0); + + if (!iter) { + ret = error_errno("cannot open directory %s", sb.buf); + goto out; + } + + while ((iter_status = dir_iterator_advance(iter)) == ITER_OK) { + if (S_ISDIR(iter->st.st_mode)) { + continue; + } else if (S_ISREG(iter->st.st_mode) || + S_ISLNK(iter->st.st_mode)) { + if (o->verbose) + fprintf_ln(stderr, "Checking %s/%s", + refs_check_dir, iter->relative_path); + for (size_t i = 0; fsck_refs_fns[i]; i++) { + if (fsck_refs_fns[i](o, gitdir, refs_check_dir, iter)) + ret = -1; + } + } else { + ret = error(_("unexpected file type for '%s'"), + iter->basename); + } + } + + if (iter_status != ITER_DONE) + ret = error(_("failed to iterate over '%s'"), sb.buf); + +out: + strbuf_release(&sb); + return ret; +} + +static int files_fsck_refs(struct ref_store *ref_store, + struct fsck_options *o) +{ + files_fsck_refs_fn fsck_refs_fns[]= { + NULL + }; + + if (o->verbose) + fprintf_ln(stderr, "Checking references consistency"); + + return files_fsck_refs_dir(ref_store, o, "refs", fsck_refs_fns); + +} + 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 refs->packed_ref_store->be->fsck(refs->packed_ref_store, o) | + files_fsck_refs(ref_store, o); } struct ref_storage_be refs_be_files = { From patchwork Mon Jul 29 13:27:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13744952 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E2F514A62A for ; Mon, 29 Jul 2024 13:27:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259649; cv=none; b=CmCaOdaBNa/IwBh115WcPHWWld7O+MTjLyTlKABC5f/ZEvtB0YYpbAYpmAhPD5m2pfk8diyullEKkeKhH+HEeNwTeG/OQRhEV0ogh0ZQwanANnkNMHMd1jTF4IQls0HQKRRv2xH9XUKx2MGGwYOivOjjDh4vbLA7D+7Dz6uIKi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259649; c=relaxed/simple; bh=8RwBGEBIjAWJ5XZJa1Rxbs3RHzkteUTrsYqIsGr0VRg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DgyoKRlboySPL1i0SOrqyo5AglhccIK4werKUOOHA5/EMYcJp0oJsRuoRCI3LacxzOfql2E63ubLGhV4aK42x0Po7hA50RB6rr66De3izjPp5o/E84WTZklMO+FKhrgxdx6OLmbYpV5dlY0+vpq38djFSXihkaizeoEVIttUSY4= 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=cPJ3hkME; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cPJ3hkME" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-70d1c8d7d95so1894671b3a.2 for ; Mon, 29 Jul 2024 06:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722259646; x=1722864446; 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=vSh3qqL5fVqO1XY1IPTM3TeR42nes8tLSFfDSjMkCBo=; b=cPJ3hkMEpYOXN+jf9B8b20c3xXZuSIC0FHI1K6paMzc1SHE+SvEl6zzSvy8PbJMet8 ivY+6VxRBZvpIlDK6G9MNbeXluIt0PA/8v4tmGeWfaFcjMqpPRhZYqtNYxfz41tJ/9BE 2FUT9Hv98r2Ac5FM6XSdMGza35bnRkj0vcR1Q6BsEDtpw8DYlPX1CmaxereM1zMeI++r 08gCs6Ps3nm2C0edfll9S76z/rOGvLRobYaRi1h+ctJ1zB7SonDeWQK/xZ+d3S2frveP 0h3eWXYF4/PdO7o/HWOiZATUMS/j8z7tD5cPvRw/JbUXr0s28nmW5hpvY9CiaHBxzKyt /2hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722259646; x=1722864446; 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=vSh3qqL5fVqO1XY1IPTM3TeR42nes8tLSFfDSjMkCBo=; b=KYL1sGkPsLitwV9ifmm+qS5v3MTrLzCOwHAJ4rrlcdgZG7/KRZ6fvEgMS972POn5WA e3AAPzU5nyeW3jUkRofUGctSEfpc+j5ukqjgKqHhOZ453c82+sPJHaMcBKtv4gNBs8eT kDcedngRX386RuTYSfVdZybWWJAmKiclBiu9Y5v0z+4Z+wpnFlokeZDhKM0f4AF+m7FB INXpKeJ2uS+FcgE/aaaT7HokJYsh4dafOYVqNTFk8ZdK83c/C+K62qT52Z6M+tBlavT8 TsXRzDJqxxG6ySGhLGdg37OIVUjpN+TV9H2+szxCIhRaL6O0eRkCjMhlCo/lGc168wBD zGrQ== X-Gm-Message-State: AOJu0Ywz5ReQZGTHBBmtqnq4jku2JC398X0ARht1YQQYv34Yv2uVzqfW L2lbTfKZWE2UjHehEQp5U+RyBwyCpNj2fFev8FQxTDrjR9xJ2WUOnGVojg== X-Google-Smtp-Source: AGHT+IEgf0JAgMJluB65QZ34Tw6d/B+ho2LEHzlgPQ/0FFM5URM+kLcAUJ0Ftcsw+3Pnuy0su0e/yg== X-Received: by 2002:a05:6a20:7fa6:b0:1bd:288f:e8b4 with SMTP id adf61e73a8af0-1c4a117c459mr6371469637.7.1722259646044; Mon, 29 Jul 2024 06:27:26 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead7115a1sm6804865b3a.46.2024.07.29.06.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 06:27:25 -0700 (PDT) Date: Mon, 29 Jul 2024 21:27:45 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v13 09/10] fsck: add ref name check for files backend Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The git-fsck(1) only implicitly checks the reference, it does not fully check refs with bad format name such as standalone "@" and name ending with ".lock". In order to provide such checks, add a new fsck message id "badRefName" with default ERROR type. Use existing "check_refname_format" to explicit check the ref name. And add a new unit test to verify the functionality. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/fsck-msgids.txt | 3 + fsck.h | 1 + refs/files-backend.c | 22 ++++++++ t/t0602-reffiles-fsck.sh | 101 ++++++++++++++++++++++++++++++++++ 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 f643585a34..d8e437a043 100644 --- a/Documentation/fsck-msgids.txt +++ b/Documentation/fsck-msgids.txt @@ -19,6 +19,9 @@ `badParentSha1`:: (ERROR) A commit object has a bad parent sha1. +`badRefName`:: + (ERROR) A ref has an invalid format. + `badTagName`:: (INFO) A tag has an invalid format. diff --git a/fsck.h b/fsck.h index b03dba442e..ce56ce4bef 100644 --- a/fsck.h +++ b/fsck.h @@ -31,6 +31,7 @@ enum fsck_msg_type { FUNC(BAD_NAME, ERROR) \ FUNC(BAD_OBJECT_SHA1, ERROR) \ FUNC(BAD_PARENT_SHA1, ERROR) \ + FUNC(BAD_REF_NAME, ERROR) \ FUNC(BAD_TIMEZONE, ERROR) \ FUNC(BAD_TREE, ERROR) \ FUNC(BAD_TREE_SHA1, ERROR) \ diff --git a/refs/files-backend.c b/refs/files-backend.c index cb184953c1..0d4fc27768 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3419,6 +3419,27 @@ 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; + struct fsck_refs_info info; + int ret = 0; + + if (check_refname_format(iter->basename, REFNAME_ALLOW_ONELEVEL)) { + strbuf_addf(&sb, "%s/%s", refs_check_dir, iter->relative_path); + info.path = sb.buf; + ret = fsck_refs_report(o, NULL, &info, + FSCK_MSG_BAD_REF_NAME, + "invalid refname format"); + } + + strbuf_release(&sb); + return ret; +} + static int files_fsck_refs_dir(struct ref_store *ref_store, struct fsck_options *o, const char *refs_check_dir, @@ -3469,6 +3490,7 @@ static int files_fsck_refs(struct ref_store *ref_store, struct fsck_options *o) { files_fsck_refs_fn fsck_refs_fns[]= { + files_fsck_refs_name, NULL }; diff --git a/t/t0602-reffiles-fsck.sh b/t/t0602-reffiles-fsck.sh new file mode 100755 index 0000000000..b2db58d2c6 --- /dev/null +++ b/t/t0602-reffiles-fsck.sh @@ -0,0 +1,101 @@ +#!/bin/sh + +test_description='Test reffiles backend consistency check' + +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +GIT_TEST_DEFAULT_REF_FORMAT=files +export GIT_TEST_DEFAULT_REF_FORMAT + +. ./test-lib.sh + +test_expect_success 'ref name should be checked' ' + test_when_finished "rm -rf repo" && + git init repo && + branch_dir_prefix=.git/refs/heads && + tag_dir_prefix=.git/refs/tags && + ( + cd repo && + git commit --allow-empty -m initial && + git checkout -b branch-1 && + git tag tag-1 && + git commit --allow-empty -m second && + git checkout -b branch-2 && + git tag tag-2 && + git tag multi_hierarchy/tag-2 + ) && + ( + cd repo && + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && + test_must_fail git fsck 2>err && + cat >expect <<-EOF && + error: refs/heads/.branch-1: badRefName: invalid refname format + EOF + rm $branch_dir_prefix/.branch-1 && + test_cmp expect err + ) && + ( + cd repo && + cp $tag_dir_prefix/tag-1 $tag_dir_prefix/tag-1.lock && + test_must_fail git fsck 2>err && + cat >expect <<-EOF && + error: refs/tags/tag-1.lock: badRefName: invalid refname format + EOF + rm $tag_dir_prefix/tag-1.lock && + test_cmp expect err + ) && + ( + cd repo && + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && + test_must_fail git fsck 2>err && + cat >expect <<-EOF && + error: refs/heads/@: badRefName: invalid refname format + EOF + rm $branch_dir_prefix/@ && + test_cmp expect err + ) && + ( + cd repo && + cp $tag_dir_prefix/multi_hierarchy/tag-2 $tag_dir_prefix/multi_hierarchy/@ && + test_must_fail git fsck 2>err && + cat >expect <<-EOF && + error: refs/tags/multi_hierarchy/@: badRefName: invalid refname format + EOF + rm $tag_dir_prefix/multi_hierarchy/@ && + test_cmp expect err + ) +' + +test_expect_success 'ref name check should be adapted into fsck messages' ' + test_when_finished "rm -rf repo" && + git init repo && + branch_dir_prefix=.git/refs/heads && + tag_dir_prefix=.git/refs/tags && + ( + cd repo && + git commit --allow-empty -m initial && + git checkout -b branch-1 && + git tag tag-1 && + git commit --allow-empty -m second && + git checkout -b branch-2 && + git tag tag-2 + ) && + ( + cd repo && + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && + git -c fsck.badRefName=warn fsck 2>err && + cat >expect <<-EOF && + warning: refs/heads/.branch-1: badRefName: invalid refname format + EOF + rm $branch_dir_prefix/.branch-1 && + test_cmp expect err + ) && + ( + cd repo && + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && + git -c fsck.badRefName=ignore fsck 2>err && + test_must_be_empty err + ) +' + +test_done From patchwork Mon Jul 29 13:27:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shejialuo X-Patchwork-Id: 13744961 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.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 57E97149C4D for ; Mon, 29 Jul 2024 13:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259659; cv=none; b=eHvtsv0PlQ8mPK7PJU6WL1Bwx5DUYqe8oiQ2E31xF5T6hf31cUzk/NuaFymJnBMAE5Y4NKcOfY6dxQZmiKcuE3Qd1g5xj9aRdZiAaYVgzWXf6nFMRC7LwGqE5FuNqn8BJz2mH180y2bYUokgprEWpr6FflVMP0zTA8SGp5eVVQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722259659; c=relaxed/simple; bh=jyPvgvaA8jeyvOtDSyeaijFCiHDttTYUBr9wFefrQqE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SG54+fhfmoePRlfFBm6wR10SpaawrefAja6w4e6VyTtoxDWqjU67bVuvgQSBd9tcwDMhUIdBsCaT+eVfYeLouxsagPnjrKrR6ptYDsTkj5irxgnhUYPzo0kRhgWjNYLB/Dzyy4sjunvRGF23xnEOxNSktU3riwgJErol2tw/3W8= 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=JlpIQ8rd; arc=none smtp.client-ip=209.85.210.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="JlpIQ8rd" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-70d25b5b6b0so2179058b3a.2 for ; Mon, 29 Jul 2024 06:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722259656; x=1722864456; 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=Wzl1qEPdfW2l9+UBkmeCflgAXmfNVUnA94Dlb5yCRws=; b=JlpIQ8rd77movObEXM4M2TJcWPA1H+XjWpKAKPActn5ESBZP8tCLZXQJgYa4TWkBnz Q6hT4XRJg2J7nVvKALLyr9MPFtnAkghKol52BGo56bnW5kDVF6TaiEGfRVeMImQXmsly K4L+YRfdcJ5VtqjlWtilysNxzbki08lFf7GtW3xCEMZQrdddYm2alcPGFLYrqis0WU57 Jm/ut79TmuOmtEYv99obPH2SDvAOMWH6uc0j7PqvoE+7jxXDkFs4cmNB+3l3YzK19eN2 v4QlTAB35+Rk/OZLwbEQ8GrawVy9cMCceLXs05Rdeg0wxEtJAGITWshGc9buWUSFkTx9 zyEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722259656; x=1722864456; 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=Wzl1qEPdfW2l9+UBkmeCflgAXmfNVUnA94Dlb5yCRws=; b=NheiD2FJ/wOmZDIjv2Tn9IoGGkYONmt8Eahh8V8sP2ZYmO6sobIDrM4wT+CTnBcT2g fwAph6W4mk5eHXi7uLvwu/+4XIV4mpA0k6Lvbss0WA5t9dwDXLyepfDv4BKT7mvDWPOM H1EVgQ6/GO2HIi/alF4k+HmQMZuuyc3saETz+QcdpAsPz/I8vMttd5J+++Y+SewMGQUp CM2nuc+3F5CASU/Muk+FlKQU+MwPp7/oYwQhg+BpIt+b/lkiXBP5EBGeOxe1qxXqFTaK Etf0BRjPE7tt8Z9SwfPDGVjapUkUZj+NswO8S8eBNUZvL8eEURpLxsjODEy+B0ccYbaZ 2piQ== X-Gm-Message-State: AOJu0YzludKB8MSXnxZWyJNYk7eVu2XDykp1/DoV9iTzeZON2RrZNDcu kb+mtgsqVFgkUv/gY3o7HezFAGT7381HkXmSo+ZdaBajL6F4yRYT7FEJCQ== X-Google-Smtp-Source: AGHT+IF2IO49UF5Mtm6Z5Oq5Wz0doprdBJ7J+pMpjriu1Ke7T2hGcQ9jz5qyYQw/RL3aQEEPqDFiPA== X-Received: by 2002:a05:6a20:258e:b0:1c2:9784:1b42 with SMTP id adf61e73a8af0-1c4a129d455mr6103613637.16.1722259655802; Mon, 29 Jul 2024 06:27:35 -0700 (PDT) Received: from localhost ([2605:52c0:1:4cf:6c5a:92ff:fe25:ceff]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7ff072asm82398995ad.296.2024.07.29.06.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 06:27:34 -0700 (PDT) Date: Mon, 29 Jul 2024 21:27:56 +0800 From: shejialuo To: git@vger.kernel.org Cc: Patrick Steinhardt , Karthik Nayak , Junio C Hamano , Eric Sunshine , Justin Tobler Subject: [GSoC][PATCH v13 10/10] fsck: add ref content check for files backend Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Enhance the git-fsck(1) command by adding a check for reference content in the files backend. The new functionality ensures that symrefs, real symbolic link and regular refs are validated correctly. In order to check the trailing content of the regular refs, add a new parameter `trailing` to `parse_loose_ref_contents`. For symrefs, `parse_loose_ref_contents` will set the "referent". However, symbolic link could be either absolute or relative. Use "strbuf_add_real_path" to read the symbolic link and convert the relative path to absolute path. Then use "skip_prefix" to make it align with symref "referent". Thus, the symrefs and symbolic links could share the same interface. Add a new function "files_fsck_symref_target" which aims at checking the following things: 1. whether the pointee is under the `refs/` directory. 2. whether the pointee name is correct. 3. whether the pointee path is a wrong type in filesystem. Last, add the following FSCK MESSAGEs: 1. "badRefContent(ERROR)": A ref has a bad content 2. "badSymrefPointee(ERROR)": The pointee of a symref is bad. 3. "trailingRefContent(WARN)": A ref content has trailing contents. Mentored-by: Patrick Steinhardt Mentored-by: Karthik Nayak Signed-off-by: shejialuo --- Documentation/fsck-msgids.txt | 9 +++ fsck.h | 3 + refs.c | 2 +- refs/files-backend.c | 144 +++++++++++++++++++++++++++++++++- refs/refs-internal.h | 5 +- t/t0602-reffiles-fsck.sh | 110 ++++++++++++++++++++++++++ 6 files changed, 268 insertions(+), 5 deletions(-) diff --git a/Documentation/fsck-msgids.txt b/Documentation/fsck-msgids.txt index d8e437a043..8fe24a960e 100644 --- a/Documentation/fsck-msgids.txt +++ b/Documentation/fsck-msgids.txt @@ -19,9 +19,15 @@ `badParentSha1`:: (ERROR) A commit object has a bad parent sha1. +`badRefContent`:: + (ERROR) A ref has a bad content. + `badRefName`:: (ERROR) A ref has an invalid format. +`badSymrefPointee`:: + (ERROR) The pointee of a symref is bad. + `badTagName`:: (INFO) A tag has an invalid format. @@ -167,6 +173,9 @@ `nullSha1`:: (WARN) Tree contains entries pointing to a null sha1. +`trailingRefContent`:: + (WARN) A ref content has trailing contents. + `treeNotSorted`:: (ERROR) A tree is not properly sorted. diff --git a/fsck.h b/fsck.h index ce56ce4bef..710b3513d0 100644 --- a/fsck.h +++ b/fsck.h @@ -32,6 +32,8 @@ enum fsck_msg_type { FUNC(BAD_OBJECT_SHA1, ERROR) \ FUNC(BAD_PARENT_SHA1, ERROR) \ FUNC(BAD_REF_NAME, ERROR) \ + FUNC(BAD_REF_CONTENT, ERROR) \ + FUNC(BAD_SYMREF_POINTEE, ERROR) \ FUNC(BAD_TIMEZONE, ERROR) \ FUNC(BAD_TREE, ERROR) \ FUNC(BAD_TREE_SHA1, ERROR) \ @@ -72,6 +74,7 @@ enum fsck_msg_type { FUNC(HAS_DOTDOT, WARN) \ FUNC(HAS_DOTGIT, WARN) \ FUNC(NULL_SHA1, WARN) \ + FUNC(TRAILING_REF_CONTENT, WARN) \ FUNC(ZERO_PADDED_FILEMODE, WARN) \ FUNC(NUL_IN_COMMIT, WARN) \ FUNC(LARGE_PATHNAME, WARN) \ diff --git a/refs.c b/refs.c index 410919246b..eb82fb7d4e 100644 --- a/refs.c +++ b/refs.c @@ -1760,7 +1760,7 @@ static int refs_read_special_head(struct ref_store *ref_store, } result = parse_loose_ref_contents(content.buf, oid, referent, type, - failure_errno); + failure_errno, NULL); done: strbuf_release(&full_path); diff --git a/refs/files-backend.c b/refs/files-backend.c index 0d4fc27768..131eec7307 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1,6 +1,7 @@ #define USE_THE_REPOSITORY_VARIABLE #include "../git-compat-util.h" +#include "../abspath.h" #include "../copy.h" #include "../environment.h" #include "../gettext.h" @@ -553,7 +554,7 @@ static int read_ref_internal(struct ref_store *ref_store, const char *refname, strbuf_rtrim(&sb_contents); buf = sb_contents.buf; - ret = parse_loose_ref_contents(buf, oid, referent, type, &myerr); + ret = parse_loose_ref_contents(buf, oid, referent, type, &myerr, NULL); out: if (ret && !myerr) @@ -589,7 +590,7 @@ static int files_read_symbolic_ref(struct ref_store *ref_store, const char *refn int parse_loose_ref_contents(const char *buf, struct object_id *oid, struct strbuf *referent, unsigned int *type, - int *failure_errno) + int *failure_errno, const char **trailing) { const char *p; if (skip_prefix(buf, "ref:", &buf)) { @@ -611,6 +612,10 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid, *failure_errno = EINVAL; return -1; } + + if (trailing) + *trailing = p; + return 0; } @@ -3440,6 +3445,140 @@ static int files_fsck_refs_name(struct fsck_options *o, return ret; } +/* + * Check the symref "pointee_name" and "pointee_path". The caller should + * make sure that "pointee_path" is absolute. For symbolic ref, "pointee_name" + * would be the content after "refs:". For symblic link, "pointee_name" would + * be the relative path agaignst "gitdir". + */ +static int files_fsck_symref_target(struct fsck_options *o, + struct fsck_refs_info *info, + const char *refname, + const char *pointee_name, + const char *pointee_path) +{ + const char *p = NULL; + struct stat st; + int ret = 0; + + if (!skip_prefix(pointee_name, "refs/", &p)) { + + ret = fsck_refs_report(o, NULL, info, + FSCK_MSG_BAD_SYMREF_POINTEE, + "points to ref outside the refs directory"); + goto out; + } + + if (check_refname_format(pointee_name, 0)) { + ret = fsck_refs_report(o, NULL, info, + FSCK_MSG_BAD_SYMREF_POINTEE, + "points to refname with invalid format"); + } + + if (lstat(pointee_path, &st) < 0) + goto out; + + if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) { + ret = fsck_refs_report(o, NULL, info, + FSCK_MSG_BAD_SYMREF_POINTEE, + "points to an invalid file type"); + goto out; + } +out: + return ret; +} + +static int files_fsck_refs_content(struct fsck_options *o, + const char *gitdir, + const char *refs_check_dir, + struct dir_iterator *iter) +{ + struct strbuf pointee_path = STRBUF_INIT, + ref_content = STRBUF_INIT, + abs_gitdir = STRBUF_INIT, + referent = STRBUF_INIT, + refname = STRBUF_INIT; + const char *trailing = NULL; + struct fsck_refs_info info; + int failure_errno = 0; + unsigned int type = 0; + struct object_id oid; + int ret = 0; + + strbuf_addf(&refname, "%s/%s", refs_check_dir, iter->relative_path); + info.path = refname.buf; + + /* + * If the file is a symlink, we need to only check the connectivity + * of the destination object. + */ + if (S_ISLNK(iter->st.st_mode)) { + const char *pointee_name = NULL; + + strbuf_add_real_path(&pointee_path, iter->path.buf); + + strbuf_add_absolute_path(&abs_gitdir, gitdir); + strbuf_normalize_path(&abs_gitdir); + if (!is_dir_sep(abs_gitdir.buf[abs_gitdir.len - 1])) + strbuf_addch(&abs_gitdir, '/'); + + if (!skip_prefix(pointee_path.buf, + abs_gitdir.buf, &pointee_name)) { + ret = fsck_refs_report(o, NULL, &info, + FSCK_MSG_BAD_SYMREF_POINTEE, + "point to target outside gitdir"); + goto clean; + } + + ret = files_fsck_symref_target(o, &info, refname.buf, + pointee_name, pointee_path.buf); + goto clean; + } + + if (strbuf_read_file(&ref_content, iter->path.buf, 0) < 0) { + ret = error_errno(_("%s/%s: unable to read the ref"), + refs_check_dir, iter->relative_path); + goto clean; + } + + if (parse_loose_ref_contents(ref_content.buf, &oid, + &referent, &type, + &failure_errno, &trailing)) { + ret = fsck_refs_report(o, NULL, &info, + FSCK_MSG_BAD_REF_CONTENT, + "invalid ref content"); + goto clean; + } + + /* + * If the ref is a symref, we need to check the destination name and + * connectivity. + */ + if (referent.len && (type & REF_ISSYMREF)) { + strbuf_addf(&pointee_path, "%s/%s", gitdir, referent.buf); + strbuf_rtrim(&referent); + + ret = files_fsck_symref_target(o, &info, refname.buf, + referent.buf, pointee_path.buf); + goto clean; + } else { + if (trailing && (*trailing != '\0' && *trailing != '\n')) { + ret = fsck_refs_report(o, NULL, &info, + FSCK_MSG_TRAILING_REF_CONTENT, + "trailing garbage in ref"); + goto clean; + } + } + +clean: + strbuf_release(&abs_gitdir); + strbuf_release(&pointee_path); + strbuf_release(&refname); + strbuf_release(&ref_content); + strbuf_release(&referent); + return ret; +} + static int files_fsck_refs_dir(struct ref_store *ref_store, struct fsck_options *o, const char *refs_check_dir, @@ -3491,6 +3630,7 @@ static int files_fsck_refs(struct ref_store *ref_store, { files_fsck_refs_fn fsck_refs_fns[]= { files_fsck_refs_name, + files_fsck_refs_content, NULL }; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index a905e187cd..2fabf41d14 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -709,11 +709,12 @@ struct ref_store { /* * Parse contents of a loose ref file. *failure_errno maybe be set to EINVAL for - * invalid contents. + * invalid contents. Also *trailing is set to the first character after the + * refname or NULL if the referent is not empty. */ int parse_loose_ref_contents(const char *buf, struct object_id *oid, struct strbuf *referent, unsigned int *type, - int *failure_errno); + int *failure_errno, const char **trailing); /* * Fill in the generic part of refs and add it to our collection of diff --git a/t/t0602-reffiles-fsck.sh b/t/t0602-reffiles-fsck.sh index b2db58d2c6..29cd824224 100755 --- a/t/t0602-reffiles-fsck.sh +++ b/t/t0602-reffiles-fsck.sh @@ -98,4 +98,114 @@ test_expect_success 'ref name check should be adapted into fsck messages' ' ) ' +test_expect_success 'regular ref content should be checked' ' + test_when_finished "rm -rf repo" && + git init repo && + branch_dir_prefix=.git/refs/heads && + tag_dir_prefix=.git/refs/tags && + ( + cd repo && + git commit --allow-empty -m initial && + git checkout -b branch-1 && + git tag tag-1 && + git commit --allow-empty -m second && + git checkout -b branch-2 && + git tag tag-2 && + git checkout -b a/b/tag-2 + ) && + ( + cd repo && + printf "%s garbage" "$(git rev-parse branch-1)" > $branch_dir_prefix/branch-1-garbage && + git fsck 2>err && + cat >expect <<-EOF && + warning: refs/heads/branch-1-garbage: trailingRefContent: trailing garbage in ref + EOF + rm $branch_dir_prefix/branch-1-garbage && + test_cmp expect err + ) && + ( + cd repo && + printf "%s garbage" "$(git rev-parse tag-1)" > $tag_dir_prefix/tag-1-garbage && + test_must_fail git -c fsck.trailingRefContent=error fsck 2>err && + cat >expect <<-EOF && + error: refs/tags/tag-1-garbage: trailingRefContent: trailing garbage in ref + EOF + rm $tag_dir_prefix/tag-1-garbage && + test_cmp expect err + ) && + ( + cd repo && + printf "%s " "$(git rev-parse tag-2)" > $tag_dir_prefix/tag-2-garbage && + git fsck 2>err && + cat >expect <<-EOF && + warning: refs/tags/tag-2-garbage: trailingRefContent: trailing garbage in ref + EOF + rm $tag_dir_prefix/tag-2-garbage && + test_cmp expect err + ) && + ( + cd repo && + printf "xfsazqfxcadas" > $tag_dir_prefix/tag-2-bad && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/tags/tag-2-bad: badRefContent: invalid ref content + EOF + rm $tag_dir_prefix/tag-2-bad && + test_cmp expect err + ) && + ( + cd repo && + printf "xfsazqfxcadas" > $branch_dir_prefix/a/b/branch-2-bad && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/a/b/branch-2-bad: badRefContent: invalid ref content + EOF + rm $branch_dir_prefix/a/b/branch-2-bad && + test_cmp expect err + ) +' + +test_expect_success 'symbolic ref content should be checked' ' + test_when_finished "rm -rf repo" && + git init repo && + branch_dir_prefix=.git/refs/heads && + tag_dir_prefix=.git/refs/tags && + ( + cd repo && + git commit --allow-empty -m initial && + git checkout -b branch-1 && + git tag tag-1 + ) && + ( + cd repo && + printf "ref: refs/heads/.branch" > $branch_dir_prefix/branch-2-bad && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/branch-2-bad: badSymrefPointee: points to refname with invalid format + EOF + rm $branch_dir_prefix/branch-2-bad && + test_cmp expect err + ) && + ( + cd repo && + printf "ref: refs/heads" > $branch_dir_prefix/branch-2-bad && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/branch-2-bad: badSymrefPointee: points to an invalid file type + EOF + rm $branch_dir_prefix/branch-2-bad && + test_cmp expect err + ) && + ( + cd repo && + printf "ref: logs/maint-v2.45" > $branch_dir_prefix/branch-2-bad && + test_must_fail git refs verify 2>err && + cat >expect <<-EOF && + error: refs/heads/branch-2-bad: badSymrefPointee: points to ref outside the refs directory + EOF + rm $branch_dir_prefix/branch-2-bad && + test_cmp expect err + ) +' + test_done