* [PATCH] line-log: fix crash when --first-parent is used
@ 2014-10-31 19:43 Tzvetan Mikov
2014-11-03 20:58 ` Junio C Hamano
2014-11-04 20:33 ` [PATCH v2] " Tzvetan Mikov
0 siblings, 2 replies; 7+ messages in thread
From: Tzvetan Mikov @ 2014-10-31 19:43 UTC (permalink / raw)
To: git; +Cc: Thomas Rast, Eric Sunshine, Tzvetan Mikov
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>
---
line-log.c | 3 +++
1 file changed, 3 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));
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] line-log: fix crash when --first-parent is used
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 20:33 ` [PATCH v2] " Tzvetan Mikov
1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2014-11-03 20:58 UTC (permalink / raw)
To: Tzvetan Mikov; +Cc: git, Thomas Rast, Eric Sunshine
Tzvetan Mikov <tmikov@gmail.com> writes:
> 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>
> ---
Thomas, how does this one look?
Tzvetan, can we have a test for this one?
Thanks.
> line-log.c | 3 +++
> 1 file changed, 3 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));
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] line-log: fix crash when --first-parent is used
2014-11-03 20:58 ` Junio C Hamano
@ 2014-11-03 22:09 ` Tzvetan Mikov
2014-11-04 9:34 ` Michael J Gruber
0 siblings, 1 reply; 7+ messages in thread
From: Tzvetan Mikov @ 2014-11-03 22:09 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Thomas Rast, Eric Sunshine, Eric Vander Weele
On Mon, Nov 3, 2014 at 12:58 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> 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.
>>
> [...]
> Tzvetan, can we have a test for this one?
Here is a sequence of commands to reproduce the crash:
git init
echo "1" > a.txt && git add a.txt && git commit -m "a"
git checkout -b branch
echo "2" > b.txt && git add b.txt && git commit -m "b"
git checkout master
git merge branch --no-ff -m "merge"
git log --first-parent -L 1,1:a.txt
I am not sure whether you have a requirement for a formal test
included with the patch, but if there is one, I am happy to
rework it.
This is a very simple fix for the crash, though possibly
a "real" comprehensive fix may be needed. I am not sure.
The real cause is that with "--first-parent" some commit
objects are never loaded from disk but may still be accessed.
(sorry about my formatting - have to use GMail)
regards,
Tzvetan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] line-log: fix crash when --first-parent is used
2014-11-03 22:09 ` Tzvetan Mikov
@ 2014-11-04 9:34 ` Michael J Gruber
0 siblings, 0 replies; 7+ messages in thread
From: Michael J Gruber @ 2014-11-04 9:34 UTC (permalink / raw)
To: Tzvetan Mikov, Junio C Hamano
Cc: git, Thomas Rast, Eric Sunshine, Eric Vander Weele
Tzvetan Mikov schrieb am 03.11.2014 um 23:09:
> On Mon, Nov 3, 2014 at 12:58 PM, Junio C Hamano <gitster@pobox.com> wrote:
>
>>> 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.
>>>
>
>> [...]
>> Tzvetan, can we have a test for this one?
>
> Here is a sequence of commands to reproduce the crash:
>
> git init
> echo "1" > a.txt && git add a.txt && git commit -m "a"
> git checkout -b branch
> echo "2" > b.txt && git add b.txt && git commit -m "b"
> git checkout master
> git merge branch --no-ff -m "merge"
> git log --first-parent -L 1,1:a.txt
>
> I am not sure whether you have a requirement for a formal test
> included with the patch, but if there is one, I am happy to
> rework it.
>
> This is a very simple fix for the crash, though possibly
> a "real" comprehensive fix may be needed. I am not sure.
> The real cause is that with "--first-parent" some commit
> objects are never loaded from disk but may still be accessed.
>
> (sorry about my formatting - have to use GMail)
>
> regards,
> Tzvetan
>
A test would be nice, yes. Look in t/t4211-line-log.sh - you should be
OK if you add a test at the end which does the following:
"git checkout parallel-change" so that you have commits with more than 1
parent in the history
test "git log -L1,1 b.c" (it core dumps with current git)
That is, you don't have to set up merges and history, you can use the
existing one.
Cheers,
Michael
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] line-log: fix crash when --first-parent is used
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-04 20:33 ` Tzvetan Mikov
2014-11-04 21:24 ` Junio C Hamano
1 sibling, 1 reply; 7+ messages in thread
From: Tzvetan Mikov @ 2014-11-04 20:33 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Michael J Gruber, Eric Vander Weele,
Tzvetan Mikov
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] line-log: fix crash when --first-parent is used
2014-11-04 20:33 ` [PATCH v2] " Tzvetan Mikov
@ 2014-11-04 21:24 ` Junio C Hamano
2014-11-04 21:41 ` Tzvetan Mikov
0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2014-11-04 21:24 UTC (permalink / raw)
To: Tzvetan Mikov; +Cc: git, Michael J Gruber, Eric Vander Weele
Tzvetan Mikov <tmikov@gmail.com> writes:
> 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)
Thanks, both. The patch looks good (modulo the indentation of
nparents assignment, which I'll locally fix up).
Will queue.
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] line-log: fix crash when --first-parent is used
2014-11-04 21:24 ` Junio C Hamano
@ 2014-11-04 21:41 ` Tzvetan Mikov
0 siblings, 0 replies; 7+ messages in thread
From: Tzvetan Mikov @ 2014-11-04 21:41 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Michael J Gruber, Eric Vander Weele
On Tue, Nov 4, 2014 at 1:24 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Thanks, both. The patch looks good (modulo the indentation of
> nparents assignment, which I'll locally fix up).
>
> Will queue.
Awesome, thanks!
(I can't believe I missed that tab. Well, at least one of my two
lines was correct :-) )
regards,
Tzvetan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-11-04 21:42 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2] " Tzvetan Mikov
2014-11-04 21:24 ` Junio C Hamano
2014-11-04 21:41 ` Tzvetan Mikov
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).