svn import: Add a loop limit option
The svn library has a serious memory leak. Added a new option (-l NUM) which causes git-svnimport to exit cleanly after fetching that many changes, in order to . Signed-Off-By: Matthias Urlichs <smurf@smurf.noris.de>
Matthias Urlichs committed
Oct 10, 2005 at 18:45 UTC
3ef378a67b5b39441837700ab4dfb800eb443c5a
2 files changed
+20
-6
Documentation/git-svnimport.txt
+10
-1
@@ -10,7 +10,7 @@ git-svnimport - Import a SVN repository into git
10
SYNOPSIS
11
--------
12
'git-svnimport' [ -o <branch-for-HEAD> ] [ -h ] [ -v ]
13
- [ -C <GIT_repository> ] [ -i ] [ -u ]
13
+ [ -C <GIT_repository> ] [ -i ] [ -u ] [-l limit_nr_changes]
14
[ -b branch_subdir ] [ -t trunk_subdir ] [ -T tag_subdir ]
15
[ -s start_chg ] [ -m ] [ -M regex ] [ <SVN_repository_URL> ]
16
@@ -70,6 +70,15 @@ When importing incementally, you might need to edit the .git/svn2git file.
70
regex. It can be used with -m to also see the default regexes.
71
You must escape forward slashes.
72
73
+-l <max_num_changes>::
74
+ Limit the number of SVN changesets we pull before quitting.
75
+ This option is necessary because the SVN library has serious memory
76
+ leaks; the recommended value for nontrivial imports is 100.
77
+
78
+ git-svnimport will still exit with a zero exit code. You can check
79
+ the size of the file ".git/svn2git" to determine whether to call
80
+ the importer again.
81
+
82
-v::
83
Verbosity: let 'svnimport' report what it is doing.
84
git-svnimport.perl
+10
-5
@@ -31,19 +31,19 @@ die "Need CVN:COre 1.2.1 or better" if $SVN::Core::VERSION lt "1.2.1";
31
$SIG{'PIPE'}="IGNORE";
32
$ENV{'TZ'}="UTC";
33
34
-our($opt_h,$opt_o,$opt_v,$opt_u,$opt_C,$opt_i,$opt_m,$opt_M,$opt_t,$opt_T,$opt_b,$opt_s);
34
+our($opt_h,$opt_o,$opt_v,$opt_u,$opt_C,$opt_i,$opt_m,$opt_M,$opt_t,$opt_T,$opt_b,$opt_s,$opt_l);
35
36
sub usage() {
37
print STDERR <<END;
38
Usage: ${\basename $0} # fetch/update GIT from CVS
39
- [-o branch-for-HEAD] [-h] [-v]
39
+ [-o branch-for-HEAD] [-h] [-v] [-l max_num_changes]
40
[-C GIT_repository] [-t tagname] [-T trunkname] [-b branchname]
41
[-i] [-u] [-s start_chg] [-m] [-M regex] [SVN_URL]
42
END
43
exit(1);
44
}
45
46
-getopts("b:C:hivmM:o:s:t:T:u") or usage();
46
+getopts("b:C:hil:mM:o:s:t:T:uv") or usage();
47
usage if $opt_h;
48
49
my $tag_name = $opt_t || "tags";
@@ -53,6 +53,7 @@ my $branch_name = $opt_b || "branches";
53
@ARGV <= 1 or usage();
54
55
$opt_o ||= "origin";
56
+$opt_l = 100 unless defined $opt_l;
57
my $git_tree = $opt_C;
58
$git_tree ||= ".";
59
@@ -624,6 +625,10 @@ sub commit_all {
625
while(++$current_rev < $svn->{'maxrev'}) {
626
$svn->{'svn'}->get_log("/",$current_rev,$current_rev,$current_rev,1,1,\&_commit_all,"");
627
commit_all();
628
+ if($opt_l and not --$opt_l) {
629
+ print STDERR "Exiting due to a memory leak. Repeat, please.\n";
630
+ last;
631
+ }
632
}
633
634
@@ -637,7 +642,7 @@ if (defined $orig_git_index) {
642
643
# Now switch back to the branch we were in before all of this happened
644
if($orig_branch) {
640
- print "DONE\n" if $opt_v;
645
+ print "DONE\n" if $opt_v and (not defined $opt_l or $opt_l > 0);
646
system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
647
if $forward_master;
648
unless ($opt_i) {
@@ -646,7 +651,7 @@ if($orig_branch) {
651
}
652
} else {
653
$orig_branch = "master";
649
- print "DONE; creating $orig_branch branch\n" if $opt_v;
654
+ print "DONE; creating $orig_branch branch\n" if $opt_v and (not defined $opt_l or $opt_l > 0);
655
system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
656
unless -f "$git_dir/refs/heads/master";
657
unlink("$git_dir/HEAD");