Skip to content

Commit 5e7d4d3

Browse files
peffgitster
authored andcommitted
assume parse_commit checks for NULL commit
The parse_commit function will check whether it was passed a NULL commit pointer, and if so, return an error. There is no need for callers to check this separately. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0064053 commit 5e7d4d3

File tree

5 files changed

+5
-7
lines changed

5 files changed

+5
-7
lines changed

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item,
490490
const char *sub = _(" **** invalid ref ****");
491491
struct commit *commit = item->commit;
492492

493-
if (commit && !parse_commit(commit)) {
493+
if (!parse_commit(commit)) {
494494
pp_commit_easy(CMIT_FMT_ONELINE, commit, &subject);
495495
sub = subject.buf;
496496
}

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
13111311
commit = lookup_commit(sha1);
13121312
if (!commit)
13131313
die(_("couldn't look up newly created commit"));
1314-
if (!commit || parse_commit(commit))
1314+
if (parse_commit(commit))
13151315
die(_("could not parse newly created commit"));
13161316

13171317
strbuf_addstr(&format, "format:%h] %s");
@@ -1503,7 +1503,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
15031503
current_head = NULL;
15041504
else {
15051505
current_head = lookup_commit_or_die(sha1, "HEAD");
1506-
if (!current_head || parse_commit(current_head))
1506+
if (parse_commit(current_head))
15071507
die(_("could not parse HEAD commit"));
15081508
}
15091509
argc = parse_and_validate_options(argc, argv, builtin_commit_options,

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
7979
if (get_sha1_committish(name, sha1))
8080
return NULL;
8181
commit = lookup_commit_reference(sha1);
82-
if (!commit || parse_commit(commit))
82+
if (parse_commit(commit))
8383
return NULL;
8484
return commit;
8585
}

notes-utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
1818
unsigned char parent_sha1[20];
1919
if (!read_ref(t->ref, parent_sha1)) {
2020
struct commit *parent = lookup_commit(parent_sha1);
21-
if (!parent || parse_commit(parent))
21+
if (parse_commit(parent))
2222
die("Failed to find/parse commit %s", t->ref);
2323
commit_list_insert(parent, &parents);
2424
}

sha1_name.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,6 @@ static int get_parent(const char *name, int len,
582582
if (ret)
583583
return ret;
584584
commit = lookup_commit_reference(sha1);
585-
if (!commit)
586-
return -1;
587585
if (parse_commit(commit))
588586
return -1;
589587
if (!idx) {

0 commit comments

Comments
 (0)