Showing posts with label svn. Show all posts
Showing posts with label svn. Show all posts

Thursday, August 8, 2013

Svn file full history

If you’d need to search in the full history of a file stored in SVN, the script below can make an export of all changes ever applied into a file, starting for the first revision (full file) and adding each time an overview of all changes applied.

If you remember you ever applied some changes in a file, but removed it afterwards, this can help to search in the full history. Only tested on text based files.

For each revision, the revision number, author, timestamp and svn comments will be listed, followed by an overview of the removed lines, added lines, update lines etc. The initial revision will be a full extract of the original file.

Usage: save the SvnFileFullHistory.bat script in an SVN folder next to the file for which you’d need a full history extract. Drop the svn file onto the bat script to start the script and retrieve the full history of the dropped svn file. The full svn file history will be saved in a txt file in the same folder and with the same base name as the file to extract, but adding “-FullSvnHistory.txt” behind the file name. The extract can take a while, depending on the number of revisions and the size of the svn file. But while the extract is ongoing, the “…-FullSvnHistory.txt” can be read already, reloading it to get future updates.

A similar linux shell script has been created as well (not fully tested).

Based on information found on stackoverflow by user ladenedge.

Full script content:

@echo off   
TITLE SVN - Full file history
REM Original source: http://stackoverflow.com/questions/282802/how-can-i-view-all-historical-changes-to-a-file-in-svn and http://stackoverflow.com/questions/5622367/generate-history-of-changes-on-a-file-in-svn/5721533#5721533
echo Copy this bat script next to the checked out svn file on which to get full svn history. Drag and drop the svn file onto the bat script to start fetching the info (or a open command window and provide the name of the svn file as first parameter to the bat script execution)
if "%1%"=="" pause
set file=%1
set report=%file%-FullSvnHistory.txt
if [%file%] == [] (
  echo Usage: "%0 <file>"
  exit /b
)
echo Retrieving svn history of file, please wait...
echo The report will be saved in the file: %report%.
echo To stop the process press Ctrl+c.
rem first revision as full text
for /F "tokens=1 delims=-r " %%R in ('"svn log -q %file%"') do (
  svn log -r %%R %file% > %report%
  svn cat -r %%R %file% >> %report%
  goto :diffs
)
:diffs
rem remaining revisions as differences to previous revision
for /F "skip=2 tokens=1 delims=-r " %%R in ('"svn log -q %file%"') do (
  echo.
  svn log -r %%R %file% >> %report%
  svn diff -c %%R %file% >> %report%
)

Wednesday, November 24, 2010

InstantRails + Redmine

I just discovered Redmine, and it looks quite promising to me as a project development tracking system.

InstantRails

Since I’m a big fan of portable applications, I tried to play with Redmine using InstantRails, but had some trouble getting it to run, since InstantRails uses some old versions of some required gems. So after upgrading gems to 1.3.7 and rack to 1.0.1 and finding some old version of the MySQL lib libmysql.dll v5.0 I got it all working nicely locally and portable. If anyone would like to play with it: download InstantRails 2.0 + Redmine 1.1.1 (42MB). I removed some parts of the gems documentation files to make it smaller.

The InstantRails package contains MySQL, Apache, Ruby and Rails. To use it, just run ‘InstantRails.exe’, the Apache and MySQL servers will automatically be launched.

 InstantRails

During startup, InstantRails may request to regenerate the configuration because of a folder location change. Just press ‘Yes’. If Apache doesn’t start automatically, make sure the ‘apache\logs’ folder exists.

Next click on the ‘i’ button, in the menu chose ‘Rails Applications’ –> ‘Manage Rails Applications’, select ‘Redmine’ push the button ‘Start with Mongrel’.

ManageRailsApplications

StartMongrel

A command window will open up and when it’s loaded you can navigate to http://localhost:3003 and start using your own personal portable Redmine. (default login: admin, password: admin). To manage the database, phpMyAdmin is included as well, just navigate to http://localhost/mysql.

If you don’t care to have it portable, you could as well install Ruby on Rails and Redmine using this 1 minute guide.

Plugins

