查找正在修改文件的分支

时间:2013-11-12 14:13:35

标签: svn search branch

我正在寻找一种在SVN中进行非常具体搜索的方法。有没有办法找到哪个分支改变了一个文件?
想象一下,我提供了文件名,工具告诉我:

  • 该文件具有更高版本号的分支,然后是主干的最高版本,或
  • 该文件具有更高版本的分支,然后是创建分支的分支。

理想情况下,这将在TortoiseSVN中实现,但任何(免费)解决方案都是受欢迎的。当然包括脚本/程序的想法。

2 个答案:

答案 0 :(得分:1)

我不确定Tortoise是否可以这样做,但是要查找是否使用CLI在分支中更改了文件,您可以使用来自trunk的版本从分支中区分版本:

svn diff --summarize BRANCH_URL TRUNK_URL

如果文件不同,您将得到以下内容:

M        svn://path/to/file

如果文件相同,则不会输出。您可以编写一个脚本来为要检查的每个分支运行此命令。

答案 1 :(得分:1)

这是一个批处理脚本,可以使用Subversion CLI实现您的目标。您只需提供存储库的根URL(SVN_ROOT)和您感兴趣的文件的子路径(TARGET_FILE)。

@ECHO OFF
SetLocal EnableDelayedExpansion

SET SVN_ROOT=http://mysvn.myhost.com/svn/myrepo/myproject
SET TARGET_FILE=src/main/java/example/SomeClass.java

FOR /F "tokens=1" %%I IN ('svn ls -v "%SVN_ROOT%/trunk/%TARGET_FILE%"') DO (
    SET TRUNK_FILE_VERSION=%%I
)

IF "%TRUNK_FILE_VERSION%" == "" (
    ECHO Trunk does not contain target file %TARGET_FILE%
    EXIT 1
)

ECHO Trunk has target file at revision %TRUNK_FILE_VERSION%.

FOR /F "tokens=1" %%I IN ('svn ls "%SVN_ROOT%/branches"') DO (
    REM see which branches contain target file
    svn ls -v "%SVN_ROOT%/branches/%%I%TARGET_FILE%" >nul 2>&1
    IF !ERRORLEVEL! EQU 0 (
        REM get version of target file in branch
        FOR /F "tokens=1" %%J IN ('svn ls -v %SVN_ROOT%/branches/%%I%TARGET_FILE%') DO (
            SET BRANCH_FILE_VERSION=%%J
        )
        IF !TRUNK_FILE_VERSION! LSS !BRANCH_FILE_VERSION! (
            ECHO Branch %%I has newer version !BRANCH_FILE_VERSION! of target file.
        )
        REM get creation version of branch itself
        FOR /F "tokens=1" %%J IN ('svn log -q --stop-on-copy --limit 1 -r0:HEAD "%SVN_ROOT%/branches/%%I" ^| FINDSTR /V \-\-\-\-') DO (
            SET BRANCH_VERSION=%%J
            SET BRANCH_VERSION=!BRANCH_VERSION:~1!
        )
        IF !BRANCH_VERSION! LSS !BRANCH_FILE_VERSION! (
            ECHO Branch %%I has a modified version !BRANCH_FILE_VERSION! of target file - branch created at revision !BRANCH_VERSION!
        )
    )

)
ECHO All branches checked.

以下是脚本的一些示例输出:

Trunk has target file at revision 72199.
Branch 2.1-SNAPSHOT/ has a modified version 22824 of target file - branch created at revision 20868
Branch 2.2-SNAPSHOT/ has a modified version 24717 of target file - branch created at revision 24361
Branch 2.6-SNAPSHOT/ has a modified version 43942 of target file - branch created at revision 40381
Branch 2.7-SNAPSHOT/ has a modified version 53012 of target file - branch created at revision 48111
Branch 2.8.1-SNAPSHOT/ has a modified version 62083 of target file - branch created at revision 55875
Branch 2.8.5-SNAPSHOT/ has a modified version 70542 of target file - branch created at revision 69681
Branch 2.9.0-SNAPSHOT/ has newer version 72543 of target file.
Branch 2.9.0-SNAPSHOT/ has a modified version 72543 of target file - branch created at revision 72312
All branches checked.