Imported Upstream version 2.12.3
[platform/upstream/git.git] / git-svn.perl
index 32d109e..fa42364 100755 (executable)
@@ -11,14 +11,10 @@ $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
 $VERSION = '@@GIT_VERSION@@';
 
 use Carp qw/croak/;
-use Digest::MD5;
-use IO::File qw//;
 use File::Basename qw/dirname basename/;
 use File::Path qw/mkpath/;
 use File::Spec;
-use File::Find;
 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
-use IPC::Open3;
 use Memoize;
 
 use Git::SVN;
@@ -48,6 +44,7 @@ use Git qw(
        command_close_pipe
        command_bidi_pipe
        command_close_bidi_pipe
+       get_record
 );
 
 BEGIN {
@@ -298,7 +295,6 @@ my %cmd = (
                {} ],
 );
 
-use Term::ReadLine;
 package FakeTerm;
 sub new {
        my ($class, $reason) = @_;
@@ -313,6 +309,7 @@ package main;
 my $term;
 sub term_init {
        $term = eval {
+               require Term::ReadLine;
                $ENV{"GIT_SVN_NOTTY"}
                        ? new Term::ReadLine 'git-svn', \*STDIN, \*STDOUT
                        : new Term::ReadLine 'git-svn';
@@ -343,7 +340,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/]);
@@ -360,7 +357,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');
 }
@@ -511,7 +508,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\+]+://#) {
@@ -1173,6 +1173,7 @@ sub cmd_branch {
        }
 
        ::_req_svn();
+       require SVN::Client;
 
        my $ctx = SVN::Client->new(
                config => SVN::Core::config_get_config(
@@ -1693,11 +1694,13 @@ sub cmd_reset {
 }
 
 sub cmd_gc {
+       require File::Find;
        if (!can_compress()) {
                warn "Compress::Zlib could not be found; unhandled.log " .
                     "files will not be compressed.\n";
        }
-       find({ wanted => \&gc_directory, no_chdir => 1}, "$ENV{GIT_DIR}/svn");
+       File::Find::find({ wanted => \&gc_directory, no_chdir => 1},
+                        Git::SVN::svn_dir());
 }
 
 ########################### utility functions #########################
@@ -1731,7 +1734,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';
@@ -1746,11 +1749,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");
                }
@@ -1765,11 +1769,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 ",
@@ -1831,8 +1836,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);
@@ -1876,10 +1882,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};
@@ -1925,7 +1930,7 @@ sub load_authors {
        my $log = $cmd eq 'log';
        while (<$authors>) {
                chomp;
-               next unless /^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/;
+               next unless /^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.*)>\s*$/;
                my ($user, $name, $email) = ($1, $2, $3);
                if ($log) {
                        $Git::SVN::Log::rusers{"$name <$email>"} = $user;
@@ -2122,6 +2127,7 @@ sub find_file_type_and_diff_status {
 sub md5sum {
        my $arg = shift;
        my $ref = ref $arg;
+       require Digest::MD5;
        my $md5 = Digest::MD5->new();
         if ($ref eq 'GLOB' || $ref eq 'IO::File' || $ref eq 'File::Temp') {
                $md5->addfile($arg) or croak $!;
@@ -2148,6 +2154,7 @@ sub gc_directory {
                        $gz->gzwrite($str) or
                                die "Unable to write: ".$gz->gzerror()."!\n";
                }
+               no warnings 'once'; # $File::Find::name would warn
                unlink $_ or die "unlink $File::Find::name: $!\n";
        } elsif (-f $_ && basename($_) eq "index") {
                unlink $_ or die "unlink $_: $!\n";