From: Colin Stagner <ask+git@howdoi.land>
To: git@vger.kernel.org, Christian Heusel <christian@heusel.eu>,
george@mail.dietrich.pub
Cc: Christian Hesse <list@eworm.de>,
Phillip Wood <phillip.wood@dunelm.org.uk>,
Junio C Hamano <gitster@pobox.com>,
Colin Stagner <ask+git@howdoi.land>
Subject: [PATCH v2 2/3] contrib/subtree: functionalize split traversal
Date: Thu, 05 Mar 2026 17:55:48 -0600 [thread overview]
Message-ID: <20260305-cs-subtree-split-recursion-v2-2-7266be870ba9@howdoi.land> (raw)
In-Reply-To: <20260305-cs-subtree-split-recursion-v2-0-7266be870ba9@howdoi.land>
`git subtree split` requires an ancestor-first history traversal.
Refactor the existing rev-list traversal into its own function,
`find_commits_to_split`.
Pass unrevs via stdin to avoid limits on the maximum length of
command-line arguments. Also remove an unnecessary `eval`.
Signed-off-by: Colin Stagner <ask+git@howdoi.land>
---
contrib/subtree/git-subtree.sh | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index bae5d9170b..c1756b3e74 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -519,6 +519,31 @@ find_existing_splits () {
done || exit $?
}
+# Usage: find_commits_to_split REV UNREVS [ARGS...]
+#
+# List each commit to split, with its parents.
+#
+# Specify the starting REV for the split, which is usually
+# a branch tip. Populate UNREVS with the last --rejoin for
+# this prefix, if any. Typically, `subtree split` ignores
+# history prior to the last --rejoin... unless and if it
+# becomes necessary to consider it. `find_existing_splits` is
+# a convenient source of UNREVS.
+#
+# Remaining arguments are passed to rev-list.
+#
+# Outputs commits in ancestor-first order, one per line, with
+# parent information. Outputs all parents before any child.
+find_commits_to_split() {
+ assert test $# -ge 2
+ rev="$1"
+ unrevs="$2"
+ shift 2
+
+ echo "$unrevs" |
+ git rev-list --topo-order --reverse --parents --stdin "$rev" "$@"
+}
+
# Usage: copy_commit REV TREE FLAGS_STR
copy_commit () {
assert test $# = 3
@@ -976,12 +1001,11 @@ cmd_split () {
# 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)
- grl='git rev-list --topo-order --reverse --parents $rev $unrevs'
- revmax=$(eval "$grl" | wc -l)
+ revmax="$(find_commits_to_split "$rev" "$unrevs" --count)"
revcount=0
createcount=0
extracount=0
- eval "$grl" |
+ find_commits_to_split "$rev" "$unrevs" |
while read rev parents
do
process_split_commit "$rev" "$parents"
--
2.43.0
next prev parent reply other threads:[~2026-03-05 23:56 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-15 20:17 [PATCH 0/3] contrib/subtree: reduce recursion during split Colin Stagner
2026-02-15 20:17 ` [PATCH 1/3] contrib/subtree: reduce function side-effects Colin Stagner
2026-02-15 20:17 ` [PATCH 2/3] contrib/subtree: functionalize split traversal Colin Stagner
2026-02-15 20:17 ` [PATCH 3/3] contrib/subtree: reduce recursion during split Colin Stagner
2026-03-05 23:55 ` [PATCH v2 0/3] " Colin Stagner
2026-03-05 23:55 ` [PATCH v2 1/3] contrib/subtree: reduce function side-effects Colin Stagner
2026-03-05 23:55 ` Colin Stagner [this message]
2026-03-05 23:55 ` [PATCH v2 3/3] contrib/subtree: reduce recursion during split Colin Stagner
2026-03-13 22:51 ` [PATCH v2 0/3] " Junio C Hamano
2026-03-13 23:06 ` Junio C Hamano
2026-04-15 17:58 ` Junio C Hamano
2026-04-15 21:39 ` Ben Knoble
2026-04-16 13:25 ` Ian Jackson
2026-04-16 19:34 ` Junio C Hamano
2026-04-17 4:50 ` Colin Stagner
2026-04-19 19:55 ` Ian Jackson
2026-04-20 1:09 ` Ben Knoble
2026-04-20 1:50 ` Junio C Hamano
2026-04-20 9:57 ` Ian Jackson
2026-04-21 5:07 ` Colin Stagner
2026-04-22 9:43 ` Johannes Schindelin
2026-04-22 17:12 ` git-subtree rewrite Ian Jackson
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=20260305-cs-subtree-split-recursion-v2-2-7266be870ba9@howdoi.land \
--to=ask+git@howdoi.land \
--cc=christian@heusel.eu \
--cc=george@mail.dietrich.pub \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=list@eworm.de \
--cc=phillip.wood@dunelm.org.uk \
/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.