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