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 # nothing there. it's not an error though.
179 echo no repository in $directory
184 restore_terminal_title
191 local directory="$1"; shift
195 pushd "$directory" &>/dev/null
196 local retval=0 # normally successful.
198 # only update if we see a repository living there.
199 if [ -d ".svn" ]; then
202 elif [ -d ".git" ]; then
205 elif [ -d "CVS" ]; then
212 restore_terminal_title
217 function do_report_new
219 local directory="$1"; shift
223 pushd "$directory" &>/dev/null
224 local retval=0 # normally successful.
226 # only update if we see a repository living there.
227 if [ -f ".no-checkin" ]; then
228 echo "skipping reporting due to presence of .no-checkin sentinel file."
229 elif [ -d ".svn" ]; then
230 # this action so far only makes sense and is needed for svn.
231 bash $FEISTY_MEOW_SCRIPTS/rev_control/svnapply.sh \? echo
233 elif [ -d ".git" ]; then
240 restore_terminal_title
245 # checks in all the folders in a specified list.
246 function checkin_list()
248 # make the list of directories unique.
249 local list="$(uniquify $*)"
253 # turn repo list back into an array.
254 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
258 for outer in "${repository_list[@]}"; do
259 # check the repository first, since it might be an absolute path.
260 if [[ $outer =~ /.* ]]; then
261 # yep, this path is absolute. just handle it directly.
262 if [ ! -d "$outer" ]; then continue; fi
264 test_or_die "running check-in on: $outer"
267 for inner in $list; do
268 # add in the directory component to see if we can find the folder.
269 local path="$inner/$outer"
270 if [ ! -d "$path" ]; then continue; fi
272 test_or_die "running check-in on: $path"
278 restore_terminal_title
281 # takes out the first few carriage returns that are in the input.
282 function squash_first_few_crs()
285 while read input_text; do
287 if [ $i -le 5 ]; then
288 echo -n "$input_text "
293 if [ $i -le 3 ]; then
294 # if we're still squashing eols, make sure we don't leave them hanging.
299 # selects the checkout method based on where we are (the host the script runs on).
302 directory="$1"; shift
306 # make a nice echoer since we want to use it inside conditions below.
307 local nicedir="$directory"
308 if [ $nicedir == "." ]; then
311 local blatt="echo retrieving '$nicedir'..."
313 local retval=0 # plan on success for now.
314 pushd "$directory" &>/dev/null
315 if [ -d "CVS" ]; then
316 if test_writeable "CVS"; then
318 cvs update . | squash_first_few_crs
319 retval=${PIPESTATUS[0]}
321 elif [ -d ".svn" ]; then
322 if test_writeable ".svn"; then
324 svn update . | squash_first_few_crs
325 retval=${PIPESTATUS[0]}
327 elif [ -d ".git" ]; then
328 if test_writeable ".git"; then
330 git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
331 retval=${PIPESTATUS[0]}
334 # this is not an error necessarily; we'll just pretend they planned this.
335 echo no repository in $directory
339 restore_terminal_title
344 # gets all the updates for a list of folders under revision control.
345 function checkout_list()
347 local list="$(uniquify $*)"
351 # turn repo list back into an array.
352 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
356 for outer in "${repository_list[@]}"; do
357 # check the repository first, since it might be an absolute path.
358 if [[ $outer =~ /.* ]]; then
359 # yep, this path is absolute. just handle it directly.
360 if [ ! -d "$outer" ]; then continue; fi
362 test_or_die "running update on: $path"
365 for inner in $list; do
366 # add in the directory component to see if we can find the folder.
367 local path="$inner/$outer"
368 if [ ! -d "$path" ]; then continue; fi
370 test_or_die "running update on: $path"
376 restore_terminal_title
379 # provides a list of absolute paths of revision control directories
380 # that are located under the directory passed as the first parameter.
381 function generate_rev_ctrl_filelist()
383 local dir="$1"; shift
384 pushd "$dir" &>/dev/null
385 local dirhere="$( \cd "$(\dirname "$dir")" && /bin/pwd )"
386 local tempfile=$(mktemp /tmp/zz_checkins.XXXXXX)
388 local additional_filter
389 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".svn" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
390 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".git" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
391 # CVS is not well behaved like git and (now) svn, and we seldom use it anymore.
394 # see if they've warned us not to try checking in within vendor hierarchies.
395 if [ ! -z "NO_CHECKIN_VENDOR" ]; then
396 sed -i -e '/.*\/vendor\/.*/d' "$tempfile"
399 local sortfile=$(mktemp /tmp/zz_checkin_sort.XXXXXX)
400 sort <"$tempfile" >"$sortfile"
405 # iterates across a list of directories contained in a file (first parameter).
406 # on each directory name, it performs the action (second parameter) provided.
407 function perform_revctrl_action_on_file()
409 local tempfile="$1"; shift
410 local action="$1"; shift
414 while read -u 3 dirname; do
415 if [ -z "$dirname" ]; then continue; fi
416 pushd "$dirname" &>/dev/null
419 test_or_die "performing action $action on: $(pwd)"
424 restore_terminal_title