From patchwork Wed Mar 17 18:20:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 012DCC433E0 for ; Wed, 17 Mar 2021 18:21:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA31F64F3B for ; Wed, 17 Mar 2021 18:21:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233024AbhCQSVW (ORCPT ); Wed, 17 Mar 2021 14:21:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232860AbhCQSVN (ORCPT ); Wed, 17 Mar 2021 14:21:13 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D42F1C06175F for ; Wed, 17 Mar 2021 11:21:12 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id j7so2843915wrd.1 for ; Wed, 17 Mar 2021 11:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fx0sC5TkzFx2GfWSWJCiitiaa1S4K8HgpiWxq/HPxgY=; b=UlxIbGuZqU3cS66YILDSCtpDZiNWLmb6PWMLZQ4IqgUVJqHwDJJrYX3xmLHIprasAi tcQ86FPfHbQ5eYMtKqir8QUz5BbeMTcesO9RbDm+pNLiJMZsmYrp1wWp3lVjqB2bunkT OOPG2kugpCFT6GMfw8U5GZhWLae/xFRhWB/JLazqXG+19JLq4G4pUI4S8p5rNPhbWPP9 NiopzLYauU1ypkPAb0KD0nmoBOiYjN/HPgWKlyUoiQQXhI+iqh1GI9gQ1OPPhAQux8NI 1fQlxhFAY4ix16CRXSinTX+i76hdlFSt/ky4DoSAWtav9o1XiQKFuZI8Oqmmr3LawF2Z ju3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fx0sC5TkzFx2GfWSWJCiitiaa1S4K8HgpiWxq/HPxgY=; b=aEKZYdHsDJ5kekP02rbxbehp+vAwtQlG/jvmLdmULuBDLl4mIpWvei/Hhanc9BHA2q e0UZpRC/kJjCjdjZc+Rm+2Ir/4T1P7JDevYg+tlm2ge/RWhsyajz4/s90FWaN5Zk61rO 0Q24HiZQL9oCoqfy4Nj70wXd/lM176AN92EalA4CAWds7zeBn5v8jzueb/7X06JqOPLr VdKIglhQUAPtpU43YDgnUZde+RpkHtNAfoB8m2wvA8quy/upI7shrARWk6bMZn/GyLwz KE37I7wNX/6U7AHuNIw1zJr+xOYBqs3Oqv+epJUJPKY02PJzhy72DH4DAoeVkb8PJaWC GcYA== X-Gm-Message-State: AOAM533SHmJlxi5eUfIOAah2RoSlzJYy/GgmuTBmYrgZJKI7EfbeE0hB gUPLecFnNBTM0XCsymy3kU+1SKXaw6skeA== X-Google-Smtp-Source: ABdhPJzu2Ny0Y68oix1fTgWJpsRSUjgbltMOCF2ViHvJt3rBdi2XL9aT+u+jPvRMu1EsPcSXQkYN7Q== X-Received: by 2002:adf:fb8a:: with SMTP id a10mr5622881wrr.365.1616005271401; Wed, 17 Mar 2021 11:21:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:11 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 01/19] fsck.c: refactor and rename common config callback Date: Wed, 17 Mar 2021 19:20:36 +0100 Message-Id: <20210317182054.5986-2-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor code I recently changed in 1f3299fda9 (fsck: make fsck_config() re-usable, 2021-01-05) so that I could use fsck's config callback in mktag in 1f3299fda9 (fsck: make fsck_config() re-usable, 2021-01-05). I don't know what I was thinking in structuring the code this way, but it clearly makes no sense to have an fsck_config_internal() at all just so it can get a fsck_options when git_config() already supports passing along some void* data. Let's just make use of that instead, which gets us rid of the two wrapper functions, and brings fsck's common config callback in line with other such reusable config callbacks. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fsck.c | 7 +------ builtin/mktag.c | 7 +------ fsck.c | 4 ++-- fsck.h | 3 +-- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 821e7798c7..a56a2d0513 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -71,11 +71,6 @@ static const char *printable_type(const struct object_id *oid, return ret; } -static int fsck_config(const char *var, const char *value, void *cb) -{ - return fsck_config_internal(var, value, cb, &fsck_obj_options); -} - static int objerror(struct object *obj, const char *err) { errors_found |= ERROR_OBJECT; @@ -803,7 +798,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) if (name_objects) fsck_enable_object_names(&fsck_walk_options); - git_config(fsck_config, NULL); + git_config(git_fsck_config, &fsck_obj_options); if (connectivity_only) { for_each_loose_object(mark_loose_for_connectivity, NULL, 0); diff --git a/builtin/mktag.c b/builtin/mktag.c index 41a399a69e..23c4b8763f 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -14,11 +14,6 @@ static int option_strict = 1; static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; -static int mktag_config(const char *var, const char *value, void *cb) -{ - return fsck_config_internal(var, value, cb, &fsck_options); -} - static int mktag_fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, @@ -93,7 +88,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix) fsck_options.error_func = mktag_fsck_error_func; fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn"); /* config might set fsck.extraHeaderEntry=* again */ - git_config(mktag_config, NULL); + git_config(git_fsck_config, &fsck_options); if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options, &tagged_oid, &tagged_type)) die(_("tag on stdin did not pass our strict fsck check")); diff --git a/fsck.c b/fsck.c index e3030f3b35..5dfb99665a 100644 --- a/fsck.c +++ b/fsck.c @@ -1323,9 +1323,9 @@ int fsck_finish(struct fsck_options *options) return ret; } -int fsck_config_internal(const char *var, const char *value, void *cb, - struct fsck_options *options) +int git_fsck_config(const char *var, const char *value, void *cb) { + struct fsck_options *options = cb; if (strcmp(var, "fsck.skiplist") == 0) { const char *path; struct strbuf sb = STRBUF_INIT; diff --git a/fsck.h b/fsck.h index 733378f126..f70d11c559 100644 --- a/fsck.h +++ b/fsck.h @@ -109,7 +109,6 @@ const char *fsck_describe_object(struct fsck_options *options, * git_config() callback for use by fsck-y tools that want to support * fsck. fsck.skipList etc. */ -int fsck_config_internal(const char *var, const char *value, void *cb, - struct fsck_options *options); +int git_fsck_config(const char *var, const char *value, void *cb); #endif From patchwork Wed Mar 17 18:20:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E34DBC43381 for ; Wed, 17 Mar 2021 18:21:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A551E64F4F for ; Wed, 17 Mar 2021 18:21:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232985AbhCQSVZ (ORCPT ); Wed, 17 Mar 2021 14:21:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232942AbhCQSVO (ORCPT ); Wed, 17 Mar 2021 14:21:14 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B18D2C06174A for ; Wed, 17 Mar 2021 11:21:13 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id v4so2823015wrp.13 for ; Wed, 17 Mar 2021 11:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O+FIxwKwSqGjF8S+lR63tXVM+rkWT7p0qumHxdrPm/s=; b=BVF6ay2nAenhaG++CJ39QV161DYO0KKTiG4FqJl3icQfKj4o90Mf71CgguRTGP963M ztpUFkdE85OvxNJ4V8DiLa+f5jC++iEsJf9F+V/FhfeJDFjOSsGqfGPe+f3vlQSQ1U1m NaZOdj1zeesnGZ49Bkz4fcnUrcas7ZFSKn/q9g9wHYLN8WVMdpDLFpO6fmfK2KgZxUfj u0b2q4fd2bhJXXVFrYLsSeh3HQmP0B9Czo31ZPudFosR2JBtgTYcpq+sPakh6KaoKSqD OmfXw0nr7m9f+p5hHYLimpuhv0jo/X8YgWgh+sMB5BjvOy/6izRmPE1AjvgsxRkBxq/T /CCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O+FIxwKwSqGjF8S+lR63tXVM+rkWT7p0qumHxdrPm/s=; b=alnd/hSF6YuXsKzMSm9GkIOPqCbFa6GsUMgMAMfQIJnXvPwv0z0Um44Zy2GeMrdaL3 vpq2u9Q/Xdh3Wq8VdxhZo2dQIDdPKMqbyUY4wCq/E/X4uaHLTuanBQ/3izBPh9Iry6g5 PPHwQlHMGTSHkd2g0n7Xd7CIZzrOvNktQ4qyhEGQ0Y7X87CbtTscpl2IPSKtf0RsavQq zehDrQI1jCsMpb7S1LI4ULOEHd/EtA67UYEMOZNXS9UQcEGJHOjRe2LVZXzmBSodj+fL JwbF9pM/pieANNekGS8kp+HhekJRvffrZ01gmMK8/Yqqdm9vSltGbrsw+UYUty19m1ff 0FQw== X-Gm-Message-State: AOAM533MP+sO3VwYxMRF8NbHDQKYLuxeXireQ9m26H7qVLK9GgW8SVA9 LFMjrIMDDqMDVH+gXQp50YmBBuO8FYVR2Q== X-Google-Smtp-Source: ABdhPJyvWqsC/MJKLM7nfB8MebEsn68wUjNgi1n6vbBqmkOwvEtGQtPQK3B7mg7TZS8+kU84k6B4Tw== X-Received: by 2002:adf:a2cf:: with SMTP id t15mr6000575wra.250.1616005272131; Wed, 17 Mar 2021 11:21:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:11 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Date: Wed, 17 Mar 2021 19:20:37 +0100 Message-Id: <20210317182054.5986-3-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the definitions of FSCK_OPTIONS_{DEFAULT,STRICT} to use designated initializers. While I'm at it add the "object_names" member to the initialization. This was omitted in 7b35efd734e (fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added. I'm using a new FSCK_OPTIONS_COMMON and FSCK_OPTIONS_COMMON_ERROR_FUNC helper macros to define what FSCK_OPTIONS_{DEFAULT,STRICT} have in common, and define the two in terms of those macro. The FSCK_OPTIONS_COMMON macro will be used in a subsequent commit to define other variants of common fsck initialization that wants to use a custom error function, but share the rest of the defaults. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fsck.h b/fsck.h index f70d11c559..15e12f292f 100644 --- a/fsck.h +++ b/fsck.h @@ -43,8 +43,17 @@ struct fsck_options { kh_oid_map_t *object_names; }; -#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT } -#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT } +#define FSCK_OPTIONS_COMMON \ + .walk = NULL, \ + .msg_type = NULL, \ + .skiplist = OIDSET_INIT, \ + .object_names = NULL, +#define FSCK_OPTIONS_COMMON_ERROR_FUNC \ + FSCK_OPTIONS_COMMON \ + .error_func = fsck_error_function + +#define FSCK_OPTIONS_DEFAULT { .strict = 0, FSCK_OPTIONS_COMMON_ERROR_FUNC } +#define FSCK_OPTIONS_STRICT { .strict = 1, FSCK_OPTIONS_COMMON_ERROR_FUNC } /* descend in all linked child objects * the return value is: From patchwork Wed Mar 17 18:20:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146695 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF717C433E9 for ; Wed, 17 Mar 2021 18:21:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92CF764F44 for ; Wed, 17 Mar 2021 18:21:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233049AbhCQSV0 (ORCPT ); Wed, 17 Mar 2021 14:21:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232883AbhCQSVO (ORCPT ); Wed, 17 Mar 2021 14:21:14 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FE0DC06174A for ; Wed, 17 Mar 2021 11:21:14 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id j18so2833840wra.2 for ; Wed, 17 Mar 2021 11:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tv9/sGpXcdz5uoZZQ+gyisCOmUir/Kc9Y7V/RQYVCJo=; b=MftI7qe76bayoNWVpfUhA2WyFZWkOhk3pG8fQk3eV+czV04raMorfBGujE7TdZVqcp FRDlvW9TKU5HEp7uTyGUFvCSPL1jSVlvO4puzXqayKAynTF7FyHsn7bvise4i6VtwGhA DiChUberCghq4OJ/grTyEOS/gPiW6lLPgL7q7gsHSMW6Uj57QSTL+W96MHoGf43N7uKA oc/HgcFNCdn7L2O1cJMIWoiRbB5ga46jUovwt10i0HfB6m2DyEorTzxlY5dJi+VB0FDb /lXRbOugpvqyctCGHF/iJfocKjLBHXa51R75ibjIc1K/HMTWPUZ0S+an+nxNRRwi85gx U8hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tv9/sGpXcdz5uoZZQ+gyisCOmUir/Kc9Y7V/RQYVCJo=; b=Dm4QXl1vC3Cprwqqj7IjzLdTfFsU01Y1F32W4H7Wh413bpJsmM0DMvZrzZGtYkSUjs PkFx2X0kzk6O1iduT0XQBcX89ym3Ls6zrYKdmDmmBXVmoKYICQE4Za1VT2/XFKHWjho4 WAWqLUqFO6qsoeXYiTbvSQaadefkogj0Gw3jUzokKolPHyxL9y+HJ9lGLxQdplq49Lu8 xT+W7EO5fT7bfPUYnoN2QoTX37WXKj14+b74baIVVaPYCfeNKlE9stN+gq82RoP1L0+c iw/bxynvvz4hqIz3mZ6whdVNPcEfmkG87qoyix3c8dZSHBQmhkYwBDM5q8T6bMXPfzoU ZbsA== X-Gm-Message-State: AOAM531N8ReZBjBnyjaEdZW0E/MNGKXWURHqRtgI4hFpFh3ttdrdoxNa 2ihv9j3dPcKLsmEqtnMb6W828iOAQhhjUA== X-Google-Smtp-Source: ABdhPJzioJ4lHFZ9I4rxx5JRfEySEgZgjL7pUkOs/byTG98Krj3wO1EHiv8aYvcABBj+KyWtcwG04g== X-Received: by 2002:a05:6000:1803:: with SMTP id m3mr5849218wrh.50.1616005272996; Wed, 17 Mar 2021 11:21:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:12 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 03/19] fsck.h: use "enum object_type" instead of "int" Date: Wed, 17 Mar 2021 19:20:38 +0100 Message-Id: <20210317182054.5986-4-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the fsck_walk_func to use an "enum object_type" instead of an "int" type. The types are compatible, and ever since this was added in 355885d5315 (add generic, type aware object chain walker, 2008-02-25) we've used entries from object_type (OBJ_BLOB etc.). So this doesn't really change anything as far as the generated code is concerned, it just gives the compiler more information and makes this easier to read. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fsck.c | 3 ++- builtin/index-pack.c | 3 ++- builtin/unpack-objects.c | 3 ++- fsck.h | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index a56a2d0513..ed5f2af6b5 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -192,7 +192,8 @@ static int traverse_reachable(void) return !!result; } -static int mark_used(struct object *obj, int type, void *data, struct fsck_options *options) +static int mark_used(struct object *obj, enum object_type object_type, + void *data, struct fsck_options *options) { if (!obj) return 1; diff --git a/builtin/index-pack.c b/builtin/index-pack.c index bad5748807..69f24fe9f7 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -212,7 +212,8 @@ static void cleanup_thread(void) free(thread_data); } -static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options) +static int mark_link(struct object *obj, enum object_type type, + void *data, struct fsck_options *options) { if (!obj) return -1; diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index dd4a75e030..ca54fd1668 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -187,7 +187,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf) * that have reachability requirements and calls this function. * Verify its reachability and validity recursively and write it out. */ -static int check_object(struct object *obj, int type, void *data, struct fsck_options *options) +static int check_object(struct object *obj, enum object_type type, + void *data, struct fsck_options *options) { struct obj_buffer *obj_buf; diff --git a/fsck.h b/fsck.h index 15e12f292f..e3edaff8e7 100644 --- a/fsck.h +++ b/fsck.h @@ -23,7 +23,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type); * <0 error signaled and abort * >0 error signaled and do not abort */ -typedef int (*fsck_walk_func)(struct object *obj, int type, void *data, struct fsck_options *options); +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 */ typedef int (*fsck_error)(struct fsck_options *o, From patchwork Wed Mar 17 18:20:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146699 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13352C4332E for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DEB4E64F3B for ; Wed, 17 Mar 2021 18:21:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233060AbhCQSV1 (ORCPT ); Wed, 17 Mar 2021 14:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232946AbhCQSVP (ORCPT ); Wed, 17 Mar 2021 14:21:15 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42B99C06174A for ; Wed, 17 Mar 2021 11:21:15 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id b9so2832979wrt.8 for ; Wed, 17 Mar 2021 11:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dj4R1z5WjejkTK819mL17+k5twm4kg36VHwxL48S7i4=; b=KSfVYCiciRYxlPSx8k7OlZf9wjAlxz3adlBduV308N08OjVhoSmCrhBoKhLoK5jrTR Kk3OuT69qDx/qZz4rgishg43ec8q7nhp5f3TYQOKu6QWNsUTbVFOe/Rfcj/1dgppu2UB 1HPxJVsIGUSygdEjbxrRdT52spAmh5NCwpu9W8nkJ46cW1wuO6X1vFyZ2Yu2CZD/+s8y 28Qyo81Eb5Ou4JWtNO1WvCF6xCV0wES5oUdIgbtbsfS1qIshsfPb17Ira8DX6H0NDQQM GYfJmoegfUR81WvFLpt3nuqAHA3L6EpWLBC0cy5qhkeeDbDKiVRCMwLRrAlaBhiyCZe3 Jvng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dj4R1z5WjejkTK819mL17+k5twm4kg36VHwxL48S7i4=; b=ugG4r4v0oX4NpyZPW1LtESk0F89wwV3zi1AeJgUz4M+1Npu7j1QXBAMDo/8dmuhy0q VGa1tSsy7o87Dx9rDwzh0mHlBcbTzz5ZSSY1ss9rgSuir8ze2r6SHpYGWtCWQfSOmnSt BJ/5S6cIGGelyqrCW5Z9bPY4qSiw69n+tPkcCSvMedc1Qv0VwoXndFF++F/Nq1rjPU2M UDf4mM2BTwWeM1I5i3pN4nmBB1Yc35u8pbhv2Z5HFsQPcjukalPyWLBMWuYRZKSYBo7+ LxfYunDJ4e/Q5MCXFVxsnq8Agzmmc9HUebRnExf5n0O0t629BmcZQqz3E1GoBlKMbbHR GRnw== X-Gm-Message-State: AOAM533EnzJXwxmFBursTNwEIBk8QWsM91zt9+FCrwCJYMYUYo/dJJgP 1PLkWTme5S3NRbqvygQVJEwXPZ1Qbdd9EA== X-Google-Smtp-Source: ABdhPJxOs+KrOMBzm1PtqibNqPAyHuX/KtdN8YnEctUWbNqVoxYDrmjG4g9io4ZaTghBd8s2tUGjVA== X-Received: by 2002:a5d:6412:: with SMTP id z18mr5745236wru.214.1616005273801; Wed, 17 Mar 2021 11:21:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:13 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 04/19] fsck.c: rename variables in fsck_set_msg_type() for less confusion Date: Wed, 17 Mar 2021 19:20:39 +0100 Message-Id: <20210317182054.5986-5-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename variables in a function added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22). It was needlessly confusing that it took a "msg_type" argument, but then later declared another "msg_type" of a different type. Let's rename that to "severity", and rename "id" to "msg_id" and "msg_id" to "msg_id_str" etc. This will make a follow-up change smaller. While I'm at it properly indent the fsck_set_msg_type() argument list. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 24 ++++++++++++------------ fsck.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/fsck.c b/fsck.c index 5dfb99665a..7cc722a25c 100644 --- a/fsck.c +++ b/fsck.c @@ -203,27 +203,27 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type) } void fsck_set_msg_type(struct fsck_options *options, - const char *msg_id, const char *msg_type) + const char *msg_id_str, const char *msg_type_str) { - int id = parse_msg_id(msg_id), type; + int msg_id = parse_msg_id(msg_id_str), msg_type; - if (id < 0) - die("Unhandled message id: %s", msg_id); - type = parse_msg_type(msg_type); + if (msg_id < 0) + die("Unhandled message id: %s", msg_id_str); + msg_type = parse_msg_type(msg_type_str); - if (type != FSCK_ERROR && msg_id_info[id].msg_type == FSCK_FATAL) - die("Cannot demote %s to %s", msg_id, msg_type); + if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL) + die("Cannot demote %s to %s", msg_id_str, msg_type_str); if (!options->msg_type) { int i; - int *msg_type; - ALLOC_ARRAY(msg_type, FSCK_MSG_MAX); + int *severity; + ALLOC_ARRAY(severity, FSCK_MSG_MAX); for (i = 0; i < FSCK_MSG_MAX; i++) - msg_type[i] = fsck_msg_type(i, options); - options->msg_type = msg_type; + severity[i] = fsck_msg_type(i, options); + options->msg_type = severity; } - options->msg_type[id] = type; + options->msg_type[msg_id] = msg_type; } void fsck_set_msg_types(struct fsck_options *options, const char *values) diff --git a/fsck.h b/fsck.h index e3edaff8e7..12ff99b56e 100644 --- a/fsck.h +++ b/fsck.h @@ -11,7 +11,7 @@ struct fsck_options; struct object; void fsck_set_msg_type(struct fsck_options *options, - const char *msg_id, const char *msg_type); + const char *msg_id, const char *msg_type); void fsck_set_msg_types(struct fsck_options *options, const char *values); int is_valid_msg_type(const char *msg_id, const char *msg_type); From patchwork Wed Mar 17 18:20:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 117B2C4332D for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C066164F6A for ; Wed, 17 Mar 2021 18:21:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233055AbhCQSV1 (ORCPT ); Wed, 17 Mar 2021 14:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232950AbhCQSVQ (ORCPT ); Wed, 17 Mar 2021 14:21:16 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA97CC06175F for ; Wed, 17 Mar 2021 11:21:15 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id w203-20020a1c49d40000b029010c706d0642so5769562wma.0 for ; Wed, 17 Mar 2021 11:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mtIwibjrPTzGKWdE3IE2iHjmv2W1UPSv+r4i1zRSv6s=; b=LDTpHQ4/u+nEx2wbLZ56NOOQQA8zjxr294sdybnEyXv4F9aLYWeKKcETiU4zlfMXq5 wO50B8S29BuARzeiksyYdijTDxHdDzF12T00WCzuBObrIg82MP15l/fDVdOQPHiesGHt 7Y52HlkZqAiPHkw9FQgL5IUcRFyxzGWVe1tfOmHsGulhYULooy5dcCTBalWdG1cJlZ8L WayANGZzEg1SUyA8EDv/kefcXHaDII4DUD532Y2W6e81Id2bJg3J3Ajio9Nh+S4NGnjE bRQ6dJI/8ocxNE9XliT6t7693NX9JIFCNMwXwGlmPZalV3HbQ+1z2c2V430ZGuvvvfiR lr/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mtIwibjrPTzGKWdE3IE2iHjmv2W1UPSv+r4i1zRSv6s=; b=HeNzabbfp8JLyxa+eblXyaWkGvya0en3VrZftG/fd5vorm4DZv4+v0dr37DYqIELpK YIlcNBbaNaH6MfxnCIGREaCfbJD+jvYjxORDNrwlmbW2SY775MoUGUg+jBZ1ZXZoFF9O hLM7myFn2NcJ/4opOfjMqsCklTB+2do+/9+CkSkmEPGvJ1UMSYC9bqUm4chISVVt6QpF t5YEiFvY0R8qGOs2xLrfn6DDHUcn050vmEWgRDqCfOS2CmOBoD/Zudsn772UtNBLshcp YwXsfCScV2a+2k2BLyjXz/kNzjhhB49LHpSe56BMa3kmk1xLbYiw7b8A/4I9kStFwjkP DBzA== X-Gm-Message-State: AOAM533GgBtZh3FJ8eXfEQEvEoDe66BvVkt/+k6DQL6dr2QKAWPIiHfh k+OS7r1ga+5clLcH3/R6+T3J28D/LNUMZg== X-Google-Smtp-Source: ABdhPJz99yNU4RNpgxecF6rvrMO2RqHQxWShJovCQ2mgMW6jnjPM9scHj7frvAyIikYHjCQCvzetPQ== X-Received: by 2002:a05:600c:2053:: with SMTP id p19mr100050wmg.87.1616005274512; Wed, 17 Mar 2021 11:21:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 05/19] fsck.c: move definition of msg_id into append_msg_id() Date: Wed, 17 Mar 2021 19:20:40 +0100 Message-Id: <20210317182054.5986-6-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor code added in 71ab8fa840f (fsck: report the ID of the error/warning, 2015-06-22) to resolve the msg_id to a string in the function that wants it, instead of doing it in report(). Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fsck.c b/fsck.c index 7cc722a25c..ffb9115ddb 100644 --- a/fsck.c +++ b/fsck.c @@ -264,8 +264,9 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) free(to_free); } -static void append_msg_id(struct strbuf *sb, const char *msg_id) +static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id) { + const char *msg_id = msg_id_info[id].id_string; for (;;) { char c = *(msg_id)++; @@ -308,7 +309,7 @@ static int report(struct fsck_options *options, else if (msg_type == FSCK_INFO) msg_type = FSCK_WARN; - append_msg_id(&sb, msg_id_info[id].id_string); + append_msg_id(&sb, id); va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); From patchwork Wed Mar 17 18:20:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146703 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FA4AC43331 for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0645964F4F for ; Wed, 17 Mar 2021 18:21:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233074AbhCQSV2 (ORCPT ); Wed, 17 Mar 2021 14:21:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232951AbhCQSVR (ORCPT ); Wed, 17 Mar 2021 14:21:17 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4A6BC06174A for ; Wed, 17 Mar 2021 11:21:16 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id p19so2055456wmq.1 for ; Wed, 17 Mar 2021 11:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8AzMYsrTTeSkoMQVPos8db6WQ8cf7xhTQpaVmxgqEyM=; b=eMlzH6iujoeAkqdldiNgR6HjkDh2kz6Hj3ZssEZKEInuElwvNsho2yalfX08MNfnNF /zG8m6yJcFO8fwQKLC7tQXXRdcjERAnuRRtJjlL6eP6wQweGE3+mDEo8+dtFIz4uCHFc Jcb6AMKnlSxMNEi7Jg86Kq1quZW5FPyoh2uVY6ReQ9CirGWTt1yZ7vT7hcv3aEBhkpbb txO8Q7C6CuvjjBI1E8tNoXB9MOAwbr/4o3SS/oVmns8MfTsHgPxsD7iakGnn5J/qBqD5 t/JGKZHViXovG3V+sBa/IkO7MswsNSm8Ca4oKTQt95AwCA2ONeEyJm4MuBmMFMRmS/Cn wOZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8AzMYsrTTeSkoMQVPos8db6WQ8cf7xhTQpaVmxgqEyM=; b=iJ9DV2Efai5HEUfZNG+gPp+qYJYZ5L+arL25EguqqHDQ1M8UBMm3d/LLTEQRKrYhMw hx02QRC1ABOkyc3lewOpScBEbrMOiPos8rQPbr53ooc52YVx1MMONBEwwQ4Hp6s3RKjo LHPQTX+v+HL5VFllzlsUuPWR4fYYw9nM3AxZc5dQlCJRz/IPOg+IP1dXmGKKHS9oTE0h nJfuqXKobUkQMULZaNgywdk5DStA7+MC26FfEgGLbQ8WdrWrBAYOLHerazbTO5srKpLy RKz+oTN1QnmLx4AjjhDyfi6Wa3XgAJT6HFpAdHyFkfpTC5cBGGQ9nTT7bbQxHyhWA+tI bKoQ== X-Gm-Message-State: AOAM533/0DY8x9FXUMzWeqlIxtZpW7qOp3O1vqqn6lXv+zrY03DFatGI k26xQU8wsxV2Hzv0a+Ha1xZIF1s1amhV/w== X-Google-Smtp-Source: ABdhPJxBkHFxfzk04qlhrE6YQIzVcNiOxHmFuqWl/ap31Vvr00eX0SoZQCBrfX29fQi2aJ2676F5dA== X-Received: by 2002:a1c:9817:: with SMTP id a23mr107254wme.57.1616005275254; Wed, 17 Mar 2021 11:21:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 06/19] fsck.c: rename remaining fsck_msg_id "id" to "msg_id" Date: Wed, 17 Mar 2021 19:20:41 +0100 Message-Id: <20210317182054.5986-7-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the remaining variables of type fsck_msg_id from "id" to "msg_id". This change is relatively small, and is worth the churn for a later change where we have different id's in the "report" function. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fsck.c b/fsck.c index ffb9115ddb..a9a8783aeb 100644 --- a/fsck.c +++ b/fsck.c @@ -264,19 +264,19 @@ void fsck_set_msg_types(struct fsck_options *options, const char *values) free(to_free); } -static void append_msg_id(struct strbuf *sb, enum fsck_msg_id id) +static void append_msg_id(struct strbuf *sb, enum fsck_msg_id msg_id) { - const char *msg_id = msg_id_info[id].id_string; + const char *msg_id_str = msg_id_info[msg_id].id_string; for (;;) { - char c = *(msg_id)++; + char c = *(msg_id_str)++; if (!c) break; if (c != '_') strbuf_addch(sb, tolower(c)); else { - assert(*msg_id); - strbuf_addch(sb, *(msg_id)++); + assert(*msg_id_str); + strbuf_addch(sb, *(msg_id_str)++); } } @@ -292,11 +292,11 @@ static int object_on_skiplist(struct fsck_options *opts, __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 id, const char *fmt, ...) + enum fsck_msg_id msg_id, const char *fmt, ...) { va_list ap; struct strbuf sb = STRBUF_INIT; - int msg_type = fsck_msg_type(id, options), result; + int msg_type = fsck_msg_type(msg_id, options), result; if (msg_type == FSCK_IGNORE) return 0; @@ -309,7 +309,7 @@ static int report(struct fsck_options *options, else if (msg_type == FSCK_INFO) msg_type = FSCK_WARN; - append_msg_id(&sb, id); + append_msg_id(&sb, msg_id); va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); From patchwork Wed Mar 17 18:20:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B23CC43332 for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3501064F41 for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232137AbhCQSV3 (ORCPT ); Wed, 17 Mar 2021 14:21:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232982AbhCQSVS (ORCPT ); Wed, 17 Mar 2021 14:21:18 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A177AC06174A for ; Wed, 17 Mar 2021 11:21:17 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id y124-20020a1c32820000b029010c93864955so3940660wmy.5 for ; Wed, 17 Mar 2021 11:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jnJ3KDudFz8JR7MlAhUceLZ3oXaJi0ZT0ll69csfueg=; b=q+vInioQkFgtwNqrxEdAvkgQ5cGYKk6X9IyRnPdHRQLz31ezIqw/sAN+/0CoCX0NB7 POTpFoyNToDhila3Q+i0rWdT9F4PRwiWSOlmqX/xiXBvffZz4xE8+JzCSy9i8FTGeOQn Ib844d1CgKdoWxz0sbh03gzu7JS8crsgVq/jJBc0CPkvc2Bxa5K9h8ChAyfzFcO53YVR bVKbHY62RXPrPPYg+IwYuU8POX+n+F0oTuxrejnp6QHZfGRk1bB2L9KYHZuPO45VmswA 4RdXu0dcMV8CdqzpKqParvGePu907x3kBaddJ7D6TPJ9lvyu8amkAsEmDAh608+znSjP /L8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jnJ3KDudFz8JR7MlAhUceLZ3oXaJi0ZT0ll69csfueg=; b=nwM5yhnod6AbBpYd/Ey497CT0SkUGB4PCJMusrDtmip3wtvECrTzKPqMoyUYdLgxHN CXNtFpiWeU+YjeDuYYApyFSYGJ0Mh0r9HgfzTZiMMaxPcc4BrmemOxh/t14V8x5E5atH 6HcgiP/Dt0G1+BfU/plOS7k2m3cpL2g03VDQVn4jkkgkzDJnslvGsGMXKrJfuei9+aux NgPS1yj8cSJN97bFd6Q9k9+udNLH1EntQaWM+zszb1/pgQyh5XcPXG78aDBB35owRxnM imhcDVBtKWHqG5rpHmAtakIdHDkLBTRwobmpncjhEaQTOERy+RB4n/vIMVBVcMKJqzb8 kEIA== X-Gm-Message-State: AOAM533wwPa6gpJbtDZ/fV6joP/ns/VeIURqg7Rcy/Z7zUJFDpvX7awM Hf9jcHNxhTh72hPY566JSyvYgsps77M64A== X-Google-Smtp-Source: ABdhPJx6v5e9RnkctBjPdCYu9F13af3CdfXpWygHxoTbPCoPLfnk/fHng5YtO4yZ2I9MPkjE+Lt1uA== X-Received: by 2002:a7b:cb89:: with SMTP id m9mr112554wmi.27.1616005276138; Wed, 17 Mar 2021 11:21:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:15 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 07/19] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" Date: Wed, 17 Mar 2021 19:20:42 +0100 Message-Id: <20210317182054.5986-8-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor "if options->msg_type" and other code added in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) to reduce the scope of the "int msg_type" variable. This is in preparation for changing its type in a subsequent commit, only using it in the "!options->msg_type" scope makes that change This also brings the code in line with the fsck_set_msg_type() function (also added in 0282f4dced0), which does a similar check for "!options->msg_type". Another minor benefit is getting rid of the style violation of not having braces for the body of the "if". Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fsck.c b/fsck.c index a9a8783aeb..2f23255f99 100644 --- a/fsck.c +++ b/fsck.c @@ -167,19 +167,17 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix) static int fsck_msg_type(enum fsck_msg_id msg_id, struct fsck_options *options) { - int msg_type; - assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX); - if (options->msg_type) - msg_type = options->msg_type[msg_id]; - else { - msg_type = msg_id_info[msg_id].msg_type; + if (!options->msg_type) { + int msg_type = msg_id_info[msg_id].msg_type; + if (options->strict && msg_type == FSCK_WARN) msg_type = FSCK_ERROR; + return msg_type; } - return msg_type; + return options->msg_type[msg_id]; } static int parse_msg_type(const char *str) From patchwork Wed Mar 17 18:20:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 436B9C4332B for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F74564F50 for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233086AbhCQSVa (ORCPT ); Wed, 17 Mar 2021 14:21:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232988AbhCQSVS (ORCPT ); Wed, 17 Mar 2021 14:21:18 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68077C06175F for ; Wed, 17 Mar 2021 11:21:18 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id u5-20020a7bcb050000b029010e9316b9d5so1881041wmj.2 for ; Wed, 17 Mar 2021 11:21:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4C7ADjdpbdgf71g+hE/D35kRM6BR6yFjYamCwu+Hqto=; b=XpKRQ7JtHwJoPRf0xvzNxc74TDnmjNmqpdfJ8Xp9RNuguac0rMR0+lc0aiTOfBVc+J Z5l6MofTFDaiVgnZyTqoGzEiEc3gbU2v87TtwdAlbD4yQbG58xAc6med6jR/mWKHvJRJ dftR+9Q10eVn93GduJB4eKYzGalDgrz+bT5nksDOdLIWrzZLYFTj2kA0vSQpw3BeyTnI byxPuv+O7T00eUHtA0m46dALTh81xnwGFgQX4/9ciaW8VIrAgPXJKWDFGsII5jFPUmqc WQXpmySriTPP9thB0HZv4fqETCNDI0Bzjp5DAdUALkv9CZYWdR4cXCsQqGA4UDg3sWCm x+pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4C7ADjdpbdgf71g+hE/D35kRM6BR6yFjYamCwu+Hqto=; b=riUqZxyBpV7KkHTTgTZ/YtWFygLDeTniTVdeGc2FKAzhjz29IrrLLe/DYLMkohefOe D5APEH/hEXg8fuM2n9Kz9/WykyMx0OqlvFpB5DCylM7uDIg+62mdduz7aMg9C8xYLQwq rPgkLJ2cyPB3ufzSD48iGTvUVLycGbRDtM5q6wCfFn0Fqx7TkvBnkPz0YEyseOXeHyho CZGukCOnzDp30O2FRR+waiY2iWhMlwte5zJ/V2uu33Sh/Ir+YXCZsNDzFeTKPsOIldG5 1sjN8cMGYpzYFQQRR+F8SIa+VlmAp8OFli9BjjuKx+TROXg98d+BUcyof9EbZeJbD+t9 TV4A== X-Gm-Message-State: AOAM531G7RfROIg5P3ML6844QzSYZYyxPQm/DgIZywfnL9+1syjpZJBy TPLZhF9LaelEsHxkckS0dBxe92OxgNqr0g== X-Google-Smtp-Source: ABdhPJxgFgLBkFps3ZERktRbQup1/WnM7R8N/B8AwNiUuhsYpQ7zfXszSpG/7XLFOyKAlwgZFSBVlg== X-Received: by 2002:a1c:400b:: with SMTP id n11mr87719wma.167.1616005276895; Wed, 17 Mar 2021 11:21:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:16 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 08/19] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Date: Wed, 17 Mar 2021 19:20:43 +0100 Message-Id: <20210317182054.5986-9-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} defines into a new fsck_msg_type enum. These defines were originally introduced in: - ba002f3b28a (builtin-fsck: move common object checking code to fsck.c, 2008-02-25) - f50c4407305 (fsck: disallow demoting grave fsck errors to warnings, 2015-06-22) - efaba7cc77f (fsck: optionally ignore specific fsck issues completely, 2015-06-22) - f27d05b1704 (fsck: allow upgrading fsck warnings to errors, 2015-06-22) The reason these were defined in two different places is because we use FSCK_{IGNORE,INFO,FATAL} only in fsck.c, but FSCK_{ERROR,WARN} are used by external callbacks. Untangling that would take some more work, since we expose the new "enum fsck_msg_type" to both. Similar to "enum object_type" it's not worth structuring the API in such a way that only those who need FSCK_{ERROR,WARN} pass around a different type. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fsck.c | 2 +- builtin/index-pack.c | 3 ++- builtin/mktag.c | 3 ++- fsck.c | 21 ++++++++++----------- fsck.h | 16 ++++++++++------ 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index ed5f2af6b5..17940a4e24 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -84,7 +84,7 @@ static int objerror(struct object *obj, const char *err) static int fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - int msg_type, const char *message) + enum fsck_msg_type msg_type, const char *message) { switch (msg_type) { case FSCK_WARN: diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 69f24fe9f7..56b8efaa89 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1716,7 +1716,8 @@ static void show_pack_info(int stat_only) static int print_dangling_gitmodules(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - int msg_type, const char *message) + enum fsck_msg_type msg_type, + const char *message) { /* * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it diff --git a/builtin/mktag.c b/builtin/mktag.c index 23c4b8763f..052a510ad7 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -17,7 +17,8 @@ static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; static int mktag_fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - int msg_type, const char *message) + enum fsck_msg_type msg_type, + const char *message) { switch (msg_type) { case FSCK_WARN: diff --git a/fsck.c b/fsck.c index 2f23255f99..e1e942821d 100644 --- a/fsck.c +++ b/fsck.c @@ -22,9 +22,6 @@ static struct oidset gitmodules_found = OIDSET_INIT; static struct oidset gitmodules_done = OIDSET_INIT; -#define FSCK_FATAL -1 -#define FSCK_INFO -2 - #define FOREACH_MSG_ID(FUNC) \ /* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \ @@ -97,7 +94,7 @@ static struct { const char *id_string; const char *downcased; const char *camelcased; - int msg_type; + enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = { FOREACH_MSG_ID(MSG_ID) { NULL, NULL, NULL, -1 } @@ -164,13 +161,13 @@ void list_config_fsck_msg_ids(struct string_list *list, const char *prefix) list_config_item(list, prefix, msg_id_info[i].camelcased); } -static int fsck_msg_type(enum fsck_msg_id msg_id, +static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id, struct fsck_options *options) { assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX); if (!options->msg_type) { - int msg_type = msg_id_info[msg_id].msg_type; + enum fsck_msg_type msg_type = msg_id_info[msg_id].msg_type; if (options->strict && msg_type == FSCK_WARN) msg_type = FSCK_ERROR; @@ -180,7 +177,7 @@ static int fsck_msg_type(enum fsck_msg_id msg_id, return options->msg_type[msg_id]; } -static int parse_msg_type(const char *str) +static enum fsck_msg_type parse_msg_type(const char *str) { if (!strcmp(str, "error")) return FSCK_ERROR; @@ -203,7 +200,8 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type) void fsck_set_msg_type(struct fsck_options *options, const char *msg_id_str, const char *msg_type_str) { - int msg_id = parse_msg_id(msg_id_str), msg_type; + int msg_id = parse_msg_id(msg_id_str); + enum fsck_msg_type msg_type; if (msg_id < 0) die("Unhandled message id: %s", msg_id_str); @@ -214,7 +212,7 @@ void fsck_set_msg_type(struct fsck_options *options, if (!options->msg_type) { int i; - int *severity; + enum fsck_msg_type *severity; ALLOC_ARRAY(severity, FSCK_MSG_MAX); for (i = 0; i < FSCK_MSG_MAX; i++) severity[i] = fsck_msg_type(i, options); @@ -294,7 +292,8 @@ static int report(struct fsck_options *options, { va_list ap; struct strbuf sb = STRBUF_INIT; - int msg_type = fsck_msg_type(msg_id, options), result; + enum fsck_msg_type msg_type = fsck_msg_type(msg_id, options); + int result; if (msg_type == FSCK_IGNORE) return 0; @@ -1265,7 +1264,7 @@ int fsck_object(struct object *obj, void *data, unsigned long size, int fsck_error_function(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - int msg_type, const char *message) + enum fsck_msg_type msg_type, const char *message) { if (msg_type == FSCK_WARN) { warning("object %s: %s", fsck_describe_object(o, oid), message); diff --git a/fsck.h b/fsck.h index 12ff99b56e..0fff04373e 100644 --- a/fsck.h +++ b/fsck.h @@ -3,9 +3,13 @@ #include "oidset.h" -#define FSCK_ERROR 1 -#define FSCK_WARN 2 -#define FSCK_IGNORE 3 +enum fsck_msg_type { + FSCK_INFO = -2, + FSCK_FATAL = -1, + FSCK_ERROR = 1, + FSCK_WARN, + FSCK_IGNORE +}; struct fsck_options; struct object; @@ -29,17 +33,17 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type, /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error)(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - int msg_type, const char *message); + enum fsck_msg_type msg_type, const char *message); int fsck_error_function(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - int msg_type, const char *message); + enum fsck_msg_type msg_type, const char *message); struct fsck_options { fsck_walk_func walk; fsck_error error_func; unsigned strict:1; - int *msg_type; + enum fsck_msg_type *msg_type; struct oidset skiplist; kh_oid_map_t *object_names; }; From patchwork Wed Mar 17 18:20:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146707 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B1D1C432C3 for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DD0A64F5E for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233093AbhCQSVb (ORCPT ); Wed, 17 Mar 2021 14:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232977AbhCQSVT (ORCPT ); Wed, 17 Mar 2021 14:21:19 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4952DC061760 for ; Wed, 17 Mar 2021 11:21:19 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id u5-20020a7bcb050000b029010e9316b9d5so1881060wmj.2 for ; Wed, 17 Mar 2021 11:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hrhe2HTJZB5eFPococ6oZHMr2amKORBZgobAnkFyO/8=; b=Lm6GXR0uHf6oChGrgIZTz2IEFFtCRqh406FZBAsbwzLaWzjGMbi9jRiFiIpFfQmxf0 SO5QdB/YiI+E7DXgentSl+ZTDuB5at6PHbr+E3po6beY0Xp080KOFlMTA92plmG15wdV xvAQpVgZjWsgJdC1SK0AX4N6TcLWPtoqKa5a6lSW3DBFsbDKEd+bQFlZrY2zET2Ag6SK ZbC7l6Qtzm+KmckU0ogHurEyd50ORaXSoP1DPi+DrYQHgKxp+VBOB6JHVDU3a/8aK8Yn oBqDa6Gbtzrk5rVTF3paCTrRa+zu7cbg3LRQ35hzf1/sUs/NHrVFsL4s8xOwA5xmvZo3 S5ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hrhe2HTJZB5eFPococ6oZHMr2amKORBZgobAnkFyO/8=; b=UD/iP2zn0mIbHZBWcCFPpwOAWCXCyYDa1pcrbDZZB7o9LMZY4JTkCxgo8gwOoSOJzn weRqrM/7w/qjPRZ/DsbwmhvhLte2PRQNLvcK7Mahx6M+LuLTKebFdtiL6KwUKhYA6+YY RGr7gM4kNn4/2pfg3VUCW9yQ4LUoNIyNj4tyqQE5WbpjhWR9UIdx0Rq4e73vmQh+8LFz 8BH7Eiz06r97qiFZ3KNBwk2c7pmXsix02T3aNHXCiTw/xDD0OgJXUiJJUZW0APOLakpM W5gq9wbgiNGTAf6gR7wi2rYqLhmwLXc2nwHEgKhCRw0RThuY9RymL7hJ6WbqJBC8b3kB pfMg== X-Gm-Message-State: AOAM532yWfew+Ifwv1JuIDwBvY/TbhEoY1uYz+saPZXOG7l7sEJ3bgZE 70FKrtCZgv14myxGBSOhLOpb/9oORXlHjQ== X-Google-Smtp-Source: ABdhPJxC02DRMhyzEwbBOsekDiC73SyyRuecceU1Y+33Yj25uCiveZaClWtydZZUdkV34uHZI6I3rQ== X-Received: by 2002:a1c:f702:: with SMTP id v2mr91030wmh.131.1616005277851; Wed, 17 Mar 2021 11:21:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:17 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 09/19] fsck.h: re-order and re-assign "enum fsck_msg_type" Date: Wed, 17 Mar 2021 19:20:44 +0100 Message-Id: <20210317182054.5986-10-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the values in the "enum fsck_msg_type" from being manually assigned to using default C enum values. This means we end up with a FSCK_IGNORE=0, which was previously defined as "2". I'm confident that nothing relies on these values, we always compare them explicitly. Let's not omit "0" so it won't be assumed that we're using these as a boolean somewhere. This also allows us to re-structure the fields to mark which are "private" v.s. "public". See the preceding commit for a rationale for not simply splitting these into two enums, namely that this is used for both the private and public fsck API. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fsck.h b/fsck.h index 0fff04373e..25c456bbd3 100644 --- a/fsck.h +++ b/fsck.h @@ -4,11 +4,13 @@ #include "oidset.h" enum fsck_msg_type { - FSCK_INFO = -2, - FSCK_FATAL = -1, - FSCK_ERROR = 1, + /* for internal use only */ + FSCK_IGNORE, + FSCK_INFO, + FSCK_FATAL, + /* "public", fed to e.g. error_func callbacks */ + FSCK_ERROR, FSCK_WARN, - FSCK_IGNORE }; struct fsck_options; From patchwork Wed Mar 17 18:20:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EAE9C43333 for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6999164F4F for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233089AbhCQSVa (ORCPT ); Wed, 17 Mar 2021 14:21:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232956AbhCQSVU (ORCPT ); Wed, 17 Mar 2021 14:21:20 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F214C06174A for ; Wed, 17 Mar 2021 11:21:20 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id f22-20020a7bc8d60000b029010c024a1407so3954405wml.2 for ; Wed, 17 Mar 2021 11:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uNxKQn4LWflJp3zVbUeKRR8PJHBq91o4KntAb3/Y7Rc=; b=HciKWEf5eZ96DVuBQsuIbvhOZwxlgJDaj3BdujAzDWod0dmypsHnlabNXIGAV75N6e faoiWr305dIEGtWN975Z6uP1Wx7W7RZ+b/KwToKq8coXJEN5Fn3jw890lZO+HKSFD8tn M12xji4tpUpofDI+KbMbvax5ITcA7LaR86nfNHEW8r8h+jFZNCOvZwCbAR1WEvkcnaAE JJaI5JnGRew9lR3XGhWUbPTjQW9UP+2KcER5oC2uyUBa5rxZvXesqnUgzWfqJncXgSBN u7B2aUWiKYzv2J+1EcM6qS52ToN5+aUVyif9OhWAmuJtRLYNRSW2kN8A65EsFillgO6h EwLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uNxKQn4LWflJp3zVbUeKRR8PJHBq91o4KntAb3/Y7Rc=; b=lG789RdheVrqO3zrfBZo+araikzrD6WZzNKsPlKrJorf6iGwGfL3qy6ISWHTOMLC6N 0dQGyGtn0+64oD/ZwvDCw52YXkd5fuy5w54qJltWhWcwbPEH7WoN5k1kMrzbTowca3xc E9S16sgruCfvpl7Z4Gt9LlSM9FKtDsDpo1+iTbUVQEu6JN0aMNgTgNjLJoFBRWanX0KZ wGm6BpSsgaNSbgUIrDPp+YEuOzQzgqRgnIPpWcPO0JZ18an1+/8hFWpWTR0i6UGLInvD HBlKcyePrrs+TX5T0utdxwP7eUrr+h2miqvdamCLmH/xWl8QXrZt7miAqw98BiNLtrQn lpmg== X-Gm-Message-State: AOAM533ui0Z8K1yYDzWQrXH3aMwNhYlRuDUnzGTvsM3d67Xex9jAGI/c ine/9zp/l+KOQOVPOIWSI3/hw/cwmpG+ZQ== X-Google-Smtp-Source: ABdhPJyEJ5yYHiGVQcEtwr0POsU+69Zg6U4zVwXhzeJbKGmNgjCiW2fYqPaifu1w0nJzdlkQkqVnIQ== X-Received: by 2002:a1c:8005:: with SMTP id b5mr128836wmd.130.1616005278572; Wed, 17 Mar 2021 11:21:18 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:18 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 10/19] fsck.c: call parse_msg_type() early in fsck_set_msg_type() Date: Wed, 17 Mar 2021 19:20:45 +0100 Message-Id: <20210317182054.5986-11-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There's no reason to defer the calling of parse_msg_type() until after we've checked if the "id < 0". This is not a hot codepath, and parse_msg_type() itself may die on invalid input. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fsck.c b/fsck.c index e1e942821d..341c482fed 100644 --- a/fsck.c +++ b/fsck.c @@ -201,11 +201,10 @@ void fsck_set_msg_type(struct fsck_options *options, const char *msg_id_str, const char *msg_type_str) { int msg_id = parse_msg_id(msg_id_str); - enum fsck_msg_type msg_type; + enum fsck_msg_type msg_type = parse_msg_type(msg_type_str); if (msg_id < 0) die("Unhandled message id: %s", msg_id_str); - msg_type = parse_msg_type(msg_type_str); if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL) die("Cannot demote %s to %s", msg_id_str, msg_type_str); From patchwork Wed Mar 17 18:20:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2023C4321A for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A700664F7E for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233075AbhCQSVb (ORCPT ); Wed, 17 Mar 2021 14:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232993AbhCQSVV (ORCPT ); Wed, 17 Mar 2021 14:21:21 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB8E9C06175F for ; Wed, 17 Mar 2021 11:21:20 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so1874900wmi.3 for ; Wed, 17 Mar 2021 11:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SAHTG+EgpxZAlDX3vxSLrH9AscZjXYwixsTgbzS0E/M=; b=E1I43TJ4SE0vNkXLlu+eUhxLjp/oVBHdt53DabtdbPdaZ+hSEhoiqWnp78KEC50PWc TSQEWm+pV3SP6nIsYcShGkzAKyzi1MyM5TBRgXycXLKHX5BI2kLd5KqzfnllhTOU0zhY dl61lzdSScR0ZBMn/VbGAH913xfclCNOWV5JVbWM8HhjOb6252Mu4CUVVN68Bq8czuJK 8EoUA1alfH08sN8EuCqaYuWxoL3YK4sSOVRCRDLUABDvVewX0o9nrmoHCO73m4+ic8NM xdhtc1ydTVOhguK1j3M5e8s7ngXgBbAUVQ6fr7z/MYg3LeIdZ/2poxuJeq/YWTgDaSQe wnuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SAHTG+EgpxZAlDX3vxSLrH9AscZjXYwixsTgbzS0E/M=; b=U3yRyhFAI/3tfFZOJSVwF9mUntIlhHY015oa83xHdytU8ksBLi+HVsa3+VV9v5b1cx IVlC6J5VwRj+k8AFI1nxaamN3qcyTcYHx3Z0YoKTnMK2imHYDRocy7h2pyZuEszityuH lcUBp60a6yWLixB/422hkJNtGnCIRckxBW7b2TN4eN1v5UHaWxd6LypYEV8pOoGd0M4s 3+oIJFElqWl+CRFnNWMYGBDkMuxGhaG73zEinA9lvBhXusf/o9xi4mxmkIuVPni81XQO D3uZ40oZ0mFn62y9Fh2tjAfzCPgGIa7WNx1AHhO8EDT7V3NdTjckY8U+Jy9EIeXcZ8ho iTjQ== X-Gm-Message-State: AOAM530hb/K0+RapJszwmvu9rnQ/GA7BUDfyeXp6P0mijYgck9CXHqow JuLqVltBmCpGL+FD20lGZpHY5l64TzBwMw== X-Google-Smtp-Source: ABdhPJwc4t1khj1e2spk7mfnq/sfm4xVzHEL0FH0SD1Kcs4AxX0byfUrJAa4B9Rzcp9dlJ/kSJzuUg== X-Received: by 2002:a1c:b006:: with SMTP id z6mr110297wme.19.1616005279360; Wed, 17 Mar 2021 11:21:19 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:18 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 11/19] fsck.c: undefine temporary STR macro after use Date: Wed, 17 Mar 2021 19:20:46 +0100 Message-Id: <20210317182054.5986-12-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In f417eed8cde (fsck: provide a function to parse fsck message IDs, 2015-06-22) the "STR" macro was introduced, but that short macro name was not undefined after use as was done earlier in the same series for the MSG_ID macro in c99ba492f1c (fsck: introduce identifiers for fsck messages, 2015-06-22). Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fsck.c b/fsck.c index 341c482fed..e657636a6f 100644 --- a/fsck.c +++ b/fsck.c @@ -100,6 +100,7 @@ static struct { { NULL, NULL, NULL, -1 } }; #undef MSG_ID +#undef STR static void prepare_msg_ids(void) { From patchwork Wed Mar 17 18:20:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA2D0C43603 for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8AB2A64F73 for ; Wed, 17 Mar 2021 18:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233100AbhCQSVc (ORCPT ); Wed, 17 Mar 2021 14:21:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233001AbhCQSVV (ORCPT ); Wed, 17 Mar 2021 14:21:21 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F2ACC06174A for ; Wed, 17 Mar 2021 11:21:21 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id r10-20020a05600c35cab029010c946c95easo1872027wmq.4 for ; Wed, 17 Mar 2021 11:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3Yn7ZE5LnR/l8/KqJi2HPu78wVassmxwUo2jdgWO2sc=; b=OEuPQWo5BKSlfypX/IrTAtobo3erkSyUQqS8uORLASbF/s3h70ev6uailGO1SDI6dT SfgoLlOJASZm00qdso9bb70FmaMiSMVMJgQEKhnJdj548C8+pv6gNaA7p+YcRQkc9XFN z0znsnRR6CdGnZh98x/v12+NKQDv7K7EjrxOPB2Wr9+dgg1mRIIlDMDj4WnyC9zPg+7G iSvxbP2Z5GN9/YNGYgC/aur4SA5atCwToxeNYjczEAzV+TGWWUQu4PtYdVwOqzX49d6L o00YlIIdm9mZMRnNJiAbpSWFZN8Pi3VtszsdyuSevnA/kjhnAluy2ca05E0oHP7q258p zGUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3Yn7ZE5LnR/l8/KqJi2HPu78wVassmxwUo2jdgWO2sc=; b=FZ4Et9l/T7CnpR/Z49LURm0NqMO9xy665qyTdf7iKDKLIhIxfUaVeaWzX9ZkT6Vfsx w0IqTvG3qnOl8B5+A5peq57AYORPvu56skJzzmxDDEt7PXfjKY2v2bUZxT/ce1UOanpu 3yLO2zvvJJhsP5GCqowX7PB+KL2EXdp1weXSLc86J0NqVHOM/DDvpvG6gvZuA0EWAdUA qSsBeWj5LDjsH5HaeK6WqVB8dc9Le4VDEVS9bhdTiBXwo3Wg2BYbu3IB/BMyPQw1xMqL sIqiKxqCNA4m59kJWPZmDMpFICNqaEcm5x0KYlxC6U97sscZjl3dr5/tcrgr7Iwn11MB dErQ== X-Gm-Message-State: AOAM533MHttfP00yTijpTGHBSJx1w8a6FXNsJw/7bbUdnjoN+juSbn8d vmnJdDMh+DGL36/olftG553nrqPiCbFb1A== X-Google-Smtp-Source: ABdhPJyojEnxlzuWeFllvawNEL+QWtgCIXhKPATMKWnAJnylwmFjuCMlJ5/orJ3D9zkVEoRsnn5sGA== X-Received: by 2002:a05:600c:4151:: with SMTP id h17mr142584wmm.68.1616005280139; Wed, 17 Mar 2021 11:21:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:19 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 12/19] fsck.c: give "FOREACH_MSG_ID" a more specific name Date: Wed, 17 Mar 2021 19:20:47 +0100 Message-Id: <20210317182054.5986-13-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the FOREACH_MSG_ID macro to FOREACH_FSCK_MSG_ID in preparation for moving it over to fsck.h. It's good convention to name macros in *.h files in such a way as to clearly not clash with any other names in other files. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fsck.c b/fsck.c index e657636a6f..b64526ea35 100644 --- a/fsck.c +++ b/fsck.c @@ -22,7 +22,7 @@ static struct oidset gitmodules_found = OIDSET_INIT; static struct oidset gitmodules_done = OIDSET_INIT; -#define FOREACH_MSG_ID(FUNC) \ +#define FOREACH_FSCK_MSG_ID(FUNC) \ /* fatal errors */ \ FUNC(NUL_IN_HEADER, FATAL) \ FUNC(UNTERMINATED_HEADER, FATAL) \ @@ -83,7 +83,7 @@ static struct oidset gitmodules_done = OIDSET_INIT; #define MSG_ID(id, msg_type) FSCK_MSG_##id, enum fsck_msg_id { - FOREACH_MSG_ID(MSG_ID) + FOREACH_FSCK_MSG_ID(MSG_ID) FSCK_MSG_MAX }; #undef MSG_ID @@ -96,7 +96,7 @@ static struct { const char *camelcased; enum fsck_msg_type msg_type; } msg_id_info[FSCK_MSG_MAX + 1] = { - FOREACH_MSG_ID(MSG_ID) + FOREACH_FSCK_MSG_ID(MSG_ID) { NULL, NULL, NULL, -1 } }; #undef MSG_ID From patchwork Wed Mar 17 18:20:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UPPERCASE_50_75,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9375DC433E0 for ; Wed, 17 Mar 2021 18:22:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D4EA64F3B for ; Wed, 17 Mar 2021 18:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232600AbhCQSVz (ORCPT ); Wed, 17 Mar 2021 14:21:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232763AbhCQSVW (ORCPT ); Wed, 17 Mar 2021 14:21:22 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B49DC06174A for ; Wed, 17 Mar 2021 11:21:22 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id j18so2834209wra.2 for ; Wed, 17 Mar 2021 11:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UH1WJ+qdg2KSq2/MhZ8gfhLaVf5mTg3uZPIoqOb3gp4=; b=jKBdkRBsZzi55LXTf/24FSJ+969mp+aIZ9QA5cc5euosayMMMflJ2SoiHR1+gd02vq crQwc6T8gowSN3cFbaOXHxDdz+c411sTaG0DvPH6zjfYHz0sWwHjzCbN7RsKWoXp/SQs 87CxkKFF9uMLvlx/QjDJEYbPxnjJPxowXz+FbRRNSLwCsm+aPazm5aavCp7xsH5dENUl lQXglOgr/MTKs+3ca09Sinlr8oumDBhU5S5a41KpS+YBg/6z66dr6zlE42Ctpy1CDnJX Usi1jU67p1ZVwrkh2mVIJy6p94hedvii7SZMm6QMae0PiUfqC5phFKuSVL1jsUVmZQhU RpyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UH1WJ+qdg2KSq2/MhZ8gfhLaVf5mTg3uZPIoqOb3gp4=; b=tKOU7gl067bpQY9PPRsgolE06moue81NE3AUnYFS5aC8TWkr5DouGXW1bsE1yk+k5d sfK+becxYKUnkseqhjEhk2b2F/o3Fz/+jK97VgVyRzpGsKFzSLovBh68y1boM/dH08jd ofnH1kC9GkrbNPSuOHI3TvfwkD/9jFoX/SIiOSdZ/AlI0PDZsVjEXchT92fHn4Q5yq2+ cRYgWNbuRjgsbYrOuOzdGHfSMws2mvVZ27YED/i1NgRNppF1g9kHs58i2/0Z6e6oFNuq TkIVLgwGc4YIoFOXbHFb0MIk6cIZ3ThgJDleoyQo79yZzDISCS0eT6etJL3E98PYBFWm o28w== X-Gm-Message-State: AOAM530IcQgbcKN3mksXmzHJbhcilKpHEGBWbjlApRFUmJA7sSkjHHVf HuFR3ISPQOzFRaeQfAkzigqotgBhtaxNCg== X-Google-Smtp-Source: ABdhPJwb48kJw0uwMqQS3cd5ru1XNxR44CNxHFGcUZObLXJRnvmveI4dC7KIGAL89QzBuB3W49dWtw== X-Received: by 2002:a05:6000:1363:: with SMTP id q3mr5781429wrz.74.1616005280814; Wed, 17 Mar 2021 11:21:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:20 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 13/19] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h Date: Wed, 17 Mar 2021 19:20:48 +0100 Message-Id: <20210317182054.5986-14-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the FOREACH_FSCK_MSG_ID macro and the fsck_msg_id enum it helps define from fsck.c to fsck.h. This is in preparation for having non-static functions take the fsck_msg_id as an argument. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 66 ---------------------------------------------------------- fsck.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/fsck.c b/fsck.c index b64526ea35..49208ec636 100644 --- a/fsck.c +++ b/fsck.c @@ -22,72 +22,6 @@ static struct oidset gitmodules_found = OIDSET_INIT; static struct oidset gitmodules_done = OIDSET_INIT; -#define FOREACH_FSCK_MSG_ID(FUNC) \ - /* fatal errors */ \ - FUNC(NUL_IN_HEADER, FATAL) \ - FUNC(UNTERMINATED_HEADER, FATAL) \ - /* errors */ \ - FUNC(BAD_DATE, ERROR) \ - FUNC(BAD_DATE_OVERFLOW, ERROR) \ - FUNC(BAD_EMAIL, ERROR) \ - FUNC(BAD_NAME, ERROR) \ - FUNC(BAD_OBJECT_SHA1, ERROR) \ - FUNC(BAD_PARENT_SHA1, ERROR) \ - FUNC(BAD_TAG_OBJECT, ERROR) \ - FUNC(BAD_TIMEZONE, ERROR) \ - FUNC(BAD_TREE, ERROR) \ - FUNC(BAD_TREE_SHA1, ERROR) \ - FUNC(BAD_TYPE, ERROR) \ - FUNC(DUPLICATE_ENTRIES, ERROR) \ - FUNC(MISSING_AUTHOR, ERROR) \ - FUNC(MISSING_COMMITTER, ERROR) \ - FUNC(MISSING_EMAIL, ERROR) \ - FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \ - FUNC(MISSING_OBJECT, ERROR) \ - FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \ - FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \ - FUNC(MISSING_TAG, ERROR) \ - FUNC(MISSING_TAG_ENTRY, ERROR) \ - FUNC(MISSING_TREE, ERROR) \ - FUNC(MISSING_TREE_OBJECT, ERROR) \ - FUNC(MISSING_TYPE, ERROR) \ - FUNC(MISSING_TYPE_ENTRY, ERROR) \ - FUNC(MULTIPLE_AUTHORS, ERROR) \ - FUNC(TREE_NOT_SORTED, ERROR) \ - FUNC(UNKNOWN_TYPE, ERROR) \ - FUNC(ZERO_PADDED_DATE, ERROR) \ - FUNC(GITMODULES_MISSING, ERROR) \ - FUNC(GITMODULES_BLOB, ERROR) \ - FUNC(GITMODULES_LARGE, ERROR) \ - FUNC(GITMODULES_NAME, ERROR) \ - FUNC(GITMODULES_SYMLINK, ERROR) \ - FUNC(GITMODULES_URL, ERROR) \ - FUNC(GITMODULES_PATH, ERROR) \ - FUNC(GITMODULES_UPDATE, ERROR) \ - /* warnings */ \ - FUNC(BAD_FILEMODE, WARN) \ - FUNC(EMPTY_NAME, WARN) \ - FUNC(FULL_PATHNAME, WARN) \ - FUNC(HAS_DOT, WARN) \ - FUNC(HAS_DOTDOT, WARN) \ - FUNC(HAS_DOTGIT, WARN) \ - FUNC(NULL_SHA1, WARN) \ - FUNC(ZERO_PADDED_FILEMODE, WARN) \ - FUNC(NUL_IN_COMMIT, WARN) \ - /* infos (reported as warnings, but ignored by default) */ \ - FUNC(GITMODULES_PARSE, INFO) \ - FUNC(BAD_TAG_NAME, INFO) \ - FUNC(MISSING_TAGGER_ENTRY, INFO) \ - /* ignored (elevated when requested) */ \ - FUNC(EXTRA_HEADER_ENTRY, IGNORE) - -#define MSG_ID(id, msg_type) FSCK_MSG_##id, -enum fsck_msg_id { - FOREACH_FSCK_MSG_ID(MSG_ID) - FSCK_MSG_MAX -}; -#undef MSG_ID - #define STR(x) #x #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, static struct { diff --git a/fsck.h b/fsck.h index 25c456bbd3..7c868410eb 100644 --- a/fsck.h +++ b/fsck.h @@ -13,6 +13,72 @@ enum fsck_msg_type { FSCK_WARN, }; +#define FOREACH_FSCK_MSG_ID(FUNC) \ + /* fatal errors */ \ + FUNC(NUL_IN_HEADER, FATAL) \ + FUNC(UNTERMINATED_HEADER, FATAL) \ + /* errors */ \ + FUNC(BAD_DATE, ERROR) \ + FUNC(BAD_DATE_OVERFLOW, ERROR) \ + FUNC(BAD_EMAIL, ERROR) \ + FUNC(BAD_NAME, ERROR) \ + FUNC(BAD_OBJECT_SHA1, ERROR) \ + FUNC(BAD_PARENT_SHA1, ERROR) \ + FUNC(BAD_TAG_OBJECT, ERROR) \ + FUNC(BAD_TIMEZONE, ERROR) \ + FUNC(BAD_TREE, ERROR) \ + FUNC(BAD_TREE_SHA1, ERROR) \ + FUNC(BAD_TYPE, ERROR) \ + FUNC(DUPLICATE_ENTRIES, ERROR) \ + FUNC(MISSING_AUTHOR, ERROR) \ + FUNC(MISSING_COMMITTER, ERROR) \ + FUNC(MISSING_EMAIL, ERROR) \ + FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \ + FUNC(MISSING_OBJECT, ERROR) \ + FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \ + FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \ + FUNC(MISSING_TAG, ERROR) \ + FUNC(MISSING_TAG_ENTRY, ERROR) \ + FUNC(MISSING_TREE, ERROR) \ + FUNC(MISSING_TREE_OBJECT, ERROR) \ + FUNC(MISSING_TYPE, ERROR) \ + FUNC(MISSING_TYPE_ENTRY, ERROR) \ + FUNC(MULTIPLE_AUTHORS, ERROR) \ + FUNC(TREE_NOT_SORTED, ERROR) \ + FUNC(UNKNOWN_TYPE, ERROR) \ + FUNC(ZERO_PADDED_DATE, ERROR) \ + FUNC(GITMODULES_MISSING, ERROR) \ + FUNC(GITMODULES_BLOB, ERROR) \ + FUNC(GITMODULES_LARGE, ERROR) \ + FUNC(GITMODULES_NAME, ERROR) \ + FUNC(GITMODULES_SYMLINK, ERROR) \ + FUNC(GITMODULES_URL, ERROR) \ + FUNC(GITMODULES_PATH, ERROR) \ + FUNC(GITMODULES_UPDATE, ERROR) \ + /* warnings */ \ + FUNC(BAD_FILEMODE, WARN) \ + FUNC(EMPTY_NAME, WARN) \ + FUNC(FULL_PATHNAME, WARN) \ + FUNC(HAS_DOT, WARN) \ + FUNC(HAS_DOTDOT, WARN) \ + FUNC(HAS_DOTGIT, WARN) \ + FUNC(NULL_SHA1, WARN) \ + FUNC(ZERO_PADDED_FILEMODE, WARN) \ + FUNC(NUL_IN_COMMIT, WARN) \ + /* infos (reported as warnings, but ignored by default) */ \ + FUNC(GITMODULES_PARSE, INFO) \ + FUNC(BAD_TAG_NAME, INFO) \ + FUNC(MISSING_TAGGER_ENTRY, INFO) \ + /* ignored (elevated when requested) */ \ + FUNC(EXTRA_HEADER_ENTRY, IGNORE) + +#define MSG_ID(id, msg_type) FSCK_MSG_##id, +enum fsck_msg_id { + FOREACH_FSCK_MSG_ID(MSG_ID) + FSCK_MSG_MAX +}; +#undef MSG_ID + struct fsck_options; struct object; From patchwork Wed Mar 17 18:20:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E14E6C433E6 for ; Wed, 17 Mar 2021 18:22:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C3BD64F4F for ; Wed, 17 Mar 2021 18:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233005AbhCQSV4 (ORCPT ); Wed, 17 Mar 2021 14:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233025AbhCQSVX (ORCPT ); Wed, 17 Mar 2021 14:21:23 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B78BC06174A for ; Wed, 17 Mar 2021 11:21:23 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id g8so2041598wmd.4 for ; Wed, 17 Mar 2021 11:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5/uzG+2biayW9Qu6KLJ09jWl488ZuuVJRpzwFNTW9Dk=; b=M7oQuQCnjJOrZB7xmBAZZCgbR2iTwCIlDC0Pl600QEDerriXscBOLToPrh2B5+JpTy e1zjjyQPEd+Z76J1/aKViwzAJvYcRihXEaPsTRr92zhn+TVALPqNAkzCuONKy8v8P0uz wehm9lXXKPYSHqiaQf7x5MI/8zJkqSL7mbBgCzIvHLNjtJbH2JB5gPNrEdilZFEIRdtf INmCT6Zp3FhyJ5N1XBMNIAe07AIbn34GfZibRQUzEKhGoNBtBxEoZDlhD+7QNzW02Tvv 2cU7y5OSu9ClNoctZu2PLDDqxL+5Rtd85gw7r7FzB/yIdnaFZJSKkYwvHe3Tbpwdp6MJ dImQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5/uzG+2biayW9Qu6KLJ09jWl488ZuuVJRpzwFNTW9Dk=; b=XmoHN+WC7bT4oUsJLkCoEgllFtrAQfOKBGuc4Mu5oZH8p+048cbBo0XS7RIz3iT8vt q9B9LMWs7XcVAoVFJeCcMh4+l+giQjxDO1vuwKRhNnKHq9mV0Y97f6xf1QLF4pTO433u Vhhumdudr9IwYV3QXIInYATedpdHResmj6n49g53XYs0xfYvawFfD7amL7MDXfP8sAZz QUrL6T2vnaS3YRCJ1gBnzbzQ3PRwhMMmeXm9rBB8MXUfKDK24MF6cexH73IDthCPgPUc rx7hihKQcfVC6YO7ENFSWYfrNQen29HOPAt3riK443eWnLQUtL9MjX4QySDqWHI33qIL DhNA== X-Gm-Message-State: AOAM532mx/WBlrsQMgBnSU8on/qFMer6AwDLDJ3W3moDLu8IUH6DziaL y7UNKbQYAli8OnhuRj4VSv93iBDsJsOmPg== X-Google-Smtp-Source: ABdhPJwvv02Y1WoYGO5X97AKeLcgTHDSanBjttd+d1yNJzsfIAgT/QpljmLehIXt+K/YN1U3k4aY7Q== X-Received: by 2002:a1c:9d8b:: with SMTP id g133mr89490wme.161.1616005281650; Wed, 17 Mar 2021 11:21:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:21 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 14/19] fsck.c: pass along the fsck_msg_id in the fsck_error callback Date: Wed, 17 Mar 2021 19:20:49 +0100 Message-Id: <20210317182054.5986-15-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the fsck_error callback to also pass along the fsck_msg_id. Before this change the only way to get the message id was to parse it back out of the "message". Let's pass it down explicitly for the benefit of callers that might want to use it, as discussed in [1]. Passing the msg_type is now redundant, as you can always get it back from the msg_id, but I'm not changing that convention. It's really common to need the msg_type, and the report() function itself (which calls "fsck_error") needs to call fsck_msg_type() to discover it. Let's not needlessly re-do that work in the user callback. 1. https://lore.kernel.org/git/87blcja2ha.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fsck.c | 4 +++- builtin/index-pack.c | 3 ++- builtin/mktag.c | 1 + fsck.c | 6 ++++-- fsck.h | 6 ++++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 17940a4e24..70ff95837a 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -84,7 +84,9 @@ static int objerror(struct object *obj, const char *err) static int fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - enum fsck_msg_type msg_type, const char *message) + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message) { switch (msg_type) { case FSCK_WARN: diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 56b8efaa89..2b2266a4b7 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1717,6 +1717,7 @@ static int print_dangling_gitmodules(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, const char *message) { /* @@ -1727,7 +1728,7 @@ static int print_dangling_gitmodules(struct fsck_options *o, printf("%s\n", oid_to_hex(oid)); return 0; } - return fsck_error_function(o, oid, object_type, msg_type, message); + return fsck_error_function(o, oid, object_type, msg_type, msg_id, message); } int cmd_index_pack(int argc, const char **argv, const char *prefix) diff --git a/builtin/mktag.c b/builtin/mktag.c index 052a510ad7..96e63bc772 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -18,6 +18,7 @@ static int mktag_fsck_error_func(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, const char *message) { switch (msg_type) { diff --git a/fsck.c b/fsck.c index 49208ec636..01b2724ac0 100644 --- a/fsck.c +++ b/fsck.c @@ -245,7 +245,7 @@ static int report(struct fsck_options *options, va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); result = options->error_func(options, oid, object_type, - msg_type, sb.buf); + msg_type, msg_id, sb.buf); strbuf_release(&sb); va_end(ap); @@ -1198,7 +1198,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size, int fsck_error_function(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - enum fsck_msg_type msg_type, const char *message) + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message) { if (msg_type == FSCK_WARN) { warning("object %s: %s", fsck_describe_object(o, oid), message); diff --git a/fsck.h b/fsck.h index 7c868410eb..80b1984f34 100644 --- a/fsck.h +++ b/fsck.h @@ -101,11 +101,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type, /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */ typedef int (*fsck_error)(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - enum fsck_msg_type msg_type, const char *message); + enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, + const char *message); int fsck_error_function(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, - enum fsck_msg_type msg_type, const char *message); + enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, + const char *message); struct fsck_options { fsck_walk_func walk; From patchwork Wed Mar 17 18:20:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06675C43381 for ; Wed, 17 Mar 2021 18:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB54564F50 for ; Wed, 17 Mar 2021 18:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233111AbhCQSV5 (ORCPT ); Wed, 17 Mar 2021 14:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232979AbhCQSVY (ORCPT ); Wed, 17 Mar 2021 14:21:24 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE5CCC06175F for ; Wed, 17 Mar 2021 11:21:23 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id o16so2853272wrn.0 for ; Wed, 17 Mar 2021 11:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vo6qKEfgTN4WCdQ/POanr/8yE9eXgo9vYyLOSdibKJE=; b=dRSwWtEqYMoxeoYQHk8ZTWakrJrdC3WPNJyuws3Fn+K+IIZnLzeal5iPo9C9Jxb0FE t/OwH7HPZTjcsZWcLS3vSKqjNoHJ8Gec9f38RUfOjP8HxFSy59Pgei0uQ7EfMTDP9dFE 7rfm5zmTnPGD5p1FRZcY9JF9Q5BgJvQ6tbMYA+sfEnK8sUCGoW4IPFF9T4E9fW3z+L+F fxfUjBZOk9r8Aj759X5FLILg0J0OeoGe4lYFsMyUO/QYWXL+gjIFRtUN4wE8WGT7+O2i lVf28NvXRMd2ia6JW2RdYl9nTLvL8mrzRThhIWIHvjhbCAqb3Kup1EO/zphtAu2i/p1U 9Nhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vo6qKEfgTN4WCdQ/POanr/8yE9eXgo9vYyLOSdibKJE=; b=II8LduC/AqXllKWwa35cKs97nm2DKD919Z6L/N8ntiHY0UdfNZMtuHvph6edO5RUhL MGLsKaEapC46ISVn93gObqBubwu4wDvhcSCQFLj8PDY+/zDAYoZC6PjBsCQwmLoBs6mH y98rDN0FMPoNhimhcBiaOJZ017Pu3R2b+ZhSpmpMGYMP4AMPDBcxmn3jmhvdMmgszzbc dd14bw5ajZexwMF9CxQVSjIWzauqvIs8IYk6VlR3xv6q/YQO8mEefl+XXYBOI+hO5aqj Bp5tQoXST3pMyZNxmrOXEyLGUFXcJJGYP081VsBvO0YJ5IY2/gm40XLfy/8ltLWxdsKS hrGg== X-Gm-Message-State: AOAM532LYxYGJu2Xr9xLlMkJXn47WY3Z1yf4htazNul22ewtI5GHHbJx fH0wJTTA8/JptDU9im94f0PGkoMN/2JaRw== X-Google-Smtp-Source: ABdhPJzrMJpYCv56aypgp+yeXRsnDYVam/akH3aepyN8QZA4pQINgQQ3pIOGckeUtBgxsv9DVSPmwg== X-Received: by 2002:adf:ef4c:: with SMTP id c12mr5827909wrp.112.1616005282436; Wed, 17 Mar 2021 11:21:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:21 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 15/19] fsck.c: add an fsck_set_msg_type() API that takes enums Date: Wed, 17 Mar 2021 19:20:50 +0100 Message-Id: <20210317182054.5986-16-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code I added in acf9de4c94e (mktag: use fsck instead of custom verify_tag(), 2021-01-05) to make use of a new API function that takes the fsck_msg_{id,type} types, instead of arbitrary strings that we'll (hopefully) parse into those types. At the time that the fsck_set_msg_type() API was introduced in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) it was only intended to be used to parse user-supplied data. For things that are purely internal to the C code it makes sense to have the compiler check these arguments, and to skip the sanity checking of the data in fsck_set_msg_type() which is redundant to checks we get from the compiler. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/mktag.c | 3 ++- fsck.c | 27 +++++++++++++++++---------- fsck.h | 3 +++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/builtin/mktag.c b/builtin/mktag.c index 96e63bc772..dddcccdd36 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -88,7 +88,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix) die_errno(_("could not read from stdin")); fsck_options.error_func = mktag_fsck_error_func; - fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn"); + fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY, + FSCK_WARN); /* config might set fsck.extraHeaderEntry=* again */ git_config(git_fsck_config, &fsck_options); if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options, diff --git a/fsck.c b/fsck.c index 01b2724ac0..307d454d92 100644 --- a/fsck.c +++ b/fsck.c @@ -132,6 +132,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type) return 1; } +void fsck_set_msg_type_from_ids(struct fsck_options *options, + enum fsck_msg_id msg_id, + enum fsck_msg_type msg_type) +{ + if (!options->msg_type) { + int i; + enum fsck_msg_type *severity; + ALLOC_ARRAY(severity, FSCK_MSG_MAX); + for (i = 0; i < FSCK_MSG_MAX; i++) + severity[i] = fsck_msg_type(i, options); + options->msg_type = severity; + } + + options->msg_type[msg_id] = msg_type; +} + void fsck_set_msg_type(struct fsck_options *options, const char *msg_id_str, const char *msg_type_str) { @@ -144,16 +160,7 @@ void fsck_set_msg_type(struct fsck_options *options, if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL) die("Cannot demote %s to %s", msg_id_str, msg_type_str); - if (!options->msg_type) { - int i; - enum fsck_msg_type *severity; - ALLOC_ARRAY(severity, FSCK_MSG_MAX); - for (i = 0; i < FSCK_MSG_MAX; i++) - severity[i] = fsck_msg_type(i, options); - options->msg_type = severity; - } - - options->msg_type[msg_id] = msg_type; + fsck_set_msg_type_from_ids(options, msg_id, msg_type); } void fsck_set_msg_types(struct fsck_options *options, const char *values) diff --git a/fsck.h b/fsck.h index 80b1984f34..344c3ddc74 100644 --- a/fsck.h +++ b/fsck.h @@ -82,6 +82,9 @@ enum fsck_msg_id { struct fsck_options; struct object; +void fsck_set_msg_type_from_ids(struct fsck_options *options, + enum fsck_msg_id msg_id, + enum fsck_msg_type msg_type); void fsck_set_msg_type(struct fsck_options *options, const char *msg_id, const char *msg_type); void fsck_set_msg_types(struct fsck_options *options, const char *values); From patchwork Wed Mar 17 18:20:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2933C433DB for ; Wed, 17 Mar 2021 18:22:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 811CA64F44 for ; Wed, 17 Mar 2021 18:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233105AbhCQSV5 (ORCPT ); Wed, 17 Mar 2021 14:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232762AbhCQSVZ (ORCPT ); Wed, 17 Mar 2021 14:21:25 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A70E7C06174A for ; Wed, 17 Mar 2021 11:21:24 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id z6-20020a1c4c060000b029010f13694ba2so1866235wmf.5 for ; Wed, 17 Mar 2021 11:21:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YxXaQhKKDImbKww4WtZYHgS/NFxDHSbGo40ilOcOwRs=; b=hIyLpHlrvsV/mrvORiM5tZ9kk4U+mcWRmvxLv6B1l1r5yGbIRiYvQqRt1x0aJDU193 T/LN+VTzP2b2v7vNWGzOiwvJJL8Nz4gujmoKaHP+qNNoMfP9db+kaElmyVFC/wtd6mPA vnKe6NEXtHUlRn0taRp/g0z39xqoMZKxakcxEeBlo3DoOnSHjt9RL+SfMnevk3gTi2AG T2F10cehLCcnEkFseVNFwUKi7zR7vK2K4CocYfdwhi3wL+T9XzwKfO4S7BxSP5nSds2w SmTDYKAyw2JdpjMF+uoyeTM1VhAaqWg0wMyCbPopkEVBYYH8Xab1KJoyxZlldQVO1K+U vBig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YxXaQhKKDImbKww4WtZYHgS/NFxDHSbGo40ilOcOwRs=; b=oqUOULORWDdpOJ5wlHW6MaJnn6bpnfYUNUQMRJ4/mVr1/dIu9mhDXGJsd3ZmA5DKQM ShnBt3Q9I+MM/9h+/akt+q+uH4gNz/RXOGfeoQWePPIGgMkGPUMhX8JzLiiWMKJ/wS2E cR2g5iyT0NTfyobwZX5enD52OAFSogootX6yd0I3qQ9J6Zhsjtt4cSNIPV/8TUyTMoFO aOkM/UWTpg8ziflmMkrMRMt8TGTGooorl5ofztSYPicf5ZNetnsV6XsJMIzXgZMhGDFd Es3cFZs1popDLAZpH477ol1lG9R9CAsxOUe605jLlt1ne0LlbuzLYjKp9jA+pCRLGyTP Ot3Q== X-Gm-Message-State: AOAM531lQYUYTypqaxZDJlHb+eNj7orMltDYF7sQeY9bWSl8jNyyL4EW AU9cnpWhA7DZmCJ061tabuXQf8epRQi1eg== X-Google-Smtp-Source: ABdhPJwx4z82rCE4YnE2QVUYkdZvRc8TLwzQJISc0S5PO9VSC5GHEnd1WXVkmsIGfWa5vnaUKwPwMQ== X-Received: by 2002:a1c:6a03:: with SMTP id f3mr85916wmc.179.1616005283195; Wed, 17 Mar 2021 11:21:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:22 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 16/19] fsck.c: move gitmodules_{found,done} into fsck_options Date: Wed, 17 Mar 2021 19:20:51 +0100 Message-Id: <20210317182054.5986-17-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the gitmodules_{found,done} static variables added in 159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the fsck_options struct. It makes sense to keep all the context in the same place. This requires changing the recently added register_found_gitmodules() function added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to take fsck_options. That function will be removed in a subsequent commit, but as it'll require the new gitmodules_found attribute of "fsck_options" we need this intermediate step first. Signed-off-by: Ævar Arnfjörð Bjarmason --- fetch-pack.c | 2 +- fsck.c | 23 ++++++++++------------- fsck.h | 7 ++++++- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/fetch-pack.c b/fetch-pack.c index 6a61a46428..82c3c2c043 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids) oidset_iter_init(gitmodules_oids, &iter); while ((oid = oidset_iter_next(&iter))) - register_found_gitmodules(oid); + register_found_gitmodules(&fo, oid); if (fsck_finish(&fo)) die("fsck failed"); } diff --git a/fsck.c b/fsck.c index 307d454d92..00760b1f42 100644 --- a/fsck.c +++ b/fsck.c @@ -19,9 +19,6 @@ #include "credential.h" #include "help.h" -static struct oidset gitmodules_found = OIDSET_INIT; -static struct oidset gitmodules_done = OIDSET_INIT; - #define STR(x) #x #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type }, static struct { @@ -624,7 +621,7 @@ static int fsck_tree(const struct object_id *oid, if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) { if (!S_ISLNK(mode)) - oidset_insert(&gitmodules_found, oid); + oidset_insert(&options->gitmodules_found, oid); else retval += report(options, oid, OBJ_TREE, @@ -638,7 +635,7 @@ static int fsck_tree(const struct object_id *oid, has_dotgit |= is_ntfs_dotgit(backslash); if (is_ntfs_dotgitmodules(backslash)) { if (!S_ISLNK(mode)) - oidset_insert(&gitmodules_found, oid); + oidset_insert(&options->gitmodules_found, oid); else retval += report(options, oid, OBJ_TREE, FSCK_MSG_GITMODULES_SYMLINK, @@ -1150,9 +1147,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf, struct fsck_gitmodules_data data; struct config_options config_opts = { 0 }; - if (!oidset_contains(&gitmodules_found, oid)) + if (!oidset_contains(&options->gitmodules_found, oid)) return 0; - oidset_insert(&gitmodules_done, oid); + oidset_insert(&options->gitmodules_done, oid); if (object_on_skiplist(options, oid)) return 0; @@ -1217,9 +1214,9 @@ int fsck_error_function(struct fsck_options *o, return 1; } -void register_found_gitmodules(const struct object_id *oid) +void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid) { - oidset_insert(&gitmodules_found, oid); + oidset_insert(&options->gitmodules_found, oid); } int fsck_finish(struct fsck_options *options) @@ -1228,13 +1225,13 @@ int fsck_finish(struct fsck_options *options) struct oidset_iter iter; const struct object_id *oid; - oidset_iter_init(&gitmodules_found, &iter); + oidset_iter_init(&options->gitmodules_found, &iter); while ((oid = oidset_iter_next(&iter))) { enum object_type type; unsigned long size; char *buf; - if (oidset_contains(&gitmodules_done, oid)) + if (oidset_contains(&options->gitmodules_done, oid)) continue; buf = read_object_file(oid, &type, &size); @@ -1259,8 +1256,8 @@ int fsck_finish(struct fsck_options *options) } - oidset_clear(&gitmodules_found); - oidset_clear(&gitmodules_done); + oidset_clear(&options->gitmodules_found); + oidset_clear(&options->gitmodules_done); return ret; } diff --git a/fsck.h b/fsck.h index 344c3ddc74..b25ae9d8b9 100644 --- a/fsck.h +++ b/fsck.h @@ -118,6 +118,8 @@ struct fsck_options { unsigned strict:1; enum fsck_msg_type *msg_type; struct oidset skiplist; + struct oidset gitmodules_found; + struct oidset gitmodules_done; kh_oid_map_t *object_names; }; @@ -125,6 +127,8 @@ struct fsck_options { .walk = NULL, \ .msg_type = NULL, \ .skiplist = OIDSET_INIT, \ + .gitmodules_found = OIDSET_INIT, \ + .gitmodules_done = OIDSET_INIT, \ .object_names = NULL, #define FSCK_OPTIONS_COMMON_ERROR_FUNC \ FSCK_OPTIONS_COMMON \ @@ -149,7 +153,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options); int fsck_object(struct object *obj, void *data, unsigned long size, struct fsck_options *options); -void register_found_gitmodules(const struct object_id *oid); +void register_found_gitmodules(struct fsck_options *options, + const struct object_id *oid); /* * fsck a tag, and pass info about it back to the caller. This is From patchwork Wed Mar 17 18:20:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23FE9C433E9 for ; Wed, 17 Mar 2021 18:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3F1964F41 for ; Wed, 17 Mar 2021 18:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233117AbhCQSV6 (ORCPT ); Wed, 17 Mar 2021 14:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232942AbhCQSVZ (ORCPT ); Wed, 17 Mar 2021 14:21:25 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7230EC06174A for ; Wed, 17 Mar 2021 11:21:25 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id v11so2832123wro.7 for ; Wed, 17 Mar 2021 11:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TTEfu+yAtM4EH9C+MXnOphrNzv2WHfSFRJGRl2nPKgQ=; b=Yzf/sANpeOkx6Eb+sJZ7jpyZOOX8UINWUZ/G21RJ34K0BJsidg8ZXhapnAIN5Eyg2K vjj0hnLDRijyWJ03FCUogykQdH/ah1bcZNR+J8ub1D+hyceChnpc7cKX2Njbs2eyLN2b 3sGUljqxHDAFrpSfkYiUGiTSm7QrRD833bAKV1x3Jf1zjHD19WO1dZ4IuJGvi6WIsREB mVGDVNAFXhrCAtZiN5W8VXvRjhnYp37m8MbnZuqJV4+I14mgNZSUYiffoX4wdz6vboLQ U0XhDWEM+pY6lFZ/onjPWW5yIq2Dv645cCUUrK25zekMVyZiOcfk1zOOSlA55P+bB+Ag 6c6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TTEfu+yAtM4EH9C+MXnOphrNzv2WHfSFRJGRl2nPKgQ=; b=jIwbAqdpEDyyX0XS+/1cVyRrZV4TU4pg1Z6gDjDoXx/ctqIaORQhs7//2gevHSkvcw E1ioHD5M8fvhTJybw6G2kA+9xUhZxvkJagLtlmyBPVglXLjK7U8OrgyjohRkOhW9mDjk b/3XiPyXBC9C7LReoTuwoBwnwoeAnUmhjQuxvOFLQfBJATh2JExD0lzt/EUJq4tHBQwB fp3R1PZcpyL7HE9Ktkg+nVfFCftwTGVRPuXt9oRyIc8unrLBrM2zcQg3mgLSWyOMhae5 aSrfagZE82scEtfVp1YQ+g708PGeV36mB/jyXzvrV3jC54rtCA0WfZm7bSSlYKxVrtmk PThQ== X-Gm-Message-State: AOAM5305af3n11lb5Si7YpC8aw1WDiZhsWS0Gb1BvhwgojZf7PrLZvKI 8AWZfmXyS+NzPzjgWLDhEDTqWxHm7RO9QA== X-Google-Smtp-Source: ABdhPJxiovDT2QMUXjRs+rj6o5mhKK3MbF9yo2pK41w5H2lgQfahVdIYW5TRyvpcI8a/3DA2+vUf/Q== X-Received: by 2002:adf:dd48:: with SMTP id u8mr5661903wrm.139.1616005284010; Wed, 17 Mar 2021 11:21:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:23 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 17/19] fetch-pack: don't needlessly copy fsck_options Date: Wed, 17 Mar 2021 19:20:52 +0100 Message-Id: <20210317182054.5986-18-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the behavior of the .gitmodules validation added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) so we're using one "fsck_options". I found that code confusing to read. One might think that not setting up the error_func earlier means that we're relying on the "error_func" not being set in some code in between the two hunks being modified here. But we're not, all we're doing in the rest of "cmd_index_pack()" is further setup by calling fsck_set_msg_types(), and assigning to do_fsck_object. So there was no reason in 5476e1efde to make a shallow copy of the fsck_options struct before setting error_func. Let's just do this setup at the top of the function, along with the "walk" assignment. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/index-pack.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 2b2266a4b7..5ad80b85b4 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1761,6 +1761,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs = 0; fsck_options.walk = mark_link; + fsck_options.error_func = print_dangling_gitmodules; reset_pack_idx_option(&opts); git_config(git_index_pack_config, &opts); @@ -1951,13 +1952,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) else close(input_fd); - if (do_fsck_object) { - struct fsck_options fo = fsck_options; - - fo.error_func = print_dangling_gitmodules; - if (fsck_finish(&fo)) - die(_("fsck error in pack objects")); - } + if (do_fsck_object && fsck_finish(&fsck_options)) + die(_("fsck error in pack objects")); free(objects); strbuf_release(&index_name_buf); From patchwork Wed Mar 17 18:20:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37D59C4332B for ; Wed, 17 Mar 2021 18:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1564E64F50 for ; Wed, 17 Mar 2021 18:22:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233113AbhCQSWA (ORCPT ); Wed, 17 Mar 2021 14:22:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232883AbhCQSV0 (ORCPT ); Wed, 17 Mar 2021 14:21:26 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40085C06174A for ; Wed, 17 Mar 2021 11:21:26 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id b2-20020a7bc2420000b029010be1081172so1893290wmj.1 for ; Wed, 17 Mar 2021 11:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P3vXHWJ2/Ynpr02hktr7aopm6VP3FNrN5iPVrzOnnFE=; b=QFg2NSEzbwprzdpPeoRZtkxyVE9NLBi5clLlramsWhf3efLIo4lXqEo7huSJk3YdCo Fpk7S8LmIqq3Qet+/dcPDO6ICBiiSQ6BoGab2pbQPe5xZ1efYRqeFw6o/akb1xTMtv1X jR/C/EpAuF2udQv5OeKAURhe6YzjpBwbFUr31oNocEzz/cWdFaZZmUFnn/RDLugCVkWz YfN0xgVDA0z37tvkY50clnztL0zkiXDsPmyxrnMzzIK+n7kVMUl5GBSdqyNRhc91NO9h l7qLcjLF56elwuThtFPWSVStAs3NdiAH6CF8OGkkdAS6AsXNrEZrqWUnaUN/n5kPu7yZ 6xyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P3vXHWJ2/Ynpr02hktr7aopm6VP3FNrN5iPVrzOnnFE=; b=TKhsMWN/BSFInEITVI/xi+cOQGt9jxc1qRLsUlwvYzL/LLqrwbysc1RGtmI94o9kZs sV6yJsY+u5NCx23uuQx+IPH+gkvdyK0oSGKPFZOJWgCGFNppOVzbX/cvLxNDv9RjMOOe EwnPgZdB2AJ2tkbzUXP72pULyf6lBrQKC3HvGO/MynGduqXx8qbzFQHPWCjgo8MRbbYt J+VL0tWXi36RKz7RGuJ1LJBIN1fVzj2uiWOxrGFwUhgYWVs9Qb6aVUOMGLp3L//+g/t6 zpRuDuQNlC8C/OygUZVe7x5zcpNMf0BfErgg9uMNsShxsbLQ74XJA2fE4RCfmKxST8Qv 8iaw== X-Gm-Message-State: AOAM532T22oZ3dzXrKHpyir9RQiWrQS8Yduv+D6j+vO07nxkOgbFnp0D rAZ6Gr/KDrIlG5Z5dNZe0mmFmBzBUh653Q== X-Google-Smtp-Source: ABdhPJzvBVecZWTnU3N6vpRR/opb54puJI6G50aawjfdvDEV+lnM5XTVtbv5o3VHBc6YNLvah16bqw== X-Received: by 2002:a05:600c:2053:: with SMTP id p19mr100515wmg.87.1616005284724; Wed, 17 Mar 2021 11:21:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 18/19] fetch-pack: use file-scope static struct for fsck_options Date: Wed, 17 Mar 2021 19:20:53 +0100 Message-Id: <20210317182054.5986-19-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) so that we use a file-scoped "static struct fsck_options" instead of defining one in the "fsck_gitmodules_oids()" function. We use this pattern in all of builtin/{fsck,index-pack,mktag,unpack-objects}.c. It's odd to see fetch-pack be the odd one out. One might think that we're using other fsck_options structs in fetch-pack, or doing on fsck twice there, but we're not. Signed-off-by: Ævar Arnfjörð Bjarmason --- fetch-pack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fetch-pack.c b/fetch-pack.c index 82c3c2c043..229fd8e2c2 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -38,6 +38,7 @@ static int server_supports_filtering; static int advertise_sid; static struct shallow_lock shallow_lock; static const char *alternate_shallow_file; +static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; static struct strbuf fsck_msg_types = STRBUF_INIT; static struct string_list uri_protocols = STRING_LIST_INIT_DUP; @@ -991,15 +992,14 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids) { struct oidset_iter iter; const struct object_id *oid; - struct fsck_options fo = FSCK_OPTIONS_STRICT; if (!oidset_size(gitmodules_oids)) return; oidset_iter_init(gitmodules_oids, &iter); while ((oid = oidset_iter_next(&iter))) - register_found_gitmodules(&fo, oid); - if (fsck_finish(&fo)) + register_found_gitmodules(&fsck_options, oid); + if (fsck_finish(&fsck_options)) die("fsck failed"); } From patchwork Wed Mar 17 18:20:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12146729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25CE3C4332D for ; Wed, 17 Mar 2021 18:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC01A64F6E for ; Wed, 17 Mar 2021 18:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233131AbhCQSWA (ORCPT ); Wed, 17 Mar 2021 14:22:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233039AbhCQSV1 (ORCPT ); Wed, 17 Mar 2021 14:21:27 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10CF3C06174A for ; Wed, 17 Mar 2021 11:21:27 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id e9so2826468wrw.10 for ; Wed, 17 Mar 2021 11:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3VUlhJqV+4qqZa6g/W6Uzu8UXP2k0UGv75ptPp/Y4fU=; b=sHSlpYIFhYQoW7BEarmh2KN5eCL66fQDQctMqa2pwKOkrIgn+5UrOT7AipJyNIybhw 3781RDewAlG05krmT0xLuE4JN8brDjRzTC2cQ7XsKxrt6RpYCzU1amWlWhkeIsYchg58 +6NJ3f3+AXBCpZwvxpcb1gFTHhj/JgKwikUM4npoRnmffm+Vxd8oOek3FdqNHow15agh SsERgEn3XUBeFdtzfEHRWGPKAm/8qNDLCyAZVwhQ1OWNCvwOiTET/zzf4vrjQ3OorYij FYSjls+rvS09Ku09lg6xd0S0I4pCirptOknKFiwqewlJcO9oumc1HhVlssu4VrSjn5RO mikQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3VUlhJqV+4qqZa6g/W6Uzu8UXP2k0UGv75ptPp/Y4fU=; b=SJZHrchHHkSdOtg+fHKp3GZfOGra1R+OAQixEFIOX/rLiK8FCID18Xp/ZnQfdetTra nIEVsIQHjFfWcw/mFh4dxK68LWpdKMpnrit/4W1u0NQlSdM3Fus/KwnjsMrYHVRQRPeR uaptOKzYj5+iPCFzaNdb+a0AiNbcxg6I8bcYTmWbdc2q0f3bXF/fwrMyv1IbV7AmSf82 OApWRauXb+ApPXMZ6v2D3Z6TSRR+hdyLUlXejHoMWdhsi3M9AVZHjYtBhybNpNwppZxR kXlPbuPrqo5uqKGG7A3E39rtAJdoxwTNO+3J6hNNxd6pAIoD47Fx0b2bUsuusMPDqQ1n 584g== X-Gm-Message-State: AOAM533GvPCIiLuY4KpigZpwKjyzqVBrF2afaw6in1Uy6GIjlvMssDI9 lGqJADZv1mOZ3YE5cOgFPVI4KtQhcMPlVA== X-Google-Smtp-Source: ABdhPJzWD+GHQUYtmndbUWaKfmEo3Y9Igl/C1QZW6sDd0VzyU7nHOfL3Yvan5jPVxpOLl13sN72ICQ== X-Received: by 2002:adf:ded1:: with SMTP id i17mr5807930wrn.349.1616005285493; Wed, 17 Mar 2021 11:21:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id x23sm3177205wmi.33.2021.03.17.11.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 11:21:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Johannes Schindelin , Jonathan Tan , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v5 19/19] fetch-pack: use new fsck API to printing dangling submodules Date: Wed, 17 Mar 2021 19:20:54 +0100 Message-Id: <20210317182054.5986-20-avarab@gmail.com> X-Mailer: git-send-email 2.31.0.260.g719c683c1d In-Reply-To: <20210316161738.30254-1-avarab@gmail.com> References: <20210316161738.30254-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the check added in 5476e1efde (fetch-pack: print and use dangling .gitmodules, 2021-02-22) to make use of us now passing the "msg_id" to the user defined "error_func". We can now compare against the FSCK_MSG_GITMODULES_MISSING instead of parsing the generated message. Let's also replace register_found_gitmodules() with directly manipulating the "gitmodules_found" member. A recent commit moved it into "fsck_options" so we could do this here. I'm sticking this callback in fsck.c. Perhaps in the future we'd like to accumulate such callbacks into another file (maybe fsck-cb.c, similar to parse-options-cb.c?), but while we've got just the one let's just put it into fsck.c. A better alternative in this case would be some library some more obvious library shared by fetch-pack.c ad builtin/index-pack.c, but there isn't such a thing. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/index-pack.c | 21 +-------------------- fetch-pack.c | 4 ++-- fsck.c | 23 ++++++++++++++++++----- fsck.h | 18 +++++++++++++++--- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 5ad80b85b4..11f0fafd33 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -120,7 +120,7 @@ static int nr_threads; static int from_stdin; static int strict; static int do_fsck_object; -static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; +static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES; static int verbose; static int show_resolving_progress; static int show_stat; @@ -1713,24 +1713,6 @@ static void show_pack_info(int stat_only) } } -static int print_dangling_gitmodules(struct fsck_options *o, - const struct object_id *oid, - enum object_type object_type, - enum fsck_msg_type msg_type, - enum fsck_msg_id msg_id, - const char *message) -{ - /* - * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it - * instead of relying on this string check. - */ - if (starts_with(message, "gitmodulesMissing")) { - printf("%s\n", oid_to_hex(oid)); - return 0; - } - return fsck_error_function(o, oid, object_type, msg_type, msg_id, message); -} - int cmd_index_pack(int argc, const char **argv, const char *prefix) { int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index; @@ -1761,7 +1743,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) read_replace_refs = 0; fsck_options.walk = mark_link; - fsck_options.error_func = print_dangling_gitmodules; reset_pack_idx_option(&opts); git_config(git_index_pack_config, &opts); diff --git a/fetch-pack.c b/fetch-pack.c index 229fd8e2c2..008a3facd4 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -38,7 +38,7 @@ static int server_supports_filtering; static int advertise_sid; static struct shallow_lock shallow_lock; static const char *alternate_shallow_file; -static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; +static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES; static struct strbuf fsck_msg_types = STRBUF_INIT; static struct string_list uri_protocols = STRING_LIST_INIT_DUP; @@ -998,7 +998,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids) oidset_iter_init(gitmodules_oids, &iter); while ((oid = oidset_iter_next(&iter))) - register_found_gitmodules(&fsck_options, oid); + oidset_insert(&fsck_options.gitmodules_found, oid); if (fsck_finish(&fsck_options)) die("fsck failed"); } diff --git a/fsck.c b/fsck.c index 00760b1f42..048cf81937 100644 --- a/fsck.c +++ b/fsck.c @@ -1214,11 +1214,6 @@ int fsck_error_function(struct fsck_options *o, return 1; } -void register_found_gitmodules(struct fsck_options *options, const struct object_id *oid) -{ - oidset_insert(&options->gitmodules_found, oid); -} - int fsck_finish(struct fsck_options *options) { int ret = 0; @@ -1284,3 +1279,21 @@ int git_fsck_config(const char *var, const char *value, void *cb) return git_default_config(var, value, cb); } + +/* + * Custom error callbacks that are used in more than one place. + */ + +int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message) +{ + if (msg_id == FSCK_MSG_GITMODULES_MISSING) { + puts(oid_to_hex(oid)); + return 0; + } + return fsck_error_function(o, oid, object_type, msg_type, msg_id, message); +} diff --git a/fsck.h b/fsck.h index b25ae9d8b9..da58f585d7 100644 --- a/fsck.h +++ b/fsck.h @@ -153,9 +153,6 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options); int fsck_object(struct object *obj, void *data, unsigned long size, struct fsck_options *options); -void register_found_gitmodules(struct fsck_options *options, - const struct object_id *oid); - /* * fsck a tag, and pass info about it back to the caller. This is * exposed fsck_object() internals for git-mktag(1). @@ -203,4 +200,19 @@ const char *fsck_describe_object(struct fsck_options *options, */ int git_fsck_config(const char *var, const char *value, void *cb); +/* + * Custom error callbacks that are used in more than one place. + */ +#define FSCK_OPTIONS_MISSING_GITMODULES { \ + .strict = 1, \ + .error_func = fsck_error_cb_print_missing_gitmodules, \ + FSCK_OPTIONS_COMMON \ +} +int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message); + #endif