3 # these are helper functions for doing localized revision control.
4 # this script should be sourced into other scripts that use it.
6 # one unpleasantry to take care of first; cygwin barfs aggressively if the TMP directory
7 # is a DOS path, but we need it to be a DOS path for our XSEDE testing, so that blows.
8 # to get past this, TMP gets changed below to a hopefully generic and safe place.
10 if [[ "$TMP" =~ .:.* ]]; then
11 echo making weirdo temporary directory for DOS path.
12 export TMP=/tmp/rev_control_$USER
14 if [ ! -d "$TMP" ]; then
17 if [ ! -d "$TMP" ]; then
18 echo "Could not create the temporary directory TMP in: $TMP"
19 echo "This script will not work properly without an existing TMP directory."
23 # gets the machine's hostname and stores it in the variable "this_host".
24 function get_our_hostname()
26 if [ "$OS" == "Windows_NT" ]; then
28 elif [ ! -z "$(echo $MACHTYPE | grep apple)" ]; then
30 elif [ ! -z "$(echo $MACHTYPE | grep suse)" ]; then
31 this_host=$(hostname --long)
35 #echo "hostname is $this_host"
38 # this function sets a variable called "home_system" to "true" if the
39 # machine is considered one of fred's home machines. if you are not
40 # fred, you may want to change the machine choices.
42 function is_home_system()
44 # load up the name of the host.
46 # reset the variable that we'll be setting.
48 if [[ $this_host == *.gruntose.blurgh ]]; then
51 elif [[ $this_host == buildy ]]; then
53 elif [[ $this_host == simmy ]]; then
59 # we only want to totally personalize this script if the user is right.
62 if [ "$USER" == "fred" ]; then
63 export SVNUSER=fred_t_hamster@
64 export EXTRA_PROTOCOL=+ssh
67 export EXTRA_PROTOCOL=
71 # calculates the right modifier for hostnames / repositories.
73 function compute_modifier()
79 # some project specific overrides.
80 if [[ "$directory" == hoople* ]]; then
81 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/hoople2/svn/"
83 if [[ "$directory" == yeti* ]]; then
84 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/yeti/svn/"
86 # see if we're on one of fred's home machines.
88 # special override to pick local servers when at home.
89 if [ "$home_system" == "true" ]; then
90 if [ "$in_or_out" == "out" ]; then
91 # need the right home machine for modifier when checking out.
92 #huhhh? modifier="svn://shaggy/"
95 # 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
105 pushd "$directory" &>/dev/null
106 retval=0 # normally successful.
107 if [ -d "CVS" ]; then
110 elif [ -d ".svn" ]; then
113 elif [ -d ".git" ]; then
114 # snag all new files. not to everyone's liking.
117 # tell git about all the files and get a check-in comment.
120 # upload the files to the server so others can see them.
121 git push 2>&1 | grep -v "X11 forwarding request failed"
124 echo unknown repository for $directory...
133 local directory="$1"; shift
134 pushd "$directory" &>/dev/null
135 retval=0 # normally successful.
137 # only update if we see a repository living there.
138 if [ -d ".svn" ]; then
140 elif [ -d ".git" ]; then
142 elif [ -d "CVS" ]; then
150 function do_report_new
152 local directory="$1"; shift
153 pushd "$directory" &>/dev/null
154 retval=0 # normally successful.
156 # only update if we see a repository living there.
157 if [ -d ".svn" ]; then
158 # this action so far only makes sense and is needed for svn.
159 bash $FEISTY_MEOW_SCRIPTS/rev_control/svnapply.sh \? echo
166 # checks in all the folders in a specified list.
167 function checkin_list()
171 # turn repo list back into an array.
172 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
173 for j in "${repository_list[@]}"; do
174 # add in the directory component.
176 if [ ! -d "$j" ]; then continue; fi
177 echo "checking in '$j'..."
183 # takes out the first few carriage returns that are in the input.
184 function squash_first_few_crs()
189 if [ $i -le 3 ]; then
195 if [ $i -le 3 ]; then
196 # if we're still squashing eols, make sure we don't leave them hanging.
201 # selects the checkout method based on where we are (the host the script runs on).
204 directory="$1"; shift
206 pushd "$directory" &>/dev/null
207 if [ -d "CVS" ]; then
208 cvs update . | squash_first_few_crs
209 elif [ -d ".svn" ]; then
210 svn update . | squash_first_few_crs
211 elif [ -d ".git" ]; then
212 git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
214 echo unknown repository for $directory...
219 # gets all the updates for a list of folders under revision control.
220 function checkout_list {
223 # turn repo list back into an array.
224 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
225 for j in "${repository_list[@]}"; do
226 # add in the directory for our purposes here.
229 if [ ! -z "$SHELL_DEBUG" ]; then
230 echo "No directory called $j exists."
235 echo -n "retrieving '$j'... "
241 # provides a list of absolute paths of revision control directories
242 # that are located under the directory passed as the first parameter.
243 function generate_rev_ctrl_filelist()
245 local dir="$1"; shift
246 pushd "$dir" &>/dev/null
247 local dirhere="$(\pwd)"
248 local tempfile=$(mktemp /tmp/zz_rev_checkin.XXXXXX)
250 find $dirhere -maxdepth 4 -type d -iname ".svn" -exec echo {}/.. ';' >>$tempfile
251 find $dirhere -maxdepth 4 -type d -iname ".git" -exec echo {}/.. ';' >>$tempfile
252 #CVS is not well behaved, and we seldom use it anymore.
253 # find $dirhere -maxdepth 3 -type d -iname "CVS" -exec echo {}/.. ';' >>$tempfile
258 # iterates across a list of directories contained in a file (first parameter).
259 # on each directory name, it performs the action (second parameter) provided.
260 function perform_action_on_file()
262 local tempfile="$1"; shift
263 local action="$1"; shift
265 dirs=($(cat $tempfile))
267 for dirname in ${dirs[@]}; do
268 if [ -z "$dirname" ]; then continue; fi
269 pushd $dirname &>/dev/null