From: Junio C Hamano Date: Fri, 5 Feb 2016 22:54:10 +0000 (-0800) Subject: Merge branch 'dk/reflog-walk-with-non-commit' into maint X-Git-Tag: v2.7.1~23 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/90b99869d4ab750b7de0250f02d4c3f08c86f61b?hp=-c Merge branch 'dk/reflog-walk-with-non-commit' into maint "git reflog" incorrectly assumed that all objects that used to be at the tip of a ref must be commits, which caused it to segfault. * dk/reflog-walk-with-non-commit: reflog-walk: don't segfault on non-commit sha1's in the reflog --- 90b99869d4ab750b7de0250f02d4c3f08c86f61b diff --combined reflog-walk.c index 85b8a54241,d3cc5240f3..0ebd1da5ce --- a/reflog-walk.c +++ b/reflog-walk.c @@@ -56,11 -56,12 +56,11 @@@ static struct complete_reflogs *read_co } } if (reflogs->nr == 0) { - int len = strlen(ref); - char *refname = xmalloc(len + 12); - sprintf(refname, "refs/%s", ref); + char *refname = xstrfmt("refs/%s", ref); for_each_reflog_ent(refname, read_one_reflog, reflogs); if (reflogs->nr == 0) { - sprintf(refname, "refs/heads/%s", ref); + free(refname); + refname = xstrfmt("refs/heads/%s", ref); for_each_reflog_ent(refname, read_one_reflog, reflogs); } free(refname); @@@ -221,6 -222,7 +221,7 @@@ void fake_reflog_parent(struct reflog_w struct commit_info *commit_info = get_commit_info(commit, &info->reflogs, 0); struct commit_reflog *commit_reflog; + struct object *logobj; struct reflog_info *reflog; info->last_commit_reflog = NULL; @@@ -232,15 -234,20 +233,20 @@@ commit->parents = NULL; return; } - - reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; info->last_commit_reflog = commit_reflog; - commit_reflog->recno--; - commit_info->commit = (struct commit *)parse_object(reflog->osha1); - if (!commit_info->commit) { + + do { + reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; + commit_reflog->recno--; + logobj = parse_object(reflog->osha1); + } while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT)); + + if (!logobj || logobj->type != OBJ_COMMIT) { + commit_info->commit = NULL; commit->parents = NULL; return; } + commit_info->commit = (struct commit *)logobj; commit->parents = xcalloc(1, sizeof(struct commit_list)); commit->parents->item = commit_info->commit;