Skip to content

Commit db58d5a

Browse files
Unique-Usmangitster
authored andcommitted
builtin/verify-commit: stop using the_repository
Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/verify-commit.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_verify_commit()` function with `repo` set to NULL and then early in the function, `parse_options()` call will give the options help and exit. Pass the repository available in the calling context to `verify_commit()` to remove it's dependency on the global `the_repository` variable. Mentored-by: Christian Couder <[email protected]> Signed-off-by: Usman Akinyemi <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 43a8391 commit db58d5a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

builtin/verify-commit.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*
66
* Based on git-verify-tag
77
*/
8-
#define USE_THE_REPOSITORY_VARIABLE
98
#include "builtin.h"
109
#include "config.h"
1110
#include "gettext.h"
@@ -33,15 +32,15 @@ static int run_gpg_verify(struct commit *commit, unsigned flags)
3332
return ret;
3433
}
3534

36-
static int verify_commit(const char *name, unsigned flags)
35+
static int verify_commit(struct repository *repo, const char *name, unsigned flags)
3736
{
3837
struct object_id oid;
3938
struct object *obj;
4039

41-
if (repo_get_oid(the_repository, name, &oid))
40+
if (repo_get_oid(repo, name, &oid))
4241
return error("commit '%s' not found.", name);
4342

44-
obj = parse_object(the_repository, &oid);
43+
obj = parse_object(repo, &oid);
4544
if (!obj)
4645
return error("%s: unable to read file.", name);
4746
if (obj->type != OBJ_COMMIT)
@@ -54,7 +53,7 @@ static int verify_commit(const char *name, unsigned flags)
5453
int cmd_verify_commit(int argc,
5554
const char **argv,
5655
const char *prefix,
57-
struct repository *repo UNUSED)
56+
struct repository *repo)
5857
{
5958
int i = 1, verbose = 0, had_error = 0;
6059
unsigned flags = 0;
@@ -64,7 +63,7 @@ int cmd_verify_commit(int argc,
6463
OPT_END()
6564
};
6665

67-
git_config(git_default_config, NULL);
66+
repo_config(repo, git_default_config, NULL);
6867

6968
argc = parse_options(argc, argv, prefix, verify_commit_options,
7069
verify_commit_usage, PARSE_OPT_KEEP_ARGV0);
@@ -78,7 +77,7 @@ int cmd_verify_commit(int argc,
7877
* was received in the process of writing the gpg input: */
7978
signal(SIGPIPE, SIG_IGN);
8079
while (i < argc)
81-
if (verify_commit(argv[i++], flags))
80+
if (verify_commit(repo, argv[i++], flags))
8281
had_error = 1;
8382
return had_error;
8483
}

t/t7510-signed-commit.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
88
GNUPGHOME_NOT_USED=$GNUPGHOME
99
. "$TEST_DIRECTORY/lib-gpg.sh"
1010

11+
test_expect_success GPG 'verify-commit does not crash with -h' '
12+
test_expect_code 129 git verify-commit -h >usage &&
13+
test_grep "[Uu]sage: git verify-commit " usage &&
14+
test_expect_code 129 nongit git verify-commit -h >usage &&
15+
test_grep "[Uu]sage: git verify-commit " usage
16+
'
17+
1118
test_expect_success GPG 'create signed commits' '
1219
test_oid_cache <<-\EOF &&
1320
header sha1:gpgsig

0 commit comments

Comments
 (0)