3 # these are helper functions for doing localized revision control.
4 # this script should be sourced into other scripts that use it.
6 # the maximum depth that the recursive functions will try to go below the starting directory.
9 #hmmm: re-address this code, since it doesn't make a lot of sense to me right now...
10 # one unpleasantry to take care of first; cygwin barfs aggressively if the TMP directory
11 # is a DOS path, but we need it to be a DOS path for our GFFS testing, so that blows.
12 # to get past this, TMP gets changed below to a hopefully generic and safe place.
14 if [[ "$TMP" =~ .:.* ]]; then
15 echo making weirdo temporary directory for DOS path.
16 export TMP=/tmp/rev_control_$USER
18 if [ ! -d "$TMP" ]; then
21 if [ ! -d "$TMP" ]; then
22 echo "Could not create the temporary directory TMP in: $TMP"
23 echo "This script will not work properly without an existing TMP directory."
27 # gets the machine's hostname and stores it in the variable "this_host".
28 function get_our_hostname()
30 if [ "$OS" == "Windows_NT" ]; then
32 elif [ ! -z "$(echo $MACHTYPE | grep apple)" ]; then
34 elif [ ! -z "$(echo $MACHTYPE | grep suse)" ]; then
35 this_host=$(hostname --long)
39 #echo "hostname is $this_host"
42 # this function sets a variable called "home_system" to "true" if the
43 # machine is considered one of fred's home machines. if you are not
44 # fred, you may want to change the machine choices.
46 function is_home_system()
48 # load up the name of the host.
50 # reset the variable that we'll be setting.
52 if [[ $this_host == *.gruntose.blurgh ]]; then
55 elif [[ $this_host == buildy ]]; then
57 elif [[ $this_host == simmy ]]; then
63 # we only want to totally personalize this script if the user is right.
66 if [ "$USER" == "fred" ]; then
67 export SVNUSER=fred_t_hamster@
68 export EXTRA_PROTOCOL=+ssh
71 export EXTRA_PROTOCOL=
75 # calculates the right modifier for hostnames / repositories.
77 function compute_modifier()
83 # some project specific overrides.
84 if [[ "$directory" == hoople* ]]; then
85 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/hoople2/svn/"
87 if [[ "$directory" == yeti* ]]; then
88 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/yeti/svn/"
90 # see if we're on one of fred's home machines.
92 # special override to pick local servers when at home.
93 if [ "$home_system" == "true" ]; then
94 if [ "$in_or_out" == "out" ]; then
95 # need the right home machine for modifier when checking out.
96 #huhhh? modifier="svn://shaggy/"
99 # no modifier for checkin.
105 # selects the method for check-in based on where we are.
106 function do_checkin()
108 local directory="$1"; shift
109 do_update "$directory"
110 if [ $? -ne 0 ]; then
111 echo "Repository update failed; this should be fixed before check-in."
114 pushd "$directory" &>/dev/null
115 local retval=0 # normally successful.
116 if [ -d "CVS" ]; then
119 elif [ -d ".svn" ]; then
122 elif [ -d ".git" ]; then
123 # snag all new files. not to everyone's liking.
126 # tell git about all the files and get a check-in comment.
129 # upload the files to the server so others can see them.
130 git push 2>&1 | grep -v "X11 forwarding request failed"
133 echo no repository in $directory
142 local directory="$1"; shift
143 pushd "$directory" &>/dev/null
144 local retval=0 # normally successful.
146 # only update if we see a repository living there.
147 if [ -d ".svn" ]; then
149 elif [ -d ".git" ]; then
151 elif [ -d "CVS" ]; then
159 function do_report_new
161 local directory="$1"; shift
162 pushd "$directory" &>/dev/null
163 local retval=0 # normally successful.
165 # only update if we see a repository living there.
166 if [ -d ".svn" ]; then
167 # this action so far only makes sense and is needed for svn.
168 bash $FEISTY_MEOW_SCRIPTS/rev_control/svnapply.sh \? echo
170 elif [ -d ".git" ]; then
179 # checks in all the folders in a specified list.
180 function checkin_list()
184 # turn repo list back into an array.
185 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
186 for j in "${repository_list[@]}"; do
187 # add in the directory component.
189 if [ ! -d "$j" ]; then continue; fi
190 echo "checking in '$j'..."
196 # takes out the first few carriage returns that are in the input.
197 function squash_first_few_crs()
200 while read input_text; do
202 if [ $i -le 5 ]; then
203 echo -n "$input_text "
208 if [ $i -le 3 ]; then
209 # if we're still squashing eols, make sure we don't leave them hanging.
214 # selects the checkout method based on where we are (the host the script runs on).
217 directory="$1"; shift
218 local retval=0 # plan on success for now.
219 pushd "$directory" &>/dev/null
220 if [ -d "CVS" ]; then
221 cvs update . | squash_first_few_crs
222 retval=${PIPESTATUS[0]}
223 elif [ -d ".svn" ]; then
224 svn update . | squash_first_few_crs
225 retval=${PIPESTATUS[0]}
226 elif [ -d ".git" ]; then
227 git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
228 retval=${PIPESTATUS[0]}
230 # this is not an error necessarily; we'll just pretend they planned this.
231 echo no repository in $directory
237 # gets all the updates for a list of folders under revision control.
238 function checkout_list {
241 # turn repo list back into an array.
242 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
243 for j in "${repository_list[@]}"; do
244 # add in the directory for our purposes here.
247 if [ ! -z "$SHELL_DEBUG" ]; then
248 echo "No directory called $j exists."
253 echo -n "retrieving '$j'... "
259 # provides a list of absolute paths of revision control directories
260 # that are located under the directory passed as the first parameter.
261 function generate_rev_ctrl_filelist()
263 local dir="$1"; shift
264 pushd "$dir" &>/dev/null
265 local dirhere="$( \cd "$(\dirname "$dir")" && /bin/pwd )"
266 local tempfile=$(mktemp /tmp/zz_rev_checkin.XXXXXX)
268 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".svn" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
269 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".git" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
270 # CVS is not well behaved like git and (now) svn, and we seldom use it anymore.
272 local sortfile=$(mktemp /tmp/zz_rev_checkin_sort.XXXXXX)
273 sort <"$tempfile" >"$sortfile"
278 # iterates across a list of directories contained in a file (first parameter).
279 # on each directory name, it performs the action (second parameter) provided.
280 function perform_revctrl_action_on_file()
282 local tempfile="$1"; shift
283 local action="$1"; shift
285 while read -u 3 dirname; do
286 if [ -z "$dirname" ]; then continue; fi
287 pushd "$dirname" &>/dev/null