zanitizer: Reformat with perltidy.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-03-24 10:32:23 -07:00 committed by Tim Abbott
parent 29e4c71ec4
commit 3b4cb899b6
2 changed files with 156 additions and 134 deletions

View File

@ -19,15 +19,16 @@ 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
or die "cannot open $export_marks_file: $!";
%export_marks = map { split } <EXPORT_MARKS>; %export_marks = map { split } <EXPORT_MARKS>;
close EXPORT_MARKS; close EXPORT_MARKS;
} }
@ -41,7 +42,8 @@ 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" ) {
@ -59,11 +61,13 @@ while (defined $_) {
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 { }
else {
$blob_mark{$hash} = $mark_map{$mark} = $mark; $blob_mark{$hash} = $mark_map{$mark} = $mark;
print "blob\nmark $mark\ndata ", length $data, "\n", $data, "\n"; print "blob\nmark $mark\ndata ", length $data, "\n", $data, "\n";
} }
} elsif (/^reset (?'ref'.*)\n$/s) { }
elsif (/^reset (?'ref'.*)\n$/s) {
my $ref = $+{ref}; my $ref = $+{ref};
$_ = <FAST_EXPORT>; $_ = <FAST_EXPORT>;
my $from = undef; my $from = undef;
@ -71,9 +75,11 @@ while (defined $_) {
if ( $_ eq "\n" ) { if ( $_ eq "\n" ) {
$_ = <FAST_EXPORT>; $_ = <FAST_EXPORT>;
last; last;
} elsif (my ($from_) = /^from (?'from'.*)\n$/s) { }
elsif ( my ($from_) = /^from (?'from'.*)\n$/s ) {
$from = $+{from}; $from = $+{from};
} else { }
else {
# The trailing LF on reset is optional # The trailing LF on reset is optional
last; last;
} }
@ -82,11 +88,13 @@ while (defined $_) {
$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"
if defined $from && defined $mark_map{$from};
print "\n"; print "\n";
next; next;
} elsif (/^commit (?'ref'.*)\n$/s) { }
elsif (/^commit (?'ref'.*)\n$/s) {
my $ref = $+{ref}; my $ref = $+{ref};
my ($mark) = <FAST_EXPORT> =~ /^mark (\S*)\n$/s or die; my ($mark) = <FAST_EXPORT> =~ /^mark (\S*)\n$/s or die;
my ($author) = <FAST_EXPORT> =~ /^author (.*)\n$/s or die; my ($author) = <FAST_EXPORT> =~ /^author (.*)\n$/s or die;
@ -95,6 +103,7 @@ while (defined $_) {
read FAST_EXPORT, my ($data), $len; read FAST_EXPORT, my ($data), $len;
$_ = <FAST_EXPORT>; $_ = <FAST_EXPORT>;
my $from = undef; my $from = undef;
if (/^from (?'from'.*)\n$/s) { if (/^from (?'from'.*)\n$/s) {
$from = $+{from}; $from = $+{from};
$_ = <FAST_EXPORT>; $_ = <FAST_EXPORT>;
@ -106,6 +115,7 @@ while (defined $_) {
push @merge, $+{mark}; push @merge, $+{mark};
$_ = <FAST_EXPORT>; $_ = <FAST_EXPORT>;
} }
# git fast-export incorrectly writes M before D when replacing # git fast-export incorrectly writes M before D when replacing
# a symlink with a directory. We move every D before every M # a symlink with a directory. We move every D before every M
# to work around this bug. # to work around this bug.
@ -114,21 +124,25 @@ while (defined $_) {
while (1) { while (1) {
if ( $_ eq "\n" ) { if ( $_ eq "\n" ) {
last; last;
} elsif (/^D (?'file'.*)\n$/s) { }
elsif (/^D (?'file'.*)\n$/s) {
$_ = $+{file}; $_ = $+{file};
scrub_filename; scrub_filename;
push @delete, { %+, file => $_ } if defined $_; push @delete, { %+, file => $_ } if defined $_;
} elsif (/^M (?'mode'\d+) (?'mark'\S+) (?'file'.*)\n$/s) { }
elsif (/^M (?'mode'\d+) (?'mark'\S+) (?'file'.*)\n$/s) {
$_ = $+{file}; $_ = $+{file};
scrub_filename; scrub_filename;
if ( defined $_ ) { if ( defined $_ ) {
$renamed_file{ $+{file} } = $_ if $_ ne $+{file}; $renamed_file{ $+{file} } = $_ if $_ ne $+{file};
$scrubbed_file{$_} = 1 if exists $scrubbed_blob{ $+{mark} }; $scrubbed_file{$_} = 1 if exists $scrubbed_blob{ $+{mark} };
push @modify, { %+, file => $_ }; push @modify, { %+, file => $_ };
} else { }
else {
$deleted_file{ $+{file} } = 1; $deleted_file{ $+{file} } = 1;
} }
} else { }
else {
die "unhandled command in commit: $_"; die "unhandled command in commit: $_";
} }
$_ = <FAST_EXPORT>; $_ = <FAST_EXPORT>;
@ -138,9 +152,12 @@ while (defined $_) {
delete $tree{ $$_{file} } for @delete; delete $tree{ $$_{file} } for @delete;
$tree{ $$_{file} } = "$$_{mode} $mark_map{$$_{mark}}" for @modify; $tree{ $$_{file} } = "$$_{mode} $mark_map{$$_{mark}}" for @modify;
if (eq_tree(\%tree, $base_tree) && !(grep {defined $mark_map{$_}} @merge)) { if ( eq_tree( \%tree, $base_tree )
&& !( grep { defined $mark_map{$_} } @merge ) )
{
$ref_commit{$ref} = $mark_map{$mark} = $base; $ref_commit{$ref} = $mark_map{$mark} = $base;
} else { }
else {
$ref_commit{$ref} = $mark_map{$mark} = $mark; $ref_commit{$ref} = $mark_map{$mark} = $mark;
$commit_tree{$mark} = \%tree; $commit_tree{$mark} = \%tree;
$_ = $data; $_ = $data;
@ -149,7 +166,9 @@ while (defined $_) {
$_ .= "\n" until /\n\n$/; $_ .= "\n" until /\n\n$/;
$_ .= "(imported from commit $export_marks{$mark})\n"; $_ .= "(imported from commit $export_marks{$mark})\n";
} }
print "commit $ref\nmark $mark\nauthor $author\ncommitter $committer\ndata ", length $_, "\n", $_; print
"commit $ref\nmark $mark\nauthor $author\ncommitter $committer\ndata ",
length $_, "\n", $_;
if ( defined $from ) { if ( defined $from ) {
die "unimplemented case" if !defined $mark_map{$from}; die "unimplemented case" if !defined $mark_map{$from};
print "from $mark_map{$from}\n"; print "from $mark_map{$from}\n";
@ -161,9 +180,11 @@ while (defined $_) {
print "M $$_{mode} $mark_map{$$_{mark}} $$_{file}\n" for @modify; print "M $$_{mode} $mark_map{$$_{mark}} $$_{file}\n" for @modify;
print "\n"; print "\n";
} }
} elsif (/^progress /) { }
elsif (/^progress /) {
print $_; print $_;
} else { }
else {
die "unhandled command: $_"; die "unhandled command: $_";
} }
$_ = <FAST_EXPORT>; $_ = <FAST_EXPORT>;

View File

@ -11,7 +11,8 @@ 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;
} }
} }