Parse out the gitlog cli data
(filename=None)
| 43 | |
| 44 | |
| 45 | def parse_gitlog(filename=None): |
| 46 | """ |
| 47 | Parse out the gitlog cli data |
| 48 | """ |
| 49 | results = {} |
| 50 | commits = {} |
| 51 | commits_by_contributor = {} |
| 52 | |
| 53 | if not filename or filename == "-": |
| 54 | fh = sys.stdin |
| 55 | else: |
| 56 | fh = open(filename, "r+", encoding="utf-8") |
| 57 | |
| 58 | try: |
| 59 | commitcount = 0 |
| 60 | for line in fh.readlines(): |
| 61 | line = line.rstrip() |
| 62 | if line.startswith("commit "): |
| 63 | new_commit = True |
| 64 | commitcount += 1 |
| 65 | continue |
| 66 | |
| 67 | if line.startswith("Author:"): |
| 68 | author = re.match(r"Author:\s+(.*)\s+<(.*)>", line) |
| 69 | if author: |
| 70 | email = author.group(2) |
| 71 | continue |
| 72 | |
| 73 | if line.startswith("Date:"): |
| 74 | |
| 75 | isodate = re.match(r"Date:\s+(.*)", line) |
| 76 | d = parse_date(isodate.group(1)) |
| 77 | continue |
| 78 | |
| 79 | if len(line) < 2 and new_commit: |
| 80 | new_commit = False |
| 81 | key = f"{d.year}-{str(d.month).zfill(2)}" |
| 82 | |
| 83 | if key not in results: |
| 84 | results[key] = [] |
| 85 | |
| 86 | if key not in commits: |
| 87 | commits[key] = 0 |
| 88 | |
| 89 | if email not in commits_by_contributor: |
| 90 | commits_by_contributor[email] = {} |
| 91 | |
| 92 | if key not in commits_by_contributor[email]: |
| 93 | commits_by_contributor[email][key] = 1 |
| 94 | else: |
| 95 | commits_by_contributor[email][key] += 1 |
| 96 | |
| 97 | if email not in results[key]: |
| 98 | results[key].append(email) |
| 99 | |
| 100 | commits[key] += commitcount |
| 101 | commitcount = 0 |
| 102 | finally: |