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

git-gui: Add a 4 digit commit abbreviation to the blame viewer

We now show the first 4 digits of each commit in the left most column of our blame viewer, before the line numbers. These are drawn as the data becomes available from git-blame --incremental, and helps the user to visually group lines together. I'm using only the first 4 digits because within a given cluster of lines its unlikely that two neighboring commits will have the same 4 digit prefix. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed May 31, 2007 at 23:58 UTC a46fe1c1c0007fbbe0c196e7cc0db89567a8eae0
1 file changed +40 -2
lib/blame.tcl
+40 -2
@@ -8,6 +8,7 @@ field path ; # input filename to view in $commit
8
9 field w
10 field w_line
11 +field w_cgrp
12 field w_load
13 field w_file
14 field w_cmit
@@ -65,6 +66,14 @@ constructor new {i_commit i_path} {
66 -font font_diff
67 $w.out.linenumber_t tag conf linenumber -justify right
68
69 + text $w.out.commit_t \
70 + -background white -borderwidth 0 \
71 + -state disabled \
72 + -wrap none \
73 + -height 40 \
74 + -width 4 \
75 + -font font_diff
76 +
77 text $w.out.file_t \
78 -background white -borderwidth 0 \
79 -state disabled \
@@ -79,16 +88,18 @@ constructor new {i_commit i_path} {
88 -command [list scrollbar2many [list \
89 $w.out.loaded_t \
90 $w.out.linenumber_t \
91 + $w.out.commit_t \
92 $w.out.file_t \
93 ] yview]
94 grid \
95 + $w.out.commit_t \
96 $w.out.linenumber_t \
97 $w.out.loaded_t \
98 $w.out.file_t \
99 $w.out.sby \
100 -sticky nsew
90 - grid conf $w.out.sbx -column 2 -sticky we
91 - grid columnconfigure $w.out 2 -weight 1
101 + grid conf $w.out.sbx -column 3 -sticky we
102 + grid columnconfigure $w.out 3 -weight 1
103 grid rowconfigure $w.out 0 -weight 1
104 pack $w.out -fill both -expand 1
105
@@ -123,11 +134,13 @@ constructor new {i_commit i_path} {
134 -command [cb _copycommit]
135
136 set w_line $w.out.linenumber_t
137 + set w_cgrp $w.out.commit_t
138 set w_load $w.out.loaded_t
139 set w_file $w.out.file_t
140 set w_cmit $w.cm.t
141
142 foreach i [list \
143 + $w.out.commit_t \
144 $w.out.loaded_t \
145 $w.out.linenumber_t \
146 $w.out.file_t] {
@@ -136,6 +149,7 @@ constructor new {i_commit i_path} {
149 -foreground [$i cget -background]
150 $i conf -yscrollcommand \
151 [list many2scrollbar [list \
152 + $w.out.commit_t \
153 $w.out.loaded_t \
154 $w.out.linenumber_t \
155 $w.out.file_t \
@@ -150,6 +164,7 @@ constructor new {i_commit i_path} {
164 }
165
166 foreach i [list \
167 + $w.out.commit_t \
168 $w.out.loaded_t \
169 $w.out.linenumber_t \
170 $w.out.file_t \
@@ -182,16 +197,20 @@ constructor new {i_commit i_path} {
197
198 method _read_file {fd} {
199 $w_load conf -state normal
200 + $w_cgrp conf -state normal
201 $w_line conf -state normal
202 $w_file conf -state normal
203 while {[gets $fd line] >= 0} {
204 regsub "\r\$" $line {} line
205 incr total_lines
206 +
207 $w_load insert end "\n"
208 + $w_cgrp insert end "\n"
209 $w_line insert end "$total_lines\n" linenumber
210 $w_file insert end "$line\n"
211 }
212 $w_load conf -state disabled
213 + $w_cgrp conf -state disabled
214 $w_line conf -state disabled
215 $w_file conf -state disabled
216
@@ -212,6 +231,7 @@ method _read_file {fd} {
231 } ifdeleted { catch {close $fd} }
232
233 method _read_blame {fd} {
234 + $w_cgrp conf -state normal
235 while {[gets $fd line] >= 0} {
236 if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
237 cmit original_line final_line line_count]} {
@@ -221,10 +241,14 @@ method _read_blame {fd} {
241 set r_line_count $line_count
242
243 if {[catch {set g $order($cmit)}]} {
244 + $w_cgrp tag conf g$cmit
245 $w_line tag conf g$cmit
246 $w_file tag conf g$cmit
247 +
248 + $w_cgrp tag raise in_sel
249 $w_line tag raise in_sel
250 $w_file tag raise in_sel
251 +
252 $w_file tag raise sel
253 set order($cmit) $commit_count
254 incr commit_count
@@ -235,18 +259,25 @@ method _read_blame {fd} {
259 set n $r_line_count
260 set lno $r_final_line
261 set cmit $r_commit
262 + set abbr [string range $cmit 0 4]
263
264 while {$n > 0} {
265 set lno_e "$lno.0 lineend + 1c"
266 if {[catch {set g g$line_commit($lno)}]} {
267 $w_load tag add annotated $lno.0 $lno_e
268 } else {
269 + $w_cgrp tag remove g$g $lno.0 $lno_e
270 $w_line tag remove g$g $lno.0 $lno_e
271 $w_file tag remove g$g $lno.0 $lno_e
272 }
273
274 set line_commit($lno) $cmit
275 set line_file($lno) $file
276 +
277 + $w_cgrp delete $lno.0 $lno_e
278 + $w_cgrp insert $lno.0 "$abbr\n"
279 +
280 + $w_cgrp tag add g$cmit $lno.0 $lno_e
281 $w_line tag add g$cmit $lno.0 $lno_e
282 $w_file tag add g$cmit $lno.0 $lno_e
283
@@ -273,6 +304,7 @@ method _read_blame {fd} {
304 set header($r_commit,$key) $data
305 }
306 }
307 + $w_cgrp conf -state disabled
308
309 if {[eof $fd]} {
310 close $fd
@@ -298,8 +330,12 @@ method _click {cur_w pos} {
330 if {$lno eq {}} return
331
332 set lno_e "$lno.0 + 1 line"
333 +
334 + $w_cgrp tag remove in_sel 0.0 end
335 $w_line tag remove in_sel 0.0 end
336 $w_file tag remove in_sel 0.0 end
337 +
338 + $w_cgrp tag add in_sel $lno.0 $lno_e
339 $w_line tag add in_sel $lno.0 $lno_e
340 $w_file tag add in_sel $lno.0 $lno_e
341
@@ -321,6 +357,7 @@ method _showcommit {lno} {
357 set i 0
358 foreach c $blame_colors {
359 set h [lindex $commit_list [expr {$idx - 1 + $i}]]
360 + $w_cgrp tag conf g$h -background white
361 $w_line tag conf g$h -background white
362 $w_file tag conf g$h -background white
363 incr i
@@ -337,6 +374,7 @@ method _showcommit {lno} {
374 set i 0
375 foreach c $blame_colors {
376 set h [lindex $commit_list [expr {$idx - 1 + $i}]]
377 + $w_cgrp tag conf g$h -background $c
378 $w_line tag conf g$h -background $c
379 $w_file tag conf g$h -background $c
380 incr i