@matheusbsbs / matheus-bagliano / commits / 0fd49d0a7d
Fork 0

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 <spearce@spearce.org>

Shawn O. Pearce committed Jan 24, 2007 at 15:21 UTC 0fd49d0a7d579722bd1a0a1645afc16646b05794
1 file changed +64 -3
git-gui.sh
+64 -3
@@ -1904,7 +1904,7 @@ proc do_create_branch {} {
1904 -width 40 \
1905 -font font_ui
1906 $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}
1908 bind $w.desc.name_t <Shift-Key-Tab> {focus [tk_focusPrev %W];break}
1909 bind $w.desc.name_t <Key-Tab> {focus [tk_focusNext %W];break}
1910 bind $w.desc.name_t <Key-Return> "do_create_branch_action $w;break"
@@ -1954,7 +1954,7 @@ proc do_create_branch {} {
1954 -height 1 \
1955 -width 50 \
1956 -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}
1958 bind $w.from.exp_t <Shift-Key-Tab> {focus [tk_focusPrev %W];break}
1959 bind $w.from.exp_t <Key-Tab> {focus [tk_focusNext %W];break}
1960 bind $w.from.exp_t <Key-Return> "do_create_branch_action $w;break"
@@ -2719,6 +2719,63 @@ proc do_gitk {revs} {
2719 }
2720 }
2721
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 +
2779 proc do_gc {} {
2780 set w [new_console {gc} {Compressing the object database}]
2781 console_exec $w {git gc}
@@ -3542,6 +3599,10 @@ if {![is_MacOSX]} {
3599 .mbar.repository add separator
3600
3601 if {!$single_commit} {
3602 + .mbar.repository add command -label {Database Statistics} \
3603 + -command do_stats \
3604 + -font font_ui
3605 +
3606 .mbar.repository add command -label {Compress Database} \
3607 -command do_gc \
3608 -font font_ui
@@ -3847,7 +3908,7 @@ frame .vpane.lower.commarea
3908 frame .vpane.lower.diff -relief sunken -borderwidth 1
3909 pack .vpane.lower.commarea -side top -fill x
3910 pack .vpane.lower.diff -side bottom -fill both -expand 1
3850 -.vpane add .vpane.lower -stick nsew
3911 +.vpane add .vpane.lower -sticky nsew
3912
3913 # -- Commit Area Buttons
3914 #