Message ID | 20250219203349.787173-3-usmanakinyemi202@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | stop using the_repository global variable. | expand |
Usman Akinyemi <usmanakinyemi202@gmail.com> writes: > @@ -23,7 +22,7 @@ static const char * const verify_tag_usage[] = { > int cmd_verify_tag(int argc, > const char **argv, > const char *prefix, > - struct repository *repo UNUSED) > + struct repository *repo) > { > int i = 1, verbose = 0, had_error = 0; > unsigned flags = 0; > @@ -50,13 +49,13 @@ int cmd_verify_tag(int argc, > flags |= GPG_VERIFY_OMIT_STATUS; > } > > - git_config(git_default_config, NULL); > + repo_config(repo, git_default_config, NULL); I seriously think that it is a horrible idea (but the previous step of this series is hardly the first one that commits the same sin) to move git_config() down only to deal with "repo might be NULL if run outside a repository". We should stop making such changes, and we should revert the changes we already made along that line, to solve it differently. Wouldn't it work much better if we teach repo_config() to allow repo to be NULL to signal that we are outside any repository, and behave the same way the current git_config() works when called outside a repository? Even though the function is called repo_config(), it is *NOT* limited to read from $GIT_DIR/config but does read from the usual "repository configuration trumps per-user configuration which trumps system-side configuration" cascade, so it is natural to skip the repository configuration when called outside any repository but read the other configuration sources, which should be what happens when git_config() is called from outside the repository, no?
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index f0e7c2a2b5..0acdb364dd 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -5,7 +5,6 @@ * * Based on git-verify-tag.sh */ -#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "config.h" #include "gettext.h" @@ -23,7 +22,7 @@ static const char * const verify_tag_usage[] = { int cmd_verify_tag(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { int i = 1, verbose = 0, had_error = 0; unsigned flags = 0; @@ -50,13 +49,13 @@ int cmd_verify_tag(int argc, flags |= GPG_VERIFY_OMIT_STATUS; } - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); while (i < argc) { struct object_id oid; const char *name = argv[i++]; - if (repo_get_oid(the_repository, name, &oid)) { + if (repo_get_oid(repo, name, &oid)) { had_error = !!error("tag '%s' not found.", name); continue; }
Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/verify-tag.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_verify_tag()` function with `repo` set to NULL and then early in the function, `parse_options()` call will give the options help and exit, without having to consult much of the configuration file. Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com> --- builtin/verify-tag.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)