[PATCH] log -g: ignore revision parameters that have no reflog

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



git log -g (and by extension, git reflog) gets mightly confused when
trying to display the reflog of something that is not a ref that has a
reflog. We can help by teaching handle_revision_arg to check all
revision arguments for reflog existence if it's in reflog mode.

git log -g something-that-is-not-a ref makes no sense, so let's die when
the user is trying that. git log -g ref-that-has-no-reflog is perfectly
sensible, so we just ignore it.

Signed-off-by: Dennis Kaarsemaker <dennis@xxxxxxxxxxxxxxx>
---
 revision.c             | 12 ++++++++++++
 t/t1411-reflog-show.sh | 10 ++++++++++
 2 files changed, 22 insertions(+)

diff --git a/revision.c b/revision.c
index 0a282f5..43182c6 100644
--- a/revision.c
+++ b/revision.c
@@ -1498,6 +1498,18 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
 
 	flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM;
 
+	if (revs->reflog_info) {
+		/*
+		 * The reflog iterator gets confused when fed things that don't
+		 * have reflogs. Help it along a bit
+		 */
+		if (strchr(arg, '@') != arg &&
+		    !dwim_ref(arg, strchrnul(arg, '@')-arg, sha1, &dotdot))
+			die("only refs can have reflogs");
+		if(!reflog_exists(dotdot))
+			return 0;
+	}
+
 	dotdot = strstr(arg, "..");
 	if (dotdot) {
 		unsigned char from_sha1[20];
diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh
index 6ac7734..e55518f 100755
--- a/t/t1411-reflog-show.sh
+++ b/t/t1411-reflog-show.sh
@@ -171,4 +171,14 @@ test_expect_success 'reflog exists works' '
 	! git reflog exists refs/heads/nonexistent
 '
 
+test_expect_success 'reflog against non-ref dies' '
+	test_must_fail git reflog HEAD^
+'
+
+test_expect_success 'reflog against ref with no log is empty' '
+	git tag nolog &&
+	git reflog nolog > actual &&
+	test_line_count = 0 actual
+'
+
 test_done
-- 
2.7.0-345-gadc6f59

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]