Skip to content
Browse files

Replace all display related `echo` calls with a custom function

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  • Loading branch information...
1 parent 28506ea commit 4fae1acfb29d16e086c704d51fecf8ebd16bceed @jeffpc jeffpc committed Mar 30, 2008
Showing with 92 additions and 86 deletions.
  1. +24 −18 guilt
  2. +1 −1 guilt-export
  3. +5 −5 guilt-files
  4. +4 −4 guilt-graph
  5. +8 −8 guilt-import-commit
  6. +1 −1 guilt-new
  7. +1 −1 guilt-next
  8. +7 −7 guilt-patchbomb
  9. +2 −2 guilt-pop
  10. +1 −1 guilt-prev
  11. +2 −2 guilt-push
  12. +14 −14 guilt-rebase
  13. +10 −10 guilt-repair
  14. +3 −3 guilt-series
  15. +8 −8 guilt-status
  16. +1 −1 guilt-top
View
42 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
View
2 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."
View
10 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=:
View
8 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 "}"
View
16 guilt-import-commit
@@ -17,23 +17,23 @@ 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-`
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
View
2 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
View
2 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
View
14 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
View
4 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."
View
2 guilt-prev
@@ -19,5 +19,5 @@ done
p=`get_prev`
if [ -n "$p" ]; then
- echo $path$p
+ disp $path$p
fi
View
4 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
View
28 guilt-rebase
@@ -8,12 +8,12 @@
USAGE="<upstream>"
. `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,26 +74,26 @@ 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=":"
done
rm -rf "$rebase_dir"
-echo ""
-echo "Done."
+disp ""
+disp "Done."
View
20 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
View
6 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
View
16 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
}
View
2 guilt-top
@@ -19,5 +19,5 @@ done
p=`get_top`
if [ -n "$p" ]; then
- echo $path$p
+ disp "$path$p"
fi

0 comments on commit 4fae1ac

Please sign in to comment.
Something went wrong with that request. Please try again.