Merge branch 'jk/robustify-parse-commit'

* jk/robustify-parse-commit:
  checkout: do not die when leaving broken detached HEAD
  use parse_commit_or_die instead of custom message
  use parse_commit_or_die instead of segfaulting
  assume parse_commit checks for NULL commit
  assume parse_commit checks commit->object.parsed
  log_tree_diff: die when we fail to parse a commit
This commit is contained in:
Junio C Hamano 2013-12-05 12:54:01 -08:00
Родитель b2a0afd96a 3c62183929
Коммит 5bb62059f2
15 изменённых файлов: 32 добавлений и 33 удалений

Просмотреть файл

@ -1551,7 +1551,6 @@ static void assign_blame(struct scoreboard *sb, int opt)
*/
origin_incref(suspect);
commit = suspect->commit;
if (!commit->object.parsed)
parse_commit(commit);
if (reverse ||
(!(commit->object.flags & UNINTERESTING) &&

Просмотреть файл

@ -502,7 +502,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_item *item,
const char *sub = _(" **** invalid ref ****");
struct commit *commit = item->commit;
if (commit && !parse_commit(commit)) {
if (!parse_commit(commit)) {
pp_commit_easy(CMIT_FMT_ONELINE, commit, &subject);
sub = subject.buf;
}

Просмотреть файл

@ -380,7 +380,7 @@ static void show_local_changes(struct object *head,
static void describe_detached_head(const char *msg, struct commit *commit)
{
struct strbuf sb = STRBUF_INIT;
parse_commit(commit);
if (!parse_commit(commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
fprintf(stderr, "%s %s... %s\n", msg,
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
@ -677,11 +677,11 @@ static int add_pending_uninteresting_ref(const char *refname,
static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
{
parse_commit(commit);
strbuf_addstr(sb, " ");
strbuf_addstr(sb,
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
strbuf_addch(sb, ' ');
if (!parse_commit(commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
strbuf_addch(sb, '\n');
}
@ -789,7 +789,7 @@ static int switch_branches(const struct checkout_opts *opts,
new->commit = old.commit;
if (!new->commit)
die(_("You are on a branch yet to be born"));
parse_commit(new->commit);
parse_commit_or_die(new->commit);
}
ret = merge_working_tree(opts, &old, new, &writeout_error);
@ -995,7 +995,7 @@ static int parse_branchname_arg(int argc, const char **argv,
/* not a commit */
*source_tree = parse_tree_indirect(rev);
} else {
parse_commit(new->commit);
parse_commit_or_die(new->commit);
*source_tree = new->commit->tree;
}

Просмотреть файл

@ -1338,7 +1338,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
commit = lookup_commit(sha1);
if (!commit)
die(_("couldn't look up newly created commit"));
if (!commit || parse_commit(commit))
if (parse_commit(commit))
die(_("could not parse newly created commit"));
strbuf_addstr(&format, "format:%h] %s");
@ -1525,7 +1525,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
current_head = NULL;
else {
current_head = lookup_commit_or_die(sha1, "HEAD");
if (!current_head || parse_commit(current_head))
if (parse_commit(current_head))
die(_("could not parse HEAD commit"));
}
argc = parse_and_validate_options(argc, argv, builtin_commit_options,

Просмотреть файл

@ -287,7 +287,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
parse_commit(commit);
parse_commit_or_die(commit);
author = strstr(commit->buffer, "\nauthor ");
if (!author)
die ("Could not find author in commit %s",
@ -308,7 +308,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
if (commit->parents &&
get_object_mark(&commit->parents->item->object) != 0 &&
!full_tree) {
parse_commit(commit->parents->item);
parse_commit_or_die(commit->parents->item);
diff_tree_sha1(commit->parents->item->tree->object.sha1,
commit->tree->object.sha1, "", &rev->diffopt);
}

Просмотреть файл

@ -27,7 +27,6 @@ static void name_rev(struct commit *commit,
struct commit_list *parents;
int parent_number = 1;
if (!commit->object.parsed)
parse_commit(commit);
if (commit->date < cutoff)

Просмотреть файл

@ -227,7 +227,6 @@ static void join_revs(struct commit_list **list_p,
parents = parents->next;
if ((this_flag & flags) == flags)
continue;
if (!p->object.parsed)
parse_commit(p);
if (mark_seen(p, seen_p) && !still_interesting)
extra--;

Просмотреть файл

@ -79,7 +79,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
if (get_sha1_committish(name, sha1))
return NULL;
commit = lookup_commit_reference(sha1);
if (!commit || parse_commit(commit))
if (parse_commit(commit))
return NULL;
return commit;
}
@ -341,6 +341,13 @@ int parse_commit(struct commit *item)
return ret;
}
void parse_commit_or_die(struct commit *item)
{
if (parse_commit(item))
die("unable to parse commit %s",
item ? sha1_to_hex(item->object.sha1) : "(null)");
}
int find_commit_subject(const char *commit_buffer, const char **subject)
{
const char *eol;

Просмотреть файл

@ -49,6 +49,7 @@ struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_n
int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size);
int parse_commit(struct commit *item);
void parse_commit_or_die(struct commit *item);
/* Find beginning and length of commit subject. */
int find_commit_subject(const char *commit_buffer, const char **subject);

Просмотреть файл

@ -47,7 +47,6 @@ static void rev_list_push(struct commit *commit, int mark)
if (!(commit->object.flags & mark)) {
commit->object.flags |= mark;
if (!(commit->object.parsed))
if (parse_commit(commit))
return;
@ -128,7 +127,6 @@ static const unsigned char *get_rev(void)
return NULL;
commit = prio_queue_get(&rev_list);
if (!commit->object.parsed)
parse_commit(commit);
parents = commit->parents;

Просмотреть файл

@ -734,7 +734,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS))
return 0;
parse_commit(commit);
parse_commit_or_die(commit);
sha1 = commit->tree->object.sha1;
/* Root commit? */
@ -759,7 +759,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
* parent, showing summary diff of the others
* we merged _in_.
*/
parse_commit(parents->item);
parse_commit_or_die(parents->item);
diff_tree_sha1(parents->item->tree->object.sha1,
sha1, "", &opt->diffopt);
log_tree_diff_flush(opt);
@ -774,7 +774,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
for (;;) {
struct commit *parent = parents->item;
parse_commit(parent);
parse_commit_or_die(parent);
diff_tree_sha1(parent->tree->object.sha1,
sha1, "", &opt->diffopt);
log_tree_diff_flush(opt);

Просмотреть файл

@ -18,7 +18,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
unsigned char parent_sha1[20];
if (!read_ref(t->ref, parent_sha1)) {
struct commit *parent = lookup_commit(parent_sha1);
if (!parent || parse_commit(parent))
if (parse_commit(parent))
die("Failed to find/parse commit %s", t->ref);
commit_list_insert(parent, &parents);
}

Просмотреть файл

@ -581,8 +581,6 @@ static int get_parent(const char *name, int len,
if (ret)
return ret;
commit = lookup_commit_reference(sha1);
if (!commit)
return -1;
if (parse_commit(commit))
return -1;
if (!idx) {

Просмотреть файл

@ -90,8 +90,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
cur_depth = *(int *)commit->util;
}
}
if (parse_commit(commit))
die("invalid commit");
parse_commit_or_die(commit);
cur_depth++;
if (cur_depth >= depth) {
commit_list_insert(commit, &result);

Просмотреть файл

@ -649,8 +649,7 @@ static void receive_needs(void)
/* make sure the real parents are parsed */
unregister_shallow(object->sha1);
object->parsed = 0;
if (parse_commit((struct commit *)object))
die("invalid commit");
parse_commit_or_die((struct commit *)object);
parents = ((struct commit *)object)->parents;
while (parents) {
add_object_array(&parents->item->object,