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/functions.sh"
8 # the maximum depth that the recursive functions will try to go below the starting directory.
11 #hmmm: re-address this code, since it doesn't make a lot of sense to me right now...
12 # one unpleasantry to take care of first; cygwin barfs aggressively if the TMP directory
13 # is a DOS path, but we need it to be a DOS path for our GFFS testing, so that blows.
14 # to get past this, TMP gets changed below to a hopefully generic and safe place.
16 if [[ "$TMP" =~ .:.* ]]; then
17 echo making weirdo temporary directory for DOS path.
18 export TMP=/tmp/rev_control_$USER
20 if [ ! -d "$TMP" ]; then
23 if [ ! -d "$TMP" ]; then
24 echo "could not create the temporary directory TMP in: $TMP"
25 echo "this script will not work properly without an existing TMP directory."
29 # gets the machine's hostname and stores it in the variable "this_host".
30 function get_our_hostname()
32 if [ "$OS" == "Windows_NT" ]; then
34 elif [ ! -z "$(echo $MACHTYPE | grep apple)" ]; then
36 elif [ ! -z "$(echo $MACHTYPE | grep suse)" ]; then
37 this_host=$(hostname --long)
41 #echo "hostname is $this_host"
44 # this function sets a variable called "home_system" to "true" if the
45 # machine is considered one of fred's home machines. if you are not
46 # fred, you may want to change the machine choices.
48 function is_home_system()
50 # load up the name of the host.
52 # reset the variable that we'll be setting.
54 if [[ $this_host == *.gruntose.blurgh ]]; then
57 elif [[ $this_host == buildy ]]; then
59 elif [[ $this_host == simmy ]]; then
65 # we only want to totally personalize this script if the user is right.
68 if [ "$USER" == "fred" ]; then
69 export SVNUSER=fred_t_hamster@
70 export EXTRA_PROTOCOL=+ssh
73 export EXTRA_PROTOCOL=
77 # calculates the right modifier for hostnames / repositories.
79 function compute_modifier()
85 # some project specific overrides.
86 if [[ "$directory" == hoople* ]]; then
87 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/hoople2/svn/"
89 if [[ "$directory" == yeti* ]]; then
90 modifier="svn${EXTRA_PROTOCOL}://${SVNUSER}svn.code.sf.net/p/yeti/svn/"
92 # see if we're on one of fred's home machines.
94 # special override to pick local servers when at home.
95 if [ "$home_system" == "true" ]; then
96 if [ "$in_or_out" == "out" ]; then
97 # need the right home machine for modifier when checking out.
98 #huhhh? modifier="svn://shaggy/"
101 # no modifier for checkin.
107 # selects the method for check-in based on where we are.
108 function do_checkin()
110 local directory="$1"; shift
111 do_update "$directory"
112 if [ $? -ne 0 ]; then
113 echo "repository update failed; this should be fixed before check-in."
116 pushd "$directory" &>/dev/null
117 local retval=0 # normally successful.
118 if [ -f ".no-checkin" ]; then
119 echo "skipping check-in due to presence of .no-checkin sentinel file."
120 elif [ -d "CVS" ]; then
123 elif [ -d ".svn" ]; then
126 elif [ -d ".git" ]; then
127 # snag all new files. not to everyone's liking.
130 # tell git about all the files and get a check-in comment.
133 # upload the files to the server so others can see them.
134 git push 2>&1 | grep -v "X11 forwarding request failed"
137 echo no repository in $directory
146 local directory="$1"; shift
147 pushd "$directory" &>/dev/null
148 local retval=0 # normally successful.
150 # only update if we see a repository living there.
151 if [ -d ".svn" ]; then
153 elif [ -d ".git" ]; then
155 elif [ -d "CVS" ]; then
163 function do_report_new
165 local directory="$1"; shift
166 pushd "$directory" &>/dev/null
167 local retval=0 # normally successful.
169 # only update if we see a repository living there.
170 if [ -f ".no-checkin" ]; then
171 echo "skipping reporting due to presence of .no-checkin sentinel file."
172 elif [ -d ".svn" ]; then
173 # this action so far only makes sense and is needed for svn.
174 bash $FEISTY_MEOW_SCRIPTS/rev_control/svnapply.sh \? echo
176 elif [ -d ".git" ]; then
185 # checks in all the folders in a specified list.
186 function checkin_list()
190 # turn repo list back into an array.
191 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
192 for j in "${repository_list[@]}"; do
193 # add in the directory component.
195 if [ ! -d "$j" ]; then continue; fi
196 echo "checking in '$j'..."
203 # takes out the first few carriage returns that are in the input.
204 function squash_first_few_crs()
207 while read input_text; do
209 if [ $i -le 5 ]; then
210 echo -n "$input_text "
215 if [ $i -le 3 ]; then
216 # if we're still squashing eols, make sure we don't leave them hanging.
221 # selects the checkout method based on where we are (the host the script runs on).
224 directory="$1"; shift
225 local retval=0 # plan on success for now.
226 pushd "$directory" &>/dev/null
227 if [ -d "CVS" ]; then
228 cvs update . | squash_first_few_crs
229 retval=${PIPESTATUS[0]}
230 elif [ -d ".svn" ]; then
231 svn update . | squash_first_few_crs
232 retval=${PIPESTATUS[0]}
233 elif [ -d ".git" ]; then
234 git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
235 retval=${PIPESTATUS[0]}
237 # this is not an error necessarily; we'll just pretend they planned this.
238 echo no repository in $directory
244 # gets all the updates for a list of folders under revision control.
245 function checkout_list {
248 # turn repo list back into an array.
249 eval "repository_list=( ${REPOSITORY_LIST[*]} )"
250 for j in "${repository_list[@]}"; do
251 # add in the directory for our purposes here.
254 if [ ! -z "$SHELL_DEBUG" ]; then
255 echo "no directory called $j exists."
260 echo -n "retrieving '$j'... "
266 # provides a list of absolute paths of revision control directories
267 # that are located under the directory passed as the first parameter.
268 function generate_rev_ctrl_filelist()
270 local dir="$1"; shift
271 pushd "$dir" &>/dev/null
272 local dirhere="$( \cd "$(\dirname "$dir")" && /bin/pwd )"
273 local tempfile=$(mktemp /tmp/zz_rev_checkin.XXXXXX)
275 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".svn" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
276 find $dirhere -follow -maxdepth $MAX_DEPTH -type d -iname ".git" -exec echo {}/.. ';' >>$tempfile 2>/dev/null
277 # CVS is not well behaved like git and (now) svn, and we seldom use it anymore.
279 local sortfile=$(mktemp /tmp/zz_rev_checkin_sort.XXXXXX)
280 sort <"$tempfile" >"$sortfile"
285 # iterates across a list of directories contained in a file (first parameter).
286 # on each directory name, it performs the action (second parameter) provided.
287 function perform_revctrl_action_on_file()
289 local tempfile="$1"; shift
290 local action="$1"; shift
292 while read -u 3 dirname; do
293 if [ -z "$dirname" ]; then continue; fi
294 pushd "$dirname" &>/dev/null