git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-gui: search 4 directories to improve statistic of gc hint

From
Clemens Buchacher <drizzd@aon.at>
Date
Sep 13, 2009, 22:20 UTC
Message-ID
<20090913222044.GA17146@localhost>
In-Reply-To
<20090913211916.GA5029@localhost>

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 <drizzd@aon.at>
---
 git-gui/lib/database.tcl |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/git-gui/lib/database.tcl b/git-gui/lib/database.tcl
index a18ac8b..d4e0bed 100644
--- a/git-gui/lib/database.tcl
+++ b/git-gui/lib/database.tcl
@@ -89,27 +89,26 @@ proc do_fsck_objects {} {
 }
 
 proc hint_gc {} {
-	set object_limit 8
+	set ndirs 1
+	set limit 8
 	if {[is_Windows]} {
-		set object_limit 1
+		set ndirs 4
+		set limit 1
 	}
 
-	set objects_current [llength [glob \
-		-directory [gitdir objects 42] \
+	set count [llength [glob \
 		-nocomplain \
-		-tails \
 		-- \
-		*]]
+		[gitdir objects 4\[0-[expr {$ndirs-1}]\]/*]]]
 
-	if {$objects_current >= $object_limit} {
-		set objects_current [expr {$objects_current * 250}]
-		set object_limit    [expr {$object_limit    * 250}]
+	if {$count >= $limit * $ndirs} {
+		set objects_current [expr {$count * 256/$ndirs}]
 		if {[ask_popup \
 			[mc "This repository currently has approximately %i loose objects.
 
-To maintain optimal performance it is strongly recommended that you compress the database when more than %i loose objects exist.
+To maintain optimal performance it is strongly recommended that you compress the database.
 
-Compress the database now?" $objects_current $object_limit]] eq yes} {
+Compress the database now?" $objects_current]] eq yes} {
 			do_gc
 		}
 	}
-- 
1.6.5.rc0.164.g5f6b0
Previous: Clemens BuchacherNext: Shawn O. Pearce
Message 12 of 13 in “preserve mtime of local clone”
  1. preserve mtime of local cloneClemens Buchacher, Sep 9, 2009
  2. Junio C HamanoSep 12, 2009
  3. Clemens BuchacherSep 12, 2009
  4. preserve mtime of local cloneClemens Buchacher, Sep 12, 2009
  5. Junio C HamanoSep 13, 2009
  6. preserve mtime of local cloneClemens Buchacher, Sep 13, 2009
  7. git-gui: suggest gc only when counting at least 2 objectsClemens Buchacher, Sep 13, 2009
  8. Junio C HamanoSep 13, 2009
  9. Clemens BuchacherSep 13, 2009
  10. Jeff KingSep 13, 2009
  11. Clemens BuchacherSep 13, 2009
  12. git-gui: search 4 directories to improve statistic of gc hintClemens Buchacher, Sep 13, 2009
  13. Shawn O. PearceSep 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.