@matheusbsbs / matheus-bagliano / commits / a01fe996a2
Fork 0

Add a menu item to invoke full copy detection in blame.

Add a context menu item to invoke blame -C -C -C on a chunk of the file. The results are used to update the 'original location' column of the blame display. The chunk is computed as the smallest line range that covers both the 'last change' and 'original location' ranges of the line that was clicked to open the menu. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Alexander Gavrilov committed Jul 17, 2008 at 00:51 UTC a01fe996a2f70b759b4d94bd3e9985a01d514ad7
1 file changed +69
lib/blame.tcl
+69
@@ -256,6 +256,9 @@ constructor new {i_commit i_path} {
256 $w.ctxm add command \
257 -label [mc "Copy Commit"] \
258 -command [cb _copycommit]
259 + $w.ctxm add command \
260 + -label [mc "Do Full Copy Detection"] \
261 + -command [cb _fullcopyblame]
262
263 foreach i $w_columns {
264 for {set g 0} {$g < [llength $group_colors]} {incr g} {
@@ -708,6 +711,72 @@ method _read_blame {fd cur_w cur_d} {
711 }
712 } ifdeleted { catch {close $fd} }
713
714 +method _find_commit_bound {data_list start_idx delta} {
715 + upvar #0 $data_list line_data
716 + set pos $start_idx
717 + set limit [expr {[llength $line_data] - 1}]
718 + set base_commit [lindex $line_data $pos 0]
719 +
720 + while {$pos > 0 && $pos < $limit} {
721 + set new_pos [expr {$pos + $delta}]
722 + if {[lindex $line_data $new_pos 0] ne $base_commit} {
723 + return $pos
724 + }
725 +
726 + set pos $new_pos
727 + }
728 +
729 + return $pos
730 +}
731 +
732 +method _fullcopyblame {} {
733 + if {$current_fd ne {}} {
734 + tk_messageBox \
735 + -icon error \
736 + -type ok \
737 + -title [mc "Busy"] \
738 + -message [mc "Annotation process is already running."]
739 +
740 + return
741 + }
742 +
743 + # Switches for original location detection
744 + set threshold [get_config gui.copyblamethreshold]
745 + set original_options [list -C -C "-C$threshold"]
746 +
747 + if {[git-version >= 1.5.3]} {
748 + lappend original_options -w ; # ignore indentation changes
749 + }
750 +
751 + # Find the line range
752 + set pos @$::cursorX,$::cursorY
753 + set lno [lindex [split [$::cursorW index $pos] .] 0]
754 + set min_amov_lno [_find_commit_bound $this @amov_data $lno -1]
755 + set max_amov_lno [_find_commit_bound $this @amov_data $lno 1]
756 + set min_asim_lno [_find_commit_bound $this @asim_data $lno -1]
757 + set max_asim_lno [_find_commit_bound $this @asim_data $lno 1]
758 +
759 + if {$min_asim_lno < $min_amov_lno} {
760 + set min_amov_lno $min_asim_lno
761 + }
762 +
763 + if {$max_asim_lno > $max_amov_lno} {
764 + set max_amov_lno $max_asim_lno
765 + }
766 +
767 + lappend original_options -L "$min_amov_lno,$max_amov_lno"
768 +
769 + # Clear lines
770 + for {set i $min_amov_lno} {$i <= $max_amov_lno} {incr i} {
771 + lset amov_data $i [list ]
772 + }
773 +
774 + # Start the back-end process
775 + _exec_blame $this $w_amov @amov_data \
776 + $original_options \
777 + [mc "Running thorough copy detection..."]
778 +}
779 +
780 method _click {cur_w pos} {
781 set lno [lindex [split [$cur_w index $pos] .] 0]
782 _showcommit $this $cur_w $lno