Patchwork Only spout to stderr if $VERBOSE is set

login
register
mail settings
Submitter Martin Krafft
Date April 27, 2010, 4:50 p.m.
Message ID <1272387056-31476-1-git-send-email-madduck@madduck.net>
Download mbox | patch
Permalink /patch/51096/
State Not Applicable
Delegated to: Jeremy Kerr
Headers show

Comments

Martin Krafft - April 27, 2010, 4:50 p.m.
Informational and warning messages are now inhibited unless $VERBOSE is
set.

Signed-off-by: martin f. krafft <madduck@madduck.net>
---
 lib/git/post-receive.hook |   36 +++++++++++++++++++++++++++++-------
 1 files changed, 29 insertions(+), 7 deletions(-)

Patch

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