All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Rast <trast@student.ethz.ch>
To: Jonathan Nieder <jrnieder@gmail.com>, Bo Yang <struggleyb.nku@gmail.com>
Cc: <git@vger.kernel.org>, Jens Lehmann <Jens.Lehmann@web.de>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] log -L: do not free parents lists we might need again
Date: Sat, 11 Sep 2010 23:10:57 +0200	[thread overview]
Message-ID: <92a37c8a8d7157aa8bf4d654f4e5bd713c69382d.1284239099.git.trast@student.ethz.ch> (raw)
In-Reply-To: <20100830171007.GC21441@burratino>

The parent rewriting code of 'git log -L' was too aggressive in
freeing memory: assign_range_to_parent() will free the commit->parents
field when it sees that a parent cannot pass off any blame (is a root
commit in rewritten history).

Its caller assign_parents_range() however will, upon finding the first
parent that takes *full* blame for all ranges, rewind and reinstate
all previous parents' line ranges and parent lists.  This resurrects
pointers to ranges that were freed in assign_range_to_parent() under
some circumstances.

Furthermore, we must not empty the parent lists either: the same
rewind/reinstate code relies on them.

Do both only if the commit was an ordinary (not merge or root) commit,
in which case the merge code-path discussed here is never taken.

Reported-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
[sorry for the double post, forgot to cc the list]

After staring at it for some time, I think this is the problem.

Sadly I cannot come up with an independent test that reproduces it (or
at least generates a valgrind warning).  Based on my analysis I tried

 diff --git a/t/t4302-log-line-merge-history.sh b/t/t4302-log-line-merge-history.sh
 index 8634116..7c86903 100755
 --- a/t/t4302-log-line-merge-history.sh
 +++ b/t/t4302-log-line-merge-history.sh
 @@ -171,4 +171,17 @@ test_expect_success 'validate the graph output.' '
  	test_cmp current-graph expected-graph
  '
  
 +test_expect_success 'set up trivial side merge' '
 +	git checkout -b trivial-side &&
 +	echo new_line >> path0 &&
 +	git add path0 &&
 +	git commit -m new_line &&
 +	git checkout master &&
 +	git merge --no-ff trivial-side
 +'
 +
 +test_expect_success 'log -L on the trivial-merged file' '
 +	git log -L /new_line/,+1 path0
 +'
 +
  test_done

but that does not fail.  I am hesitant to add your original test
because it strays into the directory where git was built, to test with
git's own history.  It just feels wrong.


 line.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/line.c b/line.c
index 63dd19a..b0deafb 100644
--- a/line.c
+++ b/line.c
@@ -961,8 +961,10 @@ static int assign_range_to_parent(struct rev_info *rev, struct commit *c,
 		 * If there is no new ranges assigned to the parent,
 		 * we should mark it as a 'root' commit.
 		 */
-		free(c->parents);
-		c->parents = NULL;
+		if (c->parents && !c->parents->next) {
+			free(c->parents);
+			c->parents = NULL;
+		}
 	}
 
 	/* and the ranges of current commit c is updated */
-- 
1.7.3.rc1.333.gf62981

  parent reply	other threads:[~2010-09-11 21:11 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-11 15:03 [PATCH V5 00/17] Reroll a version 5 of this series Bo Yang
2010-08-11 15:03 ` [PATCH V5 01/17] parse-options: enhance STOP_AT_NON_OPTION Bo Yang
2010-08-11 15:03 ` [PATCH V5 02/17] parse-options: add two helper functions Bo Yang
2010-08-11 15:03 ` [PATCH V5 03/17] Add the basic data structure for line level history Bo Yang
2010-08-11 15:03 ` [PATCH V5 04/17] Refactor parse_loc Bo Yang
2010-08-11 15:03 ` [PATCH V5 05/17] Parse the -L options Bo Yang
2010-08-11 15:03 ` [PATCH V5 06/17] Export three functions from diff.c Bo Yang
2010-08-11 15:03 ` [PATCH V5 07/17] Add range clone functions Bo Yang
2010-08-11 15:03 ` [PATCH V5 08/17] map/take range to the parent of commits Bo Yang
2010-08-11 15:03 ` [PATCH V5 09/17] Print the line log Bo Yang
2010-08-11 15:03 ` [PATCH V5 10/17] Hook line history into cmd_log, ensuring a topo-ordered walk Bo Yang
2010-08-11 15:03 ` [PATCH V5 11/17] Make rewrite_parents public to other part of git Bo Yang
2010-08-11 15:03 ` [PATCH V5 12/17] Make graph_next_line external " Bo Yang
2010-08-11 15:03 ` [PATCH V5 13/17] Add parent rewriting to line history browser Bo Yang
2010-08-30 17:10   ` log -L crash (Re: [PATCH V5 13/17] Add parent rewriting to line history browser) Jonathan Nieder
2010-09-01 14:47     ` Bo Yang
2010-09-11 21:10     ` Thomas Rast [this message]
2010-08-11 15:03 ` [PATCH V5 14/17] Add --graph prefix before line history output Bo Yang
2010-08-11 15:03 ` [PATCH V5 15/17] Add --full-line-diff option Bo Yang
2010-08-11 15:03 ` [PATCH V5 16/17] Add tests for line history browser Bo Yang
2010-08-12  1:25   ` Ævar Arnfjörð Bjarmason
2010-08-12 12:24     ` Bo Yang
2010-08-12 16:27       ` Ævar Arnfjörð Bjarmason
2010-08-12 20:37       ` Junio C Hamano
2010-08-12 21:06   ` Junio C Hamano
2010-08-11 15:03 ` [PATCH V5 17/17] Document " Bo Yang
2010-08-12  8:31 ` [PATCH V5 00/17] Reroll a version 5 of this series david
2010-08-12 17:23 ` 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=92a37c8a8d7157aa8bf4d654f4e5bd713c69382d.1284239099.git.trast@student.ethz.ch \
    --to=trast@student.ethz.ch \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=struggleyb.nku@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.