git-svn: convert multi-init over to using Git::SVN
Signed-off-by: Eric Wong <normalperson@yhbt.net>
This commit is contained in:
52
git-svn.perl
52
git-svn.perl
@ -133,7 +133,7 @@ my %cmd = (
|
|||||||
'branch-all-refs|B' => \$_branch_all_refs,
|
'branch-all-refs|B' => \$_branch_all_refs,
|
||||||
'no-default-regex' => \$_no_default_regex,
|
'no-default-regex' => \$_no_default_regex,
|
||||||
'no-graft-copy' => \$_no_graft_copy } ],
|
'no-graft-copy' => \$_no_graft_copy } ],
|
||||||
'multi-init' => [ \&multi_init,
|
'multi-init' => [ \&cmd_multi_init,
|
||||||
'Initialize multiple trees (like git-svnimport)',
|
'Initialize multiple trees (like git-svnimport)',
|
||||||
{ %multi_opts, %init_opts,
|
{ %multi_opts, %init_opts,
|
||||||
'revision|r=i' => \$_revision,
|
'revision|r=i' => \$_revision,
|
||||||
@ -278,6 +278,15 @@ sub rebuild {
|
|||||||
command_close_pipe($rev_list, $ctx);
|
command_close_pipe($rev_list, $ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub do_git_init_db {
|
||||||
|
unless (-d $ENV{GIT_DIR}) {
|
||||||
|
my @init_db = ('init');
|
||||||
|
push @init_db, "--template=$_template" if defined $_template;
|
||||||
|
push @init_db, "--shared" if defined $_shared;
|
||||||
|
command_noisy(@init_db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub cmd_init {
|
sub cmd_init {
|
||||||
my $url = shift or die "SVN repository location required " .
|
my $url = shift or die "SVN repository location required " .
|
||||||
"as a command-line argument\n";
|
"as a command-line argument\n";
|
||||||
@ -288,13 +297,8 @@ sub cmd_init {
|
|||||||
chdir $repo_path or croak $!;
|
chdir $repo_path or croak $!;
|
||||||
$ENV{GIT_DIR} = $repo_path . "/.git";
|
$ENV{GIT_DIR} = $repo_path . "/.git";
|
||||||
}
|
}
|
||||||
|
do_git_init_db();
|
||||||
|
|
||||||
unless (-d $ENV{GIT_DIR}) {
|
|
||||||
my @init_db = ('init');
|
|
||||||
push @init_db, "--template=$_template" if defined $_template;
|
|
||||||
push @init_db, "--shared" if defined $_shared;
|
|
||||||
command_noisy(@init_db);
|
|
||||||
}
|
|
||||||
Git::SVN->init(undef, $url);
|
Git::SVN->init(undef, $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,29 +579,22 @@ sub graft_branches {
|
|||||||
unlink "$gr_file~$gr_sha1" if $gr_sha1;
|
unlink "$gr_file~$gr_sha1" if $gr_sha1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub multi_init {
|
sub cmd_multi_init {
|
||||||
my $url = shift;
|
my $url = shift;
|
||||||
unless (defined $_trunk || defined $_branches || defined $_tags) {
|
unless (defined $_trunk || defined $_branches || defined $_tags) {
|
||||||
usage(1);
|
usage(1);
|
||||||
}
|
}
|
||||||
|
do_git_init_db();
|
||||||
|
$_prefix = '' unless defined $_prefix;
|
||||||
if (defined $_trunk) {
|
if (defined $_trunk) {
|
||||||
|
my $gs_trunk = eval { Git::SVN->new($_prefix . 'trunk') };
|
||||||
|
unless ($gs_trunk) {
|
||||||
my $trunk_url = complete_svn_url($url, $_trunk);
|
my $trunk_url = complete_svn_url($url, $_trunk);
|
||||||
my $ch_id;
|
$gs_trunk = Git::SVN->init($_prefix . 'trunk',
|
||||||
if ($GIT_SVN eq 'git-svn') {
|
$trunk_url);
|
||||||
$ch_id = 1;
|
|
||||||
$GIT_SVN = $ENV{GIT_SVN_ID} = 'trunk';
|
|
||||||
}
|
|
||||||
init_vars();
|
|
||||||
unless (-d $GIT_SVN_DIR) {
|
|
||||||
if ($ch_id) {
|
|
||||||
print "GIT_SVN_ID set to 'trunk' for ",
|
|
||||||
"$trunk_url ($_trunk)\n";
|
|
||||||
}
|
|
||||||
cmd_init($trunk_url);
|
|
||||||
command_noisy('config', 'svn.trunk', $trunk_url);
|
command_noisy('config', 'svn.trunk', $trunk_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$_prefix = '' unless defined $_prefix;
|
|
||||||
complete_url_ls_init($url, $_branches, '--branches/-b', $_prefix);
|
complete_url_ls_init($url, $_branches, '--branches/-b', $_prefix);
|
||||||
complete_url_ls_init($url, $_tags, '--tags/-t', $_prefix . 'tags/');
|
complete_url_ls_init($url, $_tags, '--tags/-t', $_prefix . 'tags/');
|
||||||
}
|
}
|
||||||
@ -900,8 +897,6 @@ sub complete_url_ls_init {
|
|||||||
}
|
}
|
||||||
my $full_url = complete_svn_url($url, $path);
|
my $full_url = complete_svn_url($url, $path);
|
||||||
my @ls = libsvn_ls_fullurl($full_url);
|
my @ls = libsvn_ls_fullurl($full_url);
|
||||||
defined(my $pid = fork) or croak $!;
|
|
||||||
if (!$pid) {
|
|
||||||
foreach my $u (map { "$full_url/$_" } (grep m!/$!, @ls)) {
|
foreach my $u (map { "$full_url/$_" } (grep m!/$!, @ls)) {
|
||||||
$u =~ s#/+$##;
|
$u =~ s#/+$##;
|
||||||
if ($u !~ m!\Q$full_url\E/(.+)$!) {
|
if ($u !~ m!\Q$full_url\E/(.+)$!) {
|
||||||
@ -910,17 +905,12 @@ sub complete_url_ls_init {
|
|||||||
}
|
}
|
||||||
# don't try to init already existing refs
|
# don't try to init already existing refs
|
||||||
my $id = $pfx.$1;
|
my $id = $pfx.$1;
|
||||||
$GIT_SVN = $ENV{GIT_SVN_ID} = $id;
|
my $gs = eval { Git::SVN->new($id) };
|
||||||
init_vars();
|
unless ($gs) {
|
||||||
unless (-d $GIT_SVN_DIR) {
|
|
||||||
print "init $u => $id\n";
|
print "init $u => $id\n";
|
||||||
cmd_init($u);
|
Git::SVN->init($id, $u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
waitpid $pid, 0;
|
|
||||||
croak $? if $?;
|
|
||||||
my ($n) = ($switch =~ /^--(\w+)/);
|
my ($n) = ($switch =~ /^--(\w+)/);
|
||||||
command_noisy('config', "svn.$n", $full_url);
|
command_noisy('config', "svn.$n", $full_url);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user