All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: Junio C Hamano <gitster@pobox.com>, Kyle Meyer <kyle@kyleam.com>,
	git@vger.kernel.org, Sahil Dua <sahildua2305@gmail.com>
Subject: [PATCH 1/6] reflog-walk: skip over double-null oid due to HEAD rename
Date: Wed, 5 Jul 2017 03:57:37 -0400	[thread overview]
Message-ID: <20170705075737.6qsotqkzxdxofni6@sigill.intra.peff.net> (raw)
In-Reply-To: <20170705075508.c5ul23vivzpklpy6@sigill.intra.peff.net>

Since 39ee4c6c2f (branch: record creation of renamed branch
in HEAD's log, 2017-02-20), a rename on the currently
checked out branch will create two entries in the HEAD
reflog: one where the branch goes away (switching to the
null oid), and one where it comes back (switching away from
the null oid).

This confuses the reflog-walk code. When walking backwards,
it first sees the null oid in the "old" field of the second
entry. Thanks to the "root commit" logic added by 71abeb753f
(reflog: continue walking the reflog past root commits,
2016-06-03), we keep looking for the next entry by scanning
the "new" field from the previous entry. But that field is
also null! We need to go just a tiny bit further, and look
at its "old" field. But with the current code, we decide the
reflog has nothing else to show and just give up. To the
user this looks like the reflog was truncated by the rename
operation, when in fact those entries are still there.

This patch does the absolute minimal fix, which is to look
back that one extra level and keep traversing.

The resulting behavior may not be the _best_ thing to do in
the long run (for example, we show both reflog entries each
with the same commit id), but it's a simple way to fix the
problem without risking further regressions.

Signed-off-by: Jeff King <peff@peff.net>
---
I do still think it would be worth looking into making this rename
create a single reflog entry, but that's largely orthogonal to making
the display code sane(r).

 reflog-walk.c     |  2 ++
 t/t3200-branch.sh | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/reflog-walk.c b/reflog-walk.c
index ed99437ad2..b7e489ad32 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) {
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 48d152b9a9..dd37ac47c5 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -162,6 +162,17 @@ test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD'
 	grep "^0\{40\}.*$msg$" .git/logs/HEAD
 '
 
+test_expect_success 'resulting reflog can be shown by log -g' '
+	oid=$(git rev-parse HEAD) &&
+	cat >expect <<-EOF &&
+	HEAD@{0} $oid $msg
+	HEAD@{1} $oid $msg
+	HEAD@{2} $oid checkout: moving from foo to baz
+	EOF
+	git log -g --format="%gd %H %gs" -3 HEAD >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
 	git checkout master &&
 	git worktree add -b baz bazdir &&
-- 
2.13.2.892.g25f9b59978


  reply	other threads:[~2017-07-05  7:57 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-21 21:40 Truncating HEAD reflog on branch move brian m. carlson
2017-06-21 21:46 ` Junio C Hamano
2017-06-21 23:04   ` Kyle Meyer
2017-06-21 23:12     ` Kyle Meyer
2017-06-22 15:16     ` Jeff King
2017-06-22 18:32       ` Junio C Hamano
2017-06-22 18:45         ` Jeff King
2017-06-22 19:03           ` Junio C Hamano
2017-06-22 20:21             ` Jeff King
2017-06-22 20:32               ` Junio C Hamano
2017-06-22 21:52                 ` Jeff King
2017-06-22 22:25                   ` Jeff King
2017-06-23  3:13                     ` Jeff King
2017-07-04 19:58                       ` brian m. carlson
2017-07-04 21:24                         ` Jeff King
2017-07-04 21:27                           ` brian m. carlson
2017-07-04 21:28                             ` Jeff King
2017-07-05  1:49                           ` Junio C Hamano
2017-07-05  7:55                           ` [PATCH 0/6] fixing reflog-walk oddities Jeff King
2017-07-05  7:57                             ` Jeff King [this message]
2017-07-05 17:34                               ` [PATCH 1/6] reflog-walk: skip over double-null oid due to HEAD rename Junio C Hamano
2017-07-05 21:21                                 ` Jeff King
2017-07-05  8:00                             ` [PATCH 2/6] t1414: document some reflog-walk oddities Jeff King
2017-07-05 17:56                               ` Junio C Hamano
2017-07-05 21:27                                 ` Jeff King
2017-07-05 22:45                                   ` Junio C Hamano
2017-07-06  7:16                                     ` Jeff King
2017-07-06  7:55                                       ` Jeff King
2017-07-06 15:42                                       ` Junio C Hamano
2017-07-07  5:19                                         ` Jeff King
2017-07-07  6:00                                           ` Junio C Hamano
2017-07-07  6:22                                             ` Jeff King
2017-07-05 20:05                               ` Ramsay Jones
2017-07-05 21:30                                 ` Jeff King
2017-07-05  8:02                             ` [PATCH 3/6] log: do not free parents when walking reflog Jeff King
2017-07-05  8:04                             ` [PATCH 4/6] get_revision_1(): replace do-while with an early return Jeff King
2017-07-05  8:06                             ` [PATCH 5/6] rev-list: check reflog_info before showing usage Jeff King
2017-07-05 18:07                               ` Junio C Hamano
2017-07-05 21:31                                 ` Jeff King
2017-07-05  8:09                             ` [PATCH 6/6] reflog-walk: stop using fake parents Jeff King
2017-07-07  0:32                               ` Eric Wong
2017-07-07  3:02                                 ` Jeff King
2017-07-07  3:15                                   ` Jeff King
2017-07-10  9:42                                   ` Eric Wong
2017-07-10 11:20                                     ` Jeff King
2017-07-10 16:09                                     ` Junio C Hamano
2017-07-07  8:36                             ` [PATCH v2 0/4] reflog-walk fixes for maint Jeff King
2017-07-07  8:37                               ` [PATCH v2 1/4] reflog-walk: skip over double-null oid due to HEAD rename Jeff King
2017-07-07  8:39                               ` [PATCH v2 2/4] reflog-walk: duplicate strings in complete_reflogs list Jeff King
2017-07-07  8:41                               ` [PATCH v2 3/4] reflog-walk: don't free reflogs added to cache Jeff King
2017-07-07  8:43                               ` [PATCH v2 4/4] reflog-walk: include all fields when freeing complete_reflogs Jeff King
2017-07-07  9:05                               ` [PATCH v2 0/7] fixing reflog-walk oddities Jeff King
2017-07-07  9:06                                 ` [PATCH v2 1/7] t1414: document some " Jeff King
2017-07-07  9:21                                   ` Jeff King
2017-07-07 15:54                                   ` Kyle Meyer
2017-07-07  9:07                                 ` [PATCH v2 2/7] revision: disallow reflog walking with revs->limited Jeff King
2017-07-07  9:07                                 ` [PATCH v2 3/7] log: do not free parents when walking reflog Jeff King
2017-07-07 17:10                                   ` Junio C Hamano
2017-07-09 10:13                                     ` Jeff King
2017-07-09 16:59                                       ` Junio C Hamano
2017-07-10 13:27                                         ` Jeff King
2017-07-07  9:07                                 ` [PATCH v2 4/7] get_revision_1(): replace do-while with an early return Jeff King
2017-07-07  9:08                                 ` [PATCH v2 5/7] rev-list: check reflog_info before showing usage Jeff King
2017-07-07  9:14                                 ` [PATCH v2 6/7] reflog-walk: stop using fake parents Jeff King
2017-07-07  9:24                                   ` Jeff King
2017-07-07 15:54                                   ` Kyle Meyer
2017-07-09 10:08                                     ` Jeff King
2017-07-07  9:16                                 ` [PATCH v2 7/7] reflog-walk: apply --since/--until to reflog dates Jeff King
2017-07-07 20:15                               ` [PATCH v2 0/4] reflog-walk fixes for maint Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170705075737.6qsotqkzxdxofni6@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kyle@kyleam.com \
    --cc=sahildua2305@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.