Skip to content

Commit 88520ca

Browse files
Clemens Buchacherspearce
authored andcommitted
git-gui: search 4 directories to improve statistic of gc hint
On Windows, git-gui suggests running the garbage collector if it finds 1 or more files in .git/objects/42 (as opposed to 8 files on other platforms). The probability of that happening if the repo contains about 100 loose objects is 32%. The probability for the same to happen when searching 4 directories is only 8%, which is bit more reasonable. Also remove $objects_limit from the message, because we already know that we are above (or close to) that limit. Telling the user about that number does not really give him any useful information. The following octave script shows the probability for at least m*q objects to be found in q subdirectories of .git/objects if n is the total number of objects. q = 4; m = [1 2 8]; n = 0:10:2000; P = zeros(length(n), length(m)); for k = 1:length(n) P(k, :) = 1-binocdf(q*m-1, n(k), q/(256-q)); end plot(n, P); n \ q 1 4 50 18% 1% 100 32% 8% 200 54% 39% 500 86% 96% Signed-off-by: Clemens Buchacher <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent c0d1532 commit 88520ca

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/database.tcl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,26 @@ proc do_fsck_objects {} {
8989
}
9090

9191
proc hint_gc {} {
92-
set object_limit 8
92+
set ndirs 1
93+
set limit 8
9394
if {[is_Windows]} {
94-
set object_limit 1
95+
set ndirs 4
96+
set limit 1
9597
}
9698

97-
set objects_current [llength [glob \
98-
-directory [gitdir objects 42] \
99+
set count [llength [glob \
99100
-nocomplain \
100-
-tails \
101101
-- \
102-
*]]
102+
[gitdir objects 4\[0-[expr {$ndirs-1}]\]/*]]]
103103

104-
if {$objects_current >= $object_limit} {
105-
set objects_current [expr {$objects_current * 250}]
106-
set object_limit [expr {$object_limit * 250}]
104+
if {$count >= $limit * $ndirs} {
105+
set objects_current [expr {$count * 256/$ndirs}]
107106
if {[ask_popup \
108107
[mc "This repository currently has approximately %i loose objects.
109108
110-
To maintain optimal performance it is strongly recommended that you compress the database when more than %i loose objects exist.
109+
To maintain optimal performance it is strongly recommended that you compress the database.
111110
112-
Compress the database now?" $objects_current $object_limit]] eq yes} {
111+
Compress the database now?" $objects_current]] eq yes} {
113112
do_gc
114113
}
115114
}

0 commit comments

Comments
 (0)