75
75
__version__ = get_version (root = '..' , relative_to = __file__ )
76
76
except (ImportError , LookupError ):
77
77
__version__ = "UNKNOWN"
78
- __author__ = "Casper da Costa-Luis <casper@caspersci.uk.to >"
78
+ __author__ = "Casper da Costa-Luis <casper[email protected] >"
79
79
__date__ = "2016-2023"
80
80
__licence__ = "[MPLv2.0](https://mozilla.org/MPL/2.0/)"
81
81
__all__ = ["main" ]
107
107
108
108
def hours (dates , maxCommitDiffInSec = 120 * 60 , firstCommitAdditionInMinutes = 120 ):
109
109
"""
110
- Convert list of commit times (in seconds) to an estimate of hours spent.
110
+ Convert list of commit times (in seconds) to an estimate of hours spent.
111
111
112
- https://github.com/kimmobrunfeldt/git-hours/blob/\
112
+ https://github.com/kimmobrunfeldt/git-hours/blob/\
113
113
8aaeee237cb9d9028e7a2592a25ad8468b1f45e4/index.js#L114-L143
114
- """
114
+ """
115
115
dates = sorted (dates )
116
116
diffInSec = [i - j for (i , j ) in zip (dates [1 :], dates [:- 1 ])]
117
117
res = sum (filter (lambda i : i < maxCommitDiffInSec , diffInSec ))
@@ -121,9 +121,9 @@ def hours(dates, maxCommitDiffInSec=120 * 60, firstCommitAdditionInMinutes=120):
121
121
def tabulate (auth_stats , stats_tot , sort = 'loc' , bytype = False , backend = 'md' , cost = None ,
122
122
row_nums = False ):
123
123
"""
124
- backends : [default: md]|yaml|json|csv|tsv|tabulate|
125
- `in tabulate.tabulate_formats`
126
- """
124
+ backends : [default: md]|yaml|json|csv|tsv|tabulate|
125
+ `in tabulate.tabulate_formats`
126
+ """
127
127
COL_NAMES = ['Author' , 'loc' , 'coms' , 'fils' , ' distribution' ]
128
128
it_as = getattr (auth_stats , 'iteritems' , auth_stats .items )
129
129
# get ready
@@ -193,8 +193,8 @@ def tabulate(auth_stats, stats_tot, sort='loc', bytype=False, backend='md', cost
193
193
else :
194
194
import tabulate as tabber
195
195
if backend not in tabber .tabulate_formats :
196
- raise ValueError ("Unknown backend:%s" % backend )
197
- log .debug ("backend:tabulate:" + backend )
196
+ raise ValueError (f "Unknown backend:{ backend } " )
197
+ log .debug ("backend:tabulate:%s" , backend )
198
198
COL_LENS = [max (len (Str (i [j ])) for i in [COL_NAMES ] + tab ) for j in range (len (COL_NAMES ))]
199
199
COL_LENS [0 ] = min (TERM_WIDTH - sum (COL_LENS [1 :]) - len (COL_LENS ) * 3 - 4 , COL_LENS [0 ])
200
200
tab = [[i [0 ][:COL_LENS [0 ]]] + i [1 :] for i in tab ]
@@ -208,11 +208,10 @@ def _get_auth_stats(gitdir, branch="HEAD", since=None, include_files=None, exclu
208
208
silent_progress = False , ignore_whitespace = False , M = False , C = False ,
209
209
warn_binary = False , bytype = False , show_email = False , prefix_gitdir = False ,
210
210
churn = None , ignore_rev = "" , ignore_revs_file = None ):
211
- """Returns dict: {"<author>": {"loc": int, "files": {}, "commits": int,
212
- "ctimes": [int]}}"""
211
+ """Returns dict: {"<author>": {"loc": int, "files": {}, "commits": int, "ctimes": [int]}}"""
213
212
since = ["--since" , since ] if since else []
214
213
git_cmd = ["git" , "-C" , gitdir ]
215
- log .debug ("base command:" + ' ' .join (git_cmd ))
214
+ log .debug ("base command:%s" , ' ' .join (git_cmd ))
216
215
file_list = check_output (git_cmd + ["ls-files" , "--with-tree" , branch ]).strip ().split ('\n ' )
217
216
if not hasattr (include_files , 'search' ):
218
217
file_list = [
@@ -222,7 +221,7 @@ def _get_auth_stats(gitdir, branch="HEAD", since=None, include_files=None, exclu
222
221
file_list = [
223
222
i for i in file_list if include_files .search (i )
224
223
if not (exclude_files and exclude_files .search (i ))]
225
- log .log (logging .NOTSET , "files:\n " + '\n ' .join (file_list ))
224
+ log .log (logging .NOTSET , "files:\n %s" , '\n ' .join (file_list ))
226
225
churn = churn or set ()
227
226
228
227
if churn & CHURN_SLOC :
@@ -265,7 +264,6 @@ def stats_append(fname, auth, loc, tstamp):
265
264
if churn & CHURN_SLOC :
266
265
for fname in tqdm (file_list , desc = gitdir if prefix_gitdir else "Processing" ,
267
266
disable = silent_progress , unit = "file" ):
268
-
269
267
if prefix_gitdir :
270
268
fname = path .join (gitdir , fname )
271
269
try :
@@ -275,12 +273,12 @@ def stats_append(fname, auth, loc, tstamp):
275
273
continue
276
274
log .log (logging .NOTSET , blame_out )
277
275
278
- # Strip boundary messages,
279
- # preventing user with nearest commit to boundary owning the LOC
280
- blame_out = RE_BLAME_BOUNDS . sub ( '' , blame_out )
281
- loc_auth_times = RE_AUTHS_BLAME . findall ( blame_out )
276
+ if since :
277
+ # Strip boundary messages,
278
+ # preventing user with nearest commit to boundary owning the LOC
279
+ blame_out = RE_BLAME_BOUNDS . sub ( '' , blame_out )
282
280
283
- for loc , auth , tstamp in loc_auth_times : # for each chunk
281
+ for loc , auth , tstamp in RE_AUTHS_BLAME . findall ( blame_out ) : # for each chunk
284
282
loc = int (loc )
285
283
stats_append (fname , auth , loc , tstamp )
286
284
@@ -312,7 +310,7 @@ def stats_append(fname, auth, loc, tstamp):
312
310
stats_append (fname , auth , loc , tstamp )
313
311
314
312
# quickly count commits (even if no surviving loc)
315
- log .log (logging .NOTSET , "authors:" + '; ' .join (auth_stats .keys ()))
313
+ log .log (logging .NOTSET , "authors:%s" , '; ' .join (auth_stats .keys ()))
316
314
auth_commits = check_output (git_cmd + ["shortlog" , "-s" , "-e" , branch ] + since )
317
315
for stats in auth_stats .values ():
318
316
stats .setdefault ("commits" , 0 )
@@ -347,7 +345,7 @@ def run(args):
347
345
log .debug ("parsing args" )
348
346
349
347
if args .sort not in "loc commits files hours months" .split ():
350
- log .warning ("--sort argument (%s) unrecognised\n %s" % ( args .sort , __doc__ ) )
348
+ log .warning ("--sort argument (%s) unrecognised\n %s" , args .sort , __doc__ )
351
349
raise KeyError (args .sort )
352
350
353
351
if not args .excl :
@@ -481,7 +479,7 @@ def main(args=None):
481
479
fi = resource_filename (__name__ , 'git-fame.1' )
482
480
fo = path .join (args .manpath , 'git-fame.1' )
483
481
copyfile (fi , fo )
484
- log .info ("written:" + fo )
482
+ log .info ("written:%s" , fo )
485
483
sys .exit (0 )
486
484
487
485
run (args )
0 commit comments