gnats-prs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnats/697: send-pr: comments not removed when template is provided by th


From: bug-gnats
Subject: gnats/697: send-pr: comments not removed when template is provided by the user
Date: Mon, 28 Aug 2006 10:15:02 -0500 (CDT)

>Number:         697
>Category:       gnats
>Synopsis:       send-pr: comments not removed when template is provided by the 
>user
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 28 10:15:01 -0500 2006
>Originator:     Stephane Chazelas <address@hidden>
>Release:        
>Description:
 
 Hi guys,
 
 A problem with send-pr. If one uses his own template for the
 send-pr command, the comments inside <...> are not removed
 before submitting the PR as they are when a template is not provided.
 
 Also, I noticed that some error messages where not sent to
 stderr. Some tidy up in other places as well in the patch below.
 
>Fix:

Also added a $SENDPR_CLEANUP variable that the user might want
to define in his ~/.send-pr.conf

--- /opt/gnats/sparc-sun-solaris2.7/bin/send-pr 2006-08-25 12:20:40.354208000 
+0100
+++ send-pr     2006-08-28 12:22:09.267001000 +0100
@@ -92,6 +92,9 @@
   fi
 fi
 
+NL='
+'
+
 # TEMP:   Temporary copy of the PR, to be edited by the user.
 # BAD:    The PR will end up here if the user aborts.
 # REF:    The 'reference' copy of the PR template, used to verify that the user
@@ -227,23 +230,23 @@
     -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
        shift ; IN_FILE="$1"
        if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
-         echo "$COMMAND: cannot read $IN_FILE"
+         echo >&2 "$COMMAND: cannot read $IN_FILE"
          exit 1
        fi
        ;;
     -b | --batch) BATCH=true ;;
-    -d | --database) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
+    -d | --database) if [ $# -eq 1 ]; then echo >&2 "$USAGE"; exit 1; fi
         shift; GNATSDB="$1"; export GNATSDB
     ;;
-    -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
+    -s | --severity) if [ $# -eq 1 ]; then echo >&2 "$USAGE"; exit 1; fi
        shift ; DEFAULT_SEVERITY="$1"
        ;;
     -p | -P | --print) PRINT=true ;;
     --request-id) REQUEST_ID=true ;;
     -h | --help) echo "$USAGE"; exit 0 ;;
     -V | --version) echo "$VERSION"; exit 0 ;;
-    -*) echo "$USAGE" ; exit 1 ;;
-    *)  echo "$USAGE" ; exit 1 ;;
+    -*) echo >&2 "$USAGE" ; exit 1 ;;
+    *)  echo >&2 "$USAGE" ; exit 1 ;;
  esac
  shift
 done
@@ -275,7 +278,7 @@
 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
 xs=0
 trap 'rm -f $REF $TEMP $FIXFIL; exit $xs' 0
-trap 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP $FIXFIL; xs=1; exit' 1 3 
13 15
+trap 'echo >&2 "$COMMAND: Aborting ..."; rm -f $REF $TEMP $FIXFIL; xs=1; exit' 
1 3 13 15
 
 if [ "x$PRINT" = "xtrue" ]; then
   FROM="<FROM>"
@@ -297,7 +300,7 @@
   if [ -n "$TEMPLATE" -a -z "$PRINT_INTERN" ]; then
     # If their TEMPLATE points to a bogus entry, then bail.
     if [ ! -f "$TEMPLATE" -o ! -r "$TEMPLATE" -o ! -s "$TEMPLATE" ]; then
-      echo "$COMMAND: can't seem to read your template file (\`$TEMPLATE'), 
ignoring TEMPLATE"
+      echo >&2 "$COMMAND: can't seem to read your template file 
(\`$TEMPLATE'), ignoring TEMPLATE"
       sleep 1
       PRINT_INTERN=bad_prform
     fi
@@ -305,7 +308,27 @@
 
   if [ -n "$TEMPLATE" -a -z "$PRINT_INTERN" ]; then
     sed 
"s/<FROM>/$FROM/;s/<REPLYTO>/$REPLYTO/;s/<DEFAULT_ORIGINATOR>/$DEFAULT_ORIGINATOR/;s/<SUBMITTER>/$DEFAULT_SUBMITTERID/"
 < $TEMPLATE > $TEMP ||
-      ( echo "$COMMAND: could not copy $TEMPLATE" ; xs=1; exit )
+      { echo >&2 "$COMMAND: could not copy $TEMPLATE" ; xs=1; exit; }
+    if [ -z "${SENDPR_CLEANUP+set}" ]; then
+      # build a cleanup sed script to schedule the removal of comments
+      # that the template may contain. It turns every <...> into a
+      # s/<...>//g sed command. <address@hidden> are not considered as 
comments.
+      # the user may want to provide with his own SENDPR_CLEANUP via the
+      # environment or ~/.send-pr.conf
+      SENDPR_CLEANUP=`
+        sed '
+         /<[^<>@]*>/!d
+         s/_/_u/g
+         s/|/_p/g
+         s/<[^<>@]*>/|&|/g
+         s/.*/|&|/
+         s/|[^|]*|//g
+         s|[][^$\\\\*/.]|\\\\&|g
+         s|<[^>]*>|s/&//g\\'"$NL"'|g
+         s/_p/|/g
+         s/_u/_/g
+         s/.$//' < "$TEMP"`
+    fi
   else
     # Which genius thought of iterating through this loop twice, when the
     # cp command would suffice?
@@ -384,8 +407,11 @@
                        else
                                desc="<${values} (one line)>";
                        fi
-                       dpat=`echo "$desc" | tr '\]\[*+^$|\()&/' '............'`
-                       echo "/^>${fieldname}:/ s/${dpat}//" >> $FIXFIL
+                       printf '%s\n' "$desc" |
+                           sed '
+                               s|[][\\^$*./]|\\&|g
+                               s|.*|/^>'"$fieldname"':/ s/&//|
+                           ' >> "$FIXFIL"
                    fi
                    echo "${fmtname}${desc}" >> $file
                    ;;
@@ -395,8 +421,11 @@
                        desc="  $default_val";
                    else
                        desc="  <`${bindir}/query-pr --field-description 
$fieldname` (multiple lines)>";
-                       dpat=`echo "$desc" | tr '\]\[*+^$|\()&/' '............'`
-                       echo "s/^${dpat}//" >> $FIXFIL
+                       printf '%s\n' "$desc" |
+                           sed '
+                               s|[][\\^$*./]|\\&|g
+                               s|.*|s/^&//|
+                           ' >> "$FIXFIL"
                    fi
                    echo "${fmtname}" >> $file;
                    echo "$desc" >> $file;
@@ -407,8 +436,11 @@
                        desc="${default_val}"
                    else
                        desc="<`${bindir}/query-pr --field-description 
$fieldname` (one line)>"
-                       dpat=`echo "$desc" | tr '\]\[*+^$|\()&/' '............'`
-                       echo "/^>${fieldname}:/ s/${dpat}//" >> $FIXFIL
+                       printf '%s\n' "$desc" |
+                           sed '
+                               s|[][\\^$*./]|\\&|g
+                               s|.*|/^>'"$fieldname"':/ s/&//|
+                           ' >> "$FIXFIL"
                    fi
                    echo "${fmtname}${desc}" >> $file
                    ;;
@@ -450,6 +452,7 @@
   #    Remove comments.
   #
   echo '/^SEND-PR:/d' >> $FIXFIL
+  printf '%s\n' "$SENDPR_CLEANUP" >> "$FIXFIL"
   sed -f $FIXFIL $TEMP > $REF

   # REF now has the actual PR that we want to send.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]