{"thread":{"id":"43571","subject":"[PATCH] Run \"git repack -a -d\" once more at end, if there's 1MB or more of not-packed data.","startedAt":"2006-11-15T20:15:44Z","lastAt":"2006-11-15T20:15:44Z","messageCount":1,"participants":["Jim Meyering"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"295599","messageId":"87ejs4mpov.fsf@rho.meyering.net","threadId":"43571","inReplyTo":null,"subject":"[PATCH] Run \"git repack -a -d\" once more at end, if there's 1MB or more of not-packed data.","fromName":"Jim Meyering","fromEmail":"jim@meyering.net","sentAt":"2006-11-15T20:15:44Z","receivedAt":"2006-11-15T20:15:44Z","isPatch":true,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"Although I converted upstream coreutils to git last month, I just\nreconverted coreutils once again, as a test, and ended up with a\ngit repository of about 130MB (contrast with my packed git repo of\nsize 52MB).  That was because there were a lot of commits (but < 1024)\nafter the final automatic \"git-repack -a -d\".\n\nRunning a final\n  git-repack -a -d && git-prune-packed\ncut the final repository size down to the expected size.\n\nSo this looks like an easy way to improve git-cvsimport.\nJust run \"git repack ...\" at the end if there's more than\nsome reasonable amount of not-packed data.\n\nMy choice of 1MB is a little arbitrarily.  I wouldn't mind missing\nthe minimal repo size by 1MB.  At the other end of the spectrum,\nit's probably not worthwhile to pack everything when the total\nrepository size is less than 1MB.\n\nHere's the patch:\n\nSigned-off-by: Jim Meyering <jim@meyering.net>\n---\n git-cvsimport.perl |   10 ++++++++++\n 1 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex 14e2c61..b54a948 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -876,6 +876,16 @@ while(<CVS>) {\n }\n commit() if $branch and $state != 11;\n \n+# The heuristic of repacking every 1024 commits can leave a\n+# lot of unpacked data.  If there is more than 1MB worth of\n+# not-packed objects, repack once more.\n+my $line = `git-count-objects`;\n+if ($line =~ /^(\\d+) objects, (\\d+) kilobytes$/) {\n+  my ($n_objects, $kb) = ($1, $2);\n+  1024 < $kb\n+    and system(\"git repack -a -d\");\n+}\n+\n foreach my $git_index (values %index) {\n     if ($git_index ne '.git/index') {\n \tunlink($git_index);\n-- \n"}]}