Redmine 2 is included, but I added the following plugins I found interesting as well:

  • Codereview: code review comments can be added in repository within Redmine. It has a project tab with an overview of the code review comments as well
  • Hudson: project tab for Hudson administration
  • Issue due date: automatically set issue due date to the version due date
  • Timesheet: create a timesheet with overview of tracked timings
  • Time Tracker: easily track timings while working on issues
  • Wiki notes: extra wiki options, example created
  • Wiki tabs: possibility to add a project tab linked to wiki page, not configured yet
  • Tab: custom project tab configuration, configured to get the Sonar project information page

Demo

Within Redmine I configured roles, issues states, permissions and a workflow. I set up different users, projects and issues to be able to play with different configuration settings. Each user is configured to use the same password as the username: admin, teamleader, developer, etc. (see administration console). It is very easy to configure which role can perform what tasks and see specific content within Redmine.

Administration

Creation and management of issues is straightforward. It has a good integration of time tracking, at every update of an issue, the user can immediately update the time tracks.

UpdateIssue

With the time tracker plugin, it is even easier to track your timings. With an issues selected, you can easily let Redmine keep track of the time you spend on that issue by using the start/stop links at the top.

TimeTracker

Reporting

An important part of an issue tracking system is the reporting capabilities.

A summary with the number of issue in open or closed state can be seen:

Summary

In the list of issues, filters can quickly be added and columns can be chosen:

IssuesFilter

In the roadmap overview, all versions / planned version of the project are listed with an overview of their related issues:

Roadmap

The activity overview shows the activities performed within a project.

Activity

The spent time within a project can be viewed in an overview:

SpentTime

But custom reports can be created on the fly as well:

SpentTimeCustomReport

SpentTimeCustomReportFilters

With the Timesheet plugin, an overview of all projects, all users, etc. of the spent time can be generated easily on the fly:

Timesheet

Integration

Specific plugins exist to integrate the Redmine issue lists with TortoiseSVN and TortoiseGIT: Tortoise Redmine Plugin.

For full integration, follow this manual for the BugTraq properties configuration.

TortoiseIntegration

Points of improvement

One thing I noticed during my tests: if an issues is updated and a user changes the state of the issue, he still can select any user to assign it to. In my opinion, only users able to make changes on the selected target state of the issue, should appear in the list of users to assign the issue to. An issue tracking system should enforce all constraints of the workflow to make sure an issue can’t come in an invalid workflow state (eg. assigned user can not change the status). But this problem occurs on most tracking systems I checked (Track+, Jira, etc.). See this feature request, I checked the plugin development, but so far I couldn’t make it work myself yet.

Update 31/01/2011: InstantRedmine package updated to Redmin 1.1.1

Sunday, April 19, 2009

SVN Automated repeated backup / dump – Windows / Linux

Every project using SVN should have an automated backup system in place for their SVN repository. We decided we wanted a weekly incremental backup. But we also wanted to easily create a new initial backup. I scripted it on Windows and Linux with the Shell/Batch scripts shown below.

For both scripts, the same methods is used: we keep track of the last backed up revision in a file called svn_backup_delta.txt. Every time the script is started, an incremental dump is exported and archived, starting from the last dumped revision till the latest available revision. If the latest revision is the same as the last dumped revision, nothing will happen.

If the svn_backup_delta.txt doesn’t exist or the revision could not be read correctly, a complete initial dump from revision 0 till the latest revision will be exported and archived. The scripts are called daily or weekly with a standard OS scheduler. When we want to have a new initial complete dump, we simply remove the svn_backup_delta.txt file.

The scripts can be a good starting point to create your own automated SVN dumping mechanism.

Windows backup_svn.bat Batch script. This script now expects the svn.exe and svnrdump.exe to be in the same folder as the script. It also requires a repos.txt and backup.properties files in the same folder. The output of the script will be stored in the same folder within the file backup_svn.log.

@echo off 
  TITLE %~n0 - see log %~n0.log 
  echo All details will be logged into %~n0.log 
  CALL :STARTBATCH >> %~dp0%~n0.log 2>&1 
  GOTO :EOF

