Code

gitk: Fix compare-commits function when we have local changes
[git.git] / gitk
diff --git a/gitk b/gitk
index bdd12236b86e7fbcd4314afb32c3e603037c648e..1a7887b2528140d63b84a72843c0d0ef64f56538 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -521,7 +521,7 @@ proc updatecommits {} {
     incr viewactive($view)
     set viewcomplete($view) 0
     reset_pending_select {}
-    nowbusy $view "Reading"
+    nowbusy $view [mc "Reading"]
     if {$showneartags} {
        getallcommits
     }
@@ -2251,6 +2251,10 @@ proc makewindow {} {
        }
     }
 
+    if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
+        wm state . $geometry(state)
+    }
+
     if {[tk windowingsystem] eq {aqua}} {
         set M1B M1
         set ::BM "3"
@@ -2313,6 +2317,7 @@ proc makewindow {} {
     bindkey d "$ctext yview scroll 18 units"
     bindkey u "$ctext yview scroll -18 units"
     bindkey / {focus $fstring}
+    bindkey <Key-KP_Divide> {focus $fstring}
     bindkey <Key-Return> {dofind 1 1}
     bindkey ? {dofind -1 1}
     bindkey f nextfile
@@ -2519,6 +2524,9 @@ proc savestuff {w} {
     if {![winfo viewable .]} return
     catch {
        set f [open "~/.gitk-new" w]
+       if {$::tcl_platform(platform) eq {windows}} {
+           file attributes "~/.gitk-new" -hidden true
+       }
        puts $f [list set mainfont $mainfont]
        puts $f [list set textfont $textfont]
        puts $f [list set uifont $uifont]
@@ -2544,6 +2552,7 @@ proc savestuff {w} {
        puts $f [list set perfile_attrs $perfile_attrs]
 
        puts $f "set geometry(main) [wm geometry .]"
+       puts $f "set geometry(state) [wm state .]"
        puts $f "set geometry(topwidth) [winfo width .tf]"
        puts $f "set geometry(topheight) [winfo height .tf]"
         puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
@@ -3236,9 +3245,8 @@ proc external_diff {} {
     set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
 
     if {$difffromfile ne {} && $difftofile ne {}} {
-        set cmd [concat | [shellsplit $extdifftool] \
-                    [list $difffromfile $difftofile]]
-        if {[catch {set fl [open $cmd r]} err]} {
+        set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
+        if {[catch {set fl [open |$cmd r]} err]} {
             file delete -force $diffdir
             error_popup "$extdifftool: [mc "command failed:"] $err"
         } else {
@@ -3769,7 +3777,7 @@ proc editview {} {
     set newviewopts($curview,perm) $viewperm($curview)
     set newviewopts($curview,cmd)  $viewargscmd($curview)
     decode_view_opts $curview $viewargs($curview)
-    vieweditor $top $curview "Gitk: edit view $viewname($curview)"
+    vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
 }
 
 proc vieweditor {top n title} {
@@ -6481,6 +6489,17 @@ proc setlink {id lk} {
     }
 }
 
+proc appendshortlink {id {pre {}} {post {}}} {
+    global ctext linknum
+
+    $ctext insert end $pre
+    $ctext tag delete link$linknum
+    $ctext insert end [string range $id 0 7] link$linknum
+    $ctext insert end $post
+    setlink $id link$linknum
+    incr linknum
+}
+
 proc makelink {id} {
     global pendinglinks
 
@@ -6537,7 +6556,7 @@ proc appendrefs {pos ids var} {
        }
     }
     if {[llength $tags] > $maxrefs} {
-       $ctext insert $pos "many ([llength $tags])"
+       $ctext insert $pos "[mc "many"] ([llength $tags])"
     } else {
        set tags [lsort -index 0 -decreasing $tags]
        set sep {}
@@ -8119,8 +8138,15 @@ proc getpatchid {id} {
     global patchids
 
     if {![info exists patchids($id)]} {
-       set x [exec git diff-tree -p --root $id | git patch-id]
-       set patchids($id) [lindex $x 0]
+       set cmd [diffcmd [list $id] {-p --root}]
+       # trim off the initial "|"
+       set cmd [lrange $cmd 1 end]
+       if {[catch {
+           set x [eval exec $cmd | git patch-id]
+           set patchids($id) [lindex $x 0]
+       }]} {
+           set patchids($id) "error"
+       }
     }
     return $patchids($id)
 }
@@ -8132,18 +8158,16 @@ proc do_cmp_commits {a b} {
     clear_ctext
     init_flist {}
     for {set i 0} {$i < 100} {incr i} {
-       set shorta [string range $a 0 7]
-       set shortb [string range $b 0 7]
        set skipa 0
        set skipb 0
        if {[llength $parents($curview,$a)] > 1} {
-           appendwithlinks [mc "Skipping merge commit %s\n" $shorta] {}
+           appendshortlink $a [mc "Skipping merge commit "] "\n"
            set skipa 1
        } else {
            set patcha [getpatchid $a]
        }
        if {[llength $parents($curview,$b)] > 1} {
-           appendwithlinks [mc "Skipping merge commit %s\n" $shortb] {}
+           appendshortlink $b [mc "Skipping merge commit "] "\n"
            set skipb 1
        } else {
            set patchb [getpatchid $b]
@@ -8151,39 +8175,51 @@ proc do_cmp_commits {a b} {
        if {!$skipa && !$skipb} {
            set heada [lindex $commitinfo($a) 0]
            set headb [lindex $commitinfo($b) 0]
+           if {$patcha eq "error"} {
+               appendshortlink $a [mc "Error getting patch ID for "] \
+                   [mc " - stopping\n"]
+               break
+           }
+           if {$patchb eq "error"} {
+               appendshortlink $b [mc "Error getting patch ID for "] \
+                   [mc " - stopping\n"]
+               break
+           }
            if {$patcha eq $patchb} {
                if {$heada eq $headb} {
-                   appendwithlinks [mc "Commit %s == %s  %s\n" \
-                                        $shorta $shortb $heada] {}
+                   appendshortlink $a [mc "Commit "]
+                   appendshortlink $b " == " "  $heada\n"
                } else {
-                   appendwithlinks [mc "Commit %s  %s\n" $shorta $heada] {}
-                   appendwithlinks [mc " is the same patch as\n"] {}
-                   appendwithlinks [mc "       %s  %s\n" $shortb $headb] {}
+                   appendshortlink $a [mc "Commit "] "  $heada\n"
+                   appendshortlink $b [mc " is the same patch as\n       "] \
+                       "  $headb\n"
                }
                set skipa 1
                set skipb 1
            } else {
                $ctext insert end "\n"
-               appendwithlinks [mc "Commit %s  %s\n" $shorta $heada] {}
-               appendwithlinks [mc " differs from\n"] {}
-               appendwithlinks [mc "       %s  %s\n" $shortb $headb] {}
-               appendwithlinks [mc "- stopping\n"]
+               appendshortlink $a [mc "Commit "] "  $heada\n"
+               appendshortlink $b [mc " differs from\n       "] \
+                   "  $headb\n"
+               $ctext insert end [mc "- stopping\n"]
                break
            }
        }
        if {$skipa} {
            if {[llength $children($curview,$a)] != 1} {
                $ctext insert end "\n"
-               appendwithlinks [mc "Commit %s has %s children - stopping\n" \
-                                   $shorta [llength $children($curview,$a)]] {}
+               appendshortlink $a [mc "Commit "] \
+                   [mc " has %s children - stopping\n" \
+                        [llength $children($curview,$a)]]
                break
            }
            set a [lindex $children($curview,$a) 0]
        }
        if {$skipb} {
            if {[llength $children($curview,$b)] != 1} {
-               appendwithlinks [mc "Commit %s has %s children - stopping\n" \
-                                   $shortb [llength $children($curview,$b)]] {}
+               appendshortlink $b [mc "Commit "] \
+                   [mc " has %s children - stopping\n" \
+                        [llength $children($curview,$b)]]
                break
            }
            set b [lindex $children($curview,$b) 0]
@@ -10397,7 +10433,7 @@ proc doprefs {} {
 proc choose_extdiff {} {
     global extdifftool
 
-    set prog [tk_getOpenFile -title "External diff tool" -multiple false]
+    set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
     if {$prog ne {}} {
        set extdifftool $prog
     }
@@ -11120,6 +11156,7 @@ catch {
 # wait for the window to become visible
 tkwait visibility .
 wm title . "[file tail $argv0]: [file tail [pwd]]"
+update
 readrefs
 
 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {