git-gui: Always use eq/ne for string comparsions.
This is one of those stupid Tcl mistakes that an experienced Tcl programmer just wouldn't make. We should always use eq and ne to compare string values (and never == or !=) as when we use ==/!= Tcl will attempt to convert either side to numeric if one of the two sides looks like a numeric. This could cause some trouble if a file named "1" exists and a different file named "1.0" also exists; their paths are equal according to == but not according to eq. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 12, 2006 at 18:16 UTC
043f701116c30067c2a7096135b6e419dd1f7b47
1 file changed
+70
-70
git-gui
+70
-70
@@ -90,15 +90,15 @@ proc save_config {} {
90
91
foreach name [array names default_config] {
92
set value $global_config_new($name)
93
- if {$value != $global_config($name)} {
94
- if {$value == $default_config($name)} {
93
+ if {$value ne $global_config($name)} {
94
+ if {$value eq $default_config($name)} {
95
catch {exec git repo-config --global --unset $name}
96
} else {
97
regsub -all "\[{}\]" $value {"} value
98
exec git repo-config --global $name $value
99
}
100
set global_config($name) $value
101
- if {$value == $repo_config($name)} {
101
+ if {$value eq $repo_config($name)} {
102
catch {exec git repo-config --unset $name}
103
set repo_config($name) $value
104
}
@@ -107,8 +107,8 @@ proc save_config {} {
107
108
foreach name [array names default_config] {
109
set value $repo_config_new($name)
110
- if {$value != $repo_config($name)} {
111
- if {$value == $global_config($name)} {
110
+ if {$value ne $repo_config($name)} {
111
+ if {$value eq $global_config($name)} {
112
catch {exec git repo-config --unset $name}
113
} else {
114
regsub -all "\[{}\]" $value {"} value
@@ -123,7 +123,7 @@ proc error_popup {msg} {
123
global gitdir appname
124
125
set title $appname
126
- if {$gitdir != {}} {
126
+ if {$gitdir ne {}} {
127
append title { (}
128
append title [lindex \
129
[file split [file normalize [file dirname $gitdir]]] \
@@ -142,7 +142,7 @@ proc info_popup {msg} {
142
global gitdir appname
143
144
set title $appname
145
- if {$gitdir != {}} {
145
+ if {$gitdir ne {}} {
146
append title { (}
147
append title [lindex \
148
[file split [file normalize [file dirname $gitdir]]] \
@@ -167,13 +167,13 @@ if { [catch {set cdup [exec git rev-parse --show-cdup]} err]
167
error_popup "Cannot find the git directory:\n\n$err"
168
exit 1
169
}
170
-if {$cdup != ""} {
170
+if {$cdup ne ""} {
171
cd $cdup
172
}
173
unset cdup
174
175
set single_commit 0
176
-if {$appname == {git-citool}} {
176
+if {$appname eq {git-citool}} {
177
set single_commit 1
178
}
179
@@ -194,13 +194,13 @@ set commit_type {}
194
proc lock_index {type} {
195
global index_lock_type disable_on_lock
196
197
- if {$index_lock_type == {none}} {
197
+ if {$index_lock_type eq {none}} {
198
set index_lock_type $type
199
foreach w $disable_on_lock {
200
uplevel #0 $w disabled
201
}
202
return 1
203
- } elseif {$index_lock_type == {begin-update} && $type == {update}} {
203
+ } elseif {$index_lock_type eq {begin-update} && $type eq {update}} {
204
set index_lock_type $type
205
return 1
206
}
@@ -242,9 +242,9 @@ proc update_status {{final Ready.}} {
242
if {$status_active || ![lock_index read]} return
243
244
repository_state new_HEAD new_type
245
- if {$commit_type == {amend}
246
- && $new_type == {normal}
247
- && $new_HEAD == $HEAD} {
245
+ if {$commit_type eq {amend}
246
+ && $new_type eq {normal}
247
+ && $new_HEAD eq $HEAD} {
248
} else {
249
set HEAD $new_HEAD
250
set PARENT $new_HEAD
@@ -254,7 +254,7 @@ proc update_status {{final Ready.}} {
254
array unset file_states
255
256
if {![$ui_comm edit modified]
257
- || [string trim [$ui_comm get 0.0 end]] == {}} {
257
+ || [string trim [$ui_comm get 0.0 end]] eq {}} {
258
if {[load_message GITGUI_MSG]} {
259
} elseif {[load_message MERGE_MSG]} {
260
} elseif {[load_message SQUASH_MSG]} {
@@ -263,7 +263,7 @@ proc update_status {{final Ready.}} {
263
$ui_comm edit reset
264
}
265
266
- if {$repo_config(gui.trustmtime) == {true}} {
266
+ if {$repo_config(gui.trustmtime) eq {true}} {
267
update_status_stage2 {} $final
268
} else {
269
set status_active 1
@@ -286,7 +286,7 @@ proc update_status_stage2 {fd final} {
286
global status_active
287
global buf_rdi buf_rdf buf_rlo
288
289
- if {$fd != {}} {
289
+ if {$fd ne {}} {
290
read $fd
291
if {![eof $fd]} return
292
close $fd
@@ -442,7 +442,7 @@ proc clear_diff {} {
442
proc reshow_diff {} {
443
global ui_fname_value ui_status_value file_states
444
445
- if {$ui_fname_value == {}
445
+ if {$ui_fname_value eq {}
446
|| [catch {set s $file_states($ui_fname_value)}]} {
447
clear_diff
448
} else {
@@ -455,7 +455,7 @@ proc handle_empty_diff {} {
455
456
set path $ui_fname_value
457
set s $file_states($path)
458
- if {[lindex $s 0] != {_M}} return
458
+ if {[lindex $s 0] ne {_M}} return
459
460
info_popup "No differences detected.
461
@@ -494,7 +494,7 @@ proc show_diff {path {w {}} {lno {}}} {
494
if {$diff_active || ![lock_index read]} return
495
496
clear_diff
497
- if {$w == {} || $lno == {}} {
497
+ if {$w eq {} || $lno == {}} {
498
foreach w [array names file_lists] {
499
set lno [lsearch -sorted $file_lists($w) $path]
500
if {$lno >= 0} {
@@ -503,7 +503,7 @@ proc show_diff {path {w {}} {lno {}}} {
503
}
504
}
505
}
506
- if {$w != {} && $lno >= 1} {
506
+ if {$w ne {} && $lno >= 1} {
507
$w tag add in_diff $lno.0 [expr $lno + 1].0
508
}
509
@@ -604,8 +604,8 @@ proc read_diff {fd} {
604
unlock_index
605
set ui_status_value {Ready.}
606
607
- if {$repo_config(gui.trustmtime) == {true}
608
- && [$ui_diff index end] == {2.0}} {
607
+ if {$repo_config(gui.trustmtime) eq {true}
608
+ && [$ui_diff index end] eq {2.0}} {
609
handle_empty_diff
610
}
611
}
@@ -618,8 +618,8 @@ proc read_diff {fd} {
618
proc load_last_commit {} {
619
global HEAD PARENT commit_type ui_comm
620
621
- if {$commit_type == {amend}} return
622
- if {$commit_type != {normal}} {
621
+ if {$commit_type eq {amend}} return
622
+ if {$commit_type ne {normal}} {
623
error_popup "Can't amend a $commit_type commit."
624
return
625
}
@@ -671,10 +671,10 @@ proc commit_tree {} {
671
# -- Our in memory state should match the repository.
672
#
673
repository_state curHEAD cur_type
674
- if {$commit_type == {amend}
675
- && $cur_type == {normal}
676
- && $curHEAD == $HEAD} {
677
- } elseif {$commit_type != $cur_type || $HEAD != $curHEAD} {
674
+ if {$commit_type eq {amend}
675
+ && $cur_type eq {normal}
676
+ && $curHEAD eq $HEAD} {
677
+ } elseif {$commit_type ne $cur_type || $HEAD ne $curHEAD} {
678
error_popup {Last scanned state does not match repository state.
679
680
Its highly likely that another Git program modified the
@@ -725,7 +725,7 @@ You must include at least 1 file before you can commit.
725
# -- A message is required.
726
#
727
set msg [string trim [$ui_comm get 1.0 end]]
728
- if {$msg == {}} {
728
+ if {$msg eq {}} {
729
error_popup {Please supply a commit message.
730
731
A good commit message has the following format:
@@ -741,7 +741,7 @@ A good commit message has the following format:
741
# -- Ask the pre-commit hook for the go-ahead.
742
#
743
set pchook [file join $gitdir hooks pre-commit]
744
- if {$tcl_platform(platform) == {windows} && [file isfile $pchook]} {
744
+ if {$tcl_platform(platform) eq {windows} && [file isfile $pchook]} {
745
set pchook [list sh -c [concat \
746
"if test -x \"$pchook\";" \
747
"then exec \"$pchook\" 2>&1;" \
@@ -751,7 +751,7 @@ A good commit message has the following format:
751
} else {
752
set pchook {}
753
}
754
- if {$pchook != {}} {
754
+ if {$pchook ne {}} {
755
set ui_status_value {Calling pre-commit hook...}
756
set pch_error {}
757
set fd_ph [open "| $pchook" r]
@@ -798,7 +798,7 @@ proc commit_stage3 {fd_wt curHEAD msg} {
798
global file_states
799
800
gets $fd_wt tree_id
801
- if {$tree_id == {} || [catch {close $fd_wt} err]} {
801
+ if {$tree_id eq {} || [catch {close $fd_wt} err]} {
802
error_popup "write-tree failed:\n\n$err"
803
set ui_status_value {Commit failed.}
804
unlock_index
@@ -808,10 +808,10 @@ proc commit_stage3 {fd_wt curHEAD msg} {
808
# -- Create the commit.
809
#
810
set cmd [list git commit-tree $tree_id]
811
- if {$PARENT != {}} {
811
+ if {$PARENT ne {}} {
812
lappend cmd -p $PARENT
813
}
814
- if {$commit_type == {merge}} {
814
+ if {$commit_type eq {merge}} {
815
if {[catch {
816
set fd_mh [open [file join $gitdir MERGE_HEAD] r]
817
while {[gets $fd_mh merge_head] >= 0} {
@@ -825,7 +825,7 @@ proc commit_stage3 {fd_wt curHEAD msg} {
825
return
826
}
827
}
828
- if {$PARENT == {}} {
828
+ if {$PARENT eq {}} {
829
# git commit-tree writes to stderr during initial commit.
830
lappend cmd 2>/dev/null
831
}
@@ -840,7 +840,7 @@ proc commit_stage3 {fd_wt curHEAD msg} {
840
# -- Update the HEAD ref.
841
#
842
set reflogm commit
843
- if {$commit_type != {normal}} {
843
+ if {$commit_type ne {normal}} {
844
append reflogm " ($commit_type)"
845
}
846
set i [string first "\n" $msg]
@@ -873,7 +873,7 @@ proc commit_stage3 {fd_wt curHEAD msg} {
873
# -- Run the post-commit hook.
874
#
875
set pchook [file join $gitdir hooks post-commit]
876
- if {$tcl_platform(platform) == {windows} && [file isfile $pchook]} {
876
+ if {$tcl_platform(platform) eq {windows} && [file isfile $pchook]} {
877
set pchook [list sh -c [concat \
878
"if test -x \"$pchook\";" \
879
"then exec \"$pchook\";" \
@@ -881,7 +881,7 @@ proc commit_stage3 {fd_wt curHEAD msg} {
881
} elseif {![file executable $pchook]} {
882
set pchook {}
883
}
884
- if {$pchook != {}} {
884
+ if {$pchook ne {}} {
885
catch {exec $pchook &}
886
}
887
@@ -906,7 +906,7 @@ proc commit_stage3 {fd_wt curHEAD msg} {
906
D? {set m _[string index $m 1]}
907
}
908
909
- if {$m == {__}} {
909
+ if {$m eq {__}} {
910
unset file_states($path)
911
} else {
912
lset file_states($path) 0 $m
@@ -940,7 +940,7 @@ proc pull_remote {remote branch} {
940
# -- Our in memory state should match the repository.
941
#
942
repository_state curHEAD cur_type
943
- if {$commit_type != $cur_type || $HEAD != $curHEAD} {
943
+ if {$commit_type ne $cur_type || $HEAD ne $curHEAD} {
944
error_popup {Last scanned state does not match repository state.
945
946
Its highly likely that another Git program modified the
@@ -969,7 +969,7 @@ Commit or throw away all changes before starting a pull operation.
969
set w [new_console "pull $remote $branch" \
970
"Pulling new changes from branch $branch in $remote"]
971
set cmd [list git pull]
972
- if {$repo_config(gui.pullsummary) == {false}} {
972
+ if {$repo_config(gui.pullsummary) eq {false}} {
973
lappend cmd --no-summary
974
}
975
lappend cmd $remote
@@ -1059,15 +1059,15 @@ proc merge_state {path new_state} {
1059
set icon [lindex $info 1]
1060
}
1061
1062
- if {$s0 == {_}} {
1062
+ if {$s0 eq {_}} {
1063
set s0 [string index $state 0]
1064
- } elseif {$s0 == {*}} {
1064
+ } elseif {$s0 eq {*}} {
1065
set s0 _
1066
}
1067
1068
- if {$s1 == {_}} {
1068
+ if {$s1 eq {_}} {
1069
set s1 [string index $state 1]
1070
- } elseif {$s1 == {*}} {
1070
+ } elseif {$s1 eq {*}} {
1071
set s1 _
1072
}
1073
@@ -1087,7 +1087,7 @@ proc display_file {path state} {
1087
set old_w [mapcol $old_m $path]
1088
set new_icon [mapicon $new_m $path]
1089
1090
- if {$new_w != $old_w} {
1090
+ if {$new_w ne $old_w} {
1091
set lno [lsearch -sorted $file_lists($old_w) $path]
1092
if {$lno >= 0} {
1093
incr lno
@@ -1107,7 +1107,7 @@ proc display_file {path state} {
1107
-image $new_icon
1108
$new_w insert $lno.1 "[escape_path $path]\n"
1109
$new_w conf -state disabled
1110
- } elseif {$new_icon != [mapicon $old_m $path]} {
1110
+ } elseif {$new_icon ne [mapicon $old_m $path]} {
1111
$new_w conf -state normal
1112
$new_w image conf [lindex $s 1] -image $new_icon
1113
$new_w conf -state disabled
@@ -1199,7 +1199,7 @@ proc write_update_index {fd pathList totalCnt batch} {
1199
puts -nonewline $fd $path
1200
puts -nonewline $fd "\0"
1201
display_file $path $new
1202
- if {$ui_fname_value == $path} {
1202
+ if {$ui_fname_value eq $path} {
1203
show_diff $path
1204
}
1205
}
@@ -1252,8 +1252,8 @@ proc populate_pull_menu {m} {
1252
1253
foreach remote $all_remotes {
1254
set rb {}
1255
- if {[array get repo_config remote.$remote.url] != {}} {
1256
- if {[array get repo_config remote.$remote.fetch] != {}} {
1255
+ if {[array get repo_config remote.$remote.url] ne {}} {
1256
+ if {[array get repo_config remote.$remote.fetch] ne {}} {
1257
regexp {^([^:]+):} \
1258
[lindex $repo_config(remote.$remote.fetch) 0] \
1259
line rb
@@ -1272,7 +1272,7 @@ proc populate_pull_menu {m} {
1272
1273
set rb_short $rb
1274
regsub ^refs/heads/ $rb {} rb_short
1275
- if {$rb_short != {}} {
1275
+ if {$rb_short ne {}} {
1276
$m add command \
1277
-label "Branch $rb_short from $remote..." \
1278
-command [list pull_remote $remote $rb] \
@@ -1384,7 +1384,7 @@ foreach i {
1384
if {$max_status_desc < [string length [lindex $i 3]]} {
1385
set max_status_desc [string length [lindex $i 3]]
1386
}
1387
- if {[lindex $i 1] == {i}} {
1387
+ if {[lindex $i 1] eq {i}} {
1388
set all_cols([lindex $i 0]) $ui_index
1389
} else {
1390
set all_cols([lindex $i 0]) $ui_other
@@ -1400,8 +1400,8 @@ unset filemask i
1400
1401
proc is_MacOSX {} {
1402
global tcl_platform tk_library
1403
- if {$tcl_platform(platform) == {unix}
1404
- && $tcl_platform(os) == {Darwin}
1403
+ if {$tcl_platform(platform) eq {unix}
1404
+ && $tcl_platform(os) eq {Darwin}
1405
&& [string match /Library/Frameworks/* $tk_library]} {
1406
return 1
1407
}
@@ -1543,7 +1543,7 @@ proc console_exec {w cmd {after {}}} {
1543
# -- Windows tosses the enviroment when we exec our child.
1544
# But most users need that so we have to relogin. :-(
1545
#
1546
- if {$tcl_platform(platform) == {windows}} {
1546
+ if {$tcl_platform(platform) eq {windows}} {
1547
set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"]
1548
}
1549
@@ -1561,7 +1561,7 @@ proc console_read {w fd after} {
1561
global console_cr console_data
1562
1563
set buf [read $fd]
1564
- if {$buf != {}} {
1564
+ if {$buf ne {}} {
1565
if {![winfo exists $w]} {console_init $w}
1566
$w.m.t conf -state normal
1567
set c 0
@@ -1605,7 +1605,7 @@ proc console_read {w fd after} {
1605
}
1606
array unset console_cr $w
1607
array unset console_data $w
1608
- if {$after != {}} {
1608
+ if {$after ne {}} {
1609
uplevel #0 $after $ok
1610
}
1611
return
@@ -1624,12 +1624,12 @@ proc do_gitk {} {
1624
1625
set ui_status_value $starting_gitk_msg
1626
after 10000 {
1627
- if {$ui_status_value == $starting_gitk_msg} {
1627
+ if {$ui_status_value eq $starting_gitk_msg} {
1628
set ui_status_value {Ready.}
1629
}
1630
}
1631
1632
- if {$tcl_platform(platform) == {windows}} {
1632
+ if {$tcl_platform(platform) eq {windows}} {
1633
exec sh -c gitk &
1634
} else {
1635
exec gitk &
@@ -1656,13 +1656,13 @@ proc do_quit {} {
1656
#
1657
set save [file join $gitdir GITGUI_MSG]
1658
set msg [string trim [$ui_comm get 0.0 end]]
1659
- if {[$ui_comm edit modified] && $msg != {}} {
1659
+ if {[$ui_comm edit modified] && $msg ne {}} {
1660
catch {
1661
set fd [open $save w]
1662
puts $fd [string trim [$ui_comm get 0.0 end]]
1663
close $fd
1664
}
1665
- } elseif {$msg == {} && [file exists $save]} {
1665
+ } elseif {$msg eq {} && [file exists $save]} {
1666
file delete $save
1667
}
1668
@@ -1675,7 +1675,7 @@ proc do_quit {} {
1675
if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
1676
set rc_geometry {}
1677
}
1678
- if {$cfg_geometry != $rc_geometry} {
1678
+ if {$cfg_geometry ne $rc_geometry} {
1679
catch {exec git repo-config gui.geometry $cfg_geometry}
1680
}
1681
@@ -1702,7 +1702,7 @@ proc do_include_all {} {
1702
_D {lappend pathList $path}
1703
}
1704
}
1705
- if {$pathList == {}} {
1705
+ if {$pathList eq {}} {
1706
unlock_index
1707
} else {
1708
update_index $pathList
@@ -1714,7 +1714,7 @@ set GIT_COMMITTER_IDENT {}
1714
proc do_signoff {} {
1715
global ui_comm GIT_COMMITTER_IDENT
1716
1717
- if {$GIT_COMMITTER_IDENT == {}} {
1717
+ if {$GIT_COMMITTER_IDENT eq {}} {
1718
if {[catch {set me [exec git var GIT_COMMITTER_IDENT]} err]} {
1719
error_popup "Unable to obtain your identity:\n\n$err"
1720
return
@@ -1728,9 +1728,9 @@ proc do_signoff {} {
1728
1729
set sob "Signed-off-by: $GIT_COMMITTER_IDENT"
1730
set last [$ui_comm get {end -1c linestart} {end -1c}]
1731
- if {$last != $sob} {
1731
+ if {$last ne $sob} {
1732
$ui_comm edit separator
1733
- if {$last != {}
1733
+ if {$last ne {}
1734
&& ![regexp {^[A-Z][A-Za-z]*-[A-Za-z-]+: *} $last]} {
1735
$ui_comm insert end "\n"
1736
}
@@ -1888,7 +1888,7 @@ proc click {w x y shift wx wy} {
1888
set lno [lindex $pos 0]
1889
set col [lindex $pos 1]
1890
set path [lindex $file_lists($w) [expr $lno - 1]]
1891
- if {$path == {}} return
1891
+ if {$path eq {}} return
1892
1893
if {$col > 0 && $shift == 1} {
1894
show_diff $path $w $lno
@@ -1902,7 +1902,7 @@ proc unclick {w x y} {
1902
set lno [lindex $pos 0]
1903
set col [lindex $pos 1]
1904
set path [lindex $file_lists($w) [expr $lno - 1]]
1905
- if {$path == {}} return
1905
+ if {$path eq {}} return
1906
1907
if {$col == 0} {
1908
update_index [list $path]
@@ -1927,7 +1927,7 @@ font create font_diffbold
1927
1928
set M1B M1
1929
set M1T M1
1930
-if {$tcl_platform(platform) == {windows}} {
1930
+if {$tcl_platform(platform) eq {windows}} {
1931
set M1B Control
1932
set M1T Ctrl
1933
} elseif {[is_MacOSX]} {