From ae0754ac9a24afa2693246222fc078fe9c133b3a Mon Sep 17 00:00:00 2001
From: Simon Sasburg <simon.sasburg@gmail.com>
Date: Wed, 19 Sep 2007 00:33:34 +0200
Subject: [PATCH 01/10] git-gui: Avoid using bold text in entire gui for some
 fonts

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-gui.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-gui.sh b/git-gui.sh
index f789e91b66..28d7c21692 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1648,7 +1648,7 @@ proc apply_config {} {
 		set font [lindex $option 1]
 		if {[catch {
 			foreach {cn cv} $repo_config(gui.$name) {
-				font configure $font $cn $cv
+				font configure $font $cn $cv -weight normal
 			}
 			} err]} {
 			error_popup "Invalid font specified in gui.$name:\n\n$err"

From 183a1d1496921e16d316ac523146385af39fcdb0 Mon Sep 17 00:00:00 2001
From: "Shawn O. Pearce" <spearce@spearce.org>
Date: Fri, 21 Sep 2007 10:58:02 -0400
Subject: [PATCH 02/10] git-gui: Display message box when we cannot find git in
 $PATH

If we cannot find the git executable in the user's $PATH then
we cannot function correctly.  Because we need that to get the
version so we can load our library correctly we cannot rely on
the library function "error_popup" here, as this is all running
before the library path has been configured, so error_popup is
not available to us.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-gui.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/git-gui.sh b/git-gui.sh
index 28d7c21692..10710e26c6 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -498,7 +498,11 @@ proc rmsel_tag {text} {
 set _git  [_which git]
 if {$_git eq {}} {
 	catch {wm withdraw .}
-	error_popup "Cannot find git in PATH."
+	tk_messageBox \
+		-icon error \
+		-type ok \
+		-title [mc "git-gui: fatal error"] \
+		-message [mc "Cannot find git in PATH."]
 	exit 1
 }
 

From 299077fb40eac1e128b7bc09d5d992960e6f11c2 Mon Sep 17 00:00:00 2001
From: "Shawn O. Pearce" <spearce@spearce.org>
Date: Fri, 21 Sep 2007 11:08:50 -0400
Subject: [PATCH 03/10] git-gui: Handle starting on mapped shares under Cygwin

I really cannot explain Cygwin's behavior here but if we start
git-gui through Cygwin on a local drive it appears that Cygwin
is leaving $env(PATH) in Unix style, even if it started a native
(non-Cygwin) Tcl/Tk process to run git-gui.  Yet starting that
same git-gui and Tcl/Tk combination through Cygwin on a network
share causes it to automatically convert $env(PATH) into Windows
style, which broke our internal "which" implementation.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-gui.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-gui.sh b/git-gui.sh
index 10710e26c6..62e1652276 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -305,7 +305,7 @@ proc _which {what} {
 	global env _search_exe _search_path
 
 	if {$_search_path eq {}} {
-		if {[is_Cygwin]} {
+		if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
 			set _search_path [split [exec cygpath \
 				--windows \
 				--path \

From 2fe167b67a479b19e52b974f9518436565e6793b Mon Sep 17 00:00:00 2001
From: "Shawn O. Pearce" <spearce@spearce.org>
Date: Fri, 21 Sep 2007 11:44:23 -0400
Subject: [PATCH 04/10] git-gui: Ensure .git/info/exclude is honored in Cygwin
 workdirs

If we are using Cygwin and the git repository is actually a
workdir (by way of git-new-workdir) but this Tcl process is
a native Tcl/Tk and not the Cygwin Tcl/Tk then we are unable
to traverse the .git/info path as it is a Cygwin symlink and
not a standard Windows directory.

So we actually need to start a Cygwin process that can do the
path translation for us and let it test for .git/info/exclude
so we know if we can include that file in our git-ls-files or
not.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-gui.sh | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/git-gui.sh b/git-gui.sh
index 62e1652276..c8375029dd 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -907,6 +907,35 @@ proc rescan {after {honor_trustmtime 1}} {
 	}
 }
 
+if {[is_Cygwin]} {
+	set is_git_info_link {}
+	set is_git_info_exclude {}
+	proc have_info_exclude {} {
+		global is_git_info_link is_git_info_exclude
+
+		if {$is_git_info_link eq {}} {
+			set is_git_info_link [file isfile [gitdir info.lnk]]
+		}
+
+		if {$is_git_info_link} {
+			if {$is_git_info_exclude eq {}} {
+				if {[catch {exec test -f [gitdir info exclude]}]} {
+					set is_git_info_exclude 0
+				} else {
+					set is_git_info_exclude 1
+				}
+			}
+			return $is_git_info_exclude
+		} else {
+			return [file readable [gitdir info exclude]]
+		}
+	}
+} else {
+	proc have_info_exclude {} {
+		return [file readable [gitdir info exclude]]
+	}
+}
+
 proc rescan_stage2 {fd after} {
 	global rescan_active buf_rdi buf_rdf buf_rlo
 
@@ -917,9 +946,8 @@ proc rescan_stage2 {fd after} {
 	}
 
 	set ls_others [list --exclude-per-directory=.gitignore]
-	set info_exclude [gitdir info exclude]
-	if {[file readable $info_exclude]} {
-		lappend ls_others "--exclude-from=$info_exclude"
+	if {[have_info_exclude]} {
+		lappend ls_others "--exclude-from=[gitdir info exclude]"
 	}
 	set user_exclude [get_config core.excludesfile]
 	if {$user_exclude ne {} && [file readable $user_exclude]} {

From 501e4c6f23378aca2ce14ba4bc3eebeccb92e8d7 Mon Sep 17 00:00:00 2001
From: "Shawn O. Pearce" <spearce@spearce.org>
Date: Tue, 2 Oct 2007 12:24:44 -0400
Subject: [PATCH 05/10] git-gui: Allow gitk to be started on Cygwin with native
 Tcl/Tk

gitk expects $env(GIT_DIR) to be valid as both a path that core Git
and Tcl/Tk can resolve to a valid directory, but it has no special
handling for Cygwin style UNIX paths and Windows style paths.  So
we need to do that for gitk and ensure that only relative paths are
fed to it, thus allowing both Cygwin style and UNIX style paths to
be resolved.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-gui.sh | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/git-gui.sh b/git-gui.sh
index c8375029dd..9682418e12 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1468,7 +1468,27 @@ proc do_gitk {revs} {
 	if {! [file exists $exe]} {
 		error_popup "Unable to start gitk:\n\n$exe does not exist"
 	} else {
+		global env
+
+		if {[info exists env(GIT_DIR)]} {
+			set old_GIT_DIR $env(GIT_DIR)
+		} else {
+			set old_GIT_DIR {}
+		}
+
+		set pwd [pwd]
+		cd [file dirname [gitdir]]
+		set env(GIT_DIR) [file tail [gitdir]]
+
 		eval exec $cmd $revs &
+
+		if {$old_GIT_DIR eq {}} {
+			unset env(GIT_DIR)
+		} else {
+			set env(GIT_DIR) $old_GIT_DIR
+		}
+		cd $pwd
+
 		ui_status $::starting_gitk_msg
 		after 10000 {
 			ui_ready $starting_gitk_msg

From 906ab7f6c03764423adef6c0e4d77442405adc23 Mon Sep 17 00:00:00 2001
From: "Shawn O. Pearce" <spearce@spearce.org>
Date: Tue, 2 Oct 2007 12:27:32 -0400
Subject: [PATCH 06/10] git-gui: Don't crash when starting gitk from a browser
 session

If the user has started git-gui from the command line as a browser
we offer the gitk menu options but we didn't create the main status
bar widget in the "." toplevel.  Trying to access it while starting
gitk just results in Tcl errors.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-gui.sh | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/git-gui.sh b/git-gui.sh
index 9682418e12..cf88a0d824 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1125,11 +1125,17 @@ proc mapdesc {state path} {
 }
 
 proc ui_status {msg} {
-	$::main_status show $msg
+	global main_status
+	if {[info exists main_status]} {
+		$main_status show $msg
+	}
 }
 
 proc ui_ready {{test {}}} {
-	$::main_status show {Ready.} $test
+	global main_status
+	if {[info exists main_status]} {
+		$main_status show [mc "Ready."] $test
+	}
 }
 
 proc escape_path {path} {

From 96f11953c0b0b9b0a0c75fb98bdf239dce5ff582 Mon Sep 17 00:00:00 2001
From: Steffen Prohaska <prohaska@zib.de>
Date: Sat, 6 Oct 2007 15:27:22 +0200
Subject: [PATCH 07/10] git-gui: accept versions containing text annotations,
 like 1.5.3.mingw.1

This commit teaches git-gui to accept versions with annotations
that start with text and optionally end with a dot followed by
a number.

This is needed by the current versioning scheme of msysgit,
which uses versions like 1.5.3.mingw.1. However, the changes
is not limited to this use case. Any version of the form
<numeric version>.<anytext>.<number> would be parsed and only
the starting <numeric version> used for validation.

[sp: Minor edit to remove unnecessary group matching]

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-gui.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/git-gui.sh b/git-gui.sh
index cf88a0d824..9335a9761b 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -538,6 +538,7 @@ regsub -- {-dirty$} $_git_version {} _git_version
 regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version
 regsub {\.rc[0-9]+$} $_git_version {} _git_version
 regsub {\.GIT$} $_git_version {} _git_version
+regsub {\.[a-zA-Z]+\.[0-9]+$} $_git_version {} _git_version
 
 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
 	catch {wm withdraw .}

From 8af52d7a83a78c5f3a60d5bd5099a5073655339a Mon Sep 17 00:00:00 2001
From: "Shawn O. Pearce" <spearce@spearce.org>
Date: Sat, 20 Oct 2007 01:42:01 -0400
Subject: [PATCH 08/10] git-gui: Correctly report failures from git-write-tree

If git-write-tree fails (such as if the index file is currently
locked and it wants to write to it) we were not getting the error
message as $tree_id was always the empty string so we shortcut
through the catch and never got the output from stderr.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 lib/commit.tcl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/commit.tcl b/lib/commit.tcl
index f857a2ff5b..57238129e4 100644
--- a/lib/commit.tcl
+++ b/lib/commit.tcl
@@ -253,7 +253,7 @@ proc commit_committree {fd_wt curHEAD msg} {
 	global repo_config
 
 	gets $fd_wt tree_id
-	if {$tree_id eq {} || [catch {close $fd_wt} err]} {
+	if {[catch {close $fd_wt} err]} {
 		error_popup "write-tree failed:\n\n$err"
 		ui_status {Commit failed.}
 		unlock_index

From bea6878be2fb73e50407f93f2bcd71b961510c19 Mon Sep 17 00:00:00 2001
From: "Shawn O. Pearce" <spearce@spearce.org>
Date: Sat, 20 Oct 2007 14:16:15 -0400
Subject: [PATCH 09/10] git-gui: Handle progress bars from newer gits

Post Git 1.5.3 a new style progress bar has been introduced that
uses only one line rather than two.  The formatting of the completed
and total section is also slightly different so we must adjust our
regexp to match.  Unfortunately both styles are in active use by
different versions of Git so we need to look for both.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 lib/status_bar.tcl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/status_bar.tcl b/lib/status_bar.tcl
index 72a8fe1fd3..3bf79eb6e0 100644
--- a/lib/status_bar.tcl
+++ b/lib/status_bar.tcl
@@ -69,7 +69,10 @@ method update_meter {buf} {
 
 	set prior [string range $meter 0 $r]
 	set meter [string range $meter [expr {$r + 1}] end]
-	if {[regexp "\\((\\d+)/(\\d+)\\)\\s+done\r\$" $prior _j a b]} {
+	set p "\\((\\d+)/(\\d+)\\)"
+	if {[regexp ":\\s*\\d+% $p\(?:, done.\\s*\n|\\s*\r)\$" $prior _j a b]} {
+		update $this $a $b
+	} elseif {[regexp "$p\\s+done\r\$" $prior _j a b]} {
 		update $this $a $b
 	}
 }

From bbbadf6e58f72ac6bf739d2a1109cbd872eb1083 Mon Sep 17 00:00:00 2001
From: "Shawn O. Pearce" <spearce@spearce.org>
Date: Sat, 20 Oct 2007 20:42:01 -0400
Subject: [PATCH 10/10] git-gui: Don't display CR within console windows

Git progress bars from tools like git-push and git-fetch use CR
to skip back to the start of the current line and redraw it with
an updated progress.  We were doing this in our Tk widget but had
failed to skip the CR, which Tk doesn't draw well.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 lib/console.tcl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/console.tcl b/lib/console.tcl
index 6f718fbac3..b038a78358 100644
--- a/lib/console.tcl
+++ b/lib/console.tcl
@@ -122,7 +122,7 @@ method _read {fd after} {
 			} else {
 				$w.m.t delete $console_cr end
 				$w.m.t insert end "\n"
-				$w.m.t insert end [string range $buf $c $cr]
+				$w.m.t insert end [string range $buf $c [expr {$cr - 1}]]
 				set c $cr
 				incr c
 			}