-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_wrapper.py
More file actions
69 lines (48 loc) · 1.57 KB
/
git_wrapper.py
File metadata and controls
69 lines (48 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
from git import Commit, Actor, Repo
import git.types
from gitdb.db.loose import LooseObjectDB
from git.db import GitCmdObjectDB
from typing import Iterator
class GitActor(Actor):
commits: int = 0
def __init__(
self,
name: str | None,
email: str | None,
commits: int = 0
) -> None:
super().__init__(
name=name,
email=email
)
self.commits = commits
@staticmethod
def from_actor(actor: Actor, commits: int = 0):
return GitActor(
name=actor.name,
email=actor.email,
commits=commits
)
class GitRepo(Repo):
name: str
commits: list[Commit] = []
authors: set[GitActor]
def __init__(
self,
path: git.types.PathLike | None = None,
odbt: type[LooseObjectDB] = GitCmdObjectDB,
search_parent_directories: bool = False,
expand_vars: bool = True
) -> None:
super().__init__(
path=path,
odbt=odbt,
search_parent_directories=search_parent_directories,
expand_vars=expand_vars
)
# obtain info once for reuse
self.name = os.path.basename(self.working_dir)
self.commits = list(self.iter_commits("--all"))
_authors = set( commit.author for commit in self.commits.copy() )
self.authors = set(map(lambda author: GitActor.from_actor(actor=author, commits=[commit.author for commit in self.commits].count(author)), list(_authors)))