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>
Eric Wong committed
Jan 14, 2007 at 02:17 UTC
1c8443b05074cfa466845c4dad98fe962f6dd4c2
1 file changed
+51
-38
git-svn.perl
+51
-38
@@ -9,7 +9,7 @@ use vars qw/ $AUTHOR $VERSION
9
$GIT_DIR $GIT_SVN_DIR $REVDB
10
$_follow_parent $sha1 $sha1_short $_revision
11
$_cp_remote $_upgrade $_rmdir $_q $_cp_similarity
12
- $_find_copies_harder $_l/;
12
+ $_find_copies_harder $_l $_authors %users/;
13
$AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
14
$VERSION = '@@GIT_VERSION@@';
15
@@ -71,10 +71,10 @@ my ($_stdin, $_help, $_edit,
71
$_repack, $_repack_nr, $_repack_flags,
72
$_message, $_file, $_no_metadata,
73
$_template, $_shared, $_no_default_regex, $_no_graft_copy,
74
- $_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m,
74
+ $_version, $_upgrade, $_branch_all_refs, @_opt_m,
75
$_merge, $_strategy, $_dry_run,
76
$_prefix);
77
-my (@_branch_from, %tree_map, %users);
77
+my (@_branch_from, %tree_map);
78
my @repo_path_split_cache;
79
80
my %fc_opts = ( 'branch|b=s' => \@_branch_from,
@@ -135,7 +135,7 @@ my %cmd = (
135
'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache,
136
'prefix=s' => \$_prefix,
137
} ],
138
- 'multi-fetch' => [ \&multi_fetch,
138
+ 'multi-fetch' => [ \&cmd_multi_fetch,
139
'Fetch multiple trees (like git-svnimport)',
140
\%fc_opts ],
141
'log' => [ \&Git::SVN::Log::cmd_show_log, 'Show commit logs',
@@ -292,7 +292,12 @@ sub cmd_init {
292
}
293
294
sub cmd_fetch {
295
- fetch_child_id($GIT_SVN, @_);
295
+ my $gs = Git::SVN->new;
296
+ $gs->fetch(@_);
297
+ if ($gs->{last_commit} && !verify_ref('refs/heads/master^0')) {
298
+ command_noisy(qw(update-ref refs/heads/master),
299
+ $gs->{last_commit});
300
+ }
301
}
302
303
sub fetch {
@@ -583,13 +588,14 @@ sub cmd_multi_init {
588
complete_url_ls_init($ra, $_tags, '--tags/-t', $_prefix . 'tags/');
589
}
590
586
-sub multi_fetch {
591
+sub cmd_multi_fetch {
592
# try to do trunk first, since branches/tags
593
# may be descended from it.
589
- if (-e "$GIT_DIR/svn/trunk/info/url") {
590
- fetch_child_id('trunk', @_);
594
+ if (-e "$ENV{GIT_DIR}/svn/trunk/info/url") {
595
+ my $gs = Git::SVN->new('trunk');
596
+ $gs->fetch(@_);
597
}
592
- rec_fetch('', "$GIT_DIR/svn", @_);
598
+ rec_fetch('', "$ENV{GIT_DIR}/svn", @_);
599
}
600
601
# this command is special because it requires no metadata
@@ -706,24 +712,6 @@ sub commit_diff {
712
713
########################### utility functions #########################
714
709
-sub fetch_child_id {
710
- my $id = shift;
711
- print "Fetching $id\n";
712
- my $ref = "$GIT_DIR/refs/remotes/$id";
713
- defined(my $pid = open my $fh, '-|') or croak $!;
714
- if (!$pid) {
715
- $GIT_SVN = $ENV{GIT_SVN_ID} = $id;
716
- init_vars();
717
- fetch(@_);
718
- exit 0;
719
- }
720
- while (<$fh>) {
721
- print $_;
722
- check_repack() if (/^r\d+ = $sha1/o);
723
- }
724
- close $fh or croak $?;
725
-}
726
-
715
sub rec_fetch {
716
my ($pfx, $p, @args) = @_;
717
my @dir;
@@ -732,15 +720,16 @@ sub rec_fetch {
720
$pfx .= '/' if $pfx && $pfx !~ m!/$!;
721
my $id = $pfx . basename $_;
722
next if $id eq 'trunk';
735
- fetch_child_id($id, @args);
723
+ my $gs = Git::SVN->new($id);
724
+ $gs->fetch(@args);
725
} elsif (-d $_) {
726
push @dir, $_;
727
}
728
}
729
foreach (@dir) {
730
my $x = $_;
742
- $x =~ s!^\Q$GIT_DIR\E/svn/!!;
743
- rec_fetch($x, $_);
731
+ $x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
732
+ rec_fetch($x, $_, @args);
733
}
734
}
735
@@ -1841,8 +1830,9 @@ sub do_git_commit {
1830
croak "$log_entry->{revision} = $c already exists! ",
1831
"Why are we refetching it?\n";
1832
}
1844
- my ($name, $email) = ::author_name_email($log_entry->{author},
1845
- $self->ra);
1833
+ my $author = $log_entry->{author};
1834
+ my ($name, $email) = (defined $::users{$author} ? @{$::users{$author}}
1835
+ : ($author, "$author\@".$self->ra->uuid));
1836
$ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $name;
1837
$ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = $email;
1838
$ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_entry->{date};
@@ -1894,7 +1884,7 @@ sub do_fetch {
1884
} else {
1885
$last_rev = $rev;
1886
}
1897
- unless ($self->ra->do_update($last_rev, $rev, '', 1, $ed)) {
1887
+ unless ($self->ra->gs_do_update($last_rev, $rev, '', 1, $ed)) {
1888
die "SVN connection failed somewhere...\n";
1889
}
1890
$self->make_log_entry($rev, \@parents, $ed);
@@ -1946,6 +1936,25 @@ sub write_untracked {
1936
}
1937
}
1938
1939
+sub parse_svn_date {
1940
+ my $date = shift || return '+0000 1970-01-01 00:00:00';
1941
+ my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d{4})\-(\d\d)\-(\d\d)T
1942
+ (\d\d)\:(\d\d)\:(\d\d).\d+Z$/x) or
1943
+ croak "Unable to parse date: $date\n";
1944
+ "+0000 $Y-$m-$d $H:$M:$S";
1945
+}
1946
+
1947
+sub check_author {
1948
+ my ($author) = @_;
1949
+ if (!defined $author || length $author == 0) {
1950
+ $author = '(no author)';
1951
+ }
1952
+ if (defined $::_authors && ! defined $::users{$author}) {
1953
+ die "Author: $author not defined in $::_authors file\n";
1954
+ }
1955
+ $author;
1956
+}
1957
+
1958
sub make_log_entry {
1959
my ($self, $rev, $parents, $untracked) = @_;
1960
my $rp = $self->ra->rev_proplist($rev);
@@ -2105,6 +2114,11 @@ sub _new {
2114
db_path => "$dir/.rev_db" }, $class;
2115
}
2116
2117
+sub uri_encode {
2118
+ my ($f) = @_;
2119
+ $f =~ s#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
2120
+ $f
2121
+}
2122
2123
package Git::SVN::Prompt;
2124
use strict;
@@ -2662,15 +2676,14 @@ sub new {
2676
my ($class, $git_svn) = @_;
2677
my $self = SVN::Delta::Editor->new;
2678
bless $self, $class;
2665
- $self->{c} = $git_svn->{c} if exists $git_svn->{c};
2666
- $self->{q} = $git_svn->{q};
2679
+ $self->{c} = $git_svn->{last_commit} if exists $git_svn->{last_commit};
2680
$self->{empty} = {};
2681
$self->{dir_prop} = {};
2682
$self->{file_prop} = {};
2683
$self->{absent_dir} = {};
2684
$self->{absent_file} = {};
2672
- ($self->{gui}, $self->{ctx}) = command_input_pipe(
2673
- qw/update-index -z --index-info/);
2685
+ ($self->{gui}, $self->{ctx}) = $git_svn->tmp_index_do(
2686
+ sub { command_input_pipe(qw/update-index -z --index-info/) } );
2687
require Digest::MD5;
2688
$self;
2689
}
@@ -3416,7 +3429,7 @@ sub get_author_info {
3429
$author =~ s/(?:^\s*|\s*$)//g;
3430
$dest->{a_raw} = $author;
3431
my $au;
3419
- if ($_authors) {
3432
+ if ($::_authors) {
3433
$au = $rusers{$author} || undef;
3434
}
3435
if (!$au) {