3 # these are helper functions for doing localized revision control.
4 # this script should be sourced into other scripts that use it.
6 source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh"
7 source "$FEISTY_MEOW_SCRIPTS/tty/terminal_titler.sh"
11 # the maximum depth that the recursive functions will try to go below the starting directory.
14 #hmmm: re-address this code, since it doesn't make a lot of sense to me right now...
15 # one unpleasantry to take care of first; cygwin barfs aggressively if the TMP directory
16 # is a DOS path, but we need it to be a DOS path for our GFFS testing, so that blows.
17 # to get past this, TMP gets changed below to a hopefully generic and safe place.
19 if [[ "$TMP" =~ .:.* ]]; then
20 echo making weirdo temporary directory for DOS path.
21 export TMP=/tmp/rev_control_$USER
23 if [ ! -d "$TMP" ]; then
26 if [ ! -d "$TMP" ]; then
27 echo "could not create the temporary directory TMP in: $TMP"
28 echo "this script will not work properly without an existing TMP directory."
32 # gets the machine's hostname and stores it in the variable "this_host".
33 function get_our_hostname()
35 if [ "$OS" == "Windows_NT" ]; then
37 elif [ ! -z "$(echo $MACHTYPE | grep apple)" ]; then
39 elif [ ! -z "$(echo $MACHTYPE | grep suse)" ]; then
40 this_host=$(hostname --long)
44 #echo "hostname is $this_host"
47 # this function sets a variable called "home_system" to "true" if the
48 # machine is considered one of fred's home machines. if you are not
49 # fred, you may want to change the machine choices.
50 function is_home_system()
52 # load up the name of the host.
54 # reset the variable that we'll be setting.
57 if [[ $this_host == *.gruntose.blurgh ]]; then
63 # makes sure that the "folder" is a directory and is writable.
64 # remember that bash successful returns are zeroes...
65 function test_writeable()
67 local folder="$1"; shift
68 if [ ! -d "$folder" -o ! -w "$folder" ]; then return 1; fi
72 # we only want to totally personalize this script if the user is right.
75 if [ "$USER" == "fred" ]; then
76 export SVNUSER=fred_t_hamster@
77 export EXTRA_PROTOCOL=+ssh
80 export EXTRA_PROTOCOL=
84 # calculates the right modifier for hostnames / repositories.
86 function compute_modifier()
92 # some project specific overrides.
93 if [[ "$directory" == hoople* ]]; then
94 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/hoople2/svn/"
96 if [[ "$directory" == yeti* ]]; then
97 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/yeti/svn/"
99 # see if we're on one of fred's home machines.
101 # special override to pick local servers when at home.
102 if [ "$home_system" == "true" ]; then
103 #hmmm: this "home system" feature seems to be unnecessary?
104 if [ "$in_or_out" == "out" ]; then
105 # need the right home machine for modifier when checking out.
108 # no modifier for checkin.
116 # selects the method for check-in based on where we are.
117 function do_checkin()
119 local directory="$1"; shift
123 # make a nice echoer since we want to use it inside conditions below.
124 local nicedir="$directory"
125 if [ $nicedir == "." ]; then
128 local blatt="echo checking in '$nicedir'..."
130 local retval=0 # normally successful.
132 do_update "$directory"
134 test_or_die "repository update failed; this should be fixed before check-in."
136 pushd "$directory" &>/dev/null
137 if [ -f ".no-checkin" ]; then
138 echo "skipping check-in due to presence of .no-checkin sentinel file."
139 elif [ -d "CVS" ]; then
140 if test_writeable "CVS"; then
145 elif [ -d ".svn" ]; then
146 if test_writeable ".svn"; then
151 elif [ -d ".git" ]; then
152 if test_writeable ".git"; then
154 # snag all new files. not to everyone's liking.
157 echo A: retval=$retval
159 # see if there are any changes in the local repository.
160 if ! git diff-index --quiet HEAD --; then
161 # tell git about all the files and get a check-in comment.
164 echo B.1: retval=$retval
166 # catch if the diff-index failed somehow.
168 echo B.2: retval=$retval
170 # upload any changes to the upstream repo so others can see them.
172 #| grep -v "X11 forwarding request failed"
173 #have to do pipestatus if want to keep the above.
175 echo C: retval=$retval
178 echo no repository in $directory
183 restore_terminal_title
190 local directory="$1"; shift
194 pushd "$directory" &>/dev/null
195 local retval=0 # normally successful.
197 # only update if we see a repository living there.
198 if [ -d ".svn" ]; then
201 elif [ -d ".git" ]; then
204 elif [ -d "CVS" ]; then
211 restore_terminal_title
216 function do_report_new
218 local directory="$1"; shift
222 pushd "$directory" &>/dev/null
223 local retval=0 # normally successful.
225 # only update if we see a repository living there.
226 if [ -f ".no-checkin" ]; then
227 echo "skipping reporting due to presence of .no-checkin sentinel file."
228 elif [ -d ".svn" ]; then
229 # this action so far only makes sense and is needed for svn.
230 bash $FEISTY_MEOW_SCRIPTS/rev_control/svnapply.sh \? echo
232 elif [ -d ".git" ]; then
239 restore_terminal_title
244 # checks in all the folders in a specified list.
245 function checkin_list()
247 # make the list of directories unique.
248 local list="$(uniquify $*)"
252 # turn repo list back into an array.
253 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
257 for outer in "${repository_list[@]}"; do
258 # check the repository first, since it might be an absolute path.
259 if [[ $outer =~ /.* ]]; then
260 # yep, this path is absolute. just handle it directly.
261 if [ ! -d "$outer" ]; then continue; fi
263 test_or_die "running check-in on: $outer"
266 for inner in $list; do
267 # add in the directory component to see if we can find the folder.
268 local path="$inner/$outer"
269 if [ ! -d "$path" ]; then continue; fi
271 test_or_die "running check-in on: $path"
277 restore_terminal_title
280 # takes out the first few carriage returns that are in the input.
281 function squash_first_few_crs()
284 while read input_text; do
286 if [ $i -le 5 ]; then
287 echo -n "$input_text "
292 if [ $i -le 3 ]; then
293 # if we're still squashing eols, make sure we don't leave them hanging.
298 # selects the checkout method based on where we are (the host the script runs on).
301 directory="$1"; shift
305 # make a nice echoer since we want to use it inside conditions below.
306 local nicedir="$directory"
307 if [ $nicedir == "." ]; then
310 local blatt="echo retrieving '$nicedir'..."
312 local retval=0 # plan on success for now.
313 pushd "$directory" &>/dev/null
314 if [ -d "CVS" ]; then
315 if test_writeable "CVS"; then
317 cvs update . | squash_first_few_crs
318 retval=${PIPESTATUS[0]}
320 elif [ -d ".svn" ]; then
321 if test_writeable ".svn"; then
323 svn update . | squash_first_few_crs
324 retval=${PIPESTATUS[0]}
326 elif [ -d ".git" ]; then
327 if test_writeable ".git"; then
329 git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
330 retval=${PIPESTATUS[0]}
333 # this is not an error necessarily; we'll just pretend they planned this.
334 echo no repository in $directory
338 restore_terminal_title
343 # gets all the updates for a list of folders under revision control.
344 function checkout_list()
346 local list="$(uniquify $*)"
350 # turn repo list back into an array.
351 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
355 for outer in "${repository_list[@]}"; do
356 # check the repository first, since it might be an absolute path.
357 if [[ $outer =~ /.* ]]; then
358 # yep, this path is absolute. just handle it directly.
359 if [ ! -d "$outer" ]; then continue; fi
361 test_or_die "running update on: $path"
364 for inner in $list; do
365 # add in the directory component to see if we can find the folder.
366 local path="$inner/$outer"
367 if [ ! -d "$path" ]; then continue; fi
369 test_or_die "running update on: $path"
375 restore_terminal_title
378 # provides a list of absolute paths of revision control directories
379 # that are located under the directory passed as the first parameter.
380 function generate_rev_ctrl_filelist()
382 local dir="$1"; shift
383 pushd "$dir" &>/dev/null
384 local dirhere="$( \cd "$(\dirname "$dir")" && /bin/pwd )"
385 local tempfile=$(mktemp /tmp/zz_checkins.XXXXXX)
387 local additional_filter
388 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".svn" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
389 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".git" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
390 # CVS is not well behaved like git and (now) svn, and we seldom use it anymore.
393 # see if they've warned us not to try checking in within vendor hierarchies.
394 if [ ! -z "NO_CHECKIN_VENDOR" ]; then
395 sed -i -e '/.*\/vendor\/.*/d' "$tempfile"
398 local sortfile=$(mktemp /tmp/zz_checkin_sort.XXXXXX)
399 sort <"$tempfile" >"$sortfile"
404 # iterates across a list of directories contained in a file (first parameter).
405 # on each directory name, it performs the action (second parameter) provided.
406 function perform_revctrl_action_on_file()
408 local tempfile="$1"; shift
409 local action="$1"; shift
413 while read -u 3 dirname; do
414 if [ -z "$dirname" ]; then continue; fi
415 pushd "$dirname" &>/dev/null
418 test_or_die "performing action $action on: $(pwd)"
423 restore_terminal_title