Skip to content

Commit f6f2aa3

Browse files
committed
git-gui: Brown paper bag fix division by 0 in blame
If we generate a blame status string before we have obtained any annotation data at all from the input file, or if the input file is empty, our total_lines will be 0. This causes a division by 0 error when we blindly divide by the 0 to compute the total percentage of lines loaded. Instead we should report 0% done. Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 2ec0cb7 commit f6f2aa3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

git-gui.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3604,12 +3604,14 @@ proc read_blame_incremental {fd w w_load w_cmit w_line w_file} {
36043604
proc blame_incremental_status {w} {
36053605
global blame_status blame_data
36063606

3607+
set have $blame_data($w,blame_lines)
3608+
set total $blame_data($w,total_lines)
3609+
set pdone 0
3610+
if {$total} {set pdone [expr {100 * $have / $total}]}
3611+
36073612
set blame_status($w) [format \
36083613
"Loading annotations... %i of %i lines annotated (%2i%%)" \
3609-
$blame_data($w,blame_lines) \
3610-
$blame_data($w,total_lines) \
3611-
[expr {100 * $blame_data($w,blame_lines)
3612-
/ $blame_data($w,total_lines)}]]
3614+
$have $total $pdone]
36133615
}
36143616

36153617
proc blame_click {w w_cmit w_line w_file cur_w pos} {

0 commit comments

Comments
 (0)