mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
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:
commit
5bb62059f2
|
@ -1551,7 +1551,6 @@ static void assign_blame(struct scoreboard *sb, int opt)
|
||||||
*/
|
*/
|
||||||
origin_incref(suspect);
|
origin_incref(suspect);
|
||||||
commit = suspect->commit;
|
commit = suspect->commit;
|
||||||
if (!commit->object.parsed)
|
|
||||||
parse_commit(commit);
|
parse_commit(commit);
|
||||||
if (reverse ||
|
if (reverse ||
|
||||||
(!(commit->object.flags & UNINTERESTING) &&
|
(!(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 ****");
|
const char *sub = _(" **** invalid ref ****");
|
||||||
struct commit *commit = item->commit;
|
struct commit *commit = item->commit;
|
||||||
|
|
||||||
if (commit && !parse_commit(commit)) {
|
if (!parse_commit(commit)) {
|
||||||
pp_commit_easy(CMIT_FMT_ONELINE, commit, &subject);
|
pp_commit_easy(CMIT_FMT_ONELINE, commit, &subject);
|
||||||
sub = subject.buf;
|
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)
|
static void describe_detached_head(const char *msg, struct commit *commit)
|
||||||
{
|
{
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
parse_commit(commit);
|
if (!parse_commit(commit))
|
||||||
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
|
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
|
||||||
fprintf(stderr, "%s %s... %s\n", msg,
|
fprintf(stderr, "%s %s... %s\n", msg,
|
||||||
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
|
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)
|
static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
|
||||||
{
|
{
|
||||||
parse_commit(commit);
|
|
||||||
strbuf_addstr(sb, " ");
|
strbuf_addstr(sb, " ");
|
||||||
strbuf_addstr(sb,
|
strbuf_addstr(sb,
|
||||||
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
|
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
|
||||||
strbuf_addch(sb, ' ');
|
strbuf_addch(sb, ' ');
|
||||||
|
if (!parse_commit(commit))
|
||||||
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
|
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
|
||||||
strbuf_addch(sb, '\n');
|
strbuf_addch(sb, '\n');
|
||||||
}
|
}
|
||||||
|
@ -789,7 +789,7 @@ static int switch_branches(const struct checkout_opts *opts,
|
||||||
new->commit = old.commit;
|
new->commit = old.commit;
|
||||||
if (!new->commit)
|
if (!new->commit)
|
||||||
die(_("You are on a branch yet to be born"));
|
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);
|
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 */
|
/* not a commit */
|
||||||
*source_tree = parse_tree_indirect(rev);
|
*source_tree = parse_tree_indirect(rev);
|
||||||
} else {
|
} else {
|
||||||
parse_commit(new->commit);
|
parse_commit_or_die(new->commit);
|
||||||
*source_tree = new->commit->tree;
|
*source_tree = new->commit->tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1338,7 +1338,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
|
||||||
commit = lookup_commit(sha1);
|
commit = lookup_commit(sha1);
|
||||||
if (!commit)
|
if (!commit)
|
||||||
die(_("couldn't look up newly created 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"));
|
die(_("could not parse newly created commit"));
|
||||||
|
|
||||||
strbuf_addstr(&format, "format:%h] %s");
|
strbuf_addstr(&format, "format:%h] %s");
|
||||||
|
@ -1525,7 +1525,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
||||||
current_head = NULL;
|
current_head = NULL;
|
||||||
else {
|
else {
|
||||||
current_head = lookup_commit_or_die(sha1, "HEAD");
|
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"));
|
die(_("could not parse HEAD commit"));
|
||||||
}
|
}
|
||||||
argc = parse_and_validate_options(argc, argv, builtin_commit_options,
|
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;
|
rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
|
||||||
|
|
||||||
parse_commit(commit);
|
parse_commit_or_die(commit);
|
||||||
author = strstr(commit->buffer, "\nauthor ");
|
author = strstr(commit->buffer, "\nauthor ");
|
||||||
if (!author)
|
if (!author)
|
||||||
die ("Could not find author in commit %s",
|
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 &&
|
if (commit->parents &&
|
||||||
get_object_mark(&commit->parents->item->object) != 0 &&
|
get_object_mark(&commit->parents->item->object) != 0 &&
|
||||||
!full_tree) {
|
!full_tree) {
|
||||||
parse_commit(commit->parents->item);
|
parse_commit_or_die(commit->parents->item);
|
||||||
diff_tree_sha1(commit->parents->item->tree->object.sha1,
|
diff_tree_sha1(commit->parents->item->tree->object.sha1,
|
||||||
commit->tree->object.sha1, "", &rev->diffopt);
|
commit->tree->object.sha1, "", &rev->diffopt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ static void name_rev(struct commit *commit,
|
||||||
struct commit_list *parents;
|
struct commit_list *parents;
|
||||||
int parent_number = 1;
|
int parent_number = 1;
|
||||||
|
|
||||||
if (!commit->object.parsed)
|
|
||||||
parse_commit(commit);
|
parse_commit(commit);
|
||||||
|
|
||||||
if (commit->date < cutoff)
|
if (commit->date < cutoff)
|
||||||
|
|
|
@ -227,7 +227,6 @@ static void join_revs(struct commit_list **list_p,
|
||||||
parents = parents->next;
|
parents = parents->next;
|
||||||
if ((this_flag & flags) == flags)
|
if ((this_flag & flags) == flags)
|
||||||
continue;
|
continue;
|
||||||
if (!p->object.parsed)
|
|
||||||
parse_commit(p);
|
parse_commit(p);
|
||||||
if (mark_seen(p, seen_p) && !still_interesting)
|
if (mark_seen(p, seen_p) && !still_interesting)
|
||||||
extra--;
|
extra--;
|
||||||
|
|
9
commit.c
9
commit.c
|
@ -79,7 +79,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
|
||||||
if (get_sha1_committish(name, sha1))
|
if (get_sha1_committish(name, sha1))
|
||||||
return NULL;
|
return NULL;
|
||||||
commit = lookup_commit_reference(sha1);
|
commit = lookup_commit_reference(sha1);
|
||||||
if (!commit || parse_commit(commit))
|
if (parse_commit(commit))
|
||||||
return NULL;
|
return NULL;
|
||||||
return commit;
|
return commit;
|
||||||
}
|
}
|
||||||
|
@ -341,6 +341,13 @@ int parse_commit(struct commit *item)
|
||||||
return ret;
|
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)
|
int find_commit_subject(const char *commit_buffer, const char **subject)
|
||||||
{
|
{
|
||||||
const char *eol;
|
const char *eol;
|
||||||
|
|
1
commit.h
1
commit.h
|
@ -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_buffer(struct commit *item, const void *buffer, unsigned long size);
|
||||||
int parse_commit(struct commit *item);
|
int parse_commit(struct commit *item);
|
||||||
|
void parse_commit_or_die(struct commit *item);
|
||||||
|
|
||||||
/* Find beginning and length of commit subject. */
|
/* Find beginning and length of commit subject. */
|
||||||
int find_commit_subject(const char *commit_buffer, const char **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)) {
|
if (!(commit->object.flags & mark)) {
|
||||||
commit->object.flags |= mark;
|
commit->object.flags |= mark;
|
||||||
|
|
||||||
if (!(commit->object.parsed))
|
|
||||||
if (parse_commit(commit))
|
if (parse_commit(commit))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -128,7 +127,6 @@ static const unsigned char *get_rev(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
commit = prio_queue_get(&rev_list);
|
commit = prio_queue_get(&rev_list);
|
||||||
if (!commit->object.parsed)
|
|
||||||
parse_commit(commit);
|
parse_commit(commit);
|
||||||
parents = commit->parents;
|
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))
|
if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
parse_commit(commit);
|
parse_commit_or_die(commit);
|
||||||
sha1 = commit->tree->object.sha1;
|
sha1 = commit->tree->object.sha1;
|
||||||
|
|
||||||
/* Root commit? */
|
/* 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
|
* parent, showing summary diff of the others
|
||||||
* we merged _in_.
|
* we merged _in_.
|
||||||
*/
|
*/
|
||||||
parse_commit(parents->item);
|
parse_commit_or_die(parents->item);
|
||||||
diff_tree_sha1(parents->item->tree->object.sha1,
|
diff_tree_sha1(parents->item->tree->object.sha1,
|
||||||
sha1, "", &opt->diffopt);
|
sha1, "", &opt->diffopt);
|
||||||
log_tree_diff_flush(opt);
|
log_tree_diff_flush(opt);
|
||||||
|
@ -774,7 +774,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct commit *parent = parents->item;
|
struct commit *parent = parents->item;
|
||||||
|
|
||||||
parse_commit(parent);
|
parse_commit_or_die(parent);
|
||||||
diff_tree_sha1(parent->tree->object.sha1,
|
diff_tree_sha1(parent->tree->object.sha1,
|
||||||
sha1, "", &opt->diffopt);
|
sha1, "", &opt->diffopt);
|
||||||
log_tree_diff_flush(opt);
|
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];
|
unsigned char parent_sha1[20];
|
||||||
if (!read_ref(t->ref, parent_sha1)) {
|
if (!read_ref(t->ref, parent_sha1)) {
|
||||||
struct commit *parent = lookup_commit(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);
|
die("Failed to find/parse commit %s", t->ref);
|
||||||
commit_list_insert(parent, &parents);
|
commit_list_insert(parent, &parents);
|
||||||
}
|
}
|
||||||
|
|
|
@ -581,8 +581,6 @@ static int get_parent(const char *name, int len,
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
commit = lookup_commit_reference(sha1);
|
commit = lookup_commit_reference(sha1);
|
||||||
if (!commit)
|
|
||||||
return -1;
|
|
||||||
if (parse_commit(commit))
|
if (parse_commit(commit))
|
||||||
return -1;
|
return -1;
|
||||||
if (!idx) {
|
if (!idx) {
|
||||||
|
|
|
@ -90,8 +90,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
|
||||||
cur_depth = *(int *)commit->util;
|
cur_depth = *(int *)commit->util;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (parse_commit(commit))
|
parse_commit_or_die(commit);
|
||||||
die("invalid commit");
|
|
||||||
cur_depth++;
|
cur_depth++;
|
||||||
if (cur_depth >= depth) {
|
if (cur_depth >= depth) {
|
||||||
commit_list_insert(commit, &result);
|
commit_list_insert(commit, &result);
|
||||||
|
|
|
@ -649,8 +649,7 @@ static void receive_needs(void)
|
||||||
/* make sure the real parents are parsed */
|
/* make sure the real parents are parsed */
|
||||||
unregister_shallow(object->sha1);
|
unregister_shallow(object->sha1);
|
||||||
object->parsed = 0;
|
object->parsed = 0;
|
||||||
if (parse_commit((struct commit *)object))
|
parse_commit_or_die((struct commit *)object);
|
||||||
die("invalid commit");
|
|
||||||
parents = ((struct commit *)object)->parents;
|
parents = ((struct commit *)object)->parents;
|
||||||
while (parents) {
|
while (parents) {
|
||||||
add_object_array(&parents->item->object,
|
add_object_array(&parents->item->object,
|
||||||
|
|
Loading…
Reference in a new issue