{"thread":{"id":"4694","subject":"[PATCH] cvsimport - cleanup of the multi-indexes handling","startedAt":"2006-06-28T10:13:23Z","lastAt":"2006-06-28T11:10:38Z","messageCount":2,"participants":["Martin Langhoff","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"22732","messageId":"11514896033560-git-send-email-martin@catalyst.net.nz","threadId":"4694","inReplyTo":null,"subject":"[PATCH] cvsimport - cleanup of the multi-indexes handling","fromName":"Martin Langhoff","fromEmail":"martin@catalyst.net.nz","sentAt":"2006-06-28T10:13:23Z","receivedAt":"2006-06-28T10:13:23Z","isPatch":true,"sender":{"key":"martin@laptop.org","avatar":null},"body":"Indexes are only needed when we are about preparing to commit. Prime them\ninside commit() when we have all the info we need, and remove all the\nredundant index setups.\n\nWhile we are at it, make sure that index handling is correct when opening\nnew branches, and on initial import.\n\nSigned-off-by: Martin Langhoff <martin@catalyst.net.nz>\n\n---\n\nThis has passed some light testing. Applies on top of master, and seems to\ndo the right thing with tidier code . It even makes sense ;-)\n\n---\n git-cvsimport.perl |   62 ++++++++++++++++++++--------------------------------\n 1 files changed, 24 insertions(+), 38 deletions(-)\n\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex 50f5d96..9fa598a 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -467,11 +467,6 @@ my $orig_git_index;\n $orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};\n \n my %index; # holds filenames of one index per branch\n-$index{$opt_o} = tmpnam();\n-\n-$ENV{GIT_INDEX_FILE} = $index{$opt_o};\n-system(\"git-read-tree\", $opt_o);\n-die \"read-tree failed: $?\\n\" if $?;\n \n unless(-d $git_dir) {\n \tsystem(\"git-init-db\");\n@@ -499,14 +494,6 @@ unless(-d $git_dir) {\n \t$orig_branch = $last_branch;\n \t$tip_at_start = `git-rev-parse --verify HEAD`;\n \n-\t# populate index\n-\tunless ($index{$last_branch}) {\n-\t    $index{$last_branch} = tmpnam();\n-\t}\n-\t$ENV{GIT_INDEX_FILE} = $index{$last_branch};\n-\tsystem('git-read-tree', $last_branch);\n-\tdie \"read-tree failed: $?\\n\" if $?;\n-\n \t# Get the last import timestamps\n \topendir(D,\"$git_dir/refs/heads\");\n \twhile(defined(my $head = readdir(D))) {\n@@ -623,6 +610,27 @@ # commits that cvsps cannot place anywhe\n $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;\n \n sub commit {\n+\tif ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) { \n+\t    # looks like an initial commit\n+\t    # use the index primed by git-init-db\n+\t    $ENV{GIT_INDEX_FILE} = '.git/index';\n+\t    $index{$branch} = '.git/index';\n+\t} else {\n+\t    # use an index per branch to speed up\n+\t    # imports of projects with many branches\n+\t    unless ($index{$branch}) {\n+\t\t$index{$branch} = tmpnam();\n+\t\t$ENV{GIT_INDEX_FILE} = $index{$branch};\n+\t\tif ($ancestor) {\n+\t\t    system(\"git-read-tree\", $ancestor);\n+\t\t} else {\n+\t\t    system(\"git-read-tree\", $branch);\n+\t\t}\n+\t\tdie \"read-tree failed: $?\\n\" if $?;\n+\t    }\n+\t}\n+        $ENV{GIT_INDEX_FILE} = $index{$branch};\n+\n \tupdate_index(@old, @new);\n \t@old = @new = ();\n \tmy $tree = write_tree();\n@@ -811,30 +819,6 @@ while(<CVS>) {\n \t\t\tclose(H)\n \t\t\t\tor die \"Could not write branch $branch: $!\";\n \t\t}\n-\t\tif(($ancestor || $branch) ne $last_branch) {\n-\t\t\tprint \"Switching from $last_branch to $branch\\n\" if $opt_v;\n-\t\t\tunless ($index{$branch}) {\n-\t\t\t    $index{$branch} = tmpnam();\n-\t\t\t    $ENV{GIT_INDEX_FILE} = $index{$branch};\n-\t\t\t    system(\"git-read-tree\", $branch);\n-\t\t\t    die \"read-tree failed: $?\\n\" if $?;\n-\t\t\t}\n-\t\t\t# just in case\n-\t\t\t$ENV{GIT_INDEX_FILE} = $index{$branch};\n-\t\t\tif ($ancestor) {\n-\t\t\t    print \"have ancestor $ancestor\" if $opt_v;\n-\t\t\t    system(\"git-read-tree\", $ancestor);\n-\t\t\t    die \"read-tree failed: $?\\n\" if $?;\n-\t\t\t}\n-\t\t} else {\n-\t\t\t# just in case\n-\t\t\tunless ($index{$branch}) {\n-\t\t\t    $index{$branch} = tmpnam();\n-\t\t\t    $ENV{GIT_INDEX_FILE} = $index{$branch};\n-\t\t\t    system(\"git-read-tree\", $branch);\n-\t\t\t    die \"read-tree failed: $?\\n\" if $?;\n-\t\t\t}\n-\t\t}\n \t\t$last_branch = $branch if $branch ne $last_branch;\n \t\t$state = 9;\n \t} elsif($state == 8) {\n@@ -898,7 +882,9 @@ #\tVERSION:1.96->1.96.2.1\n commit() if $branch and $state != 11;\n \n foreach my $git_index (values %index) {\n-    unlink($git_index);\n+    if ($git_index ne '.git/index') {\n+\tunlink($git_index);\n+    }\n }\n \n if (defined $orig_git_index) {\n-- \n1.4.1.rc1.g1ef9\n"},{"id":"22736","messageId":"7vzmfx1qoh.fsf@assigned-by-dhcp.cox.net","threadId":"4694","inReplyTo":"11514896033560-git-send-email-martin@catalyst.net.nz","subject":"Re: [PATCH] cvsimport - cleanup of the multi-indexes handling","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-28T11:10:38Z","receivedAt":"2006-06-28T11:10:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Martin Langhoff <martin@catalyst.net.nz> writes:\n\n> Indexes are only needed when we are about preparing to commit. Prime them\n> inside commit() when we have all the info we need, and remove all the\n> redundant index setups.\n\nObviously makes sense although I admit I do not have to interact\nwith CVS these days anymore (lucky me ;-).\n"}]}