Skip to content

Commit 8373037

Browse files
peffgitster
authored andcommitted
verify-commit: simplify parameters to run_gpg_verify()
The buf/len parameters of run_gpg_verify() have never been used since the function was added in d07b00b (verify-commit: scriptable commit signature verification, 2014-06-23). Instead, check_commit_signature() accesses the commit struct directly. Worse, we read the whole object just to check its type and do not attach it to the "struct commit". Meaning we end up loading the object from disk twice for no good reason. And to further confuse matters, our type check is comes from what we read from disk, but we later assume that lookup_commit() will return non-NULL. This might not be true if some other object previously referenced the same oid as a non-commit (though this may be impossible to trigger in practice since we don't generally parse any other objects in this command). Instead, let's do our type check by loading the object via parse_object(). That will attach the buffer to the struct so it can be used later by check_commit_signature(). And it ensures that lookup_commit() will return something sane. And then we can just drop the unused "buf" and "len" parameters entirely. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d713e88 commit 8373037

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

builtin/verify-commit.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ static const char * const verify_commit_usage[] = {
2121
NULL
2222
};
2323

24-
static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned long size, unsigned flags)
24+
static int run_gpg_verify(struct commit *commit, unsigned flags)
2525
{
2626
struct signature_check signature_check;
2727
int ret;
2828

2929
memset(&signature_check, 0, sizeof(signature_check));
3030

31-
ret = check_commit_signature(lookup_commit(the_repository, oid),
32-
&signature_check);
31+
ret = check_commit_signature(commit, &signature_check);
3332
print_signature_buffer(&signature_check, flags);
3433

3534
signature_check_clear(&signature_check);
@@ -38,26 +37,20 @@ static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned
3837

3938
static int verify_commit(const char *name, unsigned flags)
4039
{
41-
enum object_type type;
4240
struct object_id oid;
43-
char *buf;
44-
unsigned long size;
45-
int ret;
41+
struct object *obj;
4642

4743
if (get_oid(name, &oid))
4844
return error("commit '%s' not found.", name);
4945

50-
buf = read_object_file(&oid, &type, &size);
51-
if (!buf)
46+
obj = parse_object(the_repository, &oid);
47+
if (!obj)
5248
return error("%s: unable to read file.", name);
53-
if (type != OBJ_COMMIT)
49+
if (obj->type != OBJ_COMMIT)
5450
return error("%s: cannot verify a non-commit object of type %s.",
55-
name, type_name(type));
56-
57-
ret = run_gpg_verify(&oid, buf, size, flags);
51+
name, type_name(obj->type));
5852

59-
free(buf);
60-
return ret;
53+
return run_gpg_verify((struct commit *)obj, flags);
6154
}
6255

6356
static int git_verify_commit_config(const char *var, const char *value, void *cb)

0 commit comments

Comments
 (0)