git-svnimport: support for partial imports
This adds support for partial svn imports. Let's assume that SVN repository layout looks like: $trunk/path/to/our/project $branches/path/to/our/project $tags/path/to/our/project , and we would like to import only tree under this specific 'path/to/our/project' and not whole tree under $trunk, $branches, etc.. Now we will be be able to do it by using '-P path/to/our/project' option with git-svnimport. Signed-off-by: Sasha Khapyorsky <sashak@voltaire.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Sasha Khapyorsky committed
Oct 26, 2006 at 00:50 UTC
ec1e46897329317d7a9996264d7e999f9a68e307
1 file changed
+25
-4
git-svnimport.perl
+25
-4
@@ -31,7 +31,7 @@ $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);
34
+ $opt_b,$opt_r,$opt_I,$opt_A,$opt_s,$opt_l,$opt_d,$opt_D,$opt_S,$opt_F,$opt_P);
35
36
sub usage() {
37
print STDERR <<END;
@@ -39,17 +39,19 @@ Usage: ${\basename $0} # fetch/update GIT from SVN
39
[-o branch-for-HEAD] [-h] [-v] [-l max_rev]
40
[-C GIT_repository] [-t tagname] [-T trunkname] [-b branchname]
41
[-d|-D] [-i] [-u] [-r] [-I ignorefilename] [-s start_chg]
42
- [-m] [-M regex] [-A author_file] [-S] [-F] [SVN_URL]
42
+ [-m] [-M regex] [-A author_file] [-S] [-F] [-P project_name] [SVN_URL]
43
END
44
exit(1);
45
}
46
47
-getopts("A:b:C:dDFhiI:l:mM:o:rs:t:T:Suv") or usage();
47
+getopts("A:b:C:dDFhiI:l:mM:o:rs:t:T:SP:uv") or usage();
48
usage if $opt_h;
49
50
my $tag_name = $opt_t || "tags";
51
my $trunk_name = $opt_T || "trunk";
52
my $branch_name = $opt_b || "branches";
53
+my $project_name = $opt_P || "";
54
+$project_name = "/" . $project_name if ($project_name);
55
56
@ARGV == 1 or @ARGV == 2 or usage();
57
@@ -427,6 +429,20 @@ sub get_ignore($$$$$) {
429
}
430
}
431
432
+sub project_path($$)
433
+{
434
+ my ($path, $project) = @_;
435
+
436
+ $path = "/".$path unless ($path =~ m#^\/#) ;
437
+ return $1 if ($path =~ m#^$project\/(.*)$#);
438
+
439
+ $path =~ s#\.#\\\.#g;
440
+ $path =~ s#\+#\\\+#g;
441
+ return "/" if ($project =~ m#^$path.*$#);
442
+
443
+ return undef;
444
+}
445
+
446
sub split_path($$) {
447
my($rev,$path) = @_;
448
my $branch;
@@ -446,7 +462,11 @@ sub split_path($$) {
462
print STDERR "$rev: Unrecognized path: $path\n" unless (defined $no_error{$path});
463
return ()
464
}
449
- $path = "/" if $path eq "";
465
+ if ($path eq "") {
466
+ $path = "/";
467
+ } elsif ($project_name) {
468
+ $path = project_path($path, $project_name);
469
+ }
470
return ($branch,$path);
471
}
472
@@ -898,6 +918,7 @@ sub commit_all {
918
while(my($path,$action) = each %$changed_paths) {
919
($branch,$path) = split_path($revision,$path);
920
next if not defined $branch;
921
+ next if not defined $path;
922
$done{$branch}{$path} = $action;
923
}
924
while(($branch,$changed_paths) = each %done) {