Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 290 Lines • ▼ Show 20 Lines | class RevisionType(Enum): | ||||
MERCURIAL = 'hg' | MERCURIAL = 'hg' | ||||
@attr.s(frozen=True) | @attr.s(frozen=True) | ||||
class Revision(BaseModel, HashableObject): | class Revision(BaseModel, HashableObject): | ||||
message = attr.ib(type=bytes) | message = attr.ib(type=bytes) | ||||
author = attr.ib(type=Person) | author = attr.ib(type=Person) | ||||
committer = attr.ib(type=Person) | committer = attr.ib(type=Person) | ||||
date = attr.ib(type=TimestampWithTimezone) | date = attr.ib(type=Optional[TimestampWithTimezone]) | ||||
committer_date = attr.ib(type=TimestampWithTimezone) | committer_date = attr.ib(type=Optional[TimestampWithTimezone]) | ||||
type = attr.ib(type=RevisionType) | type = attr.ib(type=RevisionType) | ||||
directory = attr.ib(type=Sha1Git) | directory = attr.ib(type=Sha1Git) | ||||
synthetic = attr.ib(type=bool) | synthetic = attr.ib(type=bool) | ||||
metadata = attr.ib(type=Optional[Dict[str, object]], | metadata = attr.ib(type=Optional[Dict[str, object]], | ||||
default=None) | default=None) | ||||
parents = attr.ib(type=List[Sha1Git], | parents = attr.ib(type=List[Sha1Git], | ||||
default=attr.Factory(list)) | default=attr.Factory(list)) | ||||
id = attr.ib(type=Sha1Git, default=b'') | id = attr.ib(type=Sha1Git, default=b'') | ||||
@staticmethod | @staticmethod | ||||
def compute_hash(object_dict): | def compute_hash(object_dict): | ||||
return revision_identifier(object_dict) | return revision_identifier(object_dict) | ||||
@classmethod | @classmethod | ||||
def from_dict(cls, d): | def from_dict(cls, d): | ||||
d = d.copy() | d = d.copy() | ||||
date = d.pop('date') | |||||
if date: | |||||
date = TimestampWithTimezone.from_dict(date) | |||||
committer_date = d.pop('committer_date') | |||||
if committer_date: | |||||
committer_date = TimestampWithTimezone.from_dict( | |||||
committer_date) | |||||
return cls( | return cls( | ||||
author=Person.from_dict(d.pop('author')), | author=Person.from_dict(d.pop('author')), | ||||
committer=Person.from_dict(d.pop('committer')), | committer=Person.from_dict(d.pop('committer')), | ||||
date=TimestampWithTimezone.from_dict(d.pop('date')), | date=date, | ||||
committer_date=TimestampWithTimezone.from_dict( | committer_date=committer_date, | ||||
d.pop('committer_date')), | |||||
type=RevisionType(d.pop('type')), | type=RevisionType(d.pop('type')), | ||||
**d) | **d) | ||||
@attr.s(frozen=True) | @attr.s(frozen=True) | ||||
class DirectoryEntry(BaseModel): | class DirectoryEntry(BaseModel): | ||||
name = attr.ib(type=bytes) | name = attr.ib(type=bytes) | ||||
type = attr.ib(type=str, | type = attr.ib(type=str, | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |