Merge branch 'svn-maint-fixes' into svn-fixes
authorJunio C Hamano <gitster@pobox.com>
Thu, 26 Feb 2015 22:03:57 +0000 (14:03 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Feb 2015 22:03:57 +0000 (14:03 -0800)
* svn-maint-fixes:
Git::SVN::*: avoid premature FileHandle closure
git-svn: fix localtime=true on non-glibc environments

1  2 
perl/Git/SVN.pm
perl/Git/SVN/Fetcher.pm
perl/Git/SVN/Ra.pm
diff --combined perl/Git/SVN.pm
index afa562c8b9f8129e76b2cd7c9568ba1b3dfa06df,7006219c0a386f59030f6a08810abfeb211a0da2..152fb7e9274c779cb66de099878b4de40e5406e4
@@@ -9,9 -9,12 +9,10 @@@ use vars qw/$_no_metadat
            $_use_log_author $_add_author_from $_localtime/;
  use Carp qw/croak/;
  use File::Path qw/mkpath/;
 -use File::Copy qw/copy/;
  use IPC::Open3;
  use Memoize;  # core since 5.8.0, Jul 2002
 -use Memoize::Storable;
  use POSIX qw(:signal_h);
+ use Time::Local;
  
  use Git qw(
      command
@@@ -30,7 -33,11 +31,7 @@@ use Git::SVN::Utils qw
        add_path_to_url
  );
  
 -my $can_use_yaml;
 -BEGIN {
 -      $can_use_yaml = eval { require Git::SVN::Memoize::YAML; 1};
 -}
 -
 +my $memo_backend;
  our $_follow_parent  = 1;
  our $_minimize_url   = 'unset';
  our $default_repo_id = 'svn';
@@@ -1326,7 -1333,7 +1327,7 @@@ sub parse_svn_date 
                $ENV{TZ} = 'UTC';
  
                my $epoch_in_UTC =
-                   POSIX::strftime('%s', $S, $M, $H, $d, $m - 1, $Y - 1900);
+                   Time::Local::timelocal($S, $M, $H, $d, $m - 1, $Y - 1900);
  
                # Determine our local timezone (including DST) at the
                # time of $epoch_in_UTC.  $Git::SVN::Log::TZ stored the
@@@ -1572,16 -1579,7 +1573,16 @@@ sub tie_for_persistent_memoization 
        my $hash = shift;
        my $path = shift;
  
 -      if ($can_use_yaml) {
 +      unless ($memo_backend) {
 +              if (eval { require Git::SVN::Memoize::YAML; 1}) {
 +                      $memo_backend = 1;
 +              } else {
 +                      require Memoize::Storable;
 +                      $memo_backend = -1;
 +              }
 +      }
 +
 +      if ($memo_backend > 0) {
                tie %$hash => 'Git::SVN::Memoize::YAML', "$path.yaml";
        } else {
                tie %$hash => 'Memoize::Storable', "$path.db", 'nstore';
@@@ -2191,9 -2189,8 +2192,9 @@@ sub rev_map_set 
        # both of these options make our .rev_db file very, very important
        # and we can't afford to lose it because rebuild() won't work
        if ($self->use_svm_props || $self->no_metadata) {
 +              require File::Copy;
                $sync = 1;
 -              copy($db, $db_lock) or die "rev_map_set(@_): ",
 +              File::Copy::copy($db, $db_lock) or die "rev_map_set(@_): ",
                                           "Failed to copy: ",
                                           "$db => $db_lock ($!)\n";
        } else {
@@@ -2369,7 -2366,7 +2370,7 @@@ sub _new 
  
        # Older repos imported by us used $GIT_DIR/svn/foo instead of
        # $GIT_DIR/svn/refs/remotes/foo when tracking refs/remotes/foo
 -      if ($ref_id =~ m{^refs/remotes/(.*)}) {
 +      if ($ref_id =~ m{^refs/remotes/(.+)}) {
                my $old_dir = "$ENV{GIT_DIR}/svn/$1";
                if (-d $old_dir && ! -d $dir) {
                        $dir = $old_dir;
diff --combined perl/Git/SVN/Fetcher.pm
index 6b9c6e01386fee3756298fcb4d580a478158302f,613055a3f5f794d02644e32dbaf91f907836b396..d8c21ad91549b4e52ce95c5e694db2f53f9931c9
@@@ -7,6 -7,7 +7,6 @@@ use warnings
  use SVN::Delta;
  use Carp qw/croak/;
  use File::Basename qw/dirname/;
 -use IO::File qw//;
  use Git qw/command command_oneline command_noisy command_output_pipe
             command_input_pipe command_close_pipe
             command_bidi_pipe command_close_bidi_pipe/;
@@@ -321,6 -322,14 +321,14 @@@ sub apply_textdelta 
        # (but $base does not,) so dup() it for reading in close_file
        open my $dup, '<&', $fh or croak $!;
        my $base = $::_repository->temp_acquire("git_blob_${$}_$suffix");
+       # close_file may call temp_acquire on 'svn_hash', but because of the
+       # call chain, if the temp_acquire call from close_file ends up being the
+       # call that first creates the 'svn_hash' temp file, then the FileHandle
+       # that's created as a result will end up in an SVN::Pool that we clear
+       # in SVN::Ra::gs_fetch_loop_common.  Avoid that by making sure the
+       # 'svn_hash' FileHandle is already created before close_file is called.
+       my $tmp_fh = $::_repository->temp_acquire('svn_hash');
+       $::_repository->temp_release($tmp_fh, 1);
  
        if ($fb->{blob}) {
                my ($base_is_link, $size);
@@@ -599,7 -608,7 +607,7 @@@ developing git-svn
  =head1 DEPENDENCIES
  
  L<SVN::Delta> from the Subversion perl bindings,
 -the core L<Carp>, L<File::Basename>, and L<IO::File> modules,
 +the core L<Carp> and L<File::Basename> modules,
  and git's L<Git> helper module.
  
  C<Git::SVN::Fetcher> has not been tested using callers other than
diff --combined perl/Git/SVN/Ra.pm
index cf36b9d3cdde67f03f147d596f8f277ea11ba302,32e2f19ea41b2dfed735cf1fa5e1fa49f3fed915..4a499fcb38daf4ab8d3e20ca0fa10e5732e684a9
@@@ -3,6 -3,7 +3,6 @@@ use vars qw/@ISA $config_dir $_ignore_r
  use strict;
  use warnings;
  use Memoize;
 -use SVN::Client;
  use Git::SVN::Utils qw(
        canonicalize_url
        canonicalize_path
@@@ -41,7 -42,6 +41,7 @@@ END 
  }
  
  sub _auth_providers () {
 +      require SVN::Client;
        my @rv = (
          SVN::Client::get_simple_provider(),
          SVN::Client::get_ssl_server_trust_file_provider(),
@@@ -247,10 -247,7 +247,10 @@@ sub get_log 
        $ret;
  }
  
 +# uncommon, only for ancient SVN (<= 1.4.2)
  sub trees_match {
 +      require IO::File;
 +      require SVN::Client;
        my ($self, $url1, $rev1, $url2, $rev2) = @_;
        my $ctx = SVN::Client->new(auth => _auth_providers);
        my $out = IO::File->new_tmpfile;
@@@ -394,6 -391,9 +394,9 @@@ sub longest_common_path 
  sub gs_fetch_loop_common {
        my ($self, $base, $head, $gsv, $globs) = @_;
        return if ($base > $head);
+       # Make sure the cat_blob open2 FileHandle is created before calling
+       # SVN::Pool::new_default so that it does not incorrectly end up in the pool.
+       $::_repository->_open_cat_blob_if_needed;
        my $gpool = SVN::Pool->new_default;
        my $ra_url = $self->url;
        my $reload_ra = sub {