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 "Unstaging [short_path $current_diff_path] from commit" \
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 "Adding [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
;}
354 set n
[llength $pathList]
359 set s
"[short_path [lindex $pathList]]"
361 set s
"these $n files"
364 set reply
[tk_dialog \
366 "[appname] ([reponame])" \
367 "Revert changes in $s?
369 Any unstaged changes will be permanently lost by the revert." \
379 [concat $after [list ui_ready
]]
385 proc do_revert_selection
{} {
386 global current_diff_path selected_paths
388 if {[array size selected_paths
] > 0} {
390 {Reverting selected files
} \
391 [array names selected_paths
]
392 } elseif
{$current_diff_path ne
{}} {
394 "Reverting [short_path $current_diff_path]" \
395 [list $current_diff_path]
399 proc do_select_commit_type
{} {
400 global commit_type selected_commit_type
402 if {$selected_commit_type eq
{new
}
403 && [string match amend
* $commit_type]} {
405 } elseif
{$selected_commit_type eq
{amend
}
406 && ![string match amend
* $commit_type]} {
409 # The amend request was rejected...
411 if {![string match amend
* $commit_type]} {
412 set selected_commit_type new