summaryrefslogtreecommitdiff
blob: c27eb29d4762146f9a28fe55871b288218c9b6ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
# review - Move a certain revision from sunrise/ to reviewed/
# Released into the public domain

source /etc/init.d/functions.sh

BLUE=$'\033[34;01m'
BOLD=$'\e[0;01m'
DARKGREEN=$'\e[32m'
GREEN=$'\e[32;01m'
LIGHTBLUE=$HILITE
RED=$'\033[31;01m'
YELLOW=$'\033[33;01m'
opt_norepoman=0
opt_noupdate=0
opt_quiet=0
opt_verbose=0

svn_up() {
	if [[ "$opt_noupdate" == "0" ]] ; then
		svn update $*

		local conflict_files=$(svn status | sed -rn 's/^C.+ ([^ ]+)$/\1/p')
		if [[ -n "$conflict_files" ]] ; then
			echo "!!! Error: Some local files have changes that conflict with the latest"
			echo "!!! revisions in the repository. Please contact the previous committer(s) to"
			echo "!!! resolve the conflicts manually before running sunrise-commit again:"
			for filename in $conflict_files ; do
				echo "!!!"
				echo "!!!        file: ${filename}"
				echo "!!!   committer: $(svn info ${filename} | sed -rn 's/Last Changed Author\: (.*)$/\1/p')"
			done
			exit 1
		fi
	fi
	return 0
}

repoman_check() {
	if [[ "$opt_norepoman" == "0" ]] ; then
		ebegin "Running repoman"
		export PORTDIR_OVERLAY="$(pwd)"
		repoman
		eend $?
		return $?
	fi
}

usage() {
cat << EOF
${BOLD}Usage:${NORMAL} ${LIGHTBLUE}$0${NORMAL} [ ${GREEN}options${NORMAL} ] ${BLUE}revision${NORMAL}

${GREEN}options${NORMAL}:
  ${BOLD}--help, -h${NORMAL}       Show help
  ${BOLD}--norepoman, -p${NORMAL}  Skip repoman check
  ${BOLD}--noupdate, -d${NORMAL}   Don't update from repository before committing
  ${BOLD}--quiet, -q${NORMAL}      Don't ask for confirmation
  ${BOLD}--verbose, -v${NORMAL}    Show detailed information during commit
EOF
	exit ${1:-0}
}

while [[ $# > 0 ]] ; do
	case "$1" in
		--help|-h)
			usage ;;

		--norepoman|-p)
			opt_norepoman=1
			shift ;;

		--noupdate|-d)
			opt_noupdate=1
			shift ;;

		--quiet|-q)
			opt_quiet=1
			shift ;;

		--verbose|-v)
			opt_verbose=1
			shift ;;

		-*)
   			echo "!!! Error: Unknown option ${1}. See: sunrise-commit -h"
   			exit 1 ;;

		*)
			break ;;
	esac
done

cd sunrise
LC_ALL="C" ls -d *-* > profiles/categories
if [[ $(svn diff profiles/categories) ]]; then
	svn diff profiles/categories | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi
	echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
	read choice
	echo
	case "$choice" in
		y*|Y*|"")
			svn commit -m "Automatic update to categories" profiles/categories || exit 1
			;;
		*)
			echo "Quitting."
			echo
			exit ;;
	esac
fi
sh scripts/use_desc_gen.sh . || exit $?
if [[ $(svn diff profiles/use.local.desc) ]]; then
	svn diff profiles/use.local.desc | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi
	echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
	read choice
	echo
	case "$choice" in
		y*|Y*|"")
			svn commit -m "Automatic update to use.local.desc" profiles/use.local.desc || exit 1
			;;
		*)
			echo "Quitting."
			echo
			exit ;;
	esac
fi
cd ..

if [[ -z "$*" ]] ; then
	ebegin "Updating working copy to latest version from repository"
	update=$(svn_up)
	if [[ "$opt_verbose" == "1" ]] ; then
		echo "$update"
	fi
	update=$(echo $update|awk '// {print $NF}' )
	sunrise_revision=${update/.}
	[ "$sunrise_revision" -lt "10" ] && exit 1
	eend
#elif [[ "$*" =~ "^[0-9]*$" ]]; then 
#	echo "!!! Error: The revision must be an integer value $*"
#	exit 1
else
	sunrise_revision=$*

	ebegin "Updating working copy to latest version from repository"
	svn_up -r $sunrise_revision || exit $?
	eend
fi

if ! [ -e sunrise ] || ! [ -e reviewed ]; then
	eerror "You need to have sunrise and reviewed subdirs"
	exit 1
fi

reviewed_revision=$(svn log reviewed 2>/dev/null | grep "Reviewed up to revision " -m 1 | sed "s:Reviewed up to revision ::")

if [ $reviewed_revision -gt $sunrise_revision ]; then
	eerror "a newer revision is already reviewed"
	exit 1
fi
(
cd sunrise

repoman_check || exit $?

ebegin "Running portdupe"
scripts/portdupe
eend $?

cd ..
if [[ "$opt_quiet" == "0" ]] ; then
	which diffstat >/dev/null 2>&1 && diff -Nur reviewed sunrise --exclude=.svn | diffstat
	diff -Nur reviewed sunrise --exclude=Manifest --exclude=.svn --exclude=metadata.xml --exclude=digest-*
fi
) | if [[ "$opt_quiet" == "0" ]] ; then less; else cat; fi

if [[ "$opt_quiet" == "0" ]] ; then
	echo
	echo -n "${BOLD}Commit changes?${NORMAL} [${GREEN}Yes${NORMAL}/${RED}No${NORMAL}] "
	read choice
	echo

	case "$choice" in
		y*|Y*|"")
			;;

		*)
			echo "Quitting."
			echo
			exit ;;
	esac
fi

ebegin "Merging in changes..."
if [[ "$opt_verbose" == "1" ]] ; then
	svn merge sunrise@$reviewed_revision sunrise@$sunrise_revision reviewed
else
	svn merge sunrise@$reviewed_revision sunrise@$sunrise_revision reviewed -q
fi
eend ${?}

ebegin "Committing working copy to repository"
svn commit reviewed -m "Reviewed up to revision $sunrise_revision"
eend $?