git-svn: add --shared and --template= options to pass to init-db
[gitweb.git] / contrib / git-svn / git-svn.perl
index a24306072e3663ee00ef6f1e7058a75996765d7e..d8f103ed9adada780b56d5ae9270025e0a48ec6d 100755 (executable)
@@ -34,6 +34,8 @@
 my $sha1_short = qr/[a-f\d]{4,40}/;
 my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
        $_find_copies_harder, $_l, $_cp_similarity,
+       $_repack, $_repack_nr, $_repack_flags,
+       $_template, $_shared,
        $_version, $_upgrade, $_authors, $_branch_all_refs);
 my (@_branch_from, %tree_map, %users);
 my ($_svn_co_url_revs, $_svn_pg_peg_revs);
@@ -42,7 +44,9 @@
 my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext,
                'branch|b=s' => \@_branch_from,
                'branch-all-refs|B' => \$_branch_all_refs,
-               'authors-file|A=s' => \$_authors );
+               'authors-file|A=s' => \$_authors,
+               'repack:i' => \$_repack,
+               'repack-flags|repack-args|repack-opts=s' => \$_repack_flags);
 
 # yes, 'native' sets "\n".  Patches to fix this for non-*nix systems welcome:
 my %EOL = ( CR => "\015", LF => "\012", CRLF => "\015\012", native => "\012" );
@@ -51,7 +55,9 @@
        fetch => [ \&fetch, "Download new revisions from SVN",
                        { 'revision|r=s' => \$_revision, %fc_opts } ],
        init => [ \&init, "Initialize a repo for tracking" .
-                         " (requires URL argument)", { } ],
+                         " (requires URL argument)",
+                         { 'template=s' => \$_template,
+                           'shared' => \$_shared } ],
        commit => [ \&commit, "Commit git revisions to SVN",
                        {       'stdin|' => \$_stdin,
                                'edit|e' => \$_edit,
@@ -82,6 +88,7 @@
                'version|V' => \$_version,
                'id|i=s' => \$GIT_SVN) or exit 1;
 
+set_default_vals();
 usage(0) if $_help;
 version() if $_version;
 usage(1) unless defined $cmd;
@@ -213,7 +220,10 @@ sub init {
        $SVN_URL = shift or die "SVN repository location required " .
                                "as a command-line argument\n";
        unless (-d $GIT_DIR) {
-               sys('git-init-db');
+               my @init_db = ('git-init-db');
+               push @init_db, "--template=$_template" if defined $_template;
+               push @init_db, "--shared" if defined $_shared;
+               sys(@init_db);
        }
        setup_git_svn();
 }
@@ -1120,6 +1130,10 @@ sub git_commit {
        sys(@update_ref);
        sys('git-update-ref',"svn/$GIT_SVN/revs/$log_msg->{revision}",$commit);
        print "r$log_msg->{revision} = $commit\n";
+       if ($_repack && (--$_repack_nr == 0)) {
+               $_repack_nr = $_repack;
+               sys("git repack $_repack_flags");
+       }
        return $commit;
 }
 
@@ -1362,6 +1376,14 @@ sub read_repo_config {
        }
 }
 
+sub set_default_vals {
+       if (defined $_repack) {
+               $_repack = 1000 if ($_repack <= 0);
+               $_repack_nr = $_repack;
+               $_repack_flags ||= '';
+       }
+}
+
 __END__
 
 Data structures: