From patchwork Thu Jan 9 10:16:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11325439 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1E681398 for ; Thu, 9 Jan 2020 10:16:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 802C92072A for ; Thu, 9 Jan 2020 10:16:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U+YTdLZl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729003AbgAIKQq (ORCPT ); Thu, 9 Jan 2020 05:16:46 -0500 Received: from mail-wm1-f53.google.com ([209.85.128.53]:36774 "EHLO mail-wm1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728707AbgAIKQq (ORCPT ); Thu, 9 Jan 2020 05:16:46 -0500 Received: by mail-wm1-f53.google.com with SMTP id p17so2173932wma.1 for ; Thu, 09 Jan 2020 02:16:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=saMlTNkKEqcBRL5aUOy1TDYQZGXm7gjU9li+Opxvdcs=; b=U+YTdLZll/44S6WAZI5h2HsJQRXXwUkIkeb6hBBLF3VygAM1gm6tUXxSiTZk5gQ4kU 8pc5VGoa4U0shEzh0/zb8bDzh9uhDkI8gYKvnnvnzaRHlRwEqqjy/f+o0n6jHrLAr56H PmOgVGwbx2HQJU6id9iCmj+7t5wNDiDnmj9qoZv50YtNteoadK747meyFaS5TMzQQ+AZ 355Ib7EUnxacbAgOMIIDZlHumMYh1nGKfLU++mqwRt+UzLz2xE9UtrtGgwbkN6v5Kk+B ATKLsgDnhZWxnNXwTqmih+SjI0arwCCw7AF5CFgWrcHdYCPNVhKbOB+VwUcsqNV0M52X h7jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=saMlTNkKEqcBRL5aUOy1TDYQZGXm7gjU9li+Opxvdcs=; b=GDxAe3Uj0Aqv7wY9pHbcr609IqYNs+dxsCZz2PjSNRL8uEmEbwtN4BuCXTjHjTMOEy K7SaZdxMuMQMHYJwp9w05F+obGF9QqbddbRRbilfU+02rinBpN7eTrfhgZRVQUCWWd8l pmIP5CgEsmQbRHhLiPv4QUqYgpTPElwm0JXCtAu8+TBo5RLFewoj8A5kQLM5/3pVXdLq 1bqGh0ajBKLOm7ltBvsHA86WhLyVE3gOI9ZrbxJIYDhvVX2GBAWx8/DYMz3ArVRggVYn vd+jdCZTwFk9M+3jA6dpfTZgHXrFj1/Er0psBbzZ2pNM8QycPQ5Poe6N0n9WklYSCODi A1zg== X-Gm-Message-State: APjAAAUb9LSSMD32MhgTlo+4W5kr5Mas+rMjRKXqxFyYDpPA4cvxQNIi Js2Q1leqAL/SgMlSd+LxERBfOyae X-Google-Smtp-Source: APXvYqzSIXpj5tk7U7yPUJQFh9Dd3UVQKc2zUhJv0WQ2rwNOweUdS0ehkNDZNuWivQh+Bm1+UKAnXg== X-Received: by 2002:a05:600c:24ca:: with SMTP id 10mr3767935wmu.4.1578565004376; Thu, 09 Jan 2020 02:16:44 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y20sm2281239wmi.25.2020.01.09.02.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2020 02:16:43 -0800 (PST) Message-Id: In-Reply-To: References: From: "Matthew Rogers via GitGitGadget" Date: Thu, 09 Jan 2020 10:16:38 +0000 Subject: [PATCH v2 1/4] config: fix typo in variable name Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Matthew Rogers , Matthew Rogers Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Matthew Rogers In git config use of the end_null variable to determine if we should be null terminating our output. While it is correct to say a string is "null terminated" the character is actually the "nul" character, so this malapropism is being fixed. Signed-off-by: Matthew Rogers --- builtin/config.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 98d65bc0ad..52a904cfb1 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -29,7 +29,7 @@ static int use_worktree_config; static struct git_config_source given_config_source; static int actions, type; static char *default_value; -static int end_null; +static int end_nul; static int respect_includes_opt = -1; static struct config_options config_options; static int show_origin; @@ -151,7 +151,7 @@ static struct option builtin_config_options[] = { OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE), OPT_GROUP(N_("Other")), - OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL byte")), + OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), @@ -178,11 +178,11 @@ static void check_argc(int argc, int min, int max) static void show_config_origin(struct strbuf *buf) { - const char term = end_null ? '\0' : '\t'; + const char term = end_nul ? '\0' : '\t'; strbuf_addstr(buf, current_config_origin_type()); strbuf_addch(buf, ':'); - if (end_null) + if (end_nul) strbuf_addstr(buf, current_config_name()); else quote_c_style(current_config_name(), buf, NULL, 0); @@ -678,7 +678,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) config_options.git_dir = get_git_dir(); } - if (end_null) { + if (end_nul) { term = '\0'; delim = '\n'; key_delim = '\n'; From patchwork Thu Jan 9 10:16:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11325441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 71B501398 for ; Thu, 9 Jan 2020 10:16:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4ED2C2072A for ; Thu, 9 Jan 2020 10:16:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JiJAsL0z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729182AbgAIKQr (ORCPT ); Thu, 9 Jan 2020 05:16:47 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52630 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728916AbgAIKQr (ORCPT ); Thu, 9 Jan 2020 05:16:47 -0500 Received: by mail-wm1-f67.google.com with SMTP id p9so2253979wmc.2 for ; Thu, 09 Jan 2020 02:16:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=8oBhDWlWyOzHbbpQeAdkFN0i+3jb3DNMT4uyPUWAjZk=; b=JiJAsL0z++GOBhzWffnRWna0JXNFy4ynX0c9CqWa3j2yQsCBjt9UdL//BJcyRMLHzo mWkHQBjefd9xp+BR9mxpyp6hV7IK3/hLOKy9+g0i9ljiBQ5gSw/fv8/yJpG+bMC5HkhZ ZCaT+dh1tQ/nbjpoJspDVv88tDUUiQ7MEjX8dTFNzaGQ6FtJmvy2Bv3JcRUGAmiOX14I 2C3AyI5YS49wnnNB2reDWt6Yed1r1zX9IkePBLF7b4FA2hRTnc7+F0t+fGsCinu2hzXJ xHptG5JgCY1RVzI7C5jMhC/BvpxBQ0+55kl4IPMCegMAC+7a1mgxMO/g2RdJ3RhAosVo bBxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=8oBhDWlWyOzHbbpQeAdkFN0i+3jb3DNMT4uyPUWAjZk=; b=YEoJVCqN/Hs9ru/pqCSRFCPfOQuYTIfpw3O6YjvU3Wq/ZgfAuvy5edjn7u0KoUjwob 3S4oFTePHnm41qZQD/6oLgwYgL2kTi0pPjr0dim4Kd7r0NIBENrpuiEIJ1AWtkuExCcd oRg0655Iq/pDBLRXmmmPAM8fQ25Of86w8rd4O4L+h0rMvTnHUsuNgivI8QC6TvTfnvh3 Gj6PaHSbuG8cJXowFhea12ffHtBjwWEQLRBsFoC04AvGr01RoWVaKzEfoGaXl8HLgI/t ukBtsRB7k8pEb9YIp8jWOrVUxXUl4bDYCwLJFjfI1JUUMXXfcMrrfX7jdQ6HA/NueExr jRCQ== X-Gm-Message-State: APjAAAUkOKq33tOMaVeRYF8z0gW050pGqYeoiU7Nd3jexUg3FjK598rF SVMXQl5VEAsQsTuOEpOhReEnJhBC X-Google-Smtp-Source: APXvYqy0hsNLss6ef917DFdllcpQfiJt1raQuv+WoLSHdcf/xzDvSyG/yGD8vefojp0mYsu9WvthZA== X-Received: by 2002:a7b:c934:: with SMTP id h20mr3792716wml.103.1578565005091; Thu, 09 Jan 2020 02:16:45 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c9sm2237028wmc.47.2020.01.09.02.16.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2020 02:16:44 -0800 (PST) Message-Id: In-Reply-To: References: From: "Matthew Rogers via GitGitGadget" Date: Thu, 09 Jan 2020 10:16:39 +0000 Subject: [PATCH v2 2/4] config: fix config scope enum Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Matthew Rogers , Matthew Rogers Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Matthew Rogers Previously when iterating through git config variables, worktree config and local config were both considered "CONFIG_SCOPE_REPO". This was never a problem before as no one had needed to differentiate between the two cases. Additionally we rename what was CONFIG_SCOPE_REPO to CONFIG_SCOPE_LOCAL to reflect its new, more specific meaning. The clients of 'current_config_scope()' who cared about CONFIG_SCOPE_REPO are also modified to similarly care about CONFIG_SCOPE_WORKTREE and CONFIG_SCOPE_LOCAL to preserve previous behavior. Signed-off-by: Matthew Rogers --- config.c | 7 ++----- config.h | 3 ++- remote.c | 3 ++- t/helper/test-config.c | 4 +++- upload-pack.c | 3 ++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/config.c b/config.c index d75f88ca0c..447a013a15 100644 --- a/config.c +++ b/config.c @@ -1724,15 +1724,12 @@ static int do_git_config_sequence(const struct config_options *opts, if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK)) ret += git_config_from_file(fn, user_config, data); - current_parsing_scope = CONFIG_SCOPE_REPO; + current_parsing_scope = CONFIG_SCOPE_LOCAL; if (!opts->ignore_repo && repo_config && !access_or_die(repo_config, R_OK, 0)) ret += git_config_from_file(fn, repo_config, data); - /* - * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE. - * But let's not complicate things before it's actually needed. - */ + current_parsing_scope = CONFIG_SCOPE_WORKTREE; if (!opts->ignore_worktree && repository_format_worktree_config) { char *path = git_pathdup("config.worktree"); if (!access_or_die(path, R_OK, 0)) diff --git a/config.h b/config.h index 91fd4c5e96..284d92fb0e 100644 --- a/config.h +++ b/config.h @@ -298,7 +298,8 @@ enum config_scope { CONFIG_SCOPE_UNKNOWN = 0, CONFIG_SCOPE_SYSTEM, CONFIG_SCOPE_GLOBAL, - CONFIG_SCOPE_REPO, + CONFIG_SCOPE_LOCAL, + CONFIG_SCOPE_WORKTREE, CONFIG_SCOPE_CMDLINE, }; diff --git a/remote.c b/remote.c index 5c4666b53a..593ce297ed 100644 --- a/remote.c +++ b/remote.c @@ -369,7 +369,8 @@ static int handle_config(const char *key, const char *value, void *cb) } remote = make_remote(name, namelen); remote->origin = REMOTE_CONFIG; - if (current_config_scope() == CONFIG_SCOPE_REPO) + if (current_config_scope() == CONFIG_SCOPE_LOCAL || + current_config_scope() == CONFIG_SCOPE_WORKTREE) remote->configured_in_repo = 1; if (!strcmp(subkey, "mirror")) remote->mirror = git_config_bool(key, value); diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 214003d5b2..6695e463eb 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -44,8 +44,10 @@ static const char *scope_name(enum config_scope scope) return "system"; case CONFIG_SCOPE_GLOBAL: return "global"; - case CONFIG_SCOPE_REPO: + case CONFIG_SCOPE_LOCAL: return "repo"; + case CONFIG_SCOPE_WORKTREE: + return "worktree"; case CONFIG_SCOPE_CMDLINE: return "cmdline"; default: diff --git a/upload-pack.c b/upload-pack.c index a00d7ece6b..c53249cac1 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1073,7 +1073,8 @@ static int upload_pack_config(const char *var, const char *value, void *unused) precomposed_unicode = git_config_bool(var, value); } - if (current_config_scope() != CONFIG_SCOPE_REPO) { + if (current_config_scope() != CONFIG_SCOPE_LOCAL && + current_config_scope() != CONFIG_SCOPE_WORKTREE) { if (!strcmp("uploadpack.packobjectshook", var)) return git_config_string(&pack_objects_hook, var, value); } From patchwork Thu Jan 9 10:16:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11325445 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26E341398 for ; Thu, 9 Jan 2020 10:16:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 05B0E2073A for ; Thu, 9 Jan 2020 10:16:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FX+Ey7Fz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729225AbgAIKQt (ORCPT ); Thu, 9 Jan 2020 05:16:49 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:45053 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728707AbgAIKQs (ORCPT ); Thu, 9 Jan 2020 05:16:48 -0500 Received: by mail-wr1-f67.google.com with SMTP id q10so6717526wrm.11 for ; Thu, 09 Jan 2020 02:16:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ep6BgXY97d/k/RaCUBzI+q+YFgW8dWJXGxjJn8yUxaM=; b=FX+Ey7Fz/g9QPtByfeGugX21DI1ti7hr5+UQjKZr/6vYk8z+0LUPAklPumgrQ+Cd1W vaqyIHmEeHBSF+Kv8SR2a95qic+MvVYLBKujq/bc8fDVsWn3T+8IJUUL7pcs/Kw0cnXk +ceTKLEeiYsUToM/eBa8E5hQQcjVdHhEyjtEt/p9xfoQooHhmpkG4yv8PVuKTgUT666g CZxWe5gc50khLMCCfw1EP99vsq4WWZCZAT1OjpuOjiKoz30vLbkJ0hwYJnsw5twDgAIS XnP4PzDAYNjRFMa2No7vp6LdK+e3b0iWPouDUU+Kqi+Euv7jW5XMOfLha9D7YsAQWC81 gBDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ep6BgXY97d/k/RaCUBzI+q+YFgW8dWJXGxjJn8yUxaM=; b=UNciuRKdgRP7O9eKy18O/5+91mT2sDgjkIL0phv7L1STtkwE57lkLjxXGqouzNTYdm HnYgA7GvUNMxYhUjmQ2udd+6iL2lN3bi2FIvbIMp1xavpQIZQB+pNSirELUOg0Gikm8j ojLctndZoe/FpWlGPZfbdO7Catu7fcwl3JtkFaZ4wnRYwNGnXmGDL4zenJeQImEEXeCH p+XCV9wCRFEptxRvh0+2znrJuBZnUPfji90mTmhmxtTfJ0ER9ntpWpWtYdL1Mu0ryLG0 Isg/vjCKcqD2uLrgqduWtcpN/SPG8P1oBVnLFcOW1NmaDJsFHQt3gHTxtpbkDtqyDO8D NXww== X-Gm-Message-State: APjAAAXy7EGBWVklQmsEzB0zvJ1XFgSUGTZOcyTPLQFK0up8NAtB8zxH Pbg3YuD6XrjHqzay6a+F/5b62662 X-Google-Smtp-Source: APXvYqxtlgLoFzk8mNd9Y4TUW2EDnWrh2zF/8hWLsirIdlZhIjDeS6rRPnwERhCStDtxYAFQsVbbWQ== X-Received: by 2002:adf:e74a:: with SMTP id c10mr9753990wrn.386.1578565005804; Thu, 09 Jan 2020 02:16:45 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g9sm7884938wro.67.2020.01.09.02.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2020 02:16:45 -0800 (PST) Message-Id: <82252735467d876b4726f512a02cc44d271696ca.1578565001.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Matthew Rogers via GitGitGadget" Date: Thu, 09 Jan 2020 10:16:40 +0000 Subject: [PATCH v2 3/4] config: clarify meaning of command line scoping Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Matthew Rogers , Matthew Rogers Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Matthew Rogers CONFIG_SCOPE_CMDLINE is generally used in the code to refer to config values passed in via the -c option. This is a little bit too specific as there are other methods to pass config values so that the last for a single command (namely --file and --blob). As the "visibility" of config values passed by these situations is common, we unify them as having a scope of "command" rather than "command line". Signed-off-by: Matthew Rogers --- config.c | 2 +- config.h | 2 +- t/helper/test-config.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index 447a013a15..f319a3d6a0 100644 --- a/config.c +++ b/config.c @@ -1737,7 +1737,7 @@ static int do_git_config_sequence(const struct config_options *opts, free(path); } - current_parsing_scope = CONFIG_SCOPE_CMDLINE; + current_parsing_scope = CONFIG_SCOPE_COMMAND; if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0) die(_("unable to parse command-line config")); diff --git a/config.h b/config.h index 284d92fb0e..f383a71404 100644 --- a/config.h +++ b/config.h @@ -300,7 +300,7 @@ enum config_scope { CONFIG_SCOPE_GLOBAL, CONFIG_SCOPE_LOCAL, CONFIG_SCOPE_WORKTREE, - CONFIG_SCOPE_CMDLINE, + CONFIG_SCOPE_COMMAND, }; enum config_scope current_config_scope(void); diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 6695e463eb..78bbb9eb98 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -48,8 +48,8 @@ static const char *scope_name(enum config_scope scope) return "repo"; case CONFIG_SCOPE_WORKTREE: return "worktree"; - case CONFIG_SCOPE_CMDLINE: - return "cmdline"; + case CONFIG_SCOPE_COMMAND: + return "command"; default: return "unknown"; } From patchwork Thu Jan 9 10:16:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11325447 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A486D18B8 for ; Thu, 9 Jan 2020 10:16:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 780122072A for ; Thu, 9 Jan 2020 10:16:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MRXDffSm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730063AbgAIKQu (ORCPT ); Thu, 9 Jan 2020 05:16:50 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53457 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728916AbgAIKQt (ORCPT ); Thu, 9 Jan 2020 05:16:49 -0500 Received: by mail-wm1-f65.google.com with SMTP id m24so2242626wmc.3 for ; Thu, 09 Jan 2020 02:16:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=qWmg/xL7g9yWslqNv6R13TICb47JCLBo7no8ny0brdc=; b=MRXDffSm6kZLGgHTRO1odlDpdZ3Khi99oiuorxYP4bYNChUj/9H+HCfwf6qpoTKOqn xT5C27Gi+z+Qml2N3d5zl6/me/FsAAW/cxI6RhfI29kh9Xjuo9Iyh43VKYLUhvqwkHfs YrE6/ESAQpULMpDZzTMyZcU7oJgTLSRO+bts0UNuQq0h3teAKOHgKryEd905Pva/NprW eEU/z7jRu9NgHXFlTW2jXB2oKqVP2qE7AkblOAG9XVGPa3vKfiNEKqaenKi/BNxUBW+I YA3Q4zO1ghnLoOC5UQ3ZfMTaVhl+gtSb+PGu6QMNLFPrFCyV0pHkBESCI50xzL3QMXqo 2gHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=qWmg/xL7g9yWslqNv6R13TICb47JCLBo7no8ny0brdc=; b=ATam1gE7e4e1ajF7a/T2rtP3aUE8sscfqwco/Z+DYAtqaiJT2OLVc2dKs8+dcVRBxA qBjNs0K89nKOWJ0vcVwg0wHwOo2YG2YwGN9HBOkOxb060dQREqvsCtwsbZsagw7f3Ih9 1Ai1w3Kd+4BHGpe+PwTjvLxfv46xBrIC+2xWoyvjAQCt4FmNiVRoFBei8ZCTCK4/La2B xC8LE/XCOCbSrUTL0ryjB2vkTPur7MoEI57+KcESqX9XzKpfioUMa8GXx/uKksQ6g8KC YrZ6Y1LrjFnsYHh4KjfQvocYp5bCp1AxC5lS0j/YAyobFxMhjeacUNmltOluehc0TcyT 3y5w== X-Gm-Message-State: APjAAAUruO5Pg10ricpK1T2aB2Yl/h+YHVFH8YT56H2a9yq4WwGYMEDg LiQKxvMgoO+D83ViY+JQ13xpcPe4 X-Google-Smtp-Source: APXvYqxlOe3it/ORhRYM5dTUUWSnOVdXTCVaJVlwVD6O34jSU+A5KThNGEUNKmnTcSKjmUBB+Pwn2w== X-Received: by 2002:a1c:1f51:: with SMTP id f78mr3732231wmf.60.1578565006741; Thu, 09 Jan 2020 02:16:46 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b68sm2436696wme.6.2020.01.09.02.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2020 02:16:46 -0800 (PST) Message-Id: <92ce9b782429248197bb87cfa11c89082304218f.1578565002.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Matthew Rogers via GitGitGadget" Date: Thu, 09 Jan 2020 10:16:41 +0000 Subject: [PATCH v2 4/4] config: add '--show-scope' to print the scope of a config value Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Matthew Rogers , Matthew Rogers Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Matthew Rogers When a user queries config values with --show-origin, often it's difficult to determine what the actual "scope" (local, global, etc.) of a given value is based on just the origin file. Teach 'git config' the '--show-scope' option to print the scope of all displayed config values. Note that we should never see anything of "submodule" scope as that is only ever used by submodule-config.c when parsing the '.gitmodules' file. Signed-off-by: Matthew Rogers --- Documentation/git-config.txt | 15 ++++++---- builtin/config.c | 56 ++++++++++++++++++++++++++++++++---- config.c | 6 +++- config.h | 20 +++++++------ submodule-config.c | 4 ++- t/helper/test-config.c | 4 ++- t/t1300-config.sh | 50 ++++++++++++++++++++++++++++++++ 7 files changed, 133 insertions(+), 22 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 899e92a1c9..2e47765aab 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -9,18 +9,18 @@ git-config - Get and set repository or global options SYNOPSIS -------- [verse] -'git config' [] [--type=] [--show-origin] [-z|--null] name [value [value_regex]] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] name [value [value_regex]] 'git config' [] [--type=] --add name value 'git config' [] [--type=] --replace-all name value [value_regex] -'git config' [] [--type=] [--show-origin] [-z|--null] --get name [value_regex] -'git config' [] [--type=] [--show-origin] [-z|--null] --get-all name [value_regex] -'git config' [] [--type=] [--show-origin] [-z|--null] [--name-only] --get-regexp name_regex [value_regex] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] --get name [value_regex] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] --get-all name [value_regex] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--name-only] --get-regexp name_regex [value_regex] 'git config' [] [--type=] [-z|--null] --get-urlmatch name URL 'git config' [] --unset name [value_regex] 'git config' [] --unset-all name [value_regex] 'git config' [] --rename-section old_name new_name 'git config' [] --remove-section name -'git config' [] [--show-origin] [-z|--null] [--name-only] -l | --list +'git config' [] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list 'git config' [] --get-color name [default] 'git config' [] --get-colorbool name [stdout-is-tty] 'git config' [] -e | --edit @@ -222,6 +222,11 @@ Valid ``'s include: the actual origin (config file path, ref, or blob id if applicable). +--show-scope:: + Similar to `--show-origin` in that it augments the output of + all queried config options with the scope of that value + (local, global, system, command). + --get-colorbool name [stdout-is-tty]:: Find the color setting for `name` (e.g. `color.diff`) and output diff --git a/builtin/config.c b/builtin/config.c index 52a904cfb1..0367d28ec1 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -33,6 +33,7 @@ static int end_nul; static int respect_includes_opt = -1; static struct config_options config_options; static int show_origin; +static int show_scope; #define ACTION_GET (1<<0) #define ACTION_GET_ALL (1<<1) @@ -155,6 +156,7 @@ static struct option builtin_config_options[] = { OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), + OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")), OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), OPT_END(), }; @@ -189,11 +191,41 @@ static void show_config_origin(struct strbuf *buf) strbuf_addch(buf, term); } +static const char *scope_to_string(enum config_scope scope) { + switch (scope) { + case CONFIG_SCOPE_LOCAL: + return "local"; + case CONFIG_SCOPE_GLOBAL: + return "global"; + case CONFIG_SCOPE_SYSTEM: + return "system"; + case CONFIG_SCOPE_WORKTREE: + return "worktree"; + case CONFIG_SCOPE_COMMAND: + return "command"; + case CONFIG_SCOPE_SUBMODULE: + return "submodule"; + default: + return "unknown"; + } +} + +static void show_config_scope(struct strbuf *buf) { + const char term = end_nul ? '\0' : '\t'; + const char *scope = scope_to_string(current_config_scope()); + + strbuf_addstr(buf, N_(scope)); + strbuf_addch(buf, term); +} + static int show_all_config(const char *key_, const char *value_, void *cb) { - if (show_origin) { + if (show_origin || show_scope) { struct strbuf buf = STRBUF_INIT; - show_config_origin(&buf); + if (show_scope) + show_config_scope(&buf); + if (show_origin) + show_config_origin(&buf); /* Use fwrite as "buf" can contain \0's if "end_null" is set. */ fwrite(buf.buf, 1, buf.len, stdout); strbuf_release(&buf); @@ -213,6 +245,8 @@ struct strbuf_list { static int format_config(struct strbuf *buf, const char *key_, const char *value_) { + if (show_scope) + show_config_origin(buf); if (show_origin) show_config_origin(buf); if (show_keys) @@ -599,6 +633,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) int nongit = !startup_info->have_repository; char *value; + + given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); argc = parse_options(argc, argv, prefix, builtin_config_options, @@ -622,6 +658,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) !strcmp(given_config_source.file, "-")) { given_config_source.file = NULL; given_config_source.use_stdin = 1; + given_config_source.scope = CONFIG_SCOPE_COMMAND; } if (use_global_config) { @@ -637,6 +674,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) */ die(_("$HOME not set")); + given_config_source.scope = CONFIG_SCOPE_GLOBAL; + if (access_or_warn(user_config, R_OK, 0) && xdg_config && !access_or_warn(xdg_config, R_OK, 0)) { given_config_source.file = xdg_config; @@ -646,11 +685,13 @@ int cmd_config(int argc, const char **argv, const char *prefix) free(xdg_config); } } - else if (use_system_config) + else if (use_system_config) { given_config_source.file = git_etc_gitconfig(); - else if (use_local_config) + given_config_source.scope = CONFIG_SCOPE_SYSTEM; + } else if (use_local_config) { given_config_source.file = git_pathdup("config"); - else if (use_worktree_config) { + given_config_source.scope = CONFIG_SCOPE_LOCAL; + } else if (use_worktree_config) { struct worktree **worktrees = get_worktrees(0); if (repository_format_worktree_config) given_config_source.file = git_pathdup("config.worktree"); @@ -662,13 +703,18 @@ int cmd_config(int argc, const char **argv, const char *prefix) "section in \"git help worktree\" for details")); else given_config_source.file = git_pathdup("config"); + given_config_source.scope = CONFIG_SCOPE_LOCAL; free_worktrees(worktrees); } else if (given_config_source.file) { if (!is_absolute_path(given_config_source.file) && prefix) given_config_source.file = prefix_filename(prefix, given_config_source.file); + given_config_source.scope = CONFIG_SCOPE_COMMAND; + } else if (given_config_source.blob) { + given_config_source.scope = CONFIG_SCOPE_COMMAND; } + if (respect_includes_opt == -1) config_options.respect_includes = !given_config_source.file; else diff --git a/config.c b/config.c index f319a3d6a0..035fc8fb29 100644 --- a/config.c +++ b/config.c @@ -1702,6 +1702,7 @@ static int do_git_config_sequence(const struct config_options *opts, char *xdg_config = xdg_config_home("config"); char *user_config = expand_user_path("~/.gitconfig", 0); char *repo_config; + enum config_scope prev_parsing_scope = current_parsing_scope; if (opts->commondir) repo_config = mkpathdup("%s/config", opts->commondir); @@ -1741,7 +1742,7 @@ static int do_git_config_sequence(const struct config_options *opts, if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0) die(_("unable to parse command-line config")); - current_parsing_scope = CONFIG_SCOPE_UNKNOWN; + current_parsing_scope = prev_parsing_scope; free(xdg_config); free(user_config); free(repo_config); @@ -1762,6 +1763,9 @@ int config_with_options(config_fn_t fn, void *data, data = &inc; } + if (config_source) + current_parsing_scope = config_source->scope; + /* * If we have a specific filename, use it. Otherwise, follow the * regular lookup sequence. diff --git a/config.h b/config.h index f383a71404..91f851e925 100644 --- a/config.h +++ b/config.h @@ -35,10 +35,21 @@ struct object_id; #define CONFIG_REGEX_NONE ((void *)1) +enum config_scope { + CONFIG_SCOPE_UNKNOWN = 0, + CONFIG_SCOPE_SYSTEM, + CONFIG_SCOPE_GLOBAL, + CONFIG_SCOPE_LOCAL, + CONFIG_SCOPE_WORKTREE, + CONFIG_SCOPE_COMMAND, + CONFIG_SCOPE_SUBMODULE, +}; + struct git_config_source { unsigned int use_stdin:1; const char *file; const char *blob; + enum config_scope scope; }; enum config_origin_type { @@ -294,15 +305,6 @@ int config_error_nonbool(const char *); int git_config_parse_parameter(const char *, config_fn_t fn, void *data); -enum config_scope { - CONFIG_SCOPE_UNKNOWN = 0, - CONFIG_SCOPE_SYSTEM, - CONFIG_SCOPE_GLOBAL, - CONFIG_SCOPE_LOCAL, - CONFIG_SCOPE_WORKTREE, - CONFIG_SCOPE_COMMAND, -}; - enum config_scope current_config_scope(void); const char *current_config_origin_type(void); const char *current_config_name(void); diff --git a/submodule-config.c b/submodule-config.c index 85064810b2..b8e97d8ae8 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -635,7 +635,9 @@ static void submodule_cache_check_init(struct repository *repo) static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void *data) { if (repo->worktree) { - struct git_config_source config_source = { 0 }; + struct git_config_source config_source = { + 0, .scope = CONFIG_SCOPE_SUBMODULE + }; const struct config_options opts = { 0 }; struct object_id oid; char *file; diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 78bbb9eb98..aae2c6fc9e 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -48,8 +48,10 @@ static const char *scope_name(enum config_scope scope) return "repo"; case CONFIG_SCOPE_WORKTREE: return "worktree"; + case CONFIG_SCOPE_SUBMODULE: + return "submodule"; case CONFIG_SCOPE_COMMAND: - return "command"; + return "cmdline"; default: return "unknown"; } diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 983a0a1583..6cecc80b18 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1766,6 +1766,56 @@ test_expect_success !MINGW '--show-origin blob ref' ' test_cmp expect output ' +test_expect_success '--show-scope with --list' ' + cat >expect <<-EOF && + global user.global=true + global user.override=global + global include.path=$INCLUDE_DIR/absolute.include + global user.absolute=include + local user.local=true + local user.override=local + local include.path=../include/relative.include + local user.relative=include + command user.cmdline=true + EOF + git -c user.cmdline=true config --list --show-scope >output && + test_cmp expect output +' + +test_expect_success !MINGW '--show-scope with --blob' ' + blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") && + cat >expect <<-EOF && + command user.custom=true + EOF + git config --blob=$blob --show-scope --list >output && + test_cmp expect output +' +test_expect_success '--show-scope with --local' ' + cat >expect <<-\EOF && + local user.local=true + local user.override=local + local include.path=../include/relative.include + EOF + git config --local --list --show-scope >output && + test_cmp expect output +' + +test_expect_success '--show-scope with --show-origin' ' + cat >expect <<-EOF && + global file:$HOME/.gitconfig user.global=true + global file:$HOME/.gitconfig user.override=global + global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include + global file:$INCLUDE_DIR/absolute.include user.absolute=include + local file:.git/config user.local=true + local file:.git/config user.override=local + local file:.git/config include.path=../include/relative.include + local file:.git/../include/relative.include user.relative=include + command command line: user.cmdline=true + EOF + git -c user.cmdline=true config --list --show-origin --show-scope >output && + test_cmp expect output +' + test_expect_success '--local requires a repo' ' # we expect 128 to ensure that we do not simply # fail to find anything and return code "1"