Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/service.py
Show First 20 Lines • Show All 581 Lines • ▼ Show 20 Lines | Args: | ||||
rev_sha1_git (str): The revision's sha1 as hexadecimal | rev_sha1_git (str): The revision's sha1 as hexadecimal | ||||
limit (int): the maximum number of revisions returned | limit (int): the maximum number of revisions returned | ||||
Returns: | Returns: | ||||
list: Revision log as list of revision dicts | list: Revision log as list of revision dicts | ||||
Raises: | Raises: | ||||
ValueError: if the identifier provided is not of sha1 nature. | ValueError: if the identifier provided is not of sha1 nature. | ||||
NotFoundExc: if there is no revision with the provided sha1_git. | swh.web.common.exc.NotFoundExc: if there is no revision with the | ||||
provided sha1_git. | |||||
""" | """ | ||||
lookup_revision(rev_sha1_git) | lookup_revision(rev_sha1_git) | ||||
sha1_git_bin = _to_sha1_bin(rev_sha1_git) | sha1_git_bin = _to_sha1_bin(rev_sha1_git) | ||||
revision_entries = storage.revision_log([sha1_git_bin], limit) | revision_entries = storage.revision_log([sha1_git_bin], limit) | ||||
return map(converters.from_revision, revision_entries) | return map(converters.from_revision, revision_entries) | ||||
def lookup_revision_log_by(origin, branch_name, timestamp, limit): | def lookup_revision_log_by(origin, branch_name, timestamp, limit): | ||||
"""Lookup revision by origin, snapshot branch name and visit timestamp. | """Lookup revision by origin, snapshot branch name and visit timestamp. | ||||
Args: | Args: | ||||
origin (Union[int,str]): origin of the revision | origin (Union[int,str]): origin of the revision | ||||
branch_name (str): snapshot branch | branch_name (str): snapshot branch | ||||
timestamp (str/int): origin visit time frame | timestamp (str/int): origin visit time frame | ||||
limit (int): the maximum number of revisions returned | limit (int): the maximum number of revisions returned | ||||
Returns: | Returns: | ||||
list: Revision log as list of revision dicts | list: Revision log as list of revision dicts | ||||
Raises: | Raises: | ||||
NotFoundExc: if no revision corresponds to the criterion | swh.web.common.exc.NotFoundExc: if no revision corresponds to the | ||||
criterion | |||||
""" | """ | ||||
rev_id = _lookup_revision_id_by(origin, branch_name, timestamp) | rev_id = _lookup_revision_id_by(origin, branch_name, timestamp) | ||||
return lookup_revision_log(rev_id, limit) | return lookup_revision_log(rev_id, limit) | ||||
def lookup_revision_with_context_by(origin, branch_name, timestamp, | def lookup_revision_with_context_by(origin, branch_name, timestamp, | ||||
sha1_git, limit=100): | sha1_git, limit=100): | ||||
▲ Show 20 Lines • Show All 525 Lines • ▼ Show 20 Lines | Args: | ||||
object_id (str): the *sha1_git* checksum identifier in hexadecimal | object_id (str): the *sha1_git* checksum identifier in hexadecimal | ||||
form of the object to lookup | form of the object to lookup | ||||
Returns: | Returns: | ||||
Dict[str, Any]: A dictionary describing the object or a list of | Dict[str, Any]: A dictionary describing the object or a list of | ||||
dictionary for the directory object type. | dictionary for the directory object type. | ||||
Raises: | Raises: | ||||
NotFoundExc: if the object could not be found in the archive | swh.web.common.exc.NotFoundExc: if the object could not be found in | ||||
the archive | |||||
BadInputExc: if the object identifier is invalid | BadInputExc: if the object identifier is invalid | ||||
""" | """ | ||||
if object_type == CONTENT: | if object_type == CONTENT: | ||||
return lookup_content(f'sha1_git:{object_id}') | return lookup_content(f'sha1_git:{object_id}') | ||||
elif object_type == DIRECTORY: | elif object_type == DIRECTORY: | ||||
return { | return { | ||||
'id': object_id, | 'id': object_id, | ||||
'content': list(lookup_directory(object_id)) | 'content': list(lookup_directory(object_id)) | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |