Skip to content

Commit 3b3ace4

Browse files
Colin Stagnergitster
authored andcommitted
contrib/subtree: functionalize split traversal
`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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f8e90b9 commit 3b3ace4

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,31 @@ find_existing_splits () {
519519
done || exit $?
520520
}
521521

522+
# Usage: find_commits_to_split REV UNREVS [ARGS...]
523+
#
524+
# List each commit to split, with its parents.
525+
#
526+
# Specify the starting REV for the split, which is usually
527+
# a branch tip. Populate UNREVS with the last --rejoin for
528+
# this prefix, if any. Typically, `subtree split` ignores
529+
# history prior to the last --rejoin... unless and if it
530+
# becomes necessary to consider it. `find_existing_splits` is
531+
# a convenient source of UNREVS.
532+
#
533+
# Remaining arguments are passed to rev-list.
534+
#
535+
# Outputs commits in ancestor-first order, one per line, with
536+
# parent information. Outputs all parents before any child.
537+
find_commits_to_split() {
538+
assert test $# -ge 2
539+
rev="$1"
540+
unrevs="$2"
541+
shift 2
542+
543+
echo "$unrevs" |
544+
git rev-list --topo-order --reverse --parents --stdin "$rev" "$@"
545+
}
546+
522547
# Usage: copy_commit REV TREE FLAGS_STR
523548
copy_commit () {
524549
assert test $# = 3
@@ -976,12 +1001,11 @@ cmd_split () {
9761001
# We can't restrict rev-list to only $dir here, because some of our
9771002
# parents have the $dir contents the root, and those won't match.
9781003
# (and rev-list --follow doesn't seem to solve this)
979-
grl='git rev-list --topo-order --reverse --parents $rev $unrevs'
980-
revmax=$(eval "$grl" | wc -l)
1004+
revmax="$(find_commits_to_split "$rev" "$unrevs" --count)"
9811005
revcount=0
9821006
createcount=0
9831007
extracount=0
984-
eval "$grl" |
1008+
find_commits_to_split "$rev" "$unrevs" |
9851009
while read rev parents
9861010
do
9871011
process_split_commit "$rev" "$parents"

0 commit comments

Comments
 (0)