[PATCH] Only spout to stderr if $VERBOSE is set
martin f. krafft
madduck at madduck.net
Wed Apr 28 02:50:56 EST 2010
Informational and warning messages are now inhibited unless $VERBOSE is
set.
Signed-off-by: martin f. krafft <madduck at madduck.net>
---
lib/git/post-receive.hook | 36 +++++++++++++++++++++++++++++-------
1 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/lib/git/post-receive.hook b/lib/git/post-receive.hook
index f8a7c18..c7fa5d0 100755
--- a/lib/git/post-receive.hook
+++ b/lib/git/post-receive.hook
@@ -15,6 +15,28 @@ PWDIR=/srv/patchwork/apps/patchwork
do_exit=0
trap "do_exit=1" INT
+is_verbose()
+{
+ [ -n "${VERBOSE:-}" ]
+}
+
+err()
+{
+ echo "E: $@" >&2
+}
+
+warn()
+{
+ is_verbose || return
+ echo "W: $@" >&2
+}
+
+msg()
+{
+ is_verbose || return
+ echo "I: $@" >&2
+}
+
get_patchwork_hash()
{
local hash
@@ -42,19 +64,19 @@ update_patches()
local cnt; cnt=0
for rev in $(git rev-list --no-merges --reverse ${1}^..${2}); do
if [ "$do_exit" = 1 ]; then
- echo "I: exiting..." >&2
+ msg "exiting..."
break
fi
hash=$(get_patchwork_hash $rev) \
- || { echo "E: failed to hash rev $rev." >&2; continue; }
+ || { err "failed to hash rev $rev."; continue; }
id=$(get_patch_id $hash) \
- || { echo "E: failed to find patch for rev $rev." >&2; continue; }
+ || { warn "failed to find patch for rev $rev."; continue; }
reason="$(set_patch_state $id $3 $rev)" \
- || { echo "E: failed to update patch #$id${reason:+: $reason}." >&2; continue; }
- echo "I: set patch #$id to state $3 using rev $rev." >&2
+ || { err "failed to update patch #$id${reason:+: $reason}."; continue; }
+ msg "set patch #$id to state $3 using rev $rev."
cnt=$(($cnt + 1))
done
- echo "I: $cnt patch(es) updated to state $3." >&2
+ msg "$cnt patch(es) updated to state $3."
}
while read oldrev newrev refname; do
@@ -68,6 +90,6 @@ while read oldrev newrev refname; do
fi
done
if [ $found -eq 0 ]; then
- echo "E: no mapping for refname $key" >&2
+ err "no mapping for refname $key"
fi
done
--
1.6.5
More information about the Patchwork
mailing list