]> Pileus Git - ~andy/sunrise/blob - scripts/review
Make review script more particular about the directory from which it is run.
[~andy/sunrise] / scripts / review
1 #!/bin/bash
2 # review - Move a certain revision from sunrise/ to reviewed/
3 # Released into the public domain
4
5 source /etc/init.d/functions.sh
6
7 BLUE=$'\033[34;01m'
8 BOLD=$'\e[0;01m'
9 DARKGREEN=$'\e[32m'
10 GREEN=$'\e[32;01m'
11 LIGHTBLUE=$HILITE
12 RED=$'\033[31;01m'
13 YELLOW=$'\033[33;01m'
14 opt_norepoman=0
15 opt_noupdate=0
16 opt_quiet=0
17 opt_verbose=0
18
19 DIFF="${DIFF:-diff}"
20 DIFF_OPTS="${DIFF_OPTS:--Nur}"
21
22 svn_up() {
23         if [[ "$opt_noupdate" == "0" ]] ; then
24                 svn update $*
25
26                 local conflict_files=$(svn status | sed -rn 's/^C.+ ([^ ]+)$/\1/p')
27                 if [[ -n "$conflict_files" ]] ; then
28                         echo "!!! Error: Some local files have changes that conflict with the latest"
29                         echo "!!! revisions in the repository. Please contact the previous committer(s) to"
30                         echo "!!! resolve the conflicts manually before running sunrise-commit again:"
31                         for filename in $conflict_files ; do
32                                 echo "!!!"
33                                 echo "!!!        file: ${filename}"
34                                 echo "!!!   committer: $(svn info ${filename} | sed -rn 's/Last Changed Author\: (.*)$/\1/p')"
35                         done
36                         exit 1
37                 fi
38         fi
39         return 0
40 }
41
42 repoman_check() {
43         if [[ "$opt_norepoman" == "0" ]] ; then
44                 ebegin "Running repoman"
45                 export PORTDIR_OVERLAY="$(pwd)"
46                 repoman
47                 eend $?
48                 return $?
49         fi
50 }
51
52 usage() {
53 cat << EOF
54 ${BOLD}Usage:${NORMAL} ${LIGHTBLUE}$0${NORMAL} [ ${GREEN}options${NORMAL} ] ${BLUE}revision${NORMAL}
55
56 ${GREEN}options${NORMAL}:
57   ${BOLD}--help, -h${NORMAL}       Show help
58   ${BOLD}--norepoman, -p${NORMAL}  Skip repoman check
59   ${BOLD}--noupdate, -d${NORMAL}   Don't update from repository before committing
60   ${BOLD}--quiet, -q${NORMAL}      Don't ask for confirmation
61   ${BOLD}--verbose, -v${NORMAL}    Show detailed information during commit
62 EOF
63         exit ${1:-0}
64 }
65
66 while [[ $# > 0 ]] ; do
67         case "$1" in
68                 --help|-h)
69                         usage ;;
70
71                 --norepoman|-p)
72                         opt_norepoman=1
73                         shift ;;
74
75                 --noupdate|-d)
76                         opt_noupdate=1
77                         shift ;;
78
79                 --quiet|-q)
80                         opt_quiet=1
81                         shift ;;
82
83                 --verbose|-v)
84                         opt_verbose=1
85                         shift ;;
86
87                 -*)
88                         echo "!!! Error: Unknown option ${1}. See: sunrise-commit -h"
89                         exit 1 ;;
90
91                 *)
92                         break ;;
93         esac
94 done
95
96 cd sunrise || { eerror "You must run this script from the top level of the sunrise subversion repository."; exit 1; }
97 LC_ALL="C" ls -d *-* > profiles/categories
98 if [[ $(svn diff profiles/categories) ]]; then
99         svn diff profiles/categories | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi
100         echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
101         read choice
102         echo
103         case "$choice" in
104                 y*|Y*|"")
105                         svn commit -m "Automatic update to categories" profiles/categories || exit 1
106                         ;;
107                 *)
108                         echo "Quitting."
109                         echo
110                         exit ;;
111         esac
112 fi
113 LC_ALL="C" sh scripts/use_desc_gen.sh . || exit $?
114 if [[ $(svn diff profiles/use.local.desc) ]]; then
115         svn diff profiles/use.local.desc | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi
116         echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
117         read choice
118         echo
119         case "$choice" in
120                 y*|Y*|"")
121                         svn commit -m "Automatic update to use.local.desc" profiles/use.local.desc || exit 1
122                         ;;
123                 *)
124                         echo "Quitting."
125                         echo
126                         exit ;;
127         esac
128 fi
129 cd ..
130
131 if [[ -z "$*" ]] ; then
132         ebegin "Updating working copy to latest version from repository"
133         update=$(svn_up)
134         if [[ "$opt_verbose" == "1" ]] ; then
135                 echo "$update"
136         fi
137         update=$(echo $update|awk '// {print $NF}' )
138         sunrise_revision=${update/.}
139         [ "$sunrise_revision" -lt "10" ] && exit 1
140         eend
141 #elif [[ "$*" =~ "^[0-9]*$" ]]; then 
142 #       echo "!!! Error: The revision must be an integer value $*"
143 #       exit 1
144 else
145         sunrise_revision=$*
146
147         ebegin "Updating working copy to latest version from repository"
148         svn_up -r $sunrise_revision || exit $?
149         eend
150 fi
151
152 if ! [ -e sunrise ] || ! [ -e reviewed ]; then
153         eerror "You need to have sunrise and reviewed subdirs"
154         exit 1
155 fi
156
157 reviewed_revision=$(svn log reviewed 2>/dev/null | grep "Reviewed up to revision " -m 1 | sed "s:Reviewed up to revision ::")
158
159 if [ $reviewed_revision -gt $sunrise_revision ]; then
160         eerror "a newer revision is already reviewed"
161         exit 1
162 fi
163 (
164 cd sunrise
165
166 repoman_check || exit $?
167
168 ebegin "Running portdupe"
169 scripts/portdupe
170 eend $?
171
172 cd ..
173 if [[ "$opt_quiet" == "0" ]] ; then
174         which diffstat >/dev/null 2>&1 && diff -Nur reviewed sunrise --exclude=.svn | diffstat
175         ${DIFF} ${DIFF_OPTS} reviewed sunrise --exclude=Manifest --exclude=.svn --exclude=metadata.xml --exclude=digest-*
176 fi
177 ) | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi
178
179 if [[ "$opt_quiet" == "0" ]] ; then
180         echo
181         echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
182         read choice
183         echo
184
185         case "$choice" in
186                 y*|Y*|"")
187                         ;;
188
189                 *)
190                         echo "Quitting."
191                         echo
192                         exit ;;
193         esac
194 fi
195
196 ebegin "Merging in changes..."
197 if [[ "$opt_verbose" == "1" ]] ; then
198         svn merge sunrise@$reviewed_revision sunrise@$sunrise_revision reviewed
199 else
200         svn merge sunrise@$reviewed_revision sunrise@$sunrise_revision reviewed -q
201 fi
202 eend ${?}
203
204 ebegin "Committing working copy to repository"
205 svn commit reviewed -m "Reviewed up to revision $sunrise_revision"
206 eend $?