Skip to content

Commit e9525a8

Browse files
LukeShugitster
authored andcommitted
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 315a84f ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 534ff90 commit e9525a8

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ arg_split_annotate=
5555
arg_addmerge_squash=
5656
arg_addmerge_message=
5757

58+
indent=0
59+
5860
# Usage: debug [MSG...]
5961
debug () {
6062
if test -n "$arg_debug"
6163
then
62-
printf "%s\n" "$*" >&2
64+
printf "%$(($indent * 2))s%s\n" '' "$*" >&2
6365
fi
6466
}
6567

@@ -251,17 +253,17 @@ cache_miss () {
251253
done
252254
}
253255

254-
# Usage: check_parents PARENTS_EXPR INDENT
256+
# Usage: check_parents PARENTS_EXPR
255257
check_parents () {
256-
assert test $# = 2
258+
assert test $# = 1
257259
missed=$(cache_miss "$1") || exit $?
258-
local indent=$(($2 + 1))
260+
local indent=$(($indent + 1))
259261
for miss in $missed
260262
do
261263
if ! test -r "$cachedir/notree/$miss"
262264
then
263-
debug " incorrect order: $miss"
264-
process_split_commit "$miss" "" "$indent"
265+
debug "incorrect order: $miss"
266+
process_split_commit "$miss" ""
265267
fi
266268
done
267269
}
@@ -314,6 +316,8 @@ try_remove_previous () {
314316
find_latest_squash () {
315317
assert test $# = 1
316318
debug "Looking for latest squash ($dir)..."
319+
local indent=$(($indent + 1))
320+
317321
dir="$1"
318322
sq=
319323
main=
@@ -360,6 +364,8 @@ find_latest_squash () {
360364
find_existing_splits () {
361365
assert test $# = 2
362366
debug "Looking for prior splits..."
367+
local indent=$(($indent + 1))
368+
363369
dir="$1"
364370
rev="$2"
365371
main=
@@ -385,7 +391,7 @@ find_existing_splits () {
385391
die "could not rev-parse split hash $b from commit $sq"
386392
;;
387393
END)
388-
debug " Main is: '$main'"
394+
debug "Main is: '$main'"
389395
if test -z "$main" -a -n "$sub"
390396
then
391397
# squash commits refer to a subtree
@@ -668,12 +674,11 @@ ensure_valid_ref_format () {
668674
die "'$1' does not look like a ref"
669675
}
670676

671-
# Usage: process_split_commit REV PARENTS INDENT
677+
# Usage: process_split_commit REV PARENTS
672678
process_split_commit () {
673-
assert test $# = 3
679+
assert test $# = 2
674680
local rev="$1"
675681
local parents="$2"
676-
local indent=$3
677682

678683
if test $indent -eq 0
679684
then
@@ -688,20 +693,21 @@ process_split_commit () {
688693
progress "$revcount/$revmax ($createcount) [$extracount]"
689694

690695
debug "Processing commit: $rev"
696+
local indent=$(($indent + 1))
691697
exists=$(cache_get "$rev") || exit $?
692698
if test -n "$exists"
693699
then
694-
debug " prior: $exists"
700+
debug "prior: $exists"
695701
return
696702
fi
697703
createcount=$(($createcount + 1))
698-
debug " parents: $parents"
699-
check_parents "$parents" "$indent"
704+
debug "parents: $parents"
705+
check_parents "$parents"
700706
newparents=$(cache_get $parents) || exit $?
701-
debug " newparents: $newparents"
707+
debug "newparents: $newparents"
702708

703709
tree=$(subtree_for_commit "$rev" "$dir") || exit $?
704-
debug " tree is: $tree"
710+
debug "tree is: $tree"
705711

706712
# ugly. is there no better way to tell if this is a subtree
707713
# vs. a mainline commit? Does it matter?
@@ -716,7 +722,7 @@ process_split_commit () {
716722
fi
717723

718724
newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $?
719-
debug " newrev is: $newrev"
725+
debug "newrev is: $newrev"
720726
cache_set "$rev" "$newrev"
721727
cache_set latest_new "$newrev"
722728
cache_set latest_old "$rev"
@@ -820,7 +826,7 @@ cmd_split () {
820826
do
821827
# the 'onto' history is already just the subdir, so
822828
# any parent we find there can be used verbatim
823-
debug " cache: $rev"
829+
debug "cache: $rev"
824830
cache_set "$rev" "$rev"
825831
done || exit $?
826832
fi
@@ -838,7 +844,7 @@ cmd_split () {
838844
eval "$grl" |
839845
while read rev parents
840846
do
841-
process_split_commit "$rev" "$parents" 0
847+
process_split_commit "$rev" "$parents"
842848
done || exit $?
843849

844850
latest_new=$(cache_get latest_new) || exit $?

0 commit comments

Comments
 (0)