Imported Upstream version 2.25.1
[platform/upstream/git.git] / git-svn.perl
index fa5f253..4aa208f 100755 (executable)
@@ -44,6 +44,7 @@ use Git qw(
        command_close_pipe
        command_bidi_pipe
        command_close_bidi_pipe
+       get_record
 );
 
 BEGIN {
@@ -109,7 +110,7 @@ my ($_stdin, $_help, $_edit,
        $_template, $_shared,
        $_version, $_fetch_all, $_no_rebase, $_fetch_parent,
        $_before, $_after,
-       $_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local,
+       $_merge, $_strategy, $_rebase_merges, $_dry_run, $_parents, $_local,
        $_prefix, $_no_checkout, $_url, $_verbose,
        $_commit_url, $_tag, $_merge_info, $_interactive, $_set_svn_props);
 
@@ -269,7 +270,8 @@ my %cmd = (
                          'local|l' => \$_local,
                          'fetch-all|all' => \$_fetch_all,
                          'dry-run|n' => \$_dry_run,
-                         'preserve-merges|p' => \$_preserve_merges,
+                         'rebase-merges|p' => \$_rebase_merges,
+                         'preserve-merges|p' => \$_rebase_merges,
                          %fc_opts } ],
        'commit-diff' => [ \&cmd_commit_diff,
                           'Commit a diff between two trees',
@@ -339,7 +341,7 @@ if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
                        die "failed to open $ENV{GIT_DIR}: $!\n";
                $ENV{GIT_DIR} = $1 if <$fh> =~ /^gitdir: (.+)$/;
        }
