script to display a distribution of longest common hash prefixes
This script was originally posted on the git mailing list by Randal L. Schwartz <merlyn@stonehenge.com>. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nicolas Pitre committed
Jul 12, 2007 at 03:40 UTC
750bd6ac350079cf1f76c24acb7686ad89a95102
1 file changed
+26
contrib/stats/git-common-hash
new
+26
@@ -0,0 +1,26 @@
1
+#!/bin/sh
2
+
3
+# This script displays the distribution of longest common hash prefixes.
4
+# This can be used to determine the minimum prefix length to use
5
+# for object names to be unique.
6
+
7
+git rev-list --objects --all | sort | perl -lne '
8
+ substr($_, 40) = "";
9
+ # uncomment next line for a distribution of bits instead of hex chars
10
+ # $_ = unpack("B*",pack("H*",$_));
11
+ if (defined $p) {
12
+ ($p ^ $_) =~ /^(\0*)/;
13
+ $common = length $1;
14
+ if (defined $pcommon) {
15
+ $count[$pcommon > $common ? $pcommon : $common]++;
16
+ } else {
17
+ $count[$common]++; # first item
18
+ }
19
+ }
20
+ $p = $_;
21
+ $pcommon = $common;
22
+ END {
23
+ $count[$common]++; # last item
24
+ print "$_: $count[$_]" for 0..$#count;
25
+ }
26
+'