From patchwork Fri Mar 17 05:01:06 2023 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: 13178520 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8620C74A5B for ; Fri, 17 Mar 2023 05:01:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229808AbjCQFBV (ORCPT ); Fri, 17 Mar 2023 01:01:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbjCQFBT (ORCPT ); Fri, 17 Mar 2023 01:01:19 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E11C5A920 for ; Thu, 16 Mar 2023 22:01:17 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id l12so3338164wrm.10 for ; Thu, 16 Mar 2023 22:01:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679029275; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jq6EtT3ivDdJlpJBGbRAFd/+oTBhB0RxGrEbZmVA5r4=; b=CfCu0hutIfoirpPgiFRaFD25DxepdcqUFe+2MR5BFMc4rOMBKNhq+vHkVQGVUjs6lY s81aRKlZzSbT4Ck0kdh6MsH0twVasOqKYDrdP4kIRfMs8KDGNaxH1P2lv2LFtxpVLNY/ pfwjQpxQFX4WFp08UcoWA10pZSqLjGtByyIyHBzEUfNSVe0oNuI12iO7LbZzfxLxzXMd 2Fp19IKuK+Dn7vX/Gw3Pj/qMe7qY2uLjnIAITBojNLVMqStetUtzCGYtVSYgMP1M+/9D d5NV6bCMayOUPEmSe1IwK2Xbe5YpaStG/ZZ7kiCvKUNG7D7MS22Mn1czJT/fM+LmBfC/ N3aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679029275; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jq6EtT3ivDdJlpJBGbRAFd/+oTBhB0RxGrEbZmVA5r4=; b=tb9dSOCrBsqlaRJCHMvz21m/bo9IBgEX6OgFERjs7MsNZFoLTSfEFhH9qUh+o0fX5t GMazCE9EKUueb2AICKr0dx1bZyk4Fa6GmCSxTRhYWWqVh9tqgKaedvxL+1ZYlLA7r1CT FHBNTRdXdOQsaW8g+eyLo9OK5G2TwuUfF6XYgit9wvxv5c3O7xVq2UQvR3RsfDhqG3c8 LQSf7PN40giTLYq5vqCBTTa5VPwOiSFGBWdFG8ayel59Vr2Ra95kes+Xgs5n9HV7wE1A oeKsSXf0tJ8vCEkMNEkYNXtXfiTZQ2LSmwrOM00BBFE7E6B6uGKR8+XvYyjTfWbc5uWV 0cFQ== X-Gm-Message-State: AO0yUKVOvcdb9/W6BM1d+7YA/JkVsQKI+J/h6dt9DRPvHalyqzxAj1v/ zNN77p0WCOVCNUsge0hWMdhMnlvUm6bHMw== X-Google-Smtp-Source: AK7set9WVTu1R2ltZwVmyGPOv1fx1LBLoaZLRX5JFtBoQqMMMMpbg0NyROfTjNu99C0khdLQ5Csusg== X-Received: by 2002:a5d:5234:0:b0:2ce:a3c7:d2a4 with SMTP id i20-20020a5d5234000000b002cea3c7d2a4mr1292926wra.25.1679029275301; Thu, 16 Mar 2023 22:01:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g9-20020a5d4889000000b002c559843748sm1027844wrq.10.2023.03.16.22.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 22:01:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Jonathan Tan , Junio C Hamano , Jeff King , Emily Shaffer , Derrick Stolee , Calvin Wan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC PATCH 1/5] config.h: move up "struct key_value_info" Date: Fri, 17 Mar 2023 06:01:06 +0100 Message-Id: X-Mailer: git-send-email 2.40.0.rc1.1034.g5867a1b10c5 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the declaration of the "struct key_value_info" earlier in the file, in a subsequent commit we'll need it shortly after this line. Signed-off-by: Ævar Arnfjörð Bjarmason --- config.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/config.h b/config.h index 7606246531a..571b92d674a 100644 --- a/config.h +++ b/config.h @@ -110,6 +110,13 @@ struct config_options { } error_action; }; +struct key_value_info { + const char *filename; + int linenr; + enum config_origin_type origin_type; + enum config_scope scope; +}; + /** * A config callback function takes three parameters: * @@ -612,13 +619,6 @@ int git_config_get_expiry(const char *key, const char **output); /* parse either "this many days" integer, or "5.days.ago" approxidate */ int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now); -struct key_value_info { - const char *filename; - int linenr; - enum config_origin_type origin_type; - enum config_scope scope; -}; - /** * First prints the error message specified by the caller in `err` and then * dies printing the line number and the file name of the highest priority From patchwork Fri Mar 17 05:01:07 2023 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: 13178521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7C9DC74A5B for ; Fri, 17 Mar 2023 05:01:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229842AbjCQFBY (ORCPT ); Fri, 17 Mar 2023 01:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229541AbjCQFBT (ORCPT ); Fri, 17 Mar 2023 01:01:19 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CD79B06D5 for ; Thu, 16 Mar 2023 22:01:18 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id v16so3373156wrn.0 for ; Thu, 16 Mar 2023 22:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679029276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TVgrrDQ7TZ9L5crFTK76RMSQO1cZr2KVRQQQ/Vcs+qE=; b=hU8GknUWguX34IFnr6S/H3SudGMx4WDXbVOZAgmTvOBqQWqcJucDyEahT97IfLDHya q8wa1SxD+nz//udwrg1DgBTQfWJx3QvtxN989gX4ZPhGynVRRJyiV1P0A+pYmr+U0pjp ohpFH0S+wLM/WP7YI54L4qUZOJPbkhDtcFoA70MAe9JSVunStMTK97feQRlPIf9irwk7 ny2FaA6j0fKY1DxaW86ok0ucrFtDYbUdgNBmyVBzI/N/RQTrgbPjuF0DofS4SIMrpb50 ThPrfqoNDGgSPOzCShXGsaCFOijtoNGcm4GKL6QgyexQIgmmY2Eof/phQEySyCec+q2d SOGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679029276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TVgrrDQ7TZ9L5crFTK76RMSQO1cZr2KVRQQQ/Vcs+qE=; b=4+z1pEZaRfa59FSCLQ9dKL9wlz/TwRTwRvmT3QFXE4DcJTSLZEXiQhy+zStGq2x+0x rtaknq7OZhaAeZP5TN0B6vVKvvYeVHzHRRR57zY22PH46+PgxEqyIQzsgcZ1xmmUlGFR 7YgwI5hiBj0YUFUBQYc0uXu25lXtZKxVwxh9ailuRzMPLFWt6JgSK8BlBgmjnFbxZYLO AUI0F4ry/Y3CidFaUIL4a+AWsF7QGyBW2yX5Q1Pwz3W04/O/Yj3mDQ9jL0M8gyjnGdys NOhIXXcstcNQU8ajtxVkxPXVzumVbVWTfCGDijNxLu04xVKxR+5jFR5W8xs9DkET5NDY OrXg== X-Gm-Message-State: AO0yUKVo7WarMol0Zl9477bUCah+kOl1unhVUTfsGa2b6lp6ih0eXfeh W26xIyL9g0P1QXK2NtvkvSYquG0G6S6AVQ== X-Google-Smtp-Source: AK7set9LdA6rVCiDgtggsI2/jQdJqHfmrHavS7JmMrZZ9f5/c+c9Fmuy/lw4habXtKKYarECeKXtKQ== X-Received: by 2002:a5d:674c:0:b0:2ce:aace:5b27 with SMTP id l12-20020a5d674c000000b002ceaace5b27mr5706347wrw.11.1679029276555; Thu, 16 Mar 2023 22:01:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g9-20020a5d4889000000b002c559843748sm1027844wrq.10.2023.03.16.22.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 22:01:15 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Jonathan Tan , Junio C Hamano , Jeff King , Emily Shaffer , Derrick Stolee , Calvin Wan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC PATCH 2/5] config.c: use "enum config_origin_type", not "int" Date: Fri, 17 Mar 2023 06:01:07 +0100 Message-Id: X-Mailer: git-send-email 2.40.0.rc1.1034.g5867a1b10c5 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the current_config_origin_type() function to use the appropriate enum type for its "type" variable. Signed-off-by: Ævar Arnfjörð Bjarmason --- config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 00090a32fc3..a4105c456c3 100644 --- a/config.c +++ b/config.c @@ -3768,7 +3768,8 @@ int parse_config_key(const char *var, const char *current_config_origin_type(void) { - int type; + enum config_origin_type type; + if (current_config_kvi) type = current_config_kvi->origin_type; else if(cf) From patchwork Fri Mar 17 05:01:08 2023 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: 13178522 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B46D4C74A5B for ; Fri, 17 Mar 2023 05:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229887AbjCQFB1 (ORCPT ); Fri, 17 Mar 2023 01:01:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbjCQFBU (ORCPT ); Fri, 17 Mar 2023 01:01:20 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7B04B06F4 for ; Thu, 16 Mar 2023 22:01:19 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id j2so3343689wrh.9 for ; Thu, 16 Mar 2023 22:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679029278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/Ickpqw+K6y4SumjjnKJNV2kz2xj6SGxndDC7UGmBHA=; b=OKUmwZUymeNuoioXpqX0rASWtNTJ9rjGvwAjk2hwZ9Vbn6klb1hY1e1SlMtkNT7DF5 O8Ak/1ZuQtw/eMCgRV0EXvNyTBGu62RmtAIATzWpPXe6L4ALloL4f+zL9Bga6EI0K5Wp PyoztvdT1nws/a47Vo3nyoRUSDYlGYTzaXOZHhu5ZRE2SfVufk0AESsspk18m8PDlWiC A6G0KU+BmMdCbBLECuQr3OMDDlw1LnMM/u7fjvLKb4SWGa/1cIpp3sR1YXZbDWMuESEj 0K/dsRLGezSzk2+wJV1rgJdzRFRtLRJdyHFR/dwWa57CcWhuj1rcrOR70/FBd+AtcZsD Jw/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679029278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/Ickpqw+K6y4SumjjnKJNV2kz2xj6SGxndDC7UGmBHA=; b=GkggaRWf3fps+ylGnY1sBaD3Z8y3AArNBrCKSdE16z+0xBA1dVKhNo+LABXDWrtqHO Hf0hblT12zeLuAjfuLb3k4RSHWeCLUVjbP5alIvSgFF6Rn+xggTSkyfFlFonC9pfpSxs +6aYvG+QrmK28D7DYbibUUpgIlZBKZuHzE0vPISDF9guPaC2dBrUH4mtKYx0pWjw1j+N qGLFF+q3WHjePExaBe7bQFuqYji4jWjzU6HYu+cRqJN18uFfjZV5n9Q7lsDJ31otPf/u vlHxKPkQWJeXG9vdsCqXzLFm2h7xqqbKN5GO8s8lHkSbCHjcKTOAUVVmF+4seX5xtbV5 06VQ== X-Gm-Message-State: AO0yUKV7VVoRDLrUd0w29BmrM8pTjdQ9iIjh5fMMDr23oZi4cvVUC2XZ r6JfZH7nVApuVIFgFxM3/H18CGBqEeSAYQ== X-Google-Smtp-Source: AK7set/hj9KQPpYNhZkscBemkPKrCo5VbmGHomCDBorvCO4H9L6hPhBHzY2GbE1nkhJK8hZjh/3swA== X-Received: by 2002:a5d:6044:0:b0:2cf:e956:9740 with SMTP id j4-20020a5d6044000000b002cfe9569740mr1186134wrt.6.1679029277636; Thu, 16 Mar 2023 22:01:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g9-20020a5d4889000000b002c559843748sm1027844wrq.10.2023.03.16.22.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 22:01:16 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Jonathan Tan , Junio C Hamano , Jeff King , Emily Shaffer , Derrick Stolee , Calvin Wan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC PATCH 3/5] config API: add a config_origin_type_name() helper Date: Fri, 17 Mar 2023 06:01:08 +0100 Message-Id: X-Mailer: git-send-email 2.40.0.rc1.1034.g5867a1b10c5 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a config_origin_type_name() helper function. In a subsequent commit we'll want to invoke this part of current_config_origin_type() without requiring the global "current_config_kvi" or "cf" state. Signed-off-by: Ævar Arnfjörð Bjarmason --- config.c | 25 +++++++++++++++---------- config.h | 6 ++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/config.c b/config.c index a4105c456c3..a65e7bb36d3 100644 --- a/config.c +++ b/config.c @@ -3766,17 +3766,8 @@ int parse_config_key(const char *var, return 0; } -const char *current_config_origin_type(void) +const char *config_origin_type_name(enum config_origin_type type) { - enum config_origin_type type; - - if (current_config_kvi) - type = current_config_kvi->origin_type; - else if(cf) - type = cf->origin_type; - else - BUG("current_config_origin_type called outside config callback"); - switch (type) { case CONFIG_ORIGIN_BLOB: return "blob"; @@ -3793,6 +3784,20 @@ const char *current_config_origin_type(void) } } +const char *current_config_origin_type(void) +{ + enum config_origin_type type; + + if (current_config_kvi) + type = current_config_kvi->origin_type; + else if(cf) + type = cf->origin_type; + else + BUG("current_config_origin_type called outside config callback"); + + return config_origin_type_name(type); +} + const char *config_scope_name(enum config_scope scope) { switch (scope) { diff --git a/config.h b/config.h index 571b92d674a..a9cb01e9405 100644 --- a/config.h +++ b/config.h @@ -117,6 +117,12 @@ struct key_value_info { enum config_scope scope; }; +/** + * Given the "enum config_origin_type origin_type" + * (e.g. CONFIG_ORIGIN_BLOB) return a string (e.g. "blob"). + */ +const char *config_origin_type_name(enum config_origin_type type); + /** * A config callback function takes three parameters: * From patchwork Fri Mar 17 05:01:09 2023 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: 13178523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA327C6FD1D for ; Fri, 17 Mar 2023 05:01:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbjCQFB3 (ORCPT ); Fri, 17 Mar 2023 01:01:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbjCQFBW (ORCPT ); Fri, 17 Mar 2023 01:01:22 -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 D2190B06D5 for ; Thu, 16 Mar 2023 22:01:20 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id c8-20020a05600c0ac800b003ed2f97a63eso4387390wmr.3 for ; Thu, 16 Mar 2023 22:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679029279; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZJa2gU4qnwkxG7CMb6TZDE2ZBj0ctRC6a/a9Vj+Ar0A=; b=FE8TUCy13WakKPRLackd9pR+/6FVL5wfQyPlXAVitTDrxClWjwKSKZpJQbR50W7Dyp w2YHWsLb1l/Rr+bl5z5KL3NgquN4xqNgkFKz+VzQU0cnNwXNyyx9+JNnz/r00EwoWHbs 63YY/dfhiXFR1uba9vIir6b4tJXCwU3FJy031CDOj5ZPt3S2OQ4UBYjkRmuzjaScRY+V 0d+mcI0nAnXa6FfFffZekIx1oOkRqAmc7CM0Lg9hedceFmEXGnooPScWpEKWhn1X9u6S rrb6Q55ooM48Jr+G5hP78cvBzC+t/5pNOWMUliN4chIsUwIMNscjZVe3YrXUZ9X7qQB1 i+Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679029279; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZJa2gU4qnwkxG7CMb6TZDE2ZBj0ctRC6a/a9Vj+Ar0A=; b=ZXtM/gVD0n1Nl/+5KHXSZxkcstEUbTfH/eB/Z/CcCl0eWz1s03yQLQBgMP6F7P6m0p irqMm7elsMAiipkQzhSa1PzPCzhfCnjKMl+L8rlPvLze+ac3PEcvfMHZZ6DYocRowEfl AemjGaEjMa6RHwewbsQaP7qnm5a1WtCNBRr3XA3wQBQl05GMLbWGCjDgge0yUVKf2iwu rI/uC6zl10Hx3gjzySPQ8I7fSiiDibejMyCtMqZiAkAqvOXp31jzmbaZ3nVVHLEgR6CH UqNk3GHgN4JXn1Ou4ZGcz5nVrx9U1a/Krwq6IrksjU1i6oBLP9aQ7PnN/9ugXRW11Z9+ 1NTA== X-Gm-Message-State: AO0yUKWhhHQef1SdfEqenXLOYGLROoYtjWutC0H06QWE58K9IJaC0gPJ IRb93cNPh9JZfKjeE62ot0gS+FcD9JsTFw== X-Google-Smtp-Source: AK7set8L7/ThHF6ampJ7RdK2iOLoRDOv0bf/qGU7kj2En2bdsRhUNqizbX9bCn+tCnRz1Oh6jkgwUw== X-Received: by 2002:a05:600c:458b:b0:3ed:23e5:e6ae with SMTP id r11-20020a05600c458b00b003ed23e5e6aemr15888065wmo.34.1679029278895; Thu, 16 Mar 2023 22:01:18 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g9-20020a5d4889000000b002c559843748sm1027844wrq.10.2023.03.16.22.01.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 22:01:18 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Jonathan Tan , Junio C Hamano , Jeff King , Emily Shaffer , Derrick Stolee , Calvin Wan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC PATCH 4/5] config.c: refactor configset_iter() Date: Fri, 17 Mar 2023 06:01:09 +0100 Message-Id: X-Mailer: git-send-email 2.40.0.rc1.1034.g5867a1b10c5 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use variables rather than long lines in configset_iter(), and use our own "kvi" rather than relying on the global "current_config_kvi" within this function. There's no functional change here, but doing this will make a subsequent functional change smaller. Signed-off-by: Ævar Arnfjörð Bjarmason --- config.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/config.c b/config.c index a65e7bb36d3..230a98b0631 100644 --- a/config.c +++ b/config.c @@ -2227,17 +2227,22 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data) struct configset_list *list = &cs->list; for (i = 0; i < list->nr; i++) { + const char *key; + const char *val; + struct key_value_info *kvi; + entry = list->items[i].e; value_index = list->items[i].value_index; values = &entry->value_list; - current_config_kvi = values->items[value_index].util; - - if (fn(entry->key, values->items[value_index].string, data) < 0) - git_die_config_linenr(entry->key, - current_config_kvi->filename, - current_config_kvi->linenr); + key = entry->key; + val = values->items[value_index].string; + kvi = values->items[value_index].util; + current_config_kvi = kvi; + if (fn(key, val, data) < 0) + git_die_config_linenr(entry->key, kvi->filename, + kvi->linenr); current_config_kvi = NULL; } } From patchwork Fri Mar 17 05:01:10 2023 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: 13178524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF504C6FD1D for ; Fri, 17 Mar 2023 05:01:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229844AbjCQFBa (ORCPT ); Fri, 17 Mar 2023 01:01:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbjCQFBX (ORCPT ); Fri, 17 Mar 2023 01:01:23 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B17B06E2 for ; Thu, 16 Mar 2023 22:01:20 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id i9so3355246wrp.3 for ; Thu, 16 Mar 2023 22:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679029280; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bsaVfHXBcKemTCXldc4n+DmxkKkZetZryL+LR9ilXo0=; b=I7cQwRXb/TRzhVpfIDiwLBNhvQ+H86YSfap7LJAWbnn2jCvzs8OH13hQN3uIQT7GLo EOHpnqGMbS5JG7yhvcyMS0jiRu4hMoYGlR2ebRHI6thVptCHtCHJqMzornLlwGXxEzDY 3n7gdujqPWgro5WNeaJmOmApGxP+13wxLYF8qbt075Qp8+rfdc9rR3og4v3Qdg3oIPAB YKy9ZJYpyVIticNEo+YsESUgtobtBStHTWmMGfgk4cNVm5mNFie63OQjwudrnGouwyHv jlerCWuMQ4Pt0iXdcri3etp468+VCLkHiJwaE2AKQVbMXLmzL+ZxMLGGX73FKLMN/O8F Mwew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679029280; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bsaVfHXBcKemTCXldc4n+DmxkKkZetZryL+LR9ilXo0=; b=Ua74VRy8RrwQ/+c1fdyziF1XtzeaWrOPFu+fQiBE4H0SQFDozHCyKb+aEKtTh+6yvx I30gHD5ALUVzKdT+M0uV6QHsZDzNivQXw40KWu2XGzB4ufL+7M/nqmGUcnPEgIBViZjO IioVbjBuX2YMd9jLw3/SGsiY1F1lRDDOfWHwZQr73ABV3f3f6g18JIB31H1VTnOO8PWT S+ddTbtxk06Fj5BtYF4uAckVvsR69n8q1DZ6f89Nto0TUEH1meeL2wCpOo1LPDIAso4J 6i4KmjYaKz2r4buwtko0eGz8GrcchwXI8sIr4mBmH4aoFdmkDTMJd2ojQcG4GzXuwcSS NYHw== X-Gm-Message-State: AO0yUKV9TW11MYD1ou0xTMYoKqiCCRXhWLZ94NLA6hH4+xHgfTa2h2Zh ovfaKpQHSTpr1M4jj2jkVFwddL/iyY0T2w== X-Google-Smtp-Source: AK7set9Iw72u3mgJzDTf3QEJTdf315ZaN7z7jjAvdsu0oazM6dCF0D4dv69G2opTIChUJgR+AaIUOQ== X-Received: by 2002:a5d:5010:0:b0:2d0:d73a:7671 with SMTP id e16-20020a5d5010000000b002d0d73a7671mr4807614wrt.22.1679029280015; Thu, 16 Mar 2023 22:01:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id g9-20020a5d4889000000b002c559843748sm1027844wrq.10.2023.03.16.22.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 22:01:19 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Glen Choo , Jonathan Tan , Junio C Hamano , Jeff King , Emily Shaffer , Derrick Stolee , Calvin Wan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [RFC PATCH 5/5] config API: add and use a repo_config_kvi() Date: Fri, 17 Mar 2023 06:01:10 +0100 Message-Id: X-Mailer: git-send-email 2.40.0.rc1.1034.g5867a1b10c5 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Introduce a repo_config_kvi(), which is a repo_config() which calls a "config_kvi_fn_t", rather than the "config_fn_t" that repo_config() uses. This allows us to pass along the "struct key_value_info *" directly, rather than having the callback grab it from the global "current_config_kvi" that we've been maintaining in "configset_iter()". This change is an alternate direction to the topic at [1], this expands on the vague suggestions I made in [2] to go in this direction. As this shows we can split apart the "config_fn_t", and thus avoid having to change the hundreds of existing "config_fn_t" callers. By doing this we can already get rid of the current_config_kvi() function, as "builtin/remote.c" and "t/helper/test-config.c" were the only users of it. The change to "t/t5505-remote.sh" ensures that the change here to config_read_push_default() isn't breaking things. It's the only test that would go through that codepath, but nothing asserted that we'd get the correct line number. Let's sanity check that, as well as the other callback data. This leaves the other current_config_*() functions. Subsequent commits will need to deal with those. 1. https://lore.kernel.org/git/pull.1463.v2.git.git.1678925506.gitgitgadget@gmail.com/ 2. https://lore.kernel.org/git/230307.86wn3szrzu.gmgdl@evledraar.gmail.com/ 3. https://lore.kernel.org/git/230308.867cvrziac.gmgdl@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/remote.c | 11 ++++++----- config.c | 32 ++++++++++++++++++-------------- config.h | 9 ++++++++- t/helper/test-config.c | 13 +++++++------ t/t5505-remote.sh | 7 +++++-- 5 files changed, 44 insertions(+), 28 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 729f6f3643a..c65bce05034 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -644,17 +644,18 @@ struct push_default_info }; static int config_read_push_default(const char *key, const char *value, - void *cb) + struct key_value_info *kvi, void *cb) { struct push_default_info* info = cb; if (strcmp(key, "remote.pushdefault") || !value || strcmp(value, info->old_name)) return 0; - info->scope = current_config_scope(); + info->scope = kvi->scope; strbuf_reset(&info->origin); - strbuf_addstr(&info->origin, current_config_name()); - info->linenr = current_config_line(); + if (kvi->filename) + strbuf_addstr(&info->origin, kvi->filename); + info->linenr = kvi->linenr; return 0; } @@ -663,7 +664,7 @@ static void handle_push_default(const char* old_name, const char* new_name) { struct push_default_info push_default = { old_name, CONFIG_SCOPE_UNKNOWN, STRBUF_INIT, -1 }; - git_config(config_read_push_default, &push_default); + repo_config_kvi(the_repository, config_read_push_default, &push_default); if (push_default.scope >= CONFIG_SCOPE_COMMAND) ; /* pass */ else if (push_default.scope >= CONFIG_SCOPE_LOCAL) { diff --git a/config.c b/config.c index 230a98b0631..1b3f534757c 100644 --- a/config.c +++ b/config.c @@ -2219,7 +2219,8 @@ int config_with_options(config_fn_t fn, void *data, return ret; } -static void configset_iter(struct config_set *cs, config_fn_t fn, void *data) +static void configset_iter(struct config_set *cs, config_fn_t fn, + config_kvi_fn_t fn_kvi, void *data) { int i, value_index; struct string_list *values; @@ -2230,6 +2231,7 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data) const char *key; const char *val; struct key_value_info *kvi; + int ret; entry = list->items[i].e; value_index = list->items[i].value_index; @@ -2239,11 +2241,15 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data) val = values->items[value_index].string; kvi = values->items[value_index].util; - current_config_kvi = kvi; - if (fn(key, val, data) < 0) + if (!fn_kvi) + current_config_kvi = kvi; + ret = fn_kvi ? fn_kvi(key, val, kvi, data) : + fn(key, val, data); + current_config_kvi = NULL; + + if (ret < 0) git_die_config_linenr(entry->key, kvi->filename, kvi->linenr); - current_config_kvi = NULL; } } @@ -2567,7 +2573,13 @@ static void repo_config_clear(struct repository *repo) void repo_config(struct repository *repo, config_fn_t fn, void *data) { git_config_check_init(repo); - configset_iter(repo->config, fn, data); + configset_iter(repo->config, fn, NULL, data); +} + +void repo_config_kvi(struct repository *repo, config_kvi_fn_t fn, void *data) +{ + git_config_check_init(repo); + configset_iter(repo->config, NULL, fn, data); } int repo_config_get_value(struct repository *repo, @@ -2670,7 +2682,7 @@ void git_protected_config(config_fn_t fn, void *data) { if (!protected_config.hash_initialized) read_protected_config(); - configset_iter(&protected_config, fn, data); + configset_iter(&protected_config, fn, NULL, data); } /* Functions used historically to read configuration from 'the_repository' */ @@ -3843,14 +3855,6 @@ enum config_scope current_config_scope(void) return current_parsing_scope; } -int current_config_line(void) -{ - if (current_config_kvi) - return current_config_kvi->linenr; - else - return cf->linenr; -} - int lookup_config(const char **mapping, int nr_mapping, const char *var) { int i; diff --git a/config.h b/config.h index a9cb01e9405..de5350dbee5 100644 --- a/config.h +++ b/config.h @@ -143,6 +143,13 @@ const char *config_origin_type_name(enum config_origin_type type); */ typedef int (*config_fn_t)(const char *, const char *, void *); +/** + * Like config_fn_t, but before the callback-specific data we'll get a + * "struct key_value_info" indicating the origin of the config. + */ +typedef int (*config_kvi_fn_t)(const char *key, const char *var, + struct key_value_info *kvi, void *data); + int git_default_config(const char *, const char *, void *); /** @@ -371,7 +378,6 @@ int git_config_parse_parameter(const char *, config_fn_t fn, void *data); enum config_scope current_config_scope(void); const char *current_config_origin_type(void); const char *current_config_name(void); -int current_config_line(void); /* * Match and parse a config key of the form: @@ -498,6 +504,7 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha /* Functions for reading a repository's config */ struct repository; void repo_config(struct repository *repo, config_fn_t fn, void *data); +void repo_config_kvi(struct repository *repo, config_kvi_fn_t fn, void *data); int repo_config_get_value(struct repository *repo, const char *key, const char **value); const struct string_list *repo_config_get_value_multi(struct repository *repo, diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 4ba9eb65606..2ef67b18a0b 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -37,7 +37,8 @@ * */ -static int iterate_cb(const char *var, const char *value, void *data UNUSED) +static int iterate_cb(const char *var, const char *value, + struct key_value_info *kvi, void *data UNUSED) { static int nr; @@ -46,10 +47,10 @@ static int iterate_cb(const char *var, const char *value, void *data UNUSED) printf("key=%s\n", var); printf("value=%s\n", value ? value : "(null)"); - printf("origin=%s\n", current_config_origin_type()); - printf("name=%s\n", current_config_name()); - printf("lno=%d\n", current_config_line()); - printf("scope=%s\n", config_scope_name(current_config_scope())); + printf("origin=%s\n", config_origin_type_name(kvi->origin_type)); + printf("name=%s\n", kvi->filename ? kvi->filename : ""); + printf("lno=%d\n", kvi->linenr); + printf("scope=%s\n", config_scope_name(kvi->scope)); return 0; } @@ -174,7 +175,7 @@ int cmd__config(int argc, const char **argv) goto exit1; } } else if (!strcmp(argv[1], "iterate")) { - git_config(iterate_cb, NULL); + repo_config_kvi(the_repository, iterate_cb, NULL); goto exit0; } diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 43b7bcd7159..d9659b9c65e 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -853,8 +853,11 @@ test_expect_success 'rename a remote' ' ( cd four && git config branch.main.pushRemote origin && - GIT_TRACE2_EVENT=$(pwd)/trace \ - git remote rename --progress origin upstream && + GIT_TRACE2_EVENT=$PWD/trace \ + git remote rename --progress origin upstream 2>warn && + grep -F "The global configuration remote.pushDefault" warn && + grep "/\.gitconfig:2$" warn && + grep "remote '\''origin'\''" warn && test_region progress "Renaming remote references" trace && grep "pushRemote" .git/config && test -z "$(git for-each-ref refs/remotes/origin)" &&