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 <roger.strain@swri.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Strain, Roger L committed Sep 28, 2018 at 13:35 UTC 565e4b79816c1618161a5bd647982aa0daff81c4
1 file changed +42 -36
contrib/subtree/git-subtree.sh
+42 -36
@@ -598,6 +598,47 @@ ensure_valid_ref_format () {
598 die "'$1' does not look like a ref"
599 }
600
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 +
642 cmd_add () {
643 if test -e "$dir"
644 then
@@ -706,42 +747,7 @@ cmd_split () {
747 eval "$grl" |
748 while read rev parents
749 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"
751 done || exit $?
752
753 latest_new=$(cache_get latest_new)