Merge branch 'pt/mingw-misc-fixes'
authorJunio C Hamano <gitster@pobox.com>
Wed, 19 Oct 2011 04:59:11 +0000 (21:59 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 19 Oct 2011 04:59:11 +0000 (21:59 -0700)
* pt/mingw-misc-fixes:
t9901: fix line-ending dependency on windows
mingw: ensure sockets are initialized before calling gethostname
mergetools: use the correct tool for Beyond Compare 3 on Windows
t9300: do not run --cat-blob-fd related tests on MinGW
git-svn: On MSYS, escape and quote SVN_SSH also if set by the user
t9001: do not fail only due to CR/LF issues
t1020: disable the pwd test on MinGW

1  2 
compat/mingw.c
git-svn.perl
diff --combined compat/mingw.c
index 8947418ce78faa3619779c12319c0dd99b1557d3,8e17daeac3dee79cedf0aeed73527d16f27e4527..efdc703257c9589018e59dc5bc93e9980e0f30b6
@@@ -1183,7 -1183,7 +1183,7 @@@ static int WSAAPI getaddrinfo_stub(cons
        }
        ai->ai_addrlen = sizeof(struct sockaddr_in);
        if (hints && (hints->ai_flags & AI_CANONNAME))
 -              ai->ai_canonname = h ? strdup(h->h_name) : NULL;
 +              ai->ai_canonname = h ? xstrdup(h->h_name) : NULL;
        else
                ai->ai_canonname = NULL;
  
@@@ -1321,6 -1321,13 +1321,13 @@@ static void ensure_socket_initializatio
        initialized = 1;
  }
  
+ #undef gethostname
+ int mingw_gethostname(char *name, int namelen)
+ {
+     ensure_socket_initialization();
+     return gethostname(name, namelen);
+ }
  #undef gethostbyname
  struct hostent *mingw_gethostbyname(const char *host)
  {
diff --combined git-svn.perl
index b608bbf95a9c9530af4151c3077f4fe32f3a3340,3b333794736adad0e1651cf55b2bd579315e5fab..b67fef0bf69da170a5a9748b9da8c31c6e1ca5c7
@@@ -22,14 -22,13 +22,13 @@@ $Git::SVN::default_ref_id = $ENV{GIT_SV
  $Git::SVN::Ra::_log_window_size = 100;
  $Git::SVN::_minimize_url = 'unset';
  
- if (! exists $ENV{SVN_SSH}) {
-       if (exists $ENV{GIT_SSH}) {
-               $ENV{SVN_SSH} = $ENV{GIT_SSH};
-               if ($^O eq 'msys') {
-                       $ENV{SVN_SSH} =~ s/\\/\\\\/g;
-                       $ENV{SVN_SSH} =~ s/(.*)/"$1"/;
-               }
-       }
+ if (! exists $ENV{SVN_SSH} && exists $ENV{GIT_SSH}) {
+       $ENV{SVN_SSH} = $ENV{GIT_SSH};
+ }
+ if (exists $ENV{SVN_SSH} && $^O eq 'msys') {
+       $ENV{SVN_SSH} =~ s/\\/\\\\/g;
+       $ENV{SVN_SSH} =~ s/(.*)/"$1"/;
  }
  
  $Git::SVN::Log::TZ = $ENV{TZ};
@@@ -87,15 -86,14 +86,15 @@@ my ($_stdin, $_help, $_edit
        $_version, $_fetch_all, $_no_rebase, $_fetch_parent,
        $_merge, $_strategy, $_dry_run, $_local,
        $_prefix, $_no_checkout, $_url, $_verbose,
 -      $_git_format, $_commit_url, $_tag, $_merge_info);
 +      $_git_format, $_commit_url, $_tag, $_merge_info, $_interactive);
  $Git::SVN::_follow_parent = 1;
  $SVN::Git::Fetcher::_placeholder_filename = ".gitignore";
  $_q ||= 0;
  my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
                      'config-dir=s' => \$Git::SVN::Ra::config_dir,
                      'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache,
 -                    'ignore-paths=s' => \$SVN::Git::Fetcher::_ignore_regex );
 +                    'ignore-paths=s' => \$SVN::Git::Fetcher::_ignore_regex,
 +                    'ignore-refs=s' => \$Git::SVN::Ra::_ignore_refs_regex );
  my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
                'authors-file|A=s' => \$_authors,
                'authors-prog=s' => \$_authors_prog,