-} else {
+} elsif ($cmd) {
        my ($git_dir, $cdup);
        git_cmd_try {
                $git_dir = command_oneline([qw/rev-parse --git-dir/]);
@@ -356,7 +358,7 @@ if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
 
 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
 
-read_git_config(\%opts);
+read_git_config(\%opts) if $ENV{GIT_DIR};
 if ($cmd && ($cmd eq 'log' || $cmd eq 'blame')) {
        Getopt::Long::Configure('pass_through');
 }
@@ -373,7 +375,8 @@ version() if $_version;
 usage(1) unless defined $cmd;
 load_authors() if $_authors;
 if (defined $_authors_prog) {
-       $_authors_prog = "'" . File::Spec->rel2abs($_authors_prog) . "'";
+       my $abs_file = File::Spec->rel2abs($_authors_prog);
+       $_authors_prog = "'" . $abs_file . "'" if -x $abs_file;
 }
 
 unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
@@ -507,7 +510,10 @@ sub init_subdir {
 
 sub cmd_clone {
        my ($url, $path) = @_;
-       if (!defined $path &&
+       if (!$url) {
+               die "SVN repository location required ",
+                   "as a command-line argument\n";
+       } elsif (!defined $path &&
            (defined $_trunk || @_branches || @_tags ||
             defined $_stdlayout) &&
            $url !~ m#^[a-z\+]+://#) {
@@ -927,6 +933,7 @@ sub cmd_dcommit {
                # information from different SVN repos, and paths
                # which are not underneath this repository root.
                my $rooturl = $gs->repos_root;
+               Git::SVN::remove_username($rooturl);
                foreach my $d (@$linear_refs) {
                        my %parentshash;
                        read_commit_parents(\%parentshash, $d);
@@ -1048,7 +1055,7 @@ sub cmd_dcommit {
                                          'If you are attempting to commit ',
                                          "merges, try running:\n\t",
                                          'git rebase --interactive',
-                                         '--preserve-merges ',
+                                         '--rebase-merges ',
                                          $gs->refname,
                                          "\nBefore dcommitting";
                                }
@@ -1171,10 +1178,10 @@ sub cmd_branch {
        ::_req_svn();
        require SVN::Client;
 
+       my ($config, $baton, undef) = Git::SVN::Ra::prepare_config_once();
        my $ctx = SVN::Client->new(
-               config => SVN::Core::config_get_config(
-                       $Git::SVN::Ra::config_dir
-               ),
+               auth => $baton,
+               config => $config,
                log_msg => sub {
                        ${ $_[0] } = defined $_message
                                ? $_message
@@ -1195,6 +1202,11 @@ sub cmd_branch {
        $ctx->copy($src, $rev, $dst)
                unless $_dry_run;
 
+       # Release resources held by ctx before creating another SVN::Ra
+       # so destruction is orderly.  This seems necessary with SVN 1.9.5
+       # to avoid segfaults.
+       $ctx = undef;
+
        $gs->fetch_all;
 }
 
@@ -1696,7 +1708,7 @@ sub cmd_gc {
                     "files will not be compressed.\n";
        }
        File::Find::find({ wanted => \&gc_directory, no_chdir => 1},
-                        "$ENV{GIT_DIR}/svn");
+                        Git::SVN::svn_dir());
 }
 
 ########################### utility functions #########################
@@ -1706,7 +1718,7 @@ sub rebase_cmd {
        push @cmd, '-v' if $_verbose;
        push @cmd, qw/--merge/ if $_merge;
        push @cmd, "--strategy=$_strategy" if $_strategy;
-       push @cmd, "--preserve-merges" if $_preserve_merges;
+       push @cmd, "--rebase-merges" if $_rebase_merges;
        @cmd;
 }
 
@@ -1730,7 +1742,7 @@ sub post_fetch_checkout {
        return unless verify_ref('HEAD^0');
 
        return if $ENV{GIT_DIR} !~ m#^(?:.*/)?\.git$#;
-       my $index = $ENV{GIT_INDEX_FILE} || "$ENV{GIT_DIR}/index";
+       my $index = command_oneline(qw(rev-parse --git-path index));
        return if -f $index;
 
        return if command_oneline(qw/rev-parse --is-inside-work-tree/) eq 'false';
@@ -1745,11 +1757,12 @@ sub post_fetch_checkout {
 
 sub complete_svn_url {
        my ($url, $path) = @_;
-       $path = canonicalize_path($path);
 
-       # If the path is not a URL...
-       if ($path !~ m#^[a-z\+]+://#) {
-               if (!defined $url || $url !~ m#^[a-z\+]+://#) {
+       if ($path =~ m#^[a-z\+]+://#i) { # path is a URL
+               $path = canonicalize_url($path);
+       } else {
+               $path = canonicalize_path($path);
+               if (!defined $url || $url !~ m#^[a-z\+]+://#i) {
                        fatal("E: '$path' is not a complete URL ",
                              "and a separate URL is not specified");
                }
@@ -1764,11 +1777,12 @@ sub complete_url_ls_init {
                print STDERR "W: $switch not specified\n";
                return;
        }
-       $repo_path = canonicalize_path($repo_path);
-       if ($repo_path =~ m#^[a-z\+]+://#) {
+       if ($repo_path =~ m#^[a-z\+]+://#i) {
+               $repo_path = canonicalize_url($repo_path);
                $ra = Git::SVN::Ra->new($repo_path);
                $repo_path = '';
        } else {
+               $repo_path = canonicalize_path($repo_path);
                $repo_path =~ s#^/+##;
                unless ($ra) {
                        fatal("E: '$repo_path' is not a complete URL ",
@@ -1830,8 +1844,9 @@ sub get_tree_from_treeish {
 sub get_commit_entry {
        my ($treeish) = shift;
        my %log_entry = ( log => '', tree => get_tree_from_treeish($treeish) );
-       my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG";
-       my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG";
+       my @git_path = qw(rev-parse --git-path);
+       my $commit_editmsg = command_oneline(@git_path, 'COMMIT_EDITMSG');
+       my $commit_msg = command_oneline(@git_path, 'COMMIT_MSG');
        open my $log_fh, '>', $commit_editmsg or croak $!;
 
        my $type = command_oneline(qw/cat-file -t/, $treeish);
@@ -1858,6 +1873,7 @@ sub get_commit_entry {
                        }
                }
                $msgbuf =~ s/\s+$//s;
+               $msgbuf =~ s/\r\n/\n/sg; # SVN 1.6+ disallows CRLF
                if ($Git::SVN::_add_author_from && defined($author)
                    && !$saw_from) {
                        $msgbuf .= "\n\nFrom: $author";
@@ -1875,10 +1891,9 @@ sub get_commit_entry {
        {
                require Encode;
                # SVN requires messages to be UTF-8 when entering the repo
-               local $/;
                open $log_fh, '<', $commit_msg or croak $!;
                binmode $log_fh;
-               chomp($log_entry{log} = <$log_fh>);
+               chomp($log_entry{log} = get_record($log_fh, undef));
 
                my $enc = Git::config('i18n.commitencoding') || 'UTF-8';
                my $msg = $log_entry{log};