justinmassiot
12/4/2019 - 2:55 PM

Generate Excel file from SVN log

Exports SVN logs to an XML file, then opens the data into an Excel sheet

@echo off


REM You can modify the following parameters

REM Path to the SVN command line executable
REM Example: "svn=svn.exe" (if it's in your system path), or perhaps "svn=C:\Program Files\TortoiseSVN\bin\svn.exe"
REM Note that this file can be located elsewhere on your own computer, depending on your installation.
set svn=svn.exe

REM user_prompt = 0 => use "repo_url" as the SVN URL
REM user_prompt = 1 => prompt the user for the SVN URL
set user_prompt=1

REM Set the SVN repository URL (not used if user_prompt = 1)
set repo_url="svn+ssh://my_server_url/my_repo_path"

REM Set output file name
set filename="logs.xml"

REM rev_sort = 0 => show revision with the oldest first (chronological order)
REM rev_sort = 1 => show revision with the newest first (anti-chronological order)
set rev_sort=1

REM Set the start revision (2 is the default value, because the 1st revision is generally the folder tree creation)
set start_revision=2
REM Set the end revision (HEAD is the default value)
set end_revision=HEAD


REM ========================================
REM Do NOT modify under this line! (unless you're absolutely sure of what you're doing)

REM Set the window title
title Generate SVN logs

REM Skip the "user prompt" section if user_prompt = 0
if %user_prompt% equ 0 ( goto svnlog )

:prompt
REM Clear the SVN repo URL and prompt the user for the SVN repository URL to work on.
set repo_url=
echo Enter the URL of the repository from which to extract the logs.
echo Example: svn+ssh://my_server_url/my_repo_path
set /p repo_url="URL="

:svnlog
REM Set the order of the log to be retrieved
set revisions="%start_revision%:%end_revision%"
if %rev_sort% equ 1 ( set revisions="%end_revision%:%start_revision%" )
REM Execute SVN command to get all the commit logs from the defined repository. "svn.exe" must be in the path!
if not defined repo_url ( goto error )
"%svn%" log --xml --revision %revisions% %repo_url% > %filename%
if errorlevel 1 ( goto error )

:excel
REM Launch the generated file in Excel in "embedded" mode, with Current Directory as the start folder.
start /b /d "%cd%" excel /e /p "%cd%" %filename%
goto eof

:error
echo.
echo Either your SVN executable is not reachable (check the SVN path: %svn%), or your SVN remote repository is invalid or unavailable.
echo Export of logs is aborted.
echo.
pause

:eof