git-gui: View blame from the command line.
Viewing annotated files is one of those tasks that is relatively difficult to do in a simple vt100 terminal emulator. The user really wants to be able to browse through a lot of information, and to interact with it by navigating through revisions. Now users can start our file viewer with annotations by running 'git gui blame commit path', thereby seeing the contents of the given file at the given commit. Right now I am being lazy by not allowing the user to omit the commit name (and have us thus assume HEAD). Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Feb 8, 2007 at 19:10 UTC
2ebba528dcb64ec1a408ec3b06cf9f928a7fb76d
1 file changed
+136
-84
git-gui.sh
+136
-84
@@ -319,16 +319,6 @@ set _reponame [lindex [file split \
319
[file normalize [file dirname $_gitdir]]] \
320
end]
321
322
-enable_option multicommit
323
-enable_option branch
324
-enable_option transport
325
-
326
-if {[appname] eq {git-citool}} {
327
- disable_option multicommit
328
- disable_option branch
329
- disable_option transport
330
-}
331
-
322
######################################################################
323
##
324
## task management
@@ -1307,7 +1297,7 @@ proc commit_committree {fd_wt curHEAD msg} {
1297
$ui_comm edit reset
1298
$ui_comm edit modified false
1299
1310
- if {![is_enabled multicommit]} do_quit
1300
+ if {[is_enabled singlecommit]} do_quit
1301
1302
# -- Update in memory status
1303
#
@@ -3236,12 +3226,17 @@ proc read_ls_tree {fd w} {
3226
proc show_blame {commit path} {
3227
global next_browser_id blame_status blame_data
3228
3239
- set w .browser[incr next_browser_id]
3229
+ if {[winfo ismapped .]} {
3230
+ set w .browser[incr next_browser_id]
3231
+ set tl $w
3232
+ toplevel $w
3233
+ } else {
3234
+ set w {}
3235
+ set tl .
3236
+ }
3237
set blame_status($w) {Loading current file content...}
3238
set texts [list]
3239
3243
- toplevel $w
3244
-
3240
label $w.path -text "$commit:$path" \
3241
-anchor w \
3242
-justify left \
@@ -3399,12 +3394,12 @@ proc show_blame {commit path} {
3394
3395
set blame_data($w,colors) {}
3396
3402
- bind $w <Visibility> "focus $w"
3403
- bind $w <Destroy> "
3404
- array unset blame_status $w
3397
+ bind $tl <Visibility> "focus $tl"
3398
+ bind $tl <Destroy> "
3399
+ array unset blame_status {$w}
3400
array unset blame_data $w,*
3401
"
3407
- wm title $w "[appname] ([reponame]): File Viewer"
3402
+ wm title $tl "[appname] ([reponame]): File Viewer"
3403
3404
set blame_data($w,total_lines) 0
3405
set cmd [list git cat-file blob "$commit:$path"]
@@ -3442,7 +3437,9 @@ proc read_blame_catfile {fd w commit path texts w_lno w_file} {
3437
lappend cmd $commit -- $path
3438
set fd [open "| $cmd" r]
3439
fconfigure $fd -blocking 0 -translation lf -encoding binary
3445
- fileevent $fd readable "read_blame_incremental $fd $w $texts"
3440
+ set handler [list read_blame_incremental $fd $w]
3441
+ append handler " $texts"
3442
+ fileevent $fd readable $handler
3443
}
3444
}
3445
@@ -4916,10 +4913,36 @@ set font_descs {
4913
load_config 0
4914
apply_config
4915
4916
+######################################################################
4917
+##
4918
+## feature option selection
4919
+
4920
+enable_option multicommit
4921
+enable_option branch
4922
+enable_option transport
4923
+
4924
+if {[appname] eq {git-citool}} {
4925
+ enable_option singlecommit
4926
+
4927
+ disable_option multicommit
4928
+ disable_option branch
4929
+ disable_option transport
4930
+}
4931
+
4932
+switch -- [lindex $argv 0] {
4933
+blame {
4934
+ disable_option multicommit
4935
+ disable_option branch
4936
+ disable_option transport
4937
+}
4938
+}
4939
+
4940
######################################################################
4941
##
4942
## ui construction
4943
4944
+set ui_comm {}
4945
+
4946
# -- Menu Bar
4947
#
4948
menu .mbar -tearoff 0
@@ -4928,7 +4951,9 @@ menu .mbar -tearoff 0
4951
if {[is_enabled branch]} {
4952
.mbar add cascade -label Branch -menu .mbar.branch
4953
}
4931
-.mbar add cascade -label Commit -menu .mbar.commit
4954
+if {[is_enabled multicommit] || [is_enabled singlecommit]} {
4955
+ .mbar add cascade -label Commit -menu .mbar.commit
4956
+}
4957
if {[is_enabled transport]} {
4958
.mbar add cascade -label Merge -menu .mbar.merge
4959
.mbar add cascade -label Fetch -menu .mbar.fetch
@@ -4944,15 +4969,17 @@ menu .mbar.repository
4969
-label {Browse Current Branch} \
4970
-command {new_browser $current_branch} \
4971
-font font_ui
4972
+trace add variable current_branch write ".mbar.repository entryconf [.mbar.repository index last] -label \"Browse \$current_branch\" ;#"
4973
.mbar.repository add separator
4974
4975
.mbar.repository add command \
4976
-label {Visualize Current Branch} \
4951
- -command {do_gitk {}} \
4977
+ -command {do_gitk $current_branch} \
4978
-font font_ui
4979
+trace add variable current_branch write ".mbar.repository entryconf [.mbar.repository index last] -label \"Visualize \$current_branch\" ;#"
4980
.mbar.repository add command \
4981
-label {Visualize All Branches} \
4955
- -command {do_gitk {--all}} \
4982
+ -command {do_gitk --all} \
4983
-font font_ui
4984
.mbar.repository add separator
4985
@@ -5049,73 +5076,75 @@ if {[is_enabled branch]} {
5076
5077
# -- Commit Menu
5078
#
5052
-menu .mbar.commit
5053
-
5054
-.mbar.commit add radiobutton \
5055
- -label {New Commit} \
5056
- -command do_select_commit_type \
5057
- -variable selected_commit_type \
5058
- -value new \
5059
- -font font_ui
5060
-lappend disable_on_lock \
5061
- [list .mbar.commit entryconf [.mbar.commit index last] -state]
5079
+if {[is_enabled multicommit] || [is_enabled singlecommit]} {
5080
+ menu .mbar.commit
5081
+
5082
+ .mbar.commit add radiobutton \
5083
+ -label {New Commit} \
5084
+ -command do_select_commit_type \
5085
+ -variable selected_commit_type \
5086
+ -value new \
5087
+ -font font_ui
5088
+ lappend disable_on_lock \
5089
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
5090
5063
-.mbar.commit add radiobutton \
5064
- -label {Amend Last Commit} \
5065
- -command do_select_commit_type \
5066
- -variable selected_commit_type \
5067
- -value amend \
5068
- -font font_ui
5069
-lappend disable_on_lock \
5070
- [list .mbar.commit entryconf [.mbar.commit index last] -state]
5091
+ .mbar.commit add radiobutton \
5092
+ -label {Amend Last Commit} \
5093
+ -command do_select_commit_type \
5094
+ -variable selected_commit_type \
5095
+ -value amend \
5096
+ -font font_ui
5097
+ lappend disable_on_lock \
5098
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
5099
5072
-.mbar.commit add separator
5100
+ .mbar.commit add separator
5101
5074
-.mbar.commit add command -label Rescan \
5075
- -command do_rescan \
5076
- -accelerator F5 \
5077
- -font font_ui
5078
-lappend disable_on_lock \
5079
- [list .mbar.commit entryconf [.mbar.commit index last] -state]
5102
+ .mbar.commit add command -label Rescan \
5103
+ -command do_rescan \
5104
+ -accelerator F5 \
5105
+ -font font_ui
5106
+ lappend disable_on_lock \
5107
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
5108
5081
-.mbar.commit add command -label {Add To Commit} \
5082
- -command do_add_selection \
5083
- -font font_ui
5084
-lappend disable_on_lock \
5085
- [list .mbar.commit entryconf [.mbar.commit index last] -state]
5109
+ .mbar.commit add command -label {Add To Commit} \
5110
+ -command do_add_selection \
5111
+ -font font_ui
5112
+ lappend disable_on_lock \
5113
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
5114
5087
-.mbar.commit add command -label {Add All To Commit} \
5088
- -command do_add_all \
5089
- -accelerator $M1T-I \
5090
- -font font_ui
5091
-lappend disable_on_lock \
5092
- [list .mbar.commit entryconf [.mbar.commit index last] -state]
5115
+ .mbar.commit add command -label {Add All To Commit} \
5116
+ -command do_add_all \
5117
+ -accelerator $M1T-I \
5118
+ -font font_ui
5119
+ lappend disable_on_lock \
5120
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
5121
5094
-.mbar.commit add command -label {Unstage From Commit} \
5095
- -command do_unstage_selection \
5096
- -font font_ui
5097
-lappend disable_on_lock \
5098
- [list .mbar.commit entryconf [.mbar.commit index last] -state]
5122
+ .mbar.commit add command -label {Unstage From Commit} \
5123
+ -command do_unstage_selection \
5124
+ -font font_ui
5125
+ lappend disable_on_lock \
5126
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
5127
5100
-.mbar.commit add command -label {Revert Changes} \
5101
- -command do_revert_selection \
5102
- -font font_ui
5103
-lappend disable_on_lock \
5104
- [list .mbar.commit entryconf [.mbar.commit index last] -state]
5128
+ .mbar.commit add command -label {Revert Changes} \
5129
+ -command do_revert_selection \
5130
+ -font font_ui
5131
+ lappend disable_on_lock \
5132
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
5133
5106
-.mbar.commit add separator
5134
+ .mbar.commit add separator
5135
5108
-.mbar.commit add command -label {Sign Off} \
5109
- -command do_signoff \
5110
- -accelerator $M1T-S \
5111
- -font font_ui
5136
+ .mbar.commit add command -label {Sign Off} \
5137
+ -command do_signoff \
5138
+ -accelerator $M1T-S \
5139
+ -font font_ui
5140
5113
-.mbar.commit add command -label Commit \
5114
- -command do_commit \
5115
- -accelerator $M1T-Return \
5116
- -font font_ui
5117
-lappend disable_on_lock \
5118
- [list .mbar.commit entryconf [.mbar.commit index last] -state]
5141
+ .mbar.commit add command -label Commit \
5142
+ -command do_commit \
5143
+ -accelerator $M1T-Return \
5144
+ -font font_ui
5145
+ lappend disable_on_lock \
5146
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
5147
+}
5148
5149
if {[is_MacOSX]} {
5150
# -- Apple Menu (Mac OS X only)
@@ -5218,6 +5247,34 @@ if {$browser ne {}} {
5247
}
5248
unset browser doc_path doc_url
5249
5250
+# -- Standard bindings
5251
+#
5252
+bind . <Destroy> do_quit
5253
+bind all <$M1B-Key-q> do_quit
5254
+bind all <$M1B-Key-Q> do_quit
5255
+bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
5256
+bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
5257
+
5258
+# -- Not a normal commit type invocation? Do that instead!
5259
+#
5260
+switch -- [lindex $argv 0] {
5261
+blame {
5262
+ if {[llength $argv] == 3} {
5263
+ set current_branch [lindex $argv 1]
5264
+ show_blame $current_branch [lindex $argv 2]
5265
+ return
5266
+ } else {
5267
+ puts stderr "usage: $argv0 blame commit path"
5268
+ exit 1
5269
+ }
5270
+}
5271
+{} {}
5272
+default {
5273
+ puts stderr "usage: $argv0 \[{blame}\]"
5274
+ exit 1
5275
+}
5276
+}
5277
+
5278
# -- Branch Control
5279
#
5280
frame .branch \
@@ -5714,7 +5771,6 @@ if {[is_enabled branch]} {
5771
bind . <$M1B-Key-N> do_create_branch
5772
}
5773
5717
-bind . <Destroy> do_quit
5774
bind all <Key-F5> do_rescan
5775
bind all <$M1B-Key-r> do_rescan
5776
bind all <$M1B-Key-R> do_rescan
@@ -5723,10 +5779,6 @@ bind . <$M1B-Key-S> do_signoff
5779
bind . <$M1B-Key-i> do_add_all
5780
bind . <$M1B-Key-I> do_add_all
5781
bind . <$M1B-Key-Return> do_commit
5726
-bind all <$M1B-Key-q> do_quit
5727
-bind all <$M1B-Key-Q> do_quit
5728
-bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
5729
-bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
5782
foreach i [list $ui_index $ui_workdir] {
5783
bind $i <Button-1> "toggle_or_diff $i %x %y; break"
5784
bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"