Skip to content

Commit 06cfa8a

Browse files
committed
Merge branch 'master' of git://repo.or.cz/git-gui
* 'master' of git://repo.or.cz/git-gui: git-gui: apply color information from git diff output git-gui: use wordprocessor tab style to ensure tabs work as expected git-gui: correct assignment of work-tree git-gui: use full dialog width for old name when renaming branch git-gui: generic version trimming git-gui: enable the Tk console when tracing/debugging on Windows git-gui: show command-line errors in a messagebox on Windows On Windows, avoid git-gui to call Cygwin's nice utility
2 parents 31731b0 + 8f85599 commit 06cfa8a

File tree

3 files changed

+90
-23
lines changed

3 files changed

+90
-23
lines changed

git-gui/git-gui.sh

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
8383
puts stderr "source $name"
8484
uplevel 1 real__source $name
8585
}
86+
if {[tk windowingsystem] eq "win32"} { console show }
8687
}
8788

8889
######################################################################
@@ -444,6 +445,8 @@ proc _lappend_nice {cmd_var} {
444445
set _nice [_which nice]
445446
if {[catch {exec $_nice git version}]} {
446447
set _nice {}
448+
} elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} {
449+
set _nice {}
447450
}
448451
}
449452
if {$_nice ne {}} {
@@ -673,6 +676,7 @@ bind . <Visibility> {
673676
if {[is_Windows]} {
674677
wm iconbitmap . -default $oguilib/git-gui.ico
675678
set ::tk::AlwaysShowSelection 1
679+
bind . <Control-F2> {console show}
676680
677681
# Spoof an X11 display for SSH
678682
if {![info exists env(DISPLAY)]} {
@@ -874,12 +878,19 @@ if {![regsub {^git version } $_git_version {} _git_version]} {
874878
exit 1
875879
}
876880
881+
proc get_trimmed_version {s} {
882+
set r {}
883+
foreach x [split $s -._] {
884+
if {[string is integer -strict $x]} {
885+
lappend r $x
886+
} else {
887+
break
888+
}
889+
}
890+
return [join $r .]
891+
}
877892
set _real_git_version $_git_version
878-
regsub -- {[\-\.]dirty$} $_git_version {} _git_version
879-
regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version
880-
regsub {\.[a-zA-Z]+\.?[0-9]+$} $_git_version {} _git_version
881-
regsub {\.GIT$} $_git_version {} _git_version
882-
regsub {\.[a-zA-Z]+\.?[0-9]+$} $_git_version {} _git_version
893+
set _git_version [get_trimmed_version $_git_version]
883894
884895
if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
885896
catch {wm withdraw .}
@@ -1183,13 +1194,22 @@ if {![file isdirectory $_gitdir]} {
11831194
# _gitdir exists, so try loading the config
11841195
load_config 0
11851196
apply_config
1186-
# try to set work tree from environment, falling back to core.worktree
1187-
if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1188-
set _gitworktree [get_config core.worktree]
1189-
if {$_gitworktree eq ""} {
1190-
set _gitworktree [file dirname [file normalize $_gitdir]]
1197+
1198+
# v1.7.0 introduced --show-toplevel to return the canonical work-tree
1199+
if {[package vsatisfies $_git_version 1.7.0]} {
1200+
set _gitworktree [git rev-parse --show-toplevel]
1201+
} else {
1202+
# try to set work tree from environment, core.worktree or use
1203+
# cdup to obtain a relative path to the top of the worktree. If
1204+
# run from the top, the ./ prefix ensures normalize expands pwd.
1205+
if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1206+
set _gitworktree [get_config core.worktree]
1207+
if {$_gitworktree eq ""} {
1208+
set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1209+
}
11911210
}
11921211
}
1212+
11931213
if {$_prefix ne {}} {
11941214
if {$_gitworktree eq {}} {
11951215
regsub -all {[^/]+/} $_prefix ../ cdup
@@ -2861,7 +2881,8 @@ proc usage {} {
28612881
set s "usage: $::argv0 $::subcommand $::subcommand_args"
28622882
if {[tk windowingsystem] eq "win32"} {
28632883
wm withdraw .
2864-
tk_messageBox -icon info -title "Usage" -message $s
2884+
tk_messageBox -icon info -message $s \
2885+
-title [mc "Usage"]
28652886
} else {
28662887
puts stderr $s
28672888
}
@@ -2934,7 +2955,11 @@ blame {
29342955
if {[catch {
29352956
set head [git rev-parse --verify $head]
29362957
} err]} {
2937-
puts stderr $err
2958+
if {[tk windowingsystem] eq "win32"} {
2959+
tk_messageBox -icon error -title [mc Error] -message $err
2960+
} else {
2961+
puts stderr $err
2962+
}
29382963
exit 1
29392964
}
29402965
}
@@ -2973,18 +2998,19 @@ blame {
29732998
citool -
29742999
gui {
29753000
if {[llength $argv] != 0} {
2976-
puts -nonewline stderr "usage: $argv0"
2977-
if {$subcommand ne {gui}
2978-
&& [file tail $argv0] ne "git-$subcommand"} {
2979-
puts -nonewline stderr " $subcommand"
2980-
}
2981-
puts stderr {}
2982-
exit 1
3001+
usage
29833002
}
29843003
# fall through to setup UI for commits
29853004
}
29863005
default {
2987-
puts stderr "usage: $argv0 \[{blame|browser|citool}\]"
3006+
set err "usage: $argv0 \[{blame|browser|citool}\]"
3007+
if {[tk windowingsystem] eq "win32"} {
3008+
wm withdraw .
3009+
tk_messageBox -icon error -message $err \
3010+
-title [mc "Usage"]
3011+
} else {
3012+
puts stderr $err
3013+
}
29883014
exit 1
29893015
}
29903016
}
@@ -3286,6 +3312,7 @@ text $ui_diff -background white -foreground black \
32863312
-xscrollcommand {.vpane.lower.diff.body.sbx set} \
32873313
-yscrollcommand {.vpane.lower.diff.body.sby set} \
32883314
-state disabled
3315+
catch {$ui_diff configure -tabstyle wordprocessor}
32893316
${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
32903317
-command [list $ui_diff xview]
32913318
${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
@@ -3296,8 +3323,16 @@ pack $ui_diff -side left -fill both -expand 1
32963323
pack .vpane.lower.diff.header -side top -fill x
32973324
pack .vpane.lower.diff.body -side bottom -fill both -expand 1
32983325
3326+
foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {
3327+
$ui_diff tag configure clr4$n -background $c
3328+
$ui_diff tag configure clri4$n -foreground $c
3329+
$ui_diff tag configure clr3$n -foreground $c
3330+
$ui_diff tag configure clri3$n -background $c
3331+
}
3332+
$ui_diff tag configure clr1 -font font_diffbold
3333+
32993334
$ui_diff tag conf d_cr -elide true
3300-
$ui_diff tag conf d_@ -foreground blue -font font_diffbold
3335+
$ui_diff tag conf d_@ -font font_diffbold
33013336
$ui_diff tag conf d_+ -foreground {#00a000}
33023337
$ui_diff tag conf d_- -foreground red
33033338

git-gui/lib/branch_rename.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ constructor dialog {} {
5353
return 1
5454
}
5555

56-
grid $w.rename.oldname_l $w.rename.oldname_m -sticky w -padx {0 5}
56+
grid $w.rename.oldname_l $w.rename.oldname_m -sticky we -padx {0 5}
5757
grid $w.rename.newname_l $w.rename.newname_t -sticky we -padx {0 5}
5858
grid columnconfigure $w.rename 1 -weight 1
5959
pack $w.rename -anchor nw -fill x -pady 5 -padx 5

git-gui/lib/diff.tcl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
294294
}
295295

296296
lappend cmd -p
297-
lappend cmd --no-color
297+
lappend cmd --color
298298
if {$repo_config(gui.diffcontext) >= 1} {
299299
lappend cmd "-U$repo_config(gui.diffcontext)"
300300
}
@@ -332,6 +332,23 @@ proc start_show_diff {cont_info {add_opts {}}} {
332332
fileevent $fd readable [list read_diff $fd $cont_info]
333333
}
334334

335+
proc parse_color_line {line} {
336+
set start 0
337+
set result ""
338+
set markup [list]
339+
set regexp {\033\[((?:\d+;)*\d+)?m}
340+
while {[regexp -indices -start $start $regexp $line match code]} {
341+
foreach {begin end} $match break
342+
append result [string range $line $start [expr {$begin - 1}]]
343+
lappend markup [string length $result] \
344+
[eval [linsert $code 0 string range $line]]
345+
set start [incr end]
346+
}
347+
append result [string range $line $start end]
348+
if {[llength $markup] < 4} {set markup {}}
349+
return [list $result $markup]
350+
}
351+
335352
proc read_diff {fd cont_info} {
336353
global ui_diff diff_active is_submodule_diff
337354
global is_3way_diff is_conflict_diff current_diff_header
@@ -340,6 +357,9 @@ proc read_diff {fd cont_info} {
340357

341358
$ui_diff conf -state normal
342359
while {[gets $fd line] >= 0} {
360+
foreach {line markup} [parse_color_line $line] break
361+
set line [string map {\033 ^} $line]
362+
343363
# -- Cleanup uninteresting diff header lines.
344364
#
345365
if {$::current_diff_inheader} {
@@ -434,11 +454,23 @@ proc read_diff {fd cont_info} {
434454
}
435455
}
436456
}
457+
set mark [$ui_diff index "end - 1 line linestart"]
437458
$ui_diff insert end $line $tags
438459
if {[string index $line end] eq "\r"} {
439460
$ui_diff tag add d_cr {end - 2c}
440461
}
441462
$ui_diff insert end "\n" $tags
463+
464+
foreach {posbegin colbegin posend colend} $markup {
465+
set prefix clr
466+
foreach style [split $colbegin ";"] {
467+
if {$style eq "7"} {append prefix i; continue}
468+
if {$style < 30 || $style > 47} {continue}
469+
set a "$mark linestart + $posbegin chars"
470+
set b "$mark linestart + $posend chars"
471+
catch {$ui_diff tag add $prefix$style $a $b}
472+
}
473+
}
442474
}
443475
$ui_diff conf -state disabled
444476

0 commit comments

Comments
 (0)