@matheusbsbs / matheus-bagliano / commits / b4b491e388
Fork 0

git-gui: Refactor the add to commit state filters.

The list of states which are valid for update-index were a little too verbose and fed a few too many cases to the program. We can do better with less lines of code by using more pattern matching, and since we already were globbing here there's little change in runtime cost. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 20, 2007 at 23:33 UTC b4b491e388627b75ed3aee5dc60e4199eae7b362
1 file changed +15 -35
git-gui.sh
+15 -35
@@ -1512,26 +1512,15 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
1512 incr update_index_cp
1513
1514 switch -glob -- [lindex $file_states($path) 0] {
1515 - AD -
1516 - MD -
1517 - UD -
1518 - _D {set new D_}
1519 -
1520 - _M -
1521 - MM -
1522 - UM -
1523 - U_ -
1524 - M_ {set new M_}
1525 -
1515 + AD {set new __}
1516 + ?D {set new D_}
1517 _O -
1527 - AM -
1528 - A_ {set new A_}
1529 -
1518 + AM {set new A_}
1519 + U_ -
1520 + ?M {set new M_}
1521 ?? {continue}
1522 }
1532 -
1533 - puts -nonewline $fd $path
1534 - puts -nonewline $fd "\0"
1523 + puts -nonewline $fd "$path\0"
1524 display_file $path $new
1525 }
1526
@@ -2333,14 +2322,10 @@ proc add_helper {txt paths} {
2322 set after {}
2323 foreach path $paths {
2324 switch -glob -- [lindex $file_states($path) 0] {
2336 - AM -
2337 - AD -
2338 - MM -
2339 - MD -
2340 - U? -
2341 - _M -
2342 - _D -
2343 - _O {
2325 + _O -
2326 + ?M -
2327 + ?D -
2328 + U? {
2329 lappend pathList $path
2330 if {$path eq $current_diff} {
2331 set after {reshow_diff;}
@@ -2377,18 +2362,13 @@ proc do_add_all {} {
2362
2363 set paths [list]
2364 foreach path [array names file_states] {
2380 - switch -- [lindex $file_states($path) 0] {
2381 - AM -
2382 - AD -
2383 - MM -
2384 - MD -
2385 - _M -
2386 - _D {lappend paths $path}
2365 + switch -glob -- [lindex $file_states($path) 0] {
2366 + U? {continue}
2367 + ?M -
2368 + ?D {lappend paths $path}
2369 }
2370 }
2389 - add_helper \
2390 - {Adding all modified files} \
2391 - $paths
2371 + add_helper {Adding all changed files} $paths
2372 }
2373
2374 proc revert_helper {txt paths} {