Skip to content

Commit 6b06afc

Browse files
committed
path_entry_reorder code reviewed
1 parent e48dea7 commit 6b06afc

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

tcl/envmngt.tcl.in

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,46 +1816,45 @@ 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
18191825
if {[getConf path_entry_reorder] && [info exists countarr($dir)]\
18201826
&& ! $allow_dup} {
1821-
# if $dir is in $val and duplicates are not allowed:
1822-
# first remove all occurences of $dir in $val
1823-
# and add $dir at the beginning or end if $val
1824-
# is not the empty string
18251827
set mpath_list [split $val $separator]
18261828
set mpath_list [lsearch -inline -all -not -exact $mpath_list $dir]
18271829
set val [join $mpath_list $separator]
1828-
if {$val ne {}} {
1830+
}
1831+
if {[getConf path_entry_reorder] || ![info exists countarr($dir)]\
1832+
|| $allow_dup} {
1833+
# ignore env var set empty if no empty entry found in reference
1834+
# counter array (sometimes var is cleared by setting it empty not
1835+
# unsetting it)
1836+
if {$val ne {} || [info exists countarr()]} {
18291837
set sep [expr {$val eq $separator ? {} : $separator}]
18301838
set val [expr {$bhv eq {prepend} ? "$dir$sep$val" :\
1831-
"$val$sep$dir"}]
1839+
"$val$sep$dir"}]
18321840
} else {
18331841
set val $dir
18341842
}
1835-
set countarr($dir) 1
1836-
} else {
1837-
if {![info exists countarr($dir)] || $allow_dup} {
1838-
# ignore env var set empty if no empty entry found in reference
1839-
# counter array (sometimes var is cleared by setting it empty not
1840-
# unsetting it)
1841-
if {$val ne {} || [info exists countarr()]} {
1842-
set sep [expr {$val eq $separator ? {} : $separator}]
1843-
set val [expr {$bhv eq {prepend} ? "$dir$sep$val" :\
1844-
"$val$sep$dir"}]
1845-
} else {
1846-
set val $dir
1847-
}
1848-
}
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 {
1857-
set countarr($dir) 1
1843+
}
1844+
#### ref-counting
1845+
# if $dir is NOT in path
1846+
# 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)
18581855
}
1856+
} else {
1857+
set countarr($dir) 1
18591858
}
18601859
}
18611860

0 commit comments

Comments
 (0)