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 "$msg... %i/%i files (%.2f%%)" \
20 set fd
[git_write update-index
-z --index-info
]
27 fileevent $fd writable
[list \
28 write_update_indexinfo
\
38 proc write_update_indexinfo
{fd pathList totalCnt batch msg
after} {
39 global update_index_cp
40 global file_states current_diff_path
42 if {$update_index_cp >= $totalCnt} {
50 {$update_index_cp < $totalCnt && $i > 0} \
52 set path
[lindex $pathList $update_index_cp]
55 set s
$file_states($path)
56 switch -glob -- [lindex $s 0] {
63 set info [lindex $s 2]
64 if {$info eq
{}} continue
66 puts -nonewline $fd "$info\t[encoding convertto $path]\0"
67 display_file
$path $new
71 "$msg... %i/%i files (%.2f%%)" \
74 [expr {100.0 * $update_index_cp / $totalCnt}]]
77 proc update_index
{msg pathList
after} {
78 global update_index_cp
80 if {![lock_index
update]} return
83 set pathList
[lsort $pathList]
84 set totalCnt
[llength $pathList]
85 set batch
[expr {int
($totalCnt * .01) + 1}]
86 if {$batch > 25} {set batch
25}
89 "$msg... %i/%i files (%.2f%%)" \
93 set fd
[git_write update-index
--add --remove -z --stdin]
100 fileevent $fd writable
[list \
111 proc write_update_index
{fd pathList totalCnt batch msg
after} {
112 global update_index_cp
113 global file_states current_diff_path
115 if {$update_index_cp >= $totalCnt} {
123 {$update_index_cp < $totalCnt && $i > 0} \
125 set path
[lindex $pathList $update_index_cp]
128 switch -glob -- [lindex $file_states($path) 0] {
134 if {[file exists
$path]} {
143 puts -nonewline $fd "[encoding convertto $path]\0"
144 display_file
$path $new
148 "$msg... %i/%i files (%.2f%%)" \
151 [expr {100.0 * $update_index_cp / $totalCnt}]]
154 proc checkout_index
{msg pathList
after} {
155 global update_index_cp
157 if {![lock_index
update]} return
159 set update_index_cp
0
160 set pathList
[lsort $pathList]
161 set totalCnt
[llength $pathList]
162 set batch
[expr {int
($totalCnt * .01) + 1}]
163 if {$batch > 25} {set batch
25}
166 "$msg... %i/%i files (%.2f%%)" \
170 set fd
[git_write checkout-index
\
183 fileevent $fd writable
[list \
184 write_checkout_index
\
194 proc write_checkout_index
{fd pathList totalCnt batch msg
after} {
195 global update_index_cp
196 global file_states current_diff_path
198 if {$update_index_cp >= $totalCnt} {
206 {$update_index_cp < $totalCnt && $i > 0} \
208 set path
[lindex $pathList $update_index_cp]
210 switch -glob -- [lindex $file_states($path) 0] {
214 puts -nonewline $fd "[encoding convertto $path]\0"
215 display_file
$path ?_
221 "$msg... %i/%i files (%.2f%%)" \
224 [expr {100.0 * $update_index_cp / $totalCnt}]]
227 proc unstage_helper
{txt paths
} {
228 global file_states current_diff_path
230 if {![lock_index begin-update
]} return
234 foreach path
$paths {
235 switch -glob -- [lindex $file_states($path) 0] {
239 lappend pathList
$path
240 if {$path eq
$current_diff_path} {
241 set after {reshow_diff
;}
246 if {$pathList eq
{}} {
252 [concat $after [list ui_ready
]]
256 proc do_unstage_selection
{} {
257 global current_diff_path selected_paths
259 if {[array size selected_paths
] > 0} {
261 {Unstaging selected files from commit
} \
262 [array names selected_paths
]
263 } elseif
{$current_diff_path ne
{}} {
265 "Unstaging [short_path $current_diff_path] from commit" \
266 [list $current_diff_path]
270 proc add_helper
{txt paths
} {
271 global file_states current_diff_path
273 if {![lock_index begin-update
]} return
277 foreach path
$paths {
278 switch -glob -- [lindex $file_states($path) 0] {
283 lappend pathList
$path
284 if {$path eq
$current_diff_path} {
285 set after {reshow_diff
;}
290 if {$pathList eq
{}} {
296 [concat $after {ui_status
{Ready to commit.
}}]
300 proc do_add_selection
{} {
301 global current_diff_path selected_paths
303 if {[array size selected_paths
] > 0} {
305 {Adding selected files
} \
306 [array names selected_paths
]
307 } elseif
{$current_diff_path ne
{}} {
309 "Adding [short_path $current_diff_path]" \
310 [list $current_diff_path]
318 foreach path
[array names file_states
] {
319 switch -glob -- [lindex $file_states($path) 0] {
322 ?D
{lappend paths
$path}
325 add_helper
{Adding all changed files
} $paths
328 proc revert_helper
{txt paths
} {
329 global file_states current_diff_path
331 if {![lock_index begin-update
]} return
335 foreach path
$paths {
336 switch -glob -- [lindex $file_states($path) 0] {
340 lappend pathList
$path
341 if {$path eq
$current_diff_path} {
342 set after {reshow_diff
;}
349 # Split question between singular and plural cases, because
350 # such distinction is needed in some languages. Previously, the
351 # code used "Revert changes in" for both, but that can't work
352 # in languages where 'in' must be combined with word from
353 # rest of string (in diffrent way for both cases of course).
355 # FIXME: Unfortunately, even that isn't enough in some languages
356 # as they have quite complex plural-form rules. Unfortunately,
357 # msgcat doesn't seem to support that kind of string translation.
359 set n
[llength $pathList]
364 set query
[mc
"Revert changes in file %s?" [short_path
[lindex $pathList]]]
366 set query
[mc
"Revert changes in these %i files?" $n]
369 set reply
[tk_dialog \
371 "[appname] ([reponame])" \
372 [mc
"Any unstaged changes will be permanently lost by the revert."] \
376 [mc
"Revert Changes"] \
382 [concat $after [list ui_ready
]]
388 proc do_revert_selection
{} {
389 global current_diff_path selected_paths
391 if {[array size selected_paths
] > 0} {
393 {Reverting selected files
} \
394 [array names selected_paths
]
395 } elseif
{$current_diff_path ne
{}} {
397 "Reverting [short_path $current_diff_path]" \
398 [list $current_diff_path]
402 proc do_select_commit_type
{} {
403 global commit_type selected_commit_type
405 if {$selected_commit_type eq
{new
}
406 && [string match amend
* $commit_type]} {
408 } elseif
{$selected_commit_type eq
{amend
}
409 && ![string match amend
* $commit_type]} {
412 # The amend request was rejected...
414 if {![string match amend
* $commit_type]} {
415 set selected_commit_type new