From fd2d4c135ed974fdddf2af687748d28c58575984 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 9 Feb 2023 12:24:14 -0800 Subject: gpg-interface: lazily initialize and read the configuration Instead of forcing the porcelain commands to always read the configuration variables related to the signing and verifying signatures, lazily initialize the necessary subsystem on demand upon the first use. This hopefully would make it more future-proof as we do not have to think and decide whether we should call git_gpg_config() in the git_config() callback for each command. A few git_config() callback functions that used to be custom callbacks are now just a thin wrapper around git_default_config(). We could further remove, git_FOO_config and replace calls to git_config(git_FOO_config) with git_config(git_default_config), but to make it clear which ones are affected and the effect is only the removal of git_gpg_config(), it is vastly preferred not to do such a change in this step (they can be done on top once the dust settled). Signed-off-by: Junio C Hamano --- builtin/commit-tree.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'builtin/commit-tree.c') diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index cc8d584be2..f6a099d601 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -39,9 +39,6 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p) static int commit_tree_config(const char *var, const char *value, void *cb) { - int status = git_gpg_config(var, value, NULL); - if (status) - return status; return git_default_config(var, value, cb); } -- cgit v1.2.3 From cc5d1d32fd489f7eb98f762de303b499f2117638 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Feb 2023 17:40:46 -0500 Subject: drop pure pass-through config callbacks Commit fd2d4c135e (gpg-interface: lazily initialize and read the configuration, 2023-02-09) shrunk a few custom config callbacks so that they are just one-liners of: return git_default_config(...); We can drop them entirely and replace them direct calls of git_default_config() intead. This makes the code a little shorter and easier to understand (with the downside being that if they do grow custom options again later, we'll have to recreate the functions). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/am.c | 7 +------ builtin/commit-tree.c | 7 +------ builtin/verify-commit.c | 7 +------ builtin/verify-tag.c | 7 +------ 4 files changed, 4 insertions(+), 24 deletions(-) (limited to 'builtin/commit-tree.c') diff --git a/builtin/am.c b/builtin/am.c index 40126b59c5..fccf40f8ee 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2312,11 +2312,6 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar return 0; } -static int git_am_config(const char *k, const char *v, void *cb UNUSED) -{ - return git_default_config(k, v, NULL); -} - int cmd_am(int argc, const char **argv, const char *prefix) { struct am_state state; @@ -2440,7 +2435,7 @@ int cmd_am(int argc, const char **argv, const char *prefix) if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(usage, options); - git_config(git_am_config, NULL); + git_config(git_default_config, NULL); am_state_init(&state); diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index f6a099d601..c0bbe9373d 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -37,11 +37,6 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p) commit_list_insert(parent, parents_p); } -static int commit_tree_config(const char *var, const char *value, void *cb) -{ - return git_default_config(var, value, cb); -} - static int parse_parent_arg_callback(const struct option *opt, const char *arg, int unset) { @@ -118,7 +113,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(commit_tree_config, NULL); + git_config(git_default_config, NULL); if (argc < 2 || !strcmp(argv[1], "-h")) usage_with_options(commit_tree_usage, options); diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 3c5d0b024c..7aedf10e85 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -52,11 +52,6 @@ static int verify_commit(const char *name, unsigned flags) return run_gpg_verify((struct commit *)obj, flags); } -static int git_verify_commit_config(const char *var, const char *value, void *cb) -{ - return git_default_config(var, value, cb); -} - int cmd_verify_commit(int argc, const char **argv, const char *prefix) { int i = 1, verbose = 0, had_error = 0; @@ -67,7 +62,7 @@ int cmd_verify_commit(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_verify_commit_config, NULL); + git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, verify_commit_options, verify_commit_usage, PARSE_OPT_KEEP_ARGV0); diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index ecffb069bf..5c00b0b0f7 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -19,11 +19,6 @@ static const char * const verify_tag_usage[] = { NULL }; -static int git_verify_tag_config(const char *var, const char *value, void *cb) -{ - return git_default_config(var, value, cb); -} - int cmd_verify_tag(int argc, const char **argv, const char *prefix) { int i = 1, verbose = 0, had_error = 0; @@ -36,7 +31,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_verify_tag_config, NULL); + git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, verify_tag_options, verify_tag_usage, PARSE_OPT_KEEP_ARGV0); -- cgit v1.2.3