将文件夹更改提交到 subversion

发布于 2024-10-24 21:01:34 字数 440 浏览 2 评论 0原文

我有一个目录,在自动化过程中,其文件每天可能会或可能不会更改。该目录包含一堆 oracle 仓库构建器 mdl 文件,它们代表单独的映射。自动 oracle 进程根据 oracle 模块中存在的映射创建 mdl 文件。在 oracle 进程运行之前,不可能知道该目录将包含哪些文件。

在进程填充文件夹后,我需要将目录中的所有文件提交到 subversion。如果昨天存在的文件已经消失(因为 oracle 映射不再存在),那么该文件也应该从 svn 中删除。如果在 oracle 中创建了新映射,并因此将新文件添加到该文件夹​​,则应将新文件添加到 svn。如果映射已更改并且因此修改了新文件,则应将修改提交给 svn。

所有这些都需要作为自动化过程的一部分发生,因此必须使用 svn 命令行指令将文件夹更改与 svn 同步。

是否有一个简单的 svn 命令(或命令序列)可以将文件夹而不是文件与 svn 存储库同步?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

所谓喜欢 2024-10-31 21:01:34

假设我们有一个像这样的文件夹树:

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

dailysnapshot/ 存储每天刷新的 mdl 文件。
workingcopy/ 是你的 Subversion 存储库的工作副本
请注意,此脚本只能提交工作副本下一级的更改,如果工作副本中有子文件夹,则需要改进脚本。

创建一个按照您想要调用 autocommit.sh 进行调度的 crontab

用法:

autocommit.sh [快照目录] [工作目录] [svn 用户名] [svn 密码]

autocommit.sh 源:

#!/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

自定义以使其适合您的问题。

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.

初与友歌 2024-10-31 21:01:34

没有一个简单的解决方案可用。然而,这是一个可以通过脚本来完成的任务(例如使用 bash)。

这个想法是,您将导出目录(从 oracle 导出 mdl 文件的位置)和 svn 工作副本放在不同目录中。更新需要 2 个步骤:

  1. 迭代 svn 工作副本中的所有文件并查看它们是否存在于导出目录中。如果导出中存在文件,您只需将其移动到您的 svn 工作目录,如果不存在,您svn 删除工作副本中的文件。
  2. 导出目录中的所有剩余文件都是新的。将它们移动到 svn 工作副本,然后简单地 svn add 它们。

完成后,您提交这些更改(svn commit)。在脚本中实现这一点应该不会太难。

There is not a simple solution available. However this is a task which can be done with scripting (e.g. 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.

难理解 2024-10-31 21:01:34

您可以尝试 WebDav 和 autoversioning - 即通过暴露的 subversion 存储库“网络共享”。写入和新文件将被添加到存储库中,我不确定是否也会处理删除,但期望这一点似乎不太不切实际。

您应该注意 WebDAV 的一些问题:它有点啰嗦,它不会一次性提交所有文件(因为每个文件都会单独写入),但您可能会从中获得足够的结果。

另一种选择是文件系统驱动程序,它以几乎相同的方式公开存储库。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文