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

Re: [PATCH 1/4] line-log: avoid unnecessary tree diffs when processing merge commits

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Aug 28, 2025, 20:27 UTC
Message-ID
<aLC7lQQWfdB/QUk3@szeder.dev>
In-Reply-To
<xmqqms7ntnvq.fsf@gitster.g>
On Mon, Aug 25, 2025 at 08:35:53AM -0700, Junio C Hamano wrote:
Show 39 quoted lines
> SZEDER Gábor <szeder.dev@gmail.com> writes:
> 
> > @@ -1209,7 +1202,6 @@ static int process_ranges_ordinary_commit(struct rev_info *rev, struct commit *c
> >  static int process_ranges_merge_commit(struct rev_info *rev, struct commit *commit,
> >  				       struct line_log_data *range)
> >  {
> > -	struct diff_queue_struct *diffqueues;
> >  	struct line_log_data **cand;
> >  	struct commit **parents;
> >  	struct commit_list *p;
> > @@ -1220,20 +1212,19 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
> >  	if (nparents > 1 && rev->first_parent_only)
> >  		nparents = 1;
> >  
> > -	ALLOC_ARRAY(diffqueues, nparents);
> >  	CALLOC_ARRAY(cand, nparents);
> >  	ALLOC_ARRAY(parents, nparents);
> >  
> >  	p = commit->parents;
> >  	for (i = 0; i < nparents; i++) {
> > +		struct diff_queue_struct diffqueue = DIFF_QUEUE_INIT;
> > +		int changed;
> >  		parents[i] = p->item;
> >  		p = p->next;
> > -		queue_diffs(range, &rev->diffopt, &diffqueues[i], commit, parents[i]);
> > -	}
> > +		queue_diffs(range, &rev->diffopt, &diffqueue, commit, parents[i]);
> >  
> > -	for (i = 0; i < nparents; i++) {
> > -		int changed;
> > -		changed = process_all_files(&cand[i], rev, &diffqueues[i], range);
> > +		changed = process_all_files(&cand[i], rev, &diffqueue, range);
> > +		diff_queue_clear(&diffqueue);
> >  		if (!changed) {
> >  			/*
> >  			 * This parent can take all the blame, so we
> 
> This is surprisingly small change that eliminates quite a lot of
> waste.  Nicely done.
It's funny you say that...

This patch series just turned 6 years old this weekend, and up until Sunday morning this first patch was actually two, because the optimization and the removal of the now unnecessary diffqueues array were two separate patches that I finally decided to squash together.

Here is the diff of that optimization-only patch :)
  ---- >8 ----
 line-log.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/line-log.c b/line-log.c
index 07f2154e84..b3766c67ea 100644
--- a/line-log.c
+++ b/line-log.c
@@ -1220,19 +1220,17 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
 	if (nparents > 1 && rev->first_parent_only)
 		nparents = 1;
 
-	ALLOC_ARRAY(diffqueues, nparents);
+	CALLOC_ARRAY(diffqueues, nparents);
 	CALLOC_ARRAY(cand, nparents);
 	ALLOC_ARRAY(parents, nparents);
 
 	p = commit->parents;
 	for (i = 0; i < nparents; i++) {
+		int changed;
 		parents[i] = p->item;
 		p = p->next;
 		queue_diffs(range, &rev->diffopt, &diffqueues[i], commit, parents[i]);
-	}
 
-	for (i = 0; i < nparents; i++) {
-		int changed;
 		changed = process_all_files(&cand[i], rev, &diffqueues[i], range);
 		if (!changed) {
 			/*
Previous: Junio C HamanoNext: SZEDER Gábor
Message 5 of 12 in “line-log: optimize merge commit processing”
  1. 0/4 line-log: optimize merge commit processingSZEDER Gábor, Aug 24, 2025
  2. 1/4 line-log: avoid unnecessary tree diffs when processing merge commitsSZEDER Gábor, Aug 24, 2025
  3. Derrick StoleeAug 25, 2025
  4. Junio C HamanoAug 25, 2025
  5. SZEDER GáborAug 28, 2025
  6. 2/4 line-log: get rid of the parents array in process_ranges_merge_commit()SZEDER Gábor, Aug 24, 2025
  7. 3/4 line-log: initialize diff queue in process_ranges_ordinary_commit()SZEDER Gábor, Aug 24, 2025
  8. 4/4 line-log: simplify condition checking for merge commitsSZEDER Gábor, Aug 24, 2025
  9. Junio C HamanoAug 25, 2025
  10. Derrick StoleeAug 25, 2025
  11. Junio C HamanoAug 25, 2025
  12. Derrick StoleeAug 25, 2025

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.