@matheusbsbs / matheus-bagliano / commits / 20a53c029e
Fork 0

git-gui: Refactor current_diff -> current_diff_path.

We now need to keep track of which side the current diff is for, HEAD<->index or index<->working directory. Consequently we need an additional "current diff" variable to tell us which side the diff is for. Since this is really only necessary in reshow_diff I'm going to declare a new global, rather than try to shove both the path and the side into current_diff. To keep things clear later on, I'm renaming current_diff to current_diff_path. There is no functionality change in this commit. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 21, 2007 at 11:37 UTC 20a53c029efe15cacc26c0e6a0c980ff4bda6635
1 file changed +41 -41
git-gui.sh
+41 -41
@@ -543,33 +543,33 @@ proc prune_selection {} {
543 ## diff
544
545 proc clear_diff {} {
546 - global ui_diff current_diff ui_index ui_workdir
546 + global ui_diff current_diff_path ui_index ui_workdir
547
548 $ui_diff conf -state normal
549 $ui_diff delete 0.0 end
550 $ui_diff conf -state disabled
551
552 - set current_diff {}
552 + set current_diff_path {}
553
554 $ui_index tag remove in_diff 0.0 end
555 $ui_workdir tag remove in_diff 0.0 end
556 }
557
558 proc reshow_diff {} {
559 - global current_diff ui_status_value file_states
559 + global current_diff_path ui_status_value file_states
560
561 - if {$current_diff eq {}
562 - || [catch {set s $file_states($current_diff)}]} {
561 + if {$current_diff_path eq {}
562 + || [catch {set s $file_states($current_diff_path)}]} {
563 clear_diff
564 } else {
565 - show_diff $current_diff
565 + show_diff $current_diff_path
566 }
567 }
568
569 proc handle_empty_diff {} {
570 - global current_diff file_states file_lists
570 + global current_diff_path file_states file_lists
571
572 - set path $current_diff
572 + set path $current_diff_path
573 set s $file_states($path)
574 if {[lindex $s 0] ne {_M}} return
575
@@ -598,7 +598,7 @@ files list, to prevent possible confusion.
598 proc show_diff {path {w {}} {lno {}}} {
599 global file_states file_lists
600 global is_3way_diff diff_active repo_config
601 - global ui_diff current_diff ui_status_value
601 + global ui_diff current_diff_path ui_status_value
602
603 if {$diff_active || ![lock_index read]} return
604
@@ -620,7 +620,7 @@ proc show_diff {path {w {}} {lno {}}} {
620 set m [lindex $s 0]
621 set is_3way_diff 0
622 set diff_active 1
623 - set current_diff $path
623 + set current_diff_path $path
624 set ui_status_value "Loading diff of [escape_path $path]..."
625
626 set cmd [list | git diff-index]
@@ -1379,7 +1379,7 @@ proc update_indexinfo {msg pathList after} {
1379
1380 proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
1381 global update_index_cp ui_status_value
1382 - global file_states current_diff
1382 + global file_states current_diff_path
1383
1384 if {$update_index_cp >= $totalCnt} {
1385 close $fd
@@ -1451,7 +1451,7 @@ proc update_index {msg pathList after} {
1451
1452 proc write_update_index {fd pathList totalCnt batch msg after} {
1453 global update_index_cp ui_status_value
1454 - global file_states current_diff
1454 + global file_states current_diff_path
1455
1456 if {$update_index_cp >= $totalCnt} {
1457 close $fd
@@ -1527,7 +1527,7 @@ proc checkout_index {msg pathList after} {
1527
1528 proc write_checkout_index {fd pathList totalCnt batch msg after} {
1529 global update_index_cp ui_status_value
1530 - global file_states current_diff
1530 + global file_states current_diff_path
1531
1532 if {$update_index_cp >= $totalCnt} {
1533 close $fd
@@ -2572,7 +2572,7 @@ proc do_rescan {} {
2572 }
2573
2574 proc unstage_helper {txt paths} {
2575 - global file_states current_diff
2575 + global file_states current_diff_path
2576
2577 if {![lock_index begin-update]} return
2578
@@ -2584,7 +2584,7 @@ proc unstage_helper {txt paths} {
2584 M? -
2585 D? {
2586 lappend pathList $path
2587 - if {$path eq $current_diff} {
2587 + if {$path eq $current_diff_path} {
2588 set after {reshow_diff;}
2589 }
2590 }
@@ -2601,21 +2601,21 @@ proc unstage_helper {txt paths} {
2601 }
2602
2603 proc do_unstage_selection {} {
2604 - global current_diff selected_paths
2604 + global current_diff_path selected_paths
2605
2606 if {[array size selected_paths] > 0} {
2607 unstage_helper \
2608 {Unstaging selected files from commit} \
2609 [array names selected_paths]
2610 - } elseif {$current_diff ne {}} {
2610 + } elseif {$current_diff_path ne {}} {
2611 unstage_helper \
2612 - "Unstaging [short_path $current_diff] from commit" \
2613 - [list $current_diff]
2612 + "Unstaging [short_path $current_diff_path] from commit" \
2613 + [list $current_diff_path]
2614 }
2615 }
2616
2617 proc add_helper {txt paths} {
2618 - global file_states current_diff
2618 + global file_states current_diff_path
2619
2620 if {![lock_index begin-update]} return
2621
@@ -2628,7 +2628,7 @@ proc add_helper {txt paths} {
2628 ?D -
2629 U? {
2630 lappend pathList $path
2631 - if {$path eq $current_diff} {
2631 + if {$path eq $current_diff_path} {
2632 set after {reshow_diff;}
2633 }
2634 }
@@ -2645,16 +2645,16 @@ proc add_helper {txt paths} {
2645 }
2646
2647 proc do_add_selection {} {
2648 - global current_diff selected_paths
2648 + global current_diff_path selected_paths
2649
2650 if {[array size selected_paths] > 0} {
2651 add_helper \
2652 {Adding selected files} \
2653 [array names selected_paths]
2654 - } elseif {$current_diff ne {}} {
2654 + } elseif {$current_diff_path ne {}} {
2655 add_helper \
2656 - "Adding [short_path $current_diff]" \
2657 - [list $current_diff]
2656 + "Adding [short_path $current_diff_path]" \
2657 + [list $current_diff_path]
2658 }
2659 }
2660
@@ -2673,7 +2673,7 @@ proc do_add_all {} {
2673 }
2674
2675 proc revert_helper {txt paths} {
2676 - global file_states current_diff
2676 + global file_states current_diff_path
2677
2678 if {![lock_index begin-update]} return
2679
@@ -2685,7 +2685,7 @@ proc revert_helper {txt paths} {
2685 ?M -
2686 ?D {
2687 lappend pathList $path
2688 - if {$path eq $current_diff} {
2688 + if {$path eq $current_diff_path} {
2689 set after {reshow_diff;}
2690 }
2691 }
@@ -2724,16 +2724,16 @@ Any unadded changes will be permanently lost by the revert." \
2724 }
2725
2726 proc do_revert_selection {} {
2727 - global current_diff selected_paths
2727 + global current_diff_path selected_paths
2728
2729 if {[array size selected_paths] > 0} {
2730 revert_helper \
2731 {Reverting selected files} \
2732 [array names selected_paths]
2733 - } elseif {$current_diff ne {}} {
2733 + } elseif {$current_diff_path ne {}} {
2734 revert_helper \
2735 - "Reverting [short_path $current_diff]" \
2736 - [list $current_diff]
2735 + "Reverting [short_path $current_diff_path]" \
2736 + [list $current_diff_path]
2737 }
2738 }
2739
@@ -3115,7 +3115,7 @@ proc do_macosx_app {} {
3115 }
3116
3117 proc toggle_or_diff {w x y} {
3118 - global file_states file_lists current_diff ui_index ui_workdir
3118 + global file_states file_lists current_diff_path ui_index ui_workdir
3119 global last_clicked selected_paths
3120
3121 set pos [split [$w index @$x,$y] .]
@@ -3133,7 +3133,7 @@ proc toggle_or_diff {w x y} {
3133 $ui_workdir tag remove in_sel 0.0 end
3134
3135 if {$col == 0} {
3136 - if {$current_diff eq $path} {
3136 + if {$current_diff_path eq $path} {
3137 set after {reshow_diff;}
3138 } else {
3139 set after {}
@@ -3739,17 +3739,17 @@ bind_button3 $ui_comm "tk_popup $ctxm %X %Y"
3739
3740 # -- Diff Header
3741 #
3742 -set current_diff {}
3742 +set current_diff_path {}
3743 set diff_actions [list]
3744 -proc trace_current_diff {varname args} {
3745 - global current_diff diff_actions file_states
3746 - if {$current_diff eq {}} {
3744 +proc trace_current_diff_path {varname args} {
3745 + global current_diff_path diff_actions file_states
3746 + if {$current_diff_path eq {}} {
3747 set s {}
3748 set f {}
3749 set p {}
3750 set o disabled
3751 } else {
3752 - set p $current_diff
3752 + set p $current_diff_path
3753 set s [mapdesc [lindex $file_states($p) 0] $p]
3754 set f {File:}
3755 set p [escape_path $p]
@@ -3763,7 +3763,7 @@ proc trace_current_diff {varname args} {
3763 uplevel #0 $w $o
3764 }
3765 }
3766 -trace add variable current_diff write trace_current_diff
3766 +trace add variable current_diff_path write trace_current_diff_path
3767
3768 frame .vpane.lower.diff.header -background orange
3769 label .vpane.lower.diff.header.status \
@@ -3795,7 +3795,7 @@ $ctxm add command \
3795 clipboard append \
3796 -format STRING \
3797 -type STRING \
3798 - -- $current_diff
3798 + -- $current_diff_path
3799 }
3800 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3801 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
@@ -3975,7 +3975,7 @@ set MERGE_HEAD [list]
3975 set commit_type {}
3976 set empty_tree {}
3977 set current_branch {}
3978 -set current_diff {}
3978 +set current_diff_path {}
3979 set selected_commit_type new
3980
3981 wm title . "[appname] ([file normalize [file dirname [gitdir]]])"