Created
October 30, 2012 04:41
-
-
Save niratama/3978336 to your computer and use it in GitHub Desktop.
svnadmin dumpしたものが日本語ファイル名が原因で戻せないときの対策ツール
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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