Skip to content

Commit 383d4e0

Browse files
committed
git-gui: Display both commits in our tooltips
If we have commit data from both the simple blame and the rename/move tracking blame and they differ than there is a bigger story to tell. We now include data from both commits so that the user can see that this link as moved, who moved it, and where it originated from. Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 172c92b commit 383d4e0

File tree

1 file changed

+72
-58
lines changed

1 file changed

+72
-58
lines changed

lib/blame.tcl

Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ field r_final_line ; # final line number
5656
field r_line_count ; # lines in this region
5757

5858
field tooltip_wm {} ; # Current tooltip toplevel, if open
59+
field tooltip_t {} ; # Text widget in $tooltip_wm
5960
field tooltip_timer {} ; # Current timer event for our tooltip
60-
field tooltip_commit {} ; # Commit in tooltip
61-
field tooltip_text {} ; # Text in current tooltip
61+
field tooltip_commit {} ; # Commit(s) in tooltip
6262

6363
constructor new {i_commit i_path} {
6464
global cursor_ptr
@@ -653,6 +653,7 @@ method _showcommit {cur_w lno} {
653653
if {$highlight_commit ne {}} {
654654
foreach i $w_columns {
655655
$i tag conf g$highlight_commit -background $old_bgcolor
656+
$i tag lower g$highlight_commit
656657
}
657658
}
658659

@@ -677,6 +678,7 @@ method _showcommit {cur_w lno} {
677678
set old_bgcolor [$w_file tag cget g$cmit -background]
678679
foreach i $w_columns {
679680
$i tag conf g$cmit -background $active_color
681+
$i tag raise g$cmit
680682
}
681683

682684
set author_name {}
@@ -746,7 +748,7 @@ method _showcommit {cur_w lno} {
746748
set highlight_line $lno
747749
set highlight_commit $cmit
748750

749-
if {$highlight_commit eq $tooltip_commit} {
751+
if {[lsearch -exact $tooltip_commit $highlight_commit] != -1} {
750752
_hide_tooltip $this
751753
}
752754
}
@@ -765,26 +767,7 @@ method _copycommit {} {
765767
}
766768

767769
method _show_tooltip {cur_w pos} {
768-
set lno [lindex [split [$cur_w index $pos] .] 0]
769-
if {$cur_w eq $w_amov} {
770-
set dat [lindex $amov_data $lno]
771-
} else {
772-
set dat [lindex $asim_data $lno]
773-
}
774-
if {$dat eq {}} {
775-
_hide_tooltip $this
776-
return
777-
}
778-
set cmit [lindex $dat 0]
779-
780-
if {$cmit eq $highlight_commit} {
781-
_hide_tooltip $this
782-
return
783-
}
784-
785-
if {$cmit eq $tooltip_commit} {
786-
_position_tooltip $this
787-
} elseif {$tooltip_wm ne {}} {
770+
if {$tooltip_wm ne {}} {
788771
_open_tooltip $this $cur_w
789772
} elseif {$tooltip_timer eq {}} {
790773
set tooltip_timer [after 1000 [cb _open_tooltip $cur_w]]
@@ -800,70 +783,101 @@ method _open_tooltip {cur_w} {
800783
return
801784
}
802785

786+
if {$tooltip_wm ne "$cur_w.tooltip"} {
787+
_hide_tooltip $this
788+
789+
set tooltip_wm [toplevel $cur_w.tooltip -borderwidth 1]
790+
wm overrideredirect $tooltip_wm 1
791+
wm transient $tooltip_wm [winfo toplevel $cur_w]
792+
set tooltip_t $tooltip_wm.label
793+
text $tooltip_t \
794+
-takefocus 0 \
795+
-highlightthickness 0 \
796+
-relief flat \
797+
-borderwidth 0 \
798+
-wrap none \
799+
-background lightyellow \
800+
-foreground black
801+
$tooltip_t tag conf section_header -font font_uibold
802+
pack $tooltip_t
803+
} else {
804+
$tooltip_t conf -state normal
805+
$tooltip_t delete 0.0 end
806+
}
807+
803808
set pos @[join [list \
804809
[expr {$pos_x - [winfo rootx $cur_w]}] \
805810
[expr {$pos_y - [winfo rooty $cur_w]}]] ,]
806811
set lno [lindex [split [$cur_w index $pos] .] 0]
807812
if {$cur_w eq $w_amov} {
808813
set dat [lindex $amov_data $lno]
814+
set org {}
809815
} else {
810816
set dat [lindex $asim_data $lno]
817+
set org [lindex $amov_data $lno]
811818
}
819+
812820
set cmit [lindex $dat 0]
813-
set file [lindex $dat 1]
821+
set tooltip_commit [list $cmit]
814822

815823
set author_name {}
816-
set author_email {}
824+
set summary {}
817825
set author_time {}
818826
catch {set author_name $header($cmit,author)}
819-
catch {set author_email $header($cmit,author-mail)}
827+
catch {set summary $header($cmit,summary)}
820828
catch {set author_time [clock format \
821829
$header($cmit,author-time) \
822830
-format {%Y-%m-%d %H:%M:%S}
823831
]}
824832

825-
set committer_name {}
826-
set committer_email {}
827-
set committer_time {}
828-
catch {set committer_name $header($cmit,committer)}
829-
catch {set committer_email $header($cmit,committer-mail)}
830-
catch {set committer_time [clock format \
831-
$header($cmit,committer-time) \
832-
-format {%Y-%m-%d %H:%M:%S}
833-
]}
833+
$tooltip_t insert end "commit $cmit\n"
834+
$tooltip_t insert end "$author_name $author_time\n"
835+
$tooltip_t insert end "$summary"
834836

835-
set summary {}
836-
catch {set summary $header($cmit,summary)}
837+
if {$org ne {} && [lindex $org 0] ne $cmit} {
838+
$tooltip_t insert 0.0 "Moved Here By:\n" section_header
839+
set cmit [lindex $org 0]
840+
set file [lindex $org 1]
841+
lappend tooltip_commit $cmit
837842

838-
set tooltip_commit $cmit
839-
set tooltip_text "commit $cmit
840-
$author_name $author_email $author_time
841-
$summary"
843+
set author_name {}
844+
set summary {}
845+
set author_time {}
846+
catch {set author_name $header($cmit,author)}
847+
catch {set summary $header($cmit,summary)}
848+
catch {set author_time [clock format \
849+
$header($cmit,author-time) \
850+
-format {%Y-%m-%d %H:%M:%S}
851+
]}
842852

843-
if {$file ne $path} {
844-
append tooltip_text "
853+
$tooltip_t insert end "\n\n"
854+
$tooltip_t insert end "Originally By:\n" section_header
855+
$tooltip_t insert end "commit $cmit\n"
856+
$tooltip_t insert end "$author_name $author_time\n"
857+
$tooltip_t insert end "$summary"
845858

846-
Original File: $file"
859+
if {$file ne $path} {
860+
$tooltip_t insert end "\n"
861+
$tooltip_t insert end "File: " section_header
862+
$tooltip_t insert end $file
863+
}
847864
}
848865

849-
if {$tooltip_wm ne "$cur_w.tooltip"} {
850-
_hide_tooltip $this
851-
852-
set tooltip_wm [toplevel $cur_w.tooltip -borderwidth 1]
853-
wm overrideredirect $tooltip_wm 1
854-
wm transient $tooltip_wm [winfo toplevel $cur_w]
855-
pack [label $tooltip_wm.label \
856-
-background lightyellow \
857-
-foreground black \
858-
-textvariable @tooltip_text \
859-
-justify left]
860-
}
866+
$tooltip_t conf -state disabled
861867
_position_tooltip $this
862868
}
863869

864870
method _position_tooltip {} {
865-
set req_w [winfo reqwidth $tooltip_wm.label]
866-
set req_h [winfo reqheight $tooltip_wm.label]
871+
set max_h [lindex [split [$tooltip_t index end] .] 0]
872+
set max_w 0
873+
for {set i 1} {$i <= $max_h} {incr i} {
874+
set c [lindex [split [$tooltip_t index "$i.0 lineend"] .] 1]
875+
if {$c > $max_w} {set max_w $c}
876+
}
877+
$tooltip_t conf -width $max_w -height $max_h
878+
879+
set req_w [winfo reqwidth $tooltip_t]
880+
set req_h [winfo reqheight $tooltip_t]
867881
set pos_x [expr {[winfo pointerx .] + 5}]
868882
set pos_y [expr {[winfo pointery .] + 10}]
869883

0 commit comments

Comments
 (0)