On Thu, Jun 22, 2017 at 11:32:43AM -0700, Junio C Hamano wrote: > > diff --git a/reflog-walk.c b/reflog-walk.c > > index ed99437ad..b7e489ad3 100644 > > --- a/reflog-walk.c > > +++ b/reflog-walk.c > > @@ -259,6 +259,8 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit) > > /* a root commit, but there are still more entries to show */ > > reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; > > logobj = parse_object(&reflog->noid); > > + if (!logobj) > > + logobj = parse_object(&reflog->ooid); > > } > > > > if (!logobj || logobj->type != OBJ_COMMIT) { > > We already have a loop to find an entry that is a commit that > discards any non-commit object before the pre-context of this hunk. > This "oops, old side is NULL so let's cover it up by using the new > side" kicks in after that. I wonder if we can roll that cover-up > logic into the loop, perhaps like Yeah, I tried making the second conditional its own loop, but I agree it probably ought to be part of a single loop looking for a sane parent entry. > do { > reflog = &commit_reflog->...[recno]; > commit_reflog->recno--; > - logobj = parse_object(&reflog->ooid); > + logobj = parse_object(is_null_oid(&reflog->ooid) > + ? &reflog->noid : &reflog->ooid); > - } while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT)); > + } while (commit_reflog->recno && (!logobj || logobj->type != OBJ_COMMIT)); > - > - if (!logobj && commit_reflog->recno >= 0 && is_null_oid(&reflog->ooid)) { > - /* a root commit ... */ > - reflog = &commit_reflog->...[recno]; > - logobj = parse_object(&reflog->noid); > - } I don't think this is quite right, though. We've decremented "recno" after assigning the old pointer to "reflog". So in the existing code, "reflog" in that second conditional pointing to the _next_ entry (or previous, really, since we are going in reverse order). So I think you'd need to look at commit->reflog again (after checking that we didn't go past the start of the array). -Peff