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

[PATCH 3/3] contrib/subtree: replace echo options with printf

From
Paul Campbell <pcampbell@kemitix.net>
Date
Mar 24, 2013, 19:37 UTC
Message-ID
<1364153863-27437-4-git-send-email-pcampbell@kemitix.net>
In-Reply-To
<1364153863-27437-1-git-send-email-pcampbell@kemitix.net>

Options to echo are not portable. In particular, the echo -e option is implemented by some shells, including bash, to expand escape sequences.

Use the printf command instead, which is portable and much more reliable.

Only instances of echo and say (a wrapper for echo) where they are used with options have been replaced with printf.

say_progress() is added to mirror the behaviour of say() in respecting the -q/--quiet option.

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
---

This is a better version of the previously submitted patch (http://article.gmane.org/gmane.comp.version-control.git/218103) which added another option to echo.

 contrib/subtree/git-subtree.sh | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 884cbfb..35caf12 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -61,6 +61,13 @@ say()
 	fi
 }
 
+say_progress()
+{
+	if [ -z "$quiet" ]; then
+		printf "%s\r" "$@" >&2
+	fi
+}
+
 assert()
 {
 	if "$@"; then
@@ -311,7 +318,7 @@ copy_commit()
 			GIT_COMMITTER_NAME \
 			GIT_COMMITTER_EMAIL \
 			GIT_COMMITTER_DATE
-		(echo -n "$annotate"; cat ) |
+		(printf "$annotate"; cat ) |
 		git commit-tree "$2" $3  # reads the rest of stdin
 	) || die "Can't copy commit $1"
 }
@@ -592,7 +599,7 @@ cmd_split()
 	eval "$grl" |
 	while read rev parents; do
 		revcount=$(($revcount + 1))
-		say -n "$revcount/$revmax ($createcount)
"
+		say_progress "$revcount/$revmax ($createcount)"
 		debug "Processing commit: $rev"
 		exists=$(cache_get $rev)
 		if [ -n "$exists" ]; then
-- 
1.8.2
Previous: Simon Ruderich
Message 6 of 6 in “Improve POSIX compatibility and general portablity”
  1. 0/3 Improve POSIX compatibility and general portablityPaul Campbell, Mar 24, 2013
  2. 1/3 contrib/subtree: stop explicitly using a bash shellPaul Campbell, Mar 24, 2013
  3. Junio C HamanoMar 25, 2013
  4. 2/3 contrib/subtree: remove use of -a/-o in [ commandsPaul Campbell, Mar 24, 2013
  5. Simon RuderichMar 24, 2013
  6. 3/3 contrib/subtree: replace echo options with printfPaul Campbell, Mar 24, 2013

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.