git-gui: allow Ctrl+T to toggle multiple paths
[git/git.git] / lib / database.tcl
CommitLineData
f522c9b5
SP
1# git-gui object database management support
2# Copyright (C) 2006, 2007 Shawn Pearce
3
4proc do_stats {} {
c80d7be5 5 global use_ttk NS
0b812616 6 set fd [git_read count-objects -v]
f522c9b5
SP
7 while {[gets $fd line] > 0} {
8 if {[regexp {^([^:]+): (\d+)$} $line _ name value]} {
9 set stats($name) $value
10 }
11 }
12 close $fd
13
14 set packed_sz 0
15 foreach p [glob -directory [gitdir objects pack] \
16 -type f \
17 -nocomplain -- *] {
18 incr packed_sz [file size $p]
19 }
20 if {$packed_sz > 0} {
21 set stats(size-pack) [expr {$packed_sz / 1024}]
22 }
23
24 set w .stats_view
c80d7be5
PT
25 Dialog $w
26 wm withdraw $w
f522c9b5
SP
27 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
28
c80d7be5
PT
29 ${NS}::frame $w.buttons
30 ${NS}::button $w.buttons.close -text [mc Close] \
f522c9b5
SP
31 -default active \
32 -command [list destroy $w]
c80d7be5 33 ${NS}::button $w.buttons.gc -text [mc "Compress Database"] \
f522c9b5
SP
34 -default normal \
35 -command "destroy $w;do_gc"
36 pack $w.buttons.close -side right
37 pack $w.buttons.gc -side left
38 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
39
c80d7be5 40 ${NS}::labelframe $w.stat -text [mc "Database Statistics"]
f522c9b5 41 foreach s {
1ac17950
CS
42 {count {mc "Number of loose objects"}}
43 {size {mc "Disk space used by loose objects"} { KiB}}
44 {in-pack {mc "Number of packed objects"}}
45 {packs {mc "Number of packs"}}
46 {size-pack {mc "Disk space used by packed objects"} { KiB}}
47 {prune-packable {mc "Packed objects waiting for pruning"}}
48 {garbage {mc "Garbage files"}}
f522c9b5
SP
49 } {
50 set name [lindex $s 0]
1ac17950 51 set label [eval [lindex $s 1]]
f522c9b5
SP
52 if {[catch {set value $stats($name)}]} continue
53 if {[llength $s] > 2} {
54 set value "$value[lindex $s 2]"
55 }
56
eca96368 57 ${NS}::label $w.stat.l_$name -text [mc "%s:" $label] -anchor w
c80d7be5 58 ${NS}::label $w.stat.v_$name -text $value -anchor w
f522c9b5
SP
59 grid $w.stat.l_$name $w.stat.v_$name -sticky we -padx {0 5}
60 }
61 pack $w.stat -pady 10 -padx 10
62
63 bind $w <Visibility> "grab $w; focus $w.buttons.close"
64 bind $w <Key-Escape> [list destroy $w]
65 bind $w <Key-Return> [list destroy $w]
a3d97afa 66 wm title $w [mc "%s (%s): Database Statistics" [appname] [reponame]]
c80d7be5 67 wm deiconify $w
f522c9b5
SP
68 tkwait window $w
69}
70
71proc do_gc {} {
1ac17950 72 set w [console::new {gc} [mc "Compressing the object database"]]
c74b6c66
SP
73 console::chain $w {
74 {exec git pack-refs --prune}
75 {exec git reflog expire --all}
76 {exec git repack -a -d -l}
77 {exec git rerere gc}
78 }
f522c9b5
SP
79}
80
81proc do_fsck_objects {} {
a35d65d9 82 set w [console::new {fsck-objects} \
1ac17950 83 [mc "Verifying the object database with fsck-objects"]]
f522c9b5
SP
84 set cmd [list git fsck-objects]
85 lappend cmd --full
86 lappend cmd --cache
87 lappend cmd --strict
a35d65d9 88 console::exec $w $cmd
f522c9b5 89}
3972b987
SP
90
91proc hint_gc {} {
88520cad
CB
92 set ndirs 1
93 set limit 8
3972b987 94 if {[is_Windows]} {
88520cad
CB
95 set ndirs 4
96 set limit 1
3972b987
SP
97 }
98
88520cad 99 set count [llength [glob \
3972b987 100 -nocomplain \
3972b987 101 -- \
88520cad 102 [gitdir objects 4\[0-[expr {$ndirs-1}]\]/*]]]
3972b987 103
88520cad
CB
104 if {$count >= $limit * $ndirs} {
105 set objects_current [expr {$count * 256/$ndirs}]
3972b987 106 if {[ask_popup \
c8c4854b 107 [mc "This repository currently has approximately %i loose objects.
3972b987 108
88520cad 109To maintain optimal performance it is strongly recommended that you compress the database.
3972b987 110
88520cad 111Compress the database now?" $objects_current]] eq yes} {
3972b987
SP
112 do_gc
113 }
114 }
115}