Re: Truncating HEAD reflog on branch move
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 22, 2017, 18:32 UTC
- Message-ID
- <xmqqziczkh4k.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20170622151603.rrh2j7zsotyt2jxe@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 9 quoted lines
> There's some magic in fake_reflog_parent() when we hit an entry with a > ... > This whole fake-parents things does just feel like a gigantic hack, > though. > ... > It seems like we should be able to just walk backwards down the > reflog list and show the entries. The revision machinery already > special-cases a bunch of reflog-walk bits; I don't know that adding one > or two more would be the end of the world.
Unfortunate but I tend to agree that at least such an addition would make the "gigantic hack" a bit more complete one ;-)
Show 13 quoted lines
> 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
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);
- }which may deal with your "both old and new sides were NULL" case better.