Skip to content

Commit 9208961

Browse files
Philip Oakleydscho
authored andcommitted
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 <[email protected]>
1 parent dd1190b commit 9208961

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

git-gui/lib/choose_repository.tcl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ proc _get_recentrepos {} {
247247

248248
proc _unset_recentrepo {p} {
249249
regsub -all -- {([()\[\]{}\.^$+*?\\])} $p {\\\1} p
250-
git config --global --unset-all gui.recentrepo "^$p\$"
250+
catch {git config --global --unset-all gui.recentrepo "^$p\$"}
251251
load_config 1
252252
}
253253

@@ -262,20 +262,19 @@ proc _append_recentrepos {path} {
262262
set i [lsearch $recent $path]
263263
if {$i >= 0} {
264264
_unset_recentrepo $path
265-
set recent [lreplace $recent $i $i]
266265
}
267266

268-
lappend recent $path
269267
git config --global --add gui.recentrepo $path
270268
load_config 1
269+
set recent [get_config gui.recentrepo]
271270

272271
if {[set maxrecent [get_config gui.maxrecentrepo]] eq {}} {
273272
set maxrecent 10
274273
}
275274

276275
while {[llength $recent] > $maxrecent} {
277276
_unset_recentrepo [lindex $recent 0]
278-
set recent [lrange $recent 1 end]
277+
set recent [get_config gui.recentrepo]
279278
}
280279
}
281280

0 commit comments

Comments
 (0)