Git fork

subtree: have $indent actually affect indentation

Currently, the $indent variable is just used to track how deeply we're
nested, and the debug log is indented by things like

debug " foo"

That is: The indentation-level is hard-coded. It used to be that the
code couldn't recurse, so the indentation level could be known
statically, so it made sense to just hard-code it in the
output. However, since 315a84f9aa ("subtree: use commits before rejoins
for splits", 2018-09-28), it can now recurse, and the debug log is
misleading.

So fix that. Indent according to $indent.

Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Luke Shumaker and committed by
Junio C Hamano
e9525a8a 534ff90d

+24 -18
+24 -18
contrib/subtree/git-subtree.sh
··· 55 55 arg_addmerge_squash= 56 56 arg_addmerge_message= 57 57 58 + indent=0 59 + 58 60 # Usage: debug [MSG...] 59 61 debug () { 60 62 if test -n "$arg_debug" 61 63 then 62 - printf "%s\n" "$*" >&2 64 + printf "%$(($indent * 2))s%s\n" '' "$*" >&2 63 65 fi 64 66 } 65 67 ··· 251 253 done 252 254 } 253 255 254 - # Usage: check_parents PARENTS_EXPR INDENT 256 + # Usage: check_parents PARENTS_EXPR 255 257 check_parents () { 256 - assert test $# = 2 258 + assert test $# = 1 257 259 missed=$(cache_miss "$1") || exit $? 258 - local indent=$(($2 + 1)) 260 + local indent=$(($indent + 1)) 259 261 for miss in $missed 260 262 do 261 263 if ! test -r "$cachedir/notree/$miss" 262 264 then 263 - debug " incorrect order: $miss" 264 - process_split_commit "$miss" "" "$indent" 265 + debug "incorrect order: $miss" 266 + process_split_commit "$miss" "" 265 267 fi 266 268 done 267 269 } ··· 314 316 find_latest_squash () { 315 317 assert test $# = 1 316 318 debug "Looking for latest squash ($dir)..." 319 + local indent=$(($indent + 1)) 320 + 317 321 dir="$1" 318 322 sq= 319 323 main= ··· 360 364 find_existing_splits () { 361 365 assert test $# = 2 362 366 debug "Looking for prior splits..." 367 + local indent=$(($indent + 1)) 368 + 363 369 dir="$1" 364 370 rev="$2" 365 371 main= ··· 385 391 die "could not rev-parse split hash $b from commit $sq" 386 392 ;; 387 393 END) 388 - debug " Main is: '$main'" 394 + debug "Main is: '$main'" 389 395 if test -z "$main" -a -n "$sub" 390 396 then 391 397 # squash commits refer to a subtree ··· 668 674 die "'$1' does not look like a ref" 669 675 } 670 676 671 - # Usage: process_split_commit REV PARENTS INDENT 677 + # Usage: process_split_commit REV PARENTS 672 678 process_split_commit () { 673 - assert test $# = 3 679 + assert test $# = 2 674 680 local rev="$1" 675 681 local parents="$2" 676 - local indent=$3 677 682 678 683 if test $indent -eq 0 679 684 then ··· 688 693 progress "$revcount/$revmax ($createcount) [$extracount]" 689 694 690 695 debug "Processing commit: $rev" 696 + local indent=$(($indent + 1)) 691 697 exists=$(cache_get "$rev") || exit $? 692 698 if test -n "$exists" 693 699 then 694 - debug " prior: $exists" 700 + debug "prior: $exists" 695 701 return 696 702 fi 697 703 createcount=$(($createcount + 1)) 698 - debug " parents: $parents" 699 - check_parents "$parents" "$indent" 704 + debug "parents: $parents" 705 + check_parents "$parents" 700 706 newparents=$(cache_get $parents) || exit $? 701 - debug " newparents: $newparents" 707 + debug "newparents: $newparents" 702 708 703 709 tree=$(subtree_for_commit "$rev" "$dir") || exit $? 704 - debug " tree is: $tree" 710 + debug "tree is: $tree" 705 711 706 712 # ugly. is there no better way to tell if this is a subtree 707 713 # vs. a mainline commit? Does it matter? ··· 716 722 fi 717 723 718 724 newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $? 719 - debug " newrev is: $newrev" 725 + debug "newrev is: $newrev" 720 726 cache_set "$rev" "$newrev" 721 727 cache_set latest_new "$newrev" 722 728 cache_set latest_old "$rev" ··· 820 826 do 821 827 # the 'onto' history is already just the subdir, so 822 828 # any parent we find there can be used verbatim 823 - debug " cache: $rev" 829 + debug "cache: $rev" 824 830 cache_set "$rev" "$rev" 825 831 done || exit $? 826 832 fi ··· 838 844 eval "$grl" | 839 845 while read rev parents 840 846 do 841 - process_split_commit "$rev" "$parents" 0 847 + process_split_commit "$rev" "$parents" 842 848 done || exit $? 843 849 844 850 latest_new=$(cache_get latest_new) || exit $?