Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/converters.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from typing import Any, Dict, Optional, Sequence | from typing import Dict, Optional, Sequence, Tuple | ||||
from swh.model.model import Person, Revision, RevisionType, TimestampWithTimezone | from swh.model.model import Person, Revision, RevisionType, TimestampWithTimezone | ||||
from .utils import strdate_to_timestamp | from .utils import strdate_to_timestamp | ||||
def svn_date_to_swh_date(strdate: Optional[str]) -> TimestampWithTimezone: | def svn_date_to_swh_date(strdate: Optional[str]) -> TimestampWithTimezone: | ||||
"""Convert a string date to an swh one. | """Convert a string date to an swh one. | ||||
Show All 21 Lines | def svn_author_to_swh_person(author: Optional[bytes]) -> Person: | ||||
Returns: | Returns: | ||||
a Person | a Person | ||||
""" | """ | ||||
return Person.from_fullname(author or b"") | return Person.from_fullname(author or b"") | ||||
def build_swh_revision( | def build_swh_revision( | ||||
rev: int, commit: Dict, repo_uuid: str, dir_id: bytes, parents: Sequence[bytes] | rev: int, commit: Dict, repo_uuid: bytes, dir_id: bytes, parents: Sequence[bytes] | ||||
) -> Revision: | ) -> Revision: | ||||
"""Given a svn revision, build a swh revision. | """Given a svn revision, build a swh revision. | ||||
This adds an ['metadata']['extra-headers'] entry with the | This adds an ['metadata']['extra-headers'] entry with the | ||||
repository's uuid and the svn revision. | repository's uuid and the svn revision. | ||||
Args: | Args: | ||||
- rev: the svn revision number | - rev: the svn revision number | ||||
- commit: the commit metadata | - commit: the commit metadata | ||||
- repo_uuid: The repository's uuid | - repo_uuid: The repository's uuid | ||||
- dir_id: the tree's hash identifier | - dir_id: the tree's hash identifier | ||||
- parents: the revision's parents identifier | - parents: the revision's parents identifier | ||||
Returns: | Returns: | ||||
The swh revision dictionary. | The swh revision dictionary. | ||||
""" | """ | ||||
author = commit["author_name"] | author = commit["author_name"] | ||||
msg = commit["message"] | msg = commit["message"] | ||||
date = commit["author_date"] | date = commit["author_date"] | ||||
metadata: Dict[str, Any] = { | extra_headers: Tuple[Tuple[bytes, bytes], ...] = ( | ||||
"extra_headers": [ | (b"svn_repo_uuid", repo_uuid), | ||||
["svn_repo_uuid", repo_uuid], | (b"svn_revision", str(rev).encode()), | ||||
["svn_revision", str(rev).encode("utf-8")], | ) | ||||
] | |||||
} | |||||
return Revision( | return Revision( | ||||
type=RevisionType.SUBVERSION, | type=RevisionType.SUBVERSION, | ||||
date=date, | date=date, | ||||
committer_date=date, | committer_date=date, | ||||
directory=dir_id, | directory=dir_id, | ||||
message=msg, | message=msg, | ||||
author=author, | author=author, | ||||
committer=author, | committer=author, | ||||
synthetic=True, | synthetic=True, | ||||
metadata=metadata, | extra_headers=extra_headers, | ||||
parents=tuple(parents), | parents=tuple(parents), | ||||
) | ) |