diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2007-07-17 22:49:44 -0400 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2007-07-17 22:49:44 -0400 |
commit | d164b7548ab61e50d4404d1fbc0da3a8f6c0cc87 (patch) | |
tree | 91d17e3e0bc12a444e9f738edec516d17bbbae0e | |
parent | git-gui: Don't crash in ask_popup if we haven't mapped main window yet (diff) | |
download | tgif-d164b7548ab61e50d4404d1fbc0da3a8f6c0cc87.tar.xz |
git-gui: Change our initial GC hint to be an estimate
Instead of running a full git-count-objects to count all of the loose
objects we can get a reasonably close approximation by counting the
number of files in the .git/objects/42 subdirectory. This works out
reasonably well because the SHA-1 hash has a fairly even distribution,
so every .git/objects/?? subdirectory should get a relatively equal
number of files. If we have at least 8 files in .git/objects/42 than it
is very likely there is about 8 files in every other directory, leaving
us with around 2048 loose objects.
This check is much faster, as we need to only perform a readdir of
a single directory, and we can do it directly from Tcl and avoid the
costly fork+exec.
All of the credit on how clever this is goes to Linus Torvalds; he
suggested using this trick in a post commit hook to repack every so
often.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rwxr-xr-x | git-gui.sh | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/git-gui.sh b/git-gui.sh index 5ca946a184..cd2b093723 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2560,12 +2560,21 @@ if {[is_enabled transport]} { # -- Only suggest a gc run if we are going to stay running. # if {[is_enabled multicommit]} { - set object_limit 2000 - if {[is_Windows]} {set object_limit 200} - regexp {^([0-9]+) objects,} [git count-objects] _junk objects_current + set object_limit 8 + if {[is_Windows]} { + set object_limit 1 + } + set objects_current [llength [glob \ + -directory [gitdir objects 42] \ + -nocomplain \ + -tails \ + -- \ + *]] if {$objects_current >= $object_limit} { + set objects_current [expr {$objects_current * 256}] + set object_limit [expr {$object_limit * 256}] if {[ask_popup \ - "This repository currently has $objects_current loose objects. + "This repository currently has approximately $objects_current loose objects. To maintain optimal performance it is strongly recommended that you compress the database when more than $object_limit loose objects exist. @@ -2573,7 +2582,7 @@ Compress the database now?"] eq yes} { do_gc } } - unset object_limit _junk objects_current + unset object_limit objects_current } lock_index begin-read |