[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Branch inheritance by convention: svnMergeChilds

From: Freddy Vulto <fvulto_at_gmail.com>
Date: 2006-11-12 11:31:20 CET

I'm looking for a solution to put configuration files of multiple hosts
under version control and so far I've come up with the solution below,
which I'd like to share.

The configuration files share some kind of inheritance: A change in the
global configuration file should be propagated to all host configuration
files. For example, consider a .bashrc configuration file running on 4
hosts on 2 domains:

(global) bashrc >> (domain) planet >> (host) saturn
(global) bashrc >> (domain) planet >> (host) pluto
(global) bashrc >> (domain) country >> (host) england
(global) bashrc >> (domain) country >> (host) spain

The "branch inheritance by convention" goes like this: Create a
repository with directories for every class (i.e. domain/host), using the
convention: each directory must be prefixed with its parent name:

(Note: You can apply this to filenames as well, naming it "File
inheritance by convention" :-)

trunk
|- bashrc
|- bashrc-planet
|- bashrc-planet.saturn
|- bashrc-planet.pluto
|- bashrc-country
|- bashrc-country.england
|- bashrc-country.spain

I've created a short shell script svnMergeChilds.sh which merges parent
changes to all childs (see end of mail or download from
http://fvue.nl/svnMergeChilds/).

Scenario 1: Merge changes in global .bashrc to all childs

Suppose you've made a modification (say revision 2) in the global .bashrc
you'd like to see propagated to all childs. Here's the command to do so
(leave out --dry-run for an actual run):

svnMergeChilds.sh -r1:2 --dry-run file:///proj/bash/repos/trunk/bashrcbashrc

Scenario 2: Merge changes in domain .bashrc to domain childs

Suppose you've made a modification (say revision 3) in the .bashrc planet
domain you'd like to see propagated to all childs of the planet domain.
Here's the command to do so (leave out --dry-run for an actual run):

svnMergeChilds.sh -r2:3 --dry-run
file:///proj/bash/repos/trunk/bashrc-planet bashrc-planet

See also: http://fvue.nl/svnMergeChilds/ (for nicer ASCII art diagrams and
a DejaGnu testsuite)

Hope this is useful,

Freddy Vulto
http://www.fvue.nl

---8<----------------------------

#!/bin/bash
#--- svnMergeChilds.sh --------------------------------------------
# Copyright (C) 2006 Freddy Vulto
# Version: 1.0.2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA
#
# The latest version of this software can be obtained here:
# http://fvue.nl/svnMergeChilds/

set -o errexit # Exit on error
set -o nounset # Trigger error when expanding unset variables

function svnMergeChilds {
        # If no arguments, or -h, or --help, show usage
    [[ $# == 0 || $1 == -h || $1 == --help ]] && {
        echo -n Merge childs: Apply the difference between
        echo two sources to multiple working copy paths
        echo Usage: $(basename $0) ... NAME_PARENT
        echo
        echo See \'svn help merge\' for ... arguments.
        echo
        echo For more information, see http://fvue.nl/svnMergeChilds/
        return $(test $# -gt 0)
    }
        # Get last parameter
    parent=${!#}
        # Unset last positional parameter
    args=( "$@" ); unset args[${#args[@]}-1]; set -- "${args[@]}"
        # Indicate non-verbose if either -q or --quiet specified
    for i; do [ "$i" = -q -o "$i" = --quiet ] && beVerbose=0; done
        # Loop through childs
    shopt -s failglob nullglob; for i in "$parent"?*; do
        (( "${beVerbose-1}" )) && echo svn merge "$@" "$i"
        svn merge "$@" "$i"
    done
} # svnMergeChilds

svnMergeChilds "$@"
Received on Sun Nov 12 11:32:11 2006

This is an archived mail posted to the Subversion Users mailing list.