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
58 elif [[ $this_host == buildy ]]; then
60 elif [[ $this_host == simmy ]]; then
66 # we only want to totally personalize this script if the user is right.
69 if [ "$USER" == "fred" ]; then
70 export SVNUSER=fred_t_hamster@
71 export EXTRA_PROTOCOL=+ssh
74 export EXTRA_PROTOCOL=
78 # calculates the right modifier for hostnames / repositories.
80 function compute_modifier()
86 # some project specific overrides.
87 if [[ "$directory" == hoople* ]]; then
88 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/hoople2/svn/"
90 if [[ "$directory" == yeti* ]]; then
91 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/yeti/svn/"
93 # see if we're on one of fred's home machines.
95 # special override to pick local servers when at home.
96 if [ "$home_system" == "true" ]; then
97 if [ "$in_or_out" == "out" ]; then
98 # need the right home machine for modifier when checking out.
99 #huhhh? modifier="svn://shaggy/"
102 # no modifier for checkin.
108 # selects the method for check-in based on where we are.
109 function do_checkin()
111 local directory="$1"; shift
115 do_update "$directory"
116 if [ $? -ne 0 ]; then
117 echo "repository update failed; this should be fixed before check-in."
120 pushd "$directory" &>/dev/null
121 local retval=0 # normally successful.
122 if [ -f ".no-checkin" ]; then
123 echo "skipping check-in due to presence of .no-checkin sentinel file."
124 elif [ -d "CVS" ]; then
127 elif [ -d ".svn" ]; then
130 elif [ -d ".git" ]; then
131 # snag all new files. not to everyone's liking.
134 # tell git about all the files and get a check-in comment.
137 # upload the files to the server so others can see them.
138 git push 2>&1 | grep -v "X11 forwarding request failed"
141 echo no repository in $directory
146 restore_terminal_title
153 local directory="$1"; shift
157 pushd "$directory" &>/dev/null
158 local retval=0 # normally successful.
160 # only update if we see a repository living there.
161 if [ -d ".svn" ]; then
163 elif [ -d ".git" ]; then
165 elif [ -d "CVS" ]; then
171 restore_terminal_title
176 function do_report_new
178 local directory="$1"; shift
182 pushd "$directory" &>/dev/null
183 local retval=0 # normally successful.
185 # only update if we see a repository living there.
186 if [ -f ".no-checkin" ]; then
187 echo "skipping reporting due to presence of .no-checkin sentinel file."
188 elif [ -d ".svn" ]; then
189 # this action so far only makes sense and is needed for svn.
190 bash $FEISTY_MEOW_SCRIPTS/rev_control/svnapply.sh \? echo
192 elif [ -d ".git" ]; then
199 restore_terminal_title
204 # checks in all the folders in a specified list.
205 function checkin_list()
207 # make the list of directories unique.
208 local list="$(uniquify $*)"
213 # turn repo list back into an array.
214 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
215 for j in "${repository_list[@]}"; do
216 # add in the directory component.
218 if [ ! -d "$j" ]; then continue; fi
219 echo "checking in '$j'..."
225 restore_terminal_title
228 # takes out the first few carriage returns that are in the input.
229 function squash_first_few_crs()
232 while read input_text; do
234 if [ $i -le 5 ]; then
235 echo -n "$input_text "
240 if [ $i -le 3 ]; then
241 # if we're still squashing eols, make sure we don't leave them hanging.
246 # selects the checkout method based on where we are (the host the script runs on).
249 directory="$1"; shift
253 local retval=0 # plan on success for now.
254 pushd "$directory" &>/dev/null
255 if [ -d "CVS" ]; then
256 cvs update . | squash_first_few_crs
257 retval=${PIPESTATUS[0]}
258 elif [ -d ".svn" ]; then
259 svn update . | squash_first_few_crs
260 retval=${PIPESTATUS[0]}
261 elif [ -d ".git" ]; then
262 git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
263 retval=${PIPESTATUS[0]}
265 # this is not an error necessarily; we'll just pretend they planned this.
266 echo no repository in $directory
270 restore_terminal_title
275 # gets all the updates for a list of folders under revision control.
276 function checkout_list()
278 local list="$(uniquify $*)"
283 # turn repo list back into an array.
284 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
285 for j in "${repository_list[@]}"; do
286 # add in the directory for our purposes here.
289 if [ ! -z "$SHELL_DEBUG" ]; then
290 echo "no directory called $j exists."
295 echo -n "retrieving '$j'... "
300 restore_terminal_title
303 # provides a list of absolute paths of revision control directories
304 # that are located under the directory passed as the first parameter.
305 function generate_rev_ctrl_filelist()
307 local dir="$1"; shift
308 pushd "$dir" &>/dev/null
309 local dirhere="$( \cd "$(\dirname "$dir")" && /bin/pwd )"
310 local tempfile=$(mktemp /tmp/zz_rev_checkin.XXXXXX)
312 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".svn" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
313 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".git" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
314 # CVS is not well behaved like git and (now) svn, and we seldom use it anymore.
316 local sortfile=$(mktemp /tmp/zz_rev_checkin_sort.XXXXXX)
317 sort <"$tempfile" >"$sortfile"
322 # iterates across a list of directories contained in a file (first parameter).
323 # on each directory name, it performs the action (second parameter) provided.
324 function perform_revctrl_action_on_file()
327 #hmmm: this doesn't capture any error returns!
329 local tempfile="$1"; shift
330 local action="$1"; shift
334 while read -u 3 dirname; do
335 if [ -z "$dirname" ]; then continue; fi
336 pushd "$dirname" &>/dev/null
343 restore_terminal_title