git gui: de-dup selected repo from recentrepo history

When the gui/user selects a repo for display, that repo is brought to the end of the recentrepo config list. The logic can fail if there are duplicate old entries for the repo (you cannot unset a single config entry when duplicates are present). Similarly, the maxrecentrepo logic could fail if older duplicate entries are present. The first commit of this series ({this}~2) fixed the config unsetting issue. Rather than manipulating a local copy of the $recent list (one cannot know how many entries were removed), simply re-read it. We must also catch the error when the attempt to remove the second copy from the re-read list is performed. Signed-off-by: Philip Oakley <philipoakley@iee.org>

Philip Oakley committed Dec 14, 2015 at 10:42 UTC e670fce17f79f6305f17f2a91732565909c678dd
1 file changed +3 -4
lib/choose_repository.tcl
+3 -4
@@ -247,7 +247,7 @@ proc _get_recentrepos {} {
247
248 proc _unset_recentrepo {p} {
249 regsub -all -- {([()\[\]{}\.^$+*?\\])} $p {\\\1} p
250 - git config --global --unset-all gui.recentrepo "^$p\$"
250 + catch {git config --global --unset-all gui.recentrepo "^$p\$"}
251 load_config 1
252 }
253
@@ -262,12 +262,11 @@ proc _append_recentrepos {path} {
262 set i [lsearch $recent $path]
263 if {$i >= 0} {
264 _unset_recentrepo $path
265 - set recent [lreplace $recent $i $i]
265 }
266
268 - lappend recent $path
267 git config --global --add gui.recentrepo $path
268 load_config 1
269 + set recent [get_config gui.recentrepo]
270
271 if {[set maxrecent [get_config gui.maxrecentrepo]] eq {}} {
272 set maxrecent 10
@@ -275,7 +274,7 @@ proc _append_recentrepos {path} {
274
275 while {[llength $recent] > $maxrecent} {
276 _unset_recentrepo [lindex $recent 0]
278 - set recent [lrange $recent 1 end]
277 + set recent [get_config gui.recentrepo]
278 }
279 }
280