From ff9db6c79d57c9f8921db39a73772e70ab76a1e3 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 5 Oct 2010 11:12:00 +0200 Subject: [PATCH 1/8] On Windows, avoid git-gui to call Cygwin's nice utility It's a common case for Windows developers to have both Cygwin and msysGit installed. Unfortunately, some scenarios also require to have Cygwin in PATH. By default, Cygwin comes with nice.exe, while msysGit does not. Since git-gui calls nice if it is in PATH, this results in Cygwin's nice.exe being called from msysGit's git-gui. Mixing Cygwin and msysGit generally is not a good idea, and in this particular case it causes differences not being correctly detected. So we only call nice.exe on Windows if it is in the same directory as git.exe. This way, this work-around does neither affect a pure Cygwin environment, or the case when nice.exe will be shipped with msysGit at some point in time. This fixes msysGit issue 394. Signed-off-by: Sebastian Schuberth Signed-off-by: Pat Thoyts --- git-gui.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index 4617f29c26..422d4ff5bd 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -444,6 +444,8 @@ proc _lappend_nice {cmd_var} { set _nice [_which nice] if {[catch {exec $_nice git version}]} { set _nice {} + } elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} { + set _nice {} } } if {$_nice ne {}} { From 7ae1e727622883c029550e0b99488c6d058a94bc Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Tue, 5 Oct 2010 23:39:54 +0100 Subject: [PATCH 2/8] git-gui: show command-line errors in a messagebox on Windows Signed-off-by: Pat Thoyts --- git-gui.sh | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 422d4ff5bd..ed0904d993 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2863,7 +2863,8 @@ proc usage {} { set s "usage: $::argv0 $::subcommand $::subcommand_args" if {[tk windowingsystem] eq "win32"} { wm withdraw . - tk_messageBox -icon info -title "Usage" -message $s + tk_messageBox -icon info -message $s \ + -title [mc "Usage"] } else { puts stderr $s } @@ -2936,7 +2937,11 @@ blame { if {[catch { set head [git rev-parse --verify $head] } err]} { - puts stderr $err + if {[tk windowingsystem] eq "win32"} { + tk_messageBox -icon error -title [mc Error] -message $err + } else { + puts stderr $err + } exit 1 } } @@ -2975,18 +2980,19 @@ blame { citool - gui { if {[llength $argv] != 0} { - puts -nonewline stderr "usage: $argv0" - if {$subcommand ne {gui} - && [file tail $argv0] ne "git-$subcommand"} { - puts -nonewline stderr " $subcommand" - } - puts stderr {} - exit 1 + usage } # fall through to setup UI for commits } default { - puts stderr "usage: $argv0 \[{blame|browser|citool}\]" + set err "usage: $argv0 \[{blame|browser|citool}\]" + if {[tk windowingsystem] eq "win32"} { + wm withdraw . + tk_messageBox -icon error -message $err \ + -title [mc "Usage"] + } else { + puts stderr $err + } exit 1 } } From c0d2c38d78fc3b55b7f0a2470ca89bed43eb4019 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Tue, 5 Oct 2010 23:51:34 +0100 Subject: [PATCH 3/8] git-gui: enable the Tk console when tracing/debugging on Windows Without any standard channels the trace option is pretty useless on Win32 unless you can show the Tk console which captures such output. This also permits introspection of the running application to assist in debugging. Signed-off-by: Pat Thoyts --- git-gui.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index ed0904d993..ea262a2bac 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -83,6 +83,7 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} { puts stderr "source $name" uplevel 1 real__source $name } + if {[tk windowingsystem] eq "win32"} { console show } } ###################################################################### @@ -675,6 +676,7 @@ bind . { if {[is_Windows]} { wm iconbitmap . -default $oguilib/git-gui.ico set ::tk::AlwaysShowSelection 1 + bind . {console show} # Spoof an X11 display for SSH if {![info exists env(DISPLAY)]} { From 67112c484b5d460ccceb54f3a32b62e4e6e705f0 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Thu, 7 Oct 2010 22:28:45 +0100 Subject: [PATCH 4/8] git-gui: generic version trimming Rather than attempting to trim off all the non-version number suffixes from the 'git version' result, let us scan along from the beginning until we find a non-numeric part and stop there. Any such dot-version number will be compatible with the Tcl package version comparison command which is the aim of this code. Signed-off-by: Pat Thoyts --- git-gui.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index ea262a2bac..25229a4073 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -878,12 +878,19 @@ if {![regsub {^git version } $_git_version {} _git_version]} { exit 1 } +proc get_trimmed_version {s} { + set r {} + foreach x [split $s -._] { + if {[string is integer -strict $x]} { + lappend r $x + } else { + break + } + } + return [join $r .] +} set _real_git_version $_git_version -regsub -- {[\-\.]dirty$} $_git_version {} _git_version -regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version -regsub {\.[a-zA-Z]+\.?[0-9]+$} $_git_version {} _git_version -regsub {\.GIT$} $_git_version {} _git_version -regsub {\.[a-zA-Z]+\.?[0-9]+$} $_git_version {} _git_version +set _git_version [get_trimmed_version $_git_version] if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} { catch {wm withdraw .} From 4c56d1ddc03e6370a3afc01a011e6c3e65ff65d3 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Thu, 7 Oct 2010 23:00:33 +0100 Subject: [PATCH 5/8] git-gui: use full dialog width for old name when renaming branch Let the combobox/option menu expand to fill the width of the dialog. Signed-off-by: Pat Thoyts --- lib/branch_rename.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/branch_rename.tcl b/lib/branch_rename.tcl index 63988773ba..6e510ec2e3 100644 --- a/lib/branch_rename.tcl +++ b/lib/branch_rename.tcl @@ -53,7 +53,7 @@ constructor dialog {} { return 1 } - grid $w.rename.oldname_l $w.rename.oldname_m -sticky w -padx {0 5} + grid $w.rename.oldname_l $w.rename.oldname_m -sticky we -padx {0 5} grid $w.rename.newname_l $w.rename.newname_t -sticky we -padx {0 5} grid columnconfigure $w.rename 1 -weight 1 pack $w.rename -anchor nw -fill x -pady 5 -padx 5 From 38ec8d3e265220fb091b8c5ad6233b502242f866 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Wed, 20 Oct 2010 14:29:56 +0100 Subject: [PATCH 6/8] git-gui: correct assignment of work-tree git-gui currently uses its own logic to determine the work-tree setting but 'git rev-parse --toplevel' directly returns git's work-tree value by calling get_git_work_tree() and is therefore always correct. This fixes an inability to handle some repository configurations. In particular where .git is a file containing a path to the real directory (a cross-platform symbolic link). To continue to support older versions than 1.7.0, setting the work-tree by normalizing the --show-cdup value is more reliable as git-dir might be outside the work-tree entirely. Signed-off-by: Pat Thoyts --- git-gui.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 25229a4073..5e8378fc3e 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1194,13 +1194,22 @@ if {![file isdirectory $_gitdir]} { # _gitdir exists, so try loading the config load_config 0 apply_config -# try to set work tree from environment, falling back to core.worktree -if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} { - set _gitworktree [get_config core.worktree] - if {$_gitworktree eq ""} { - set _gitworktree [file dirname [file normalize $_gitdir]] + +# v1.7.0 introduced --show-toplevel to return the canonical work-tree +if {[package vsatisfies $_git_version 1.7.0]} { + set _gitworktree [git rev-parse --show-toplevel] +} else { + # try to set work tree from environment, core.worktree or use + # cdup to obtain a relative path to the top of the worktree. If + # run from the top, the ./ prefix ensures normalize expands pwd. + if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} { + set _gitworktree [get_config core.worktree] + if {$_gitworktree eq ""} { + set _gitworktree [file normalize ./[git rev-parse --show-cdup]] + } } } + if {$_prefix ne {}} { if {$_gitworktree eq {}} { regsub -all {[^/]+/} $_prefix ../ cdup From c744086964975eedfb7a6703789219b9749167d6 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Wed, 27 Oct 2010 23:37:31 +0100 Subject: [PATCH 7/8] git-gui: use wordprocessor tab style to ensure tabs work as expected The Tk text widget tab style is tabular where the first tab will align to the first tabstop and if that position is left of the current location then just a single character space is used. With the wordprocessor style a tab moves the next character position to the next rightmost tabstop as expected for viewing code. Signed-off-by: Pat Thoyts --- git-gui.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/git-gui.sh b/git-gui.sh index 5e8378fc3e..efbc446d67 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -3312,6 +3312,7 @@ text $ui_diff -background white -foreground black \ -xscrollcommand {.vpane.lower.diff.body.sbx set} \ -yscrollcommand {.vpane.lower.diff.body.sby set} \ -state disabled +catch {$ui_diff configure -tabstyle wordprocessor} ${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \ -command [list $ui_diff xview] ${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \ From 8f85599aba6b569de5c559994704a416f52bc031 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Fri, 22 Oct 2010 16:14:38 +0100 Subject: [PATCH 8/8] git-gui: apply color information from git diff output This patch extracts the ANSI color sequences from git diff output and applies these to the diff view window. This ensures that the gui view makes use of the current git configuration for whitespace display. ANSI codes may include attributes, foreground and background in a single sequence. Handle this and support bold and reverse attributes. Ignore all other attributes. Suggested-by: Tor Arvid Lund Suggested-by: Junio C Hamano Tested-by: Tor Arvid Lund Signed-off-by: Pat Thoyts --- git-gui.sh | 10 +++++++++- lib/diff.tcl | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index efbc446d67..d3acf0d213 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -3323,8 +3323,16 @@ pack $ui_diff -side left -fill both -expand 1 pack .vpane.lower.diff.header -side top -fill x pack .vpane.lower.diff.body -side bottom -fill both -expand 1 +foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} { + $ui_diff tag configure clr4$n -background $c + $ui_diff tag configure clri4$n -foreground $c + $ui_diff tag configure clr3$n -foreground $c + $ui_diff tag configure clri3$n -background $c +} +$ui_diff tag configure clr1 -font font_diffbold + $ui_diff tag conf d_cr -elide true -$ui_diff tag conf d_@ -foreground blue -font font_diffbold +$ui_diff tag conf d_@ -font font_diffbold $ui_diff tag conf d_+ -foreground {#00a000} $ui_diff tag conf d_- -foreground red diff --git a/lib/diff.tcl b/lib/diff.tcl index c628750276..dcf0711be0 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -294,7 +294,7 @@ proc start_show_diff {cont_info {add_opts {}}} { } lappend cmd -p - lappend cmd --no-color + lappend cmd --color if {$repo_config(gui.diffcontext) >= 1} { lappend cmd "-U$repo_config(gui.diffcontext)" } @@ -332,6 +332,23 @@ proc start_show_diff {cont_info {add_opts {}}} { fileevent $fd readable [list read_diff $fd $cont_info] } +proc parse_color_line {line} { + set start 0 + set result "" + set markup [list] + set regexp {\033\[((?:\d+;)*\d+)?m} + while {[regexp -indices -start $start $regexp $line match code]} { + foreach {begin end} $match break + append result [string range $line $start [expr {$begin - 1}]] + lappend markup [string length $result] \ + [eval [linsert $code 0 string range $line]] + set start [incr end] + } + append result [string range $line $start end] + if {[llength $markup] < 4} {set markup {}} + return [list $result $markup] +} + proc read_diff {fd cont_info} { global ui_diff diff_active is_submodule_diff global is_3way_diff is_conflict_diff current_diff_header @@ -340,6 +357,9 @@ proc read_diff {fd cont_info} { $ui_diff conf -state normal while {[gets $fd line] >= 0} { + foreach {line markup} [parse_color_line $line] break + set line [string map {\033 ^} $line] + # -- Cleanup uninteresting diff header lines. # if {$::current_diff_inheader} { @@ -434,11 +454,23 @@ proc read_diff {fd cont_info} { } } } + set mark [$ui_diff index "end - 1 line linestart"] $ui_diff insert end $line $tags if {[string index $line end] eq "\r"} { $ui_diff tag add d_cr {end - 2c} } $ui_diff insert end "\n" $tags + + foreach {posbegin colbegin posend colend} $markup { + set prefix clr + foreach style [split $colbegin ";"] { + if {$style eq "7"} {append prefix i; continue} + if {$style < 30 || $style > 47} {continue} + set a "$mark linestart + $posbegin chars" + set b "$mark linestart + $posend chars" + catch {$ui_diff tag add $prefix$style $a $b} + } + } } $ui_diff conf -state disabled