Skip to content

Instantly share code, notes, and snippets.

@niratama
Created October 30, 2012 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niratama/3978336 to your computer and use it in GitHub Desktop.
Save niratama/3978336 to your computer and use it in GitHub Desktop.
svnadmin dumpしたものが日本語ファイル名が原因で戻せないときの対策ツール
#!env perl
# vi:ts=4:sw=4
use 5.010;
use strict;
use SVN::Dump;
use Data::Dumper;
my ($infile, $outfile) = @ARGV;
unless ($infile && $outfile) {
say "$0 infile outfile";
exit(1);
}
my $dump = SVN::Dump->new( { file => $infile } );
open my $fh, '>', $outfile || die $@;
my @records;
sub flush_records {
my @r;
push @r, grep { !defined($_->{path}) } @records;
push @r, sort { $a->{path} cmp $b->{path} || $a->{file} cmp $b->{file} } grep { defined($_->{path}) } @records;
say '-sorted-';
say join("\n", map { $_->{path} . ' ' . $_->{file} } @r);
say '--------';
my $str = join('', map { $_->{obj}->as_string } @r);
@records = ();
return $str;
}
while (my $record = $dump->next_record) {
my $sort_path;
my $file;
if ($record->type eq 'revision') {
print $fh &flush_records();
say 'r', $record->get_header('Revision-number');
print $fh $record->as_string;
next;
} elsif ($record->type ne 'node') {
print $record->type;
} else {
my $path = $record->get_header('Node-path');
my $kind = $record->get_header('Node-kind') // '';
my $action = $record->get_header('Node-action');
$path =~ m|((?<dir>.*)/)?(?<file>.*)|;
my $dir = $+{dir} // '';
$file = $+{file} // '';
my @parts = grep { defined($_) } map { $+{$_} } qw(dir file);
$sort_path = join('::', substr($action, 0, 1), substr($kind, 0, 1), $dir);
say 'node ', $action, '[', $kind, ']', join(' / ', @parts);
say "-> $sort_path";
}
push @records, {
path => $sort_path,
file => $file,
obj => $record,
};
}
print $fh &flush_records();
close $fh;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment