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"
9 # the maximum depth that the recursive functions will try to go below the starting directory.
12 #hmmm: re-address this code, since it doesn't make a lot of sense to me right now...
13 # one unpleasantry to take care of first; cygwin barfs aggressively if the TMP directory
14 # is a DOS path, but we need it to be a DOS path for our GFFS testing, so that blows.
15 # to get past this, TMP gets changed below to a hopefully generic and safe place.
17 if [[ "$TMP" =~ .:.* ]]; then
18 echo making weirdo temporary directory for DOS path.
19 export TMP=/tmp/rev_control_$USER
21 if [ ! -d "$TMP" ]; then
24 if [ ! -d "$TMP" ]; then
25 echo "could not create the temporary directory TMP in: $TMP"
26 echo "this script will not work properly without an existing TMP directory."
30 # gets the machine's hostname and stores it in the variable "this_host".
31 function get_our_hostname()
33 if [ "$OS" == "Windows_NT" ]; then
35 elif [ ! -z "$(echo $MACHTYPE | grep apple)" ]; then
37 elif [ ! -z "$(echo $MACHTYPE | grep suse)" ]; then
38 this_host=$(hostname --long)
42 #echo "hostname is $this_host"
45 # this function sets a variable called "home_system" to "true" if the
46 # machine is considered one of fred's home machines. if you are not
47 # fred, you may want to change the machine choices.
49 function is_home_system()
51 # load up the name of the host.
53 # reset the variable that we'll be setting.
55 if [[ $this_host == *.gruntose.blurgh ]]; then
61 # makes sure that the "folder" is a directory and is writable.
62 # remember that bash successful returns are zeroes...
63 function test_writeable()
65 local folder="$1"; shift
66 if [ ! -d "$folder" -o ! -w "$folder" ]; then return 1; fi
70 # we only want to totally personalize this script if the user is right.
73 if [ "$USER" == "fred" ]; then
74 export SVNUSER=fred_t_hamster@
75 export EXTRA_PROTOCOL=+ssh
78 export EXTRA_PROTOCOL=
82 # calculates the right modifier for hostnames / repositories.
84 function compute_modifier()
90 # some project specific overrides.
91 if [[ "$directory" == hoople* ]]; then
92 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/hoople2/svn/"
94 if [[ "$directory" == yeti* ]]; then
95 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/yeti/svn/"
97 # see if we're on one of fred's home machines.
99 # special override to pick local servers when at home.
100 if [ "$home_system" == "true" ]; then
101 #what was this section for again?
102 if [ "$in_or_out" == "out" ]; then
103 # need the right home machine for modifier when checking out.
104 #huhhh? modifier="svn://shaggy/"
107 # no modifier for checkin.
113 # selects the method for check-in based on where we are.
114 function do_checkin()
116 local directory="$1"; shift
120 # make a nice echoer since we want to use it inside conditions below.
121 local nicedir="$directory"
122 if [ $nicedir == "." ]; then
125 local blatt="echo checking in '$nicedir'..."
127 do_update "$directory"
128 if [ $? -ne 0 ]; then
129 echo "repository update failed; this should be fixed before check-in."
132 pushd "$directory" &>/dev/null
133 local retval=0 # normally successful.
134 if [ -f ".no-checkin" ]; then
135 echo "skipping check-in due to presence of .no-checkin sentinel file."
136 elif [ -d "CVS" ]; then
137 if test_writeable "CVS"; then
142 elif [ -d ".svn" ]; then
143 if test_writeable ".svn"; then
148 elif [ -d ".git" ]; then
149 if test_writeable ".git"; then
151 # snag all new files. not to everyone's liking.
154 # tell git about all the files and get a check-in comment.
157 # upload the files to the server so others can see them.
158 git push 2>&1 | grep -v "X11 forwarding request failed"
162 echo no repository in $directory
167 restore_terminal_title
174 local directory="$1"; shift
178 pushd "$directory" &>/dev/null
179 local retval=0 # normally successful.
181 # only update if we see a repository living there.
182 if [ -d ".svn" ]; then
184 elif [ -d ".git" ]; then
186 elif [ -d "CVS" ]; then
192 restore_terminal_title
197 function do_report_new
199 local directory="$1"; shift
203 pushd "$directory" &>/dev/null
204 local retval=0 # normally successful.
206 # only update if we see a repository living there.
207 if [ -f ".no-checkin" ]; then
208 echo "skipping reporting due to presence of .no-checkin sentinel file."
209 elif [ -d ".svn" ]; then
210 # this action so far only makes sense and is needed for svn.
211 bash $FEISTY_MEOW_SCRIPTS/rev_control/svnapply.sh \? echo
213 elif [ -d ".git" ]; then
220 restore_terminal_title
225 # checks in all the folders in a specified list.
226 function checkin_list()
228 # make the list of directories unique.
229 local list="$(uniquify $*)"
233 # turn repo list back into an array.
234 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
238 for outer in "${repository_list[@]}"; do
239 # check the repository first, since it might be an absolute path.
240 if [[ $outer =~ /.* ]]; then
241 # yep, this path is absolute. just handle it directly.
242 if [ ! -d "$outer" ]; then continue; fi
246 for inner in $list; do
247 # add in the directory component to see if we can find the folder.
248 local path="$inner/$outer"
249 if [ ! -d "$path" ]; then continue; fi
256 restore_terminal_title
259 # takes out the first few carriage returns that are in the input.
260 function squash_first_few_crs()
263 while read input_text; do
265 if [ $i -le 5 ]; then
266 echo -n "$input_text "
271 if [ $i -le 3 ]; then
272 # if we're still squashing eols, make sure we don't leave them hanging.
277 # selects the checkout method based on where we are (the host the script runs on).
280 directory="$1"; shift
284 # make a nice echoer since we want to use it inside conditions below.
285 local nicedir="$directory"
286 if [ $nicedir == "." ]; then
289 local blatt="echo retrieving '$nicedir'..."
291 local retval=0 # plan on success for now.
292 pushd "$directory" &>/dev/null
293 if [ -d "CVS" ]; then
294 if test_writeable "CVS"; then
296 cvs update . | squash_first_few_crs
297 retval=${PIPESTATUS[0]}
299 elif [ -d ".svn" ]; then
300 if test_writeable ".svn"; then
302 svn update . | squash_first_few_crs
303 retval=${PIPESTATUS[0]}
305 elif [ -d ".git" ]; then
306 if test_writeable ".git"; then
308 git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
309 retval=${PIPESTATUS[0]}
312 # this is not an error necessarily; we'll just pretend they planned this.
313 echo no repository in $directory
317 restore_terminal_title
322 # gets all the updates for a list of folders under revision control.
323 function checkout_list()
325 local list="$(uniquify $*)"
329 # turn repo list back into an array.
330 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
334 for outer in "${repository_list[@]}"; do
335 # check the repository first, since it might be an absolute path.
336 if [[ $outer =~ /.* ]]; then
337 # yep, this path is absolute. just handle it directly.
338 if [ ! -d "$outer" ]; then continue; fi
342 for inner in $list; do
343 # add in the directory component to see if we can find the folder.
344 local path="$inner/$outer"
345 if [ ! -d "$path" ]; then continue; fi
352 restore_terminal_title
355 # provides a list of absolute paths of revision control directories
356 # that are located under the directory passed as the first parameter.
357 function generate_rev_ctrl_filelist()
359 local dir="$1"; shift
360 pushd "$dir" &>/dev/null
361 local dirhere="$( \cd "$(\dirname "$dir")" && /bin/pwd )"
362 local tempfile=$(mktemp /tmp/zz_checkins.XXXXXX)
364 local additional_filter
365 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".svn" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
366 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".git" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
367 # CVS is not well behaved like git and (now) svn, and we seldom use it anymore.
370 # see if they've warned us not to try checking in within vendor hierarchies.
371 if [ ! -z "NO_CHECKIN_VENDOR" ]; then
372 sed -i -e '/.*\/vendor\/.*/d' "$tempfile"
375 local sortfile=$(mktemp /tmp/zz_checkin_sort.XXXXXX)
376 sort <"$tempfile" >"$sortfile"
381 # iterates across a list of directories contained in a file (first parameter).
382 # on each directory name, it performs the action (second parameter) provided.
383 function perform_revctrl_action_on_file()
386 #hmmm: this doesn't capture any error returns!
388 local tempfile="$1"; shift
389 local action="$1"; shift
393 while read -u 3 dirname; do
394 if [ -z "$dirname" ]; then continue; fi
395 pushd "$dirname" &>/dev/null
402 restore_terminal_title