git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 25/30] subtree: have $indent actually affect indentation

From
Luke Shumaker <lukeshu@lukeshu.com>
Date
Apr 26, 2021, 17:45 UTC
Message-ID
<20210426174525.3937858-26-lukeshu@lukeshu.com>
In-Reply-To
<20210426174525.3937858-1-lukeshu@lukeshu.com>
From: Luke Shumaker <lukeshu@datawire.io>

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>
---
 contrib/subtree/git-subtree.sh | 42 +++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 53a1a025f5..768fa7b6b6 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -55,11 +55,13 @@ arg_split_annotate=
 arg_addmerge_squash=
 arg_addmerge_message=
 
+indent=0
+
 # Usage: debug [MSG...]
 debug () {
 	if test -n "$arg_debug"
 	then
-		printf "%s\n" "$*" >&2
+		printf "%$(($indent * 2))s%s\n" '' "$*" >&2
 	fi
 }
 
@@ -251,17 +253,17 @@ cache_miss () {
 	done
 }
 
-# Usage: check_parents PARENTS_EXPR INDENT
+# Usage: check_parents PARENTS_EXPR
 check_parents () {
-	assert test $# = 2
+	assert test $# = 1
 	missed=$(cache_miss "$1") || exit $?
-	local indent=$(($2 + 1))
+	local indent=$(($indent + 1))
 	for miss in $missed
 	do
 		if ! test -r "$cachedir/notree/$miss"
 		then
-			debug "  incorrect order: $miss"
-			process_split_commit "$miss" "" "$indent"
+			debug "incorrect order: $miss"
+			process_split_commit "$miss" ""
 		fi
 	done
 }
