public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail•com>
To: git@vger•kernel.org
Cc: "Shawn O. Pearce" <spearce@spearce•org>,
	Mark Brown <broonie@sirena•org.uk>
Subject: [PATCH 1/3] git-gui: factor out too_many_loose_objects routine from hint_gc
Date: Thu, 18 Feb 2010 08:35:58 -0600	[thread overview]
Message-ID: <20100218143558.GA30520@progeny.tock> (raw)
In-Reply-To: <20100218143431.GA30486@progeny.tock>

Move the heuristic for deciding whether to try a gc into its own
function, to make it easier to change.  No change in behavior
intended.

Signed-off-by: Jonathan Nieder <jrnieder@gmail•com>
---
 lib/database.tcl |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/lib/database.tcl b/lib/database.tcl
index 1f187ed..25a0509 100644
--- a/lib/database.tcl
+++ b/lib/database.tcl
@@ -88,7 +88,16 @@ proc do_fsck_objects {} {
 	console::exec $w $cmd
 }
 
-proc hint_gc {} {
+proc too_many_loose_objects {} {
+	# Quickly check if a "gc" is needed, by estimating how
+	# many loose objects there are.  Because SHA-1 is evenly
+	# distributed, we can check only one and get a reasonable
+	# estimate.
+	#
+	# Roughly based on the function of the same name in builtin-gc.c
+	#
+	# 'git gc' should learn a new --porcelain option
+	# so it can take care of this.
 	set ndirs 1
 	set limit 8
 	if {[is_Windows]} {
@@ -102,7 +111,15 @@ proc hint_gc {} {
 		[gitdir objects 4\[0-[expr {$ndirs-1}]\]/*]]]
 
 	if {$count >= $limit * $ndirs} {
-		set objects_current [expr {$count * 256/$ndirs}]
+		return [expr {$count * 256/$ndirs}]
+	} else {
+		return 0
+	}
+}
+
+proc hint_gc {} {
+	set objects_current [too_many_loose_objects]
+	if {$objects_current != 0} {
 		if {[ask_popup \
 			[mc "This repository currently has approximately %i loose objects.
 
-- 
1.7.0

  reply	other threads:[~2010-02-18 14:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-18 14:34 [RFC/PATCH 0/3] git-gui: Don’t trigger garbage collection warning so easily Jonathan Nieder
2010-02-18 14:35 ` Jonathan Nieder [this message]
2010-02-18 14:39 ` [PATCH/RFC 2/3] git-gui: Do not hold the user hostage with a full gc at startup Jonathan Nieder
2010-02-18 14:41 ` [PATCH/RFC 3/3] git-gui: Do not suggest a gc if gc --auto would not do it Jonathan Nieder
2010-02-18 15:49   ` Jonathan Nieder
2010-02-18 20:40 ` [RFC/PATCH 0/3] git-gui: Don’t trigger garbage collection warning so easily Johannes Sixt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100218143558.GA30520@progeny.tock \
    --to=jrnieder@gmail$(echo .)com \
    --cc=broonie@sirena$(echo .)org.uk \
    --cc=git@vger$(echo .)kernel.org \
    --cc=spearce@spearce$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox