Skip to content

Commit 7af9614

Browse files
committed
added support for blacklists for authors and paths
1 parent fe94d55 commit 7af9614

File tree

1 file changed

+65
-42
lines changed

1 file changed

+65
-42
lines changed

gitstats

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ conf = {
4747
'linear_linestats': 1,
4848
'project_name': '',
4949
'processes': 8,
50-
'start_date': ''
50+
'start_date': '',
51+
'excluded_authors': [],
52+
'excluded_prefixes': []
5153
}
5254

5355
def getpipeoutput(cmds, quiet = False):
@@ -322,6 +324,8 @@ class GitDataCollector(DataCollector):
322324
parts = re.split('\s+', line, 2)
323325
commits = int(parts[1])
324326
author = parts[2]
327+
if author in conf["excluded_authors"]:
328+
continue
325329
self.tags[tag]['commits'] += commits
326330
self.tags[tag]['authors'][author] = commits
327331

@@ -338,6 +342,8 @@ class GitDataCollector(DataCollector):
338342
timezone = parts[3]
339343
author, mail = parts[4].split('<', 1)
340344
author = author.rstrip()
345+
if author in conf["excluded_authors"]:
346+
continue
341347
mail = mail.rstrip('>')
342348
domain = '?'
343349
if mail.find('@') != -1:
@@ -434,14 +440,16 @@ class GitDataCollector(DataCollector):
434440
self.commits_by_timezone[timezone] = self.commits_by_timezone.get(timezone, 0) + 1
435441

436442
# outputs "<stamp> <files>" for each revision
437-
revlines = getpipeoutput(['git rev-list --pretty=format:"%%at %%T" %s' % getlogrange('HEAD'), 'grep -v ^commit']).strip().split('\n')
443+
revlines = getpipeoutput(['git rev-list --pretty=format:"%%at %%T %%an" %s' % getlogrange('HEAD'), 'grep -v ^commit']).strip().split('\n')
438444
lines = []
439445
revs_to_read = []
440446
time_rev_count = []
441447
#Look up rev in cache and take info from cache if found
442448
#If not append rev to list of rev to read from repo
443449
for revline in revlines:
444-
time, rev = revline.split(' ')
450+
time, rev, author = revline.split(' ')
451+
if author in conf["excluded_authors"]:
452+
continue
445453
#if cache empty then add time and rev to list of new rev's
446454
#otherwise try to read needed info from cache
447455
if 'files_in_tree' not in self.cache.keys():
@@ -489,6 +497,14 @@ class GitDataCollector(DataCollector):
489497
blob_id = parts[2]
490498
size = int(parts[3])
491499
fullpath = parts[4]
500+
exclude = False
501+
for path in conf["excluded_prefixes"]:
502+
if fullpath.startswith(path):
503+
exclude = True
504+
break
505+
506+
if exclude:
507+
continue
492508

493509
self.total_size += size
494510
self.total_files += 1
@@ -540,6 +556,7 @@ class GitDataCollector(DataCollector):
540556
lines.reverse()
541557
files = 0; inserted = 0; deleted = 0; total_lines = 0
542558
author = None
559+
last_line = ""
543560
for line in lines:
544561
if len(line) == 0:
545562
continue
@@ -550,35 +567,36 @@ class GitDataCollector(DataCollector):
550567
if pos != -1:
551568
try:
552569
(stamp, author) = (int(line[:pos]), line[pos+1:])
553-
self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted, 'lines': total_lines }
554-
555-
date = datetime.datetime.fromtimestamp(stamp)
556-
yymm = date.strftime('%Y-%m')
557-
self.lines_added_by_month[yymm] = self.lines_added_by_month.get(yymm, 0) + inserted
558-
self.lines_removed_by_month[yymm] = self.lines_removed_by_month.get(yymm, 0) + deleted
559-
560-
yy = date.year
561-
self.lines_added_by_year[yy] = self.lines_added_by_year.get(yy,0) + inserted
562-
self.lines_removed_by_year[yy] = self.lines_removed_by_year.get(yy, 0) + deleted
563-
564-
files, inserted, deleted = 0, 0, 0
570+
if author not in conf["excluded_authors"]:
571+
self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted, 'lines': total_lines }
572+
573+
date = datetime.datetime.fromtimestamp(stamp)
574+
yymm = date.strftime('%Y-%m')
575+
self.lines_added_by_month[yymm] = self.lines_added_by_month.get(yymm, 0) + inserted
576+
self.lines_removed_by_month[yymm] = self.lines_removed_by_month.get(yymm, 0) + deleted
577+
578+
yy = date.year
579+
self.lines_added_by_year[yy] = self.lines_added_by_year.get(yy,0) + inserted
580+
self.lines_removed_by_year[yy] = self.lines_removed_by_year.get(yy, 0) + deleted
581+
582+
files, inserted, deleted = 0, 0, 0
583+
584+
numbers = getstatsummarycounts(last_line)
585+
if len(numbers) == 3:
586+
(files, inserted, deleted) = map(lambda el : int(el), numbers)
587+
total_lines += inserted
588+
total_lines -= deleted
589+
self.total_lines_added += inserted
590+
self.total_lines_removed += deleted
591+
else:
592+
print 'Warning: failed to handle line "%s"' % line
593+
(files, inserted, deleted) = (0, 0, 0)
565594
except ValueError:
566595
print 'Warning: unexpected line "%s"' % line
567596
else:
568597
print 'Warning: unexpected line "%s"' % line
569598
else:
570-
numbers = getstatsummarycounts(line)
571-
572-
if len(numbers) == 3:
573-
(files, inserted, deleted) = map(lambda el : int(el), numbers)
574-
total_lines += inserted
575-
total_lines -= deleted
576-
self.total_lines_added += inserted
577-
self.total_lines_removed += deleted
578-
579-
else:
580-
print 'Warning: failed to handle line "%s"' % line
581-
(files, inserted, deleted) = (0, 0, 0)
599+
last_line = line
582600
#self.changes_by_date[stamp] = { 'files': files, 'ins': inserted, 'del': deleted }
583601
self.total_lines += total_lines
584602

