]> asedeno.scripts.mit.edu Git - git.git/blobdiff - lib/index.tcl
git-gui: fix size and position of window panes on startup
[git.git] / lib / index.tcl
index 228bccfd82b4b9e9f9704cd28efc5252eb5d2aad..e9db0c49895fbebdf8dbe7c0472546a05fea26a0 100644 (file)
@@ -1,6 +1,61 @@
 # git-gui index (add/remove) support
 # Copyright (C) 2006, 2007 Shawn Pearce
 
+proc _delete_indexlock {} {
+       if {[catch {file delete -- [gitdir index.lock]} err]} {
+               error_popup [strcat [mc "Unable to unlock the index."] "\n\n$err"]
+       }
+}
+
+proc _close_updateindex {fd after} {
+       global use_ttk NS
+       fconfigure $fd -blocking 1
+       if {[catch {close $fd} err]} {
+               set w .indexfried
+               Dialog $w
+               wm withdraw $w
+               wm title $w [strcat "[appname] ([reponame]): " [mc "Index Error"]]
+               wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
+               set s [mc "Updating the Git index failed.  A rescan will be automatically started to resynchronize git-gui."]
+               text $w.msg -yscrollcommand [list $w.vs set] \
+                       -width [string length $s] -relief flat \
+                       -borderwidth 0 -highlightthickness 0 \
+                       -background [get_bg_color $w]
+               $w.msg tag configure bold -font font_uibold -justify center
+               ${NS}::scrollbar $w.vs -command [list $w.msg yview]
+               $w.msg insert end $s bold \n\n$err {}
+               $w.msg configure -state disabled
+
+               ${NS}::button $w.continue \
+                       -text [mc "Continue"] \
+                       -command [list destroy $w]
+               ${NS}::button $w.unlock \
+                       -text [mc "Unlock Index"] \
+                       -command "destroy $w; _delete_indexlock"
+               grid $w.msg - $w.vs -sticky news
+               grid $w.unlock $w.continue - -sticky se -padx 2 -pady 2
+               grid columnconfigure $w 0 -weight 1
+               grid rowconfigure $w 0 -weight 1
+
+               wm protocol $w WM_DELETE_WINDOW update
+               bind $w.continue <Visibility> "
+                       grab $w
+                       focus %W
+               "
+               wm deiconify $w
+               tkwait window $w
+
+               $::main_status stop
+               unlock_index
+               rescan $after 0
+               return
+       }
+
+       $::main_status stop
+       unlock_index
+       uplevel #0 $after
+}
+
 proc update_indexinfo {msg pathList after} {
        global update_index_cp
 
@@ -12,12 +67,7 @@ proc update_indexinfo {msg pathList after} {
        set batch [expr {int($totalCnt * .01) + 1}]
        if {$batch > 25} {set batch 25}
 
-       ui_status [format \
-               "%s... %i/%i files (%.2f%%)" \
-               $msg \
-               $update_index_cp \
-               $totalCnt \
-               0.0]
+       $::main_status start $msg [mc "files"]
        set fd [git_write update-index -z --index-info]
        fconfigure $fd \
                -blocking 0 \
@@ -31,19 +81,16 @@ proc update_indexinfo {msg pathList after} {
                $pathList \
                $totalCnt \
                $batch \
-               $msg \
                $after \
                ]
 }
 
-proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
+proc write_update_indexinfo {fd pathList totalCnt batch after} {
        global update_index_cp
        global file_states current_diff_path
 
        if {$update_index_cp >= $totalCnt} {
-               close $fd
-               unlock_index
-               uplevel #0 $after
+               _close_updateindex $fd $after
                return
        }
 
@@ -57,6 +104,7 @@ proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
                switch -glob -- [lindex $s 0] {
                A? {set new _O}
                M? {set new _M}
+               T_ {set new _T}
                D_ {set new _D}
                D? {set new _?}
                ?? {continue}
@@ -68,12 +116,7 @@ proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
                display_file $path $new
        }
 
-       ui_status [format \
-               "%s... %i/%i files (%.2f%%)" \
-               $msg \
-               $update_index_cp \
-               $totalCnt \
-               [expr {100.0 * $update_index_cp / $totalCnt}]]
+       $::main_status update $update_index_cp $totalCnt
 }
 
 proc update_index {msg pathList after} {
@@ -87,12 +130,7 @@ proc update_index {msg pathList after} {
        set batch [expr {int($totalCnt * .01) + 1}]
        if {$batch > 25} {set batch 25}
 
-       ui_status [format \
-               "%s... %i/%i files (%.2f%%)" \
-               $msg \
-               $update_index_cp \
-               $totalCnt \
-               0.0]
+       $::main_status start $msg [mc "files"]
        set fd [git_write update-index --add --remove -z --stdin]
        fconfigure $fd \
                -blocking 0 \
@@ -106,19 +144,16 @@ proc update_index {msg pathList after} {
                $pathList \
                $totalCnt \
                $batch \
-               $msg \
                $after \
                ]
 }
 
-proc write_update_index {fd pathList totalCnt batch msg after} {
+proc write_update_index {fd pathList totalCnt batch after} {
        global update_index_cp
        global file_states current_diff_path
 
        if {$update_index_cp >= $totalCnt} {
-               close $fd
-               unlock_index
-               uplevel #0 $after
+               _close_updateindex $fd $after
                return
        }
 
@@ -133,6 +168,8 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
                ?D {set new D_}
                _O -
                AM {set new A_}
+               _T {set new T_}
+               _U -
                U? {
                        if {[file exists $path]} {
                                set new M_
@@ -147,12 +184,7 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
                display_file $path $new
        }
 
-       ui_status [format \
-               "%s... %i/%i files (%.2f%%)" \
-               $msg \
-               $update_index_cp \
-               $totalCnt \
-               [expr {100.0 * $update_index_cp / $totalCnt}]]
+       $::main_status update $update_index_cp $totalCnt
 }
 
 proc checkout_index {msg pathList after} {
@@ -166,12 +198,7 @@ proc checkout_index {msg pathList after} {
        set batch [expr {int($totalCnt * .01) + 1}]
        if {$batch > 25} {set batch 25}
 
-       ui_status [format \
-               "%s... %i/%i files (%.2f%%)" \
-               $msg \
-               $update_index_cp \
-               $totalCnt \
-               0.0]
+       $::main_status start $msg [mc "files"]
        set fd [git_write checkout-index \
                --index \
                --quiet \
@@ -191,19 +218,16 @@ proc checkout_index {msg pathList after} {
                $pathList \
                $totalCnt \
                $batch \
-               $msg \
                $after \
                ]
 }
 
-proc write_checkout_index {fd pathList totalCnt batch msg after} {
+proc write_checkout_index {fd pathList totalCnt batch after} {
        global update_index_cp
        global file_states current_diff_path
 
        if {$update_index_cp >= $totalCnt} {
-               close $fd
-               unlock_index
-               uplevel #0 $after
+               _close_updateindex $fd $after
                return
        }
 
@@ -215,6 +239,7 @@ proc write_checkout_index {fd pathList totalCnt batch msg after} {
                switch -glob -- [lindex $file_states($path) 0] {
                U? {continue}
                ?M -
+               ?T -
                ?D {
                        puts -nonewline $fd "[encoding convertto $path]\0"
                        display_file $path ?_
@@ -222,12 +247,7 @@ proc write_checkout_index {fd pathList totalCnt batch msg after} {
                }
        }
 
-       ui_status [format \
-               "%s... %i/%i files (%.2f%%)" \
-               $msg \
-               $update_index_cp \
-               $totalCnt \
-               [expr {100.0 * $update_index_cp / $totalCnt}]]
+       $::main_status update $update_index_cp $totalCnt
 }
 
 proc unstage_helper {txt paths} {
@@ -241,6 +261,7 @@ proc unstage_helper {txt paths} {
                switch -glob -- [lindex $file_states($path) 0] {
                A? -
                M? -
+               T_ -
                D? {
                        lappend pathList $path
                        if {$path eq $current_diff_path} {
@@ -268,7 +289,7 @@ proc do_unstage_selection {} {
                        [array names selected_paths]
        } elseif {$current_diff_path ne {}} {
                unstage_helper \
-                       "Unstaging [short_path $current_diff_path] from commit" \
+                       [mc "Unstaging %s from commit" [short_path $current_diff_path]] \
                        [list $current_diff_path]
        }
 }
@@ -282,10 +303,18 @@ proc add_helper {txt paths} {
        set after {}
        foreach path $paths {
                switch -glob -- [lindex $file_states($path) 0] {
+               _U -
+               U? {
+                       if {$path eq $current_diff_path} {
+                               unlock_index
+                               merge_stage_workdir $path
+                               return
+                       }
+               }
                _O -
                ?M -
                ?D -
-               U? {
+               ?T {
                        lappend pathList $path
                        if {$path eq $current_diff_path} {
                                set after {reshow_diff;}
@@ -299,7 +328,7 @@ proc add_helper {txt paths} {
                update_index \
                        $txt \
                        $pathList \
-                       [concat $after {ui_status {Ready to commit.}}]
+                       [concat $after {ui_status [mc "Ready to commit."]}]
        }
 }
 
@@ -312,7 +341,7 @@ proc do_add_selection {} {
                        [array names selected_paths]
        } elseif {$current_diff_path ne {}} {
                add_helper \
-                       "Adding [short_path $current_diff_path]" \
+                       [mc "Adding %s" [short_path $current_diff_path]] \
                        [list $current_diff_path]
        }
 }
@@ -325,6 +354,7 @@ proc do_add_all {} {
                switch -glob -- [lindex $file_states($path) 0] {
                U? {continue}
                ?M -
+               ?T -
                ?D {lappend paths $path}
                }
        }
@@ -342,6 +372,7 @@ proc revert_helper {txt paths} {
                switch -glob -- [lindex $file_states($path) 0] {
                U? {continue}
                ?M -
+               ?T -
                ?D {
                        lappend pathList $path
                        if {$path eq $current_diff_path} {
@@ -375,7 +406,9 @@ proc revert_helper {txt paths} {
        set reply [tk_dialog \
                .confirm_revert \
                "[appname] ([reponame])" \
-               [mc "Any unstaged changes will be permanently lost by the revert."] \
+               "$query
+
+[mc "Any unstaged changes will be permanently lost by the revert."]" \
                question \
                1 \
                [mc "Do Nothing"] \
@@ -396,11 +429,11 @@ proc do_revert_selection {} {
 
        if {[array size selected_paths] > 0} {
                revert_helper \
-                       {Reverting selected files} \
+                       [mc "Reverting selected files"] \
                        [array names selected_paths]
        } elseif {$current_diff_path ne {}} {
                revert_helper \
-                       "Reverting [short_path $current_diff_path]" \
+                       [mc "Reverting %s" [short_path $current_diff_path]] \
                        [list $current_diff_path]
        }
 }