]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/scripts/relnotes-search.sh
Remove spurious newline
[FreeBSD/FreeBSD.git] / release / scripts / relnotes-search.sh
1 #!/bin/sh
2 #-
3 # Copyright (c) 2014 The FreeBSD Foundation
4 # All rights reserved.
5 #
6 # This software were developed by Glen Barber
7 # under sponsorship from the FreeBSD Foundation.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 # 1. Redistributions of source code must retain the above copyright
13 #    notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 #    notice, this list of conditions and the following disclaimer in the
16 #    documentation and/or other materials provided with the distribution.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # SUCH DAMAGE.
29 #
30 # $FreeBSD$
31 #
32
33 set -C
34
35 PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
36 export PATH
37
38 usage() {
39         echo "Usage:"
40         echo -n "$(basename ${0}) [-rNNNNNN]"
41         echo " [-l /path/for/output] /path/to/branch"
42         echo " -r: The oldest commit to include in the search"
43         echo ""
44         exit 1
45 }
46
47 main() {
48         while getopts "l:r:" arg ; do
49                 case ${arg} in
50                         l)
51                                 # Disallow '-rNNNNNN' argument for oldest
52                                 # revision # from becoming the log file
53                                 # accidentally.
54                                 where="${OPTARG##-r*}"
55                                 [ -z "${where}" ] && usage
56                                 if [ -e "${where}" ]; then
57                                         echo "Log file already exists:"
58                                         echo "  (${where})"
59                                         return 2
60                                 fi
61                                 ;;
62                         r)
63                                 rev="${OPTARG##-r}"
64                                 c=$(echo -n ${rev} | tr -d '0-9' | wc -c)
65                                 if [ ${c} -ne 0 ]; then
66                                         echo "Revision number must be numeric."
67                                         return 2
68                                 fi
69                                 # Since the last specified revision is
70                                 # specified, mangle the variable to
71                                 # make svn syntax happy.
72                                 rev="-r${rev}:rHEAD"
73                                 ;;
74                         *)
75                                 usage
76                                 ;;
77                 esac
78         done
79         shift $(( ${OPTIND} - 1 ))
80
81         # This assumes a local working copy, which svn search
82         # allows exactly one repository path (although the root
83         # can still be the path).
84         [ "$#" -ne 1 ] && usage
85
86         # If no log file, write to stdout.
87         [ -z "${where}" ] && where=/dev/stdout
88
89         svn=
90         # Where is svn?
91         for s in /usr/bin /usr/local/bin; do
92                 if [ -x ${s}/svn ]; then
93                         svn=${s}/svn
94                         break
95                 fi
96                 if [ -x ${s}/svnlite ]; then
97                         svn=${s}/svnlite
98                         break
99                 fi
100         done
101         # Did we find svn?
102         if [ -z "${svn}" ]; then
103                 echo "svn(1) binary not found."
104                 return 2
105         fi
106         # Is more than one path specified?  (This should never
107         # be triggered, because the argument count is checked
108         # above, but better safe than sorry.)
109         if [ $# -gt 1 ]; then
110                 echo "Cannot specify more than one working path."
111                 return 2
112         fi
113         # Does the directory exist?
114         if [ ! -d "${1}" ]; then
115                 echo "Specified path (${1}) is not a directory."
116                 return 2
117         fi
118         # Is it a subversion repository checkout?
119         ${svn} info ${1} >/dev/null 2>&1
120         if [ "$?" -ne 0 ]; then
121                 echo "Cannot determine svn repository information for ${1}"
122                 return 2
123         fi
124
125         # All tests passed.  Let's see what can possibly go wrong
126         # from here.  The search string specified should match this
127         # in PCRE speak: ':[\t ]*'
128         ${svn} log ${rev} --search 'Relnotes:*[A-Za-z0-9]*' ${1} > ${where}
129         return $?
130 }
131
132 main "${@}"
133 exit $?