Skip to content

Commit 0fd49d0

Browse files
committed
git-gui: Display database stats (count-objects -v) on demand.
Its nice to know how many loose objects and roughly how much disk space they are taking up, so that you can guestimate about when might be a good time to run 'Compress Database'. The same is true of packfiles, especially once the automatic keep-pack code in git-fetch starts to be more widely used. We now offer the output of count-objects -v in a nice little dialog hung off the Repository menu. Our labels are slightly more verbose than those of `count-objects -v`, so users will hopefully be able to make better sense of what we are showing them here. We probably should also offer pack file size information, and data about *.idx files which exist which lack corresponding *.pack files (a situation caused by the HTTP fetch client). But in the latter case we should only offer the data once we have way to let the user clean up old and inactive index files. Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 5988527 commit 0fd49d0

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

git-gui.sh

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ proc do_create_branch {} {
19041904
-width 40 \
19051905
-font font_ui
19061906
$w.desc.name_t insert 0.0 $repo_config(gui.newbranchtemplate)
1907-
grid $w.desc.name_l $w.desc.name_t -stick we -padx {0 5}
1907+
grid $w.desc.name_l $w.desc.name_t -sticky we -padx {0 5}
19081908
bind $w.desc.name_t <Shift-Key-Tab> {focus [tk_focusPrev %W];break}
19091909
bind $w.desc.name_t <Key-Tab> {focus [tk_focusNext %W];break}
19101910
bind $w.desc.name_t <Key-Return> "do_create_branch_action $w;break"
@@ -1954,7 +1954,7 @@ proc do_create_branch {} {
19541954
-height 1 \
19551955
-width 50 \
19561956
-font font_ui
1957-
grid $w.from.exp_r $w.from.exp_t -stick we -padx {0 5}
1957+
grid $w.from.exp_r $w.from.exp_t -sticky we -padx {0 5}
19581958
bind $w.from.exp_t <Shift-Key-Tab> {focus [tk_focusPrev %W];break}
19591959
bind $w.from.exp_t <Key-Tab> {focus [tk_focusNext %W];break}
19601960
bind $w.from.exp_t <Key-Return> "do_create_branch_action $w;break"
@@ -2719,6 +2719,63 @@ proc do_gitk {revs} {
27192719
}
27202720
}
27212721

2722+
proc do_stats {} {
2723+
set fd [open "| git count-objects -v" r]
2724+
while {[gets $fd line] > 0} {
2725+
if {[regexp {^([^:]+): (\d+)$} $line _ name value]} {
2726+
set stats($name) $value
2727+
}
2728+
}
2729+
close $fd
2730+
2731+
set w .stats_view
2732+
toplevel $w
2733+
wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
2734+
2735+
label $w.header -text {Database Statistics} \
2736+
-font font_uibold
2737+
pack $w.header -side top -fill x
2738+
2739+
frame $w.buttons -border 1
2740+
button $w.buttons.close -text Close \
2741+
-font font_ui \
2742+
-command [list destroy $w]
2743+
button $w.buttons.gc -text {Compress Database} \
2744+
-font font_ui \
2745+
-command "destroy $w;do_gc"
2746+
pack $w.buttons.close -side right
2747+
pack $w.buttons.gc -side left
2748+
pack $w.buttons -side bottom -fill x -pady 10 -padx 10
2749+
2750+
frame $w.stat -borderwidth 1 -relief solid
2751+
foreach s {
2752+
{count {Number of loose objects}}
2753+
{size {Disk space used by loose objects} { KiB}}
2754+
{in-pack {Number of packed objects}}
2755+
{packs {Number of packs}}
2756+
{prune-packable {Packed objects waiting for pruning}}
2757+
{garbage {Garbage files}}
2758+
} {
2759+
set name [lindex $s 0]
2760+
set label [lindex $s 1]
2761+
if {[catch {set value $stats($name)}]} continue
2762+
if {[llength $s] > 2} {
2763+
set value "$value[lindex $s 2]"
2764+
}
2765+
2766+
label $w.stat.l_$name -text "$label:" -anchor w -font font_ui
2767+
label $w.stat.v_$name -text $value -anchor w -font font_ui
2768+
grid $w.stat.l_$name $w.stat.v_$name -sticky we -padx {0 5}
2769+
}
2770+
pack $w.stat
2771+
2772+
bind $w <Visibility> "grab $w; focus $w"
2773+
bind $w <Key-Escape> [list destroy $w]
2774+
bind $w <Key-Return> [list destroy $w]
2775+
wm title $w "[appname] ([reponame]): Database Statistics"
2776+
tkwait window $w
2777+
}
2778+
27222779
proc do_gc {} {
27232780
set w [new_console {gc} {Compressing the object database}]
27242781
console_exec $w {git gc}
@@ -3542,6 +3599,10 @@ if {![is_MacOSX]} {
35423599
.mbar.repository add separator
35433600

35443601
if {!$single_commit} {
3602+
.mbar.repository add command -label {Database Statistics} \
3603+
-command do_stats \
3604+
-font font_ui
3605+
35453606
.mbar.repository add command -label {Compress Database} \
35463607
-command do_gc \
35473608
-font font_ui
@@ -3847,7 +3908,7 @@ frame .vpane.lower.commarea
38473908
frame .vpane.lower.diff -relief sunken -borderwidth 1
38483909
pack .vpane.lower.commarea -side top -fill x
38493910
pack .vpane.lower.diff -side bottom -fill both -expand 1
3850-
.vpane add .vpane.lower -stick nsew
3911+
.vpane add .vpane.lower -sticky nsew
38513912

38523913
# -- Commit Area Buttons
38533914
#

0 commit comments

Comments
 (0)