稀疏svn更新深层目录结构 [英] sparse svn update of deep directory structure

查看:282
本文介绍了稀疏svn更新深层目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以对具有深层嵌套目录结构的SVN存储库进行稀疏签出.

Is there a way to have a sparse checkout of an SVN repo with deep nested directory structure.

我这样做是使用仓库中所有文件的清单并仅对* .xml进行过滤:

I'm doing this using a listing of all the files in the repo and filtering for just *.xml:

svn list --recursive "http://myRepo.com/trunk" > allFiles.txt

我正在尝试执行以下操作:

I'm trying to do the following:

svn checkout "http://myRepo.com/trunk" --depth empty "myRepo"
svn update --set-depth empty project1/dirs/moreDirs/evenMore/file.xml

我尝试了此操作,但收到一条错误消息,说它正在跳过更新该文件.

I tried this but got an error saying it was skipping updating that file.

如果我手动执行以下操作,则可以在结帐时获取该文件(我希望--set-depth为空,以获取嵌套SVN路径的父目录).

If I manually do the following I can get the file in my checkout (I want a --set-depth empty that gets the parent directories for a nested SVN path).

svn update --set-depth empty project1
svn update --set-depth empty project1/dirs/moreDirs
svn update --set-depth empty project1/dirs/moreDirs/evenMore
svn update --set-depth empty project1/dirs/moreDirs/evenMore/file.xml

svn status -v project1/dirs/moreDirs/evenMore/file.xml
# prints svn file information

编辑

我现在有2个变通办法,都不理想

I have 2 workarounds right now neither ideal

1.零食svn更新--set-depth为空

我写了一个bash函数,该函数接受要查找的文件路径,并在其上执行svn update --set-depth空.例如,对于project1/dirs/moreDirs/evenMore/file.xml,它将调用:

I wrote a bash function that takes the file path that I'm looking for a executes svn update --set-depth empty on it. For example for project1/dirs/moreDirs/evenMore/file.xml it would call:

svn update --set-depth empty updateproject1 updateproject1/dirs updateproject1/dirs/moreDirs updateproject1/dirs/moreDirs/evenMore updateproject1/dirs/moreDirs/evenMore/file.xml

它可以工作,但似乎很慢(也许我可以将多个文件的调用分批处理到一个svn更新调用中).我不能同时对多个单独的文件进行svn更新调用,因为svn会锁定存储库.

It works but seems like it's pretty slow (maybe I can batch the calls for multiple files into one svn update call). I can't make multiple svn update calls for separate files in parallel because svn locks the repo.

这是完整的脚本:

function getContentFile() 
{

    CONTENT_FILE="$1"
    SVN_FILE="${SVN_REMOTE}${CONTENT_FILE}"
    LOCAL_CONTENT_FILE="${SVN_CHECKOUT}/${CONTENT_FILE}"
    LOCAL_CONTENT_FILE_DIR=$(dirname ${LOCAL_CONTENT_FILE})

    SVN_UPDATE_ARG="${CONTENT_FILE}"
    PARENT_DIR="$(dirname ${CONTENT_FILE})"
    if [ ! -e "${LOCAL_CONTENT_FILE}" ]; then
        pushd "${SVN_CHECKOUT}"
        while [ "$PARENT_DIR" != "." ]; do
            # Escape any spaces in the argument list being passed to svn update
            PARENT_ARG=$(echo $PARENT_DIR | sed 's/ /\\ /g')
            if [ -e "${SVN_CHECKOUT}/${PARENT_DIR}" ]; then
                # Stop if we detect a directory already controlled by SVN
                break
            fi
            SVN_UPDATE_ARG="$PARENT_ARG $SVN_UPDATE_ARG"
            PARENT_DIR="$(dirname ${PARENT_DIR})" || true
        done
        svn update --set-depth empty ${SVN_UPDATE_ARG}
    fi
}
# export function to use in xargs
export -f getContentFile

cat "$SVN_FILE_LISTING_CACHE" | egrep '\.xml$' | xargs -P 1 -n 1 -I{} bash -e -c 'getContentFile "$@"' _ {}

2. svn cat获取文件

我也可以只为文件夹结构创建路径,然后用svn cat该文件,并且可以同时在多个文件上执行此操作,但这会导致无法连接到svn(例如,我无法将其提交回来)轻松地进行更新或从svn更新文件而无需遍历和匹配路径),这不是真正的svn结帐.

I can also just create the path for the folder structure and svn cat the file and I can do it on multiple files at the same time, but this suffers from not being connected to svn (e.g. I can't commit it back easily or update the file from svn without walking and matching the path), it's not a real svn checkout.

function getAllContentFiles() 
{
    FILE_REGEX="$1"
    #NUM_PROCESSORS=`sysctl hw.ncpu | awk '{print $2}'`
    # Do this in parallel (doesn't have to match number of actual processors)
    NUM_PROCESSORS=50
    #TODO: need to do it 1 at a time because of SVN lock for svn updates
    cat "$SVN_FILE_LISTING_CACHE" | egrep $FILE_REGEX | xargs -P ${NUM_PROCESSORS} -n 1 -I{} bash -ex -c 'getContentFile "$@"' _ {}
}

function getContentFile() 
{

    CONTENT_FILE="$1"
    SVN_FILE="${SVN_REMOTE}${CONTENT_FILE}"
    LOCAL_CONTENT_FILE="${SVN_CHECKOUT}/${CONTENT_FILE}"
    LOCAL_CONTENT_FILE_DIR=$(dirname ${LOCAL_CONTENT_FILE})

    SVN_UPDATE_ARG="${CONTENT_FILE}"
    PARENT_DIR="$(dirname ${CONTENT_FILE})"
    mkdir -p "${PARENT_DIR}"

    if [ ! -e "${LOCAL_CONTENT_FILE}" ]; then
        pushd "${SVN_CHECKOUT}"
        svn cat "${SVN_FILE}" > "${LOCAL_CONTENT_FILE}"
    fi
}

推荐答案

自Subversion 1.7.0起,update接受了--parents选项,该选项可以实现您想要的功能.

Since Subversion 1.7.0 update has accepted a --parents option that does what you want.

因此,您可以执行以下操作:

So you can do the following for example:

$ svn co --depth empty https://svn.apache.org/repos/asf/subversion svn-sparse
 U   svn-sparse
Checked out revision 1544721.

$ svn up --parents trunk/subversion/libsvn_ra_svn/protocol
A    trunk
A    trunk/subversion
A    trunk/subversion/libsvn_ra_svn
Updating 'trunk/subversion/libsvn_ra_svn/protocol':
A    trunk/subversion/libsvn_ra_svn/protocol
Updated to revision 1544721.

这篇关于稀疏svn更新深层目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