From patchwork Sun Mar 28 13:15:33 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: 12168943 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 22FA4C433E0 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F137D6196D for ; Sun, 28 Mar 2021 13:17:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231191AbhC1NQj (ORCPT ); Sun, 28 Mar 2021 09:16:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbhC1NP6 (ORCPT ); Sun, 28 Mar 2021 09:15:58 -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 1DACFC0613B1 for ; Sun, 28 Mar 2021 06:15:57 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id y124-20020a1c32820000b029010c93864955so7156778wmy.5 for ; Sun, 28 Mar 2021 06:15:57 -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=uxEnEh43fkjvjjoFmizQeHgxD0wf9BdC/1K4E1ED1AI=; b=OQR7h8cFuDS8CQrCnKRQ6O1VFQBIr7mZNg/FmLEjvyHdsHclWHYtt7D2aooKeatRKt dGmyST8/uvWhtlt/LNmvJ4RKOFBsMeC/GMSMnapEsi5lpPBuqQy94Bxq2gNvst05ekWm KrypLPcGKH3XP5Uxbab6yGHxnhcIDbbbOcU7R3Gls0jpJ/lNKvOk0iw8bx+YbtelUSfl 01ehfksf5RHsZnOUlIK5OCDI53K9GoJlpveVI3uJq8Z1pRESQOhjKV2prbLwDEALI8VW 1P8h5D+hp7GaJCXbsgo668T5WLPoYPh/8KbkBeLzEazzOqGke5V+TddBCGRq+8vjt2lQ GLtA== 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=uxEnEh43fkjvjjoFmizQeHgxD0wf9BdC/1K4E1ED1AI=; b=WoFAW0mkWru72LuUmz0nEqUFN8p+gUAPxvONxUbYO2+uZaNl0o4y0MaY8Xydp6OBQM R3iY9PiAJoDrq0XybuDL3xc416DAs+hPCS7v2l2zaX58f7+QRLGc9BT41lnazuYIFq+S RWLGtonAh3mxX4MviBNJmJNBYf+Nq3On7cD0bdKM96SeYKJ8BC3xFdW1ehLu0WC9P8BS wac9FIAOiOImdCmshi0v5r186lEsewFm5/fZbe2162lPUuSSYmEnlYEtYT1k/2Z4LPFu mcuRg2iuzQfENUQvQ7AvYEdCwzALjDhhEgn4PIbJdIbEGmmMcf1cE52t/0bTx/u7zLKc ojvg== X-Gm-Message-State: AOAM531KX/aL/nMN8hEHlhaIiFpVf46faYQYkyFrVE0LskQe7f49BnHt O6dTt3Ldj85CrsFNXeqmsHfHuNUdN6yPJQ== X-Google-Smtp-Source: ABdhPJw+oGGw+j/L4LHLMU9YSGzmU2j7y6bdwwdcvnyyQUtabr/LgMQhN20CrXDsxN+XKfKSeA3ccA== X-Received: by 2002:a05:600c:d1:: with SMTP id u17mr21102187wmm.64.1616937354966; Sun, 28 Mar 2021 06:15:54 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:15:54 -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 v6 01/19] fsck.c: refactor and rename common config callback Date: Sun, 28 Mar 2021 15:15:33 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 821e7798c70..a56a2d0513a 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 41a399a69e4..23c4b8763fa 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 e3030f3b358..5dfb99665ae 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 733378f1260..f70d11c5594 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 Sun Mar 28 13:15:34 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: 12168941 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 1E01DC433C1 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC3216196C for ; Sun, 28 Mar 2021 13:17:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231185AbhC1NQh (ORCPT ); Sun, 28 Mar 2021 09:16:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229593AbhC1NP6 (ORCPT ); Sun, 28 Mar 2021 09:15:58 -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 44429C0613B2 for ; Sun, 28 Mar 2021 06:15:57 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id t5-20020a1c77050000b029010e62cea9deso5324821wmi.0 for ; Sun, 28 Mar 2021 06:15:57 -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=2L27Q6bYosgxfkAcwT1/u8U4X6FMWT9xBYDT6nNOlck=; b=M0dGFtIaNY0FiyPAxx/esPeXhKMZU/eopVWJskNA4YFpyEImprvldU38JvPeC9GdUb vn+n+kv4REbdBk6gF6GNN1EAfez8a07tF+JoJ3Nr1TVCTxAMuewJdTbc9aeLrnGD5Htr bdien+uq4OUXeONjdm2Vyy77x+thPMHxjYRmXuQzh3hWLJ0Ph9k4yEaQ7SdaUdPg6C+f SvF+k+TGFeyhvbBit0iRaCePE4WsCO0CYLVkCFez64HXn3Djz9J5/A58rVrexGOQyEwe /yEiXmmTas60OQrjyJ8UjkaDvq92TGwZcvfLNxJiT3R5wk1cEdamLquwgnUM7fyYOauR mWUw== 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=2L27Q6bYosgxfkAcwT1/u8U4X6FMWT9xBYDT6nNOlck=; b=iRbCV9OmwVXhQ9iYesT/wgdDZGhz7EpVxP8DSeH6k7mH5NSdukpNePAMo66oKFS9LQ XCr2y6qYPWfZgYn8iByM8pDzHMfrqUsklg7DJ963xcSVvUMLUxoahb/1hSG9MHtDu9sx 77UUhKWgDCUjEDibDYgUIgccAOQEAeEivpJCOWan1ARbRY0kiyxBeFkI7TtCF3UwY/p7 Ml1fvoX0IvbphtDYoW4loKWbn6V8t9RU1zIyNAzMPeGQlFOSSZU11OaqLMJx/AZJbMs2 q5MFxpDqr6nXqr9LBfKaHMCbcMVGj9NKVzFsM0Q7mAbcq6KxIoXZ8WxVS6M6c+LuOOox qA8w== X-Gm-Message-State: AOAM532t0lqca8zzFEige3ddmmgQTgBePjQboFHU/YQff+KvETI2kdKn gTiBzkpYoi6kO8kWnealJQGu/qDEuiLGrw== X-Google-Smtp-Source: ABdhPJz6rX2uLC1xzWviF0POYv8WcrHOKXzc22u8YRkKWNv0TVnpJeVg1E3VY7teazWPsVEZuwtxUA== X-Received: by 2002:a1c:68c5:: with SMTP id d188mr20291253wmc.119.1616937355691; Sun, 28 Mar 2021 06:15:55 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:15:55 -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 v6 02/19] fsck.h: use designed initializers for FSCK_OPTIONS_{DEFAULT,STRICT} Date: Sun, 28 Mar 2021 15:15:34 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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. This allows us to omit those fields that aren't initialized to zero or NULL. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fsck.h b/fsck.h index f70d11c5594..73e8b9f3e4e 100644 --- a/fsck.h +++ b/fsck.h @@ -43,8 +43,14 @@ 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_DEFAULT { \ + .skiplist = OIDSET_INIT, \ + .error_func = fsck_error_function \ +} +#define FSCK_OPTIONS_STRICT { \ + .strict = 1, \ + .error_func = fsck_error_function, \ +} /* descend in all linked child objects * the return value is: From patchwork Sun Mar 28 13:15:35 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: 12168951 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 8505CC433E4 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B5416196D for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231247AbhC1NQm (ORCPT ); Sun, 28 Mar 2021 09:16:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229757AbhC1NP6 (ORCPT ); Sun, 28 Mar 2021 09:15:58 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1780AC0613B3 for ; Sun, 28 Mar 2021 06:15:58 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id d191so5242088wmd.2 for ; Sun, 28 Mar 2021 06:15:57 -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=HXj6Ek9ALNXQS4Hl3+wqsvdtt64DFll1XZfoMMXbJnw=; b=jKTQc69SU6JaI7bTS0Jt+IjEEqv7L1NEe3QO/L6pCSl+Hulj5Ev2aK08G2MFqYxPww Tmo5eKn8Vz5Ct90w7H/85o+dyAtEDb1q4n3WJ1MfNMnspARa1vvD4pymP0rB9JqmpFSl 6CoFzKyF4sR9aq5oSDwQhU5wBxH8CFZng4whiGpweqHPH2Wowp7PrZnnpp+ULZ8/EY3N yUa81q8UCnWj/HFWWtElzlTTPsenGwe6/5N1CAFPNnIpQFmzcjtKvkahH58dQqFScfDa eF+X+XWoD2T6bHfiyDmSy339WGln5Qh3NszG5eRGFYr7M3JLVbJWIrH43xClADc47KRg dIdQ== 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=HXj6Ek9ALNXQS4Hl3+wqsvdtt64DFll1XZfoMMXbJnw=; b=ne34K/AeDx8THVMcKFKAVVVddHuJPcOjGuKqYIiLXW3N67G11dDFDmrjXxgqRwcq4/ IgON+0YhGZwInwzoY01CNrSISybh7OWP3ERRe+s7DSRk0KJXWI8kuJdZcMfkI+NULMaC g11hHotzZQ0jhKgP1aFvStZF+aPdVdv8muCL9NeR/trkcZgLUsq98jehUsbqH2WAQBt3 A/+JgeaRgJy8WbhjpFMSKZW79h4b12CZpDC8WKSMS1zGbv7usGy9sbb4mAj5FJ0cBfSY AMKC5upfUjeIlR2QOQUxhzux8SaOAwFgEQGAFfXAJDVIB5EeMQPUWZuW2Bjg+y+kZqaB eJ/g== X-Gm-Message-State: AOAM531uNVrreUpS6tn15fZaGGhOR3jXXdsTPP7a4NscYTuhSFHs91PR qUXcSg6JODkcjvO+jANESlqzjTCRH7SDCg== X-Google-Smtp-Source: ABdhPJzw4oDu24BCeiuQvmgM6gMbzeF+bNKNCKQpGuVOhui3Y7H37AoHVo/G4xTUqPx/l2Bmn8Kehw== X-Received: by 2002:a1c:60c2:: with SMTP id u185mr20583884wmb.157.1616937356541; Sun, 28 Mar 2021 06:15:56 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:15:55 -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 v6 03/19] fsck.h: use "enum object_type" instead of "int" Date: Sun, 28 Mar 2021 15:15:35 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 a56a2d0513a..ed5f2af6b5c 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 21899687e2c..f6e1178df90 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 a4ba2ebac69..4a70b17f8fb 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 73e8b9f3e4e..f20f1259e84 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 Sun Mar 28 13:15: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: 12168945 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 657A3C433E1 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B09B6196E for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231241AbhC1NQl (ORCPT ); Sun, 28 Mar 2021 09:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbhC1NP7 (ORCPT ); Sun, 28 Mar 2021 09:15:59 -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 C4387C0613B4 for ; Sun, 28 Mar 2021 06:15:58 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id z6-20020a1c4c060000b029010f13694ba2so5297610wmf.5 for ; Sun, 28 Mar 2021 06:15:58 -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=Vsw7inabgC0J2mp4mkdrnLJrzLAHMYdQHyg/Y/y764M=; b=JJ3TTB9EVgDYbaiJ+LUKXAUIEd7Z5RNJW3m7NGmQofqQgU8ioIFKmn/p2VVGtBpbgH duJLI4v5Am4CgAI/Oo6uloQpVIZtrBLCuEtI0B41zDVI1SwwknUTqxCb1/zTfQ+i4lYZ ya+9nJfr+ZaCffeAyGwk5KwHizl5zd/k1Ax/jhccOoZ0opW0ragaOi0aJIH55vtxRRFn eb5p+IFHaWToTGjD4trYNIkq/P0mLY4SFiozgebP3jZA6yM3VGBoFnE1MSEMfvlwXo/9 qxYy8rTFHGzSTWDPjG6npwhkENYKXPGAU+hjfI0ic98dLeq4vvvZW6wa5xPvHLXdjVw6 yOoA== 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=Vsw7inabgC0J2mp4mkdrnLJrzLAHMYdQHyg/Y/y764M=; b=DILynph+gtnq/CL+1OL7WO7/IgbrtRP0SbKaNaoYHy+nm0QNkh2W97laspN84cSuft QSKRKspog5yiy5nbnFYD6x4nGtkd0yaNkFMC36RpL11R+HOWCFJrIoQBcgOmsE7FhaSa vWkUlkK0f/1lVAxSwRvJ8L5rV5fsLhxV6ROy5ApAQaXUE1Yz8P9zm34MdVEQ5dw2pmLs OUZMaxpe04QUvyu5dMJs/ikGx0qm2ZfuCTKePoNlQwk9hlfN0/2krPYe7vcfnokd1yrP uOOPJBWxV/2yUjI9vXCUaJnMWpIo0B92+koelVlccVa6iGF+kAGqfacaje0pahG68ZBb jczA== X-Gm-Message-State: AOAM533Yxj5deeV64HBuLKwsfJWmV9iDbIMncUK+7LXMdMK3JH6/TG5s 2ZYqna5ajZOpR9cP+shzKd2f/jt1t9x9hg== X-Google-Smtp-Source: ABdhPJxMT4DzOUHZ6UwePjDHL07wBA8E/JdUePuw1d7gvUoIrlqJ2SWKzVG6+Dh/mUqnGIXUfLsXJw== X-Received: by 2002:a1c:1f4c:: with SMTP id f73mr20795845wmf.25.1616937357273; Sun, 28 Mar 2021 06:15:57 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:15:56 -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 v6 04/19] fsck.c: rename variables in fsck_set_msg_type() for less confusion Date: Sun, 28 Mar 2021 15:15:36 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 5dfb99665ae..7cc722a25cd 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 f20f1259e84..30a3acabc50 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 Sun Mar 28 13:15: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: 12168949 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 45F33C433DB for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CA5A6196B for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231219AbhC1NQk (ORCPT ); Sun, 28 Mar 2021 09:16:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230385AbhC1NQA (ORCPT ); Sun, 28 Mar 2021 09:16:00 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D647C061762 for ; Sun, 28 Mar 2021 06:15:59 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id j20-20020a05600c1914b029010f31e15a7fso7180877wmq.1 for ; Sun, 28 Mar 2021 06:15:59 -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=Pu1b9zR9Dj/kCCJZzffONapXZmdjhdqC/q4G1xIcz7Q=; b=PTHcw8yVQi5M0XxYM7FPYv2qFKaL3CoGT4Et12EJgWTlWfdF2V2xsalkAfSRUg0rt6 M7PjSQjsbknlY4xvzlx6gyNwHaXdkk8QzEDAtXaFlUXJMA8Hzq29fSkJeS0FeLDsVJul IEFTDfApGQCpTQ5Dc2hhlp01/10HouZCKyaXe+3wZdUFl+lqoDAvNsrdQ7KKyNchtDll SXKBZN3VxRUSUhHiqL/MTUZp3ZcjnoFsuBU2NtyT7PwwiCfBCIi3gOtYg9W3Ex/W+Ct2 Qoarh13dnb4CxVVJ9TZtzkGfYW3sgYN4Al4GmqbligMTbuEElSxuXHLM8NgJEJ+caGft H3SQ== 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=Pu1b9zR9Dj/kCCJZzffONapXZmdjhdqC/q4G1xIcz7Q=; b=RAdapLVh1heqdSLbL75v2AC204wyYmGvd/vpQ/QdPbfynLUaRioVPU/aIb1OT8Tk5u 0/Oh9mqfupvRzQds01AGwNT46Gfkwl2pF3MdcCpe6SEShRItlJetD0kJ6anhYCVPiVzq YHtplZLSXsYWbZmmKUcqEMdPbu49SW16oKpcpZK5RfowCR9ZrpycxKVORLMghQjaS1f1 d/+Tae+KjUoJOJ3K/JfKh+PnAKB6dRVfrWpxm7BnQ15a6n6TEEUPtJPRY4Ytp4bfEC32 8iR8m6ZkFxcGNuFHX6IPgFZlBbsAtDwiN7eQGkTuFoTbo8bbPtb43IrWrghGn4KX0m0N 9ytQ== X-Gm-Message-State: AOAM532YAf63qXzUUTJLOUoAMFgZ8r7VU0lFZ0AlwvF3aXMU2dDqr12O S3TEbXCmgdrULm4UJK3hwqz8gUsTum5OSg== X-Google-Smtp-Source: ABdhPJyee6f2SImQQ0em9QPoCnF5u4vkZxPcMn3E3sz7YO+ZlHFbZ26y68mBV8re17bjIpX7HMHwkw== X-Received: by 2002:a7b:c2f7:: with SMTP id e23mr21394002wmk.30.1616937358089; Sun, 28 Mar 2021 06:15:58 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:15:57 -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 v6 05/19] fsck.c: remove (mostly) redundant append_msg_id() function Date: Sun, 28 Mar 2021 15:15:37 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the append_msg_id() function in favor of calling prepare_msg_ids(). We already have code to compute the camel-cased msg_id strings in msg_id_info, let's use it. When the append_msg_id() function was added in 71ab8fa840f (fsck: report the ID of the error/warning, 2015-06-22) the prepare_msg_ids() function didn't exist. When prepare_msg_ids() was added in a46baac61eb (fsck: factor out msg_id_info[] lazy initialization code, 2018-05-26) this code wasn't moved over to lazy initialization. This changes the behavior of the code to initialize all the messages instead of just camel-casing the one we need on the fly. Since the common case is that we're printing just one message this is mostly redundant work. But that's OK in this case, reporting this fsck issue to the user isn't performance-sensitive. If we were somehow doing so in a tight loop (in a hopelessly broken repository?) this would help, since we'd save ourselves from re-doing this work for identical messages, we could just grab the prepared string from msg_id_info after the first invocation. Signed-off-by: Ævar Arnfjörð Bjarmason --- fsck.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/fsck.c b/fsck.c index 7cc722a25cd..25c697fa6a2 100644 --- a/fsck.c +++ b/fsck.c @@ -264,24 +264,6 @@ 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) -{ - for (;;) { - char c = *(msg_id)++; - - if (!c) - break; - if (c != '_') - strbuf_addch(sb, tolower(c)); - else { - assert(*msg_id); - strbuf_addch(sb, *(msg_id)++); - } - } - - strbuf_addstr(sb, ": "); -} - static int object_on_skiplist(struct fsck_options *opts, const struct object_id *oid) { @@ -308,7 +290,8 @@ 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); + prepare_msg_ids(); + strbuf_addf(&sb, "%s: ", msg_id_info[id].camelcased); va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); From patchwork Sun Mar 28 13:15: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: 12168947 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 7792BC433E2 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C85A6196B for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231255AbhC1NQn (ORCPT ); Sun, 28 Mar 2021 09:16:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230476AbhC1NQA (ORCPT ); Sun, 28 Mar 2021 09:16:00 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 621C3C0613B1 for ; Sun, 28 Mar 2021 06:16:00 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id u5-20020a7bcb050000b029010e9316b9d5so5315257wmj.2 for ; Sun, 28 Mar 2021 06:16:00 -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=WQMV2pG1Bc7kiV1kYOHpImLGiweUK4H4KfyF35uruKA=; b=sAf6Qx3IEDcd2oAOrbCKrkNtRx/J/KdoyTctWN/WuRXy2Ncjt0BODH3nz+3RjmmE98 Zih4/U2+SGk8zlcq2ZvRlbN5WBzNSrxiAohVqsFEe2vfGcZrNjsjMdSH/5UIpkLI5dfu zT/gpvxx2/0PF+zY9t2wEPf+mh4UgIkYe8GRILJCwdUSb1LA8Fe4MmxvveyS5C5PRmG8 QXVo5vP+5gIOFD8euYRPEQjdQGUDvRRN63ivS7MLX3fBEiKer9eUNoYCiuw56LoYtHI8 UQykCF58bmeeGOiPXB2pW2FtK1cpWrbOnv2rjT3vIvPhrr+l5Pkq3SqRzuRY0rjkNzmJ Zt9Q== 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=WQMV2pG1Bc7kiV1kYOHpImLGiweUK4H4KfyF35uruKA=; b=h8d7bglgPiNdQZwTHyQ9bWkSEX35mieRFJTeYAmVvAH+JZFTm8y06IioVoBOUucwQN onIWST8uBQqhpQYOKjA3tFcoznh5nu16XYIgt+a19LQ8PTMM3HnBOwh3ukfa25CF/Qys 489UlIVfMpX7F+WVROBfQy39CeQsrgS7k7RmAipOK6qFnMo2B59Op+bZjLi5xGk1ZJo1 n/vpjq4eqRkAj8RDy3qLPVV3HMbgFv3m7ejn7jI43o+cfc/Ymc5FTdBaLTIRGBLtk/Bm NmQwK/7p0BMjIoOmyMB9L3pbkgtbjEwUKEG6baHO+F/0NZRkp2/GTgiLnDkiqJg9s53r G17Q== X-Gm-Message-State: AOAM532TGSE9S4ph8Qv9mXbuXjRdK9LTN9V8SLfco059BLQ37D4Ocbkz BTaZaA1lU3hfa5B0ihj8ktOaZj5bAmdOOw== X-Google-Smtp-Source: ABdhPJw9QBFGZkxpjWqo4R8S9nPSQS5JCvrxht2z1Aem6ri4h6oOybnqBAGPgqo5UxJ7nV6IuF++6g== X-Received: by 2002:a05:600c:6d4:: with SMTP id b20mr20883091wmn.142.1616937358946; Sun, 28 Mar 2021 06:15:58 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:15:58 -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 v6 06/19] fsck.c: rename remaining fsck_msg_id "id" to "msg_id" Date: Sun, 28 Mar 2021 15:15:38 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fsck.c b/fsck.c index 25c697fa6a2..a0463ea22cc 100644 --- a/fsck.c +++ b/fsck.c @@ -273,11 +273,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; @@ -291,7 +291,7 @@ static int report(struct fsck_options *options, msg_type = FSCK_WARN; prepare_msg_ids(); - strbuf_addf(&sb, "%s: ", msg_id_info[id].camelcased); + strbuf_addf(&sb, "%s: ", msg_id_info[msg_id].camelcased); va_start(ap, fmt); strbuf_vaddf(&sb, fmt, ap); From patchwork Sun Mar 28 13:15: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: 12168957 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 9FFF5C433E6 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 703856196E for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231258AbhC1NQo (ORCPT ); Sun, 28 Mar 2021 09:16:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbhC1NQB (ORCPT ); Sun, 28 Mar 2021 09:16:01 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80EDCC061762 for ; Sun, 28 Mar 2021 06:16:01 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id w203-20020a1c49d40000b029010c706d0642so7506069wma.0 for ; Sun, 28 Mar 2021 06:16:01 -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=02dmYg0pq3NYMuKuhJFrUENzF0SckD0GfxPVM6LCF0U=; b=U6dJ+jKeXiGHIp0NW6IhNuMOZJenrTpX/59aTDgwUXx8WC/aWEHnQxlCjzRsfYsWux R4HG8wFWHt9x1/ds48yfs6WWteZP+wXAuE0YDPM38QYeYS4AcVxp56jlyhqhhxdBJ7+H r2VGTyIpgesEdVWBMhm0bTUzzqhlTmLjq6ndsEaUx0cC6DOXn2w0CVZYVMF97I28LfP2 zqPRfpNqyZmM9ZXd6AssL79vgd8rnjNP0TDTXTGc5kQv0BDB/kpj8Piuajt/1GjD1CTw 0FrL7XHo7ZGYhpLIiovSmz2sLAo83yFiu9/uuwdi0wde9zaWmzPFCDRJmGyKxeE7keTQ 9fTw== 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=02dmYg0pq3NYMuKuhJFrUENzF0SckD0GfxPVM6LCF0U=; b=apYmuwlR4AgtBOClUnXT/X23hdYGQNpKKnGvww1C672JGRRvZL0MLkTaqDImOkT9di HTV36HfHOzOjiePoV2rbZeD5DfQ4yLowQ1XlcStO0s9HptJq/lDBbYHmOEsED43MNZmv bHOkV0WCf9FF1DcHJB48Yh2f9x9tfXrRzF59n1MwFzD+IcWdDjz0twtCQ8W6XgfwLMMt xl2zdwGBSe/at48S7Rwu1d2YAht8qnY6CTJn1rPoDsMmoijhFKUSoQtlbB2yXR232iKy j9uH6cR9Zv+8PkM13hUk8OT4BacYwBuHTQ40JrU5frSEhOrwCpoJKrBc6jLOtffKFmYX s0oA== X-Gm-Message-State: AOAM533CmORljBit1ApepBlsvkd/0PHwlipyjvixNYIwnYaMUB6m1g/O GOcNMglFRQQxgfwiqfcih/yyBS63mdWRlg== X-Google-Smtp-Source: ABdhPJwTR5bvhQSVJ72weobLM5KLIFukOi7dyq59HFg43jBRJOho8gsrwg4LCKYGx0d20dKknmdpGA== X-Received: by 2002:a7b:c0c4:: with SMTP id s4mr21183498wmh.9.1616937360036; Sun, 28 Mar 2021 06:16:00 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:15:59 -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 v6 07/19] fsck.c: refactor fsck_msg_type() to limit scope of "int msg_type" Date: Sun, 28 Mar 2021 15:15:39 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 a0463ea22cc..8614ee2c2a0 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 Sun Mar 28 13:15: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: 12168953 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 91B59C433E3 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FE7E6196F for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231267AbhC1NQo (ORCPT ); Sun, 28 Mar 2021 09:16:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbhC1NQC (ORCPT ); Sun, 28 Mar 2021 09:16:02 -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 48538C061762 for ; Sun, 28 Mar 2021 06:16:02 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id z2so10162876wrl.5 for ; Sun, 28 Mar 2021 06:16:02 -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=Xrh5ruUrkDtP6aD+i+ttBnrPDGjDhup2yK+mV9ahqzw=; b=FTbU92yrjUWv/I4peM23Y3GG4NqDkTfjnmO/zPpn4tLHC4RLLkG7VY3DTn3uof5u8P Q8Cht4eMXtz1fjRDAPmoKwWuxihC4W34zHqJxZ0kbvP/XYb3K2GX82BolZJSQOeQgPWP ZI8kRefsthSE12NHG1gvtfdDPC7/c4mIoxAV119sV2Y1/zodyRJigptsoK0aD9Yazu58 iiqqlpnPQ3f5QUrnQLqIjkUzugtOlg8gvQzy8hB3Ys5ECm4Pvl8VT18ntTSxpF8KuBXu GStffCm/hXnttc+lXXS0Y6YLh0YNkmC79tNZXDEi/ltr0lYQTKLvFkIytaY3x63DVTFN OqrA== 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=Xrh5ruUrkDtP6aD+i+ttBnrPDGjDhup2yK+mV9ahqzw=; b=SL/WIXJQ+pdoLEn6TlOCalA1xxxVIcje2bynUI6IHZDS8hqI5g/VFUIsnJaXe7g8A/ T2ABRwFr3om/wfCMLf7z4JthgBsFBH6O4trEt78cKW6iwMzeeiKiDYU5n5p6cthPVS93 dB1rzGZSJ5gND2EWd2bSy6YiM7DxOqdA2gnT1aTGAf2DQlFSViHhXYvdUaPzOmsh3bK6 isbIrmyxvSDNKvAaOxmItneBAnkVTAcKGrCcH7M5iqTfYC2ZFFnhJ5JdUT/Yro3K1+2g thNjNzE2oLT4cBbhnJclxEuiigZ1O7EfZlAAfqKsP/+u+OAEb6uwqg1VEn9JDjAQ1BWN QAbw== X-Gm-Message-State: AOAM533N7bZYkOlDDS05Nwx2WWqOz9CmykzZekfl4Mkn1pH4zH8R7wrj 5jmN7An84UiNSAMJWSq0ZxG6hlX2N5zbdg== X-Google-Smtp-Source: ABdhPJwK0YInbwcjMnOtEMUhTb9G256fAN2N3h7XWsirpVUy8FYarC4LUzBKRKwIAJu44py9R3GhSQ== X-Received: by 2002:adf:fcc7:: with SMTP id f7mr24050959wrs.400.1616937360766; Sun, 28 Mar 2021 06:16:00 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:00 -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 v6 08/19] fsck.h: move FSCK_{FATAL,INFO,ERROR,WARN,IGNORE} into an enum Date: Sun, 28 Mar 2021 15:15:40 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 ed5f2af6b5c..17940a4e24a 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 f6e1178df90..8338b832b63 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 23c4b8763fa..052a510ad7f 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 8614ee2c2a0..c5a81e4ff05 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); @@ -275,7 +273,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; @@ -1247,7 +1246,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 30a3acabc50..baf37620760 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 Sun Mar 28 13:15: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: 12168955 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 B2F06C433E5 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0AC06196D for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231293AbhC1NQr (ORCPT ); Sun, 28 Mar 2021 09:16:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230517AbhC1NQD (ORCPT ); Sun, 28 Mar 2021 09:16:03 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 289F7C061762 for ; Sun, 28 Mar 2021 06:16:03 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id v4so10126259wrp.13 for ; Sun, 28 Mar 2021 06:16:03 -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=PDkAEWNoNstOWJZXf/6DMEiH+jY1mKIph+pAk5g8cdA=; b=uZKSQe6T0ZeXjBT0wXc6n97ULRFh9x02dO459U32/Is+Mu8DEdydXthHZ5ClgTLwsL RGWdOVMVhDrlRwcgOO+QlwxJLynQZA4OqGBCMRoHPdj1PYnqgXRty3ayAatqzrbGKkIt xCxfvLig0vh0iB2K/y63hV34BBFyFT14GzxCJEfBLufiMdH7amJzFrqpc5a7Cj4D9zgU 7WuJj5PAVp7MKdN6/JoyaCoZFXz+AP+uQ40Sb7xVhA9+FpDXWUMIclgI3IxstxBhY8SB BDV0Vfy83GlZ0wxzaohfo4o1JyzqDHX2ActJ+ehvRIJdKcxkg+XHNCvd5jHXSSaxSKrX 6yow== 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=PDkAEWNoNstOWJZXf/6DMEiH+jY1mKIph+pAk5g8cdA=; b=ZTxtVY5bpXQRs03PaCwBpscua/+2XsYk53AGxzecQodF2h1nfuaHyxvGAsQemMiaFW ery4CQDDduA2hnJO/UPlK8bkYGaZGvW7jZhYf3CSNzCyS2MBEnvYXL1jbr7O5btaBqLT guiP0ANl5cJx+kKaEcmefeBzYD2OrWHwYIrKBcUiqc+kkJjljoiEr0FfCaHoyNGvIn6e PGpUtlGAtfoQWUWkBTL9OHSDWOtwzQ3EqNHWrprx7JR5a4TGfd/1LVHKINqtECDj8hCa cEd6kK1g315yqIt5+Kt+7GNPsF3lhhLdfpvmFG3syrjWJjWWx0mj5qkAHWsoWlZGsU5F Y8fQ== X-Gm-Message-State: AOAM531UBfYoj3PnK36oYV/ZMx4tlH5Cxtf6pZmL/q7fa5i3adEO8oU8 fMqZUpkM8Qdr39NKR4aQ2u1pJp90koCy6w== X-Google-Smtp-Source: ABdhPJwT+2HigAjUuWcj1pWE5X7owVAUzFH+tObX5xZ+DV2jInY3eZunb6S6mXpmmoKFGufXj/7N/Q== X-Received: by 2002:adf:e54a:: with SMTP id z10mr23716090wrm.87.1616937361608; Sun, 28 Mar 2021 06:16:01 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:01 -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 v6 09/19] fsck.h: re-order and re-assign "enum fsck_msg_type" Date: Sun, 28 Mar 2021 15:15:41 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 for equality. 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 baf37620760..a7e092d3fb4 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 Sun Mar 28 13:15: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: 12168961 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 A7E1CC433E8 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90BF26196B for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231285AbhC1NQq (ORCPT ); Sun, 28 Mar 2021 09:16:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbhC1NQE (ORCPT ); Sun, 28 Mar 2021 09:16:04 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D1C6C061762 for ; Sun, 28 Mar 2021 06:16:04 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id j7so10184013wrd.1 for ; Sun, 28 Mar 2021 06:16:04 -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=SmN0ZTlKU1ndq9HW4UBz7I9dl7Tk5HKEh5FpMs+bW8c=; b=SVLU4FHgLHlgwkFWRXj+vhFD39CR3B3fIpfY4CaftMZKeliCpVCLu+rEeZNb9SzpQ2 iGeQoeMmcCYly7yAg7h+jDa1TXsmqAxkofz7jluV8u+YNeCgdUet3BaDxajuoQXKuW2z iyBrjSUpJL1eGFWQsAdU90yohnD+qv/Ekl+u6lFYjZfvlTmJBgEM0T+4HATd3H3SJMBW FCvQmw58nACgc+mCmz39mQ/3/XLp3fbfuypm9lwKRAM2JHUK8F5DqBOOa1lJgjo42d4a ZpinbfHaqD5mXbhUOUrBvWzx9h13TW3DmWSHHe0ccYbWBISWk6U92wOGfWlJlfXPVhWf vo7g== 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=SmN0ZTlKU1ndq9HW4UBz7I9dl7Tk5HKEh5FpMs+bW8c=; b=MMEsyXYyYSndwo4j1LyEb0kuYJdNJJ6cR5m69eYJtbD8PnENnubLEhgyuBeDiHd/XB w/kqAl4CFzSoG1GUqXzBRQgjd1Ei6d80AkPknHjd/MmbQevRQ08vIKDa7z7L0+pOA3Zh 9YDy6uRIXngk4J1T3sdpIwZ/H56cjClH4v88krtQ7hJxRFeKptDvgiQHgYs3lbHSHKDD ZU1tJotj1JVz9UCwOugZ/JYUpGcIh6b6pq12/WWz8WAv0TjPe/phzqIur7vPheyI34f8 8Esc8dCM0VSzZ5HuupAuniUitukdLrimsdvCjl1NL9Op44F/sfojQaz1h9wMpS1gZ7U7 Y2qw== X-Gm-Message-State: AOAM533oWPQR+shi2HSFjhM+MRRSZrD7ioobIa5TScTshIX2QQ1LPkZT tlCGt6zryTHeGBi5aGy3lpN2Sfd6RmVx/Q== X-Google-Smtp-Source: ABdhPJwQVrNEjBxwhKOl0fGqnDnhHIdWgGBWg2S7lnkFFdf60Hselo1r13iOJc/B+jGyBwFGPYt0vA== X-Received: by 2002:a5d:5250:: with SMTP id k16mr24136133wrc.309.1616937362646; Sun, 28 Mar 2021 06:16:02 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:01 -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 v6 10/19] fsck.c: call parse_msg_type() early in fsck_set_msg_type() Date: Sun, 28 Mar 2021 15:15:42 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 c5a81e4ff05..80365e62842 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 Sun Mar 28 13:15: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: 12168959 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 C0D5EC433E9 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF16B61971 for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231301AbhC1NQt (ORCPT ); Sun, 28 Mar 2021 09:16:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230526AbhC1NQF (ORCPT ); Sun, 28 Mar 2021 09:16:05 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D79F7C061762 for ; Sun, 28 Mar 2021 06:16:04 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id x16so10152560wrn.4 for ; Sun, 28 Mar 2021 06:16:04 -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=to7bS0gtCj+Yby1/IsFaXtxzs/o3JXlOi0AR2DdoGIg=; b=P0ldGPvl8Oq2vyUfwrXiRsWNUzgKuBfPdBjkETZUkXVOD5b0l6cVu/wUFK5YJxK0U4 8VGmraUPV/U5e5vXWjFwKE6FTqXZrJbVm0b70BxLpgRaYAR1o+PUmgV9Gl+EzzDcGszx 7zd7GMh1gN19CENWB+kGj58/O5NV5fcQcblgwh67OdZEmsdFDBLK5PgSpBNDqPGlqEm+ 5gWtoOwvWQryYKEhJ3/CTVYTSfLgyY7zM+/4wSBjYmiYhMBxyWKZupcp65pR5bdPmXKy 7XX6xskpheOrrx8e03TnuG5Hze71Z2LYHNFH1V5JqXC59ByEPN4c7b6PW213uKTAOyvO 3Dbw== 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=to7bS0gtCj+Yby1/IsFaXtxzs/o3JXlOi0AR2DdoGIg=; b=ICvmo/0oq6ov/0t9k48+7Lk3DcnWhH1CHOaTgMM+BXVg6ZjVYmc9XHF/btPayjAwgl WG+SyNeF5EEYbWKJvM8XBTP5uSzxhEzFJHork6542gwu0Lr50TwsSCrkCSfcS2Q7qWK2 uRteoWJ9lRJbM2hd9FV7Fts84HKY0kX/263NQkCymgIG/8P0dJA2u6PDDhwQonMK6sp4 DfZbUNIRwibSgmb1pawGUnzO0Pk3SfmXoczl7Zl92G2RVzGR0QTc50f4dbkizwWleyaO Al07eG0dYUbEEjAacPlxL6da7uNqAZAFV2dziDEuMQ8o/NrdI5K7DC2wOk8+tcFWzxlC sj0Q== X-Gm-Message-State: AOAM532qm9J6TrHmtmedzqDXRjX4FdOFeT+i0U7YbyRIkGrKz81LSz4T rGvvykO1io4QTmfarw6qkQ/Wu+BVAWP2eg== X-Google-Smtp-Source: ABdhPJy2BaCM9zp8Id1d1kr6LdXQuqn6MmF4FnFd5VoO5aiFAS8dN1snEcAKHZHLjp94MYX1dk3LCA== X-Received: by 2002:a5d:404f:: with SMTP id w15mr24815214wrp.106.1616937363428; Sun, 28 Mar 2021 06:16:03 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:02 -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 v6 11/19] fsck.c: undefine temporary STR macro after use Date: Sun, 28 Mar 2021 15:15:43 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 80365e62842..1b12e824ef6 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 Sun Mar 28 13:15: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: 12168973 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 D6AF5C433EA for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF4146196C for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbhC1NQu (ORCPT ); Sun, 28 Mar 2021 09:16:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231131AbhC1NQG (ORCPT ); Sun, 28 Mar 2021 09:16:06 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC14CC061762 for ; Sun, 28 Mar 2021 06:16:05 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id j7so10184050wrd.1 for ; Sun, 28 Mar 2021 06:16:05 -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=NePBdE+cKIwFwv/LanoIn7GgCdwtfSZN3QjEIwCRy/w=; b=QPa68YVDnLfYqt/2Oh3ceGlUYVBTU8ehzBe0cf5Cq552R3A53WuAePGlY2XIlc4BED GK4wY0zSQsUFuxAPwdBkIE8xbUtOircSlpF0COwV+9TeCAVOhSRxhVIdNqN8ZIbFiUuS J840E1joz1DpS1Fj+xNtm9j1AB2kQBURChbIYj0p5q4zOYGJ4uObD1X+Vkw6qj+wdv3z bRwKb7M5cRijRqOpCok7NxokKcV38sHMf1kK+2CB9V50/7vpLmebJ8irf3bO2qdUBpeZ OG/cAjX8ArHBdag01EuA4cekCJFjqNinBUlVdoE2/5HU7NZ43deji3fXATdHyEpw906z Yb3Q== 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=NePBdE+cKIwFwv/LanoIn7GgCdwtfSZN3QjEIwCRy/w=; b=A0wGjVxlqUk6Q4qVRF6LOHmUzoNzqt5KYT/mp9LTU8RS8YmUhURWNP6El0UElIl0SW 9jc8WTJNb74he0Yg0q/CRiKgtqCsJjrETHxkpflmf24Hyk0pLnyEAF3T6H9VUpkh7bWj s7BaBIZrDFsWEDE1KiD991dHUi3yjDwdnWZVf9ZvDKoFkduM5zWglGKSMzBDEYrgJatb bWe/h3Ie6Xf1m3p1F9Q36K27gK3ADYJP3yjVEOiLgceboENBXrORAEjDkj3EBaE9jZXT ZyAZ68ocgvIyoKMQNcEkVSoi4a0aeF2Z8xGSO9xrIFYBSw2H/DGdQLpDpk3LHWbMnGSH gjKg== X-Gm-Message-State: AOAM531EeGHWEQmiq5iRrspoGYN+s9nfTPdmUzW2Nm3m8boV51ewbDtZ OQppR57YPhVT+jZ3MhZvSGa9Oi6DyZ5E6A== X-Google-Smtp-Source: ABdhPJzxmk878jVg7Tad7DQOeVFgtpRRlZjRZhXXxKd0DWsJwZbAbfAmZRnpe4/zsDb3gNgwp1Usng== X-Received: by 2002:a5d:4dd2:: with SMTP id f18mr23865698wru.366.1616937364246; Sun, 28 Mar 2021 06:16:04 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:03 -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 v6 12/19] fsck.c: give "FOREACH_MSG_ID" a more specific name Date: Sun, 28 Mar 2021 15:15:44 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 1b12e824ef6..31c9088e3f7 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 Sun Mar 28 13:15: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: 12168965 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 079BEC433ED for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB9616196B for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231313AbhC1NQv (ORCPT ); Sun, 28 Mar 2021 09:16:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbhC1NQH (ORCPT ); Sun, 28 Mar 2021 09:16:07 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C4CAC061762 for ; Sun, 28 Mar 2021 06:16:06 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id b9so10137175wrt.8 for ; Sun, 28 Mar 2021 06:16:06 -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=zNi1udXeUGRIX8wlJkitrCqQ9K65xVgAqu0JxdZxWtI=; b=b54NjVHJ2b5G5cuP7kZKq/x9ARJwwl/rBgcjYISWm/oraNMbfPv0cbrQqgvKTWE7Yl tF0FFoQqfJ5E+3hmvUyKivpmdhRzdyR5z+Rq4kHMWF4dYdpcTrarvvWj+y2yVlzLlopn /lEW43Wp1gpU01TtT0bCqy2z9Bt9SeHt0MoxzT86MT6Eaiwx/Ner2AvPFzFNIwB5uGCB nsBF1NL/+iiYS1729eLIGYfmNf3YfLT5Ehozyi8IIT8IcBwsXPB7qW+sSdqQY4RixxOW CjtCZ/bmLWK5CM4/akpJOYSzu3iEUN/Rn0PCvBCRSJmR7TADZ6r2bOrYE+Dp5RREGUJm nMmw== 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=zNi1udXeUGRIX8wlJkitrCqQ9K65xVgAqu0JxdZxWtI=; b=b8jlLxs/4dLqfwLxqCQGxpDbOv9z4Qt+bTyI4ilP7y1uvVmbz30+9qM6JJUEncJvzR yZoDicsQFiwY0TQNYXxN4ExvCxEhTFkcttxfuRAzP+ZAYKd0RK8FcuqMXmSXclKre4ZT k9lbP/Ro99hEWzxyYljcI/BdkLpaHG+qL4nafsf1MrI/YcQ8QipIJ64mcQfUhNN/50qf mH0/udrO1uUUq/tv7O4oi6Lc+TrVLI+6wd7pMnI9w7Mm+LrxfxQeYBdQEF+718qgqO3V dDVrquvkQRo1wvMDerSmUjNtR3Thh4iRr3llil4Ya51ZZxoytOZDcv6zZU1pp9KffYYi lZjA== X-Gm-Message-State: AOAM532j9ZXLZbBtyykxBL9CZV47HgHFICWb1PZDyyTs6+E8PaqUiFfD Wo7NdudXbcgjBFLbQVeOuYB0uKIphaS5Yw== X-Google-Smtp-Source: ABdhPJxBU6nBU4wRcNGPxAHiXzhM3fhlUtNnuhprrA1S+M0bGgi/fJdYSA48+59zp5VoxHyldtoKQQ== X-Received: by 2002:adf:c641:: with SMTP id u1mr23731290wrg.332.1616937365150; Sun, 28 Mar 2021 06:16:05 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:04 -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 v6 13/19] fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h Date: Sun, 28 Mar 2021 15:15:45 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 31c9088e3f7..150fe467e43 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 a7e092d3fb4..66c4a71139a 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 Sun Mar 28 13:15: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: 12168969 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 F1064C433EB for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D50856196D for ; Sun, 28 Mar 2021 13:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231310AbhC1NQv (ORCPT ); Sun, 28 Mar 2021 09:16:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231143AbhC1NQH (ORCPT ); Sun, 28 Mar 2021 09:16:07 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A6C7C061762 for ; Sun, 28 Mar 2021 06:16:07 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id f22-20020a7bc8d60000b029010c024a1407so7179778wml.2 for ; Sun, 28 Mar 2021 06:16:07 -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=Ooc0gDUBZ8i80fVgZ25amsyHysLLBmREx3xHMXO2MiQ=; b=CvxvBM5mkafCYlvWNnqn9C7HwAceMElpAfAnBVE2gqPAP1y7w8NagZcf8RUhHz05Mp id4fwjsxG78j85kdlJydpH/Gz6V+M7DjzKyqykuCfE8zAJ+ecTB+7GuWSGBT+cJ/3QDc UO/zcJrTkcfbwexhUaKWg5i6B2aXnQdiE/wWlK5Z2G2mIJjyDz+Xd5mElBkX8gCmW0hs yHbBDEpUDRHOFpAjPnLk1+m7lKVfjukTVbXFT0dvNVuqJUC+hGw2c9xmdVwxAvG/ZlOn T9z4Mm74i+AgJ+67nqLB5ig0wY2xPLZJV/0gKDdsEFEw9JEELSbC/Dq2N24oHk6jp5R6 pV/g== 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=Ooc0gDUBZ8i80fVgZ25amsyHysLLBmREx3xHMXO2MiQ=; b=WrPNfZG6+cYmAm+An9v4wdDYLUKhAeGiuhn2bondlrXogPKRh+OF0eGLymGQ2Fizxx G1kmnE40H8Kt5Y6HB8rQoHnEU5fBC9V9qZGDkaZJuPE1JWLne/dwrxfUfhrQASQPxN5M VuJCoIjk0C8cX5EvFaN38O/a0xMlAxK8rV7bP0VXpTER/Xf9hscaFZiSY67QPHUg4WQR p3nRAKy7coHYq2cFzxYfSxquvzTgDoIggCQwE0oKG4UKCACMk9tPUqBUH4oObLnX49zI P7nNzHzDUKuq9N0peIMd9mEpc/xxbjJo3pZ24jrSQ2Onad86n5OXu6J3JL3h0M07P1sH 68aA== X-Gm-Message-State: AOAM530khSVsn+xRKY66Wn49hoLZ4QOyLZaKpe2JxkHEDyet1PT2BdWb +WnrH5aevdBwwci2GKLn1Ocbhgny1z+1eA== X-Google-Smtp-Source: ABdhPJw9+f7RJoH4hceVMW++Jf5OYys5HS13CdLzgh09BMxY9eUw4FTi0Xb363ZO05hk3q/p7+2ptw== X-Received: by 2002:a1c:4d09:: with SMTP id o9mr20697078wmh.15.1616937365870; Sun, 28 Mar 2021 06:16:05 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:05 -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 v6 14/19] fsck.c: pass along the fsck_msg_id in the fsck_error callback Date: Sun, 28 Mar 2021 15:15:46 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 17940a4e24a..70ff95837ae 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 8338b832b63..2f93957fb5e 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 052a510ad7f..96e63bc772a 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 150fe467e43..23a77fe2e0f 100644 --- a/fsck.c +++ b/fsck.c @@ -227,7 +227,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); @@ -1180,7 +1180,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 66c4a71139a..fa2d4955ab3 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 Sun Mar 28 13:15: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: 12168963 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 79885C433F2 for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 586046196B for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231322AbhC1NQw (ORCPT ); Sun, 28 Mar 2021 09:16:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231145AbhC1NQI (ORCPT ); Sun, 28 Mar 2021 09:16:08 -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 50B83C061762 for ; Sun, 28 Mar 2021 06:16:08 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so5305304wmi.3 for ; Sun, 28 Mar 2021 06:16:08 -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=X6TE3wc7OY6ofCSMD5RZKu2noK0DkRNhEq0/4vXIRws=; b=P5cOHglmZl0zDfZphWfpJYrGShoJG9QRImLHuodnAspFOvDzej0zzFYLvQzBvd03fO nOeCNv3egjAUOWIrvSuu2jL1u6AgJN6U5nQyQZwEpQ1Hz3hPxkisXNBn5oAYdhT+hs4H hOPxkmsxDEtqBvkG6c3Otpvx0GsZcKFH+wuq7ZOc8kNxj21LD6+GKLFuzK+QkL9lNnP6 r9yUAre6FuZHDKUzWOhLFvVA8THe8eyxYvwzHDvqAC0EO0jhLHiQlWho4QYtZXJ1x6b5 RYJtkc7GTivhYVXKxUSXxbqbM6y5MpJsYW6zGTICg7HhLNMkshtuh7y+19n0KMjkJSDJ urkw== 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=X6TE3wc7OY6ofCSMD5RZKu2noK0DkRNhEq0/4vXIRws=; b=Ak5B6m5QzK8okleD6nSt357hgzTdeAbV6sk7hneYL/n9IVpQ6PWV/e0KxODptvpgol Riett+qRfvO1XkgE8FlKrbhrqoTgJS3IQXbGAPEKqk4TJ1FX2GSocDDhCVZNMEczljB5 xAfJ/mNq7SmBFS7wOPN9Y51lsmoXBX9TNXO9LkdkZhWH8S4O0BHp2BpmGin/ibvRvW9b z6yaFX00IflfNfXTl5okYGWXVN3nK/TvaHrxlgC1bmCs0m0VdDggpTdaZK2ciFX0Y/tr XNvpFrZNYWwLfAjcvuwBq5hcA1xvHxZwqQrl16tifO2nWYBuaIcskVZAetoYPhswq5CT gSpA== X-Gm-Message-State: AOAM532G+tKy6x/SJcas5m5DX1QVfZ1QY8iNDlHUgY3potSPUw/sFwvG 0VgfJmyhlL0ESrcXZEisEgFKykDiRktukg== X-Google-Smtp-Source: ABdhPJy4CoomwjaAleIh6Ta4IGikLlsXrj/tmCtwIpnuZbMT55Avz2OZ5JTWzj8nSqUDlALuR5+LvA== X-Received: by 2002:a1c:7901:: with SMTP id l1mr21358072wme.114.1616937366806; Sun, 28 Mar 2021 06:16:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:06 -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 v6 15/19] fsck.c: add an fsck_set_msg_type() API that takes enums Date: Sun, 28 Mar 2021 15:15:47 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 96e63bc772a..dddcccdd368 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 23a77fe2e0f..a59832a1650 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 fa2d4955ab3..d284bac3614 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 Sun Mar 28 13:15: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: 12168967 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 8AAC7C433EC for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6EA9B6196D for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231329AbhC1NQx (ORCPT ); Sun, 28 Mar 2021 09:16:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231150AbhC1NQJ (ORCPT ); Sun, 28 Mar 2021 09:16:09 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 347F0C061762 for ; Sun, 28 Mar 2021 06:16:09 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 12so5228083wmf.5 for ; Sun, 28 Mar 2021 06:16:09 -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=L0jKUhbnAdlCRSN9qe3wlw58/aokVl+4Onhy95KtYSs=; b=RxCunq2C/iqavje+crlLezah9QAf8E6RI3g2suQKjqIg7Xkt0xpxRcDA4nZOr3+fyp vUwugzBk3zP4rN/eEfY1SoTxYHNVh7ygH9jcTGcYTfr66Ym6ZT86OJMVhTUH3GtbckMz 1Ugs9+EQVUqO3aqiHQoU8RNivVD1n+UzxwO68BNWpFhWqEcz/TRbwT26v7FkKMYQNhXZ ILcmSznzuZFYGKGy9lgS6Tganthk4B0uLFUhQlZSW8BGoaiekFVsuX28jJxXE5U3Dg70 Wo4qzkmeKrOqWVU5rIBxRYequEhJ8+d4F1EsHeA/hSHOYWxypefSqlS9NNR18mUXwmRE sC5Q== 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=L0jKUhbnAdlCRSN9qe3wlw58/aokVl+4Onhy95KtYSs=; b=ljlqJyKCWkaho5Vxl3bY9V/M8ZPcGLAygQo4NvKyVhZ2sjzaL+hKuvJc4Dndml09xY niL0jrBgWPx01a0APIZr5sp/Q/0tzoLlqhJkYT/GpQjmv0uySLgl0G1rrILneRvj0UVN 16TmriwyK/95GtA6QXUEWSX+edF8ikK0YXTto9DZwRFaNa5UtaHrihaRTv5Wt/8rfbPR NTTDPqokIlAUe5WHysE34CSeAclw6kyP6SKHuoS2N7skN2XfoQ/TPKWpKRPX7xGAziC1 MuDuUyUM5gNmutzbvjD7nJ/nYKL0D8C3sIGhOtQ8oYqTcsQufn07DXDTV4+O+WtZdKUm j8nw== X-Gm-Message-State: AOAM531ZTUT7Adk6Z/YpGbgbrgFiv7gx/+RMiXKgVNi7grasiCRYOsjo 69ngKKM92wkQx5d1VEO+OVrBnW96Z5uS8A== X-Google-Smtp-Source: ABdhPJz8TmQIb5EISgMLOWYgp2UFJ2GmeFz81LVaPSU+lza+z+KLrdh58nnVHMqBYd/aHUnMNAEpDQ== X-Received: by 2002:a1c:1f8e:: with SMTP id f136mr10657251wmf.185.1616937367654; Sun, 28 Mar 2021 06:16:07 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:07 -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 v6 16/19] fsck.c: move gitmodules_{found,done} into fsck_options Date: Sun, 28 Mar 2021 15:15:48 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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. An earlier version of this patch removed the small amount of duplication we now have between FSCK_OPTIONS_{DEFAULT,STRICT} with a FSCK_OPTIONS_COMMON macro. I don't think such de-duplication is worth it for this amount of copy/pasting. Signed-off-by: Ævar Arnfjörð Bjarmason --- fetch-pack.c | 2 +- fsck.c | 23 ++++++++++------------- fsck.h | 9 ++++++++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/fetch-pack.c b/fetch-pack.c index fb04a76ca26..0f898a5ae14 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 a59832a1650..642bd2ef9da 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 { @@ -606,7 +603,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, @@ -620,7 +617,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, @@ -1132,9 +1129,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; @@ -1199,9 +1196,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) @@ -1210,13 +1207,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); @@ -1241,8 +1238,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 d284bac3614..e20f9bcb394 100644 --- a/fsck.h +++ b/fsck.h @@ -118,15 +118,21 @@ 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; }; #define FSCK_OPTIONS_DEFAULT { \ .skiplist = OIDSET_INIT, \ + .gitmodules_found = OIDSET_INIT, \ + .gitmodules_done = OIDSET_INIT, \ .error_func = fsck_error_function \ } #define FSCK_OPTIONS_STRICT { \ .strict = 1, \ + .gitmodules_found = OIDSET_INIT, \ + .gitmodules_done = OIDSET_INIT, \ .error_func = fsck_error_function, \ } @@ -146,7 +152,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 Sun Mar 28 13:15: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: 12168971 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 8DDB4C433F7 for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E8CF6196C for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231332AbhC1NQy (ORCPT ); Sun, 28 Mar 2021 09:16:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231163AbhC1NQK (ORCPT ); Sun, 28 Mar 2021 09:16:10 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46288C061762 for ; Sun, 28 Mar 2021 06:16:10 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id n11-20020a05600c4f8bb029010e5cf86347so7487749wmq.1 for ; Sun, 28 Mar 2021 06:16:10 -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=tyrEqDr1cbgxRGlepMxgPedJ6jhbIsGGF/CxDBIqJRI=; b=gk8DF54qa4nC8l8jYLlbZpVK5fN/3O1i9apx4mjVMVSHAkJedKMJa1Nf0y9xX+jnip unr/Wc24azof35fl08YUZmDrs+eXSVZHWWNXC6XkWbffAPEPcoW3bjrnRTMxGuGkU6Xp 2m8dWyQ3oeeZxVRH0Cn9F6lfNF/jOlZWmB4zDdb39+63+YqOIYA9RSO+rmOV0hY8ydB9 l+Wr3QYLEnZvVkORHlN5U42FkFbNhBl11t9oZIfBEKTsjX3+Ib0x4hmZy6BGEiTc+caR FFJXHE7DngCbwJ1x3pTEtupI3Yd67aHa5SFkWWd+vLDKChicCYjd/TTbyYdChMUqszJ1 mKRg== 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=tyrEqDr1cbgxRGlepMxgPedJ6jhbIsGGF/CxDBIqJRI=; b=lnfKpswsdSy6nMtlnf0s/wnDikrzcEGSSg/wK4IXDQMsShrK0Kb7LmRW5JbyxeiOb7 diGuaKVZxXIcr+z8621EBsghJm3/OYkvKq+FTVtLzdilwiPMPya5qJ2rGmIYmPkv/egR OsDcaB7p8qB0A8jMvm4MYJKe+Cf1FMnuQ8REFWVYUhdJgD2yaczDGT/qMyCPe91BUTrw 13N2onAJ09kiWGZ0vww5TWgVLVbheFCWozpxD7af+TV4GzNXLAOybSFH7Tx5nXHYD0mn SKA2sjRvreFg9QB6+4jm0NVkmO4uSHsvJqwWrfkBtzFkVEYb5LdGLSkXnB0tlsfs9EVZ ZBLQ== X-Gm-Message-State: AOAM530hdC+pt5HnSgFuC2RwLmTtovIdURd14QzoZKUFnwwLFmDeDczm YJv0rkqnkI9HiI34efzPXlP6sdYRtNPRcA== X-Google-Smtp-Source: ABdhPJzNTjSzmcJSLfKm79IPr/doeuiV1kkhuJKs4VmxXnN3StyzssgnYXlq9c2/zA3ebDUV0FoYEQ== X-Received: by 2002:a1c:a958:: with SMTP id s85mr21467138wme.4.1616937368768; Sun, 28 Mar 2021 06:16:08 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:07 -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 v6 17/19] fetch-pack: don't needlessly copy fsck_options Date: Sun, 28 Mar 2021 15:15:49 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 2f93957fb5e..5b7bc3c8947 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 Sun Mar 28 13:15: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: 12168977 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 A0852C433F4 for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 902586196E for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231340AbhC1NQy (ORCPT ); Sun, 28 Mar 2021 09:16:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231176AbhC1NQL (ORCPT ); Sun, 28 Mar 2021 09:16:11 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F8E5C061762 for ; Sun, 28 Mar 2021 06:16:11 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id x13so10142810wrs.9 for ; Sun, 28 Mar 2021 06:16:10 -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=Z8/ZaRVDenYkZyomOTvSsvbNt712bd4wtm183qMayjo=; b=KhnniZRRxNqQSXuM5KZ3CXX0RSHyN912Y4il+VdJuaeF2bBmamA8xKJ4BWdh6EO0I1 vHnf0JmhAyZzloJ7QIJtUO90Ujf+Kvwy0YoRBIr0hXbROqSjmKpfYhVmhIHJ9EYD97Jw U55DtOiLwZHuPbGj37OwNuaaTlMMzv+9t9xG673J+q1wGDl4LTCJsxE8O5Pwi95N89Zz CF4A8YCMs/WyouSHswXK8ZxrTAxr/RKS8Mq4bvmQru484jg5cmQFXPKl2LmTePq682vf J2ihdIXq3p9LGYJ4r9uV/IJwPaf0CvfN90vVw3t8neQ4iMVnCLgMNoQL3o+i4exH2PuK 5+Dg== 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=Z8/ZaRVDenYkZyomOTvSsvbNt712bd4wtm183qMayjo=; b=NhlYwJSsfmNpsK5vwUXWJry5ZfmEwjGiGHe/NcSlVQRrcq8tc6A+7RPhe7eKRN1oV7 MRSiBuG6FWTgqnRjfo8mQsyS3+MxkASltjx0JU40oOzYWhGN0L+fNcvAERB14b4kUJ2j +1fq2EKIX7ED3SAQ/4yvGYb79O5lu59kl7q4B5upYnAnlX2x+rBDtX56XcSWAZth0DzS waS1bvgXPnhOSv1TXZu7L1KYSLAn0Pp+lFU7LetU+gA2JuZslHq9Dzk/SoPHf4jzZ3Th AvR9QmclSeExZgowmKD4jTQdX2fuyw1p2ttaQ+YrQXoxOJyuvGu/eEYmwPCMawAuvNat /h4A== X-Gm-Message-State: AOAM5306N9R9+mXrxOgw0EiL7RzAzt3RR1Vs13VnmiaxN8TpinXfJ7Rx oK+oq3WAXARF7GkAHC5Sn6wJ7Gi7+vtDEA== X-Google-Smtp-Source: ABdhPJzyL8rnm3mqdnbU+ovpXcgzU+gfm1cQGmYr117NIjPFsiq8R4xzy/sOf8KoRV3QpZIcrel1mw== X-Received: by 2002:adf:ff8c:: with SMTP id j12mr23852143wrr.297.1616937369550; Sun, 28 Mar 2021 06:16:09 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:09 -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 v6 18/19] fetch-pack: use file-scope static struct for fsck_options Date: Sun, 28 Mar 2021 15:15:50 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 0f898a5ae14..4ec10a15852 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 Sun Mar 28 13:15: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: 12168975 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,URIBL_BLOCKED,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 BFA85C433F8 for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A37CF6196B for ; Sun, 28 Mar 2021 13:17:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231344AbhC1NQz (ORCPT ); Sun, 28 Mar 2021 09:16:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbhC1NQM (ORCPT ); Sun, 28 Mar 2021 09:16:12 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48A7AC061762 for ; Sun, 28 Mar 2021 06:16:12 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id x7so10146124wrw.10 for ; Sun, 28 Mar 2021 06:16: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=APkrASEGB0c+lMjL7w3tlbh+o93gXeNIvIoHLaesxJ0=; b=HsMg/Tpoyx0bYBvlSMpi4DeuSW3f4aW96lV6FDaD26/k69etdbeTk41evF4mB6HdR9 h1i0ud/TIbUctZ9T5kduxbiIBxNfTP5bfPfKxewlGdq4M5HJf0PuW6xgh6NIeKdwtOiN Hgu0KmJs47y3ZYzza2NLMlx0yIA+hX+gG5jQaP4/BFPpEd0Y3nhaYSTbDIf+n9tOS4dU tGRibM5iixHoz63/wp3nbu2vJeN4FnOYx0JEr4eOyqZEeZYIsA98oUlO5IAukMrDfwsX p4Icvi7KHCuJLcx11Fzdoc707QGJypA76YwwQ20lnrq3dLC8bA/AiL1o5URmjKAoXWUD SbvA== 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=APkrASEGB0c+lMjL7w3tlbh+o93gXeNIvIoHLaesxJ0=; b=CpTyfaU04nLba/2gINmSfy0z1lXgCxmsH3oD9+LYO+jqdMQM451yXbxBxaYHJSZv+1 HhRUhUTzJjnCll0K6ulCL1KN1jCLKW8BWkXDIMRUzOhkMMMhRhTn88qSwcoewpbIbvIR PIcSpnwITuQzXaysVqZrE0N8KqbMKKIET56txWFe4O+CthEiuLJPG2/e43kARev77Vbt yOXDmFUoKQujdcpTnJPMf9wIVlRW5sK0FCSrSxwVdnJYqTbFVJEIWQI/l2fFGAoAusYh K/W+Tc8m9DY5S6V+5N9GwBajn3BxUAQxhUdiwtULzLCB1xRxNmDHpL4BXG4XekfeSy+S 3Dww== X-Gm-Message-State: AOAM533P3ZfHTQ1SSN0Xtw5xXdtvWvIUfIdkBKaUXE8AIKMUaOZ6TPH5 4oTCLT0FwFjMh7m4do0YyX7BTC7Rhl2x9A== X-Google-Smtp-Source: ABdhPJyV9yPcBX39coR/9cHvWJn8EGf/s+er7rIduyGphGVUh1DX7/wkxoBerJc/zjarGDSojlKbrw== X-Received: by 2002:a5d:6ca6:: with SMTP id a6mr23419192wra.179.1616937370378; Sun, 28 Mar 2021 06:16:10 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm27364935wrd.55.2021.03.28.06.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 06:16:09 -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 v6 19/19] fetch-pack: use new fsck API to printing dangling submodules Date: Sun, 28 Mar 2021 15:15:51 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.445.g087790d4945 In-Reply-To: References: <20210317182054.5986-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 | 31 ++++++++----------------------- fsck.c | 23 ++++++++++++++++++----- fsck.h | 15 ++++++++++++--- 4 files changed, 39 insertions(+), 51 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 5b7bc3c8947..15507b5cff0 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 4ec10a15852..c80eaee7694 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; @@ -988,21 +988,6 @@ static int cmp_ref_by_name(const void *a_, const void *b_) return strcmp(a->name, b->name); } -static void fsck_gitmodules_oids(struct oidset *gitmodules_oids) -{ - struct oidset_iter iter; - const struct object_id *oid; - - if (!oidset_size(gitmodules_oids)) - return; - - oidset_iter_init(gitmodules_oids, &iter); - while ((oid = oidset_iter_next(&iter))) - register_found_gitmodules(&fsck_options, oid); - if (fsck_finish(&fsck_options)) - die("fsck failed"); -} - static struct ref *do_fetch_pack(struct fetch_pack_args *args, int fd[2], const struct ref *orig_ref, @@ -1017,7 +1002,6 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args, int agent_len; struct fetch_negotiator negotiator_alloc; struct fetch_negotiator *negotiator; - struct oidset gitmodules_oids = OIDSET_INIT; negotiator = &negotiator_alloc; fetch_negotiator_init(r, negotiator); @@ -1134,9 +1118,10 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args, else alternate_shallow_file = NULL; if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought, - &gitmodules_oids)) + &fsck_options.gitmodules_found)) die(_("git fetch-pack: fetch failed.")); - fsck_gitmodules_oids(&gitmodules_oids); + if (fsck_finish(&fsck_options)) + die("fsck failed"); all_done: if (negotiator) @@ -1587,7 +1572,6 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, struct string_list packfile_uris = STRING_LIST_INIT_DUP; int i; struct strvec index_pack_args = STRVEC_INIT; - struct oidset gitmodules_oids = OIDSET_INIT; negotiator = &negotiator_alloc; fetch_negotiator_init(r, negotiator); @@ -1678,7 +1662,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, process_section_header(&reader, "packfile", 0); if (get_pack(args, fd, pack_lockfiles, packfile_uris.nr ? &index_pack_args : NULL, - sought, nr_sought, &gitmodules_oids)) + sought, nr_sought, &fsck_options.gitmodules_found)) die(_("git fetch-pack: fetch failed.")); do_check_stateless_delimiter(args, &reader); @@ -1721,7 +1705,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, packname[the_hash_algo->hexsz] = '\0'; - parse_gitmodules_oids(cmd.out, &gitmodules_oids); + parse_gitmodules_oids(cmd.out, &fsck_options.gitmodules_found); close(cmd.out); @@ -1742,7 +1726,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, string_list_clear(&packfile_uris, 0); strvec_clear(&index_pack_args); - fsck_gitmodules_oids(&gitmodules_oids); + if (fsck_finish(&fsck_options)) + die("fsck failed"); if (negotiator) negotiator->release(negotiator); diff --git a/fsck.c b/fsck.c index 642bd2ef9da..f5ed6a26358 100644 --- a/fsck.c +++ b/fsck.c @@ -1196,11 +1196,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; @@ -1266,3 +1261,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 e20f9bcb394..7202c3c87e8 100644 --- a/fsck.h +++ b/fsck.h @@ -111,6 +111,12 @@ int fsck_error_function(struct fsck_options *o, const struct object_id *oid, enum object_type object_type, enum fsck_msg_type msg_type, enum fsck_msg_id msg_id, const char *message); +int fsck_error_cb_print_missing_gitmodules(struct fsck_options *o, + const struct object_id *oid, + enum object_type object_type, + enum fsck_msg_type msg_type, + enum fsck_msg_id msg_id, + const char *message); struct fsck_options { fsck_walk_func walk; @@ -135,6 +141,12 @@ struct fsck_options { .gitmodules_done = OIDSET_INIT, \ .error_func = fsck_error_function, \ } +#define FSCK_OPTIONS_MISSING_GITMODULES { \ + .strict = 1, \ + .gitmodules_found = OIDSET_INIT, \ + .gitmodules_done = OIDSET_INIT, \ + .error_func = fsck_error_cb_print_missing_gitmodules, \ +} /* descend in all linked child objects * the return value is: @@ -152,9 +164,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).