Skip to content

Commit 565e4b7

Browse files
roger-straingitster
authored andcommitted
subtree: refactor split of a commit into standalone method
In a particularly complex repo, subtree split was not creating compatible splits for pushing back to a separate repo. Addressing one of the issues requires recursive handling of parent commits that were not initially considered by the algorithm. This commit makes no functional changes, but relocates the code to be called recursively into a new method to simply comparisons of later commits. Signed-off-by: Strain, Roger L <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f84b9b0 commit 565e4b7

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,47 @@ ensure_valid_ref_format () {
598598
die "'$1' does not look like a ref"
599599
}
600600

601+
process_split_commit () {
602+
local rev="$1"
603+
local parents="$2"
604+
revcount=$(($revcount + 1))
605+
progress "$revcount/$revmax ($createcount)"
606+
debug "Processing commit: $rev"
607+
exists=$(cache_get "$rev")
608+
if test -n "$exists"
609+
then
610+
debug " prior: $exists"
611+
return
612+
fi
613+
createcount=$(($createcount + 1))
614+
debug " parents: $parents"
615+
newparents=$(cache_get $parents)
616+
debug " newparents: $newparents"
617+
618+
tree=$(subtree_for_commit "$rev" "$dir")
619+
debug " tree is: $tree"
620+
621+
check_parents $parents
622+
623+
# ugly. is there no better way to tell if this is a subtree
624+
# vs. a mainline commit? Does it matter?
625+
if test -z "$tree"
626+
then
627+
set_notree "$rev"
628+
if test -n "$newparents"
629+
then
630+
cache_set "$rev" "$rev"
631+
fi
632+
return
633+
fi
634+
635+
newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $?
636+
debug " newrev is: $newrev"
637+
cache_set "$rev" "$newrev"
638+
cache_set latest_new "$newrev"
639+
cache_set latest_old "$rev"
640+
}
641+
601642
cmd_add () {
602643
if test -e "$dir"
603644
then
@@ -706,42 +747,7 @@ cmd_split () {
706747
eval "$grl" |
707748
while read rev parents
708749
do
709-
revcount=$(($revcount + 1))
710-
progress "$revcount/$revmax ($createcount)"
711-
debug "Processing commit: $rev"
712-
exists=$(cache_get "$rev")
713-
if test -n "$exists"
714-
then
715-
debug " prior: $exists"
716-
continue
717-
fi
718-
createcount=$(($createcount + 1))
719-
debug " parents: $parents"
720-
newparents=$(cache_get $parents)
721-
debug " newparents: $newparents"
722-
723-
tree=$(subtree_for_commit "$rev" "$dir")
724-
debug " tree is: $tree"
725-
726-
check_parents $parents
727-
728-
# ugly. is there no better way to tell if this is a subtree
729-
# vs. a mainline commit? Does it matter?
730-
if test -z "$tree"
731-
then
732-
set_notree "$rev"
733-
if test -n "$newparents"
734-
then
735-
cache_set "$rev" "$rev"
736-
fi
737-
continue
738-
fi
739-
740-
newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $?
741-
debug " newrev is: $newrev"
742-
cache_set "$rev" "$newrev"
743-
cache_set latest_new "$newrev"
744-
cache_set latest_old "$rev"
750+
process_split_commit "$rev" "$parents"
745751
done || exit $?
746752

747753
latest_new=$(cache_get latest_new)

0 commit comments

Comments
 (0)