@matheusbsbs / matheus-bagliano / commits / 1461c5f3d0
Fork 0

git-gui: Teach the gui how to uninclude a file.

Sometimes the user may want to keep their working directory file to be the same content but they don't want it to be part of the current commit anymore. In this case we need to undo any changes made to the index for that file (by reloading the info from HEAD or removing the file from the index) but leave the working directory alone. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 19, 2006 at 00:29 UTC 1461c5f3d0634f6fad0013eba1ef1087a38cc748
1 file changed +157 -28
git-gui
+157 -28
@@ -1,4 +1,3 @@
1 -#!/bin/sh
1 # Tcl ignores the next line -*- tcl -*- \
2 exec wish "$0" -- "$@"
3
@@ -369,12 +368,14 @@ proc read_diff_index {fd after} {
368 set z2 [string first "\0" $buf_rdi $z1]
369 if {$z2 == -1} break
370
372 - set c $z2
373 - incr z2 -1
374 - display_file \
375 - [string range $buf_rdi $z1 $z2] \
376 - [string index $buf_rdi [expr {$z1 - 2}]]?
371 incr c
372 + set n [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
373 + merge_state \
374 + [string range $buf_rdi $z1 [expr {$z2 - 1}]] \
375 + [lindex $n 4]? \
376 + [list [lindex $n 0] [lindex $n 2]] \
377 + [list]
378 + set c $z2
379 }
380 if {$c < $n} {
381 set buf_rdi [string range $buf_rdi $c end]
@@ -398,12 +399,14 @@ proc read_diff_files {fd after} {
399 set z2 [string first "\0" $buf_rdf $z1]
400 if {$z2 == -1} break
401
401 - set c $z2
402 - incr z2 -1
403 - display_file \
404 - [string range $buf_rdf $z1 $z2] \
405 - ?[string index $buf_rdf [expr {$z1 - 2}]]
402 incr c
403 + set n [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
404 + merge_state \
405 + [string range $buf_rdf $z1 [expr {$z2 - 1}]] \
406 + ?[lindex $n 4] \
407 + [list] \
408 + [list [lindex $n 0] [lindex $n 2]]
409 + set c $z2
410 }
411 if {$c < $n} {
412 set buf_rdf [string range $buf_rdf $c end]
@@ -421,7 +424,7 @@ proc read_ls_others {fd after} {
424 set pck [split $buf_rlo "\0"]
425 set buf_rlo [lindex $pck end]
426 foreach p [lrange $pck 0 end-1] {
424 - display_file $p ?O
427 + merge_state $p ?O
428 }
429 rescan_done $fd buf_rlo $after
430 }
@@ -1165,7 +1168,7 @@ proc short_path {path} {
1168
1169 set next_icon_id 0
1170
1168 -proc merge_state {path new_state} {
1171 +proc merge_state {path new_state {head_info {}} {index_info {}}} {
1172 global file_states next_icon_id
1173
1174 set s0 [string index $new_state 0]
@@ -1177,30 +1180,31 @@ proc merge_state {path new_state} {
1180 } else {
1181 set state [lindex $info 0]
1182 set icon [lindex $info 1]
1183 + if {$head_info eq {}} {set head_info [lindex $info 2]}
1184 + if {$index_info eq {}} {set index_info [lindex $info 3]}
1185 }
1186
1182 - if {$s0 eq {?}} {
1183 - set s0 [string index $state 0]
1184 - } elseif {$s0 eq {_}} {
1185 - set s0 _
1186 - }
1187 + if {$s0 eq {?}} {set s0 [string index $state 0]} \
1188 + elseif {$s0 eq {_}} {set s0 _}
1189 +
1190 + if {$s1 eq {?}} {set s1 [string index $state 1]} \
1191 + elseif {$s1 eq {_}} {set s1 _}
1192
1188 - if {$s1 eq {?}} {
1189 - set s1 [string index $state 1]
1190 - } elseif {$s1 eq {_}} {
1191 - set s1 _
1193 + if {$s0 ne {_} && [string index $state 0] eq {_}
1194 + && $head_info eq {}} {
1195 + set head_info $index_info
1196 }
1197
1194 - set file_states($path) [list $s0$s1 $icon]
1198 + set file_states($path) [list $s0$s1 $icon \
1199 + $head_info $index_info \
1200 + ]
1201 return $state
1202 }
1203
1204 proc display_file {path state} {
1199 - global file_states file_lists selected_paths rescan_active
1205 + global file_states file_lists selected_paths
1206
1207 set old_m [merge_state $path $state]
1202 - if {$rescan_active > 0} return
1203 -
1208 set s $file_states($path)
1209 set new_m [lindex $s 0]
1210 set new_w [mapcol $new_m $path]
@@ -1278,6 +1282,80 @@ proc display_all_files {} {
1282 $ui_other conf -state disabled
1283 }
1284
1285 +proc update_indexinfo {msg pathList after} {
1286 + global update_index_cp ui_status_value
1287 +
1288 + if {![lock_index update]} return
1289 +
1290 + set update_index_cp 0
1291 + set pathList [lsort $pathList]
1292 + set totalCnt [llength $pathList]
1293 + set batch [expr {int($totalCnt * .01) + 1}]
1294 + if {$batch > 25} {set batch 25}
1295 +
1296 + set ui_status_value [format \
1297 + "$msg... %i/%i files (%.2f%%)" \
1298 + $update_index_cp \
1299 + $totalCnt \
1300 + 0.0]
1301 + set fd [open "| git update-index -z --index-info" w]
1302 + fconfigure $fd \
1303 + -blocking 0 \
1304 + -buffering full \
1305 + -buffersize 512 \
1306 + -translation binary
1307 + fileevent $fd writable [list \
1308 + write_update_indexinfo \
1309 + $fd \
1310 + $pathList \
1311 + $totalCnt \
1312 + $batch \
1313 + $msg \
1314 + $after \
1315 + ]
1316 +}
1317 +
1318 +proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
1319 + global update_index_cp ui_status_value
1320 + global file_states current_diff
1321 +
1322 + if {$update_index_cp >= $totalCnt} {
1323 + close $fd
1324 + unlock_index
1325 + uplevel #0 $after
1326 + return
1327 + }
1328 +
1329 + for {set i $batch} \
1330 + {$update_index_cp < $totalCnt && $i > 0} \
1331 + {incr i -1} {
1332 + set path [lindex $pathList $update_index_cp]
1333 + incr update_index_cp
1334 +
1335 + set s $file_states($path)
1336 + switch -glob -- [lindex $s 0] {
1337 + A? {set new _O}
1338 + M? {set new _M}
1339 + D? {set new _?}
1340 + ?? {continue}
1341 + }
1342 + set info [lindex $s 2]
1343 + if {$info eq {}} continue
1344 +
1345 + puts -nonewline $fd $info
1346 + puts -nonewline $fd "\t"
1347 + puts -nonewline $fd $path
1348 + puts -nonewline $fd "\0"
1349 + display_file $path $new
1350 + }
1351 +
1352 + set ui_status_value [format \
1353 + "$msg... %i/%i files (%.2f%%)" \
1354 + $update_index_cp \
1355 + $totalCnt \
1356 + [expr {100.0 * $update_index_cp / $totalCnt}]]
1357 +}
1358 +
1359 proc update_index {msg pathList after} {
1360 global update_index_cp ui_status_value
1361
@@ -1881,6 +1959,49 @@ proc do_rescan {} {
1959 rescan {set ui_status_value {Ready.}}
1960 }
1961
1962 +proc remove_helper {txt paths} {
1963 + global file_states current_diff
1964 +
1965 + if {![lock_index begin-update]} return
1966 +
1967 + set pathList [list]
1968 + set after {}
1969 + foreach path $paths {
1970 + switch -glob -- [lindex $file_states($path) 0] {
1971 + A? -
1972 + M? -
1973 + D? {
1974 + lappend pathList $path
1975 + if {$path eq $current_diff} {
1976 + set after {reshow_diff;}
1977 + }
1978 + }
1979 + }
1980 + }
1981 + if {$pathList eq {}} {
1982 + unlock_index
1983 + } else {
1984 + update_indexinfo \
1985 + $txt \
1986 + $pathList \
1987 + [concat $after {set ui_status_value {Ready.}}]
1988 + }
1989 +}
1990 +
1991 +proc do_remove_selection {} {
1992 + global current_diff selected_paths
1993 +
1994 + if {[array size selected_paths] > 0} {
1995 + remove_helper \
1996 + {Removing selected files from commit} \
1997 + [array names selected_paths]
1998 + } elseif {$current_diff ne {}} {
1999 + remove_helper \
2000 + "Removing [short_path $current_diff] from commit" \
2001 + [list $current_diff]
2002 + }
2003 +}
2004 +
2005 proc include_helper {txt paths} {
2006 global file_states current_diff
2007
@@ -2525,19 +2646,27 @@ lappend disable_on_lock \
2646 lappend disable_on_lock \
2647 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2648
2528 -.mbar.commit add command -label {Include Selected Files} \
2649 +.mbar.commit add command -label {Remove From Commit} \
2650 + -command do_remove_selection \
2651 + -font font_ui
2652 +lappend disable_on_lock \
2653 + [list .mbar.commit entryconf [.mbar.commit index last] -state]
2654 +
2655 +.mbar.commit add command -label {Include In Commit} \
2656 -command do_include_selection \
2657 -font font_ui
2658 lappend disable_on_lock \
2659 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2660
2534 -.mbar.commit add command -label {Include All Files} \
2661 +.mbar.commit add command -label {Include All} \
2662 -command do_include_all \
2663 -accelerator $M1T-I \
2664 -font font_ui
2665 lappend disable_on_lock \
2666 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2667
2668 +.mbar.commit add separator
2669 +
2670 .mbar.commit add command -label {Sign Off} \
2671 -command do_signoff \
2672 -accelerator $M1T-S \