Get the highest version number from a subversion dump file in Perl or shell

I would like to extract the highest version number in the subversion dump file. Besides parsing the file line by line, is there a simpler (and, I hope, faster) way using standard perl (without additional modules on the server) or bash shell scripts?

+4
source share
2 answers

if you created a dump file using

svnadmin dump /path/to/repo > Dump1.dump 

You can find the latest version number with this one layer:

 grep --binary-files=text "Revision-number" Dump1.dump | tail -n 1 | sed 's/Revision-number\:\ //g' 

Alternatively, to avoid grepping the entire file, use tac (cat back) and stop at the first (last) match. Eliminates the need for a tail on large grep output and saves processing time.

 tac Dump1.dump | grep -m1 --binary-files=text "Revision-number" | sed 's/Revision-number\:\ //g' 
+9
source

I can undermine this non-pun decision by simply checking the text file containing something like

 Revision-number: 720 

The grep result is as follows:

 -bash-3.2$ grep "Revision-number:" test.dump.2 Revision-number: 0 Revision-number: 1 Revision-number: 2 Revision-number: 720 

To really do it right, the dump file needs to be parsed. I wrote a perl script using the SVN :: Dumpfile module and just went in cycles in 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"; 
+3
source

Source: https://habr.com/ru/post/1347110/


All Articles