]> Pileus Git - ~andy/sunrise/blob - scripts/review
do not exclude manifest and digest on the diffstat
[~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 $*
25                 else
26                         svn update -q $*
27                 fi
28
29                 eend $?
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 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 #elif [[ "$*" =~ "^[0-9]*$" ]]; then 
107 #       echo "!!! Error: The revision must be an integer value $*"
108 #       exit 1
109 fi
110 sunrise_revision=$*
111
112 svn_up -r $sunrise_revision || exit $?
113
114 if ! [ -e sunrise ] || ! [ -e reviewed ]; then
115         eerror "You need to have sunrise and reviewed subdirs"
116         exit
117 fi
118
119 reviewed_revision=$(svn log reviewed 2>/dev/null | grep "Reviewed up to revision " -m 1 | sed "s:Reviewed up to revision ::")
120
121 if [ $reviewed_revision -gt $sunrise_revision ]; then
122         eerror "a newer revision is already reviewed"
123         exit
124 fi
125 (
126 cd sunrise
127
128 repoman_check || exit $?
129
130 ebegin "Running portdupe"
131 scripts/portdupe
132 eend $?
133
134 cd ..
135 if [[ "$opt_quiet" == "0" ]] ; then
136         which diffstat >/dev/null 2>&1 && diff -Nur reviewed sunrise --exclude=.svn | diffstat
137         diff -Nur reviewed sunrise --exclude=Manifest --exclude=.svn --exclude=metadata.xml --exclude=digest-*
138 fi
139 ) | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi
140
141 if [[ "$opt_quiet" == "0" ]] ; then
142         echo
143         echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
144         read choice
145         echo
146
147         case "$choice" in
148                 y*|Y*|"")
149                         ;;
150
151                 *)
152                         echo "Quitting."
153                         echo
154                         exit ;;
155         esac
156 fi
157
158 ebegin "Merging in changes..."
159 if [[ "$opt_verbose" == "1" ]] ; then
160         svn merge sunrise@$reviewed_revision sunrise@$sunrise_revision reviewed
161 else
162         svn merge sunrise@$reviewed_revision sunrise@$sunrise_revision reviewed -q
163 fi
164 eend ${?}
165
166 ebegin "Committing working copy to repository"
167 svn commit reviewed -m "Reviewed up to revision $*"
168 eend $?