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