From: Dennis Kaarsemaker <dennis@kaarsemaker.net>
To: git@vger.kernel.org
Cc: Dennis Kaarsemaker <dennis@kaarsemaker.net>
Subject: [PATCH] log -g: ignore revision parameters that have no reflog
Date: Wed, 3 Feb 2016 00:32:41 +0100 [thread overview]
Message-ID: <1454455961-10640-1-git-send-email-dennis@kaarsemaker.net> (raw)
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
next prev parent reply other threads:[~2016-02-02 23:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-31 11:52 git log -g bizarre behaviour Dennis Kaarsemaker
2016-02-01 23:37 ` Junio C Hamano
2016-02-02 8:28 ` Dennis Kaarsemaker
2016-02-02 19:32 ` Junio C Hamano
2016-02-02 20:22 ` Dennis Kaarsemaker
2016-02-02 20:42 ` Junio C Hamano
2016-02-02 23:32 ` Dennis Kaarsemaker [this message]
2016-02-03 0:21 ` [PATCH] log -g: ignore revision parameters that have no reflog Junio C Hamano
2016-02-03 12:35 ` Dennis Kaarsemaker
2016-02-03 18:32 ` 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=1454455961-10640-1-git-send-email-dennis@kaarsemaker.net \
--to=dennis@kaarsemaker.net \
--cc=git@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).