Blame Scripts/Bash/Functions/Commons/cli_updateRepoChanges.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# cli_updateRepoChanges.sh -- This function realizes a subversion
878a2b
# update command against the working copy in order to bring changes
878a2b
# from the central repository into the working copy.
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function cli_updateRepoChanges {
878a2b
878a2b
    # Verify don't commit changes flag.
878a2b
    if [[ $FLAG_DONT_COMMIT_CHANGES != 'false' ]];then
878a2b
        return
878a2b
    fi
878a2b
878a2b
    local -a FILES
878a2b
    local -a INFO
878a2b
    local -a FILESNUM
878a2b
    local COUNT=0
878a2b
    local UPDATEOUT=''
878a2b
    local PREDICATE=''
878a2b
    local CHNGTOTAL=0
878a2b
    local LOCATIONS=''
878a2b
878a2b
    # Define source location the subversion update action will take
878a2b
    # place on. If arguments are provided use them as srouce location.
878a2b
    # Otherwise use action value as default source location.
878a2b
    if [[ "$@" != '' ]];then
878a2b
        LOCATIONS="$@"
878a2b
    else
878a2b
        LOCATIONS="$ACTIONVAL"
878a2b
    fi
878a2b
878a2b
    # Update working copy and retrive update output.
878a2b
    cli_printMessage "`gettext "Bringing changes from the repository into the working copy"`" --as-banner-line
878a2b
    UPDATEOUT=$(svn update ${LOCATIONS})
878a2b
878a2b
    # Define path of files considered recent modifications from
878a2b
    # central repository to working copy.
878a2b
    FILES[0]=$(echo "$UPDATEOUT" | egrep "^A.+$(cli_getRepoTLDir "${LOCATIONS}").+$" | sed -r "s,^.+($(cli_getRepoTLDir "${LOCATIONS}").+)$,\1,")
878a2b
    FILES[1]=$(echo "$UPDATEOUT" | egrep "^D.+$(cli_getRepoTLDir "${LOCATIONS}").+$" | sed -r "s,^.+($(cli_getRepoTLDir "${LOCATIONS}").+)$,\1,")
878a2b
    FILES[2]=$(echo "$UPDATEOUT" | egrep "^U.+$(cli_getRepoTLDir "${LOCATIONS}").+$" | sed -r "s,^.+($(cli_getRepoTLDir "${LOCATIONS}").+)$,\1,")
878a2b
    FILES[3]=$(echo "$UPDATEOUT" | egrep "^C.+$(cli_getRepoTLDir "${LOCATIONS}").+$" | sed -r "s,^.+($(cli_getRepoTLDir "${LOCATIONS}").+)$,\1,")
878a2b
    FILES[4]=$(echo "$UPDATEOUT" | egrep "^G.+$(cli_getRepoTLDir "${LOCATIONS}").+$" | sed -r "s,^.+($(cli_getRepoTLDir "${LOCATIONS}").+)$,\1,")
878a2b
878a2b
    # Define description of files considered recent modifications from
878a2b
    # central repository to working copy.
878a2b
    INFO[0]="`gettext "Added"`"
878a2b
    INFO[1]="`gettext "Deleted"`"
878a2b
    INFO[2]="`gettext "Updated"`"
878a2b
    INFO[3]="`gettext "Conflicted"`"
878a2b
    INFO[4]="`gettext "Merged"`"
878a2b
878a2b
    while [[ $COUNT -ne ${#FILES[*]} ]];do
878a2b
878a2b
        # Define total number of files. Avoid counting empty line.
878a2b
        if [[ "${FILES[$COUNT]}" == '' ]];then
878a2b
            FILESNUM[$COUNT]=0
878a2b
        else
878a2b
            FILESNUM[$COUNT]=$(echo "${FILES[$COUNT]}" | wc -l)
878a2b
        fi
878a2b
878a2b
        # Calculate total amount of changes.
878a2b
        CHNGTOTAL=$(($CHNGTOTAL + ${FILESNUM[$COUNT]}))
878a2b
878a2b
        # Build report predicate. Use report predicate to show any
878a2b
        # information specific to the number of files found. For
878a2b
        # example, you can use this section to show warning messages,
878a2b
        # notes, and so on. By default we use the word `file' or
878a2b
        # `files' at ngettext's consideration followed by change
878a2b
        # direction.
878a2b
        PREDICATE[$COUNT]=`ngettext "file from the repository" \
878a2b
            "files from the repository" $((${FILESNUM[$COUNT]} + 1))`
878a2b
878a2b
        # Output report line.
878a2b
        cli_printMessage "${INFO[$COUNT]}: ${FILESNUM[$COUNT]} ${PREDICATE[$COUNT]}"
878a2b
878a2b
        # Increase counter.
878a2b
        COUNT=$(($COUNT + 1))
878a2b
878a2b
    done
878a2b
878a2b
}