mirror of https://github.com/zulip/zulip.git
zanitizer: Reformat with perltidy.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
29e4c71ec4
commit
3b4cb899b6
285
tools/zanitizer
285
tools/zanitizer
|
@ -18,153 +18,174 @@ use lib $FindBin::Bin;
|
||||||
use zanitizer_config;
|
use zanitizer_config;
|
||||||
|
|
||||||
sub eq_tree {
|
sub eq_tree {
|
||||||
my ($a, $b) = @_;
|
my ( $a, $b ) = @_;
|
||||||
!(grep{!exists $$b{$_} || $$a{$_} ne $$b{$_}} keys %$a) &&
|
!( grep { !exists $$b{$_} || $$a{$_} ne $$b{$_} } keys %$a )
|
||||||
!(grep {!exists $$a{$_}} keys %$b)
|
&& !( grep { !exists $$a{$_} } keys %$b );
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($fast_export_file, $export_marks_file) = @ARGV;
|
my ( $fast_export_file, $export_marks_file ) = @ARGV;
|
||||||
|
|
||||||
my %export_marks = ();
|
my %export_marks = ();
|
||||||
if (defined $export_marks_file) {
|
if ( defined $export_marks_file ) {
|
||||||
open EXPORT_MARKS, '<', $export_marks_file or die "cannot open $export_marks_file: $!";
|
open EXPORT_MARKS, '<', $export_marks_file
|
||||||
%export_marks = map {split} <EXPORT_MARKS>;
|
or die "cannot open $export_marks_file: $!";
|
||||||
|
%export_marks = map { split } <EXPORT_MARKS>;
|
||||||
close EXPORT_MARKS;
|
close EXPORT_MARKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
my %mark_map = ();
|
my %mark_map = ();
|
||||||
my %blob_mark = ();
|
my %blob_mark = ();
|
||||||
my %ref_commit = ();
|
my %ref_commit = ();
|
||||||
my %commit_tree = ();
|
my %commit_tree = ();
|
||||||
my %scrubbed_blob = ();
|
my %scrubbed_blob = ();
|
||||||
my %scrubbed_file = ();
|
my %scrubbed_file = ();
|
||||||
my %deleted_file = ();
|
my %deleted_file = ();
|
||||||
my %renamed_file = ();
|
my %renamed_file = ();
|
||||||
|
|
||||||
open FAST_EXPORT, '<', $fast_export_file or die "cannot open $fast_export_file: $!";
|
open FAST_EXPORT, '<', $fast_export_file
|
||||||
|
or die "cannot open $fast_export_file: $!";
|
||||||
$_ = <FAST_EXPORT>;
|
$_ = <FAST_EXPORT>;
|
||||||
while (defined $_) {
|
while ( defined $_ ) {
|
||||||
if ($_ eq "blob\n") {
|
if ( $_ eq "blob\n" ) {
|
||||||
my ($mark) = <FAST_EXPORT> =~ /^mark (\S*)\n$/s or die;
|
my ($mark) = <FAST_EXPORT> =~ /^mark (\S*)\n$/s or die;
|
||||||
my ($len) = <FAST_EXPORT> =~ /^data (\d+)\n$/s or die;
|
my ($len) = <FAST_EXPORT> =~ /^data (\d+)\n$/s or die;
|
||||||
read(FAST_EXPORT, my $data, $len) == $len or die;
|
read( FAST_EXPORT, my $data, $len ) == $len or die;
|
||||||
$_ = $data;
|
$_ = $data;
|
||||||
scrub_text;
|
scrub_text;
|
||||||
if ($_ ne $data) {
|
if ( $_ ne $data ) {
|
||||||
$scrubbed_blob{$mark} = 1;
|
$scrubbed_blob{$mark} = 1;
|
||||||
$data = $_;
|
$data = $_;
|
||||||
}
|
}
|
||||||
<FAST_EXPORT> eq "\n" or die;
|
<FAST_EXPORT> eq "\n" or die;
|
||||||
|
|
||||||
my $hash = sha1_hex($data);
|
my $hash = sha1_hex($data);
|
||||||
if (exists $blob_mark{$hash}) {
|
if ( exists $blob_mark{$hash} ) {
|
||||||
$mark_map{$mark} = $blob_mark{$hash};
|
$mark_map{$mark} = $blob_mark{$hash};
|
||||||
} else {
|
}
|
||||||
$blob_mark{$hash} = $mark_map{$mark} = $mark;
|
else {
|
||||||
print "blob\nmark $mark\ndata ", length $data, "\n", $data, "\n";
|
$blob_mark{$hash} = $mark_map{$mark} = $mark;
|
||||||
}
|
print "blob\nmark $mark\ndata ", length $data, "\n", $data, "\n";
|
||||||
} elsif (/^reset (?'ref'.*)\n$/s) {
|
}
|
||||||
my $ref = $+{ref};
|
}
|
||||||
$_ = <FAST_EXPORT>;
|
elsif (/^reset (?'ref'.*)\n$/s) {
|
||||||
my $from = undef;
|
my $ref = $+{ref};
|
||||||
while (1) {
|
$_ = <FAST_EXPORT>;
|
||||||
if ($_ eq "\n") {
|
my $from = undef;
|
||||||
$_ = <FAST_EXPORT>;
|
while (1) {
|
||||||
last;
|
if ( $_ eq "\n" ) {
|
||||||
} elsif (my ($from_) = /^from (?'from'.*)\n$/s) {
|
$_ = <FAST_EXPORT>;
|
||||||
$from = $+{from};
|
last;
|
||||||
} else {
|
}
|
||||||
# The trailing LF on reset is optional
|
elsif ( my ($from_) = /^from (?'from'.*)\n$/s ) {
|
||||||
last;
|
$from = $+{from};
|
||||||
}
|
}
|
||||||
$_ = <FAST_EXPORT>;
|
else {
|
||||||
}
|
# The trailing LF on reset is optional
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
$_ = <FAST_EXPORT>;
|
||||||
|
}
|
||||||
|
|
||||||
$ref_commit{$ref} = $mark_map{from};
|
$ref_commit{$ref} = $mark_map{from};
|
||||||
print "reset $ref\n";
|
print "reset $ref\n";
|
||||||
print "from $mark_map{$from}\n" if defined $from && defined $mark_map{$from};
|
print "from $mark_map{$from}\n"
|
||||||
print "\n";
|
if defined $from && defined $mark_map{$from};
|
||||||
|
print "\n";
|
||||||
|
|
||||||
next;
|
next;
|
||||||
} elsif (/^commit (?'ref'.*)\n$/s) {
|
}
|
||||||
my $ref = $+{ref};
|
elsif (/^commit (?'ref'.*)\n$/s) {
|
||||||
my ($mark) = <FAST_EXPORT> =~ /^mark (\S*)\n$/s or die;
|
my $ref = $+{ref};
|
||||||
my ($author) = <FAST_EXPORT> =~ /^author (.*)\n$/s or die;
|
my ($mark) = <FAST_EXPORT> =~ /^mark (\S*)\n$/s or die;
|
||||||
my ($committer) = <FAST_EXPORT> =~ /^committer (.*)\n$/s or die;
|
my ($author) = <FAST_EXPORT> =~ /^author (.*)\n$/s or die;
|
||||||
my ($len) = <FAST_EXPORT> =~ /^data (\d+)\n$/s or die;
|
my ($committer) = <FAST_EXPORT> =~ /^committer (.*)\n$/s or die;
|
||||||
read FAST_EXPORT, my ($data), $len;
|
my ($len) = <FAST_EXPORT> =~ /^data (\d+)\n$/s or die;
|
||||||
$_ = <FAST_EXPORT>;
|
read FAST_EXPORT, my ($data), $len;
|
||||||
my $from = undef;
|
$_ = <FAST_EXPORT>;
|
||||||
if (/^from (?'from'.*)\n$/s) {
|
my $from = undef;
|
||||||
$from = $+{from};
|
|
||||||
$_ = <FAST_EXPORT>;
|
|
||||||
}
|
|
||||||
my $base = defined $from ? $mark_map{$from} : $ref_commit{ref};
|
|
||||||
my @merge = ();
|
|
||||||
while (/^merge (?'mark'\S*)\n$/s) {
|
|
||||||
die "unimplemented case" if !defined $from;
|
|
||||||
push @merge, $+{mark};
|
|
||||||
$_ = <FAST_EXPORT>;
|
|
||||||
}
|
|
||||||
# git fast-export incorrectly writes M before D when replacing
|
|
||||||
# a symlink with a directory. We move every D before every M
|
|
||||||
# to work around this bug.
|
|
||||||
my @delete = ();
|
|
||||||
my @modify = ();
|
|
||||||
while (1) {
|
|
||||||
if ($_ eq "\n") {
|
|
||||||
last;
|
|
||||||
} elsif (/^D (?'file'.*)\n$/s) {
|
|
||||||
$_ = $+{file};
|
|
||||||
scrub_filename;
|
|
||||||
push @delete, {%+, file => $_} if defined $_;
|
|
||||||
} elsif (/^M (?'mode'\d+) (?'mark'\S+) (?'file'.*)\n$/s) {
|
|
||||||
$_ = $+{file};
|
|
||||||
scrub_filename;
|
|
||||||
if (defined $_) {
|
|
||||||
$renamed_file{$+{file}} = $_ if $_ ne $+{file};
|
|
||||||
$scrubbed_file{$_} = 1 if exists $scrubbed_blob{$+{mark}};
|
|
||||||
push @modify, {%+, file => $_};
|
|
||||||
} else {
|
|
||||||
$deleted_file{$+{file}} = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
die "unhandled command in commit: $_";
|
|
||||||
}
|
|
||||||
$_ = <FAST_EXPORT>;
|
|
||||||
}
|
|
||||||
my $base_tree = defined $base ? $commit_tree{$base} : {};
|
|
||||||
my %tree = %$base_tree;
|
|
||||||
delete $tree{$$_{file}} for @delete;
|
|
||||||
$tree{$$_{file}} = "$$_{mode} $mark_map{$$_{mark}}" for @modify;
|
|
||||||
|
|
||||||
if (eq_tree(\%tree, $base_tree) && !(grep {defined $mark_map{$_}} @merge)) {
|
if (/^from (?'from'.*)\n$/s) {
|
||||||
$ref_commit{$ref} = $mark_map{$mark} = $base;
|
$from = $+{from};
|
||||||
} else {
|
$_ = <FAST_EXPORT>;
|
||||||
$ref_commit{$ref} = $mark_map{$mark} = $mark;
|
}
|
||||||
$commit_tree{$mark} = \%tree;
|
my $base = defined $from ? $mark_map{$from} : $ref_commit{ref};
|
||||||
$_ = $data;
|
my @merge = ();
|
||||||
scrub_text;
|
while (/^merge (?'mark'\S*)\n$/s) {
|
||||||
if (exists $export_marks{$mark}) {
|
die "unimplemented case" if !defined $from;
|
||||||
$_ .= "\n" until /\n\n$/;
|
push @merge, $+{mark};
|
||||||
$_ .= "(imported from commit $export_marks{$mark})\n";
|
$_ = <FAST_EXPORT>;
|
||||||
}
|
}
|
||||||
print "commit $ref\nmark $mark\nauthor $author\ncommitter $committer\ndata ", length $_, "\n", $_;
|
|
||||||
if (defined $from) {
|
# git fast-export incorrectly writes M before D when replacing
|
||||||
die "unimplemented case" if !defined $mark_map{$from};
|
# a symlink with a directory. We move every D before every M
|
||||||
print "from $mark_map{$from}\n";
|
# to work around this bug.
|
||||||
}
|
my @delete = ();
|
||||||
for (@merge) {
|
my @modify = ();
|
||||||
print "merge $mark_map{$_}\n" if defined $mark_map{$_};
|
while (1) {
|
||||||
}
|
if ( $_ eq "\n" ) {
|
||||||
print "D $$_{file}\n" for @delete;
|
last;
|
||||||
print "M $$_{mode} $mark_map{$$_{mark}} $$_{file}\n" for @modify;
|
}
|
||||||
print "\n";
|
elsif (/^D (?'file'.*)\n$/s) {
|
||||||
}
|
$_ = $+{file};
|
||||||
} elsif (/^progress /) {
|
scrub_filename;
|
||||||
print $_;
|
push @delete, { %+, file => $_ } if defined $_;
|
||||||
} else {
|
}
|
||||||
die "unhandled command: $_";
|
elsif (/^M (?'mode'\d+) (?'mark'\S+) (?'file'.*)\n$/s) {
|
||||||
|
$_ = $+{file};
|
||||||
|
scrub_filename;
|
||||||
|
if ( defined $_ ) {
|
||||||
|
$renamed_file{ $+{file} } = $_ if $_ ne $+{file};
|
||||||
|
$scrubbed_file{$_} = 1 if exists $scrubbed_blob{ $+{mark} };
|
||||||
|
push @modify, { %+, file => $_ };
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$deleted_file{ $+{file} } = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
die "unhandled command in commit: $_";
|
||||||
|
}
|
||||||
|
$_ = <FAST_EXPORT>;
|
||||||
|
}
|
||||||
|
my $base_tree = defined $base ? $commit_tree{$base} : {};
|
||||||
|
my %tree = %$base_tree;
|
||||||
|
delete $tree{ $$_{file} } for @delete;
|
||||||
|
$tree{ $$_{file} } = "$$_{mode} $mark_map{$$_{mark}}" for @modify;
|
||||||
|
|
||||||
|
if ( eq_tree( \%tree, $base_tree )
|
||||||
|
&& !( grep { defined $mark_map{$_} } @merge ) )
|
||||||
|
{
|
||||||
|
$ref_commit{$ref} = $mark_map{$mark} = $base;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$ref_commit{$ref} = $mark_map{$mark} = $mark;
|
||||||
|
$commit_tree{$mark} = \%tree;
|
||||||
|
$_ = $data;
|
||||||
|
scrub_text;
|
||||||
|
if ( exists $export_marks{$mark} ) {
|
||||||
|
$_ .= "\n" until /\n\n$/;
|
||||||
|
$_ .= "(imported from commit $export_marks{$mark})\n";
|
||||||
|
}
|
||||||
|
print
|
||||||
|
"commit $ref\nmark $mark\nauthor $author\ncommitter $committer\ndata ",
|
||||||
|
length $_, "\n", $_;
|
||||||
|
if ( defined $from ) {
|
||||||
|
die "unimplemented case" if !defined $mark_map{$from};
|
||||||
|
print "from $mark_map{$from}\n";
|
||||||
|
}
|
||||||
|
for (@merge) {
|
||||||
|
print "merge $mark_map{$_}\n" if defined $mark_map{$_};
|
||||||
|
}
|
||||||
|
print "D $$_{file}\n" for @delete;
|
||||||
|
print "M $$_{mode} $mark_map{$$_{mark}} $$_{file}\n" for @modify;
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elsif (/^progress /) {
|
||||||
|
print $_;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
die "unhandled command: $_";
|
||||||
}
|
}
|
||||||
$_ = <FAST_EXPORT>;
|
$_ = <FAST_EXPORT>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,10 @@ sub scrub_text {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub scrub_filename {
|
sub scrub_filename {
|
||||||
if (m%^secret-directory/% || m%settings\.ini$%) {
|
if ( m%^secret-directory/% || m%settings\.ini$% ) {
|
||||||
undef $_;
|
undef $_;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
s/bruce/batman/g;
|
s/bruce/batman/g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue