# [PATCH] git-gui: simplify PATH de-duplication

2 messages from 2025-08-20 to 2025-08-21. Participants: Mark Levedahl, Johannes Sixt.
Thread: https://gitlist.dev/t/63997

## Mark Levedahl, 2025-08-20 15:31

Subject: [PATCH] git-gui: simplify PATH de-duplication
Message-ID: <20250820153143.21181-1-mlevedahl@gmail.com>
URL: https://gitlist.dev/e/20250820153143.21181-1-mlevedahl%40gmail.com

```
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.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
 git-gui.sh | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/git-gui.sh b/git-gui.sh
index b64d065..4528b22 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -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]
-- 
2.51.0.99.15


```

## Johannes Sixt, 2025-08-21 18:39

Subject: Re: [PATCH] git-gui: simplify PATH de-duplication
Message-ID: <db481d03-1ebb-4e85-8b82-21ff3945289d@kdbg.org>
URL: https://gitlist.dev/e/db481d03-1ebb-4e85-8b82-21ff3945289d%40kdbg.org
In-Reply-To: <20250820153143.21181-1-mlevedahl@gmail.com>

```
Am 20.08.25 um 17:31 schrieb Mark Levedahl:
> 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.
> 
> Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
> ---
>  git-gui.sh | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/git-gui.sh b/git-gui.sh
> index b64d065..4528b22 100755
> --- a/git-gui.sh
> +++ b/git-gui.sh
> @@ -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]

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

-- Hannes


```
