2

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

  • 该文件在哪个分支中的修订号高于主干的最高修订版,或者,
  • 该文件在哪些分支中具有比创建该分支的版本更高的版本。

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

4

2 回答 2

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.
于 2013-11-19T15:45:15.207 回答
1

我不确定 Tortoise 是否可行,但要使用 CLI 查找分支中的文件是否已更改,您可以将分支中的版本与主干中的版本进行比较:

svn diff --summarize BRANCH_URL TRUNK_URL

如果文件不同,您将得到如下信息:

M        svn://path/to/file

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

于 2013-11-12T21:32:12.593 回答