@@ -25,46 +25,48 @@ def get_authors(self, path):
2525 if authors == False :
2626 return []
2727
28- if not authors :
29- try :
30- blame = self .repo .blame ('HEAD' ,path )
31- except :
32- logging .warning ("%s has no commits" % path )
33- self ._authors [path ] = False
34- return []
35-
36- if len (Path (path ).read_text ()) == 0 :
37- logging .warning ("%s has no lines" % path )
38- self ._authors [path ] = False
39- return []
40-
41- authors = {}
42- for commit , lines in blame :
43- key = commit .author .email
44-
45- # Update existing author
46- if authors .get (key ):
47- authors [key ]['lines' ] = authors [key ]['lines' ] + len (lines )
48- current_dt = authors .get (key ,{}).get ('last_datetime' )
49- if commit .committed_datetime > current_dt :
50- authors [key ]['last_datetime' ] = commit .committed_datetime
51- # Add new author
52- else :
53- authors [key ] = {
54- 'name' : commit .author .name ,
55- 'email' : key ,
56- 'last_datetime' : commit .committed_datetime ,
57- 'lines' : len (lines )
58- }
59-
60- authors = [authors [key ] for key in authors ]
61- authors = sorted (authors , key = lambda i : i ['name' ])
62-
63- total_lines = sum ([x .get ('lines' ) for x in authors ])
64- for author in authors :
65- author ['contribution' ] = self ._format_perc (author ['lines' ] / total_lines )
66-
67- self ._authors [path ] = authors
28+ if authors :
29+ return authors
30+
31+ try :
32+ blame = self .repo .blame ('HEAD' ,path )
33+ except :
34+ logging .warning ("%s has no commits" % path )
35+ self ._authors [path ] = False
36+ return []
37+
38+ if len (Path (path ).read_text ()) == 0 :
39+ logging .warning ("%s has no lines" % path )
40+ self ._authors [path ] = False
41+ return []
42+
43+ authors = {}
44+ for commit , lines in blame :
45+ key = commit .author .email
46+
47+ # Update existing author
48+ if authors .get (key ):
49+ authors [key ]['lines' ] = authors [key ]['lines' ] + len (lines )
50+ current_dt = authors .get (key ,{}).get ('last_datetime' )
51+ if commit .committed_datetime > current_dt :
52+ authors [key ]['last_datetime' ] = commit .committed_datetime
53+ # Add new author
54+ else :
55+ authors [key ] = {
56+ 'name' : commit .author .name ,
57+ 'email' : key ,
58+ 'last_datetime' : commit .committed_datetime ,
59+ 'lines' : len (lines )
60+ }
61+
62+ authors = [authors [key ] for key in authors ]
63+ authors = sorted (authors , key = lambda i : i ['name' ])
64+
65+ total_lines = sum ([x .get ('lines' ) for x in authors ])
66+ for author in authors :
67+ author ['contribution' ] = self ._format_perc (author ['lines' ] / total_lines )
68+
69+ self ._authors [path ] = authors
6870
6971 return authors
7072
0 commit comments