{"thread":{"id":"9000","subject":"[PATCH] script to display a distribution of longest common hash prefixes","startedAt":"2007-07-12T07:40:18Z","lastAt":"2007-07-12T07:40:18Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"47124","messageId":"alpine.LFD.0.999.0707120337420.32552@xanadu.home","threadId":"9000","inReplyTo":null,"subject":"[PATCH] script to display a distribution of longest common hash prefixes","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-07-12T07:40:18Z","receivedAt":"2007-07-12T07:40:18Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"This script was originally posted on the git mailing list by\nRandal L. Schwartz <merlyn@stonehenge.com>.\n    \nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\n\ndiff --git a/contrib/stats/git-common-hash b/contrib/stats/git-common-hash\nnew file mode 100755\nindex 0000000..e27fd08\n--- /dev/null\n+++ b/contrib/stats/git-common-hash\n@@ -0,0 +1,26 @@\n+#!/bin/sh\n+\n+# This script displays the distribution of longest common hash prefixes.\n+# This can be used to determine the minimum prefix length to use\n+# for object names to be unique.\n+\n+git rev-list --objects --all | sort | perl -lne '\n+  substr($_, 40) = \"\";\n+  # uncomment next line for a distribution of bits instead of hex chars\n+  # $_ = unpack(\"B*\",pack(\"H*\",$_));\n+  if (defined $p) {\n+    ($p ^ $_) =~ /^(\\0*)/;\n+    $common = length $1;\n+    if (defined $pcommon) {\n+      $count[$pcommon > $common ? $pcommon : $common]++;\n+    } else {\n+      $count[$common]++; # first item\n+    }\n+  }\n+  $p = $_;\n+  $pcommon = $common;\n+  END {\n+    $count[$common]++; # last item\n+    print \"$_: $count[$_]\" for 0..$#count;\n+  }\n+'\n"}]}