git-svn: fetch/multi-fetch converted over to Git::SVN module
--follow-parent and commit-diff are currently broken with this commit... Signed-off-by: Eric Wong <normalperson@yhbt.net>
This commit is contained in:
parent
396988e0b9
commit
1c8443b050
89
git-svn.perl
89
git-svn.perl
@ -9,7 +9,7 @@ use vars qw/ $AUTHOR $VERSION
|
|||||||
$GIT_DIR $GIT_SVN_DIR $REVDB
|
$GIT_DIR $GIT_SVN_DIR $REVDB
|
||||||
$_follow_parent $sha1 $sha1_short $_revision
|
$_follow_parent $sha1 $sha1_short $_revision
|
||||||
$_cp_remote $_upgrade $_rmdir $_q $_cp_similarity
|
$_cp_remote $_upgrade $_rmdir $_q $_cp_similarity
|
||||||
$_find_copies_harder $_l/;
|
$_find_copies_harder $_l $_authors %users/;
|
||||||
$AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
|
$AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
|
||||||
$VERSION = '@@GIT_VERSION@@';
|
$VERSION = '@@GIT_VERSION@@';
|
||||||
|
|
||||||
@ -71,10 +71,10 @@ my ($_stdin, $_help, $_edit,
|
|||||||
$_repack, $_repack_nr, $_repack_flags,
|
$_repack, $_repack_nr, $_repack_flags,
|
||||||
$_message, $_file, $_no_metadata,
|
$_message, $_file, $_no_metadata,
|
||||||
$_template, $_shared, $_no_default_regex, $_no_graft_copy,
|
$_template, $_shared, $_no_default_regex, $_no_graft_copy,
|
||||||
$_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m,
|
$_version, $_upgrade, $_branch_all_refs, @_opt_m,
|
||||||
$_merge, $_strategy, $_dry_run,
|
$_merge, $_strategy, $_dry_run,
|
||||||
$_prefix);
|
$_prefix);
|
||||||
my (@_branch_from, %tree_map, %users);
|
my (@_branch_from, %tree_map);
|
||||||
my @repo_path_split_cache;
|
my @repo_path_split_cache;
|
||||||
|
|
||||||
my %fc_opts = ( 'branch|b=s' => \@_branch_from,
|
my %fc_opts = ( 'branch|b=s' => \@_branch_from,
|
||||||
@ -135,7 +135,7 @@ my %cmd = (
|
|||||||
'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache,
|
'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache,
|
||||||
'prefix=s' => \$_prefix,
|
'prefix=s' => \$_prefix,
|
||||||
} ],
|
} ],
|
||||||
'multi-fetch' => [ \&multi_fetch,
|
'multi-fetch' => [ \&cmd_multi_fetch,
|
||||||
'Fetch multiple trees (like git-svnimport)',
|
'Fetch multiple trees (like git-svnimport)',
|
||||||
\%fc_opts ],
|
\%fc_opts ],
|
||||||
'log' => [ \&Git::SVN::Log::cmd_show_log, 'Show commit logs',
|
'log' => [ \&Git::SVN::Log::cmd_show_log, 'Show commit logs',
|
||||||
@ -292,7 +292,12 @@ sub cmd_init {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub cmd_fetch {
|
sub cmd_fetch {
|
||||||
fetch_child_id($GIT_SVN, @_);
|
my $gs = Git::SVN->new;
|
||||||
|
$gs->fetch(@_);
|
||||||
|
if ($gs->{last_commit} && !verify_ref('refs/heads/master^0')) {
|
||||||
|
command_noisy(qw(update-ref refs/heads/master),
|
||||||
|
$gs->{last_commit});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub fetch {
|
sub fetch {
|
||||||
@ -583,13 +588,14 @@ sub cmd_multi_init {
|
|||||||
complete_url_ls_init($ra, $_tags, '--tags/-t', $_prefix . 'tags/');
|
complete_url_ls_init($ra, $_tags, '--tags/-t', $_prefix . 'tags/');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub multi_fetch {
|
sub cmd_multi_fetch {
|
||||||
# try to do trunk first, since branches/tags
|
# try to do trunk first, since branches/tags
|
||||||
# may be descended from it.
|
# may be descended from it.
|
||||||
if (-e "$GIT_DIR/svn/trunk/info/url") {
|
if (-e "$ENV{GIT_DIR}/svn/trunk/info/url") {
|
||||||
fetch_child_id('trunk', @_);
|
my $gs = Git::SVN->new('trunk');
|
||||||
|
$gs->fetch(@_);
|
||||||
}
|
}
|
||||||
rec_fetch('', "$GIT_DIR/svn", @_);
|
rec_fetch('', "$ENV{GIT_DIR}/svn", @_);
|
||||||
}
|
}
|
||||||
|
|
||||||
# this command is special because it requires no metadata
|
# this command is special because it requires no metadata
|
||||||
@ -706,24 +712,6 @@ sub commit_diff {
|
|||||||
|
|
||||||
########################### utility functions #########################
|
########################### utility functions #########################
|
||||||
|
|
||||||
sub fetch_child_id {
|
|
||||||
my $id = shift;
|
|
||||||
print "Fetching $id\n";
|
|
||||||
my $ref = "$GIT_DIR/refs/remotes/$id";
|
|
||||||
defined(my $pid = open my $fh, '-|') or croak $!;
|
|
||||||
if (!$pid) {
|
|
||||||
$GIT_SVN = $ENV{GIT_SVN_ID} = $id;
|
|
||||||
init_vars();
|
|
||||||
fetch(@_);
|
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
while (<$fh>) {
|
|
||||||
print $_;
|
|
||||||
check_repack() if (/^r\d+ = $sha1/o);
|
|
||||||
}
|
|
||||||
close $fh or croak $?;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub rec_fetch {
|
sub rec_fetch {
|
||||||
my ($pfx, $p, @args) = @_;
|
my ($pfx, $p, @args) = @_;
|
||||||
my @dir;
|
my @dir;
|
||||||
@ -732,15 +720,16 @@ sub rec_fetch {
|
|||||||
$pfx .= '/' if $pfx && $pfx !~ m!/$!;
|
$pfx .= '/' if $pfx && $pfx !~ m!/$!;
|
||||||
my $id = $pfx . basename $_;
|
my $id = $pfx . basename $_;
|
||||||
next if $id eq 'trunk';
|
next if $id eq 'trunk';
|
||||||
fetch_child_id($id, @args);
|
my $gs = Git::SVN->new($id);
|
||||||
|
$gs->fetch(@args);
|
||||||
} elsif (-d $_) {
|
} elsif (-d $_) {
|
||||||
push @dir, $_;
|
push @dir, $_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (@dir) {
|
foreach (@dir) {
|
||||||
my $x = $_;
|
my $x = $_;
|
||||||
$x =~ s!^\Q$GIT_DIR\E/svn/!!;
|
$x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
|
||||||
rec_fetch($x, $_);
|
rec_fetch($x, $_, @args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1841,8 +1830,9 @@ sub do_git_commit {
|
|||||||
croak "$log_entry->{revision} = $c already exists! ",
|
croak "$log_entry->{revision} = $c already exists! ",
|
||||||
"Why are we refetching it?\n";
|
"Why are we refetching it?\n";
|
||||||
}
|
}
|
||||||
my ($name, $email) = ::author_name_email($log_entry->{author},
|
my $author = $log_entry->{author};
|
||||||
$self->ra);
|
my ($name, $email) = (defined $::users{$author} ? @{$::users{$author}}
|
||||||
|
: ($author, "$author\@".$self->ra->uuid));
|
||||||
$ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $name;
|
$ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $name;
|
||||||
$ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = $email;
|
$ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = $email;
|
||||||
$ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_entry->{date};
|
$ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_entry->{date};
|
||||||
@ -1894,7 +1884,7 @@ sub do_fetch {
|
|||||||
} else {
|
} else {
|
||||||
$last_rev = $rev;
|
$last_rev = $rev;
|
||||||
}
|
}
|
||||||
unless ($self->ra->do_update($last_rev, $rev, '', 1, $ed)) {
|
unless ($self->ra->gs_do_update($last_rev, $rev, '', 1, $ed)) {
|
||||||
die "SVN connection failed somewhere...\n";
|
die "SVN connection failed somewhere...\n";
|
||||||
}
|
}
|
||||||
$self->make_log_entry($rev, \@parents, $ed);
|
$self->make_log_entry($rev, \@parents, $ed);
|
||||||
@ -1946,6 +1936,25 @@ sub write_untracked {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub parse_svn_date {
|
||||||
|
my $date = shift || return '+0000 1970-01-01 00:00:00';
|
||||||
|
my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d{4})\-(\d\d)\-(\d\d)T
|
||||||
|
(\d\d)\:(\d\d)\:(\d\d).\d+Z$/x) or
|
||||||
|
croak "Unable to parse date: $date\n";
|
||||||
|
"+0000 $Y-$m-$d $H:$M:$S";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_author {
|
||||||
|
my ($author) = @_;
|
||||||
|
if (!defined $author || length $author == 0) {
|
||||||
|
$author = '(no author)';
|
||||||
|
}
|
||||||
|
if (defined $::_authors && ! defined $::users{$author}) {
|
||||||
|
die "Author: $author not defined in $::_authors file\n";
|
||||||
|
}
|
||||||
|
$author;
|
||||||
|
}
|
||||||
|
|
||||||
sub make_log_entry {
|
sub make_log_entry {
|
||||||
my ($self, $rev, $parents, $untracked) = @_;
|
my ($self, $rev, $parents, $untracked) = @_;
|
||||||
my $rp = $self->ra->rev_proplist($rev);
|
my $rp = $self->ra->rev_proplist($rev);
|
||||||
@ -2105,6 +2114,11 @@ sub _new {
|
|||||||
db_path => "$dir/.rev_db" }, $class;
|
db_path => "$dir/.rev_db" }, $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub uri_encode {
|
||||||
|
my ($f) = @_;
|
||||||
|
$f =~ s#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
|
||||||
|
$f
|
||||||
|
}
|
||||||
|
|
||||||
package Git::SVN::Prompt;
|
package Git::SVN::Prompt;
|
||||||
use strict;
|
use strict;
|
||||||
@ -2662,15 +2676,14 @@ sub new {
|
|||||||
my ($class, $git_svn) = @_;
|
my ($class, $git_svn) = @_;
|
||||||
my $self = SVN::Delta::Editor->new;
|
my $self = SVN::Delta::Editor->new;
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
$self->{c} = $git_svn->{c} if exists $git_svn->{c};
|
$self->{c} = $git_svn->{last_commit} if exists $git_svn->{last_commit};
|
||||||
$self->{q} = $git_svn->{q};
|
|
||||||
$self->{empty} = {};
|
$self->{empty} = {};
|
||||||
$self->{dir_prop} = {};
|
$self->{dir_prop} = {};
|
||||||
$self->{file_prop} = {};
|
$self->{file_prop} = {};
|
||||||
$self->{absent_dir} = {};
|
$self->{absent_dir} = {};
|
||||||
$self->{absent_file} = {};
|
$self->{absent_file} = {};
|
||||||
($self->{gui}, $self->{ctx}) = command_input_pipe(
|
($self->{gui}, $self->{ctx}) = $git_svn->tmp_index_do(
|
||||||
qw/update-index -z --index-info/);
|
sub { command_input_pipe(qw/update-index -z --index-info/) } );
|
||||||
require Digest::MD5;
|
require Digest::MD5;
|
||||||
$self;
|
$self;
|
||||||
}
|
}
|
||||||
@ -3416,7 +3429,7 @@ sub get_author_info {
|
|||||||
$author =~ s/(?:^\s*|\s*$)//g;
|
$author =~ s/(?:^\s*|\s*$)//g;
|
||||||
$dest->{a_raw} = $author;
|
$dest->{a_raw} = $author;
|
||||||
my $au;
|
my $au;
|
||||||
if ($_authors) {
|
if ($::_authors) {
|
||||||
$au = $rusers{$author} || undef;
|
$au = $rusers{$author} || undef;
|
||||||
}
|
}
|
||||||
if (!$au) {
|
if (!$au) {
|
||||||
|
Loading…
Reference in New Issue
Block a user