git-svn: cleanup: put SVN workarounds into their own namespace
Force some svn_ra functions to use a temporary pool via wrapper This cleans up the code a bit by removing explicit instances of pool allocation and deallocation and providing wrapper functions that make use of temporary pools. I've also added an explicit pool usage when creating the commit editor for commit-diff where get_commit_editor can be called multiple times with the same pool previously. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Jan 10, 2007 at 01:22 UTC
d81bf827192f0af6b1cca64d2cdbaac9b5ca2020
1 file changed
+173
-149
git-svn.perl
+173
-149
@@ -4,7 +4,7 @@
4
use warnings;
5
use strict;
6
use vars qw/ $AUTHOR $VERSION
7
- $SVN_URL $SVN_INFO $SVN_WC $SVN_UUID
7
+ $SVN_URL
8
$GIT_SVN_INDEX $GIT_SVN
9
$GIT_DIR $GIT_SVN_DIR $REVDB/;
10
$AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
@@ -38,6 +38,7 @@ require SVN::Delta;
38
if ($SVN::Core::VERSION lt '1.1.0') {
39
fatal "Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)\n";
40
}
41
+push @Git::SVN::Ra::ISA, 'SVN::Ra';
42
push @SVN::Git::Editor::ISA, 'SVN::Delta::Editor';
43
push @SVN::Git::Fetcher::ISA, 'SVN::Delta::Editor';
44
use Carp qw/croak/;
@@ -63,16 +64,16 @@ my $_esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
64
my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
65
$_find_copies_harder, $_l, $_cp_similarity, $_cp_remote,
66
$_repack, $_repack_nr, $_repack_flags, $_q,
66
- $_message, $_file, $_follow_parent, $_no_metadata,
67
+ $_message, $_file, $_no_metadata,
68
$_template, $_shared, $_no_default_regex, $_no_graft_copy,
69
$_limit, $_verbose, $_incremental, $_oneline, $_l_fmt, $_show_commit,
70
$_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m,
71
$_merge, $_strategy, $_dry_run, $_ignore_nodate, $_non_recursive,
71
- $_config_dir,
72
$_pager, $_color, $_prefix);
73
my (@_branch_from, %tree_map, %users, %rusers, %equiv);
74
my ($_svn_can_do_switch);
75
my @repo_path_split_cache;
76
+use vars qw/$_follow_parent/;
77
78
my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext,
79
'branch|b=s' => \@_branch_from,
@@ -83,7 +84,7 @@ my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext,
84
'no-metadata' => \$_no_metadata,
85
'quiet|q' => \$_q,
86
'username=s' => \$Git::SVN::Prompt::_username,
86
- 'config-dir=s' => \$_config_dir,
87
+ 'config-dir=s' => \$Git::SVN::Ra::config_dir,
88
'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache,
89
'ignore-nodate' => \$_ignore_nodate,
90
'repack-flags|repack-args|repack-opts=s' => \$_repack_flags);
@@ -131,7 +132,7 @@ my %cmd = (
132
{ %multi_opts, %init_opts,
133
'revision|r=i' => \$_revision,
134
'username=s' => \$Git::SVN::Prompt::_username,
134
- 'config-dir=s' => \$_config_dir,
135
+ 'config-dir=s' => \$Git::SVN::Ra::config_dir,
136
'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache,
137
'prefix=s' => \$_prefix,
138
} ],
@@ -236,6 +237,7 @@ sub rebuild {
237
my ($rev_list, $ctx) = command_output_pipe("rev-list",
238
"refs/remotes/$GIT_SVN");
239
my $latest;
240
+ my $svn_uuid;
241
while (<$rev_list>) {
242
chomp;
243
my $c = $_;
@@ -251,7 +253,7 @@ sub rebuild {
253
254
# if we merged or otherwise started elsewhere, this is
255
# how we break out of it
254
- next if (defined $SVN_UUID && ($uuid ne $SVN_UUID));
256
+ next if (defined $svn_uuid && ($uuid ne $svn_uuid));
257
next if (defined $SVN_URL && defined $url && ($url ne $SVN_URL));
258
259
unless (defined $latest) {
@@ -259,7 +261,7 @@ sub rebuild {
261
croak "SVN repository location required: $url\n";
262
}
263
$SVN_URL ||= $url;
262
- $SVN_UUID ||= $uuid;
264
+ $svn_uuid ||= $uuid;
265
setup_git_svn();
266
$latest = $rev;
267
}
@@ -310,7 +312,7 @@ sub fetch {
312
sub fetch_lib {
313
my (@parents) = @_;
314
$SVN_URL ||= file_to_s("$GIT_SVN_DIR/info/url");
313
- $SVN ||= libsvn_connect($SVN_URL);
315
+ $SVN ||= Git::SVN::Ra->new($SVN_URL);
316
my ($last_rev, $last_commit) = svn_grab_base_rev();
317
my ($base, $head) = libsvn_parse_revision($last_rev);
318
if ($base > $head) {
@@ -322,7 +324,6 @@ sub fetch_lib {
324
# after processing a revision and SVN stuff seems to leak
325
my $inc = 1000;
326
my ($min, $max) = ($base, $head < $base+$inc ? $head : $base+$inc);
325
- read_uuid();
327
if (defined $last_commit) {
328
unless (-e $GIT_SVN_INDEX) {
329
command_noisy('read-tree', $last_commit);
@@ -352,8 +353,7 @@ sub fetch_lib {
353
# performance sucks with it enabled, so it's much
354
# faster to fetch revision ranges instead of relying
355
# on the limiter.
355
- libsvn_get_log(libsvn_dup_ra($SVN), [''],
356
- $min, $max, 0, 1, 1,
356
+ $SVN->dup->get_log([''], $min, $max, 0, 1, 1,
357
sub {
358
my $log_msg;
359
if ($last_commit) {
@@ -378,7 +378,7 @@ sub fetch_lib {
378
$min = $max + 1;
379
$max += $inc;
380
$max = $head if ($max > $head);
381
- $SVN = libsvn_connect($SVN_URL);
381
+ $SVN = Git::SVN::Ra->new($SVN_URL);
382
}
383
restore_index($index);
384
return { revision => $last_rev, commit => $last_commit };
@@ -424,8 +424,6 @@ sub commit_lib {
424
" current: $fetched->{revision}\n";
425
exit 1;
426
}
427
- read_uuid();
428
- my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef, 0) : ();
427
my $commit_msg = "$GIT_SVN_DIR/.svn-commit.tmp.$$";
428
429
my $repo;
@@ -437,9 +435,10 @@ sub commit_lib {
435
# can't track down... (it's probably in the SVN code)
436
defined(my $pid = open my $fh, '-|') or croak $!;
437
if (!$pid) {
438
+ my $pool = SVN::Pool->new;
439
my $ed = SVN::Git::Editor->new(
440
{ r => $r_last,
442
- ra => libsvn_dup_ra($SVN),
441
+ ra => $SVN->dup,
442
c => $c,
443
svn_path => $SVN->{svn_path},
444
},
@@ -451,8 +450,7 @@ sub commit_lib {
450
$log_msg->{msg},
451
$r_last,
452
$cmt_last)
454
- },
455
- @lock)
453
+ }, $pool)
454
);
455
my $mods = libsvn_checkout_tree($cmt_last, $c, $ed);
456
if (@$mods == 0) {
@@ -461,6 +459,7 @@ sub commit_lib {
459
} else {
460
$ed->close_edit;
461
}
462
+ $pool->clear;
463
exit 0;
464
}
465
my ($r_new, $cmt_new, $no);
@@ -534,7 +533,7 @@ sub dcommit {
533
sub show_ignore {
534
$SVN_URL ||= file_to_s("$GIT_SVN_DIR/info/url");
535
my $repo;
537
- $SVN ||= libsvn_connect($SVN_URL);
536
+ $SVN ||= Git::SVN::Ra->new($SVN_URL);
537
my $r = defined $_revision ? $_revision : $SVN->get_latest_revnum;
538
libsvn_traverse_ignore(\*STDOUT, '', $r);
539
}
@@ -716,16 +715,16 @@ sub commit_diff {
715
$_message ||= get_commit_message($tb,
716
"$GIT_DIR/.svn-commit.tmp.$$")->{msg};
717
}
719
- $SVN ||= libsvn_connect($SVN_URL);
718
+ $SVN ||= Git::SVN::Ra->new($SVN_URL);
719
if ($r eq 'HEAD') {
720
$r = $SVN->get_latest_revnum;
721
} elsif ($r !~ /^\d+$/) {
722
die "revision argument: $r not understood by git-svn\n";
723
}
725
- my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef, 0) : ();
724
my $rev_committed;
725
+ my $pool = SVN::Pool->new;
726
my $ed = SVN::Git::Editor->new({ r => $r,
728
- ra => libsvn_dup_ra($SVN),
727
+ ra => $SVN->dup,
728
c => $tb,
729
svn_path => $SVN->{svn_path}
730
},
@@ -733,7 +732,8 @@ sub commit_diff {
732
sub {
733
$rev_committed = $_[0];
734
print "Committed $_[0]\n";
736
- }, @lock)
735
+ },
736
+ $pool)
737
);
738
eval {
739
my $mods = libsvn_checkout_tree($ta, $tb, $ed);
@@ -744,6 +744,7 @@ sub commit_diff {
744
$ed->close_edit;
745
}
746
};
747
+ $pool->clear;
748
fatal "$@\n" if $@;
749
$_message = $_file = undef;
750
return $rev_committed;
@@ -1012,7 +1013,7 @@ sub graft_file_copy_lib {
1013
my $tree_paths = $l_map->{$u};
1014
my $pfx = common_prefix([keys %$tree_paths]);
1015
my ($repo, $path) = repo_path_split($u.$pfx);
1015
- $SVN = libsvn_connect($repo);
1016
+ $SVN = Git::SVN::Ra->new($repo);
1017
1018
my ($base, $head) = libsvn_parse_revision();
1019
my $inc = 1000;
@@ -1020,14 +1021,11 @@ sub graft_file_copy_lib {
1021
my $eh = $SVN::Error::handler;
1022
$SVN::Error::handler = \&libsvn_skip_unknown_revs;
1023
while (1) {
1023
- my $pool = SVN::Pool->new;
1024
- libsvn_get_log(libsvn_dup_ra($SVN), [$path],
1025
- $min, $max, 0, 2, 1,
1024
+ $SVN->dup->get_log([$path], $min, $max, 0, 2, 1,
1025
sub {
1026
libsvn_graft_file_copies($grafts, $tree_paths,
1027
$path, @_);
1029
- }, $pool);
1030
- $pool->clear;
1028
+ });
1029
last if ($max >= $head);
1030
$min = $max + 1;
1031
$max += $inc;
@@ -1095,13 +1093,6 @@ sub graft_merge_msg {
1093
}
1094
}
1095
1098
-sub read_uuid {
1099
- return if $SVN_UUID;
1100
- my $pool = SVN::Pool->new;
1101
- $SVN_UUID = $SVN->get_uuid($pool);
1102
- $pool->clear;
1103
-}
1104
-
1096
sub verify_ref {
1097
my ($ref) = @_;
1098
eval { command_oneline([ 'rev-parse', '--verify', $ref ],
@@ -1119,7 +1110,7 @@ sub repo_path_split {
1110
return ($u, $full_url);
1111
}
1112
}
1122
- my $tmp = libsvn_connect($full_url);
1113
+ my $tmp = Git::SVN::Ra->new($full_url);
1114
return ($tmp->{repos_root}, $tmp->{svn_path});
1115
}
1116
@@ -1371,10 +1362,10 @@ sub git_commit {
1362
}
1363
next if $skip;
1364
my ($url_p, $r_p, $uuid_p) = cmt_metadata($p);
1374
- next if (($SVN_UUID eq $uuid_p) &&
1365
+ next if (($SVN->uuid eq $uuid_p) &&
1366
($log_msg->{revision} > $r_p));
1367
next if (defined $url_p && defined $SVN_URL &&
1377
- ($SVN_UUID eq $uuid_p) &&
1368
+ ($SVN->uuid eq $uuid_p) &&
1369
($url_p eq $SVN_URL));
1370
push @tmp_parents, $p;
1371
}
@@ -1394,8 +1385,8 @@ sub git_commit {
1385
or croak $!;
1386
print $msg_fh $log_msg->{msg} or croak $!;
1387
unless ($_no_metadata) {
1397
- print $msg_fh "\ngit-svn-id: $SVN_URL\@$log_msg->{revision}",
1398
- " $SVN_UUID\n" or croak $!;
1388
+ print $msg_fh "\ngit-svn-id: $SVN_URL\@$log_msg->{revision} ",
1389
+ $SVN->uuid,"\n" or croak $!;
1390
}
1391
$msg_fh->flush == 0 or croak $!;
1392
close $msg_fh or croak $!;
@@ -1429,7 +1420,7 @@ sub set_commit_env {
1420
$author = '(no author)';
1421
}
1422
my ($name,$email) = defined $users{$author} ? @{$users{$author}}
1432
- : ($author,"$author\@$SVN_UUID");
1423
+ : ($author,$author . '@' . $SVN->uuid);
1424
$ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $name;
1425
$ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = $email;
1426
$ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_msg->{date};
@@ -1589,7 +1580,6 @@ sub init_vars {
1580
$REVDB = "$GIT_SVN_DIR/.rev_db";
1581
$GIT_SVN_INDEX = "$GIT_SVN_DIR/index";
1582
$SVN_URL = undef;
1592
- $SVN_WC = "$GIT_SVN_DIR/tree";
1583
%tree_map = ();
1584
}
1585
@@ -2042,60 +2032,6 @@ sub _read_password {
2032
2033
package main;
2034
2045
-sub libsvn_connect {
2046
- my ($url) = @_;
2047
- SVN::_Core::svn_config_ensure($_config_dir, undef);
2048
- my ($baton, $callbacks) = SVN::Core::auth_open_helper([
2049
- SVN::Client::get_simple_provider(),
2050
- SVN::Client::get_ssl_server_trust_file_provider(),
2051
- SVN::Client::get_simple_prompt_provider(
2052
- \&Git::SVN::Prompt::simple, 2),
2053
- SVN::Client::get_ssl_client_cert_prompt_provider(
2054
- \&Git::SVN::Prompt::ssl_client_cert, 2),
2055
- SVN::Client::get_ssl_client_cert_pw_prompt_provider(
2056
- \&Git::SVN::Prompt::ssl_client_cert_pw, 2),
2057
- SVN::Client::get_username_provider(),
2058
- SVN::Client::get_ssl_server_trust_prompt_provider(
2059
- \&Git::SVN::Prompt::ssl_server_trust),
2060
- SVN::Client::get_username_prompt_provider(
2061
- \&Git::SVN::username, 2),
2062
- ]);
2063
- my $config = SVN::Core::config_get_config($_config_dir);
2064
- my $ra = SVN::Ra->new(url => $url, auth => $baton,
2065
- config => $config,
2066
- pool => SVN::Pool->new,
2067
- auth_provider_callbacks => $callbacks);
2068
- $ra->{svn_path} = $url;
2069
- $ra->{repos_root} = $ra->get_repos_root;
2070
- $ra->{svn_path} =~ s#^\Q$ra->{repos_root}\E/*##;
2071
- push @repo_path_split_cache, qr/^(\Q$ra->{repos_root}\E)/;
2072
- return $ra;
2073
-}
2074
-
2075
-sub libsvn_can_do_switch {
2076
- unless (defined $_svn_can_do_switch) {
2077
- my $pool = SVN::Pool->new;
2078
- my $rep = eval {
2079
- $SVN->do_switch(1, '', 0, $SVN->{url},
2080
- SVN::Delta::Editor->new, $pool);
2081
- };
2082
- if ($@) {
2083
- $_svn_can_do_switch = 0;
2084
- } else {
2085
- $rep->abort_report($pool);
2086
- $_svn_can_do_switch = 1;
2087
- }
2088
- $pool->clear;
2089
- }
2090
- $_svn_can_do_switch;
2091
-}
2092
-
2093
-sub libsvn_dup_ra {
2094
- my ($ra) = @_;
2095
- SVN::Ra->new(map { $_ => $ra->{$_} } qw/config url
2096
- auth auth_provider_callbacks repos_root svn_path/);
2097
-}
2098
-
2035
sub uri_encode {
2036
my ($f) = @_;
2037
$f =~ s#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
@@ -2165,14 +2101,12 @@ sub libsvn_log_entry {
2101
}
2102
2103
# revprops (make this optional? it's an extra network trip...)
2168
- my $pool = SVN::Pool->new;
2169
- my $rp = $SVN->rev_proplist($rev, $pool);
2104
+ my $rp = $SVN->rev_proplist($rev);
2105
foreach (sort keys %$rp) {
2106
next if /^svn:(?:author|date|log)$/;
2107
print $un " rev_prop: ", uri_encode($_), ' ',
2108
uri_encode($rp->{$_}), "\n";
2109
}
2175
- $pool->clear;
2110
close $un or croak $!;
2111
2112
{ revision => $rev, date => "+0000 $Y-$m-$d $H:$M:$S",
@@ -2182,15 +2116,9 @@ sub libsvn_log_entry {
2116
2117
sub libsvn_fetch {
2118
my ($last_commit, $paths, $rev, $author, $date, $msg) = @_;
2185
- my $pool = SVN::Pool->new;
2119
my $ed = SVN::Git::Fetcher->new({ c => $last_commit, q => $_q });
2187
- my $reporter = $SVN->do_update($rev, '', 1, $ed, $pool);
2188
- my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
2120
my (undef, $last_rev, undef) = cmt_metadata($last_commit);
2190
- $reporter->set_path('', $last_rev, 0, @lock, $pool);
2191
- $reporter->finish_report($pool);
2192
- $pool->clear;
2193
- unless ($ed->{git_commit_ok}) {
2121
+ unless ($SVN->gs_do_update($last_rev, $rev, '', 1, $ed)) {
2122
die "SVN connection failed somewhere...\n";
2123
}
2124
libsvn_log_entry($rev, $author, $date, $msg, [$last_commit], $ed);
@@ -2250,8 +2178,7 @@ sub libsvn_parse_revision {
2178
sub libsvn_traverse_ignore {
2179
my ($fh, $path, $r) = @_;
2180
$path =~ s#^/+##g;
2253
- my $pool = SVN::Pool->new;
2254
- my ($dirent, undef, $props) = $SVN->get_dir($path, $r, $pool);
2181
+ my ($dirent, undef, $props) = $SVN->get_dir($path, $r);
2182
my $p = $path;
2183
$p =~ s#^\Q$SVN->{svn_path}\E/##;
2184
print $fh length $p ? "\n# $p\n" : "\n# /\n";
@@ -2270,7 +2197,6 @@ sub libsvn_traverse_ignore {
2197
next if $dirent->{$_}->kind != $SVN::Node::dir;
2198
libsvn_traverse_ignore($fh, "$path/$_", $r);
2199
}
2273
- $pool->clear;
2200
}
2201
2202
sub revisions_eq {
@@ -2278,10 +2204,7 @@ sub revisions_eq {
2204
return 1 if $r0 == $r1;
2205
my $nr = 0;
2206
# should be OK to use Pool here (r1 - r0) should be small
2281
- my $pool = SVN::Pool->new;
2282
- libsvn_get_log($SVN, [$path], $r0, $r1,
2283
- 0, 0, 1, sub {$nr++}, $pool);
2284
- $pool->clear;
2207
+ $SVN->get_log([$path], $r0, $r1, 0, 0, 1, sub {$nr++});
2208
return 0 if ($nr > 1);
2209
return 1;
2210
}
@@ -2337,40 +2260,23 @@ sub libsvn_find_parent_branch {
2260
unlink $GIT_SVN_INDEX;
2261
print STDERR "Found branch parent: ($GIT_SVN) $parent\n";
2262
command_noisy('read-tree', $parent);
2340
- unless (libsvn_can_do_switch()) {
2263
+ unless ($SVN->can_do_switch) {
2264
return _libsvn_new_tree($paths, $rev, $author, $date,
2265
$msg, [$parent]);
2266
}
2267
# do_switch works with svn/trunk >= r22312, but that is not
2268
# included with SVN 1.4.2 (the latest version at the moment),
2269
# so we can't rely on it.
2347
- my $ra = libsvn_connect("$url/$branch_from");
2270
+ my $ra = Git::SVN::Ra->new("$url/$branch_from");
2271
my $ed = SVN::Git::Fetcher->new({c => $parent, q => $_q });
2349
- my $pool = SVN::Pool->new;
2350
- my $reporter = $ra->do_switch($rev, '', 1, $SVN->{url},
2351
- $ed, $pool);
2352
- my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
2353
- $reporter->set_path('', $r0, 0, @lock, $pool);
2354
- $reporter->finish_report($pool);
2355
- $pool->clear;
2356
- unless ($ed->{git_commit_ok}) {
2357
- die "SVN connection failed somewhere...\n";
2358
- }
2272
+ $ra->gs_do_switch($r0, $rev, '', 1, $SVN->{url}, $ed) or
2273
+ die "SVN connection failed somewhere...\n";
2274
return libsvn_log_entry($rev, $author, $date, $msg, [$parent]);
2275
}
2276
print STDERR "Nope, branch point not imported or unknown\n";
2277
return undef;
2278
}
2279
2365
-sub libsvn_get_log {
2366
- my ($ra, @args) = @_;
2367
- $args[4]-- if $args[4] && ! $_follow_parent;
2368
- if ($SVN::Core::VERSION le '1.2.0') {
2369
- splice(@args, 3, 1);
2370
- }
2371
- $ra->get_log(@args);
2372
-}
2373
-
2280
sub libsvn_new_tree {
2281
if (my $log_entry = libsvn_find_parent_branch(@_)) {
2282
return $log_entry;
@@ -2381,14 +2287,8 @@ sub libsvn_new_tree {
2287
2288
sub _libsvn_new_tree {
2289
my ($paths, $rev, $author, $date, $msg, $parents) = @_;
2384
- my $pool = SVN::Pool->new;
2290
my $ed = SVN::Git::Fetcher->new({q => $_q});
2386
- my $reporter = $SVN->do_update($rev, '', 1, $ed, $pool);
2387
- my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
2388
- $reporter->set_path('', $rev, 1, @lock, $pool);
2389
- $reporter->finish_report($pool);
2390
- $pool->clear;
2391
- unless ($ed->{git_commit_ok}) {
2291
+ unless ($SVN->gs_do_update($rev, $rev, '', 1, $ed)) {
2292
die "SVN connection failed somewhere...\n";
2293
}
2294
libsvn_log_entry($rev, $author, $date, $msg, $parents, $ed);
@@ -2474,21 +2374,18 @@ sub libsvn_commit_cb {
2374
2375
sub libsvn_ls_fullurl {
2376
my $fullurl = shift;
2477
- my $ra = libsvn_connect($fullurl);
2377
+ my $ra = Git::SVN::Ra->new($fullurl);
2378
my @ret;
2479
- my $pool = SVN::Pool->new;
2379
my $r = defined $_revision ? $_revision : $ra->get_latest_revnum;
2481
- my ($dirent, undef, undef) = $ra->get_dir('', $r, $pool);
2380
+ my ($dirent, undef, undef) = $ra->get_dir('', $r);
2381
foreach my $d (sort keys %$dirent) {
2382
if ($dirent->{$d}->kind == $SVN::Node::dir) {
2383
push @ret, "$d/"; # add '/' for compat with cli svn
2384
}
2385
}
2487
- $pool->clear;
2386
return @ret;
2387
}
2388
2491
-
2389
sub libsvn_skip_unknown_revs {
2390
my $err = shift;
2391
my $errno = $err->apr_err();
@@ -2866,9 +2763,7 @@ sub rmdirs {
2763
2764
sub open_or_add_dir {
2765
my ($self, $full_path, $baton) = @_;
2869
- my $p = SVN::Pool->new;
2870
- my $t = $self->{ra}->check_path($full_path, $self->{r}, $p);
2871
- $p->clear;
2766
+ my $t = $self->{ra}->check_path($full_path, $self->{r});
2767
if ($t == $SVN::Node::none) {
2768
return $self->add_directory($full_path, $baton,
2769
undef, -1, $self->{pool});
@@ -3023,6 +2918,135 @@ sub abort_edit {
2918
$self->{pool}->clear;
2919
}
2920
2921
+package Git::SVN::Ra;
2922
+use vars qw/@ISA $config_dir/;
2923
+use strict;
2924
+use warnings;
2925
+my ($can_do_switch);
2926
+
2927
+BEGIN {
2928
+ # enforce temporary pool usage for some simple functions
2929
+ my $e;
2930
+ foreach (qw/get_latest_revnum rev_proplist get_file
2931
+ check_path get_dir get_uuid get_repos_root/) {
2932
+ $e .= "sub $_ {
2933
+ my \$self = shift;
2934
+ my \$pool = SVN::Pool->new;
2935
+ my \@ret = \$self->SUPER::$_(\@_,\$pool);
2936
+ \$pool->clear;
2937
+ wantarray ? \@ret : \$ret[0]; }\n";
2938
+ }
2939
+ eval $e;
2940
+}
2941
+
2942
+sub new {
2943
+ my ($class, $url) = @_;
2944
+ SVN::_Core::svn_config_ensure($config_dir, undef);
2945
+ my ($baton, $callbacks) = SVN::Core::auth_open_helper([
2946
+ SVN::Client::get_simple_provider(),
2947
+ SVN::Client::get_ssl_server_trust_file_provider(),
2948
+ SVN::Client::get_simple_prompt_provider(
2949
+ \&Git::SVN::Prompt::simple, 2),
2950
+ SVN::Client::get_ssl_client_cert_prompt_provider(
2951
+ \&Git::SVN::Prompt::ssl_client_cert, 2),
2952
+ SVN::Client::get_ssl_client_cert_pw_prompt_provider(
2953
+ \&Git::SVN::Prompt::ssl_client_cert_pw, 2),
2954
+ SVN::Client::get_username_provider(),
2955
+ SVN::Client::get_ssl_server_trust_prompt_provider(
2956
+ \&Git::SVN::Prompt::ssl_server_trust),
2957
+ SVN::Client::get_username_prompt_provider(
2958
+ \&Git::SVN::Prompt::username, 2),
2959
+ ]);
2960
+ my $config = SVN::Core::config_get_config($config_dir);
2961
+ my $self = SVN::Ra->new(url => $url, auth => $baton,
2962
+ config => $config,
2963
+ pool => SVN::Pool->new,
2964
+ auth_provider_callbacks => $callbacks);
2965
+ $self->{svn_path} = $url;
2966
+ $self->{repos_root} = $self->get_repos_root;
2967
+ $self->{svn_path} =~ s#^\Q$self->{repos_root}\E/*##;
2968
+ bless $self, $class;
2969
+}
2970
+
2971
+sub DESTROY {
2972
+ my $self = shift;
2973
+ $self->{pool}->clear if $self->{pool};
2974
+ $self->SUPER::DESTROY(@_);
2975
+}
2976
+
2977
+sub dup {
2978
+ my ($self) = @_;
2979
+ my $dup = SVN::Ra->new(pool => SVN::Pool->new,
2980
+ map { $_ => $self->{$_} } qw/config url
2981
+ auth auth_provider_callbacks repos_root svn_path/);
2982
+ bless $dup, ref $self;
2983
+}
2984
+
2985
+sub get_log {
2986
+ my ($self, @args) = @_;
2987
+ my $pool = SVN::Pool->new;
2988
+ $args[4]-- if $args[4] && ! $::_follow_parent;
2989
+ splice(@args, 3, 1) if ($SVN::Core::VERSION le '1.2.0');
2990
+ my $ret = $self->SUPER::get_log(@args, $pool);
2991
+ $pool->clear;
2992
+ $ret;
2993
+}
2994
+
2995
+sub get_commit_editor {
2996
+ my ($self, $msg, $cb, $pool) = @_;
2997
+ my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef, 0) : ();
2998
+ $self->SUPER::get_commit_editor($msg, $cb, @lock, $pool);
2999
+}
3000
+
3001
+sub uuid {
3002
+ my ($self) = @_;
3003
+ $self->{uuid} ||= $self->get_uuid;
3004
+}
3005
+
3006
+sub gs_do_update {
3007
+ my ($self, $rev_a, $rev_b, $path, $recurse, $editor) = @_;
3008
+ my $pool = SVN::Pool->new;
3009
+ my $reporter = $self->do_update($rev_b, $path, $recurse,
3010
+ $editor, $pool);
3011
+ my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
3012
+ my $new = ($rev_a == $rev_b);
3013
+ $reporter->set_path($path, $rev_a, $new, @lock, $pool);
3014
+ $reporter->finish_report($pool);
3015
+ $pool->clear;
3016
+ $editor->{git_commit_ok};
3017
+}
3018
+
3019
+sub gs_do_switch {
3020
+ my ($self, $rev_a, $rev_b, $path, $recurse, $url_b, $editor) = @_;
3021
+ my $pool = SVN::Pool->new;
3022
+ my $reporter = $self->do_switch($rev_b, $path, $recurse,
3023
+ $url_b, $editor, $pool);
3024
+ my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : ();
3025
+ $reporter->set_path($path, $rev_a, 0, @lock, $pool);
3026
+ $reporter->finish_report($pool);
3027
+ $pool->clear;
3028
+ $editor->{git_commit_ok};
3029
+}
3030
+
3031
+sub can_do_switch {
3032
+ my $self = shift;
3033
+ unless (defined $can_do_switch) {
3034
+ my $pool = SVN::Pool->new;
3035
+ my $rep = eval {
3036
+ $self->do_switch(1, '', 0, $self->{url},
3037
+ SVN::Delta::Editor->new, $pool);
3038
+ };
3039
+ if ($@) {
3040
+ $can_do_switch = 0;
3041
+ } else {
3042
+ $rep->abort_report($pool);
3043
+ $can_do_switch = 1;
3044
+ }
3045
+ $pool->clear;
3046
+ }
3047
+ $can_do_switch;
3048
+}
3049
+
3050
__END__
3051
3052
Data structures: