Reputation: 300
I'm looking for a way to make a very specific search in SVN. Is there a way to find which branches changed a single file?
Imagine that I supply the file name, and the tool tells me:
Ideally this would be achieved in TortoiseSVN, but any (free) solution is welcome. Including of course ideas for scripts/programs.
Upvotes: 2
Views: 114
Reputation: 10500
Here's a batch script to achieve what you want using the Subversion CLI. You just have to provide the repository's root URL (SVN_ROOT
) and the sub-path to the file you're interested in (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.
Here is some example output of the script:
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.
Upvotes: 1
Reputation: 24063
I'm not sure if this is possible with Tortoise, but to find if a file has been changed in a branch using the CLI, you can diff the version from the branch with the version from trunk:
svn diff --summarize BRANCH_URL TRUNK_URL
If the files are different you will get something like this:
M svn://path/to/file
If the files are the same, there will be no output. You could write a script to run this command for each branch you want to check.
Upvotes: 1