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

[PATCH] cherry_pick_list: quit early if one side is empty

From
Thomas Rast <trast@student.ethz.ch>
Date
Feb 20, 2010, 11:42 UTC
Message-ID
<a39e9a6e6f043121568de106f41f5b01eb38a200.1266665083.git.trast@student.ethz.ch>
In-Reply-To
<20100220072728.GA12168@coredump.intra.peff.net>

The --cherry-pick logic starts by counting the commits on each side, so that it can filter away commits on the bigger one. However, so far it missed an opportunity for optimization: it doesn't need to do any work if either side is empty.

This in particular helps the common use-case 'git rebase -i HEAD~$n': it internally uses --cherry-pick, but since HEAD~$n is a direct ancestor the left side is always empty.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
On Saturday 20 February 2010 08:27:28 Jeff King wrote:
> 
> From my reading of the code, that is right, but this is the first time I
> ever looked at it, so who knows? :)

Junio agreed too, so here's a real patch. To keep the complexity of git-rebase--interactive from exploding even further, you can drop the earlier one.

Show 8 quoted lines
> Does it really make sense to treat binary files as anything other than a
> blob for generating patch id? That is, should we simply turn it into:
> 
>   binary diff
>   $from_sha1
>   $to_sha1
> 
> and hash that for the patch id?
I tend to agree, but I can't seem to find out what flags to flip :-(
 revision.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/revision.c b/revision.c
index 438cc87..29721ec 100644
--- a/revision.c
+++ b/revision.c
@@ -547,6 +547,9 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)
 			right_count++;
 	}
 
+	if (!left_count || !right_count)
+		return;
+
 	left_first = left_count < right_count;
 	init_patch_ids(&ids);
 	if (revs->diffopt.nr_paths) {
-- 
1.7.0.139.gd1a75.dirty
Previous: Jeff KingNext: Jeff King
Message 5 of 8 in “Git has bad performance when traversing change-sets with large PPM files”
  1. Laine Walker-AvinaFeb 19, 2010
  2. rebase -i: avoid --cherry-pick when rebasing to a direct ancestorThomas Rast, Feb 19, 2010
  3. Thomas RastFeb 20, 2010
  4. Jeff KingFeb 20, 2010
  5. cherry_pick_list: quit early if one side is emptyThomas Rast, Feb 20, 2010
  6. Jeff KingFeb 21, 2010
  7. Thomas RastFeb 20, 2010
  8. Jeff KingFeb 21, 2010

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.