git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tzvetan Mikov <tmikov@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Michael J Gruber <git@drmicha.warpmail.net>,
	Eric Vander Weele <ericvw@gmail.com>,
	Tzvetan Mikov <tmikov@gmail.com>
Subject: [PATCH v2] line-log: fix crash when --first-parent is used
Date: Tue,  4 Nov 2014 12:33:37 -0800	[thread overview]
Message-ID: <1415133217-7824-1-git-send-email-tmikov@gmail.com> (raw)
In-Reply-To: <1414784636-43155-1-git-send-email-tmikov@gmail.com>

line-log tries to access all parents of a commit, but only the first
parent has been loaded if "--first-parent" is specified, resulting
in a crash.

Limit the number of parents to one if "--first-parent" is specified.

Reported-by: Eric N. Vander Weele <ericvw@gmail.com>
Signed-off-by: Tzvetan Mikov <tmikov@gmail.com>
---
 PATCH v2: Add a test case (thanks Michael J Gruber)

 line-log.c          | 3 +++
 t/t4211-line-log.sh | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/line-log.c b/line-log.c
index 1008e72..86e7274 100644
--- a/line-log.c
+++ b/line-log.c
@@ -1141,6 +1141,9 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
 	int i;
 	int nparents = commit_list_count(commit->parents);
 
+	if (nparents > 1 && rev->first_parent_only)
+	    nparents = 1;
+
 	diffqueues = xmalloc(nparents * sizeof(*diffqueues));
 	cand = xmalloc(nparents * sizeof(*cand));
 	parents = xmalloc(nparents * sizeof(*parents));
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index 7369d3c..0901b30 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -94,4 +94,9 @@ test_expect_success '-L ,Y (Y == nlines + 2)' '
 	test_must_fail git log -L ,$n:b.c
 '
 
+test_expect_success '-L with --first-parent and a merge' '
+	git checkout parallel-change &&
+	git log --first-parent -L 1,1:b.c
+'
+
 test_done
-- 
1.9.1

  parent reply	other threads:[~2014-11-04 20:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-31 19:43 [PATCH] line-log: fix crash when --first-parent is used Tzvetan Mikov
2014-11-03 20:58 ` Junio C Hamano
2014-11-03 22:09   ` Tzvetan Mikov
2014-11-04  9:34     ` Michael J Gruber
2014-11-04 20:33 ` Tzvetan Mikov [this message]
2014-11-04 21:24   ` [PATCH v2] " Junio C Hamano
2014-11-04 21:41     ` Tzvetan Mikov

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=1415133217-7824-1-git-send-email-tmikov@gmail.com \
    --to=tmikov@gmail.com \
    --cc=ericvw@gmail.com \
    --cc=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).