def of(log: str): log_list = log.split("\n") _hash = log_list[0] subject = log_list[2] date = datetime.strptime(log_list[1][:-6], "%Y-%m-%dT%H:%M:%S") author = Mailmap.get_or_default(log_list[3], log_list[4], date) committer = Mailmap.get_or_default(log_list[5], log_list[6]) diffstats = [Diffstat.of(diffstat) for diffstat in log_list[8:-1]] return Commit(_hash, subject, author, committer, date, diffstats)
def count_reviews(numstat: List[Numstat], reviewer_regex: str) -> Tuple[List[str], List[List]]: """ :param numstat: result of :func: git_log_numstat_no_merge :param reviewer_regex: regular expression pattern :return: list of [, author1, author2, ...], [reviewer1, count, count, ...] [reviewer2, count, count, ...], ... """ logging.info("counting reviews (reviewer_regex=%s)" % reviewer_regex) authors = set() reviewer_author_reviews = defaultdict(lambda: defaultdict(int)) numstat = __unique_by(numstat, "hash") for n in numstat: reviewers = re.findall(reviewer_regex, n.subject) for reviewer in reviewers: reviewer = Mailmap.instance().get_by_username(reviewer) reviewer_author_reviews[reviewer][n.author] += 1 authors.add(n.author) authors = sorted(authors) header = [" ┌─> author\nreviewer"] header.extend(authors) data = list() for reviewer in sorted(reviewer_author_reviews.keys()): data.append( [reviewer] + list(map(lambda a: reviewer_author_reviews[reviewer][a], authors))) return header, data
def raw_line_to_ref(line: str) -> List: raw_ref = line.split(".:*-*:.") date = datetime.strptime(raw_ref[0], "%Y-%m-%d %H:%M:%S %z") name = raw_ref[1] email = raw_ref[2][1:-1] branch = raw_ref[3] author = Mailmap.get_or_default(name, email) return [date, author, branch]
def of(raw_git_blame): _hash = None author = Author("", "", "") committer = Author("", "", "") summary = None filename = None content = None for line in raw_git_blame.split("\n"): if line.startswith("author ") and len(author.name) == 0: author.name = line[7:] elif line.startswith("author-mail ") and len(author.email) == 0: email = line[13:-1].lower() author = Mailmap.get_or_default(author.name, email) elif line.startswith("committer ") and len(committer.name) == 0: committer.name = line[10:] elif line.startswith("committer-mail ") and len(committer.email) == 0: email = line[16:-1].lower() committer.email = Mailmap.get_or_default(committer.name, email) elif line.startswith("summary "): summary = line[8:] elif line.startswith("filename "): filename = line[9:] elif line.startswith("\t"): content = line[1:] elif re.match(r".{,40} \d+ \d+", line): _hash = line[:40] return Blame(_hash, author, committer, summary, filename, content)
def __print_cemetery(self): print(self.__formatter.section()) print( self.__formatter. h2("Cemetery (it happens to the best of us: authors not active for over a year)" )) dead = sorted(set( filter(lambda x: not x.is_active(), Mailmap.instance().authors_by_email.values())), key=lambda d: d.end) header = replace_author_row(dead) data = list( map( lambda d: "%s - %s" % (d.start.strftime("%d/%m/%Y"), d.end.strftime("%d/%m/%Y")), dead)) print( self.__formatter.table( header, [data], md="|%s|" % "|".join([":---:"] * len(header)))) # gravestone print(self.__formatter.section())
def load_numstat() -> List[Numstat]: Mailmap.instance().authors_by_email = __load("authors_by_email.pkl") return __load("numstat.pkl")
def dump_numstat(numstat: List[Numstat]): __dump(numstat, "numstat.pkl") __dump(Mailmap.instance().authors_by_email, "authors_by_email.pkl")
def __raw_short_log_to_short_log(short_log_match) -> Dict: name = short_log_match.group(2) email = short_log_match.group(3).lower() commits = int(short_log_match.group(1)) author = Mailmap.get_or_default(name, email) return {"author": author, "commits": commits}