@matheusbsbs / matheus-bagliano / commits / 40006ea039
Fork 0

git-svnimport: support for incremental import

This adds ability to do import "in chunks" (default 1000 revisions), after each chunk git repo will be repacked. The option -R is used to change default value of chunk size (or how often repository will repacked). Signed-off-by: Sasha Khapyorsky <sashak@voltaire.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Sasha Khapyorsky committed Jan 7, 2007 at 02:17 UTC 40006ea039b8d72cf6dce5816a50c8ba266833ee
2 files changed +34 -8
Documentation/git-svnimport.txt
+9 -1
@@ -15,7 +15,7 @@ SYNOPSIS
15 [ -b branch_subdir ] [ -T trunk_subdir ] [ -t tag_subdir ]
16 [ -s start_chg ] [ -m ] [ -r ] [ -M regex ]
17 [ -I <ignorefile_name> ] [ -A <author_file> ]
18 - [ -P <path_from_trunk> ]
18 + [ -R <repack_each_revs>] [ -P <path_from_trunk> ]
19 <SVN_repository_URL> [ <path> ]
20
21
@@ -108,6 +108,14 @@ repository without -A.
108 Formerly, this option controlled how many revisions to pull,
109 due to SVN memory leaks. (These have been worked around.)
110
111 +-R <repack_each_revs>::
112 + Specify how often git repository should be repacked.
113 ++
114 +The default value is 1000. git-svnimport will do import in chunks of 1000
115 +revisions, after each chunk git repository will be repacked. To disable
116 +this behavior specify some big value here which is mote than number of
117 +revisions to import.
118 +
119 -P <path_from_trunk>::
120 Partial import of the SVN tree.
121 +
git-svnimport.perl
+25 -7
@@ -31,12 +31,13 @@ $SIG{'PIPE'}="IGNORE";
31 $ENV{'TZ'}="UTC";
32
33 our($opt_h,$opt_o,$opt_v,$opt_u,$opt_C,$opt_i,$opt_m,$opt_M,$opt_t,$opt_T,
34 - $opt_b,$opt_r,$opt_I,$opt_A,$opt_s,$opt_l,$opt_d,$opt_D,$opt_S,$opt_F,$opt_P);
34 + $opt_b,$opt_r,$opt_I,$opt_A,$opt_s,$opt_l,$opt_d,$opt_D,$opt_S,$opt_F,
35 + $opt_P,$opt_R);
36
37 sub usage() {
38 print STDERR <<END;
39 Usage: ${\basename $0} # fetch/update GIT from SVN
39 - [-o branch-for-HEAD] [-h] [-v] [-l max_rev]
40 + [-o branch-for-HEAD] [-h] [-v] [-l max_rev] [-R repack_each_revs]
41 [-C GIT_repository] [-t tagname] [-T trunkname] [-b branchname]
42 [-d|-D] [-i] [-u] [-r] [-I ignorefilename] [-s start_chg]
43 [-m] [-M regex] [-A author_file] [-S] [-F] [-P project_name] [SVN_URL]
@@ -44,7 +45,7 @@ END
45 exit(1);
46 }
47
47 -getopts("A:b:C:dDFhiI:l:mM:o:rs:t:T:SP:uv") or usage();
48 +getopts("A:b:C:dDFhiI:l:mM:o:rs:t:T:SP:R:uv") or usage();
49 usage if $opt_h;
50
51 my $tag_name = $opt_t || "tags";
@@ -52,6 +53,7 @@ my $trunk_name = $opt_T || "trunk";
53 my $branch_name = $opt_b || "branches";
54 my $project_name = $opt_P || "";
55 $project_name = "/" . $project_name if ($project_name);
56 +my $repack_after = $opt_R || 1000;
57
58 @ARGV == 1 or @ARGV == 2 or usage();
59
@@ -934,11 +936,27 @@ if ($opt_l < $current_rev) {
936 exit;
937 }
938
937 -print "Fetching from $current_rev to $opt_l ...\n" if $opt_v;
939 +print "Processing from $current_rev to $opt_l ...\n" if $opt_v;
940
939 -my $pool=SVN::Pool->new;
940 -$svn->{'svn'}->get_log("/",$current_rev,$opt_l,0,1,1,\&commit_all,$pool);
941 -$pool->clear;
941 +my $from_rev;
942 +my $to_rev = $current_rev;
943 +
944 +while ($to_rev < $opt_l) {
945 + $from_rev = $to_rev;
946 + $to_rev = $from_rev + $repack_after;
947 + $to_rev = $opt_l if $opt_l < $to_rev;
948 + print "Fetching from $from_rev to $to_rev ...\n" if $opt_v;
949 + my $pool=SVN::Pool->new;
950 + $svn->{'svn'}->get_log("/",$from_rev,$to_rev,0,1,1,\&commit_all,$pool);
951 + $pool->clear;
952 + my $pid = fork();
953 + die "Fork: $!\n" unless defined $pid;
954 + unless($pid) {
955 + exec("git-repack", "-d")
956 + or die "Cannot repack: $!\n";
957 + }
958 + waitpid($pid, 0);
959 +}
960
961
962 unlink($git_index);