visit_svn_helper 6.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#  Script: visit_svn_help
#
#  Purpose:
#      A common location for SVN routines.
#
#  Programmer: Hank Childs
#  Creation:   May 12, 2007
#
#  Modifications:
#
#    Hank Childs, Wed Jan  9 08:44:30 PST 2008
#    Fix typo, add svn_mv_dir.
#
14 15 16
#    Hank Childs, Thu Aug  7 08:41:15 PDT 2008
#    Add support for two digit minor releases, such as 1.10 or 1.10.1.
#
17 18 19
#    Gunther H. Weber, Fri Mar 13 11:04:00 PDT 2009
#    Replaced bashisms with POSIX so that script runs on Ubuntu with dash   
#
20 21 22
#    Hank Childs, Thu Apr 23 15:22:52 PDT 2009
#    Fix some mistakes with "==" getting translated to "-ne".
#
23 24 25
#    Jeremy Meredith, Tue Aug  9 16:09:28 EDT 2011
#    Updated repository to be at new location.
#
26 27
# *****************************************************************************

28 29 30 31 32 33 34

##
##
## Check to make sure that environment variables are set
##
##

35
if [ "$SVN_NERSC_NAME" = "" ] ; then
36
   echo "You must define the environment variable SVN_NERSC_NAME to use these scripts."
37
   echo "This should be your username on portal-auth.nersc.gov"
38 39 40 41 42 43 44 45 46 47
   exit 1
fi


##
##
## Set up environment variables for other scripts
##
##

48
VISIT_SVN_REPO=svn+ssh://${SVN_NERSC_NAME}@portal-auth.nersc.gov/project/projectdirs/visit/svn/visit
49 50 51 52 53 54 55 56 57 58 59
VISIT_SVN_BRANCHES=${VISIT_SVN_REPO}/branches
VISIT_SVN_TRUNK=${VISIT_SVN_REPO}/trunk
VISIT_SVN_TAGS=${VISIT_SVN_REPO}/tags


##
##
## Define utility functions
##
##

60
get_latest_rev()
61 62 63 64
{
    # This assumes a certain format for SVN log.  It gets the second line,
    # which has "r<REV> | ...", and then strips off the "| ...", and then 
    # strips off the 'r'.
65 66 67 68
    # first check for old non posix tail command
    if [ $(uname -s) != "SunOS" ] ; then
    REV=$(svn log $VISIT_SVN_REPO --revision HEAD | head -n 2 | tail -n 1 | cut -d'|' -f1 | sed 's/r//g')
    else
69
    REV=$(svn log $VISIT_SVN_REPO --revision HEAD | head -2 | tail -1 | cut -d'|' -f1 | sed 's/r//g')
70
    fi
71 72 73 74 75 76 77 78 79 80
    if (( REV < 950 )) ; then
       echo "An error occurred in getting revision!!" >&2
       echo "Pursue this problem with a VisIt-SVN guru" >&2
       echo "1000000"
    else
       echo $REV
    fi
}


