git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Dennis Kaarsemaker <dennis@kaarsemaker.net>
Date
Feb 2, 2016, 23:32 UTC
Message-ID
<1454455961-10640-1-git-send-email-dennis@kaarsemaker.net>
In-Reply-To
<1454241144.2822.7.camel@kaarsemaker.net>

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@kaarsemaker.net>
---
 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
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 10 in “git log -g bizarre behaviour”
  1. Dennis KaarsemakerJan 31, 2016
  2. Junio C HamanoFeb 1, 2016
  3. Dennis KaarsemakerFeb 2, 2016
  4. Junio C HamanoFeb 2, 2016
  5. Dennis KaarsemakerFeb 2, 2016
  6. Junio C HamanoFeb 2, 2016
  7. log -g: ignore revision parameters that have no reflogDennis Kaarsemaker, Feb 2, 2016
  8. Junio C HamanoFeb 3, 2016
  9. Dennis KaarsemakerFeb 3, 2016
  10. Junio C HamanoFeb 3, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.