Blame Automation/Modules/Vcs/Subversion/subversion_updateRepoChanges.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# subversion_updateRepoChanges.sh -- This function realizes a
Alain Reguera Delgado 8f60cb
# subversion update command against the working copy in order to bring
Alain Reguera Delgado 8f60cb
# changes from the central repository into the working copy.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function subversion_updateRepoChanges {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local -a FILES
Alain Reguera Delgado 8f60cb
    local -a INFO
Alain Reguera Delgado 8f60cb
    local -a FILESNUM
Alain Reguera Delgado 8f60cb
    local COUNT=0
Alain Reguera Delgado 8f60cb
    local UPDATEOUT=''
Alain Reguera Delgado 8f60cb
    local PREDICATE=''
Alain Reguera Delgado 8f60cb
    local CHNGTOTAL=0
Alain Reguera Delgado 8f60cb
    local LOCATION=$(cli_checkRepoDirSource "$1")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify source location absolute path. It should point either to
Alain Reguera Delgado 8f60cb
    # existent files or directories both under version control inside
Alain Reguera Delgado 8f60cb
    # the working copy.  Otherwise, if it doesn't point to an existent
Alain Reguera Delgado 8f60cb
    # file under version control, finish the script execution with an
Alain Reguera Delgado 8f60cb
    # error message.
Alain Reguera Delgado 8f60cb
    cli_checkFiles ${LOCATION} -e --is-versioned
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Update working copy and retrieve update output.
Alain Reguera Delgado 8f60cb
    cli_printMessage "`gettext "Bringing changes from the repository into the working copy"`" --as-banner-line
Alain Reguera Delgado 8f60cb
    UPDATEOUT=$(${COMMAND} update ${LOCATION} --quiet)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define path of files considered recent modifications from
Alain Reguera Delgado 8f60cb
    # central repository to working copy.
Alain Reguera Delgado 8f60cb
    FILES[0]=$(echo "$UPDATEOUT" | egrep "^A" | sed -r "s,^.+${TCAR_WORKDIR},,")
Alain Reguera Delgado 8f60cb
    FILES[1]=$(echo "$UPDATEOUT" | egrep "^D" | sed -r "s,^.+${TCAR_WORKDIR},,")
Alain Reguera Delgado 8f60cb
    FILES[2]=$(echo "$UPDATEOUT" | egrep "^U" | sed -r "s,^.+${TCAR_WORKDIR},,")
Alain Reguera Delgado 8f60cb
    FILES[3]=$(echo "$UPDATEOUT" | egrep "^C" | sed -r "s,^.+${TCAR_WORKDIR},,")
Alain Reguera Delgado 8f60cb
    FILES[4]=$(echo "$UPDATEOUT" | egrep "^G" | sed -r "s,^.+${TCAR_WORKDIR},,")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define description of files considered recent modifications from
Alain Reguera Delgado 8f60cb
    # central repository to working copy.
Alain Reguera Delgado 8f60cb
    INFO[0]="`gettext "Added"`"
Alain Reguera Delgado 8f60cb
    INFO[1]="`gettext "Deleted"`"
Alain Reguera Delgado 8f60cb
    INFO[2]="`gettext "Updated"`"
Alain Reguera Delgado 8f60cb
    INFO[3]="`gettext "Conflicted"`"
Alain Reguera Delgado 8f60cb
    INFO[4]="`gettext "Merged"`"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    while [[ $COUNT -ne ${#FILES[*]} ]];do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define total number of files. Avoid counting empty line.
Alain Reguera Delgado 8f60cb
        if [[ "${FILES[$COUNT]}" == '' ]];then
Alain Reguera Delgado 8f60cb
            FILESNUM[$COUNT]=0
Alain Reguera Delgado 8f60cb
        else
Alain Reguera Delgado 8f60cb
            FILESNUM[$COUNT]=$(echo "${FILES[$COUNT]}" | wc -l)
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Calculate total amount of changes.
Alain Reguera Delgado 8f60cb
        CHNGTOTAL=$(($CHNGTOTAL + ${FILESNUM[$COUNT]}))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Build report predicate. Use report predicate to show any
Alain Reguera Delgado 8f60cb
        # information specific to the number of files found. For
Alain Reguera Delgado 8f60cb
        # example, you can use this section to show warning messages,
Alain Reguera Delgado 8f60cb
        # notes, and so on. By default we use the word `file' or
Alain Reguera Delgado 8f60cb
        # `files' at ngettext's consideration followed by change
Alain Reguera Delgado 8f60cb
        # direction.
Alain Reguera Delgado 8f60cb
        PREDICATE[$COUNT]=`ngettext "file from the repository" \
Alain Reguera Delgado 8f60cb
            "files from the repository" $((${FILESNUM[$COUNT]} + 1))`
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Output report line.
Alain Reguera Delgado 8f60cb
        cli_printMessage "${INFO[$COUNT]}: ${FILESNUM[$COUNT]} ${PREDICATE[$COUNT]}" --as-stdout-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Increase counter.
Alain Reguera Delgado 8f60cb
        COUNT=$(($COUNT + 1))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}