SVN Getting all revisions of a file

6

3

I have a moderate size repository (around 2500 versions) from a project I've been running in the past 3 years. There is a particular file (let's call it foo.xml) there which I now want to analyse its evolution. Ideally, what I'm looking for, is to export into a directory every versions that file had, appended with the date, e.g.

2007_08_08_foo.xml
2007_08_09_foo.xml
2007_08_15_foo.xml
...

What is the quickest way of achieving this?

Hugo Sereno Ferreira

Posted 2010-07-05T03:10:46.960

Reputation: 203

While this is not a direct answer to your question, you might want to use 'svn annotate filename'. That is a good way to study evolution. – vtest – 2010-07-05T10:09:49.077

Answers

4

I don't think SVN has that functionality built in, but if you are able to run commands on the server that holds the SVN repository (and assuming the server has the standard UNIX/Linux tools available), this bash script should do it for you:

REPOS=/path/to/repos
FILE=dir/foo.xml
for rev in "$(svnlook history $REPOS $FILE | awk 'NR > 2 { print $1 }')"; do
    rev_date=$(svnlook date -r $rev $REPOS | awk '{ print $1 }')
    svnlook cat -r $rev $REPOS $FILE > ${rev_date}_${FILE}
done

This will produce filenames of the form 2007-08-08_foo.xml. Of course, you have to change /path/to/repos in the first line to the actual filesystem path (not a URL) of the repository, and dir/foo.xml in the second line to the path of the file within the repository.

If it's really important to you to have underscores in the date, change line 4 as follows:

    rev_date=$(svnlook date -r $rev $REPOS | awk '{ print $1 }' | tr - _)

Also keep in mind that if the file was ever modified more than once on a given day, only the first edit on each day will actually be reflected in the written files.

David Z

Posted 2010-07-05T03:10:46.960

Reputation: 5 688

2

My coworker wrote this shell script for a similar purpose:

#!/bin/bash
for rev in `svn log $1 | grep ^r[0-9] | cut -c 2- | cut -d ' ' -f 1`; do
    svn log -r $rev
    svn diff -r $[$rev-1]:$rev $1 2>/dev/null || svn cat -r $rev $1
done

You don't need server access to run it; run it in a directory where you have that file checked out and pass a filename as the argument. You may want to modify the loop body to write full files instead of printing diffs to stdout:

do
    svn cat -r $rev $1 > $1.$rev
done

Marius Gedminas

Posted 2010-07-05T03:10:46.960

Reputation: 1 770

Extracting dates for each revision and putting them into the filename is left as an excercise for the reader. – Marius Gedminas – 2010-07-11T13:44:57.473

1

I was having trouble with one of the scripts in this answer, it did not appear to work whenever there was a space in a filename. I am no master at bash scripting, but this is a quick solution.

#!/bin/bash
echo "svn log \"$1\" | grep ^r[0-9] | cut -c 2- | cut -d ' ' -f 1"
for rev in `svn log "$1" | grep ^r[0-9] | cut -c 2- | cut -d ' ' -f 1`; do
    svn log -r $rev
    #svn diff -r $[$rev-1]:$rev $1 2>/dev/null || svn cat -r $rev $1
    `svn cat -r $rev "$1" > "$rev.$1"`
done

David Williams

Posted 2010-07-05T03:10:46.960

Reputation: 11

0

This might be of help if you are on Windows. The filename should be a parameter to the script. Make that your own.

=== Get-SvnFileHistory.ps1

$Filename = "C:\path\to\workingcopy\file\thefile.txt"

& svn log "$Filename" |
    Select-String -pattern '^r(\d+) ' |
    ForEach-Object {
        if ($_ -match '^r(\d+).*') {
            & svn ls -v -r $Matches[1] "$Filename"
        }
    }

Either run it from a PowerShell console prompt or from a cmd.exe prompt using:

powershell -NoLogo -NoProfile -File "C:\path\to\script\Get-SvnFileHistory.ps1

lit

Posted 2010-07-05T03:10:46.960

Reputation: 515