Skip to content

Commit f7078b4

Browse files
angavrilovspearce
authored andcommitted
git-gui: Allow specifying an initial line for git gui blame.
Add a command-line option to make git gui blame automatically scroll to a specific line in the file. Useful for integration with other tools. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent 823f7cf commit f7078b4

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

git-gui.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,10 +2296,15 @@ proc usage {} {
22962296
switch -- $subcommand {
22972297
browser -
22982298
blame {
2299-
set subcommand_args {rev? path}
2299+
if {$subcommand eq "blame"} {
2300+
set subcommand_args {[--line=<num>] rev? path}
2301+
} else {
2302+
set subcommand_args {rev? path}
2303+
}
23002304
if {$argv eq {}} usage
23012305
set head {}
23022306
set path {}
2307+
set jump_spec {}
23032308
set is_path 0
23042309
foreach a $argv {
23052310
if {$is_path || [file exists $_prefix$a]} {
@@ -2313,6 +2318,9 @@ blame {
23132318
set path {}
23142319
}
23152320
set is_path 1
2321+
} elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
2322+
if {$jump_spec ne {} || $head ne {}} usage
2323+
set jump_spec [list $lnum]
23162324
} elseif {$head eq {}} {
23172325
if {$head ne {}} usage
23182326
set head $a
@@ -2344,6 +2352,7 @@ blame {
23442352
23452353
switch -- $subcommand {
23462354
browser {
2355+
if {$jump_spec ne {}} usage
23472356
if {$head eq {}} {
23482357
if {$path ne {} && [file isdirectory $path]} {
23492358
set head $current_branch
@@ -2359,7 +2368,7 @@ blame {
23592368
puts stderr [mc "fatal: cannot stat path %s: No such file or directory" $path]
23602369
exit 1
23612370
}
2362-
blame::new $head $path
2371+
blame::new $head $path $jump_spec
23632372
}
23642373
}
23652374
return

lib/blame.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ field tooltip_t {} ; # Text widget in $tooltip_wm
5858
field tooltip_timer {} ; # Current timer event for our tooltip
5959
field tooltip_commit {} ; # Commit(s) in tooltip
6060

61-
constructor new {i_commit i_path} {
61+
constructor new {i_commit i_path i_jump} {
6262
global cursor_ptr
6363
variable active_color
6464
variable group_colors
@@ -338,7 +338,7 @@ constructor new {i_commit i_path} {
338338
wm protocol $top WM_DELETE_WINDOW "destroy $top"
339339
bind $top <Destroy> [cb _kill]
340340

341-
_load $this {}
341+
_load $this $i_jump
342342
}
343343

344344
method _kill {} {

lib/browser.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ method _enter {} {
151151
append p [lindex $n 1]
152152
}
153153
append p $name
154-
blame::new $browser_commit $p
154+
blame::new $browser_commit $p {}
155155
}
156156
}
157157
}

0 commit comments

Comments
 (0)