1 # git-gui index (add/remove) support
2 # Copyright (C) 2006, 2007 Shawn Pearce
4 proc update_indexinfo {msg pathList after} {
7 if {![lock_index update]} return
10 set pathList [lsort $pathList]
11 set totalCnt [llength $pathList]
12 set batch [expr {int($totalCnt * .01) + 1}]
13 if {$batch > 25} {set batch 25}
16 "%s... %i/%i files (%.2f%%)" \
21 set fd [git_write update-index -z --index-info]
28 fileevent $fd writable [list \
29 write_update_indexinfo \
39 proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
40 global update_index_cp
41 global file_states current_diff_path
43 if {$update_index_cp >= $totalCnt} {
51 {$update_index_cp < $totalCnt && $i > 0} \
53 set path [lindex $pathList $update_index_cp]
56 set s $file_states($path)
57 switch -glob -- [lindex $s 0] {
64 set info [lindex $s 2]
65 if {$info eq {}} continue
67 puts -nonewline $fd "$info\t[encoding convertto $path]\0"
68 display_file $path $new
72 "%s... %i/%i files (%.2f%%)" \
76 [expr {100.0 * $update_index_cp / $totalCnt}]]
79 proc update_index {msg pathList after} {
80 global update_index_cp
82 if {![lock_index update]} return
85 set pathList [lsort $pathList]
86 set totalCnt [llength $pathList]
87 set batch [expr {int($totalCnt * .01) + 1}]
88 if {$batch > 25} {set batch 25}
91 "%s... %i/%i files (%.2f%%)" \
96 set fd [git_write update-index --add --remove -z --stdin]
103 fileevent $fd writable [list \
114 proc write_update_index {fd pathList totalCnt batch msg after} {
115 global update_index_cp
116 global file_states current_diff_path
118 if {$update_index_cp >= $totalCnt} {
126 {$update_index_cp < $totalCnt && $i > 0} \
128 set path [lindex $pathList $update_index_cp]
131 switch -glob -- [lindex $file_states($path) 0] {
137 if {[file exists $path]} {
146 puts -nonewline $fd "[encoding convertto $path]\0"
147 display_file $path $new
151 "%s... %i/%i files (%.2f%%)" \
155 [expr {100.0 * $update_index_cp / $totalCnt}]]
158 proc checkout_index {msg pathList after} {
159 global update_index_cp
161 if {![lock_index update]} return
163 set update_index_cp 0
164 set pathList [lsort $pathList]
165 set totalCnt [llength $pathList]
166 set batch [expr {int($totalCnt * .01) + 1}]
167 if {$batch > 25} {set batch 25}
170 "%s... %i/%i files (%.2f%%)" \
175 set fd [git_write checkout-index \
188 fileevent $fd writable [list \
189 write_checkout_index \
199 proc write_checkout_index {fd pathList totalCnt batch msg after} {
200 global update_index_cp
201 global file_states current_diff_path
203 if {$update_index_cp >= $totalCnt} {
211 {$update_index_cp < $totalCnt && $i > 0} \
213 set path [lindex $pathList $update_index_cp]
215 switch -glob -- [lindex $file_states($path) 0] {
219 puts -nonewline $fd "[encoding convertto $path]\0"
220 display_file $path ?_
226 "%s... %i/%i files (%.2f%%)" \
230 [expr {100.0 * $update_index_cp / $totalCnt}]]
233 proc unstage_helper {txt paths} {
234 global file_states current_diff_path
236 if {![lock_index begin-update]} return
240 foreach path $paths {
241 switch -glob -- [lindex $file_states($path) 0] {
245 lappend pathList $path
246 if {$path eq $current_diff_path} {
247 set after {reshow_diff;}
252 if {$pathList eq {}} {
258 [concat $after [list ui_ready]]
262 proc do_unstage_selection {} {
263 global current_diff_path selected_paths
265 if {[array size selected_paths] > 0} {
267 {Unstaging selected files from commit} \
268 [array names selected_paths]
269 } elseif {$current_diff_path ne {}} {
271 [mc "Unstaging %s from commit" [short_path $current_diff_path]] \
272 [list $current_diff_path]
276 proc add_helper {txt paths} {
277 global file_states current_diff_path
279 if {![lock_index begin-update]} return
283 foreach path $paths {
284 switch -glob -- [lindex $file_states($path) 0] {
289 lappend pathList $path
290 if {$path eq $current_diff_path} {
291 set after {reshow_diff;}
296 if {$pathList eq {}} {
302 [concat $after {ui_status {Ready to commit.}}]
306 proc do_add_selection {} {
307 global current_diff_path selected_paths
309 if {[array size selected_paths] > 0} {
311 {Adding selected files} \
312 [array names selected_paths]
313 } elseif {$current_diff_path ne {}} {
315 [mc "Adding %s" [short_path $current_diff_path]] \
316 [list $current_diff_path]
324 foreach path [array names file_states] {
325 switch -glob -- [lindex $file_states($path) 0] {
328 ?D {lappend paths $path}
331 add_helper {Adding all changed files} $paths
334 proc revert_helper {txt paths} {
335 global file_states current_diff_path
337 if {![lock_index begin-update]} return
341 foreach path $paths {
342 switch -glob -- [lindex $file_states($path) 0] {
346 lappend pathList $path
347 if {$path eq $current_diff_path} {
348 set after {reshow_diff;}
355 # Split question between singular and plural cases, because
356 # such distinction is needed in some languages. Previously, the
357 # code used "Revert changes in" for both, but that can't work
358 # in languages where 'in' must be combined with word from
359 # rest of string (in diffrent way for both cases of course).
361 # FIXME: Unfortunately, even that isn't enough in some languages
362 # as they have quite complex plural-form rules. Unfortunately,
363 # msgcat doesn't seem to support that kind of string translation.
365 set n [llength $pathList]
370 set query [mc "Revert changes in file %s?" [short_path [lindex $pathList]]]
372 set query [mc "Revert changes in these %i files?" $n]
375 set reply [tk_dialog \
377 "[appname] ([reponame])" \
378 [mc "Any unstaged changes will be permanently lost by the revert."] \
382 [mc "Revert Changes"] \
388 [concat $after [list ui_ready]]
394 proc do_revert_selection {} {
395 global current_diff_path selected_paths
397 if {[array size selected_paths] > 0} {
399 {Reverting selected files} \
400 [array names selected_paths]
401 } elseif {$current_diff_path ne {}} {
403 "Reverting [short_path $current_diff_path]" \
404 [list $current_diff_path]
408 proc do_select_commit_type {} {
409 global commit_type selected_commit_type
411 if {$selected_commit_type eq {new}
412 && [string match amend* $commit_type]} {
414 } elseif {$selected_commit_type eq {amend}
415 && ![string match amend* $commit_type]} {
418 # The amend request was rejected...
420 if {![string match amend* $commit_type]} {
421 set selected_commit_type new