visit_svn_helper 6.24 KB
Newer Older
hrchilds's avatar
hrchilds committed
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".
#
hrchilds's avatar
hrchilds committed
23 24
# *****************************************************************************

25 26 27 28 29 30 31

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

32
if [ "$SVN_NERSC_NAME" = "" ] ; then
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
   echo "You must define the environment variable SVN_NERSC_NAME to use these scripts."
   echo "This should be your username on svn.nersc.gov"
   exit 1
fi


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

VISIT_SVN_REPO=svn+ssh://${SVN_NERSC_NAME}@svn.nersc.gov/svn/visit
VISIT_SVN_BRANCHES=${VISIT_SVN_REPO}/branches
VISIT_SVN_TRUNK=${VISIT_SVN_REPO}/trunk
VISIT_SVN_TAGS=${VISIT_SVN_REPO}/tags


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

57
get_latest_rev()
58 59 60 61
{
    # 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'.
62 63 64 65
    # 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
66
    REV=$(svn log $VISIT_SVN_REPO --revision HEAD | head -2 | tail -1 | cut -d'|' -f1 | sed 's/r//g')
67
    fi
68 69 70 71 72 73 74 75 76 77
    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
}


78 79
# 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.
80
is_version_string()
81
{
82
    if [ ${#1} -eq 3 ] ; then
83 84
       is_two_digit_version_string $1
       return $?
85
    elif [ ${#1} -eq 4 ] ; then
86 87
       is_two_digit_version_string $1
       return $?
88
    elif [ ${#1} -eq 5 ] ; then
89 90
       is_three_digit_version_string $1
       return $?
91
    elif [ ${#1} -eq 6 ] ; then
92 93
       is_three_digit_version_string $1
       return $?
94 95 96 97 98
    fi

    return 0
}

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

    typeset X
    typeset -L1 X=$1
109
    if [ "$X" != [0-9] ] ; then
110 111 112 113 114
        return 0
    fi

    typeset -L2 X=$1
    typeset -R1 X
115
    if [ "$X" != "." ] ; then
116 117 118 119 120
        return 0
    fi

    typeset -L3 X=$1
    typeset -R1 X
121
    if [ "$X" != [0-9] ] ; then
122 123 124
        return 0
    fi

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

133 134 135
    return 1
}

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

    typeset X
    typeset -L1 X=$1
144
    if [ "$X" != [0-9] ] ; then
145 146 147 148 149
        return 0
    fi

    typeset -L2 X=$1
    typeset -R1 X
150
    if [ "$X" != "." ] ; then
151 152 153 154 155
        return 0
    fi

    typeset -L3 X=$1
    typeset -R1 X
156
    if [ "$X" != [0-9] ] ; then
157 158 159 160 161
        return 0
    fi

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

    return 1
}

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

    typeset X
    typeset -L1 X=$1
195
    if [ "$X" != [0-9] ] ; then
196 197 198 199 200
        return 0
    fi

    typeset -L2 X=$1
    typeset -R1 X
201
    if [ "$X" != "." ] ; then
202 203 204 205 206
        return 0
    fi

    typeset -L3 X=$1
    typeset -R1 X
207
    if [ "$X" != [0-9] ] ; then
208 209 210 211 212
        return 0
    fi

    typeset -L4 X=$1
    typeset -R1 X
213
    if [ "$X" != "." ] ; then
214 215 216 217 218
        return 0
    fi

    typeset -L5 X=$1
    typeset -R1 X
219
    if [ "$X" != [0-9] ] ; then
220 221 222 223 224
        return 0
    fi

    typeset -L6 X=$1
    typeset -R1 X
225
    if [ "$X" != "." ] ; then
226 227 228 229 230
        return 0
    fi

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

    return 1
}


239
svn_cp_dir()
240 241 242 243 244 245
{
   SRC=$1
   DEST=$2

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

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

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


270
svn_mv_dir()
hrchilds's avatar
hrchilds committed
271 272 273 274 275 276
{
   SRC=$1
   DEST=$2

   # Confirm presence of $SRC
   svn ls $SRC 2>/dev/null > /dev/null
277
   if [ $? -ne 0 ] ; then
hrchilds's avatar
hrchilds committed
278 279 280 281 282 283 284
      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
285
   if [ $? -eq 0 ] ; then
hrchilds's avatar
hrchilds committed
286 287 288 289 290 291
      echo "Destination ($DEST) already exists.  Aborting!"
      exit 1
   fi

   echo "Creating ${DEST}...."
   svn move $SRC $DEST -m "Making copy of $SRC as $DEST"
292
   if [ $? -eq 0 ] ; then
hrchilds's avatar
hrchilds committed
293 294 295 296 297 298 299 300
      echo "Successful."
   else
      echo "Not successful."
      exit 1
   fi
}


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

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