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