@@@ -164,7 -162,6 +163,7 @@@ my %cmd = 
                          'revision|r=i' => \$_revision,
                          'no-rebase' => \$_no_rebase,
                          'mergeinfo=s' => \$_merge_info,
 +                        'interactive|i' => \$_interactive,
                        %cmt_opts, %fc_opts } ],
        branch => [ \&cmd_branch,
                    'Create a branch in the SVN repository',
                {} ],
  );
  
 +use Term::ReadLine;
 +package FakeTerm;
 +sub new {
 +      my ($class, $reason) = @_;
 +      return bless \$reason, shift;
 +}
 +sub readline {
 +      my $self = shift;
 +      die "Cannot use readline on FakeTerm: $$self";
 +}
 +package main;
 +
 +my $term = eval {
 +      $ENV{"GIT_SVN_NOTTY"}
 +              ? new Term::ReadLine 'git-svn', \*STDIN, \*STDOUT
 +              : new Term::ReadLine 'git-svn';
 +};
 +if ($@) {
 +      $term = new FakeTerm "$@: going non-interactive";
 +}
 +
  my $cmd;
  for (my $i = 0; $i < @ARGV; $i++) {
        if (defined $cmd{$ARGV[$i]}) {
@@@ -389,36 -365,6 +388,36 @@@ sub version 
        exit 0;
  }
  
 +sub ask {
 +      my ($prompt, %arg) = @_;
 +      my $valid_re = $arg{valid_re};
 +      my $default = $arg{default};
 +      my $resp;
 +      my $i = 0;
 +
 +      if ( !( defined($term->IN)
 +            && defined( fileno($term->IN) )
 +            && defined( $term->OUT )
 +            && defined( fileno($term->OUT) ) ) ){
 +              return defined($default) ? $default : undef;
 +      }
 +
 +      while ($i++ < 10) {
 +              $resp = $term->readline($prompt);
 +              if (!defined $resp) { # EOF
 +                      print "\n";
 +                      return defined $default ? $default : undef;
 +              }
 +              if ($resp eq '' and defined $default) {
 +                      return $default;
 +              }
 +              if (!defined $valid_re or $resp =~ /$valid_re/) {
 +                      return $resp;
 +              }
 +      }
 +      return undef;
 +}
 +
  sub do_git_init_db {
        unless (-d $ENV{GIT_DIR}) {
                my @init_db = ('init');
                command_noisy('config', "$pfx.$i", $icv{$i});
                $set = $i;
        }
 -      my $ignore_regex = \$SVN::Git::Fetcher::_ignore_regex;
 -      command_noisy('config', "$pfx.ignore-paths", $$ignore_regex)
 -              if defined $$ignore_regex;
 +      my $ignore_paths_regex = \$SVN::Git::Fetcher::_ignore_regex;
 +      command_noisy('config', "$pfx.ignore-paths", $$ignore_paths_regex)
 +              if defined $$ignore_paths_regex;
 +      my $ignore_refs_regex = \$Git::SVN::Ra::_ignore_refs_regex;
 +      command_noisy('config', "$pfx.ignore-refs", $$ignore_refs_regex)
 +              if defined $$ignore_refs_regex;
  
        if (defined $SVN::Git::Fetcher::_preserve_empty_dirs) {
                my $fname = \$SVN::Git::Fetcher::_placeholder_filename;
@@@ -802,27 -745,6 +801,27 @@@ sub cmd_dcommit 
                     "If these changes depend on each other, re-running ",
                     "without --no-rebase may be required."
        }
 +
 +      if (defined $_interactive){
 +              my $ask_default = "y";
 +              foreach my $d (@$linear_refs){
 +                      my ($fh, $ctx) = command_output_pipe(qw(show --summary), "$d");
 +                      while (<$fh>){
 +                              print $_;
 +                      }
 +                      command_close_pipe($fh, $ctx);
 +                      $_ = ask("Commit this patch to SVN? ([y]es (default)|[n]o|[q]uit|[a]ll): ",
 +                               valid_re => qr/^(?:yes|y|no|n|quit|q|all|a)/i,
 +                               default => $ask_default);
 +                      die "Commit this patch reply required" unless defined $_;
 +                      if (/^[nq]/i) {
 +                              exit(0);
 +                      } elsif (/^a/i) {
 +                              last;
 +                      }
 +              }
 +      }
 +
        my $expect_url = $url;
  
        my $push_merge_info = eval {
@@@ -2196,8 -2118,6 +2195,8 @@@ sub read_all_remotes 
                        $r->{$1}->{url} = $2;
                } elsif (m!^(.+)\.pushurl=\s*(.*)\s*$!) {
                        $r->{$1}->{pushurl} = $2;
 +              } elsif (m!^(.+)\.ignore-refs=\s*(.*)\s*$!) {
 +                      $r->{$1}->{ignore_refs_regex} = $2;
                } elsif (m!^(.+)\.(branches|tags)=$svn_refspec$!) {
                        my ($remote, $t, $local_ref, $remote_ref) =
                                                             ($1, $2, $3, $4);
                }
        } keys %$r;
  
 +      foreach my $remote (keys %$r) {
 +              foreach ( grep { defined $_ }
 +                        map { $r->{$remote}->{$_} } qw(branches tags) ) {
 +                      foreach my $rs ( @$_ ) {
 +                              $rs->{ignore_refs_regex} =
 +                                  $r->{$remote}->{ignore_refs_regex};
 +                      }
 +              }
 +      }
 +
        $r;
  }
  
@@@ -5399,7 -5309,7 +5398,7 @@@ sub apply_diff 
  }
  
  package Git::SVN::Ra;
 -use vars qw/@ISA $config_dir $_log_window_size/;
 +use vars qw/@ISA $config_dir $_ignore_refs_regex $_log_window_size/;
  use strict;
  use warnings;
  my ($ra_invalid, $can_do_switch, %ignored_err, $RA);
@@@ -5857,17 -5767,6 +5856,17 @@@ sub get_dir_globbed 
        @finalents;
  }
  
 +# return value: 0 -- don't ignore, 1 -- ignore
 +sub is_ref_ignored {
 +      my ($g, $p) = @_;
 +      my $refname = $g->{ref}->full_path($p);
 +      return 1 if defined($g->{ignore_refs_regex}) &&
 +                  $refname =~ m!$g->{ignore_refs_regex}!;
 +      return 0 unless defined($_ignore_refs_regex);
 +      return 1 if $refname =~ m!$_ignore_refs_regex!o;
 +      return 0;
 +}
 +
  sub match_globs {
        my ($self, $exists, $paths, $globs, $r) = @_;
  
                        next unless /$g->{path}->{regex}/;
                        my $p = $1;
                        my $pathname = $g->{path}->full_path($p);
 +                      next if is_ref_ignored($g, $p);
                        next if $exists->{$pathname};
                        next if ($self->check_path($pathname, $r) !=
                                 $SVN::Node::dir);