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

[PATCH 2/7] subtree: exclude commits predating add from recursive processing

From
Tom Clarkson via GitGitGadget <gitgitgadget@gmail.com>
Date
May 11, 2020, 05:49 UTC
Message-ID
<87af5a316a2ca75e28fda466a04c27bdb02b96b2.1589176201.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.493.git.1589176201.gitgitgadget@gmail.com>
From: Tom Clarkson <tom@tqclarkson.com>

Include recursion depth in debug logs so we can see when the recursion is getting out of hand.

Making the cache handle null mappings correctly and adding older commits to the cache allows the recursive algorithm to terminate at any point on mainline rather than needing to reach either the add point or the initial commit.

Signed-off-by: Tom Clarkson <tom@tqclarkson.com>
---
 contrib/subtree/git-subtree.sh | 37 +++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 9867718503c..da0eede6979 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -244,7 +244,7 @@ check_parents () {
 	do
 		if ! test -r "$cachedir/notree/$miss"
 		then
-			debug "  incorrect order: $miss"
+			debug "  unprocessed parent commit: $miss ($indent)"
 			process_split_commit "$miss" "" "$indent"
 		fi
 	done
@@ -392,6 +392,26 @@ find_existing_splits () {
 	done
 }
 
+find_mainline_ref () {
+	debug "Looking for first split..."
+	dir="$1"
+	revs="$2"
+	main=
+	sub=
+	local grep_format="^git-subtree-dir: $dir/*\$"
+	git log --reverse --grep="$grep_format" \
+		--no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs |
+	while read a b junk
+	do
+		case "$a" in
+		git-subtree-mainline:)
+			echo "$b"
+			return
+			;;
+		esac
+	done
+}
+
 copy_commit () {
 	# We're going to set some environment vars here, so
 	# do it in a subshell to get rid of them safely later
@@ -646,9 +666,9 @@ process_split_commit () {
 
 	progress "$revcount/$revmax ($createcount) [$extracount]"
 
-	debug "Processing commit: $rev"
+	debug "Processing commit: $rev ($indent)"
 	exists=$(cache_get "$rev")
-	if test -n "$exists"
+	if test -z "$(cache_miss "$rev")"
 	then
 		debug "  prior: $exists"
 		return
@@ -773,6 +793,17 @@ cmd_split () {
 
 	unrevs="$(find_existing_splits "$dir" "$revs")"
 
+	mainline="$(find_mainline_ref "$dir" "$revs")"
+	if test -n "$mainline"
+	then
+		debug "Mainline $mainline predates subtree add"
+		git rev-list --topo-order --skip=1 $mainline |
+		while read rev
+		do
+			cache_set "$rev" ""
+		done || exit $?
+	fi
+
 	# We can't restrict rev-list to only $dir here, because some of our
 	# parents have the $dir contents the root, and those won't match.
 	# (and rev-list --follow doesn't seem to solve this)
-- 
gitgitgadget
Previous: Tom Clarkson via GitGitGadgetNext: Tom Clarkson via GitGitGadget
Message 3 of 28 in “subtree: Fix handling of complex history”
  1. 0/7 subtree: Fix handling of complex historyTom Clarkson via GitGitGadget, May 11, 2020
  2. 1/7 subtree: handle multiple parents passed to cache_missTom Clarkson via GitGitGadget, May 11, 2020
  3. 2/7 subtree: exclude commits predating add from recursive processingTom Clarkson via GitGitGadget, May 11, 2020
  4. 4/7 subtree: add git subtree map commandTom Clarkson via GitGitGadget, May 11, 2020
  5. 3/7 subtree: persist cache between split runsTom Clarkson via GitGitGadget, May 11, 2020
  6. 5/7 subtree: add git subtree use and ignore commandsTom Clarkson via GitGitGadget, May 11, 2020
  7. 7/7 subtree: document new subtree commandsTom Clarkson via GitGitGadget, May 11, 2020
  8. 6/7 subtree: more robustly distinguish subtree and mainline commitsTom Clarkson via GitGitGadget, May 11, 2020
  9. Ed MasteOct 4, 2020
  10. Johannes SchindelinOct 4, 2020
  11. Junio C HamanoOct 5, 2020
  12. Ed MasteOct 5, 2020
  13. Johannes SchindelinOct 7, 2020
  14. 0/7 subtree: Fix handling of complex historyTom Clarkson via GitGitGadget, Oct 6, 2020
  15. 4/7 subtree: add git subtree map commandTom Clarkson via GitGitGadget, Oct 6, 2020
  16. 1/7 subtree: handle multiple parents passed to cache_missTom Clarkson via GitGitGadget, Oct 6, 2020
  17. Ed MasteOct 7, 2020
  18. 5/7 subtree: add git subtree use and ignore commandsTom Clarkson via GitGitGadget, Oct 6, 2020
  19. Johannes SchindelinOct 7, 2020
  20. 6/7 subtree: more robustly distinguish subtree and mainline commitsTom Clarkson via GitGitGadget, Oct 6, 2020
  21. Johannes SchindelinOct 7, 2020
  22. 3/7 subtree: persist cache between split runsTom Clarkson via GitGitGadget, Oct 6, 2020
  23. Johannes SchindelinOct 7, 2020
  24. 2/7 subtree: exclude commits predating add from recursive processingTom Clarkson via GitGitGadget, Oct 6, 2020
  25. Johannes SchindelinOct 7, 2020
  26. 7/7 subtree: document new subtree commandsTom Clarkson via GitGitGadget, Oct 6, 2020
  27. Johannes SchindelinOct 7, 2020
  28. Johannes SchindelinOct 7, 2020

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.