2929$SIG {' PIPE' }=" IGNORE" ;
3030$ENV {' TZ' }=" UTC" ;
3131
32- our ($opt_h ,$opt_o ,$opt_v ,$opt_u ,$opt_C ,$opt_i ,$opt_m ,$opt_M ,$opt_t ,$opt_T ,$opt_b ,$opt_r ,$opt_s ,$opt_l ,$opt_d ,$opt_D );
32+ our ($opt_h ,$opt_o ,$opt_v ,$opt_u ,$opt_C ,$opt_i ,$opt_m ,$opt_M ,$opt_t ,$opt_T ,
33+ $opt_b ,$opt_r ,$opt_I ,$opt_s ,$opt_l ,$opt_d ,$opt_D );
3334
3435sub usage () {
3536 print STDERR <<END ;
3637Usage: ${\b asename $0 } # fetch/update GIT from SVN
3738 [-o branch-for-HEAD] [-h] [-v] [-l max_rev]
3839 [-C GIT_repository] [-t tagname] [-T trunkname] [-b branchname]
39- [-d|-D] [-i] [-u] [-r] [-s start_chg] [-m] [-M regex] [SVN_URL]
40+ [-d|-D] [-i] [-u] [-r] [-I ignorefilename] [-s start_chg]
41+ [-m] [-M regex] [SVN_URL]
4042END
4143 exit (1);
4244}
4345
44- getopts(" b:C:dDhil :mM:o:rs:t:T:uv" ) or usage();
46+ getopts(" b:C:dDhiI:l :mM:o:rs:t:T:uv" ) or usage();
4547usage if $opt_h ;
4648
4749my $tag_name = $opt_t || " tags" ;
@@ -130,6 +132,24 @@ sub file {
130132 return ($name , $mode );
131133}
132134
135+ sub ignore {
136+ my ($self ,$path ,$rev ) = @_ ;
137+
138+ print " ... $rev $path ...\n " if $opt_v ;
139+ my (undef ,undef ,$properties )
140+ = $self -> {' svn' }-> get_dir($path ,$rev ,undef );
141+ if (exists $properties -> {' svn:ignore' }) {
142+ my ($fh , $name ) = tempfile(' gitsvn.XXXXXX' ,
143+ DIR => File::Spec-> tmpdir(),
144+ UNLINK => 1);
145+ print $fh $properties -> {' svn:ignore' };
146+ close ($fh );
147+ return $name ;
148+ } else {
149+ return undef ;
150+ }
151+ }
152+
133153package main ;
134154use URI;
135155
@@ -341,6 +361,34 @@ ($$$)
341361 return [$mode , $sha , $path ];
342362}
343363
364+ sub get_ignore ($$$$$) {
365+ my ($new ,$old ,$rev ,$branch ,$path ) = @_ ;
366+
367+ return unless $opt_I ;
368+ my $svnpath = revert_split_path($branch ,$path );
369+ my $name = $svn -> ignore(" $svnpath " ,$rev );
370+ if ($path eq ' /' ) {
371+ $path = $opt_I ;
372+ } else {
373+ $path = File::Spec-> catfile($path ,$opt_I );
374+ }
375+ if (defined $name ) {
376+ my $pid = open (my $F , ' -|' );
377+ die $! unless defined $pid ;
378+ if (!$pid ) {
379+ exec (" git-hash-object" , " -w" , $name )
380+ or die " Cannot create object: $! \n " ;
381+ }
382+ my $sha = <$F >;
383+ chomp $sha ;
384+ close $F ;
385+ unlink $name ;
386+ push (@$new ,[' 0644' ,$sha ,$path ]);
387+ } else {
388+ push (@$old ,$path );
389+ }
390+ }
391+
344392sub split_path ($$) {
345393 my ($rev ,$path ) = @_ ;
346394 my $branch ;
@@ -546,6 +594,9 @@ sub commit {
546594 my $opath = $action -> [3];
547595 print STDERR " $revision : $branch : could not fetch '$opath '\n " ;
548596 }
597+ } elsif ($node_kind eq $SVN::Node::dir ) {
598+ get_ignore(\@new , \@old , $revision ,
599+ $branch ,$path );
549600 }
550601 } elsif ($action -> [0] eq " D" ) {
551602 push (@old ,$path );
@@ -554,6 +605,9 @@ sub commit {
554605 if ($node_kind eq $SVN::Node::file ) {
555606 my $f = get_file($revision ,$branch ,$path );
556607 push (@new ,$f ) if $f ;
608+ } elsif ($node_kind eq $SVN::Node::dir ) {
609+ get_ignore(\@new , \@old , $revision ,
610+ $branch ,$path );
557611 }
558612 } else {
559613 die " $revision : unknown action '" .$action -> [0]." ' for $path \n " ;
0 commit comments