@matheusbsbs / matheus-bagliano / commits / 86d11cf264
Fork 0

cvsimport: style fixup.

This should not change any functionality, but just makes it readable by having a space between syntactic construct keyword and open parenthesis (e.g. "if (expr", not "if(expr") and between close parenthesis and open brace (e.g. "if (expr) {" not "if (expr){"). Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 27, 2006 at 14:21 UTC 86d11cf264c55d570484cbdfff073092c77a6342
1 file changed +84 -84
git-cvsimport.perl
+84 -84
@@ -29,7 +29,7 @@ use IPC::Open2;
29 $SIG{'PIPE'}="IGNORE";
30 $ENV{'TZ'}="UTC";
31
32 -our($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,$opt_M,$opt_A,$opt_S,$opt_L);
32 +our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,$opt_M,$opt_A,$opt_S,$opt_L);
33 my (%conv_author_name, %conv_author_email);
34
35 sub usage() {
@@ -90,15 +90,15 @@ usage if $opt_h;
90
91 @ARGV <= 1 or usage();
92
93 -if($opt_d) {
93 +if ($opt_d) {
94 $ENV{"CVSROOT"} = $opt_d;
95 -} elsif(-f 'CVS/Root') {
95 +} elsif (-f 'CVS/Root') {
96 open my $f, '<', 'CVS/Root' or die 'Failed to open CVS/Root';
97 $opt_d = <$f>;
98 chomp $opt_d;
99 close $f;
100 $ENV{"CVSROOT"} = $opt_d;
101 -} elsif($ENV{"CVSROOT"}) {
101 +} elsif ($ENV{"CVSROOT"}) {
102 $opt_d = $ENV{"CVSROOT"};
103 } else {
104 die "CVSROOT needs to be set";
@@ -141,7 +141,7 @@ use File::Temp qw(tempfile);
141 use POSIX qw(strftime dup2);
142
143 sub new {
144 - my($what,$repo,$subdir) = @_;
144 + my ($what,$repo,$subdir) = @_;
145 $what=ref($what) if ref($what);
146
147 my $self = {};
@@ -161,38 +161,38 @@ sub new {
161 sub conn {
162 my $self = shift;
163 my $repo = $self->{'fullrep'};
164 - if($repo =~ s/^:pserver(?:([^:]*)):(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?//) {
165 - my($param,$user,$pass,$serv,$port) = ($1,$2,$3,$4,$5);
164 + if ($repo =~ s/^:pserver(?:([^:]*)):(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?//) {
165 + my ($param,$user,$pass,$serv,$port) = ($1,$2,$3,$4,$5);
166
167 - my($proxyhost,$proxyport);
168 - if($param && ($param =~ m/proxy=([^;]+)/)) {
167 + my ($proxyhost,$proxyport);
168 + if ($param && ($param =~ m/proxy=([^;]+)/)) {
169 $proxyhost = $1;
170 # Default proxyport, if not specified, is 8080.
171 $proxyport = 8080;
172 - if($ENV{"CVS_PROXY_PORT"}) {
172 + if ($ENV{"CVS_PROXY_PORT"}) {
173 $proxyport = $ENV{"CVS_PROXY_PORT"};
174 }
175 - if($param =~ m/proxyport=([^;]+)/){
175 + if ($param =~ m/proxyport=([^;]+)/) {
176 $proxyport = $1;
177 }
178 }
179
180 $user="anonymous" unless defined $user;
181 my $rr2 = "-";
182 - unless($port) {
182 + unless ($port) {
183 $rr2 = ":pserver:$user\@$serv:$repo";
184 $port=2401;
185 }
186 my $rr = ":pserver:$user\@$serv:$port$repo";
187
188 - unless($pass) {
188 + unless ($pass) {
189 open(H,$ENV{'HOME'}."/.cvspass") and do {
190 # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah<Z
191 - while(<H>) {
191 + while (<H>) {
192 chomp;
193 s/^\/\d+\s+//;
194 my ($w,$p) = split(/\s/,$_,2);
195 - if($w eq $rr or $w eq $rr2) {
195 + if ($w eq $rr or $w eq $rr2) {
196 $pass = $p;
197 last;
198 }
@@ -202,7 +202,7 @@ sub conn {
202 $pass="A" unless $pass;
203
204 my ($s, $rep);
205 - if($proxyhost) {
205 + if ($proxyhost) {
206
207 # Use a HTTP Proxy. Only works for HTTP proxies that
208 # don't require user authentication
@@ -218,7 +218,7 @@ sub conn {
218 $rep = <$s>;
219
220 # The answer should look like 'HTTP/1.x 2yy ....'
221 - if(!($rep =~ m#^HTTP/1\.. 2[0-9][0-9]#)) {
221 + if (!($rep =~ m#^HTTP/1\.. 2[0-9][0-9]#)) {
222 die "Proxy connect: $rep\n";
223 }
224 # Skip up to the empty line of the proxy server output
@@ -239,7 +239,7 @@ sub conn {
239
240 $rep = <$s>;
241
242 - if($rep ne "I LOVE YOU\n") {
242 + if ($rep ne "I LOVE YOU\n") {
243 $rep="<unknown>" unless $rep;
244 die "AuthReply: $rep\n";
245 }
@@ -271,7 +271,7 @@ sub conn {
271 }
272 }
273
274 - unless($pid) {
274 + unless ($pid) {
275 $pr->writer();
276 $pw->reader();
277 dup2($pw->fileno(),0);
@@ -294,7 +294,7 @@ sub conn {
294 $self->{'socketo'}->flush();
295
296 chomp(my $rep=$self->readline());
297 - if($rep !~ s/^Valid-requests\s*//) {
297 + if ($rep !~ s/^Valid-requests\s*//) {
298 $rep="<unknown>" unless $rep;
299 die "Expected Valid-requests from server, but got: $rep\n";
300 }
@@ -306,14 +306,14 @@ sub conn {
306 }
307
308 sub readline {
309 - my($self) = @_;
309 + my ($self) = @_;
310 return $self->{'socketi'}->getline();
311 }
312
313 sub _file {
314 # Request a file with a given revision.
315 # Trial and error says this is a good way to do it. :-/
316 - my($self,$fn,$rev) = @_;
316 + my ($self,$fn,$rev) = @_;
317 $self->{'socketo'}->write("Argument -N\n") or return undef;
318 $self->{'socketo'}->write("Argument -P\n") or return undef;
319 # -kk: Linus' version doesn't use it - defaults to off
@@ -335,12 +335,12 @@ sub _file {
335 sub _line {
336 # Read a line from the server.
337 # ... except that 'line' may be an entire file. ;-)
338 - my($self, $fh) = @_;
338 + my ($self, $fh) = @_;
339 die "Not in lines" unless defined $self->{'lines'};
340
341 my $line;
342 my $res=0;
343 - while(defined($line = $self->readline())) {
343 + while (defined($line = $self->readline())) {
344 # M U gnupg-cvs-rep/AUTHORS
345 # Updated gnupg-cvs-rep/
346 # /daten/src/rsync/gnupg-cvs-rep/AUTHORS
@@ -349,7 +349,7 @@ sub _line {
349 # 0
350 # ok
351
352 - if($line =~ s/^(?:Created|Updated) //) {
352 + if ($line =~ s/^(?:Created|Updated) //) {
353 $line = $self->readline(); # path
354 $line = $self->readline(); # Entries line
355 my $mode = $self->readline(); chomp $mode;
@@ -360,12 +360,12 @@ sub _line {
360 die "Duh: Filesize $cnt" if $cnt !~ /^\d+$/;
361 $line="";
362 $res = $self->_fetchfile($fh, $cnt);
363 - } elsif($line =~ s/^ //) {
363 + } elsif ($line =~ s/^ //) {
364 print $fh $line;
365 $res += length($line);
366 - } elsif($line =~ /^M\b/) {
366 + } elsif ($line =~ /^M\b/) {
367 # output, do nothing
368 - } elsif($line =~ /^Mbinary\b/) {
368 + } elsif ($line =~ /^Mbinary\b/) {
369 my $cnt;
370 die "EOF from server after 'Mbinary'" unless defined ($cnt = $self->readline());
371 chomp $cnt;
@@ -374,12 +374,12 @@ sub _line {
374 $res += $self->_fetchfile($fh, $cnt);
375 } else {
376 chomp $line;
377 - if($line eq "ok") {
377 + if ($line eq "ok") {
378 # print STDERR "S: ok (".length($res).")\n";
379 return $res;
380 - } elsif($line =~ s/^E //) {
380 + } elsif ($line =~ s/^E //) {
381 # print STDERR "S: $line\n";
382 - } elsif($line =~ /^(Remove-entry|Removed) /i) {
382 + } elsif ($line =~ /^(Remove-entry|Removed) /i) {
383 $line = $self->readline(); # filename
384 $line = $self->readline(); # OK
385 chomp $line;
@@ -393,7 +393,7 @@ sub _line {
393 return undef;
394 }
395 sub file {
396 - my($self,$fn,$rev) = @_;
396 + my ($self,$fn,$rev) = @_;
397 my $res;
398
399 my ($fh, $name) = tempfile('gitcvs.XXXXXX',
@@ -417,7 +417,7 @@ sub _fetchfile {
417 my ($self, $fh, $cnt) = @_;
418 my $res = 0;
419 my $bufsize = 1024 * 1024;
420 - while($cnt) {
420 + while ($cnt) {
421 if ($bufsize > $cnt) {
422 $bufsize = $cnt;
423 }
@@ -438,7 +438,7 @@ my $cvs = CVSconn->new($opt_d, $cvs_tree);
438
439
440 sub pdate($) {
441 - my($d) = @_;
441 + my ($d) = @_;
442 m#(\d{2,4})/(\d\d)/(\d\d)\s(\d\d):(\d\d)(?::(\d\d))?#
443 or die "Unparseable date: $d\n";
444 my $y=$1; $y-=1900 if $y>1900;
@@ -446,22 +446,22 @@ sub pdate($) {
446 }
447
448 sub pmode($) {
449 - my($mode) = @_;
449 + my ($mode) = @_;
450 my $m = 0;
451 my $mm = 0;
452 my $um = 0;
453 for my $x(split(//,$mode)) {
454 - if($x eq ",") {
454 + if ($x eq ",") {
455 $m |= $mm&$um;
456 $mm = 0;
457 $um = 0;
458 - } elsif($x eq "u") { $um |= 0700;
459 - } elsif($x eq "g") { $um |= 0070;
460 - } elsif($x eq "o") { $um |= 0007;
461 - } elsif($x eq "r") { $mm |= 0444;
462 - } elsif($x eq "w") { $mm |= 0222;
463 - } elsif($x eq "x") { $mm |= 0111;
464 - } elsif($x eq "=") { # do nothing
458 + } elsif ($x eq "u") { $um |= 0700;
459 + } elsif ($x eq "g") { $um |= 0070;
460 + } elsif ($x eq "o") { $um |= 0007;
461 + } elsif ($x eq "r") { $mm |= 0444;
462 + } elsif ($x eq "w") { $mm |= 0222;
463 + } elsif ($x eq "x") { $mm |= 0111;
464 + } elsif ($x eq "=") { # do nothing
465 } else { die "Unknown mode: $mode\n";
466 }
467 }
@@ -485,7 +485,7 @@ sub get_headref ($$) {
485 my $git_dir = shift;
486
487 my $f = "$git_dir/refs/heads/$name";
488 - if(open(my $fh, $f)) {
488 + if (open(my $fh, $f)) {
489 chomp(my $r = <$fh>);
490 is_sha1($r) or die "Cannot get head id for $name ($r): $!";
491 return $r;
@@ -512,7 +512,7 @@ $orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};
512
513 my %index; # holds filenames of one index per branch
514
515 -unless(-d $git_dir) {
515 +unless (-d $git_dir) {
516 system("git-init-db");
517 die "Cannot init the GIT db at $git_tree: $?\n" if $?;
518 system("git-read-tree");
@@ -531,7 +531,7 @@ unless(-d $git_dir) {
531 chomp ($last_branch = <F>);
532 $last_branch = basename($last_branch);
533 close(F);
534 - unless($last_branch) {
534 + unless ($last_branch) {
535 warn "Cannot read the last branch name: $! -- assuming 'master'\n";
536 $last_branch = "master";
537 }
@@ -542,7 +542,7 @@ unless(-d $git_dir) {
542 my $fmt = '($ref, $author) = (%(refname), %(author));';
543 open(H, "git-for-each-ref --perl --format='$fmt' refs/heads |") or
544 die "Cannot run git-for-each-ref: $!\n";
545 - while(defined(my $entry = <H>)) {
545 + while (defined(my $entry = <H>)) {
546 my ($ref, $author);
547 eval($entry) || die "cannot eval refs list: $@";
548 my ($head) = ($ref =~ m|^refs/heads/(.*)|);
@@ -572,7 +572,7 @@ unless ($opt_P) {
572 print "Running cvsps...\n" if $opt_v;
573 my $pid = open(CVSPS,"-|");
574 die "Cannot fork: $!\n" unless defined $pid;
575 - unless($pid) {
575 + unless ($pid) {
576 my @opt;
577 @opt = split(/,/,$opt_p) if defined $opt_p;
578 unshift @opt, '-z', $opt_z if defined $opt_z;
@@ -642,8 +642,8 @@ sub write_tree () {
642 return $tree;
643 }
644
645 -my($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
646 -my(@old,@new,@skipped,%ignorebranch);
645 +my ($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
646 +my (@old,@new,@skipped,%ignorebranch);
647
648 # commits that cvsps cannot place anywhere...
649 $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
@@ -684,7 +684,7 @@ sub commit {
684 foreach my $rx (@mergerx) {
685 next unless $logmsg =~ $rx && $1;
686 my $mparent = $1 eq 'HEAD' ? $opt_o : $1;
687 - if(my $sha1 = get_headref($mparent, $git_dir)) {
687 + if (my $sha1 = get_headref($mparent, $git_dir)) {
688 push @commit_args, '-p', $mparent;
689 print "Merge parent branch: $mparent\n" if $opt_v;
690 }
@@ -725,9 +725,9 @@ sub commit {
725 system("git-update-ref refs/heads/$branch $cid") == 0
726 or die "Cannot write branch $branch for update: $!\n";
727
728 - if($tag) {
729 - my($in, $out) = ('','');
730 - my($xtag) = $tag;
728 + if ($tag) {
729 + my ($in, $out) = ('','');
730 + my ($xtag) = $tag;
731 $xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **
732 $xtag =~ tr/_/\./ if ( $opt_u );
733 $xtag =~ s/[\/]/$opt_s/g;
@@ -762,25 +762,25 @@ sub commit {
762 };
763
764 my $commitcount = 1;
765 -while(<CVS>) {
765 +while (<CVS>) {
766 chomp;
767 - if($state == 0 and /^-+$/) {
767 + if ($state == 0 and /^-+$/) {
768 $state = 1;
769 - } elsif($state == 0) {
769 + } elsif ($state == 0) {
770 $state = 1;
771 redo;
772 - } elsif(($state==0 or $state==1) and s/^PatchSet\s+//) {
772 + } elsif (($state==0 or $state==1) and s/^PatchSet\s+//) {
773 $patchset = 0+$_;
774 $state=2;
775 - } elsif($state == 2 and s/^Date:\s+//) {
775 + } elsif ($state == 2 and s/^Date:\s+//) {
776 $date = pdate($_);
777 - unless($date) {
777 + unless ($date) {
778 print STDERR "Could not parse date: $_\n";
779 $state=0;
780 next;
781 }
782 $state=3;
783 - } elsif($state == 3 and s/^Author:\s+//) {
783 + } elsif ($state == 3 and s/^Author:\s+//) {
784 s/\s+$//;
785 if (/^(.*?)\s+<(.*)>/) {
786 ($author_name, $author_email) = ($1, $2);
@@ -791,34 +791,34 @@ while(<CVS>) {
791 $author_name = $author_email = $_;
792 }
793 $state = 4;
794 - } elsif($state == 4 and s/^Branch:\s+//) {
794 + } elsif ($state == 4 and s/^Branch:\s+//) {
795 s/\s+$//;
796 s/[\/]/$opt_s/g;
797 $branch = $_;
798 $state = 5;
799 - } elsif($state == 5 and s/^Ancestor branch:\s+//) {
799 + } elsif ($state == 5 and s/^Ancestor branch:\s+//) {
800 s/\s+$//;
801 $ancestor = $_;
802 $ancestor = $opt_o if $ancestor eq "HEAD";
803 $state = 6;
804 - } elsif($state == 5) {
804 + } elsif ($state == 5) {
805 $ancestor = undef;
806 $state = 6;
807 redo;
808 - } elsif($state == 6 and s/^Tag:\s+//) {
808 + } elsif ($state == 6 and s/^Tag:\s+//) {
809 s/\s+$//;
810 - if($_ eq "(none)") {
810 + if ($_ eq "(none)") {
811 $tag = undef;
812 } else {
813 $tag = $_;
814 }
815 $state = 7;
816 - } elsif($state == 7 and /^Log:/) {
816 + } elsif ($state == 7 and /^Log:/) {
817 $logmsg = "";
818 $state = 8;
819 - } elsif($state == 8 and /^Members:/) {
819 + } elsif ($state == 8 and /^Members:/) {
820 $branch = $opt_o if $branch eq "HEAD";
821 - if(defined $branch_date{$branch} and $branch_date{$branch} >= $date) {
821 + if (defined $branch_date{$branch} and $branch_date{$branch} >= $date) {
822 # skip
823 print "skip patchset $patchset: $date before $branch_date{$branch}\n" if $opt_v;
824 $state = 11;
@@ -829,17 +829,17 @@ while(<CVS>) {
829 $state = 11;
830 next;
831 }
832 - if($ancestor) {
833 - if($ancestor eq $branch) {
832 + if ($ancestor) {
833 + if ($ancestor eq $branch) {
834 print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
835 $ancestor = $opt_o;
836 }
837 - if(-f "$git_dir/refs/heads/$branch") {
837 + if (-f "$git_dir/refs/heads/$branch") {
838 print STDERR "Branch $branch already exists!\n";
839 $state=11;
840 next;
841 }
842 - unless(open(H,"$git_dir/refs/heads/$ancestor")) {
842 + unless (open(H,"$git_dir/refs/heads/$ancestor")) {
843 print STDERR "Branch $ancestor does not exist!\n";
844 $ignorebranch{$branch} = 1;
845 $state=11;
@@ -847,7 +847,7 @@ while(<CVS>) {
847 }
848 chomp(my $id = <H>);
849 close(H);
850 - unless(open(H,"> $git_dir/refs/heads/$branch")) {
850 + unless (open(H,"> $git_dir/refs/heads/$branch")) {
851 print STDERR "Could not create branch $branch: $!\n";
852 $ignorebranch{$branch} = 1;
853 $state=11;
@@ -860,9 +860,9 @@ while(<CVS>) {
860 }
861 $last_branch = $branch if $branch ne $last_branch;
862 $state = 9;
863 - } elsif($state == 8) {
863 + } elsif ($state == 8) {
864 $logmsg .= "$_\n";
865 - } elsif($state == 9 and /^\s+(.+?):(INITIAL|\d+(?:\.\d+)+)->(\d+(?:\.\d+)+)\s*$/) {
865 + } elsif ($state == 9 and /^\s+(.+?):(INITIAL|\d+(?:\.\d+)+)->(\d+(?:\.\d+)+)\s*$/) {
866 # VERSION:1.96->1.96.2.1
867 my $init = ($2 eq "INITIAL");
868 my $fn = $1;
@@ -875,7 +875,7 @@ while(<CVS>) {
875 }
876 print "Fetching $fn v $rev\n" if $opt_v;
877 my ($tmpname, $size) = $cvs->file($fn,$rev);
878 - if($size == -1) {
878 + if ($size == -1) {
879 push(@old,$fn);
880 print "Drop $fn\n" if $opt_v;
881 } else {
@@ -893,14 +893,14 @@ while(<CVS>) {
893 push(@new,[$mode, $sha, $fn]); # may be resurrected!
894 }
895 unlink($tmpname);
896 - } elsif($state == 9 and /^\s+(.+?):\d+(?:\.\d+)+->(\d+(?:\.\d+)+)\(DEAD\)\s*$/) {
896 + } elsif ($state == 9 and /^\s+(.+?):\d+(?:\.\d+)+->(\d+(?:\.\d+)+)\(DEAD\)\s*$/) {
897 my $fn = $1;
898 $fn =~ s#^/+##;
899 push(@old,$fn);
900 print "Delete $fn\n" if $opt_v;
901 - } elsif($state == 9 and /^\s*$/) {
901 + } elsif ($state == 9 and /^\s*$/) {
902 $state = 10;
903 - } elsif(($state == 9 or $state == 10) and /^-+$/) {
903 + } elsif (($state == 9 or $state == 10) and /^-+$/) {
904 $commitcount++;
905 if ($opt_L && $commitcount > $opt_L) {
906 last;
@@ -910,11 +910,11 @@ while(<CVS>) {
910 system("git repack -a -d");
911 }
912 $state = 1;
913 - } elsif($state == 11 and /^-+$/) {
913 + } elsif ($state == 11 and /^-+$/) {
914 $state = 1;
915 - } elsif(/^-+$/) { # end of unknown-line processing
915 + } elsif (/^-+$/) { # end of unknown-line processing
916 $state = 1;
917 - } elsif($state != 11) { # ignore stuff when skipping
917 + } elsif ($state != 11) { # ignore stuff when skipping
918 print "* UNKNOWN LINE * $_\n";
919 }
920 }
@@ -943,7 +943,7 @@ if (defined $orig_git_index) {
943 }
944
945 # Now switch back to the branch we were in before all of this happened
946 -if($orig_branch) {
946 +if ($orig_branch) {
947 print "DONE.\n" if $opt_v;
948 if ($opt_i) {
949 exit 0;