简体   繁体   中英

Commit folder changes to subversion

I have a directory whose files may or may not change every day, during an automated process. The directory contains a bunch of oracle warehouse builder mdl files which represent individual mappings. The automated oracle process creates the mdl files based on what mappings exist in an oracle module. It isn't possible to know what files the directory will contain until after the oracle process has run.

I need to commit all files in the directory to subversion after the process has populated the folder. If a file that existed yesterday has disappeared (because the oracle mapping no longer exists) then that file should be deleted from svn as well. If a new mapping was created in oracle and therefore a new file has been added to the folder, the new file should be added to svn. If a mapping has changed and the new file is therefore modified, the modification should be committed to svn.

All of this needs to happen as part of an automated process so svn command line instructions have to be used to sync the folder changes with svn.

Is there a simple svn command (or sequence of commands) that will sync a folder rather than a file with the svn repo?

Assume that we have a folders tree like this:

.
├── autocommit.sh
├── dailysnapshot/
└── workingcopy/

dailysnapshot/ stores mdl files which refresh daily. workingcopy/ is your working copy of your subversion repository Note that this script only can commit changes which 1 level under the working copy, if there is sub-folder in working copy then you need to improve the script.

Make a crontab that is scheduled as you want to call autocommit.sh

Usage:

autocommit.sh [snapshot dir] [working dir] [svn username] [svn password]

autocommit.sh source:

#!/bin/bash
SNAPSHOT=`cd $1;pwd`
WORKINGDIR=`cd $2;pwd`
USERNAME="$3"
PASSWORD="$4"

function CheckModifiedAndNew() {    
    cd $1
    for f in $(find .)
    do
    if [ -a $f ]; then
    f=${f:2}
        if [[ -n $f ]]; then
            SnapshotFile="$1/$f"
            WorkingFile="$2/$f"        
            if [[ -f $WorkingFile ]];then
                if cmp $SnapshotFile $WorkingFile &> /dev/null; then
                    # 2 files are identical
                    echo &> /dev/null "" #do nothing here
                else
                    echo "[Modified]  $WorkingFile"
                    cp -f $SnapshotFile $WorkingFile
                fi
            else
                cp -f $SnapshotFile $WorkingFile
                echo "[Added]     $WorkingFile"
                svn add $WorkingFile
            fi
        fi
    fi
    done
}

function CheckRemove() {
    cd $2
    for f in $(find .)
    do
    if [ -a $f ]; then
        f=${f:2}
        if [[ -n $f ]]; then
            SnapshotFile="$1/$f"
            WorkingFile="$2/$f"       
            if [[ -f $SnapshotFile ]];then
                echo &> /dev/null "" #do nothing here
            else
                echo "[Removed]   $WorkingFile"
                svn remove $WorkingFile
            fi
        fi
    fi
    done
}

function CommitAllChanges() {
    cd $1
    svn commit . --message="daily auto commit" --username=$USERNAME \
                                               --password=$PASSWORD \
                                               --non-interactive \
                                               --no-auth-cache                                               
}

CheckModifiedAndNew $SNAPSHOT $WORKINGDIR

CheckRemove $SNAPSHOT $WORKINGDIR

CommitAllChanges $WORKINGDIR

Customize as far as to make it fit your problem.

There is not a simple solution available. However this is a task which can be done with scripting (eg with bash).

The idea is that you have your export directory (where you export the mdl files from oracle) and your svn working copy in a different directory. Updating takes 2 steps:

  1. You iterate over all files in your svn working copy and look if they exist in the export dir. If a file exists in the export, you simple move it to your svn working dir, if not you svn delete the file in the working copy.
  2. All remaining files in the export dir are new. Move them to the svn working copy and then simply svn add them.

After this is finished you commit these changes ( svn commit ). This shold not be too hard to implement in a script.

You could try WebDav and autoversioning - ie the subversion repo exposed via a "network share". Writes and new files will be added to the repository, I'm not sure if deletes will be handled too but it wouldn't appear to be too unrealistic to expect that.

there are issues with WebDAV that you should be aware of: its a bit chatty, it won't commit all files in 1 go (as each will be written individually), but you might get adequate results from it.

An alternative is a filesystem driver that exposes the repo in much the same way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM