Skip to content

Commit

Permalink
feat: add c2fbb, (o)bb2cf and other maps to oop api
Browse files Browse the repository at this point in the history
  • Loading branch information
hrz6976 committed Jun 8, 2024
1 parent cd82464 commit 1425b11
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 8 deletions.
71 changes: 64 additions & 7 deletions woc/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def hash(self) -> str:
return hex(hash(self))[2:]

def _get_list_values(self, map_name: str):
""" A thin wrapper around WocMapsBase.get_values to handle KeyError """
try:
return self.woc.get_values(map_name, self.key)
except KeyError:
Expand Down Expand Up @@ -134,24 +135,45 @@ def email(self) -> str:

@cached_property
def blobs(self) -> 'List[Blob]':
return [Blob(b) for b in self._get_list_values('a2b')]
return [Blob(b) for b in self._get_list_values(f'{self.ident}2b')]

@cached_property
def commits(self) -> 'List[Commit]':
return [Commit(c) for c in self._get_list_values('a2c')]
return [Commit(c) for c in self._get_list_values(f'{self.ident}2c')]

@cached_property
def files(self) -> 'List[File]':
return [File(f) for f in self._get_list_values('a2f')]
return [File(f) for f in self._get_list_values(f'{self.ident}2f')]

@cached_property
def projects(self) -> 'List[Project]':
return [Project(p) for p in self._get_list_values('a2p')]
return [Project(p) for p in self._get_list_values(f'{self.ident}2p')]

@cached_property
def unique_authors(self) -> List['UniqueAuthor']:
return [UniqueAuthor(a) for a in self._get_list_values(f'{self.ident}2A')]

@property
def authors(self):
raise NotImplementedError("Author object does not have authors method")

@cached_property
def first_blobs(self) -> List['Blob']:
return [Blob(b) for b in self._get_list_values(f'{self.ident}2fb')]


class UniqueAuthor(Author):
ident = 'A'
pass

@property
def unique_authors(self) -> 'List[Author]':
raise NotImplementedError("UniqueAuthor object does not have unique_authors method")

@cached_property
def authors(self) -> 'List[Author]':
return [Author(a) for a in self._get_list_values(f'{self.ident}2a')]




class Blob(_GitObject):
Expand Down Expand Up @@ -195,7 +217,20 @@ def files(self) -> 'List[File]':
@cached_property
def projects_unique(self) -> 'List[RootProject]':
return [RootProject(p) for p in self._get_list_values('b2P')]


@cached_property
def changed_from(self) -> 'List[Tuple[Blob, Commit, File]]':
return [
(Blob(b), Commit(c), File(f))
for b, c, f in self._get_list_values('bb2cf')
]

@cached_property
def changed_to(self) -> 'List[Tuple[Blob, Commit, File]]':
return [
(Blob(b), Commit(c), File(f))
for b, c, f in self._get_list_values('obb2cf')
]

class Commit(_GitObject):
ident = 'c'
Expand Down Expand Up @@ -248,13 +283,19 @@ def _parent_shas(self) -> List[str]:

@property
def parents(self) -> List['Commit']:
"""Parent commits of this commit"""
return [Commit(p) for p in self.data_obj['parent']]

@cached_property
def projects(self) -> List['Project']:
"""Projects associated with this commit"""
return [Project(p) for p in self._get_list_values('c2p')]

@cached_property
def root_projects(self) -> List['RootProject']:
"""Root projects associated with this commit"""
return [RootProject(p) for p in self._get_list_values('c2P')]

@cached_property
def children(self) -> List['Commit']:
"""Children of this commit"""
Expand Down Expand Up @@ -303,6 +344,14 @@ def root(self) -> 'Tuple[Commit, int]':
sha, dis = self.woc.get_values('c2r', self.key)
return Commit(sha), int(dis)

@cached_property
def changeset(self) -> 'List[Tuple[File, Blob, Blob]]':
"""Returns changed files, their new and old blobs"""
return [
(File(f), Blob(new), Blob(old))
for f, new, old in self._get_list_values('c2fbb')
]

def compare(
self,
parent: Union['Commit', str],
Expand Down Expand Up @@ -656,6 +705,10 @@ def __iter__(self) -> 'Generator[Commit, None, None]':
yield c
except KeyError:
pass

@property
def projects(self) -> List['Project']:
raise NotImplementedError("Project object does not have projects method")

class RootProject(Project):
ident = 'P'
Expand All @@ -670,4 +723,8 @@ def commits(self) -> 'List[Commit]':

@cached_property
def projects(self) -> 'List[Project]':
return [Project(p) for p in self._get_list_values(f'{self.ident}2p')]
return [Project(p) for p in self._get_list_values(f'{self.ident}2p')]

@property
def root_projects(self) -> List['RootProject']:
raise NotImplementedError("RootProject object does not have root_projects method")
5 changes: 4 additions & 1 deletion woc/wocprofile.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"dat": "colon_seperated_data",
"tch": "compressed_data",
"bin": "binary_data",
"idx": "binary_index"
"idx": "binary_index",
"bb": "new_blob",
"obb": "old_blob",
"fb": "first_blob"
},
"dtypes": {
"h": "hex",
Expand Down

0 comments on commit 1425b11

Please sign in to comment.