diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-03-17 14:03:10 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-03-17 14:03:10 -0700 |
commit | af5388d2ddb0bc7c22fbe698078f4ca07879d954 (patch) | |
tree | 6829523f0d96f2014ea373a7aa5b35cdc3c45420 /gpg-interface.c | |
parent | d0732a8120d9cc62d8b6efa4ec48966f890f84b7 (diff) | |
parent | cc5d1d32fd489f7eb98f762de303b499f2117638 (diff) | |
download | git-af5388d2ddb0bc7c22fbe698078f4ca07879d954.tar.gz |
Merge branch 'jc/gpg-lazy-init'
Instead of forcing each command to choose to honor GPG related
configuration variables, make the subsystem lazily initialize
itself.
* jc/gpg-lazy-init:
drop pure pass-through config callbacks
gpg-interface: lazily initialize and read the configuration
Diffstat (limited to 'gpg-interface.c')
-rw-r--r-- | gpg-interface.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/gpg-interface.c b/gpg-interface.c index 0c13990a42..855970bb93 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -10,6 +10,18 @@ #include "tempfile.h" #include "alias.h" +static int git_gpg_config(const char *, const char *, void *); + +static void gpg_interface_lazy_init(void) +{ + static int done; + + if (done) + return; + done = 1; + git_config(git_gpg_config, NULL); +} + static char *configured_signing_key; static const char *ssh_default_key_command, *ssh_allowed_signers, *ssh_revocation_file; static enum signature_trust_level configured_min_trust_level = TRUST_UNDEFINED; @@ -633,6 +645,8 @@ int check_signature(struct signature_check *sigc, struct gpg_format *fmt; int status; + gpg_interface_lazy_init(); + sigc->result = 'N'; sigc->trust_level = -1; @@ -696,11 +710,13 @@ int parse_signature(const char *buf, size_t size, struct strbuf *payload, struct void set_signing_key(const char *key) { + gpg_interface_lazy_init(); + free(configured_signing_key); configured_signing_key = xstrdup(key); } -int git_gpg_config(const char *var, const char *value, void *cb UNUSED) +static int git_gpg_config(const char *var, const char *value, void *cb UNUSED) { struct gpg_format *fmt = NULL; char *fmtname = NULL; @@ -889,6 +905,8 @@ static const char *get_ssh_key_id(void) { /* Returns a textual but unique representation of the signing key */ const char *get_signing_key_id(void) { + gpg_interface_lazy_init(); + if (use_format->get_key_id) { return use_format->get_key_id(); } @@ -899,6 +917,8 @@ const char *get_signing_key_id(void) const char *get_signing_key(void) { + gpg_interface_lazy_init(); + if (configured_signing_key) return configured_signing_key; if (use_format->get_default_key) { @@ -924,6 +944,8 @@ const char *gpg_trust_level_to_str(enum signature_trust_level level) int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key) { + gpg_interface_lazy_init(); + return use_format->sign_buffer(buffer, signature, signing_key); } |