Skip to content

Commit a82c71b

Browse files
committed
add-path reviewed
1 parent 6b06afc commit a82c71b

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

tcl/envmngt.tcl.in

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,18 +1816,19 @@ proc add-path {cmd mode dflbhv args} {
18161816
set val [get-env $var]
18171817

18181818
foreach dir $path_list {
1819-
# if path_entry_reorder is TRUE && dir is in path
1820-
# && duplicates are NOT allowed:
1821-
# path: remove all occurences of $dir
1822-
# if path_entry_reorder is TRUE || dir is NOT in path
1823-
# || duplicates are allowed:
1824-
# path: append/prepend $dir
1819+
# remove $dir from path only if path_entry_reorder is true and
1820+
# $dir is already in path and duplicates are NOT allowed.
18251821
if {[getConf path_entry_reorder] && [info exists countarr($dir)]\
18261822
&& ! $allow_dup} {
18271823
set mpath_list [split $val $separator]
18281824
set mpath_list [lsearch -inline -all -not -exact $mpath_list $dir]
18291825
set val [join $mpath_list $separator]
18301826
}
1827+
# add $dir to beginning or end only if path_entry_reorder is true or
1828+
# $dir is NOT in path or duplicates are allowed.
1829+
# Please note: if path_entry_reorder is true and duplicates are not
1830+
# allowed, $dir is not in path ($val) - either it was not in or it
1831+
# had been removed. Hence we have to add it.
18311832
if {[getConf path_entry_reorder] || ![info exists countarr($dir)]\
18321833
|| $allow_dup} {
18331834
# ignore env var set empty if no empty entry found in reference
@@ -1844,17 +1845,14 @@ proc add-path {cmd mode dflbhv args} {
18441845
#### ref-counting
18451846
# if $dir is NOT in path
18461847
# set ref-count 1
1847-
# else if duplicates are allowed || ref-counting is NOT ignored
1848-
# incr ref-count
1849-
if {[info exists countarr($dir)]} {
1850-
# do not increase counter if bare separator string is added or if
1851-
# reference count is ignored (--ignore-refcount set) unless if
1852-
# duplicate mode is enabled (--duplicates set)
1853-
if {!$val_set_is_delim && (!$ign_refcount || $allow_dup)} {
1854-
incr countarr($dir)
1855-
}
1856-
} else {
1848+
# else
1849+
# do NOT increase counter if bare separator string is added or if
1850+
# reference count is ignored (--ignore-refcount set) unless if
1851+
# duplicate mode is enabled (--duplicates set)
1852+
if {![info exists countarr($dir)]} {
18571853
set countarr($dir) 1
1854+
} elseif {!$val_set_is_delim && (!$ign_refcount || $allow_dup)} {
1855+
incr countarr($dir)
18581856
}
18591857
}
18601858

0 commit comments

Comments
 (0)