Thursday, December 04, 2008

Occasional Tedious Subversion Task Tip #24

In my view branching is generally the complete solution for isolating risky work.

However it does arise that the need to trim a set of revisions from  a branch or trunk is required, and while this is *possible* using TortoiseSVN, it has all the weaknesses of a manual process.

What you might need is "the backout script".

You can do as many trial runs as you like reproducibly and hand-craft the revisions to lose.

Note the following subtleties: 
  • --accept mine-full - this will reject the "incoming" reverse changes if they generate conflict in favour of your working copy
  • the format of the remove-revs.txt file is intended to match a hand-crafted edit of the output of svn log i.e. the revisions are the first token and prefixed with an r. You can even leave the author and other fields in: they're ignored.


@echo off
if (%1)==() echo need merge from URL! && exit /b 1

SET REVERT-REVS=
:: build up the revision list
FOR /F "tokens=1" %%R IN (remove-revs.txt) DO call :add-revert-rev %%R

:: now reverse merge anything out of the working copy from the file

echo revisions to be merged %REVERT-REVS% (note - prefix indicates reverse merge)

svn merge -c %REVERT-REVS% --accept mine-full %1

exit /b

:add-revert-rev

SET REV=%1
SET REV=%REV:r=%
IF NOT DEFINED REVERT-REVS (SET REVERT-REVS=-%REV%) ELSE (SET REVERT-REVS=%REVERT-REVS%,-%REV%)

goto :eof