81 82
# Note that the is_version_string test would fail for numbers bigger than 9,
# such as 1.6.10.  If this ever comes up, it should be easy to fix.
83
is_version_string()
84
{
85
    if [ ${#1} -eq 3 ] ; then
86 87
       is_two_digit_version_string $1
       return $?
88
    elif [ ${#1} -eq 4 ] ; then
89 90
       is_two_digit_version_string $1
       return $?
91
    elif [ ${#1} -eq 5 ] ; then
92 93
       is_three_digit_version_string $1
       return $?
94
    elif [ ${#1} -eq 6 ] ; then
95 96
       is_three_digit_version_string $1
       return $?
97 98 99 100 101
    fi

    return 0
}

102
is_two_digit_version_string()
103
{
104 105
    if [ ${#1} -ne 3 ] ; then
        if [ ${#1} -ne 4 ] ; then
106 107
            return 0
        fi
108 109 110 111
    fi

    typeset X
    typeset -L1 X=$1
112
    if [ "$X" != [0-9] ] ; then
113 114 115 116 117
        return 0
    fi

    typeset -L2 X=$1
    typeset -R1 X
118
    if [ "$X" != "." ] ; then
119 120 121 122 123
        return 0
    fi

    typeset -L3 X=$1
    typeset -R1 X
124
    if [ "$X" != [0-9] ] ; then
125 126 127
        return 0
    fi

128
    if [ ${#1} = 4 ] ; then
129 130
        typeset -L4 X=$1
        typeset -R1 X
131
        if [ "$X" != [0-9] ] ; then
132 133 134 135
            return 0
        fi
    fi

136 137 138
    return 1
}

139
is_three_digit_version_string()
140
{
141
    if [ ${#1} != 5 ] ; then
142 143 144 145 146
        return 0
    fi

    typeset X
    typeset -L1 X=$1
147
    if [ "$X" != [0-9] ] ; then
148 149 150 151 152
        return 0
    fi

    typeset -L2 X=$1
    typeset -R1 X
153
    if [ "$X" != "." ] ; then
154 155 156 157 158
        return 0
    fi

    typeset -L3 X=$1
    typeset -R1 X
159
    if [ "$X" != [0-9] ] ; then
160 161 162 163 164
        return 0
    fi

    typeset -L4 X=$1
    typeset -R1 X
165
    if [ "$X" = "." ] ; then
166 167
        typeset -L5 X=$1
        typeset -R1 X
168
        if [ "$X" != [0-9] ] ; then
169 170
            return 0
        fi
171 172
    elif [ "$X" != "." ] ; then
        if [ "$X" != [0-9] ] ; then
173 174 175 176
            return 0
        fi
        typeset -L5 X=$1
        typeset -R1 X
177
        if [ "$X" != "." ] ; then
178 179 180 181
            return 0
        fi
        typeset -L6 X=$1
        typeset -R1 X
182
        if [ "$X" != [0-9] ] ; then
183 184
            return 0
        fi
185 186 187 188 189
    fi

    return 1
}

190
is_four_digit_version_string()
191
{
192
    if [ ${#1} != 7 ] ; then
193 194 195 196 197
        return 0
    fi

    typeset X
    typeset -L1 X=$1
198
    if [ "$X" != [0-9] ] ; then
199 200 201 202 203
        return 0
    fi

    typeset -L2 X=$1
    typeset -R1 X
204
    if [ "$X" != "." ] ; then
205 206 207 208 209
        return 0
    fi

    typeset -L3 X=$1
    typeset -R1 X
210
    if [ "$X" != [0-9] ] ; then
211 212 213 214 215
        return 0
    fi

    typeset -L4 X=$1
    typeset -R1 X
216
    if [ "$X" != "." ] ; then
217 218 219 220 221
        return 0
    fi

    typeset -L5 X=$1
    typeset -R1 X
222
    if [ "$X" != [0-9] ] ; then
223 224 225 226 227
        return 0
    fi

    typeset -L6 X=$1
    typeset -R1 X
228
    if [ "$X" != "." ] ; then
229 230 231 232 233
        return 0
    fi

    typeset -L7 X=$1
    typeset -R1 X
234
    if [ "$X" != [0-9] ] ; then
235 236 237 238 239 240 241
        return 0
    fi

    return 1
}


242
svn_cp_dir()
243 244 245 246 247 248
{
   SRC=$1
   DEST=$2

   # Confirm presence of $SRC
   svn ls $SRC 2>/dev/null > /dev/null
249
   if [ $? -ne 0 ] ; then
250
      echo "Cannot locate directory ($SRC) for copying.  Aborting!"
hrchilds's avatar
hrchilds committed
251
      echo "(Try using ls_branches to locate the directory.)"
252 253 254 255 256
      exit 1
   fi

   # Confirm that $DEST does not already exist
   svn ls $DEST 2>/dev/null > /dev/null
257
   if [ $? -eq 0 ] ; then
258 259 260 261 262 263
      echo "Destination ($DEST) already exists.  Aborting!"
      exit 1
   fi

   echo "Creating ${DEST}...."
   svn copy $SRC $DEST -m "Making copy of $SRC as $DEST"
264
   if [ $? -eq 0 ] ; then
265 266 267 268 269 270 271 272
      echo "Successful."
   else
      echo "Not successful."
      exit 1
   fi
}


273
svn_mv_dir()
274 275 276 277 278 279
{
   SRC=$1
   DEST=$2

   # Confirm presence of $SRC
   svn ls $SRC 2>/dev/null > /dev/null
280
   if [ $? -ne 0 ] ; then
281 282 283 284 285 286 287
      echo "Cannot locate directory ($SRC) for moving.  Aborting!"
      echo "(Try using ls_branches to locate the directory.)"
      exit 1
   fi

   # Confirm that $DEST does not already exist
   svn ls $DEST 2>/dev/null > /dev/null
288
   if [ $? -eq 0 ] ; then
289 290 291 292 293 294
      echo "Destination ($DEST) already exists.  Aborting!"
      exit 1
   fi

   echo "Creating ${DEST}...."
   svn move $SRC $DEST -m "Making copy of $SRC as $DEST"
295
   if [ $? -eq 0 ] ; then
296 297 298 299 300 301 302 303
      echo "Successful."
   else
      echo "Not successful."
      exit 1
   fi
}


304
svn_rm_dir()
305 306 307 308
{
   DIR=$1
   # Confirm presence of $DIR
   svn ls $DIR 2>/dev/null > /dev/null
309
   if [ $? -ne 0 ] ; then
310 311 312 313 314 315 316 317 318 319
      echo "Cannot locate release candidate ($DIR) for deleting.  Aborting!"
      exit 1
   fi

   svn delete $DIR -m "Removing directory $DIR"
   return $?
}