MCPcopy Index your code
hub / github.com/saltstack/salt / parse_gitlog

Function parse_gitlog

tests/committer_parser.py:45–104  ·  view source on GitHub ↗

Parse out the gitlog cli data

(filename=None)

Source from the content-addressed store, hash-verified

43
44
45def 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:

Callers 1

mainFunction · 0.85

Calls 7

parse_dateFunction · 0.85
groupMethod · 0.80
openFunction · 0.50
readlinesMethod · 0.45
matchMethod · 0.45
appendMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected