Skip to contentSkip to conversation

git-gui: make gc warning threshold match 'git gc --auto'

PATCH In review Karsten Blees 2 participants 2 messages Jun 15, 2016 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-gui: make gc warning threshold match 'git gc --auto'

The number of loose objects at which git-gui shows a gc warning has historically been hardcoded to ~2000, or ~200 on Windows. The warning can only be disabled completely via gui.gcwarning=false.

Especially on Windows, the hardcoded threshold is so ridiculously low that git-gui often complains even immediately after gc (due to loose objects only referenced by the reflog).

'git gc --auto' uses a much bigger threshold to check if gc is necessary. Additionally, the value can be configured via gc.auto (default 6700). There's no special case for Windows.

Change git-gui so that it only warns if 'git gc --auto' would also do an automatic gc, i.e.:
- calculate the threshold from the gc.auto setting (default 6700, disabled if <= 0)
- check directory .git/objects/17

We still check four directories (14-17) if gc.auto is very small, to get a better estimate.

---
 git-gui/lib/database.tcl | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
git-gui/lib/database.tcl +12 -5
index 1f187ed..212b195 100644
@@ -89,19 +89,26 @@ proc do_fsck_objects {} {
 }
 
 proc hint_gc {} {
+	global repo_config
+	set auto_gc $repo_config(gc.auto)
+	if {$auto_gc eq {}} {
+		set auto_gc 6700
+	} elseif {$auto_gc <= 0} {
+		return
+	}
+
 	set ndirs 1
-	set limit 8
-	if {[is_Windows]} {
+	set limit [expr {($auto_gc + 255) / 256}]
+	if {$limit < 4} {
 		set ndirs 4
-		set limit 1
 	}
 
 	set count [llength [glob \
 		-nocomplain \
 		-- \
-		[gitdir objects 4\[0-[expr {$ndirs-1}]\]/*]]]
+		[gitdir objects 1\[[expr {8-$ndirs}]-7\]/*]]]
 
-	if {$count >= $limit * $ndirs} {
+	if {$count > $limit * $ndirs} {
 		set objects_current [expr {$count * 256/$ndirs}]
 		if {[ask_popup \
 			[mc "This repository currently has approximately %i loose objects.
Signature · 1 line
2.0.3.921.ga7e731a.dirty
#1 lore raw
Quoted 52 lines · Karsten Blees

The number of loose objects at which git-gui shows a gc warning has historically been hardcoded to ~2000, or ~200 on Windows. The warning can only be disabled completely via gui.gcwarning=false.

Especially on Windows, the hardcoded threshold is so ridiculously low that git-gui often complains even immediately after gc (due to loose objects only referenced by the reflog).

'git gc --auto' uses a much bigger threshold to check if gc is necessary. Additionally, the value can be configured via gc.auto (default 6700). There's no special case for Windows.

Change git-gui so that it only warns if 'git gc --auto' would also do an automatic gc, i.e.:
- calculate the threshold from the gc.auto setting (default 6700, disabled if <= 0)
- check directory .git/objects/17

We still check four directories (14-17) if gc.auto is very small, to get a better estimate.

---
git-gui/lib/database.tcl | 17 ++++++++++++-----

1 file changed, 12 insertions(+), 5 deletions(-)
git-gui/lib/database.tcl +10 -3
index 1f187ed..212b195 100644
@@ -89,19 +89,26 @@ proc do_fsck_objects {} {
 }
 
 proc hint_gc {} {
+	global repo_config
+	set auto_gc $repo_config(gc.auto)
+	if {$auto_gc eq {}} {
+		set auto_gc 6700
+	} elseif {$auto_gc <= 0} {
+		return
+	}
+
 	set ndirs 1
-	set limit 8
-	if {[is_Windows]} {
+	set limit [expr {($auto_gc + 255) / 256}]
+	if {$limit < 4} {
 		set ndirs 4
-		set limit 1
 	}
 
 	set count [llength [glob \

git-gui/lib/database.tcl proc do_fsck_objects {} { · line 114

Quoted 10 lines
git-gui/lib/database.tcl +2 -2
 		-nocomplain \
 		-- \
-		[gitdir objects 4\[0-[expr {$ndirs-1}]\]/*]]]
+		[gitdir objects 1\[[expr {8-$ndirs}]-7\]/*]]]
 
-	if {$count >= $limit * $ndirs} {
+	if {$count > $limit * $ndirs} {
 		set objects_current [expr {$count * 256/$ndirs}]
 		if {[ask_popup \
 			[mc "This repository currently has approximately %i loose objects.

Applying this to git-gui I get an error raised
can't read "repo_config(gc.auto)": no such element in array
which occurs because I've never set this config variable and it is not present in the default_config array which is used to initialize repo_config.

The following should solve this by moving where we ser the default:

Quoted 1 line

From bdb136cbcb2a3fc0e3441f852e4bf4525ee4cf99 Mon Sep 17 00:00:00 2001

From: Pat Thoyts <[email protected]>
Date: Sun, 10 Aug 2014 11:36:47 +0100
Subject: [PATCH] git-gui: initialize the default value for gc.auto in case it
is unset.

---
 git-gui.sh       | 1 +
 lib/database.tcl | 4 +---
 2 files changed, 2 insertions(+), 3 deletions(-)
git-gui.sh +1 -0
index b186329..ee9c47b 100755
@@ -880,6 +880,7 @@ proc apply_config {} {
 }
 
 set default_config(branch.autosetupmerge) true
+set default_config(gc.auto) 6700
 set default_config(merge.tool) {}
 set default_config(mergetool.keepbackup) true
 set default_config(merge.diffstat) true
lib/database.tcl +1 -3
index 212b195..d9ba323 100644
@@ -91,9 +91,7 @@ proc do_fsck_objects {} {
 proc hint_gc {} {
 	global repo_config
 	set auto_gc $repo_config(gc.auto)
-	if {$auto_gc eq {}} {
-		set auto_gc 6700
-	} elseif {$auto_gc <= 0} {
+	if {$auto_gc <= 0} {
 		return
 	}
 
Signature · 2 lines
Pat Thoyts                            http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD