@matheusbsbs / matheus-bagliano / commits / 25476c63e7
Fork 0

git-gui: Add a special diff popup menu for submodules

To make it easier for users to deal with submodules, a special diff popup menu has been added for submodules. The "Show Less Context" and "Show More Context" entries have been removed, as they don't make any sense for a submodule summary. Four new entries are added to the top of the popup menu to gain access to more detailed information about the changes in a submodule than the plain summary does offer. These are: - "Visualize These Changes In The Submodule" starts gitk showing the selected commit range - "Visualize These Changes In The Submodule" starts gitk showing the whole submodule history of the current branch - "Visualize All Branch History In The Submodule" starts gitk --all in the submodule - "Start git gui In The Submodule" guess what :-) Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Jens Lehmann committed Jan 2, 2010 at 17:58 UTC 25476c63e7d3357f955b44dd6a7c825aba819987
1 file changed +110 -16
git-gui.sh
+110 -16
@@ -1933,7 +1933,9 @@ proc incr_font_size {font {amt 1}} {
1933
1934 set starting_gitk_msg [mc "Starting gitk... please wait..."]
1935
1936 -proc do_gitk {revs} {
1936 +proc do_gitk {revs {is_submodule false}} {
1937 + global current_diff_path file_states current_diff_side ui_index
1938 +
1939 # -- Always start gitk through whatever we were loaded with. This
1940 # lets us bypass using shell process on Windows systems.
1941 #
@@ -1951,14 +1953,73 @@ proc do_gitk {revs} {
1953 }
1954
1955 set pwd [pwd]
1954 - cd [file dirname [gitdir]]
1955 - set env(GIT_DIR) [file tail [gitdir]]
1956
1957 + if {!$is_submodule} {
1958 + cd [file dirname [gitdir]]
1959 + set env(GIT_DIR) [file tail [gitdir]]
1960 + } else {
1961 + cd $current_diff_path
1962 + if {$revs eq {--}} {
1963 + set s $file_states($current_diff_path)
1964 + set old_sha1 {}
1965 + set new_sha1 {}
1966 + switch -glob -- [lindex $s 0] {
1967 + M_ { set old_sha1 [lindex [lindex $s 2] 1] }
1968 + _M { set old_sha1 [lindex [lindex $s 3] 1] }
1969 + MM {
1970 + if {$current_diff_side eq $ui_index} {
1971 + set old_sha1 [lindex [lindex $s 2] 1]
1972 + set new_sha1 [lindex [lindex $s 3] 1]
1973 + } else {
1974 + set old_sha1 [lindex [lindex $s 3] 1]
1975 + }
1976 + }
1977 + }
1978 + set revs $old_sha1...$new_sha1
1979 + }
1980 + if {[info exists env(GIT_DIR)]} {
1981 + unset env(GIT_DIR)
1982 + }
1983 + }
1984 eval exec $cmd $revs "--" "--" &
1985
1959 - if {$old_GIT_DIR eq {}} {
1986 + if {$old_GIT_DIR ne {}} {
1987 + set env(GIT_DIR) $old_GIT_DIR
1988 + }
1989 + cd $pwd
1990 +
1991 + ui_status $::starting_gitk_msg
1992 + after 10000 {
1993 + ui_ready $starting_gitk_msg
1994 + }
1995 + }
1996 +}
1997 +
1998 +proc do_git_gui {} {
1999 + global current_diff_path
2000 +
2001 + # -- Always start git gui through whatever we were loaded with. This
2002 + # lets us bypass using shell process on Windows systems.
2003 + #
2004 + set exe [_which git]
2005 + if {$exe eq {}} {
2006 + error_popup [mc "Couldn't find git gui in PATH"]
2007 + } else {
2008 + global env
2009 +
2010 + if {[info exists env(GIT_DIR)]} {
2011 + set old_GIT_DIR $env(GIT_DIR)
2012 unset env(GIT_DIR)
2013 } else {
2014 + set old_GIT_DIR {}
2015 + }
2016 +
2017 + set pwd [pwd]
2018 + cd $current_diff_path
2019 +
2020 + eval exec $exe gui &
2021 +
2022 + if {$old_GIT_DIR ne {}} {
2023 set env(GIT_DIR) $old_GIT_DIR
2024 }
2025 cd $pwd
@@ -3154,15 +3215,6 @@ $ui_diff tag raise sel
3215 #
3216
3217 proc create_common_diff_popup {ctxm} {
3157 - $ctxm add command \
3158 - -label [mc "Show Less Context"] \
3159 - -command show_less_context
3160 - lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3161 - $ctxm add command \
3162 - -label [mc "Show More Context"] \
3163 - -command show_more_context
3164 - lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3165 - $ctxm add separator
3218 $ctxm add command \
3219 -label [mc Refresh] \
3220 -command reshow_diff
@@ -3218,6 +3270,15 @@ $ctxm add command \
3270 set ui_diff_applyline [$ctxm index last]
3271 lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
3272 $ctxm add separator
3273 +$ctxm add command \
3274 + -label [mc "Show Less Context"] \
3275 + -command show_less_context
3276 +lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3277 +$ctxm add command \
3278 + -label [mc "Show More Context"] \
3279 + -command show_more_context
3280 +lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3281 +$ctxm add separator
3282 create_common_diff_popup $ctxm
3283
3284 set ctxmmg .vpane.lower.diff.body.ctxmmg
@@ -3240,9 +3301,40 @@ $ctxmmg add command \
3301 -command {merge_resolve_one 1}
3302 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3303 $ctxmmg add separator
3304 +$ctxmmg add command \
3305 + -label [mc "Show Less Context"] \
3306 + -command show_less_context
3307 +lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3308 +$ctxmmg add command \
3309 + -label [mc "Show More Context"] \
3310 + -command show_more_context
3311 +lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3312 +$ctxmmg add separator
3313 create_common_diff_popup $ctxmmg
3314
3245 -proc popup_diff_menu {ctxm ctxmmg x y X Y} {
3315 +set ctxmsm .vpane.lower.diff.body.ctxmsm
3316 +menu $ctxmsm -tearoff 0
3317 +$ctxmsm add command \
3318 + -label [mc "Visualize These Changes In The Submodule"] \
3319 + -command {do_gitk -- true}
3320 +lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3321 +$ctxmsm add command \
3322 + -label [mc "Visualize Current Branch History In The Submodule"] \
3323 + -command {do_gitk {} true}
3324 +lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3325 +$ctxmsm add command \
3326 + -label [mc "Visualize All Branch History In The Submodule"] \
3327 + -command {do_gitk --all true}
3328 +lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3329 +$ctxmsm add separator
3330 +$ctxmsm add command \
3331 + -label [mc "Start git gui In The Submodule"] \
3332 + -command {do_git_gui}
3333 +lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3334 +$ctxmsm add separator
3335 +create_common_diff_popup $ctxmsm
3336 +
3337 +proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3338 global current_diff_path file_states
3339 set ::cursorX $x
3340 set ::cursorY $y
@@ -3253,6 +3345,8 @@ proc popup_diff_menu {ctxm ctxmmg x y X Y} {
3345 }
3346 if {[string first {U} $state] >= 0} {
3347 tk_popup $ctxmmg $X $Y
3348 + } elseif {$::is_submodule_diff} {
3349 + tk_popup $ctxmsm $X $Y
3350 } else {
3351 if {$::ui_index eq $::current_diff_side} {
3352 set l [mc "Unstage Hunk From Commit"]
@@ -3261,7 +3355,7 @@ proc popup_diff_menu {ctxm ctxmmg x y X Y} {
3355 set l [mc "Stage Hunk For Commit"]
3356 set t [mc "Stage Line For Commit"]
3357 }
3264 - if {$::is_3way_diff || $::is_submodule_diff
3358 + if {$::is_3way_diff
3359 || $current_diff_path eq {}
3360 || {__} eq $state
3361 || {_O} eq $state
@@ -3276,7 +3370,7 @@ proc popup_diff_menu {ctxm ctxmmg x y X Y} {
3370 tk_popup $ctxm $X $Y
3371 }
3372 }
3279 -bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg %x %y %X %Y]
3373 +bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
3374
3375 # -- Status Bar
3376 #