Improve gui blame and gitk integration
Subsystems (2)
PATCH 1/7 gitk: Allow overriding the default commit.
In reply to Alexander GavrilovOther GUI tools may occasionally need to start
gitk and make it automatically select a certain
commit. This patch supports doing it using a new
command-line option.
--- gitk | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-)
gitk +20 -1
@@ -418,10 +418,12 @@ proc stop_rev_list {view} { } proc reset_pending_select {selid} { - global pending_select mainheadid + global pending_select mainheadid selectheadid if {$selid ne {}} { set pending_select $selid + } elseif {$selectheadid ne {}} { + set pending_select $selectheadid } else { set pending_select $mainheadid }
@@ -1609,6 +1611,7 @@ proc getcommit {id} { proc readrefs {} { global tagids idtags headids idheads tagobjid global otherrefids idotherrefs mainhead mainheadid + global selecthead selectheadid foreach v {tagids idtags headids idheads otherrefids idotherrefs} { catch {unset $v}
@@ -1655,6 +1658,12 @@ proc readrefs {} { set mainhead [string range $thehead 11 end] } } + set selectheadid {} + if {$selecthead ne {}} { + catch { + set selectheadid [exec git rev-parse --verify $selecthead] + } + } } # skip over fake commits
@@ -9865,6 +9874,9 @@ if {![file isdirectory $gitdir]} { exit 1 } +set selecthead {} +set selectheadid {} + set revtreeargs {} set cmdline_files {} set i 0
@@ -9876,6 +9888,9 @@ foreach arg $argv { set cmdline_files [lrange $argv [expr {$i + 1}] end] break } + "--select-commit=*" { + set selecthead [string range $arg 16 end] + } "--argscmd=*" { set revtreeargscmd [string range $arg 10 end] }
@@ -9886,6 +9901,10 @@ foreach arg $argv { incr i } +if {$selecthead eq "HEAD"} { + set selecthead {} +} + if {$i >= [llength $argv] && $revtreeargs ne {}} { # no -- on command line, but some arguments (other than --argscmd) if {[catch {
Signature · 1 line
1.6.0.rc2
cover Improve gui blame and gitk integration
This series improves git gui blame usability by providing better integration with gitk, and thus supporting more ways of navigating the history.
Viewing the history context is especially useful if the repository is imported from a VCS without atomic commits, and thus related changes are often fragmented into a sequence of several commit objects.
Note: Show History Context won't work if gitk is unpatched.
Usage scenario:
1. Start git gui blame from an IDE macro; use --line=... to immediately scroll to the same position as the IDE editor.
2. Use 'Show History Context' to view the diff and surrounding commits.
3. Use 'Blame parent commit' in gitk to explore blame for other files touched by the same commit.
4. If the change is irrelevant (e.g. some variable was renamed), close gitk and use 'Blame Parent Commit' in Gui Blame to restart search.
GITK:
gitk: Allow overriding the default commit. --- gitk | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-) gitk: Support calling git gui blame from gitk. --- gitk | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-)
GIT-GUI:
git-gui: Support starting gitk from Gui Blame --- git-gui.sh | 1 + lib/blame.tcl | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- lib/option.tcl | 1 + 3 files changed, 55 insertions(+), 2 deletions(-) git-gui: Support passing blame to a parent commit. --- lib/blame.tcl | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 38 insertions(+), 10 deletions(-) git-gui: Better positioning in Blame Parent Commit --- lib/blame.tcl | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 61 insertions(+), 4 deletions(-) git-gui: Allow specifying an initial line for git gui blame. --- git-gui.sh | 13 +++++++++++-- lib/blame.tcl | 4 ++-- lib/browser.tcl | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-)
DOCS:
Document new options of gui tools. --- Documentation/config.txt | 14 ++++++++++++++ Documentation/git-gui.txt | 5 +++++ Documentation/gitk.txt | 5 +++++ 3 files changed, 24 insertions(+), 0 deletions(-)
Paul Mackerras
AppliedRe: [PATCH (GITK,GIT-GUI,DOCS) 1/7] gitk: Allow overriding the default commit.
In reply to Alexander GavrilovQuoted 4 lines · Alexander Gavrilov
Other GUI tools may occasionally need to start
gitk and make it automatically select a certain
commit. This patch supports doing it using a new
command-line option.
Thanks, applied, with some edits to the description.
Could you have used the existing pending_select for this? Was there a reason not to use it?
Paul.
PATCH 2/7 gitk: Support calling git gui blame from gitk.
In reply to Alexander GavrilovAdd a new item to the file list popup menu, that calls git gui blame for the selected file, starting with the first parent of the current commit.
--- gitk | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-)
gitk +23 -0
@@ -2214,6 +2214,8 @@ proc makewindow {} { -command {flist_hl 1} $flist_menu add command -label [mc "External diff"] \ -command {external_diff} + $flist_menu add command -label [mc "Blame parent commit"] \ + -command {external_blame 1} } # Windows sends all mouse wheel events to the current focused window, not
@@ -3021,6 +3023,27 @@ proc external_diff {} { } } +proc external_blame {parent_idx} { + global flist_menu_file + global nullid nullid2 + global parentlist selectedline currentid + + if {$parent_idx > 0} { + set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]] + } else { + set base_commit $currentid + } + + if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} { + error_popup [mc "No such commit"] + return + } + + if {[catch {exec git gui blame $base_commit $flist_menu_file &} err]} { + error_popup [mc "git gui blame: command failed: $err"] + } +} + # delete $dir when we see eof on $f (presumably because the child has exited) proc delete_at_eof {f dir} { while {[gets $f line] >= 0} {}
Signature · 1 line
1.6.0.rc2
Re: [PATCH (GITK,GIT-GUI,DOCS) 2/7] gitk: Support calling git gui blame from gitk.
Quoted 3 lines · Alexander Gavrilov
Add a new item to the file list popup menu, that calls git gui blame for the selected file, starting with the first parent of the current commit.
Also applied, also with some edits to the description.
gitk proc makewindow {} { · line 2218
Quoted 2 lines
gitk +2
-0+ $flist_menu add command -label [mc "Blame parent commit"] \ + -command {external_blame 1}
Why the parent commit rather than the current commit?
Paul.
Re: [PATCH (GITK,GIT-GUI,DOCS) 2/7] gitk: Support calling git gui blame from gitk.
Quoted 6 lines · Paul Mackerras
Quoted 3 lines · Alexander Gavrilov
Add a new item to the file list popup menu, that calls git gui blame for the selected file, starting with the first parent of the current commit.
Quoted 6 lines
Also applied, also with some edits to the description.
gitk proc makewindow {} { · line 2218
Quoted 2 lines
gitk +2
-0+ $flist_menu add command -label [mc "Blame parent commit"] \ + -command {external_blame 1}Why the parent commit rather than the current commit?
For the lines that the current commit *adds*, you know who is to blame (the current commit). Once you know that, you are usually interested in who is to blame for the lines that the current commit *removed*. To get this information, you must "Blame the parent commit".
-- Hannes
PATCH 3/7 git-gui: Support starting gitk from Gui Blame
In reply to Alexander GavrilovAdd a context menu command to load commits that are within a certain time range from the selected commit into gitk.
It can be useful for understanding of the code, especially if the repository is imported from a VCS that does not support atomic commits.
--- git-gui.sh | 1 + lib/blame.tcl | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- lib/option.tcl | 1 + 3 files changed, 55 insertions(+), 2 deletions(-)
git-gui.sh +1 -0
@@ -668,6 +668,7 @@ set default_config(gui.pruneduringfetch) false set default_config(gui.trustmtime) false set default_config(gui.fastcopyblame) false set default_config(gui.copyblamethreshold) 40 +set default_config(gui.blamehistoryctx) 7 set default_config(gui.diffcontext) 5 set default_config(gui.commitmsgwidth) 75 set default_config(gui.newbranchtemplate) {}
lib/blame.tcl +53 -2
75 lines not on this page · raw message
lib/option.tcl +1 -0
@@ -125,6 +125,7 @@ proc do_options {} { {b gui.matchtrackingbranch {mc "Match Tracking Branches"}} {b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}} {i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}} + {i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}} {i-0..99 gui.diffcontext {mc "Number of Diff Context Lines"}} {i-0..99 gui.commitmsgwidth {mc "Commit Message Text Width"}} {t gui.newbranchtemplate {mc "New Branch Name Template"}}
Signature · 1 line
1.6.0.rc2
PATCH 4/7 git-gui: Support passing blame to a parent commit.
Add a context menu item that switches the view to the parent of the commit under cursor. It is useful to see how the file looked before the change, and find older changes in the same lines.
--- lib/blame.tcl | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 38 insertions(+), 10 deletions(-)
lib/blame.tcl +38 -10
@@ -262,6 +262,9 @@ constructor new {i_commit i_path} { $w.ctxm add command \ -label [mc "Show History Context"] \ -command [cb _gitkcommit] + $w.ctxm add command \ + -label [mc "Blame Parent Commit"] \ + -command [cb _blameparent] foreach i $w_columns { for {set g 0} {$g < [llength $group_colors]} {incr g} {
@@ -790,19 +793,27 @@ method _load_commit {cur_w cur_d pos} { set lno [lindex [split [$cur_w index $pos] .] 0] set dat [lindex $line_data $lno] if {$dat ne {}} { - lappend history [list \ - $commit $path \ - $highlight_column \ - $highlight_line \ - [lindex [$w_file xview] 0] \ - [lindex [$w_file yview] 0] \ - ] - set commit [lindex $dat 0] - set path [lindex $dat 1] - _load $this [list [lindex $dat 2]] + _load_new_commit $this \ + [lindex $dat 0] \ + [lindex $dat 1] \ + [list [lindex $dat 2]] } } +method _load_new_commit {new_commit new_path jump} { + lappend history [list \ + $commit $path \ + $highlight_column \ + $highlight_line \ + [lindex [$w_file xview] 0] \ + [lindex [$w_file yview] 0] \ + ] + + set commit $new_commit + set path $new_path + _load $this $jump +} + method _showcommit {cur_w lno} { global repo_config variable active_color
@@ -969,6 +980,23 @@ method _gitkcommit {} { } } +method _blameparent {} { + set dat [_get_click_amov_info $this] + if {$dat ne {}} { + set cmit [lindex $dat 0] + + if {[catch {set cparent [git rev-parse --verify "$cmit^"]}]} { + error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"] + return; + } + + _load_new_commit $this \ + $cparent \ + [lindex $dat 1] \ + [list [lindex $dat 2]] + } +} + method _show_tooltip {cur_w pos} { if {$tooltip_wm ne {}} { _open_tooltip $this $cur_w
Signature · 1 line
1.6.0.rc2
PATCH 5/7 git-gui: Better positioning in Blame Parent Commit
Invoke diff-tree between the commit and its parent, and use the hunks to fix the target line number, accounting for addition and removal of lines.
--- lib/blame.tcl | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 61 insertions(+), 4 deletions(-)
lib/blame.tcl +61 -4
@@ -984,19 +984,76 @@ method _blameparent {} { set dat [_get_click_amov_info $this] if {$dat ne {}} { set cmit [lindex $dat 0] + set new_path [lindex $dat 1] if {[catch {set cparent [git rev-parse --verify "$cmit^"]}]} { error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"] return; } - _load_new_commit $this \ - $cparent \ - [lindex $dat 1] \ - [list [lindex $dat 2]] + _kill $this + + # Generate a diff between the commit and its parent, + # and use the hunks to update the line number. + # Request zero context to simplify calculations. + if {[catch {set fd [eval git_read diff-tree \ + --unified=0 $cparent $cmit $new_path]} err]} { + $status stop [mc "Unable to display parent"] + error_popup [strcat [mc "Error loading diff:"] "\n\n$err"] + return + } + + set r_orig_line [lindex $dat 2] + + fconfigure $fd \ + -blocking 0 \ + -encoding binary \ + -translation binary + fileevent $fd readable [cb _read_diff_load_commit \ + $fd $cparent $new_path $r_orig_line] + set current_fd $fd } } +method _read_diff_load_commit {fd cparent new_path tline} { + if {$fd ne $current_fd} { + catch {close $fd} + return + } + + while {[gets $fd line] >= 0} { + if {[regexp {^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@} $line line \ + old_line osz old_size new_line nsz new_size]} { + + if {$osz eq {}} { set old_size 1 } + if {$nsz eq {}} { set new_size 1 } + + if {$new_line <= $tline} { + if {[expr {$new_line + $new_size}] > $tline} { + # Target line within the hunk + set line_shift [expr { + ($new_size-$old_size)*($tline-$new_line)/$new_size + }] + } else { + set line_shift [expr {$new_size-$old_size}] + } + + set r_orig_line [expr {$r_orig_line - $line_shift}] + } + } + } + + if {[eof $fd]} { + close $fd; + set current_fd {} + + _load_new_commit $this \ + $cparent \ + $new_path \ + [list $r_orig_line] + } +} ifdeleted { catch {close $fd} } + method _show_tooltip {cur_w pos} { if {$tooltip_wm ne {}} { _open_tooltip $this $cur_w
Signature · 1 line
1.6.0.rc2
PATCH 6/7 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.
--- git-gui.sh | 13 +++++++++++-- lib/blame.tcl | 4 ++-- lib/browser.tcl | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-)
git-gui.sh +11 -2
@@ -2282,10 +2282,15 @@ proc usage {} { switch -- $subcommand { browser - blame { - set subcommand_args {rev? path} + if {$subcommand eq "blame"} { + set subcommand_args {[--line=<num>] rev? path} + } else { + set subcommand_args {rev? path} + } if {$argv eq {}} usage set head {} set path {} + set jump_spec {} set is_path 0 foreach a $argv { if {$is_path || [file exists $_prefix$a]} {
@@ -2299,6 +2304,9 @@ blame { set path {} } set is_path 1 + } elseif {[regexp {^--line=(\d+)$} $a a lnum]} { + if {$jump_spec ne {} || $head ne {}} usage + set jump_spec [list $lnum] } elseif {$head eq {}} { if {$head ne {}} usage set head $a
@@ -2330,6 +2338,7 @@ blame { switch -- $subcommand { browser { + if {$jump_spec ne {}} usage if {$head eq {}} { if {$path ne {} && [file isdirectory $path]} { set head $current_branch
@@ -2345,7 +2354,7 @@ blame { puts stderr [mc "fatal: cannot stat path %s: No such file or directory" $path] exit 1 } - blame::new $head $path + blame::new $head $path $jump_spec } } return
lib/blame.tcl +2 -2
@@ -58,7 +58,7 @@ field tooltip_t {} ; # Text widget in $tooltip_wm field tooltip_timer {} ; # Current timer event for our tooltip field tooltip_commit {} ; # Commit(s) in tooltip -constructor new {i_commit i_path} { +constructor new {i_commit i_path i_jump} { global cursor_ptr variable active_color variable group_colors
@@ -338,7 +338,7 @@ constructor new {i_commit i_path} { wm protocol $top WM_DELETE_WINDOW "destroy $top" bind $top <Destroy> [cb _kill] - _load $this {} + _load $this $i_jump } method _kill {} {
lib/browser.tcl +1 -1
@@ -151,7 +151,7 @@ method _enter {} { append p [lindex $n 1] } append p $name - blame::new $browser_commit $p + blame::new $browser_commit $p {} } } }
Signature · 1 line
1.6.0.rc2
Re: [PATCH (GITK,GIT-GUI,DOCS) 3/7] git-gui: Support starting gitk from Gui Blame
In reply to Alexander GavrilovQuoted 7 lines · Alexander Gavrilov
Add a context menu command to load commits that are within a certain time range from the selected commit into gitk.
It can be useful for understanding of the code, especially if the repository is imported from a VCS that does not support atomic commits.
The git-gui part of this series is now staged in my pu branch. If Paul is going to also apply this to gitk we can ship it in the next feature release of Git (1.6.1).
Signature · 1 line
Shawn.
PATCH 7/7 Document new options of gui tools.
In reply to Alexander GavrilovAdds information on git-gui configuration, and new git-gui blame & gitk command-line options.
--- Documentation/config.txt | 14 ++++++++++++++ Documentation/git-gui.txt | 5 +++++ Documentation/gitk.txt | 5 +++++ 3 files changed, 24 insertions(+), 0 deletions(-)
Documentation/config.txt +14 -0
@@ -772,6 +772,20 @@ gui.spellingdictionary:: the linkgit:git-gui[1]. When set to "none" spell checking is turned off. +gui.fastcopyblame:: + If true, 'git gui blame' uses '-C' instead of '-C -C' for original location + detection. It makes blame significantly more usable on huge repositories. + +gui.copyblamethreshold:: + Specifies the theshold to use in 'git gui blame' original location detection, + measured in alphanumeric characters. See the linkgit:git-blame[1] manual + for more information on copy detection. + +gui.blamehistoryctx:: + Specifies the radius of history context (in days) to show in gitk for + the selected commit when the corresponding context menu item is invoked. + If this parameter is zero, all history is shown. + help.browser:: Specify the browser that will be used to display help in the 'web' format. See linkgit:git-help[1].
Documentation/git-gui.txt +5 -0
@@ -65,6 +65,11 @@ git gui blame v0.99.8 Makefile:: example the file is read from the object database and not the working directory. +git gui blame --line=100 Makefile:: + + Loads annotations as described above and automatically + scrolls the view to center on line 100. + git gui citool:: Make one commit and return to the shell when it is complete.
Documentation/gitk.txt +5 -0
@@ -49,6 +49,11 @@ frequently used options. the history between two branches (i.e. the HEAD and the MERGE_HEAD) that modify the conflicted files. +--select-commit=<ref>:: + + Automatically select the specified commit after loading the graph. + Default behavior is equivalent to specifying '--select-commit=HEAD'. + <revs>:: Limit the revisions to show. This can be either a single revision
Signature · 1 line
1.6.0.rc2