I would like to extract the highest revision number in a subversion dump file. Besides parsing the file line by line, is there any easier (and hopefully faster) way using standard perl (no extra modules allowed on the server) or bash shell scripting?
Asked
Active
Viewed 3,456 times
4
-
bah, I found it myself, so for everyone who has the same problem: `cat Dump1.dump | grep "Revision-number" | tail -n 1 | sed 's/Revision-number\:\ //g'` – Volker Apr 07 '11 at 14:13
-
2so write it as the solution and cash in! :) – Axeman Apr 07 '11 at 15:18
-
maybe you should answer yourself? – Lenik Apr 09 '11 at 10:08
2 Answers
12
if you created a dump file using
svnadmin dump /path/to/repo > Dump1.dump
The you can find the last revision number with this one-liner:
grep --binary-files=text "Revision-number" Dump1.dump | tail -n 1 | sed 's/Revision-number\:\ //g'
Alternately to avoid grepping the entire file, use tac (cat backwards) and stop on the first (last) match. Eliminates the need for tail on the large output of grep, and saves processing time.
tac Dump1.dump | grep -m1 --binary-files=text "Revision-number" | sed 's/Revision-number\:\ //g'
-
Many dump files will be considered binary by grep and will not attempt to match. grep "Revision-number" /svnrepos/reponame/20130408.dump Binary file /svnrepos/reponame/20130408.dump matches So I will edit your answer to force textual matching anyway – Eddie Apr 08 '13 at 20:16
3
I can subvert this solution, no pun intended, by simply checking in a text file that contains something like
Revision-number: 720
The output of the grep looks like this:
-bash-3.2$ grep "Revision-number:" test.dump.2
Revision-number: 0
Revision-number: 1
Revision-number: 2
Revision-number: 720
To really do this properly the dump file needs to be parsed. I wrote a perl script using the SVN::Dumpfile module and just looped through the revisions until I got to the end.
#!/usr/bin/perl
use SVN::Dumpfile;
use strict;
my $df = new SVN::Dumpfile;
$df->open('/usr/tmp/test.dump.2');
my $revision=-1;
while (my $node = $df->read_node()) {
if ($node->is_rev) {
$revision = $node->header('Revision-number');
}
}
print "$revision\n";

David Newman
- 31
- 1