@matheusbsbs / matheus-bagliano / commits / 8ff487c737
Fork 0

git-gui: Suggest when running 'git gc' may be worthwhile.

Users often forget to repack their object database, then start to complain about how slow it is to perform common operations after they have collected thousands of loose objects in their objects directory. A simple repack usually restores performance. During startup git-gui now asks git-count-objects how many loose objects exist, and if this number exceeds a hardcoded threshold we suggest that the user compress the database (aka run 'git gc') at this time. I've hardcoded this to 2000 objects on non-Windows systems as there the filesystems tend to handle the ~8 objects per directory just fine. On Windows NTFS and FAT are just so slow that we really start to lag when more than 200 loose objects exist, so the hardcoded threshold is much lower there. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 20, 2007 at 21:23 UTC 8ff487c737fe7a611da03c20f08888fb7f3a3550
1 file changed +40
git-gui.sh
+40
@@ -195,6 +195,25 @@ proc info_popup {msg} {
195 -message $msg
196 }
197
198 +proc ask_popup {msg} {
199 + global gitdir appname
200 +
201 + set title $appname
202 + if {$gitdir ne {}} {
203 + append title { (}
204 + append title [lindex \
205 + [file split [file normalize [file dirname $gitdir]]] \
206 + end]
207 + append title {)}
208 + }
209 + return [tk_messageBox \
210 + -parent . \
211 + -icon question \
212 + -type yesno \
213 + -title $title \
214 + -message $msg]
215 +}
216 +
217 ######################################################################
218 ##
219 ## repository setup
@@ -3790,5 +3809,26 @@ if {!$single_commit} {
3809 populate_push_menu .mbar.push
3810 }
3811
3812 +# -- Only suggest a gc run if we are going to stay running.
3813 +#
3814 +if {!$single_commit} {
3815 + set object_limit 2000
3816 + if {[is_Windows]} {set object_limit 200}
3817 + regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
3818 + if {$objects_current >= $object_limit} {
3819 + if {[ask_popup \
3820 + "This repository currently has $objects_current loose objects.
3821 +
3822 +To maintain optimal performance it is strongly
3823 +recommended that you compress the database
3824 +when more than $object_limit loose objects exist.
3825 +
3826 +Compress the database now?"] eq yes} {
3827 + do_gc
3828 + }
3829 + }
3830 + unset object_limit _junk objects_current
3831 +}
3832 +
3833 lock_index begin-read
3834 after 1 do_rescan