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"
48 # makes sure that the "folder" is a directory and is writable.
49 # remember that bash successful returns are zeroes...
50 function test_writeable()
52 local folder="$1"; shift
53 if [ ! -d "$folder" -o ! -w "$folder" ]; then return 1; fi
57 # we only want to totally personalize this script if the user is right.
60 if [ "$USER" == "fred" ]; then
61 export SVNUSER=fred_t_hamster@
62 export EXTRA_PROTOCOL=+ssh
65 export EXTRA_PROTOCOL=
69 # calculates the right modifier for hostnames / repositories.
71 function compute_modifier()
77 # some project specific overrides.
78 if [[ "$directory" == hoople* ]]; then
79 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/hoople2/svn/"
81 if [[ "$directory" == yeti* ]]; then
82 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/yeti/svn/"
84 # see if we're on one of fred's home machines.
86 # special override to pick local servers when at home.
87 if [ "$home_system" == "true" ]; then
88 #hmmm: this "home system" feature seems to be unnecessary?
89 if [ "$in_or_out" == "out" ]; then
90 # need the right home machine for modifier when checking out.
93 # no modifier for checkin.
101 # selects the method for check-in based on where we are.
102 function do_checkin()
104 local directory="$1"; shift
108 # make a nice echoer since we want to use it inside conditions below.
109 local nicedir="$directory"
110 if [ $nicedir == "." ]; then
113 local blatt="echo checking in '$nicedir'..."
115 local retval=0 # normally successful.
117 do_update "$directory"
119 test_or_die "repository update failed; this should be fixed before check-in."
121 pushd "$directory" &>/dev/null
122 if [ -f ".no-checkin" ]; then
123 echo "skipping check-in due to presence of .no-checkin sentinel file."
124 elif [ -d "CVS" ]; then
125 if test_writeable "CVS"; then
130 elif [ -d ".svn" ]; then
131 if test_writeable ".svn"; then
136 elif [ -d ".git" ]; then
137 if test_writeable ".git"; then
139 # snag all new files. not to everyone's liking.
142 echo A: retval=$retval
144 # see if there are any changes in the local repository.
145 if ! git diff-index --quiet HEAD --; then
146 # tell git about all the files and get a check-in comment.
149 echo B.1: retval=$retval
151 # catch if the diff-index failed somehow.
153 echo B.2: retval=$retval
155 # upload any changes to the upstream repo so others can see them.
157 #| grep -v "X11 forwarding request failed"
158 #have to do pipestatus if want to keep the above.
160 echo C: retval=$retval
163 # nothing there. it's not an error though.
164 echo no repository in $directory
169 restore_terminal_title
176 local directory="$1"; shift
180 pushd "$directory" &>/dev/null
181 local retval=0 # normally successful.
183 # only update if we see a repository living there.
184 if [ -d ".svn" ]; then
187 elif [ -d ".git" ]; then
190 elif [ -d "CVS" ]; then
197 restore_terminal_title
202 function do_report_new
204 local directory="$1"; shift
208 pushd "$directory" &>/dev/null
209 local retval=0 # normally successful.
211 # only update if we see a repository living there.
212 if [ -f ".no-checkin" ]; then
213 echo "skipping reporting due to presence of .no-checkin sentinel file."
214 elif [ -d ".svn" ]; then
215 # this action so far only makes sense and is needed for svn.
216 bash $FEISTY_MEOW_SCRIPTS/rev_control/svnapply.sh \? echo
218 elif [ -d ".git" ]; then
225 restore_terminal_title
230 # checks in all the folders in a specified list.
231 function checkin_list()
233 # make the list of directories unique.
234 local list="$(uniquify $*)"
238 # turn repo list back into an array.
239 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
243 for outer in "${repository_list[@]}"; do
244 # check the repository first, since it might be an absolute path.
245 if [[ $outer =~ /.* ]]; then
246 # yep, this path is absolute. just handle it directly.
247 if [ ! -d "$outer" ]; then continue; fi
249 test_or_die "running check-in on: $outer"
252 for inner in $list; do
253 # add in the directory component to see if we can find the folder.
254 local path="$inner/$outer"
255 if [ ! -d "$path" ]; then continue; fi
257 test_or_die "running check-in on: $path"
263 restore_terminal_title
266 # takes out the first few carriage returns that are in the input.
267 function squash_first_few_crs()
270 while read input_text; do
272 if [ $i -le 5 ]; then
273 echo -n "$input_text "
278 if [ $i -le 3 ]; then
279 # if we're still squashing eols, make sure we don't leave them hanging.
284 # selects the checkout method based on where we are (the host the script runs on).
287 directory="$1"; shift
291 # make a nice echoer since we want to use it inside conditions below.
292 local nicedir="$directory"
293 if [ $nicedir == "." ]; then
296 local blatt="echo retrieving '$nicedir'..."
298 local retval=0 # plan on success for now.
299 pushd "$directory" &>/dev/null
300 if [ -d "CVS" ]; then
301 if test_writeable "CVS"; then
303 cvs update . | squash_first_few_crs
304 retval=${PIPESTATUS[0]}
306 elif [ -d ".svn" ]; then
307 if test_writeable ".svn"; then
309 svn update . | squash_first_few_crs
310 retval=${PIPESTATUS[0]}
312 elif [ -d ".git" ]; then
313 if test_writeable ".git"; then
315 git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
316 retval=${PIPESTATUS[0]}
319 # this is not an error necessarily; we'll just pretend they planned this.
320 echo no repository in $directory
324 restore_terminal_title
329 # gets all the updates for a list of folders under revision control.
330 function checkout_list()
332 local list="$(uniquify $*)"
336 # turn repo list back into an array.
337 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
341 for outer in "${repository_list[@]}"; do
342 # check the repository first, since it might be an absolute path.
343 if [[ $outer =~ /.* ]]; then
344 # yep, this path is absolute. just handle it directly.
345 if [ ! -d "$outer" ]; then continue; fi
347 test_or_die "running update on: $path"
350 for inner in $list; do
351 # add in the directory component to see if we can find the folder.
352 local path="$inner/$outer"
353 if [ ! -d "$path" ]; then continue; fi
355 test_or_die "running update on: $path"
361 restore_terminal_title
364 # provides a list of absolute paths of revision control directories
365 # that are located under the directory passed as the first parameter.
366 function generate_rev_ctrl_filelist()
368 local dir="$1"; shift
369 pushd "$dir" &>/dev/null
370 local dirhere="$( \cd "$(\dirname "$dir")" && /bin/pwd )"
371 local tempfile=$(mktemp /tmp/zz_checkins.XXXXXX)
373 local additional_filter
374 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".svn" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
375 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".git" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
376 # CVS is not well behaved like git and (now) svn, and we seldom use it anymore.
379 # see if they've warned us not to try checking in within vendor hierarchies.
380 if [ ! -z "NO_CHECKIN_VENDOR" ]; then
381 sed -i -e '/.*\/vendor\/.*/d' "$tempfile"
384 local sortfile=$(mktemp /tmp/zz_checkin_sort.XXXXXX)
385 sort <"$tempfile" >"$sortfile"
390 # iterates across a list of directories contained in a file (first parameter).
391 # on each directory name, it performs the action (second parameter) provided.
392 function perform_revctrl_action_on_file()
394 local tempfile="$1"; shift
395 local action="$1"; shift
399 while read -u 3 dirname; do
400 if [ -z "$dirname" ]; then continue; fi
401 pushd "$dirname" &>/dev/null
404 test_or_die "performing action $action on: $(pwd)"
409 restore_terminal_title