@@ -9,6 +9,141 @@ exec wish "$0" -- "$@"
99
1010package require Tk
1111
12+ # #####################################################################
13+ # #
14+ # # Enabling platform-specific code paths
15+
16+ proc is_MacOSX {} {
17+ if {[tk windowingsystem] eq {aqua}} {
18+ return 1
19+ }
20+ return 0
21+ }
22+
23+ proc is_Windows {} {
24+ if {$::tcl_platform(platform) eq {windows}} {
25+ return 1
26+ }
27+ return 0
28+ }
29+
30+ set _iscygwin {}
31+ proc is_Cygwin {} {
32+ global _iscygwin
33+ if {$_iscygwin eq {}} {
34+ if {[string match " CYGWIN_*" $::tcl_platform(os) ]} {
35+ set _iscygwin 1
36+ } else {
37+ set _iscygwin 0
38+ }
39+ }
40+ return $_iscygwin
41+ }
42+
43+ # #####################################################################
44+ # #
45+ # # PATH lookup
46+
47+ set _search_path {}
48+ proc _which {what args} {
49+ global env _search_exe _search_path
50+
51+ if {$_search_path eq {}} {
52+ if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH) ]} {
53+ set _search_path [split [exec cygpath \
54+ --windows \
55+ --path \
56+ --absolute \
57+ $env(PATH) ] {;}]
58+ set _search_exe .exe
59+ } elseif {[is_Windows]} {
60+ set gitguidir [file dirname [info script]]
61+ regsub -all ";" $gitguidir "\\ ;" gitguidir
62+ set env(PATH) " $gitguidir ;$env(PATH) "
63+ set _search_path [ split $env(PATH) {;}]
64+ # Skip empty `PATH` elements
65+ set _search_path [ lsearch -all -inline -not -exact \
66+ $_search_path " " ]
67+ set _search_exe .exe
68+ } else {
69+ set _search_path [ split $env(PATH) :]
70+ set _search_exe {}
71+ }
72+ }
73+
74+ if {[ is_Windows] && [ lsearch -exact $args -script] >= 0} {
75+ set suffix {}
76+ } else {
77+ set suffix $_search_exe
78+ }
79+
80+ foreach p $_search_path {
81+ set p [ file join $p $what$suffix ]
82+ if {[ file exists $p ] } {
83+ return [ file normalize $p ]
84+ }
85+ }
86+ return {}
87+ }
88+
89+ proc sanitize_command_line {command_line from_index} {
90+ set i $from_index
91+ while {$i < [ llength $command_line ] } {
92+ set cmd [ lindex $command_line $i ]
93+ if {[ file pathtype $cmd ] ne " absolute" } {
94+ set fullpath [ _which $cmd ]
95+ if {$fullpath eq " " } {
96+ throw {NOT-FOUND} " $cmd not found in PATH"
97+ }
98+ lset command_line $i $fullpath
99+ }
100+
101+ # handle piped commands, e.g. `exec A | B`
102+ for {incr i} {$i < [ llength $command_line ] } {incr i} {
103+ if {[ lindex $command_line $i ] eq " |" } {
104+ incr i
105+ break
106+ }
107+ }
108+ }
109+ return $command_line
110+ }
111+
112+ # Override `exec` to avoid unsafe PATH lookup
113+
114+ rename exec real_exec
115+
116+ proc exec {args} {
117+ # skip options
118+ for {set i 0} {$i < [ llength $args ] } {incr i} {
119+ set arg [ lindex $args $i ]
120+ if {$arg eq " --" } {
121+ incr i
122+ break
123+ }
124+ if {[ string range $arg 0 0] ne " -" } {
125+ break
126+ }
127+ }
128+ set args [ sanitize_command_line $args $i ]
129+ uplevel 1 real_exec $args
130+ }
131+
132+ # Override `open` to avoid unsafe PATH lookup
133+
134+ rename open real_open
135+
136+ proc open {args} {
137+ set arg0 [ lindex $args 0]
138+ if {[ string range $arg0 0 0] eq " |" } {
139+ set command_line [ string trim [string range $arg0 1 end] ]
140+ lset args 0 " | [sanitize_command_line $command_line 0]"
141+ }
142+ uplevel 1 real_open $args
143+ }
144+
145+ # End of safe PATH lookup stuff
146+
12147proc hasworktree {} {
13148 return [ expr {[exec git rev-parse --is-bare-repository] == " false" &&
14149 [ exec git rev-parse --is-inside-git-dir] == " false" }]
@@ -2103,7 +2238,7 @@ proc makewindow {} {
21032238 global headctxmenu progresscanv progressitem progresscoords statusw
21042239 global fprogitem fprogcoord lastprogupdate progupdatepending
21052240 global rprogitem rprogcoord rownumsel numcommits
2106- global have_tk85 use_ttk NS
2241+ global have_tk85 have_tk86 use_ttk NS
21072242 global git_version
21082243 global worddiff
21092244
@@ -2601,8 +2736,13 @@ proc makewindow {} {
26012736 bind . <Key-Down> " selnextline 1"
26022737 bind . <Shift-Key-Up> " dofind -1 0"
26032738 bind . <Shift-Key-Down> " dofind 1 0"
2604- bindkey <Key-Right> " goforw"
2605- bindkey <Key-Left> " goback"
2739+ if {$have_tk86 } {
2740+ bindkey <<NextChar>> " goforw"
2741+ bindkey <<PrevChar>> " goback"
2742+ } else {
2743+ bindkey <Key-Right> " goforw"
2744+ bindkey <Key-Left> " goback"
2745+ }
26062746 bind . <Key-Prior> " selnextpage -1"
26072747 bind . <Key-Next> " selnextpage 1"
26082748 bind . <$M1B -Home> " allcanvs yview moveto 0.0"
@@ -7720,7 +7860,7 @@ proc gettreeline {gtf id} {
77207860 if {[ string index $fname 0] eq " \" " } {
77217861 set fname [ lindex $fname 0]
77227862 }
7723- set fname [encoding convertfrom $fname ]
7863+ set fname [ encoding convertfrom utf-8 $fname ]
77247864 lappend treefilelist($id ) $fname
77257865 }
77267866 if {![ eof $gtf ] } {
@@ -7982,7 +8122,7 @@ proc gettreediffline {gdtf ids} {
79828122 if {[ string index $file 0] eq " \" " } {
79838123 set file [ lindex $file 0]
79848124 }
7985- set file [encoding convertfrom $file ]
8125+ set file [ encoding convertfrom utf-8 $file ]
79868126 if {$file ne [ lindex $treediff end] } {
79878127 lappend treediff $file
79888128 lappend sublist $file
@@ -8127,7 +8267,7 @@ proc makediffhdr {fname ids} {
81278267 global ctext curdiffstart treediffs diffencoding
81288268 global ctext_file_names jump_to_here targetline diffline
81298269
8130- set fname [encoding convertfrom $fname ]
8270+ set fname [ encoding convertfrom utf-8 $fname ]
81318271 set diffencoding [ get_path_encoding $fname ]
81328272 set i [ lsearch -exact $treediffs($ids) $fname ]
81338273 if {$i >= 0} {
@@ -8189,7 +8329,7 @@ proc parseblobdiffline {ids line} {
81898329
81908330 if {![ string compare -length 5 " diff " $line ] } {
81918331 if {![ regexp {^diff (--cc|--git) } $line m type] } {
8192- set line [encoding convertfrom $line ]
8332+ set line [ encoding convertfrom utf-8 $line ]
81938333 $ctext insert end " $line \n " hunksep
81948334 continue
81958335 }
@@ -8238,7 +8378,7 @@ proc parseblobdiffline {ids line} {
82388378 makediffhdr $fname $ids
82398379
82408380 } elseif {![ string compare -length 16 " * Unmerged path " $line ] } {
8241- set fname [encoding convertfrom [string range $line 16 end]]
8381+ set fname [ encoding convertfrom utf-8 [string range $line 16 end] ]
82428382 $ctext insert end " \n "
82438383 set curdiffstart [ $ctext index " end - 1c" ]
82448384 lappend ctext_file_names $fname
@@ -8291,7 +8431,7 @@ proc parseblobdiffline {ids line} {
82918431 if {[ string index $fname 0] eq " \" " } {
82928432 set fname [ lindex $fname 0]
82938433 }
8294- set fname [encoding convertfrom $fname ]
8434+ set fname [ encoding convertfrom utf-8 $fname ]
82958435 set i [ lsearch -exact $treediffs($ids) $fname ]
82968436 if {$i >= 0} {
82978437 setinlist difffilestart $i $curdiffstart
@@ -8310,6 +8450,7 @@ proc parseblobdiffline {ids line} {
83108450 set diffinhdr 0
83118451 return
83128452 }
8453+ set line [ encoding convertfrom utf-8 $line ]
83138454 $ctext insert end " $line \n " filesep
83148455
83158456 } else {
@@ -10068,7 +10209,7 @@ proc showrefs {} {
1006810209 text $top .list -background $bgcolor -foreground $fgcolor \
1006910210 -selectbackground $selectbgcolor -font mainfont \
1007010211 -xscrollcommand " $top .xsb set" -yscrollcommand " $top .ysb set" \
10071- -width 30 -height 20 -cursor $maincursor \
10212+ -width 60 -height 20 -cursor $maincursor \
1007210213 -spacing1 1 -spacing3 1 -state disabled
1007310214 $top .list tag configure highlight -background $selectbgcolor
1007410215 if {![ lsearch -exact $bglist $top .list] } {
@@ -12305,7 +12446,7 @@ proc cache_gitattr {attr pathlist} {
1230512446 foreach row [ split $rlist " \n " ] {
1230612447 if {[ regexp "(.*): $attr : (.*)" $row m path value] } {
1230712448 if {[ string index $path 0] eq " \" " } {
12308- set path [encoding convertfrom [lindex $path 0]]
12449+ set path [ encoding convertfrom utf-8 [lindex $path 0] ]
1230912450 }
1231012451 set path_attr_cache($attr ,$path ) $value
1231112452 }
@@ -12335,7 +12476,6 @@ if { [info exists ::env(GITK_MSGSDIR)] } {
1233512476 set gitk_prefix [ file dirname [file dirname [file normalize $argv0 ] ]]
1233612477 set gitk_libdir [ file join $gitk_prefix share gitk lib]
1233712478 set gitk_msgsdir [ file join $gitk_libdir msgs]
12338- unset gitk_prefix
1233912479}
1234012480
1234112481## Internationalization (i18n) through msgcat and gettext. See
@@ -12637,6 +12777,7 @@ set nullid2 "0000000000000000000000000000000000000001"
1263712777set nullfile " /dev/null"
1263812778
1263912779set have_tk85 [ expr {[package vcompare $tk_version " 8.5" ] >= 0}]
12780+ set have_tk86 [ expr {[package vcompare $tk_version " 8.6" ] >= 0}]
1264012781if {![ info exists have_ttk] } {
1264112782 set have_ttk [ llength [info commands ::ttk::style] ]
1264212783}
@@ -12701,28 +12842,32 @@ if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
1270112842set worktree [ gitworktree]
1270212843setcoords
1270312844makewindow
12704- catch {
12705- image create photo gitlogo -width 16 -height 16
12706-
12707- image create photo gitlogominus -width 4 -height 2
12708- gitlogominus put #C00000 -to 0 0 4 2
12709- gitlogo copy gitlogominus -to 1 5
12710- gitlogo copy gitlogominus -to 6 5
12711- gitlogo copy gitlogominus -to 11 5
12712- image delete gitlogominus
12713-
12714- image create photo gitlogoplus -width 4 -height 4
12715- gitlogoplus put #008000 -to 1 0 3 4
12716- gitlogoplus put #008000 -to 0 1 4 3
12717- gitlogo copy gitlogoplus -to 1 9
12718- gitlogo copy gitlogoplus -to 6 9
12719- gitlogo copy gitlogoplus -to 11 9
12720- image delete gitlogoplus
12721-
12722- image create photo gitlogo32 -width 32 -height 32
12723- gitlogo32 copy gitlogo -zoom 2 2
12724-
12725- wm iconphoto . -default gitlogo gitlogo32
12845+ if {$::tcl_platform(platform) eq {windows} && [ file exists $gitk_prefix /etc/git.ico] } {
12846+ wm iconbitmap . -default $gitk_prefix /etc/git.ico
12847+ } else {
12848+ catch {
12849+ image create photo gitlogo -width 16 -height 16
12850+
12851+ image create photo gitlogominus -width 4 -height 2
12852+ gitlogominus put #C00000 -to 0 0 4 2
12853+ gitlogo copy gitlogominus -to 1 5
12854+ gitlogo copy gitlogominus -to 6 5
12855+ gitlogo copy gitlogominus -to 11 5
12856+ image delete gitlogominus
12857+
12858+ image create photo gitlogoplus -width 4 -height 4
12859+ gitlogoplus put #008000 -to 1 0 3 4
12860+ gitlogoplus put #008000 -to 0 1 4 3
12861+ gitlogo copy gitlogoplus -to 1 9
12862+ gitlogo copy gitlogoplus -to 6 9
12863+ gitlogo copy gitlogoplus -to 11 9
12864+ image delete gitlogoplus
12865+
12866+ image create photo gitlogo32 -width 32 -height 32
12867+ gitlogo32 copy gitlogo -zoom 2 2
12868+
12869+ wm iconphoto . -default gitlogo gitlogo32
12870+ }
1272612871}
1272712872# wait for the window to become visible
1272812873if {![ winfo viewable .] } {tkwait visibility .}
0 commit comments