Git development
 help / color / mirror / Atom feed
From: Martin Langhoff <martin@catalyst.net.nz>
To: git@vger.kernel.org, junkio@cox.net, Johannes.Schindelin@gmx.de
Cc: Martin Langhoff <martin@catalyst.net.nz>
Subject: [PATCH] cvsimport - cleanup of the multi-indexes handling
Date: Wed, 28 Jun 2006 22:13:23 +1200	[thread overview]
Message-ID: <11514896033560-git-send-email-martin@catalyst.net.nz> (raw)

Indexes are only needed when we are about preparing to commit. Prime them
inside commit() when we have all the info we need, and remove all the
redundant index setups.

While we are at it, make sure that index handling is correct when opening
new branches, and on initial import.

Signed-off-by: Martin Langhoff <martin@catalyst.net.nz>

---

This has passed some light testing. Applies on top of master, and seems to
do the right thing with tidier code . It even makes sense ;-)

---
 git-cvsimport.perl |   62 ++++++++++++++++++++--------------------------------
 1 files changed, 24 insertions(+), 38 deletions(-)

diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 50f5d96..9fa598a 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -467,11 +467,6 @@ my $orig_git_index;
 $orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};
 
 my %index; # holds filenames of one index per branch
-$index{$opt_o} = tmpnam();
-
-$ENV{GIT_INDEX_FILE} = $index{$opt_o};
-system("git-read-tree", $opt_o);
-die "read-tree failed: $?\n" if $?;
 
 unless(-d $git_dir) {
 	system("git-init-db");
@@ -499,14 +494,6 @@ unless(-d $git_dir) {
 	$orig_branch = $last_branch;
 	$tip_at_start = `git-rev-parse --verify HEAD`;
 
-	# populate index
-	unless ($index{$last_branch}) {
-	    $index{$last_branch} = tmpnam();
-	}
-	$ENV{GIT_INDEX_FILE} = $index{$last_branch};
-	system('git-read-tree', $last_branch);
-	die "read-tree failed: $?\n" if $?;
-
 	# Get the last import timestamps
 	opendir(D,"$git_dir/refs/heads");
 	while(defined(my $head = readdir(D))) {
@@ -623,6 +610,27 @@ # commits that cvsps cannot place anywhe
 $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
+	    $ENV{GIT_INDEX_FILE} = '.git/index';
+	    $index{$branch} = '.git/index';
+	} else {
+	    # use an index per branch to speed up
+	    # imports of projects with many branches
+	    unless ($index{$branch}) {
+		$index{$branch} = tmpnam();
+		$ENV{GIT_INDEX_FILE} = $index{$branch};
+		if ($ancestor) {
+		    system("git-read-tree", $ancestor);
+		} else {
+		    system("git-read-tree", $branch);
+		}
+		die "read-tree failed: $?\n" if $?;
+	    }
+	}
+        $ENV{GIT_INDEX_FILE} = $index{$branch};
+
 	update_index(@old, @new);
 	@old = @new = ();
 	my $tree = write_tree();
@@ -811,30 +819,6 @@ while(<CVS>) {
 			close(H)
 				or die "Could not write branch $branch: $!";
 		}
-		if(($ancestor || $branch) ne $last_branch) {
-			print "Switching from $last_branch to $branch\n" if $opt_v;
-			unless ($index{$branch}) {
-			    $index{$branch} = tmpnam();
-			    $ENV{GIT_INDEX_FILE} = $index{$branch};
-			    system("git-read-tree", $branch);
-			    die "read-tree failed: $?\n" if $?;
-			}
-			# just in case
-			$ENV{GIT_INDEX_FILE} = $index{$branch};
-			if ($ancestor) {
-			    print "have ancestor $ancestor" if $opt_v;
-			    system("git-read-tree", $ancestor);
-			    die "read-tree failed: $?\n" if $?;
-			}
-		} else {
-			# just in case
-			unless ($index{$branch}) {
-			    $index{$branch} = tmpnam();
-			    $ENV{GIT_INDEX_FILE} = $index{$branch};
-			    system("git-read-tree", $branch);
-			    die "read-tree failed: $?\n" if $?;
-			}
-		}
 		$last_branch = $branch if $branch ne $last_branch;
 		$state = 9;
 	} elsif($state == 8) {
@@ -898,7 +882,9 @@ #	VERSION:1.96->1.96.2.1
 commit() if $branch and $state != 11;
 
 foreach my $git_index (values %index) {
-    unlink($git_index);
+    if ($git_index ne '.git/index') {
+	unlink($git_index);
+    }
 }
 
 if (defined $orig_git_index) {
-- 
1.4.1.rc1.g1ef9

             reply	other threads:[~2006-06-28 10:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-28 10:13 Martin Langhoff [this message]
2006-06-28 11:10 ` [PATCH] cvsimport - cleanup of the multi-indexes handling Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11514896033560-git-send-email-martin@catalyst.net.nz \
    --to=martin@catalyst.net.nz \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox