use parse_commit_or_die instead of segfaulting

Some unchecked calls to parse_commit should obviously die on error, because their next step is to start looking at the parsed fields, which will cause a segfault. These are obvious candidates for parse_commit_or_die, which will be a strict improvement in behavior. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 24, 2013 at 04:53 UTC 683ff884cce955cc331929d857fac9d6bd69f46a
2 files changed +4 -4
builtin/checkout.c
+2 -2
@@ -796,7 +796,7 @@ static int switch_branches(const struct checkout_opts *opts,
796 new->commit = old.commit;
797 if (!new->commit)
798 die(_("You are on a branch yet to be born"));
799 - parse_commit(new->commit);
799 + parse_commit_or_die(new->commit);
800 }
801
802 ret = merge_working_tree(opts, &old, new, &writeout_error);
@@ -959,7 +959,7 @@ static int parse_branchname_arg(int argc, const char **argv,
959 /* not a commit */
960 *source_tree = parse_tree_indirect(rev);
961 } else {
962 - parse_commit(new->commit);
962 + parse_commit_or_die(new->commit);
963 *source_tree = new->commit->tree;
964 }
965
builtin/fast-export.c
+2 -2
@@ -286,7 +286,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
286
287 rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
288
289 - parse_commit(commit);
289 + parse_commit_or_die(commit);
290 author = strstr(commit->buffer, "\nauthor ");
291 if (!author)
292 die ("Could not find author in commit %s",
@@ -307,7 +307,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
307 if (commit->parents &&
308 get_object_mark(&commit->parents->item->object) != 0 &&
309 !full_tree) {
310 - parse_commit(commit->parents->item);
310 + parse_commit_or_die(commit->parents->item);
311 diff_tree_sha1(commit->parents->item->tree->object.sha1,
312 commit->tree->object.sha1, "", &rev->diffopt);
313 }