Skip to content

Commit 87af5a3

Browse files
committed
subtree: exclude commits predating add from recursive processing
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 <[email protected]>
1 parent 74fa670 commit 87af5a3

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ check_parents () {
244244
do
245245
if ! test -r "$cachedir/notree/$miss"
246246
then
247-
debug " incorrect order: $miss"
247+
debug " unprocessed parent commit: $miss ($indent)"
248248
process_split_commit "$miss" "" "$indent"
249249
fi
250250
done
@@ -392,6 +392,26 @@ find_existing_splits () {
392392
done
393393
}
394394

395+
find_mainline_ref () {
396+
debug "Looking for first split..."
397+
dir="$1"
398+
revs="$2"
399+
main=
400+
sub=
401+
local grep_format="^git-subtree-dir: $dir/*\$"
402+
git log --reverse --grep="$grep_format" \
403+
--no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs |
404+
while read a b junk
405+
do
406+
case "$a" in
407+
git-subtree-mainline:)
408+
echo "$b"
409+
return
410+
;;
411+
esac
412+
done
413+
}
414+
395415
copy_commit () {
396416
# We're going to set some environment vars here, so
397417
# do it in a subshell to get rid of them safely later
@@ -646,9 +666,9 @@ process_split_commit () {
646666

647667
progress "$revcount/$revmax ($createcount) [$extracount]"
648668

649-
debug "Processing commit: $rev"
669+
debug "Processing commit: $rev ($indent)"
650670
exists=$(cache_get "$rev")
651-
if test -n "$exists"
671+
if test -z "$(cache_miss "$rev")"
652672
then
653673
debug " prior: $exists"
654674
return
@@ -773,6 +793,17 @@ cmd_split () {
773793

774794
unrevs="$(find_existing_splits "$dir" "$revs")"
775795

796+
mainline="$(find_mainline_ref "$dir" "$revs")"
797+
if test -n "$mainline"
798+
then
799+
debug "Mainline $mainline predates subtree add"
800+
git rev-list --topo-order --skip=1 $mainline |
801+
while read rev
802+
do
803+
cache_set "$rev" ""
804+
done || exit $?
805+
fi
806+
776807
# We can't restrict rev-list to only $dir here, because some of our
777808
# parents have the $dir contents the root, and those won't match.
778809
# (and rev-list --follow doesn't seem to solve this)

0 commit comments

Comments
 (0)