@@ -606,21 +624,22 @@ class GitDataCollector(DataCollector):
606624
try:
607625
oldstamp = stamp
608626
(stamp, author) = (int(line[:pos]), line[pos+1:])
609-
if oldstamp > stamp:
610-
# clock skew, keep old timestamp to avoid having ugly graph
611-
stamp = oldstamp
612-
if author not in self.authors:
613-
self.authors[author] = { 'lines_added' : 0, 'lines_removed' : 0, 'commits' : 0}
614-
self.authors[author]['commits'] = self.authors[author].get('commits', 0) + 1
615-
self.authors[author]['lines_added'] = self.authors[author].get('lines_added', 0) + inserted
616-
self.authors[author]['lines_removed'] = self.authors[author].get('lines_removed', 0) + deleted
617-
if stamp not in self.changes_by_date_by_author:
618-
self.changes_by_date_by_author[stamp] = {}
619-
if author not in self.changes_by_date_by_author[stamp]:
620-
self.changes_by_date_by_author[stamp][author] = {}
621-
self.changes_by_date_by_author[stamp][author]['lines_added'] = self.authors[author]['lines_added']
622-
self.changes_by_date_by_author[stamp][author]['commits'] = self.authors[author]['commits']
623-
files, inserted, deleted = 0, 0, 0
627+
if author not in conf["excluded_authors"]:
628+
if oldstamp > stamp:
629+
# clock skew, keep old timestamp to avoid having ugly graph
630+
stamp = oldstamp
631+
if author not in self.authors:
632+
self.authors[author] = { 'lines_added' : 0, 'lines_removed' : 0, 'commits' : 0}
633+
self.authors[author]['commits'] = self.authors[author].get('commits', 0) + 1
634+
self.authors[author]['lines_added'] = self.authors[author].get('lines_added', 0) + inserted
635+
self.authors[author]['lines_removed'] = self.authors[author].get('lines_removed', 0) + deleted
636+
if stamp not in self.changes_by_date_by_author:
637+
self.changes_by_date_by_author[stamp] = {}
638+
if author not in self.changes_by_date_by_author[stamp]:
639+
self.changes_by_date_by_author[stamp][author] = {}
640+
self.changes_by_date_by_author[stamp][author]['lines_added'] = self.authors[author]['lines_added']
641+
self.changes_by_date_by_author[stamp][author]['commits'] = self.authors[author]['commits']
642+
files, inserted, deleted = 0, 0, 0
624643
except ValueError:
625644
print 'Warning: unexpected line "%s"' % line
626645
else:
@@ -644,6 +663,8 @@ class GitDataCollector(DataCollector):
644663

645664
for name in self.authors.keys():
646665
a = self.authors[name]
666+
#if a is None:
667+
# continue
647668
a['commits_frac'] = (100 * float(a['commits'])) / self.getTotalCommits()
648669
date_first = datetime.datetime.fromtimestamp(a['first_commit_stamp'])
649670
date_last = datetime.datetime.fromtimestamp(a['last_commit_stamp'])
@@ -1489,3 +1510,5 @@ if __name__=='__main__':
14891510
g = GitStats()
14901511
g.run(sys.argv[1:])
14911512

1513+
1514+
mon@open-freelancer:~/dev/go/src/openfreelancers$

0 commit comments

Comments
 (0)