From 4fae1acfb29d16e086c704d51fecf8ebd16bceed Mon Sep 17 00:00:00 2001 From: Josef 'Jeff' Sipek Date: Sun, 30 Mar 2008 02:05:20 -0400 Subject: [PATCH] Replace all display related `echo` calls with a custom function Signed-off-by: Josef 'Jeff' Sipek --- guilt | 42 ++++++++++++++++++++++++------------------ guilt-export | 2 +- guilt-files | 10 +++++----- guilt-graph | 8 ++++---- guilt-import-commit | 16 ++++++++-------- guilt-new | 2 +- guilt-next | 2 +- guilt-patchbomb | 14 +++++++------- guilt-pop | 4 ++-- guilt-prev | 2 +- guilt-push | 4 ++-- guilt-rebase | 28 ++++++++++++++-------------- guilt-repair | 20 ++++++++++---------- guilt-series | 6 +++--- guilt-status | 16 ++++++++-------- guilt-top | 2 +- 16 files changed, 92 insertions(+), 86 deletions(-) diff --git a/guilt b/guilt index 8fb5f43..4f189a9 100755 --- a/guilt +++ b/guilt @@ -38,10 +38,16 @@ esac # Shell library # -# echo -e is a bashism, fallback to /bin/echo if the builtin does not supports it -echo() +# echo -n is a bashism, use printf instead +_disp() { - /bin/echo "$@" + printf "%b" "$*" +} + +# echo -e is a bashism, use printf instead +disp() +{ + printf "%b\n" "$*" } noerr() @@ -94,23 +100,23 @@ if [ "`basename $0`" = "guilt" ]; then # this is not reached because of the exec die "Exec failed! Something is terribly wrong!" else - echo "Command $arg not found" >&2 - echo "" >&2 + disp "Command $arg not found" >&2 + disp "" >&2 fi fi # no args passed or invalid command entered, just output help summary - echo "Guilt v$GUILT_VERSION" - echo "" - echo "Pick a command:" - guilt_commands | sort | column | column -t | sed -e 's/^/\t/' + disp "Guilt v$GUILT_VERSION" + disp "" + disp "Pick a command:" + guilt_commands | sort | column | column -t | sed -e 's/^/ /' - echo "" - echo "Example:" - echo -e "\tguilt-push" - echo "or" - echo -e "\tguilt push" + disp "" + disp "Example:" + disp "\tguilt-push" + disp "or" + disp "\tguilt push" # now, let's exit exit 1 @@ -179,8 +185,8 @@ do_make_header() { # we should try to work with commit objects only if [ `git cat-file -t "$1"` != "commit" ]; then - echo "Hash $1 is not a commit object" >&2 - echo "Aborting..." >&2 + disp "Hash $1 is not a commit object" >&2 + disp "Aborting..." >&2 exit 2 fi @@ -268,8 +274,8 @@ head_check() esac if [ "`git rev-parse refs/heads/$branch`" != "`git rev-parse $1`" ]; then - echo "Expected HEAD commit $1" >&2 - echo " got `git rev-parse refs/heads/$branch`" >&2 + disp "Expected HEAD commit $1" >&2 + disp " got `git rev-parse refs/heads/$branch`" >&2 return 1 fi return 0 diff --git a/guilt-export b/guilt-export index 2c0a9fd..06e3da4 100755 --- a/guilt-export +++ b/guilt-export @@ -24,4 +24,4 @@ get_series | tee "$target_dir/series" | while read p; do done trap - 0 -echo "Series exported to \"$target_dir\" sucessfully." +disp "Series exported to \"$target_dir\" sucessfully." diff --git a/guilt-files b/guilt-files index d378327..721431a 100755 --- a/guilt-files +++ b/guilt-files @@ -35,7 +35,7 @@ fi | while read patch; do # shamelessly taken from Quilt(quilt/quilt/files) if [ -n "$opt_all" ] && [ -n "$opt_verbose" ] && [ -z "$opt_labels" ]; then - echo "$patch" + disp "$patch" fi if [ -n "$opt_verbose" ] && [ -z "$opt_labels" ]; then use_status=yes @@ -46,14 +46,14 @@ fi | while read patch; do while read omode nmode osha1 nsha1 st file; do if [ -n "$opt_labels" ]; then if [ -n "$opt_verbose" ]; then - echo -n "[$patch] " + _disp "[$patch] " else - echo -n "$patch " + _disp "$patch " fi fi if [ -z "$use_status" ]; then - echo "$file" + disp "$file" else status=" " if [ $osha1 = "0000000000000000000000000000000000000000" ]; then @@ -62,7 +62,7 @@ fi | while read patch; do if [ $nsha1 = "0000000000000000000000000000000000000000" ]; then status="-" fi - echo "$status $file" + disp "$status $file" fi done IFS=: diff --git a/guilt-graph b/guilt-graph index 8a05774..7d063b1 100755 --- a/guilt-graph +++ b/guilt-graph @@ -33,12 +33,12 @@ cache="$GUILT_DIR/$branch/.graphcache.$$" mkdir "$cache" trap "rm -rf \"$cache\"" 0 -echo "digraph G {" +disp "digraph G {" current="$top" while [ "$current" != "$base" ]; do - echo "# checking rev $current" + disp "# checking rev $current" # new "hash table" rm -f "$cache/dep" @@ -55,10 +55,10 @@ while [ "$current" != "$base" ]; do done sort -u "$cache/dep" | while read h; do - echo " \"${h:0:8}\" -> \"${current:0:8}\"; // ?" + disp " \"${h:0:8}\" -> \"${current:0:8}\"; // ?" done current=`git rev-parse $current^` done -echo "}" +disp "}" diff --git a/guilt-import-commit b/guilt-import-commit index cd4a456..a91aacb 100755 --- a/guilt-import-commit +++ b/guilt-import-commit @@ -17,8 +17,8 @@ if ! must_commit_first; then die "Uncommited changes detected. Refresh first." fi -echo "About to begin conversion..." >&2 -echo "Current head: `cat $GIT_DIR/refs/heads/$branch`" >&2 +disp "About to begin conversion..." >&2 +disp "Current head: `cat $GIT_DIR/refs/heads/$branch`" >&2 for rev in `git rev-list $rhash`; do s=`git log --pretty=oneline -1 $rev | cut -c 42-` @@ -26,14 +26,14 @@ for rev in `git rev-list $rhash`; do fname=`echo $s | sed -e "s/&/and/g" -e "s/[ :]/_/g" -e "s,[/\\],-,g" \ -e "s/['\\[{}]//g" -e 's/]//g' | tr A-Z a-z` - echo "Converting `echo $rev | cut -c 1-8` as $fname" + disp "Converting `echo $rev | cut -c 1-8` as $fname" mangle_prefix=1 fname_base=$fname while [ -f "$GUILT_DIR/$branch/$fname" ]; do fname="$fname_base-$mangle_prefix" mangle_prefix=`expr $mangle_prefix + 1` - echo "Patch under that name exists...trying '$fname'" + disp "Patch under that name exists...trying '$fname'" done ( @@ -55,12 +55,12 @@ for rev in `git rev-list $rhash`; do # history. git reset --hard $rev^ > /dev/null elif [ -z "$warned" ]; then - echo "Warning: commit $rev is not the HEAD...preserving commit" >&2 - echo "Warning: (this message is displayed only once)" >&2 + disp "Warning: commit $rev is not the HEAD...preserving commit" >&2 + disp "Warning: (this message is displayed only once)" >&2 warned=t fi done -echo "Done." >&2 -echo "Current head: `cat $GIT_DIR/refs/heads/$branch`" >&2 +disp "Done." >&2 +disp "Current head: `cat $GIT_DIR/refs/heads/$branch`" >&2 diff --git a/guilt-new b/guilt-new index da6c14e..2dcd14b 100755 --- a/guilt-new +++ b/guilt-new @@ -59,7 +59,7 @@ if [ -z "$force" ] && ! must_commit_first; then fi if ! valid_patchname "$patch"; then - echo "Patchname is invalid." >&2 + disp "Patchname is invalid." >&2 die "it cannot begin with '/', './' or '../', or contain /./, /../, or whitespace" fi diff --git a/guilt-next b/guilt-next index 510232b..8faa7b5 100755 --- a/guilt-next +++ b/guilt-next @@ -22,5 +22,5 @@ n=$(($n + 1)) p=`get_series | awk "{ if (NR == $n) print \\$0}"` if [ -n "$p" ]; then - echo $path$p + disp $path$p fi diff --git a/guilt-patchbomb b/guilt-patchbomb index 2ac3b2a..94bb0c0 100755 --- a/guilt-patchbomb +++ b/guilt-patchbomb @@ -34,7 +34,7 @@ fi # display the list of commits to be sent as patches git log --pretty=oneline "$r" | cut -c 1-8,41- | $pager -echo -n "Are these what you want to send? [Y/n] " +_disp "Are these what you want to send? [Y/n] " read n if [ "$n" = "n" ] || [ "$n" = "N" ]; then die "Aborting..." @@ -44,14 +44,14 @@ dir=/tmp/patches-$RANDOM/ if [ -e $dir ]; then die "Conspiracy uncovered: Temporary dir '$dir' already exists" fi -echo "Using '$dir' as temporary directory" +disp "Using '$dir' as temporary directory" git format-patch -o $dir -n -s "$r" # get the to/cc addresses -echo -n "Enter all the To: email addresses (separated by space): " +_disp "Enter all the To: email addresses (separated by space): " read rawto -echo -n "Enter all the Cc: email addresses (separated by space): " +_disp "Enter all the Cc: email addresses (separated by space): " read rawcc # convert list of email addresses to command line options @@ -72,7 +72,7 @@ fi opts="$opts $to_opts" # last possible point to abort! -echo -n "Proceed with patchbomb (this is the last chance to abort)? [y/N] " +_disp "Proceed with patchbomb (this is the last chance to abort)? [y/N] " read n if [ "$n" != "y" ] && [ "$n" != "Y" ]; then die "Aborting..." @@ -81,7 +81,7 @@ fi # ...and off they go. cmd="git send-email" if [ ! -z "$do_not_send" ]; then - echo "-n passed: not sending, command that would be executed:" >&2 + disp "-n passed: not sending, command that would be executed:" >&2 cmd="echo git send-email" fi @@ -92,7 +92,7 @@ else fi # cleanup? -echo -n "Delete temporary directory? [Y/n] " +_disp "Delete temporary directory? [Y/n] " read n [ "$n" = "n" ] || [ "$n" = "N" ] && exit 0 diff --git a/guilt-pop b/guilt-pop index 4d736f9..db8473e 100755 --- a/guilt-pop +++ b/guilt-pop @@ -45,7 +45,7 @@ patch="$1" [ ! -z "$all" ] && patch="-a" if [ ! -s "$applied" ]; then - echo "No patches applied." + disp "No patches applied." exit 0 elif [ "$patch" = "-a" ]; then # we are supposed to pop all patches @@ -96,5 +96,5 @@ l=`awk "BEGIN{n=0}(n==$eidx){print \\$0; exit}{n=n+1}END{}" < $applied` pop_many_patches `git rev-parse refs/patches/$branch/$l^` `expr $sidx - $eidx` p=`get_top` -[ ! -z "$p" ] && echo "Now at $p." || echo "All patches popped." +[ ! -z "$p" ] && disp "Now at $p." || disp "All patches popped." diff --git a/guilt-prev b/guilt-prev index 9309cd5..29627d5 100755 --- a/guilt-prev +++ b/guilt-prev @@ -19,5 +19,5 @@ done p=`get_prev` if [ -n "$p" ]; then - echo $path$p + disp $path$p fi diff --git a/guilt-push b/guilt-push index 3509e4b..018f9ac 100755 --- a/guilt-push +++ b/guilt-push @@ -99,7 +99,7 @@ sidx=`expr $sidx + 1` get_series | sed -n -e "${sidx},${eidx}p" | while read p do - echo "Applying patch..$p" + disp "Applying patch..$p" if [ ! -f "$GUILT_DIR/$branch/$p" ]; then die "Patch $p does not exist. Aborting." fi @@ -108,7 +108,7 @@ do # bail if necessary if [ $? -eq 0 ]; then - echo "Patch applied." + disp "Patch applied." elif [ -z "$abort_flag" ]; then die "Patch applied with rejects. Fix it up, and refresh." else diff --git a/guilt-rebase b/guilt-rebase index 3a698e1..ebfe056 100755 --- a/guilt-rebase +++ b/guilt-rebase @@ -8,12 +8,12 @@ USAGE="" . `dirname $0`/guilt -echo "Beware, rebase is currently EXPERIMENTAL." -echo "In other words, it might eat your patches." -echo -n "Do you wish to proceed? [y/N] " +disp "Beware, rebase is currently EXPERIMENTAL." +disp "In other words, it might eat your patches." +_disp "Do you wish to proceed? [y/N] " read n if [ "$n" != "y" -a "$n" != "Y" ]; then - echo "Aborted." + disp "Aborted." exit 0 fi @@ -56,13 +56,13 @@ done # the patches that were pushed before we started rebasing cp "$applied" "$rebase_dir/status" -echo "First, poping all patches..." +disp "First, poping all patches..." pop_all_patches git merge --no-commit $upstream > /dev/null 2> /dev/null -echo "" +disp "" log=`git log -1 --pretty=oneline` -echo "HEAD is now at `echo $log | cut -c 1-7`... `echo "$log" | cut -c 41-`" +disp "HEAD is now at `echo $log | cut -c 1-7`... `echo "$log" | cut -c 41-`" # # For each previously applied patch: @@ -74,20 +74,20 @@ echo "HEAD is now at `echo $log | cut -c 1-7`... `echo "$log" | cut -c 41-`" # IFS=":" cat "$rebase_dir/status" | while read hash name; do - echo "" + disp "" IFS=" " cat "$GUILT_DIR/$branch/$name" | git patch-id | while read patchid commitid ; do - echo "Applying '$name'" + disp "Applying '$name'" if [ -f "$rebase_dir/$patchid" ]; then realcommit=`head -1 "$rebase_dir/$patchid"` - echo "Matches upstream commit $realcommit" + disp "Matches upstream commit $realcommit" series_rename_patch "$name" "###rebased###$name" - echo "Patch removed from series." + disp "Patch removed from series." else # FIXME: use a guilt function instead guilt-push > /dev/null - echo "Patch applied." + disp "Patch applied." fi done IFS=":" @@ -95,5 +95,5 @@ done rm -rf "$rebase_dir" -echo "" -echo "Done." +disp "" +disp "Done." diff --git a/guilt-repair b/guilt-repair index bd88b60..42f6625 100755 --- a/guilt-repair +++ b/guilt-repair @@ -38,12 +38,12 @@ oldrev=`git show-ref -s "refs/heads/$branch"` # repair_status() { - printf "Checking status file format..." + _disp "Checking status file format..." if ! grep "^[0-9a-f]\{40\}:" "$applied" > /dev/null ; then - echo "ok; no upgrade necessary." + disp "ok; no upgrade necessary." return 0 fi - echo "old; about to upgrade." + disp "old; about to upgrade." # we got an old format status file @@ -70,7 +70,7 @@ repair_status() mv "$applied" "$applied~" mv "$applied.new" "$applied" - echo "Upgrade complete." + disp "Upgrade complete." return 0 } @@ -88,11 +88,11 @@ repair_pushed() newrev="$oldrev" fi - echo "Current HEAD commit $oldrev" - echo "New HEAD commit $newrev" + disp "Current HEAD commit $oldrev" + disp "New HEAD commit $newrev" - echo "About to forcefully pop all patches..." - echo -n "Are you sure you want to proceed? [y/N] " + disp "About to forcefully pop all patches..." + _disp "Are you sure you want to proceed? [y/N] " read n if [ "$n" != "y" ] && [ "$n" != "Y" ]; then die "Aborting..." @@ -108,7 +108,7 @@ repair_pushed() # remove the ${branch}_{top,bottom,base} tags update_stack_tags "force" - echo "Patches should be popped." + disp "Patches should be popped." return 0 } @@ -134,5 +134,5 @@ case "$repair" in ;; esac -echo "Repair complete." +disp "Repair complete." exit 0 diff --git a/guilt-series b/guilt-series index f37568b..7d8f8e9 100755 --- a/guilt-series +++ b/guilt-series @@ -44,13 +44,13 @@ else get_series | while read patch; do if [ -z "$top" ]; then - echo " $patch" + disp " $patch" else if [ "$patch" = "$top" ]; then - echo "= $patch" + disp "= $patch" prefix=" " else - echo "$prefix $patch" + disp "$prefix $patch" fi fi done diff --git a/guilt-status b/guilt-status index a34e98e..0130826 100755 --- a/guilt-status +++ b/guilt-status @@ -69,14 +69,14 @@ print_status() while read status name newname do case "$status" in - A*) echo "$Apfx$name";; - C*) echo "$Cpfx$name -> $newname";; - D*) echo "$Dpfx$name";; - M ) echo "$Mpfx$name";; - R*) echo "$Rpfx$name -> $newname";; - T ) echo "$Tpfx$name";; - U ) echo "$Upfx$name";; - ? ) echo "$Xpfx$name";; + A*) disp "$Apfx$name";; + C*) disp "$Cpfx$name -> $newname";; + D*) disp "$Dpfx$name";; + M ) disp "$Mpfx$name";; + R*) disp "$Rpfx$name -> $newname";; + T ) disp "$Tpfx$name";; + U ) disp "$Upfx$name";; + ? ) disp "$Xpfx$name";; esac done } diff --git a/guilt-top b/guilt-top index 289f798..f0907ad 100755 --- a/guilt-top +++ b/guilt-top @@ -19,5 +19,5 @@ done p=`get_top` if [ -n "$p" ]; then - echo $path$p + disp "$path$p" fi -- 2.11.4.GIT