Skip to contentSkip to conversation

git-gui: simplify PATH de-duplication

PATCH In review Mark Levedahl 2 participants 2 messages Aug 20, 2025 – Aug 21, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-gui: simplify PATH de-duplication

git-gui since 8fe7861c51 ("git-gui: assure PATH has only absolute elements.", 2025-04-11) uses a list to maintain order and a dict to detect duplicated elements without quadratic complexity. But, Tcl's dict explicitly maintains keys in the order first added, thus the list is not needed. Simplify the code.

---
 git-gui.sh | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
git-gui.sh +1 -6
index b64d065..4528b22 100755
@@ -103,21 +103,16 @@ if {[is_Windows]} {
 	set _path_sep {:}
 }
 
-set _search_path {}
 set _path_seen [dict create]
 foreach p [split $env(PATH) $_path_sep] {
 	# Keep only absolute paths, getting rid of ., empty, etc.
 	if {[file pathtype $p] ne {absolute}} {
 		continue
 	}
-	# Keep only the first occurence of any duplicates.
 	set norm_p [file normalize $p]
-	if {[dict exists $_path_seen $norm_p]} {
-		continue
-	}
 	dict set _path_seen $norm_p 1
-	lappend _search_path $norm_p
 }
+set _search_path [dict keys $_path_seen]
 unset _path_seen
 
 set env(PATH) [join $_search_path $_path_sep]
Signature · 1 line
2.51.0.99.15
#1 lore raw

Am 20.08.25 um 17:31 schrieb Mark Levedahl:

Quoted 28 lines

git-gui since 8fe7861c51 ("git-gui: assure PATH has only absolute elements.", 2025-04-11) uses a list to maintain order and a dict to detect duplicated elements without quadratic complexity. But, Tcl's dict explicitly maintains keys in the order first added, thus the list is not needed. Simplify the code.

---
 git-gui.sh | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
git-gui.sh +0 -2
index b64d065..4528b22 100755
@@ -103,21 +103,16 @@ if {[is_Windows]} {
 	set _path_sep {:}
 }
 
-set _search_path {}
 set _path_seen [dict create]
 foreach p [split $env(PATH) $_path_sep] {
 	# Keep only absolute paths, getting rid of ., empty, etc.
 	if {[file pathtype $p] ne {absolute}} {
 		continue
 	}
-	# Keep only the first occurence of any duplicates.
 	set norm_p [file normalize $p]

git-gui.sh if {[is_Windows]} { · line 118

Quoted 10 lines
git-gui.sh +1 -4
-	if {[dict exists $_path_seen $norm_p]} {
-		continue
-	}
 	dict set _path_seen $norm_p 1
-	lappend _search_path $norm_p
 }
+set _search_path [dict keys $_path_seen]
 unset _path_seen
 
 set env(PATH) [join $_search_path $_path_sep]

Thanks, this looks good; queued. I tweaked it to keep the comment.

-- Hannes