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}
15 $::main_status start
$msg [mc
"files"]
16 set fd
[git_write update-index
-z --index-info
]
23 fileevent $fd writable
[list \
24 write_update_indexinfo
\
33 proc write_update_indexinfo
{fd pathList totalCnt batch
after} {
34 global update_index_cp
35 global file_states current_diff_path
37 if {$update_index_cp >= $totalCnt} {
46 {$update_index_cp < $totalCnt && $i > 0} \
48 set path
[lindex $pathList $update_index_cp]
51 set s
$file_states($path)
52 switch -glob -- [lindex $s 0] {
59 set info [lindex $s 2]
60 if {$info eq
{}} continue
62 puts -nonewline $fd "$info\t[encoding convertto $path]\0"
63 display_file
$path $new
66 $::main_status update $update_index_cp $totalCnt
69 proc update_index
{msg pathList
after} {
70 global update_index_cp
72 if {![lock_index
update]} return
75 set pathList
[lsort $pathList]
76 set totalCnt
[llength $pathList]
77 set batch
[expr {int
($totalCnt * .01) + 1}]
78 if {$batch > 25} {set batch
25}
80 $::main_status start
$msg [mc
"files"]
81 set fd
[git_write update-index
--add --remove -z --stdin]
88 fileevent $fd writable
[list \
98 proc write_update_index
{fd pathList totalCnt batch
after} {
99 global update_index_cp
100 global file_states current_diff_path
102 if {$update_index_cp >= $totalCnt} {
111 {$update_index_cp < $totalCnt && $i > 0} \
113 set path
[lindex $pathList $update_index_cp]
116 switch -glob -- [lindex $file_states($path) 0] {
122 if {[file exists
$path]} {
131 puts -nonewline $fd "[encoding convertto $path]\0"
132 display_file
$path $new
135 $::main_status update $update_index_cp $totalCnt
138 proc checkout_index
{msg pathList
after} {
139 global update_index_cp
141 if {![lock_index
update]} return
143 set update_index_cp
0
144 set pathList
[lsort $pathList]
145 set totalCnt
[llength $pathList]
146 set batch
[expr {int
($totalCnt * .01) + 1}]
147 if {$batch > 25} {set batch
25}
149 $::main_status start
$msg [mc
"files"]
150 set fd
[git_write checkout-index
\
163 fileevent $fd writable
[list \
164 write_checkout_index
\
173 proc write_checkout_index
{fd pathList totalCnt batch
after} {
174 global update_index_cp
175 global file_states current_diff_path
177 if {$update_index_cp >= $totalCnt} {
186 {$update_index_cp < $totalCnt && $i > 0} \
188 set path
[lindex $pathList $update_index_cp]
190 switch -glob -- [lindex $file_states($path) 0] {
194 puts -nonewline $fd "[encoding convertto $path]\0"
195 display_file
$path ?_
200 $::main_status update $update_index_cp $totalCnt
203 proc unstage_helper
{txt paths
} {
204 global file_states current_diff_path
206 if {![lock_index begin-update
]} return
210 foreach path
$paths {
211 switch -glob -- [lindex $file_states($path) 0] {
215 lappend pathList
$path
216 if {$path eq
$current_diff_path} {
217 set after {reshow_diff
;}
222 if {$pathList eq
{}} {
228 [concat $after [list ui_ready
]]
232 proc do_unstage_selection
{} {
233 global current_diff_path selected_paths
235 if {[array size selected_paths
] > 0} {
237 {Unstaging selected files from commit
} \
238 [array names selected_paths
]
239 } elseif
{$current_diff_path ne
{}} {
241 [mc
"Unstaging %s from commit" [short_path
$current_diff_path]] \
242 [list $current_diff_path]
246 proc add_helper
{txt paths
} {
247 global file_states current_diff_path
249 if {![lock_index begin-update
]} return
253 foreach path
$paths {
254 switch -glob -- [lindex $file_states($path) 0] {
259 lappend pathList
$path
260 if {$path eq
$current_diff_path} {
261 set after {reshow_diff
;}
266 if {$pathList eq
{}} {
272 [concat $after {ui_status
{Ready to commit.
}}]
276 proc do_add_selection
{} {
277 global current_diff_path selected_paths
279 if {[array size selected_paths
] > 0} {
281 {Adding selected files
} \
282 [array names selected_paths
]
283 } elseif
{$current_diff_path ne
{}} {
285 [mc
"Adding %s" [short_path
$current_diff_path]] \
286 [list $current_diff_path]
294 foreach path
[array names file_states
] {
295 switch -glob -- [lindex $file_states($path) 0] {
298 ?D
{lappend paths
$path}
301 add_helper
{Adding all changed files
} $paths
304 proc revert_helper
{txt paths
} {
305 global file_states current_diff_path
307 if {![lock_index begin-update
]} return
311 foreach path
$paths {
312 switch -glob -- [lindex $file_states($path) 0] {
316 lappend pathList
$path
317 if {$path eq
$current_diff_path} {
318 set after {reshow_diff
;}
325 # Split question between singular and plural cases, because
326 # such distinction is needed in some languages. Previously, the
327 # code used "Revert changes in" for both, but that can't work
328 # in languages where 'in' must be combined with word from
329 # rest of string (in diffrent way for both cases of course).
331 # FIXME: Unfortunately, even that isn't enough in some languages
332 # as they have quite complex plural-form rules. Unfortunately,
333 # msgcat doesn't seem to support that kind of string translation.
335 set n
[llength $pathList]
340 set query
[mc
"Revert changes in file %s?" [short_path
[lindex $pathList]]]
342 set query
[mc
"Revert changes in these %i files?" $n]
345 set reply
[tk_dialog \
347 "[appname] ([reponame])" \
348 [mc
"Any unstaged changes will be permanently lost by the revert."] \
352 [mc
"Revert Changes"] \
358 [concat $after [list ui_ready
]]
364 proc do_revert_selection
{} {
365 global current_diff_path selected_paths
367 if {[array size selected_paths
] > 0} {
369 {Reverting selected files
} \
370 [array names selected_paths
]
371 } elseif
{$current_diff_path ne
{}} {
373 "Reverting [short_path $current_diff_path]" \
374 [list $current_diff_path]
378 proc do_select_commit_type
{} {
379 global commit_type selected_commit_type
381 if {$selected_commit_type eq
{new
}
382 && [string match amend
* $commit_type]} {
384 } elseif
{$selected_commit_type eq
{amend
}
385 && ![string match amend
* $commit_type]} {
388 # The amend request was rejected...
390 if {![string match amend
* $commit_type]} {
391 set selected_commit_type new