:STARTBATCH     REM All properties are set in backup.properties     REM Variables that change in a for loop, should be marked with !VARIABLE! instead of %VARIABLE%     REM Necessary to use this, otherwise SET !VARIABLE! in for loop fails     setlocal enabledelayedexpansion     ::CONFIGURATION     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% CHECKING FOR CHANGES AT %DATE%: %TIME%     REM Get properties from backup.properties and set as variables     FOR /F "tokens=1,2 delims==" %%A IN (%~dp0backup.properties) DO (     echo %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% %%A: %%B     set %%A=%%B     ) 
  :END_CONFIGURATION

REM Loop through all repos 
  for /f "delims=," %%r in (%~dp0repos.txt) DO ( 
  echo. 
  ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Starting SVN backup 
  ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Using following configuration: 
  SET REPO_URL=%REPO_BASE%/%%r 
  ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% -Repository URL: "%REPO_BASE%/%%r" 
  SET LAST_DELTA_FILE=%DUMP_BASE%\%%r\svn_backup_delta_%%r.txt 
  ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% -File to keep track of last revision backed up: !LAST_DELTA_FILE! 
  SET DUMP_FILE=%DUMP_BASE%\%%r 
  SET Today=%Date: =0% 
  SET Today=!Today:~-4!%Date:~-7,2%%Date:~-10,2% 
  SET Now=%Time: =0% 
  FOR /F "tokens=1,2 delims=:.," %%A IN ("!Now!") DO SET Now=%%A%%B

IF NOT EXIST "!DUMP_FILE!" mkdir "!DUMP_FILE!" 
  %~dp0svn --username %SVN_USERNAME% --password %SVN_PASS% --non-interactive --trust-server-cert --no-auth-cache info !REPO_URL! > %TEMP%\repoinfo.tmp

SET LAST_REV= 
  for /f "usebackq tokens=1,2 delims=: " %%i in (`find "Revision: " "%TEMP%\repoinfo.tmp"`) do (     SET LAST_REV=%%j     )     REM Check if !LAST_REV! retrieved of SVN is a number. If not, exit script.     echo !LAST_REV!| findstr /r "^[0-9]*$">nul || ( ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% ERROR: Last revision number is !LAST_REV! of %%r doesn't seem to be valid, aborting.     GOTO :END )     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Last revision: !LAST_REV!     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Last delta file: !LAST_DELTA_FILE!     REM Check if full backup exists, if true, do an incremental backup     IF NOT EXIST !LAST_DELTA_FILE! (         ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Not delta file found, processing full export         call :FULL     ) ELSE (         ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Delta found, processing delta         call :DELTA     ) 
  ) 
  ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% All repo's done, backup finalized 
  GOTO :END

REM Do an incremental backup 
  :DELTA     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% DELTA     SET LAST_DELTA=     for /f "usebackq tokens=1,2 delims=: " %%i in (`find "Revision: " "!LAST_DELTA_FILE!"`) do (         SET LAST_DELTA=%%j     )     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Last delta:!LAST_DELTA!     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Last revision:!LAST_REV!     IF "!LAST_DELTA!"=="" GOTO FULL     IF "!LAST_REV!"=="" GOTO :END     IF "!LAST_DELTA!"=="!LAST_REV!" GOTO :END     REM Check if !LAST_DELTA! is a number. If not, exit script.         echo !LAST_DELTA!| findstr /r "^[1-9][0-9]*$">nul || ( ECHO ERROR: DELTA REVISION NUMBER IN !LAST_DELTA_FILE! OF %REPO_URL% DOESN'T SEEM TO BE A NUMBER... ABORTING BACKUP...     GOTO :END )     SET /A INCRE_LAST_DELTA=LAST_DELTA+1     SET DUMP_FILE_NAME=!Today!-!Now!-INCREMENTAL-R!INCRE_LAST_DELTA!-TO-R!LAST_REV!.dump     SET DUMP_FILE=!DUMP_FILE!\!DUMP_FILE_NAME!     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Creating dump file name: !DUMP_FILE_NAME!, !DUMP_FILE!     %~dp0svnrdump --username %SVN_USERNAME% --password %SVN_PASS% --non-interactive --trust-server-cert --no-auth-cache dump !REPO_URL! -r !INCRE_LAST_DELTA!:!LAST_REV! --incremental > !DUMP_FILE!     echo %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% %~dp0%ZIP% a -tzip  !DUMP_FILE!.zip !DUMP_FILE! -v%MAX_SIZE%     call %~dp0%ZIP% a -tzip  !DUMP_FILE!.zip !DUMP_FILE! -v%MAX_SIZE%     IF EXIST !DUMP_FILE!.zip DEL /F !DUMP_FILE!     IF EXIST !DUMP_FILE!.zip.* DEL /F !DUMP_FILE!     ECHO Revision: !LAST_REV! > !LAST_DELTA_FILE!     IF EXIST "!LAST_DELTA_FILE!" GOTO DELTA     GOTO :END

REM Do a full backup 
  :FULL     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% FULL     ECHO FULL > !LAST_DELTA_FILE!     SET DUMP_FILE_NAME=!Today!-!Now!-INITIAL-R!LAST_REV!.dump     SET DUMP_FILE=!DUMP_FILE!\!DUMP_FILE_NAME!     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Dump file name: !DUMP_FILE_NAME!     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% Dump file: !DUMP_FILE!     %~dp0svnrdump --username %SVN_USERNAME% --password %SVN_PASS% --non-interactive --trust-server-cert --no-auth-cache dump !REPO_URL! -r 0:!LAST_REV! > !DUMP_FILE!     echo %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% %~dp0%ZIP% a -tzip !DUMP_FILE!.zip !DUMP_FILE! -v%MAX_SIZE%     call %~dp0%ZIP% a -tzip !DUMP_FILE!.zip !DUMP_FILE! -v%MAX_SIZE%     IF EXIST !DUMP_FILE!.zip DEL /F !DUMP_FILE!     IF EXIST !DUMP_FILE!.zip.* DEL /F !DUMP_FILE!     ECHO Revision: !LAST_REV! > !LAST_DELTA_FILE!     IF EXIST "!LAST_DELTA_FILE!" GOTO DELTA     GOTO :END

:END     ECHO %Date:~-4%%Date:~-7,2%%Date:~-10,2%-%Time% END     GOTO :EOF


Linux svnbackup.sh Shell script:



#!/bin/sh
#SETUP
REPO_URL=https://url:8443/base/project
REPO_PATH=c:/repository/project
DUMP_DIR=/home/user/dumps
LAST_DELTA_FILE=svn_backup_delta.txt
#BEGINING OF THE SCRIPT ITSELF
date=$(date +%Y%m%d)
LOG=dump-$date.log
LAST_REV=$(svn info $REPO_URL |grep Revision |gawk ' { print $2}')
#Both files MUST exist, otherwise, wer'e going to init new "delting"
if [ -e $LAST_DELTA_FILE ] ; then
LAST_DELTA=$(cat $LAST_DELTA_FILE)
if [ $LAST_DELTA -ne $LAST_REV ] ; then
DUMP_FILE_NAME=$date-INCREMENTAL-R$((LAST_DELTA+1))-TO-R$LAST_REV.dump.gz
DUMP_FILE=$DUMP_DIR/$DUMP_FILE_NAME
svnadmin dump $REPO_PATH -r $((LAST_DELTA +1)):$LAST_REV --incremental --deltas 2>>$LOG |gzip -c > $DUMP_FILE
else
echo nothing to do : last revision number is same as last delta number, run it again later !
exit 0
fi
else
DUMP_FILE_NAME=$date-INITIAL-R$LAST_REV.dump.gz
DUMP_FILE=$DUMP_DIR/$DUMP_FILE_NAME
svnadmin dump $REPO_PATH 2>>$LOG | gzip -c > $DUMP_FILE
fi
#Is all ok ?
if [ $? -eq 0 ] ; then
echo -n $LAST_REV > $LAST_DELTA_FILE
else
echo "ERROR :" $date "Problem occured while saving dump" >>$LOG
fi

Update 02/07/2010: Script tested and working in Windows 7 (in combination with Visual SVN server). Make sure to add the bin folder of Visual SVN server to your 'path' system variable to make the 'svn' command available system wide. Run the script with right-click 'Run as administrator'.

 

Update 27/06/2016 on Windows script to use a backup_properties.txt, repo.txt files and validate the retrieved revision and delta numbers before executing the windows backup