X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=lib%2Findex.tcl;h=d33896a0ce26dd34c8024e21c71123e62832b8c0;hb=379f84b8d19b5412aff5b9d6bd7bb1ada37b9353;hp=42742850eef627262844d2414a593a6e8952d08a;hpb=f0bc498ec17eeb046c3494126e2ff12339abde77;p=git.git diff --git a/lib/index.tcl b/lib/index.tcl index 42742850e..d33896a0c 100644 --- a/lib/index.tcl +++ b/lib/index.tcl @@ -1,8 +1,58 @@ # 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} { + fconfigure $fd -blocking 1 + if {[catch {close $fd} err]} { + set w .indexfried + toplevel $w + wm title $w [strcat "[appname] ([reponame]): " [mc "Index Error"]] + wm geometry $w "+[winfo rootx .]+[winfo rooty .]" + pack [label $w.msg \ + -justify left \ + -anchor w \ + -text [strcat \ + [mc "Updating the Git index failed. A rescan will be automatically started to resynchronize git-gui."] \ + "\n\n$err"] \ + ] -anchor w + + frame $w.buttons + button $w.buttons.continue \ + -text [mc "Continue"] \ + -command [list destroy $w] + pack $w.buttons.continue -side right -padx 5 + button $w.buttons.unlock \ + -text [mc "Unlock Index"] \ + -command "destroy $w; _delete_indexlock" + pack $w.buttons.unlock -side right + pack $w.buttons -side bottom -fill x -pady 10 -padx 10 + + wm protocol $w WM_DELETE_WINDOW update + bind $w.buttons.continue " + grab $w + focus $w.buttons.continue + " + 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 ui_status_value + global update_index_cp if {![lock_index update]} return @@ -12,12 +62,8 @@ proc update_indexinfo {msg pathList after} { set batch [expr {int($totalCnt * .01) + 1}] if {$batch > 25} {set batch 25} - set ui_status_value [format \ - "$msg... %i/%i files (%.2f%%)" \ - $update_index_cp \ - $totalCnt \ - 0.0] - set fd [open "| git update-index -z --index-info" w] + $::main_status start $msg [mc "files"] + set fd [git_write update-index -z --index-info] fconfigure $fd \ -blocking 0 \ -buffering full \ @@ -30,19 +76,16 @@ proc update_indexinfo {msg pathList after} { $pathList \ $totalCnt \ $batch \ - $msg \ $after \ ] } -proc write_update_indexinfo {fd pathList totalCnt batch msg after} { - global update_index_cp ui_status_value +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 } @@ -56,6 +99,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} @@ -67,15 +111,11 @@ proc write_update_indexinfo {fd pathList totalCnt batch msg after} { display_file $path $new } - set ui_status_value [format \ - "$msg... %i/%i files (%.2f%%)" \ - $update_index_cp \ - $totalCnt \ - [expr {100.0 * $update_index_cp / $totalCnt}]] + $::main_status update $update_index_cp $totalCnt } proc update_index {msg pathList after} { - global update_index_cp ui_status_value + global update_index_cp if {![lock_index update]} return @@ -85,12 +125,8 @@ proc update_index {msg pathList after} { set batch [expr {int($totalCnt * .01) + 1}] if {$batch > 25} {set batch 25} - set ui_status_value [format \ - "$msg... %i/%i files (%.2f%%)" \ - $update_index_cp \ - $totalCnt \ - 0.0] - set fd [open "| git update-index --add --remove -z --stdin" w] + $::main_status start $msg [mc "files"] + set fd [git_write update-index --add --remove -z --stdin] fconfigure $fd \ -blocking 0 \ -buffering full \ @@ -103,19 +139,16 @@ proc update_index {msg pathList after} { $pathList \ $totalCnt \ $batch \ - $msg \ $after \ ] } -proc write_update_index {fd pathList totalCnt batch msg after} { - global update_index_cp ui_status_value +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 } @@ -130,6 +163,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_ @@ -144,15 +179,11 @@ proc write_update_index {fd pathList totalCnt batch msg after} { display_file $path $new } - set ui_status_value [format \ - "$msg... %i/%i files (%.2f%%)" \ - $update_index_cp \ - $totalCnt \ - [expr {100.0 * $update_index_cp / $totalCnt}]] + $::main_status update $update_index_cp $totalCnt } proc checkout_index {msg pathList after} { - global update_index_cp ui_status_value + global update_index_cp if {![lock_index update]} return @@ -162,18 +193,14 @@ proc checkout_index {msg pathList after} { set batch [expr {int($totalCnt * .01) + 1}] if {$batch > 25} {set batch 25} - set ui_status_value [format \ - "$msg... %i/%i files (%.2f%%)" \ - $update_index_cp \ - $totalCnt \ - 0.0] - set cmd [list git checkout-index] - lappend cmd --index - lappend cmd --quiet - lappend cmd --force - lappend cmd -z - lappend cmd --stdin - set fd [open "| $cmd " w] + $::main_status start $msg [mc "files"] + set fd [git_write checkout-index \ + --index \ + --quiet \ + --force \ + -z \ + --stdin \ + ] fconfigure $fd \ -blocking 0 \ -buffering full \ @@ -186,19 +213,16 @@ proc checkout_index {msg pathList after} { $pathList \ $totalCnt \ $batch \ - $msg \ $after \ ] } -proc write_checkout_index {fd pathList totalCnt batch msg after} { - global update_index_cp ui_status_value +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 } @@ -210,6 +234,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 ?_ @@ -217,11 +242,7 @@ proc write_checkout_index {fd pathList totalCnt batch msg after} { } } - set ui_status_value [format \ - "$msg... %i/%i files (%.2f%%)" \ - $update_index_cp \ - $totalCnt \ - [expr {100.0 * $update_index_cp / $totalCnt}]] + $::main_status update $update_index_cp $totalCnt } proc unstage_helper {txt paths} { @@ -235,6 +256,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} { @@ -249,7 +271,7 @@ proc unstage_helper {txt paths} { update_indexinfo \ $txt \ $pathList \ - [concat $after {set ui_status_value {Ready.}}] + [concat $after [list ui_ready]] } } @@ -262,7 +284,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] } } @@ -276,10 +298,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;} @@ -293,7 +323,7 @@ proc add_helper {txt paths} { update_index \ $txt \ $pathList \ - [concat $after {set ui_status_value {Ready to commit.}}] + [concat $after {ui_status [mc "Ready to commit."]}] } } @@ -306,7 +336,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] } } @@ -319,6 +349,7 @@ proc do_add_all {} { switch -glob -- [lindex $file_states($path) 0] { U? {continue} ?M - + ?T - ?D {lappend paths $path} } } @@ -336,6 +367,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} { @@ -345,32 +377,43 @@ proc revert_helper {txt paths} { } } + + # Split question between singular and plural cases, because + # such distinction is needed in some languages. Previously, the + # code used "Revert changes in" for both, but that can't work + # in languages where 'in' must be combined with word from + # rest of string (in diffrent way for both cases of course). + # + # FIXME: Unfortunately, even that isn't enough in some languages + # as they have quite complex plural-form rules. Unfortunately, + # msgcat doesn't seem to support that kind of string translation. + # set n [llength $pathList] if {$n == 0} { unlock_index return } elseif {$n == 1} { - set s "[short_path [lindex $pathList]]" + set query [mc "Revert changes in file %s?" [short_path [lindex $pathList]]] } else { - set s "these $n files" + set query [mc "Revert changes in these %i files?" $n] } set reply [tk_dialog \ .confirm_revert \ "[appname] ([reponame])" \ - "Revert changes in $s? + "$query -Any unadded changes will be permanently lost by the revert." \ +[mc "Any unstaged changes will be permanently lost by the revert."]" \ question \ 1 \ - {Do Nothing} \ - {Revert Changes} \ + [mc "Do Nothing"] \ + [mc "Revert Changes"] \ ] if {$reply == 1} { checkout_index \ $txt \ $pathList \ - [concat $after {set ui_status_value {Ready.}}] + [concat $after [list ui_ready]] } else { unlock_index } @@ -381,11 +424,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] } }