Code

git-gui: Let the user continue even if we cannot understand git version
[git.git] / git-gui.sh
index 2077261e647904d9871479411263d0fdcbb79662..2127557f9d595020765dbf318051375be8c7e390 100755 (executable)
@@ -367,16 +367,25 @@ proc _which {what} {
        return {}
 }
 
+proc _lappend_nice {cmd_var} {
+       global _nice
+       upvar $cmd_var cmd
+
+       if {![info exists _nice]} {
+               set _nice [_which nice]
+       }
+       if {$_nice ne {}} {
+               lappend cmd $_nice
+       }
+}
+
 proc git {args} {
        set opt [list exec]
 
        while {1} {
                switch -- [lindex $args 0] {
                --nice {
-                       global _nice
-                       if {$_nice ne {}} {
-                               lappend opt $_nice
-                       }
+                       _lappend_nice opt
                }
 
                default {
@@ -414,6 +423,7 @@ proc _open_stdout_stderr {cmd} {
                        error $err
                }
        }
+       fconfigure $fd -eofchar {}
        return $fd
 }
 
@@ -423,10 +433,7 @@ proc git_read {args} {
        while {1} {
                switch -- [lindex $args 0] {
                --nice {
-                       global _nice
-                       if {$_nice ne {}} {
-                               lappend opt $_nice
-                       }
+                       _lappend_nice opt
                }
 
                --stderr {
@@ -454,10 +461,7 @@ proc git_write {args} {
        while {1} {
                switch -- [lindex $args 0] {
                --nice {
-                       global _nice
-                       if {$_nice ne {}} {
-                               lappend opt $_nice
-                       }
+                       _lappend_nice opt
                }
 
                default {
@@ -524,7 +528,6 @@ if {$_git eq {}} {
        error_popup "Cannot find git in PATH."
        exit 1
 }
-set _nice [_which nice]
 
 ######################################################################
 ##
@@ -544,8 +547,34 @@ if {![regsub {^git version } $_git_version {} _git_version]} {
        error_popup "Cannot parse Git version string:\n\n$_git_version"
        exit 1
 }
+
+set _real_git_version $_git_version
+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
+
+if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
+       catch {wm withdraw .}
+       if {[tk_messageBox \
+               -icon warning \
+               -type yesno \
+               -default no \
+               -title "[appname]: warning" \
+               -message "Git version cannot be determined.
+
+$_git claims it is version '$_real_git_version'.
+
+[appname] requires at least Git 1.5.0 or later.
+
+Assume '$_real_git_version' is version 1.5.0?
+"] eq {yes}} {
+               set _git_version 1.5.0
+       } else {
+               exit 1
+       }
+}
+unset _real_git_version
 
 proc git-version {args} {
        global _git_version
@@ -827,6 +856,7 @@ proc load_message {file} {
                if {[catch {set fd [open $f r]}]} {
                        return 0
                }
+               fconfigure $fd -eofchar {}
                set content [string trim [read $fd]]
                close $fd
                regsub -all -line {[ \r\t]+$} $content {} content
@@ -2554,12 +2584,21 @@ if {[is_enabled transport]} {
 # -- Only suggest a gc run if we are going to stay running.
 #
 if {[is_enabled multicommit]} {
-       set object_limit 2000
-       if {[is_Windows]} {set object_limit 200}
-       regexp {^([0-9]+) objects,} [git count-objects] _junk objects_current
+       set object_limit 8
+       if {[is_Windows]} {
+               set object_limit 1
+       }
+       set objects_current [llength [glob \
+               -directory [gitdir objects 42] \
+               -nocomplain \
+               -tails \
+               -- \
+               *]]
        if {$objects_current >= $object_limit} {
+               set objects_current [expr {$objects_current * 256}]
+               set object_limit    [expr {$object_limit    * 256}]
                if {[ask_popup \
-                       "This repository currently has $objects_current loose objects.
+                       "This repository currently has approximately $objects_current loose objects.
 
 To maintain optimal performance it is strongly recommended that you compress the database when more than $object_limit loose objects exist.
 
@@ -2567,8 +2606,11 @@ Compress the database now?"] eq yes} {
                        do_gc
                }
        }
-       unset object_limit _junk objects_current
+       unset object_limit objects_current
 }
 
 lock_index begin-read
+if {![winfo ismapped .]} {
+       wm deiconify .
+}
 after 1 do_rescan