]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-cvsimport.perl
Reuse fixup_pack_header_footer in index-pack
[thirdparty/git.git] / git-cvsimport.perl
index a86ee3cb18ce2d182608c4ce360d4b98844d3bad..ac74bc51b3197d06f13f588d6916400ac3e6fcf0 100755 (executable)
@@ -32,12 +32,15 @@ $ENV{'TZ'}="UTC";
 our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,$opt_M,$opt_A,$opt_S,$opt_L, $opt_a);
 my (%conv_author_name, %conv_author_email);
 
-sub usage() {
+sub usage(;$) {
+       my $msg = shift;
+       print(STDERR "Error: $msg\n") if $msg;
        print STDERR <<END;
 Usage: ${\basename $0}     # fetch/update GIT from CVS
        [-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
-       [-p opts-for-cvsps] [-C GIT_repository] [-z fuzz] [-i] [-k] [-u]
-       [-s subst] [-a] [-m] [-M regex] [-S regex] [CVS_module]
+       [-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]
+       [-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
+       [CVS_module]
 END
        exit(1);
 }
@@ -85,10 +88,38 @@ sub write_author_info($) {
        close ($f);
 }
 
-getopts("hivmkuo:d:p:C:z:s:M:P:A:S:L:") or usage();
+# convert getopts specs for use by git-repo-config
+sub read_repo_config {
+    # Split the string between characters, unless there is a ':'
+    # So "abc:de" becomes ["a", "b", "c:", "d", "e"]
+       my @opts = split(/ *(?!:)/, shift);
+       foreach my $o (@opts) {
+               my $key = $o;
+               $key =~ s/://g;
+               my $arg = 'git-repo-config';
+               $arg .= ' --bool' if ($o !~ /:$/);
+
+        chomp(my $tmp = `$arg --get cvsimport.$key`);
+               if ($tmp && !($arg =~ /--bool/ && $tmp eq 'false')) {
+            no strict 'refs';
+            my $opt_name = "opt_" . $key;
+            if (!$$opt_name) {
+                $$opt_name = $tmp;
+            }
+               }
+       }
+    if (@ARGV == 0) {
+        chomp(my $module = `git-repo-config --get cvsimport.module`);
+        push(@ARGV, $module);
+    }
+}
+
+my $opts = "haivmkuo:d:p:C:z:s:M:P:A:S:L:";
+read_repo_config($opts);
+getopts($opts) or usage();
 usage if $opt_h;
 
-@ARGV <= 1 or usage();
+@ARGV <= 1 or usage("You can't specify more than one CVS module");
 
 if ($opt_d) {
        $ENV{"CVSROOT"} = $opt_d;
@@ -101,7 +132,7 @@ if ($opt_d) {
 } elsif ($ENV{"CVSROOT"}) {
        $opt_d = $ENV{"CVSROOT"};
 } else {
-       die "CVSROOT needs to be set";
+       usage("CVSROOT needs to be set");
 }
 $opt_o ||= "origin";
 $opt_s ||= "-";
@@ -120,7 +151,7 @@ if ($#ARGV == 0) {
        chomp $cvs_tree;
        close $f;
 } else {
-       usage();
+       usage("CVS module has to be specified");
 }
 
 our @mergerx = ();
@@ -520,7 +551,7 @@ $orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};
 my %index; # holds filenames of one index per branch
 
 unless (-d $git_dir) {
-       system("git-init-db");
+       system("git-init");
        die "Cannot init the GIT db at $git_tree: $?\n" if $?;
        system("git-read-tree");
        die "Cannot init an empty tree: $?\n" if $?;
@@ -575,9 +606,11 @@ if ($opt_A) {
 # run cvsps into a file unless we are getting
 # it passed as a file via $opt_P
 #
+my $cvspsfile;
 unless ($opt_P) {
        print "Running cvsps...\n" if $opt_v;
        my $pid = open(CVSPS,"-|");
+       my $cvspsfh;
        die "Cannot fork: $!\n" unless defined $pid;
        unless ($pid) {
                my @opt;
@@ -590,18 +623,18 @@ unless ($opt_P) {
                exec("cvsps","--norc",@opt,"-u","-A",'--root',$opt_d,$cvs_tree);
                die "Could not start cvsps: $!\n";
        }
-       my ($cvspsfh, $cvspsfile) = tempfile('gitXXXXXX', SUFFIX => '.cvsps',
-                                            DIR => File::Spec->tmpdir());
+       ($cvspsfh, $cvspsfile) = tempfile('gitXXXXXX', SUFFIX => '.cvsps',
+                                         DIR => File::Spec->tmpdir());
        while (<CVSPS>) {
            print $cvspsfh $_;
        }
        close CVSPS;
        close $cvspsfh;
-       $opt_P = $cvspsfile;
+} else {
+       $cvspsfile = $opt_P;
 }
 
-
-open(CVS, "<$opt_P") or die $!;
+open(CVS, "<$cvspsfile") or die $!;
 
 ## cvsps output:
 #---------------------
@@ -658,7 +691,7 @@ $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
 sub commit {
        if ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) {
            # looks like an initial commit
-           # use the index primed by git-init-db
+           # use the index primed by git-init
            $ENV{GIT_INDEX_FILE} = '.git/index';
            $index{$branch} = '.git/index';
        } else {
@@ -936,6 +969,10 @@ while (<CVS>) {
 }
 commit() if $branch and $state != 11;
 
+unless ($opt_P) {
+       unlink($cvspsfile);
+}
+
 # The heuristic of repacking every 1024 commits can leave a
 # lot of unpacked data.  If there is more than 1MB worth of
 # not-packed objects, repack once more.