@@ -314,6 +316,8 @@ try_remove_previous () {
 find_latest_squash () {
 	assert test $# = 1
 	debug "Looking for latest squash ($dir)..."
+	local indent=$(($indent + 1))
+
 	dir="$1"
 	sq=
 	main=
@@ -360,6 +364,8 @@ find_latest_squash () {
 find_existing_splits () {
 	assert test $# = 2
 	debug "Looking for prior splits..."
+	local indent=$(($indent + 1))
+
 	dir="$1"
 	rev="$2"
 	main=
@@ -385,7 +391,7 @@ find_existing_splits () {
 			die "could not rev-parse split hash $b from commit $sq"
 			;;
 		END)
-			debug "  Main is: '$main'"
+			debug "Main is: '$main'"
 			if test -z "$main" -a -n "$sub"
 			then
 				# squash commits refer to a subtree
@@ -668,12 +674,11 @@ ensure_valid_ref_format () {
 		die "'$1' does not look like a ref"
 }
 
-# Usage: process_split_commit REV PARENTS INDENT
+# Usage: process_split_commit REV PARENTS
 process_split_commit () {
-	assert test $# = 3
+	assert test $# = 2
 	local rev="$1"
 	local parents="$2"
-	local indent=$3
 
 	if test $indent -eq 0
 	then
@@ -688,20 +693,21 @@ process_split_commit () {
 	progress "$revcount/$revmax ($createcount) [$extracount]"
 
 	debug "Processing commit: $rev"
+	local indent=$(($indent + 1))
 	exists=$(cache_get "$rev") || exit $?
 	if test -n "$exists"
 	then
-		debug "  prior: $exists"
+		debug "prior: $exists"
 		return
 	fi
 	createcount=$(($createcount + 1))
-	debug "  parents: $parents"
-	check_parents "$parents" "$indent"
+	debug "parents: $parents"
+	check_parents "$parents"
 	newparents=$(cache_get $parents) || exit $?
-	debug "  newparents: $newparents"
+	debug "newparents: $newparents"
 
 	tree=$(subtree_for_commit "$rev" "$dir") || exit $?
-	debug "  tree is: $tree"
+	debug "tree is: $tree"
 
 	# ugly.  is there no better way to tell if this is a subtree
 	# vs. a mainline commit?  Does it matter?
@@ -716,7 +722,7 @@ process_split_commit () {
 	fi
 
 	newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $?
-	debug "  newrev is: $newrev"
+	debug "newrev is: $newrev"
 	cache_set "$rev" "$newrev"
 	cache_set latest_new "$newrev"
 	cache_set latest_old "$rev"
@@ -820,7 +826,7 @@ cmd_split () {
 		do
 			# the 'onto' history is already just the subdir, so
 			# any parent we find there can be used verbatim
-			debug "  cache: $rev"
+			debug "cache: $rev"
 			cache_set "$rev" "$rev"
 		done || exit $?
 	fi
@@ -838,7 +844,7 @@ cmd_split () {
 	eval "$grl" |
 	while read rev parents
 	do
-		process_split_commit "$rev" "$parents" 0
+		process_split_commit "$rev" "$parents"
 	done || exit $?
 
 	latest_new=$(cache_get latest_new) || exit $?
-- 
2.31.1
Previous: Luke ShumakerNext: Luke Shumaker
Message 96 of 144 in “subtree: clean up, improve UX”
  1. 00/30 subtree: clean up, improve UXLuke Shumaker, Apr 23, 2021
  2. 01/30 .gitignore: Ignore /git-subtreeLuke Shumaker, Apr 23, 2021
  3. 02/30 subtree: t7900: update for having the default branch name be 'main'Luke Shumaker, Apr 23, 2021
  4. 04/30 subtree: t7900: use consistent formattingLuke Shumaker, Apr 23, 2021
  5. Eric SunshineApr 23, 2021
  6. Luke ShumakerApr 23, 2021
  7. Junio C HamanoApr 27, 2021
  8. Luke ShumakerApr 27, 2021
  9. Junio C HamanoApr 28, 2021
  10. 05/30 subtree: t7900: comment subtree_test_create_repoLuke Shumaker, Apr 23, 2021
  11. 03/30 subtree: t7900: use test-lib.sh's test_countLuke Shumaker, Apr 23, 2021
  12. 06/30 subtree: t7900: use 'test' for string equalityLuke Shumaker, Apr 23, 2021
  13. 07/30 subtree: t7900: delete some dead codeLuke Shumaker, Apr 23, 2021
  14. 08/30 subtree: t7900: fix 'verify one file change per commit'Luke Shumaker, Apr 23, 2021
  15. 09/30 subtree: t7900: rename last_commit_message to last_commit_subjectLuke Shumaker, Apr 23, 2021
  16. 10/30 subtree: t7900: add a test for the -h flagLuke Shumaker, Apr 23, 2021
  17. 11/30 subtree: t7900: add porcelain tests for 'pull' and 'push'Luke Shumaker, Apr 23, 2021
  18. Eric SunshineApr 23, 2021
  19. Luke ShumakerApr 23, 2021
  20. 12/30 subtree: don't have loose code outside of a functionLuke Shumaker, Apr 23, 2021
  21. Luke ShumakerApr 23, 2021
  22. Eric SunshineApr 23, 2021
  23. Luke ShumakerApr 23, 2021
  24. Eric SunshineApr 23, 2021
  25. Luke ShumakerApr 23, 2021
  26. 14/30 subtree: drop support for git < 1.7Luke Shumaker, Apr 23, 2021
  27. Luke ShumakerApr 23, 2021
  28. Eric SunshineApr 23, 2021
  29. Luke ShumakerApr 23, 2021
  30. Eric SunshineApr 23, 2021
  31. Luke ShumakerApr 24, 2021
  32. 13/30 subtree: more consistent error propagationLuke Shumaker, Apr 23, 2021
  33. 15/30 subtree: use `git merge-base --is-ancestor`Luke Shumaker, Apr 23, 2021
  34. 16/30 subtree: use git-sh-setup's `say`Luke Shumaker, Apr 23, 2021
  35. 17/30 subtree: use more explicit variable names for cmdline argsLuke Shumaker, Apr 23, 2021
  36. 18/30 subtree: use $* instead of $@ as appropriateLuke Shumaker, Apr 23, 2021
  37. Eric SunshineApr 23, 2021
  38. Luke ShumakerApr 23, 2021
  39. Eric SunshineApr 24, 2021
  40. 19/30 subtree: give `$(git --exec-path)` precedence over `$PATH`Luke Shumaker, Apr 23, 2021
  41. =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= BjarmasonApr 26, 2021
  42. 20/30 subtree: use "^{commit}" instead of "^0"Luke Shumaker, Apr 23, 2021
  43. Ævar Arnfjörð BjarmasonApr 26, 2021
  44. 21/30 subtree: parse revs in individual cmd_ functionsLuke Shumaker, Apr 23, 2021
  45. 22/30 subtree: remove duplicate checkLuke Shumaker, Apr 23, 2021
  46. 23/30 subtree: add comments and sanity checksLuke Shumaker, Apr 23, 2021
  47. Eric SunshineApr 23, 2021
  48. Luke ShumakerApr 23, 2021
  49. 24/30 subtree: don't let debug and progress output clashLuke Shumaker, Apr 23, 2021
  50. Eric SunshineApr 23, 2021
  51. Luke ShumakerApr 24, 2021
  52. Eric SunshineApr 24, 2021
  53. 25/30 subtree: have $indent actually affect indentationLuke Shumaker, Apr 23, 2021
  54. 26/30 subtree: give the docs a once-overLuke Shumaker, Apr 23, 2021
  55. 27/30 subtree: allow --squash to be used with --rejoinLuke Shumaker, Apr 23, 2021
  56. Eric SunshineApr 24, 2021
  57. Luke ShumakerApr 25, 2021
  58. 28/30 subtree: allow 'split' flags to be passed to 'push'Luke Shumaker, Apr 23, 2021
  59. 29/30 subtree: push: allow specifying a local rev other than HEADLuke Shumaker, Apr 23, 2021
  60. 30/30 subtree: be stricter about validating flagsLuke Shumaker, Apr 23, 2021
  61. Danny LinApr 25, 2021
  62. Luke ShumakerApr 26, 2021
  63. Luke ShumakerApr 23, 2021
  64. =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= BjarmasonApr 26, 2021
  65. Junio C HamanoApr 27, 2021
  66. 00/30 subtree: clean up, improve UXLuke Shumaker, Apr 26, 2021
  67. 01/30 .gitignore: Ignore /git-subtreeLuke Shumaker, Apr 26, 2021
  68. 02/30 subtree: t7900: update for having the default branch name be 'main'Luke Shumaker, Apr 26, 2021
  69. 04/30 subtree: t7900: use consistent formattingLuke Shumaker, Apr 26, 2021
  70. Luke ShumakerApr 26, 2021
  71. 03/30 subtree: t7900: use test-lib.sh's test_countLuke Shumaker, Apr 26, 2021
  72. 05/30 subtree: t7900: comment subtree_test_create_repoLuke Shumaker, Apr 26, 2021
  73. 06/30 subtree: t7900: use 'test' for string equalityLuke Shumaker, Apr 26, 2021
  74. 07/30 subtree: t7900: delete some dead codeLuke Shumaker, Apr 26, 2021
  75. 08/30 subtree: t7900: fix 'verify one file change per commit'Luke Shumaker, Apr 26, 2021
  76. 09/30 subtree: t7900: rename last_commit_message to last_commit_subjectLuke Shumaker, Apr 26, 2021
  77. 10/30 subtree: t7900: add a test for the -h flagLuke Shumaker, Apr 26, 2021
  78. 11/30 subtree: t7900: add porcelain tests for 'pull' and 'push'Luke Shumaker, Apr 26, 2021
  79. 12/30 subtree: don't have loose code outside of a functionLuke Shumaker, Apr 26, 2021
  80. 13/30 subtree: more consistent error propagationLuke Shumaker, Apr 26, 2021
  81. 16/30 subtree: use git-sh-setup's `say`Luke Shumaker, Apr 26, 2021
  82. 14/30 subtree: drop support for git < 1.7Luke Shumaker, Apr 26, 2021
  83. 17/30 subtree: use more explicit variable names for cmdline argsLuke Shumaker, Apr 26, 2021
  84. 15/30 subtree: use `git merge-base --is-ancestor`Luke Shumaker, Apr 26, 2021
  85. 18/30 subtree: use "$*" instead of "$@" as appropriateLuke Shumaker, Apr 26, 2021
  86. 20/30 subtree: use "^{commit}" instead of "^0"Luke Shumaker, Apr 26, 2021
  87. 21/30 subtree: parse revs in individual cmd_ functionsLuke Shumaker, Apr 26, 2021
  88. 19/30 subtree: Don't fuss with PATHLuke Shumaker, Apr 26, 2021
  89. Luke ShumakerApr 26, 2021
  90. 22/30 subtree: remove duplicate checkLuke Shumaker, Apr 26, 2021
  91. 28/30 subtree: allow 'split' flags to be passed to 'push'Luke Shumaker, Apr 26, 2021
  92. 24/30 subtree: don't let debug and progress output clashLuke Shumaker, Apr 26, 2021
  93. 23/30 subtree: add comments and sanity checksLuke Shumaker, Apr 26, 2021
  94. 30/30 subtree: be stricter about validating flagsLuke Shumaker, Apr 26, 2021
  95. 29/30 subtree: push: allow specifying a local rev other than HEADLuke Shumaker, Apr 26, 2021
  96. 25/30 subtree: have $indent actually affect indentationLuke Shumaker, Apr 26, 2021
  97. 27/30 subtree: allow --squash to be used with --rejoinLuke Shumaker, Apr 26, 2021
  98. Luke ShumakerApr 26, 2021
  99. 26/30 subtree: give the docs a once-overLuke Shumaker, Apr 26, 2021
  100. 00/30 subtree: clean up, improve UXLuke Shumaker, Apr 27, 2021
  101. 01/30 .gitignore: Ignore /git-subtreeLuke Shumaker, Apr 27, 2021
  102. 02/30 subtree: t7900: update for having the default branch name be 'main'Luke Shumaker, Apr 27, 2021
  103. Ævar Arnfjörð BjarmasonApr 30, 2021
  104. Luke ShumakerApr 30, 2021
  105. 03/30 subtree: t7900: use test-lib.sh's test_countLuke Shumaker, Apr 27, 2021
  106. Ævar Arnfjörð BjarmasonApr 30, 2021
  107. Luke ShumakerApr 30, 2021
  108. 04/30 subtree: t7900: use consistent formattingLuke Shumaker, Apr 27, 2021
  109. 05/30 subtree: t7900: comment subtree_test_create_repoLuke Shumaker, Apr 27, 2021
  110. Ævar Arnfjörð BjarmasonApr 30, 2021
  111. Luke ShumakerApr 30, 2021
  112. 06/30 subtree: t7900: use 'test' for string equalityLuke Shumaker, Apr 27, 2021
  113. Ævar Arnfjörð BjarmasonApr 30, 2021
  114. Luke ShumakerApr 30, 2021
  115. 07/30 subtree: t7900: delete some dead codeLuke Shumaker, Apr 27, 2021
  116. 08/30 subtree: t7900: fix 'verify one file change per commit'Luke Shumaker, Apr 27, 2021
  117. 09/30 subtree: t7900: rename last_commit_message to last_commit_subjectLuke Shumaker, Apr 27, 2021
  118. Ævar Arnfjörð BjarmasonApr 30, 2021
  119. 10/30 subtree: t7900: add a test for the -h flagLuke Shumaker, Apr 27, 2021
  120. Ævar Arnfjörð BjarmasonApr 30, 2021
  121. Luke ShumakerApr 30, 2021
  122. Bagas SanjayaApr 30, 2021
  123. Luke ShumakerApr 30, 2021
  124. 11/30 subtree: t7900: add porcelain tests for 'pull' and 'push'Luke Shumaker, Apr 27, 2021
  125. 12/30 subtree: don't have loose code outside of a functionLuke Shumaker, Apr 27, 2021
  126. 14/30 subtree: drop support for git < 1.7Luke Shumaker, Apr 27, 2021
  127. 13/30 subtree: more consistent error propagationLuke Shumaker, Apr 27, 2021
  128. 15/30 subtree: use `git merge-base --is-ancestor`Luke Shumaker, Apr 27, 2021
  129. 16/30 subtree: use git-sh-setup's `say`Luke Shumaker, Apr 27, 2021
  130. 17/30 subtree: use more explicit variable names for cmdline argsLuke Shumaker, Apr 27, 2021
  131. 18/30 subtree: use "$*" instead of "$@" as appropriateLuke Shumaker, Apr 27, 2021
  132. 19/30 subtree: don't fuss with PATHLuke Shumaker, Apr 27, 2021
  133. 20/30 subtree: use "^{commit}" instead of "^0"Luke Shumaker, Apr 27, 2021
  134. 21/30 subtree: parse revs in individual cmd_ functionsLuke Shumaker, Apr 27, 2021
  135. 22/30 subtree: remove duplicate checkLuke Shumaker, Apr 27, 2021
  136. 24/30 subtree: don't let debug and progress output clashLuke Shumaker, Apr 27, 2021
  137. 25/30 subtree: have $indent actually affect indentationLuke Shumaker, Apr 27, 2021
  138. 23/30 subtree: add comments and sanity checksLuke Shumaker, Apr 27, 2021
  139. 26/30 subtree: give the docs a once-overLuke Shumaker, Apr 27, 2021
  140. 28/30 subtree: allow 'split' flags to be passed to 'push'Luke Shumaker, Apr 27, 2021
  141. 29/30 subtree: push: allow specifying a local rev other than HEADLuke Shumaker, Apr 27, 2021
  142. 27/30 subtree: allow --squash to be used with --rejoinLuke Shumaker, Apr 27, 2021
  143. 30/30 subtree: be stricter about validating flagsLuke Shumaker, Apr 27, 2021
  144. Luke ShumakerApr 28, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.