@matheusbsbs / matheus-bagliano / commits / 24f7c64b21
Fork 0

git-gui: offer a list of recent repositories on startup

If git-gui is started outside a work tree the repository chooser will offer a list of recently opened repositories. Clicking on any list entry directly opens the repository. The list of recently opened repositories is stored in the config as the multi-valued option gui.recentrepo. If the list grows beyond 10 entries it will be truncated by removing one of the older entries. Only repositories that are opened through the repository chooser will get added to the recent list. Repositories opened from the shell will not yet be added to the recent list, as users are likely to have a way to easily return to the same directory via their shell. [sp: This is actually a combined work from both Steffen and myself. Most of the ideas are Steffen's, as is the basic outline of the code, but any outstanding bugs are entirely my fault.] Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Steffen Prohaska committed Oct 8, 2007 at 08:25 UTC 24f7c64b21bb26aab5b8525c0bac8452e7a7a4c8
2 files changed +83
git-gui.sh
+1
@@ -205,6 +205,7 @@ proc disable_option {option} {
205
206 proc is_many_config {name} {
207 switch -glob -- $name {
208 + gui.recentrepo -
209 remote.*.fetch -
210 remote.*.push
211 {return 1}
lib/choose_repository.tcl
+82
@@ -9,6 +9,7 @@ field w_body ; # Widget holding the center content
9 field w_next ; # Next button
10 field o_cons ; # Console object (if active)
11 field w_types ; # List of type buttons in clone
12 +field w_recentlist ; # Listbox containing recent repositories
13
14 field action new ; # What action are we going to perform?
15 field done 0 ; # Finished picking the repository?
@@ -17,6 +18,7 @@ field origin_url {} ; # Where we are cloning from
18 field origin_name origin ; # What we shall call 'origin'
19 field clone_type hardlink ; # Type of clone to construct
20 field readtree_err ; # Error output from read-tree (if any)
21 +field sorted_recent ; # recent repositories (sorted)
22
23 constructor pick {} {
24 global M1T M1B
@@ -82,6 +84,40 @@ constructor pick {} {
84 pack $w_body.new -anchor w -fill x
85 pack $w_body.clone -anchor w -fill x
86 pack $w_body.open -anchor w -fill x
87 +
88 + set sorted_recent [_get_recentrepos]
89 + if {[llength $sorted_recent] > 0} {
90 + label $w_body.space
91 + label $w_body.recentlabel \
92 + -anchor w \
93 + -text [mc "Open Recent Repository:"]
94 + set w_recentlist $w_body.recentlist
95 + text $w_recentlist \
96 + -cursor $::cursor_ptr \
97 + -relief flat \
98 + -background [$w_body.recentlabel cget -background] \
99 + -wrap none \
100 + -width 50 \
101 + -height 10
102 + $w_recentlist tag conf link \
103 + -foreground blue \
104 + -underline 1
105 + set home "[file normalize $::env(HOME)][file separator]"
106 + set hlen [string length $home]
107 + foreach p $sorted_recent {
108 + if {[string equal -length $hlen $home $p]} {
109 + set p "~[file separator][string range $p $hlen end]"
110 + }
111 + regsub -all "\n" $p "\\n" p
112 + $w_recentlist insert end $p link
113 + $w_recentlist insert end "\n"
114 + }
115 + $w_recentlist conf -state disabled
116 + $w_recentlist tag bind link <1> [cb _open_recent %x,%y]
117 + pack $w_body.space -anchor w -fill x
118 + pack $w_body.recentlabel -anchor w -fill x
119 + pack $w_recentlist -anchor w -fill x
120 + }
121 pack $w_body -fill x -padx 10 -pady 10
122
123 frame $w.buttons
@@ -134,6 +170,50 @@ method _invoke_next {} {
170 }
171 }
172
173 +proc _get_recentrepos {} {
174 + set recent [list]
175 + foreach p [get_config gui.recentrepo] {
176 + if {[_is_git [file join $p .git]]} {
177 + lappend recent $p
178 + }
179 + }
180 + return [lsort $recent]
181 +}
182 +
183 +proc _unset_recentrepo {p} {
184 + regsub -all -- {([()\[\]{}\.^$+*?\\])} $p {\\\1} p
185 + git config --global --unset gui.recentrepo "^$p\$"
186 +}
187 +
188 +proc _append_recentrepos {path} {
189 + set path [file normalize $path]
190 + set recent [get_config gui.recentrepo]
191 +
192 + if {[lindex $recent end] eq $path} {
193 + return
194 + }
195 +
196 + set i [lsearch $recent $path]
197 + if {$i >= 0} {
198 + _unset_recentrepo $path
199 + set recent [lreplace $recent $i $i]
200 + }
201 +
202 + lappend recent $path
203 + git config --global --add gui.recentrepo $path
204 +
205 + while {[llength $recent] > 10} {
206 + _unset_recentrepo [lindex $recent 0]
207 + set recent [lrange $recent 1 end]
208 + }
209 +}
210 +
211 +method _open_recent {xy} {
212 + set id [lindex [split [$w_recentlist index @$xy] .] 0]
213 + set local_path [lindex $sorted_recent [expr {$id - 1}]]
214 + _do_open2 $this
215 +}
216 +
217 method _next {} {
218 destroy $w_body
219 _do_$action $this
@@ -174,6 +254,7 @@ method _git_init {} {
254 return 0
255 }
256
257 + _append_recentrepos [pwd]
258 set ::_gitdir .git
259 set ::_prefix {}
260 return 1
@@ -856,6 +937,7 @@ method _do_open2 {} {
937 return
938 }
939
940 + _append_recentrepos [pwd]
941 set ::_gitdir .git
942 set ::_prefix {}
943 set done 1