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

[PATCH] contrib/subtree: portability fix for string printing

From
Danny Lin <danny0838@gmail.com>
Date
May 8, 2015, 00:51 UTC
Message-ID
<1431046299-5984-1-git-send-email-danny0838@gmail.com>
In-Reply-To
<xmqqmw1gp7aa.fsf@gitster.dls.corp.google.com>

Replace echo using printf in debug() and say() for better portability.

Also re-wrap previous 'say -n "$str<CR>"' using a new function progress() to prevent CR chars included in the source code, which could be mal-processed in some shells. For example, MsysGit trims CR before executing a shell script file in order to make it work right on Windows even if it uses CRLF as linefeeds.

Signed-off-by: Danny Lin <danny0838@gmail.com>
---
 contrib/subtree/git-subtree.sh | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index fa1a583..6f6ddbe 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -51,14 +51,21 @@ prefix=
 debug()
 {
 	if [ -n "$debug" ]; then
-		echo "$@" >&2
+		printf "%s\n" "$*" >&2
 	fi
 }
 
 say()
 {
 	if [ -z "$quiet" ]; then
-		echo "$@" >&2
+		printf "%s\n" "$*" >&2
+	fi
+}
+
+progress()
+{
+	if [ -z "$quiet" ]; then
+		printf "%s\r" "$*" >&2
 	fi
 }
 
@@ -247,7 +254,7 @@ find_latest_squash()
 						sq="$sub"
 					fi
 					debug "Squash found: $sq $sub"
-					echo "$sq" "$sub"
+					log "$sq" "$sub"
 					break
 				fi
 				sq=
@@ -599,7 +606,7 @@ cmd_split()
 	eval "$grl" |
 	while read rev parents; do
 		revcount=$(($revcount + 1))
-		say -n "$revcount/$revmax ($createcount)
"
+		progress "$revcount/$revmax ($createcount)"
 		debug "Processing commit: $rev"
 		exists=$(cache_get $rev)
 		if [ -n "$exists" ]; then
-- 
2.3.7.windows.1
Previous: Junio C HamanoNext: Danny Lin
Message 5 of 10 in “Re: [PATCH] contrib/subtree: fix linefeeds trimming for cmd_split()”
  1. Danny LinMay 7, 2015
  2. Danny LinMay 7, 2015
  3. Danny LinMay 7, 2015
  4. Junio C HamanoMay 7, 2015
  5. contrib/subtree: portability fix for string printingDanny Lin, May 8, 2015
  6. contrib/subtree: portability fix for string printingDanny Lin, May 8, 2015
  7. Junio C HamanoMay 8, 2015
  8. Eric SunshineMay 8, 2015
  9. Junio C HamanoMay 8, 2015
  10. Eric SunshineMay 8, 2015

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.