/usr/bin/edit-pr is in gnats-user 4.1.0-3+deb8u1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | #!/bin/sh
# Program to edit problem reports for GNATS.
# Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002 Free Software
# Foundation, Inc.
# Contributed by Jeffrey Osier (jeffrey@cygnus.com).
# Majorly revised by Bob Manson (manson@juniper.net).
# Further improvements by Dirk Bergstrom (dirk@juniper.net).
#
# This file is part of GNU GNATS.
#
# GNU GNATS is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU GNATS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU GNATS; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
debug_print=false # or echo to get output.
BINDIR=/usr/bin
LIBEXECDIR=/usr/lib
GNATS_PORT=
locked=
version=4.1.0
usage="
Usage: edit-pr [-V|--version] [-h|--help] [-d|--database database_name]
[-H|--host hostname] [-P|--port port_number]
[-v|--user userid] [-w|--passwd password] PR
"
# get current host name
if [ -z "$HOSTNAME" ]; then
if [ -f /bin/hostname ] ; then HOSTNAME=`/bin/hostname`
elif [ -f /usr/bin/hostname ] ; then HOSTNAME=`/usr/bin/hostname`
# Solaris et al.
elif [ -f /usr/ucb/hostname ] ; then HOSTNAME=`/usr/ucb/hostname`
# Irix
elif [ -f /usr/bsd/hostname ] ; then HOSTNAME=`/usr/bsd/hostname`
fi
fi
# check to see if there is a $EDITOR; if not, use vi
[ -z "$VISUAL" ] &&
if [ -z "$EDITOR" ]; then
VISUAL=vi
else
VISUAL="$EDITOR"
fi
# Parse command line. For the non-flag argument, assume it's pr PR id.
if [ $# -eq 0 ]; then
echo "$usage" ; exit 1
fi
while [ $# -gt 0 ]; do
case "$1" in
-V|--version|--ve*)
echo "$version"; exit 0
;;
-d | --database)
if [ $# -eq 1 ]; then echo "$usage"; exit 1; fi
shift ; GNATS_DB="--database=$1" ;;
-d=* | --database=*) GNATS_DB="$1" ;;
-H | --host)
if [ $# -eq 1 ]; then echo "$usage"; exit 1; fi
shift ; GNATS_HOST="--host=$1" ;;
-H=* | --host=*) GNATS_HOST="--host=`echo $1 | sed 's/^[-a-z]*=//'`" ;;
-P | --port)
if [ $# -eq 1 ]; then echo "$usage"; exit 1; fi
shift ; GNATS_PORT="--port=$1" ;;
-P=* | --port=*) GNATS_PORT="$1" ;;
-v | --user)
if [ $# -eq 1 ]; then echo "$usage"; exit 1; fi
shift ; EDIT_USER="--user=$1" ;;
-v=* | --user=*) EDIT_USER="$1" ;;
-w | --passwd)
if [ $# -eq 1 ]; then echo "$usage"; exit 1; fi
shift ; EDIT_PASSWD="--passwd=$1" ;;
-w=* | --passwd=*) EDIT_PASSWD="$1" ;;
-h|--help*)
echo "$usage"; exit 0
;;
-*)
echo "$usage"; exit 1
;;
*)
if [ "`echo $1 | grep /`" != "" ]; then
pr_id=`echo $1 | awk -F"/" '{print $2}' -`
else
pr_id=$1
fi
;;
esac
shift
done
# set command here to always pass host and port, and directory if supplied
QUERY_PR="$BINDIR/query-pr $GNATS_HOST $GNATS_PORT $GNATS_DB $EDIT_USER $EDIT_PASSWD"
PR_ADDR="$QUERY_PR --responsible-address"
PR_EDIT="$LIBEXECDIR/gnats/pr-edit $GNATS_HOST $GNATS_PORT $EDIT_USER $EDIT_PASSWD $GNATS_DB"
# These traps take care of deleting all the /tmp files
trap 'rm -f $new.old $change_msg $fixfil' 0
# Don't delete $new on error signals
trap 'if [ "$locked" != "" ]; then \
$PR_EDIT --unlock $pr_id ; \
locked= ; \
fi' 1 2 3 13 15
# find a user name
if [ "$USER" != "" ]; then
me=$USER
else
if [ "$LOGNAME" != "" ]; then
me=$LOGNAME
else
echo "edit-pr: no user name found---set LOGNAME." ; exit 1
fi
fi
if [ -n "$HOSTNAME" ]; then
full_me="$me@$HOSTNAME"
else
full_me="$me"
fi
# new = temp file to use for editing
new="/tmp/ep$$"
newtmp="/tmp/ep$$.tp"
change_msg="/tmp/ep$$.ch"
fixfil="/tmp/ep$$.fx"
# lock the pr
$debug_print "Locking $pr_id."
lock=`$PR_EDIT --lock=$full_me --process=$$ $pr_id 2>&1 > $new`
locked=t
if [ "$lock" != "" ] ; then
echo $lock
exit 0
fi
rm -f $fixfil
# Now add any missing fields, along with a description.
$QUERY_PR --list-fields | while read field
do
grep -i "^>${field}:" "$new" > /dev/null 2>&1
if [ $? != 0 ]
then
$QUERY_PR --field-flags "$field" | grep -i readonly > /dev/null 2>&1
if [ $? != 0 ]
then
type="`$QUERY_PR --field-type $field`"
case $type in
[Ee][Nn][Uu][Mm])
values=`$QUERY_PR --valid-values $field | tr '\n' ' ' | sed 's/ *$//g; s/ / | /g;s/^/[ /;s/$/ ]/;'`
valslen=`echo "$values" | wc -c`
if [ "$valslen" -gt 160 ]
then
desc="<`$QUERY_PR --field-description $field` (one line)>";
else
desc="<${values} (one line)>";
fi
dpat=`echo "$desc" | tr '][*+^$|\()&/' '............'`
echo "/^>${field}:/ s/${dpat}//" >> $fixfil
echo "/>${field}: ${desc}" >> $new;
;;
[Mm][Uu][Ll][Tt][Ii][Tt][Ee][Xx][Tt])
desc=" <`$QUERY_PR --field-description $field` (multiple lines)>";
dpat=`echo "$desc" | tr '][*+^$|\()&/' '............'`
echo "s/^${dpat}//" >> $fixfil
echo ">${field}:" >> $new;
echo "$desc" >> $new;
;;
*)
desc="<`$QUERY_PR --field-description $field` (one line)>"
dpat=`echo "$desc" | tr '][*+^$|\()&/' '............'`
echo "/^>${field}:/ s/${dpat}//" >> $fixfil
echo ">${field}: ${desc}" >> $new
;;
esac
else
prevfld="$field";
fi
fi
done
# here's where we actually call the editor.
cp $new $new.old
$VISUAL $new
if cmp -s $new.old $new ; then
echo "edit-pr: PR not changed"
$PR_EDIT --unlock $pr_id
exit 0
fi
if [ -f $fixfil ]
then
sed -f $fixfil < $new > $newtmp
mv $newtmp $new
sed -f $fixfil < $new.old > $newtmp
mv $newtmp $new.old
rm -f $fixfil
fi
# error-check output by calling pr-edit --check; if mistakes exist,
# call $VISUAL or exit
checking=t
while [ "$checking" != "" ]; do
errors="`$PR_EDIT --check < $new 2>&1`"
if [ "$errors" != "" ]; then
echo "Hit \`return\` to fix the following errors, or type \'quit\' to quit:"
echo "$errors"
read fixme
case "$fixme" in
q* | Q*)
echo "PR $pr_id not updated: changed file is in $new.changed"
mv $new $new.changed
$PR_EDIT --unlock $pr_id
exit 0
;;
esac
$VISUAL $new
else
checking=
fi
done
exec 3<&0
#
# Find out what fields have changed; if the changed field requires a
# change reason, then ask about it.
#
$LIBEXECDIR/gnats/diff-prs $new.old $new | while read field
do
flags=`$QUERY_PR --field-flags $field` || echo "edit-pr: Invalid field name $field" 1>&2;
if echo "$flags" | grep -i "requirechangereason" > /dev/null 2>&1
then
echo ">${field}-Changed-Why:" >> $change_msg;
echo "Why did the $field field change? (Ctrl-D to end)";
cat 0<&3 >> $change_msg;
fi
done
if [ -f $change_msg ]
then
cat $change_msg >> $new
fi
#
# Submit the changed PR.
#
while true; do
if $PR_EDIT --email-addr "$full_me" $pr_id < $new
then
echo "Edit successful"
# we need to unlock the PR
$PR_EDIT --unlock $pr_id
exit 0
else
echo "Problems with edit submission."
fi
while true; do
echo "a)bort or r)etry? "
read input
case "$input" in
a*)
echo "Cancelling edit. Changed PR is in $new."
# we need to ulock the PR no matter what
$PR_EDIT --unlock $pr_id
exit 1 ;;
r*)
break ;;
*)
echo "Unrecognized input '$input'"
;;
esac
done
done
rm -f $new
exit 0
|