diff options
Diffstat (limited to 'git-svn.perl')
-rwxr-xr-x | git-svn.perl | 97 |
1 files changed, 62 insertions, 35 deletions
diff --git a/git-svn.perl b/git-svn.perl index d0866946ce..7349ffea5a 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -61,8 +61,6 @@ my $cmd_dir_prefix = eval { command_oneline([qw/rev-parse --show-prefix/], STDERR => 0) } || ''; -my $git_dir_user_set = 1 if defined $ENV{GIT_DIR}; -$ENV{GIT_DIR} ||= '.git'; $Git::SVN::Ra::_log_window_size = 100; if (! exists $ENV{SVN_SSH} && exists $ENV{GIT_SSH}) { @@ -115,7 +113,7 @@ my ($_stdin, $_help, $_edit, $_template, $_shared, $_version, $_fetch_all, $_no_rebase, $_fetch_parent, $_before, $_after, - $_merge, $_strategy, $_preserve_merges, $_dry_run, $_local, + $_merge, $_strategy, $_preserve_merges, $_dry_run, $_parents, $_local, $_prefix, $_no_checkout, $_url, $_verbose, $_commit_url, $_tag, $_merge_info, $_interactive); @@ -128,6 +126,7 @@ 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' => \$Git::SVN::Fetcher::_ignore_regex, + 'include-paths=s' => \$Git::SVN::Fetcher::_include_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, @@ -204,6 +203,7 @@ my %cmd = ( { 'message|m=s' => \$_message, 'destination|d=s' => \$_branch_dest, 'dry-run|n' => \$_dry_run, + 'parents' => \$_parents, 'tag|t' => \$_tag, 'username=s' => \$Git::SVN::Prompt::_username, 'commit-url=s' => \$_commit_url } ], @@ -212,6 +212,7 @@ my %cmd = ( { 'message|m=s' => \$_message, 'destination|d=s' => \$_branch_dest, 'dry-run|n' => \$_dry_run, + 'parents' => \$_parents, 'username=s' => \$Git::SVN::Prompt::_username, 'commit-url=s' => \$_commit_url } ], 'set-tree' => [ \&cmd_set_tree, @@ -327,27 +328,20 @@ for (my $i = 0; $i < @ARGV; $i++) { }; # make sure we're always running at the top-level working directory -unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) { - unless (-d $ENV{GIT_DIR}) { - if ($git_dir_user_set) { - die "GIT_DIR=$ENV{GIT_DIR} explicitly set, ", - "but it is not a directory\n"; - } - my $git_dir = delete $ENV{GIT_DIR}; - my $cdup = undef; - git_cmd_try { - $cdup = command_oneline(qw/rev-parse --show-cdup/); - $git_dir = '.' unless ($cdup); - chomp $cdup if ($cdup); - $cdup = "." unless ($cdup && length $cdup); - } "Already at toplevel, but $git_dir not found\n"; - chdir $cdup or die "Unable to chdir up to '$cdup'\n"; - unless (-d $git_dir) { - die "$git_dir still not found after going to ", - "'$cdup'\n"; - } - $ENV{GIT_DIR} = $git_dir; - } +if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) { + $ENV{GIT_DIR} ||= ".git"; +} else { + my ($git_dir, $cdup); + git_cmd_try { + $git_dir = command_oneline([qw/rev-parse --git-dir/]); + } "Unable to find .git directory\n"; + git_cmd_try { + $cdup = command_oneline(qw/rev-parse --show-cdup/); + chomp $cdup if ($cdup); + $cdup = "." unless ($cdup && length $cdup); + } "Already at toplevel, but $git_dir not found\n"; + $ENV{GIT_DIR} = $git_dir; + chdir $cdup or die "Unable to chdir up to '$cdup'\n"; $_repository = Git->repository(Repository => $ENV{GIT_DIR}); } @@ -391,7 +385,7 @@ sub usage { my $fd = $exit ? \*STDERR : \*STDOUT; print $fd <<""; git-svn - bidirectional operations between a single Subversion tree and git -Usage: git svn <command> [options] [arguments]\n +usage: git svn <command> [options] [arguments]\n print $fd "Available commands:\n" unless $cmd; @@ -479,6 +473,9 @@ sub do_git_init_db { my $ignore_paths_regex = \$Git::SVN::Fetcher::_ignore_regex; command_noisy('config', "$pfx.ignore-paths", $$ignore_paths_regex) if defined $$ignore_paths_regex; + my $include_paths_regex = \$Git::SVN::Fetcher::_include_regex; + command_noisy('config', "$pfx.include-paths", $$include_paths_regex) + if defined $$include_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; @@ -543,7 +540,7 @@ sub cmd_fetch { } my ($remote) = @_; if (@_ > 1) { - die "Usage: $0 fetch [--all] [--parent] [svn-remote]\n"; + die "usage: $0 fetch [--all] [--parent] [svn-remote]\n"; } $Git::SVN::no_reuse_existing = undef; if ($_fetch_parent) { @@ -678,12 +675,14 @@ sub merge_revs_into_hash { } sub merge_merge_info { - my ($mergeinfo_one, $mergeinfo_two) = @_; + my ($mergeinfo_one, $mergeinfo_two, $ignore_branch) = @_; my %result_hash = (); merge_revs_into_hash(\%result_hash, $mergeinfo_one); merge_revs_into_hash(\%result_hash, $mergeinfo_two); + delete $result_hash{$ignore_branch} if $ignore_branch; + my $result = ''; # Sort below is for consistency's sake for my $branchname (sort keys(%result_hash)) { @@ -704,6 +703,7 @@ sub populate_merge_info { my $all_parents_ok = 1; my $aggregate_mergeinfo = ''; my $rooturl = $gs->repos_root; + my ($target_branch) = $gs->full_pushurl =~ /^\Q$rooturl\E(.*)/; if (defined($rewritten_parent)) { # Replace first parent with newly-rewritten version @@ -735,7 +735,8 @@ sub populate_merge_info { # Merge previous mergeinfo values $aggregate_mergeinfo = merge_merge_info($aggregate_mergeinfo, - $par_mergeinfo, 0); + $par_mergeinfo, + $target_branch); next if $parent eq $parents[0]; # Skip first parent # Add new changes being placed in tree by merge @@ -778,7 +779,8 @@ sub populate_merge_info { my $newmergeinfo = "$branchpath:" . join(',', @revsin); $aggregate_mergeinfo = merge_merge_info($aggregate_mergeinfo, - $newmergeinfo, 1); + $newmergeinfo, + $target_branch); } if ($all_parents_ok and $aggregate_mergeinfo) { return $aggregate_mergeinfo; @@ -829,7 +831,7 @@ sub dcommit_rebase { sub cmd_dcommit { my $head = shift; command_noisy(qw/update-index --refresh/); - git_cmd_try { command_oneline(qw/diff-index --quiet HEAD/) } + git_cmd_try { command_oneline(qw/diff-index --quiet HEAD --/) } 'Cannot dcommit with a dirty index. Commit your changes first, ' . "or stash them with `git stash'.\n"; $head ||= 'HEAD'; @@ -1172,6 +1174,10 @@ sub cmd_branch { $ctx->ls($dst, 'HEAD', 0); } and die "branch ${branch_name} already exists\n"; + if ($_parents) { + mk_parent_dirs($ctx, $dst); + } + print "Copying ${src} at r${rev} to ${dst}...\n"; $ctx->copy($src, $rev, $dst) unless $_dry_run; @@ -1179,6 +1185,17 @@ sub cmd_branch { $gs->fetch_all; } +sub mk_parent_dirs { + my ($ctx, $parent) = @_; + $parent =~ s{/[^/]*$}{}; + + if (!eval{$ctx->ls($parent, 'HEAD', 0)}) { + mk_parent_dirs($ctx, $parent); + print "Creating parent folder ${parent} ...\n"; + $ctx->mkdir($parent) unless $_dry_run; + } +} + sub cmd_find_rev { my $revision_or_hash = shift or die "SVN or git revision required ", "as a command-line argument\n"; @@ -1229,7 +1246,7 @@ sub cmd_rebase { return; } if (command(qw/diff-index HEAD --/)) { - print STDERR "Cannot rebase with uncommited changes:\n"; + print STDERR "Cannot rebase with uncommitted changes:\n"; command_noisy('status'); exit 1; } @@ -1372,7 +1389,17 @@ sub cmd_multi_init { usage(1); } - $_prefix = '' unless defined $_prefix; + unless (defined $_prefix) { + $_prefix = ''; + warn <<EOF +WARNING: --prefix is not given, defaulting to empty prefix. + This is probably not what you want! In order to stay compatible + with regular remote-tracking refs, provide a prefix like + --prefix=origin/ (remember the trailing slash), which will cause + the SVN-tracking refs to be placed at refs/remotes/origin/*. +NOTE: In Git v2.0, the default prefix will change from empty to 'origin/'. +EOF + } if (defined $url) { $url = canonicalize_url($url); init_subdir(@_); @@ -1413,7 +1440,7 @@ sub cmd_multi_fetch { # this command is special because it requires no metadata sub cmd_commit_diff { my ($ta, $tb, $url) = @_; - my $usage = "Usage: $0 commit-diff -r<revision> ". + my $usage = "usage: $0 commit-diff -r<revision> ". "<tree-ish> <tree-ish> [<URL>]"; fatal($usage) if (!defined $ta || !defined $tb); my $svn_path = ''; @@ -1742,7 +1769,7 @@ sub get_commit_entry { my $msgbuf = ""; while (<$msg_fh>) { if (!$in_msg) { - $in_msg = 1 if (/^\s*$/); + $in_msg = 1 if (/^$/); $author = $1 if (/^author (.*>)/); } elsif (/^git-svn-id: /) { # skip this for now, we regenerate the @@ -1915,7 +1942,7 @@ sub cmt_sha2rev_batch { sub working_head_info { my ($head, $refs) = @_; my @args = qw/rev-list --first-parent --pretty=medium/; - my ($fh, $ctx) = command_output_pipe(@args, $head); + my ($fh, $ctx) = command_output_pipe(@args, $head, "--"); my $hash; my %max; while (<$fh>) { |