Skip to content

Commit 25476c6

Browse files
jlehmannspearce
authored andcommitted
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 <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent a9ae14a commit 25476c6

File tree

1 file changed

+110
-16
lines changed

1 file changed

+110
-16
lines changed

git-gui.sh

Lines changed: 110 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,9 @@ proc incr_font_size {font {amt 1}} {
19331933
19341934
set starting_gitk_msg [mc "Starting gitk... please wait..."]
19351935
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+
19371939
# -- Always start gitk through whatever we were loaded with. This
19381940
# lets us bypass using shell process on Windows systems.
19391941
#
@@ -1951,14 +1953,73 @@ proc do_gitk {revs} {
19511953
}
19521954
19531955
set pwd [pwd]
1954-
cd [file dirname [gitdir]]
1955-
set env(GIT_DIR) [file tail [gitdir]]
19561956
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+
}
19571984
eval exec $cmd $revs "--" "--" &
19581985
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)
19602012
unset env(GIT_DIR)
19612013
} 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 {}} {
19622023
set env(GIT_DIR) $old_GIT_DIR
19632024
}
19642025
cd $pwd
@@ -3154,15 +3215,6 @@ $ui_diff tag raise sel
31543215
#
31553216
31563217
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
31663218
$ctxm add command \
31673219
-label [mc Refresh] \
31683220
-command reshow_diff
@@ -3218,6 +3270,15 @@ $ctxm add command \
32183270
set ui_diff_applyline [$ctxm index last]
32193271
lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
32203272
$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
32213282
create_common_diff_popup $ctxm
32223283
32233284
set ctxmmg .vpane.lower.diff.body.ctxmmg
@@ -3240,9 +3301,40 @@ $ctxmmg add command \
32403301
-command {merge_resolve_one 1}
32413302
lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
32423303
$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
32433313
create_common_diff_popup $ctxmmg
32443314
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} {
32463338
global current_diff_path file_states
32473339
set ::cursorX $x
32483340
set ::cursorY $y
@@ -3253,6 +3345,8 @@ proc popup_diff_menu {ctxm ctxmmg x y X Y} {
32533345
}
32543346
if {[string first {U} $state] >= 0} {
32553347
tk_popup $ctxmmg $X $Y
3348+
} elseif {$::is_submodule_diff} {
3349+
tk_popup $ctxmsm $X $Y
32563350
} else {
32573351
if {$::ui_index eq $::current_diff_side} {
32583352
set l [mc "Unstage Hunk From Commit"]
@@ -3261,7 +3355,7 @@ proc popup_diff_menu {ctxm ctxmmg x y X Y} {
32613355
set l [mc "Stage Hunk For Commit"]
32623356
set t [mc "Stage Line For Commit"]
32633357
}
3264-
if {$::is_3way_diff || $::is_submodule_diff
3358+
if {$::is_3way_diff
32653359
|| $current_diff_path eq {}
32663360
|| {__} eq $state
32673361
|| {_O} eq $state
@@ -3276,7 +3370,7 @@ proc popup_diff_menu {ctxm ctxmmg x y X Y} {
32763370
tk_popup $ctxm $X $Y
32773371
}
32783372
}
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]
32803374
32813375
# -- Status Bar
32823376
#

0 commit comments

Comments
 (0)