Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show First 20 Lines • Show All 757 Lines • ▼ Show 20 Lines | def snapshot_add(self, origin, visit, snapshot, | ||||
unknown object) | unknown object) | ||||
- **target_type** (:class:`str`): one of ``content``, | - **target_type** (:class:`str`): one of ``content``, | ||||
``directory``, ``revision``, ``release``, | ``directory``, ``revision``, ``release``, | ||||
``snapshot``, ``alias`` | ``snapshot``, ``alias`` | ||||
- **target** (:class:`bytes`): identifier of the target | - **target** (:class:`bytes`): identifier of the target | ||||
(currently a ``sha1_git`` for all object kinds, or the name | (currently a ``sha1_git`` for all object kinds, or the name | ||||
of the target branch for aliases) | of the target branch for aliases) | ||||
Raises: | |||||
ValueError: if the origin or visit id does not exist. | |||||
""" | """ | ||||
if not db.snapshot_exists(snapshot['id'], cur): | if not db.snapshot_exists(snapshot['id'], cur): | ||||
db.mktemp_snapshot_branch(cur) | db.mktemp_snapshot_branch(cur) | ||||
db.copy_to( | db.copy_to( | ||||
( | ( | ||||
{ | { | ||||
'name': name, | 'name': name, | ||||
'target': info['target'] if info else None, | 'target': info['target'] if info else None, | ||||
'target_type': info['target_type'] if info else None, | 'target_type': info['target_type'] if info else None, | ||||
} | } | ||||
for name, info in snapshot['branches'].items() | for name, info in snapshot['branches'].items() | ||||
), | ), | ||||
'tmp_snapshot_branch', | 'tmp_snapshot_branch', | ||||
['name', 'target', 'target_type'], | ['name', 'target', 'target_type'], | ||||
cur, | cur, | ||||
) | ) | ||||
if not db.origin_visit_exists(origin, visit): | |||||
raise ValueError('Not origin visit with ids (%s, %s)' % | |||||
(origin, visit)) | |||||
db.snapshot_add(origin, visit, snapshot['id'], cur) | db.snapshot_add(origin, visit, snapshot['id'], cur) | ||||
@db_transaction(statement_timeout=2000) | @db_transaction(statement_timeout=2000) | ||||
def snapshot_get(self, snapshot_id, db=None, cur=None): | def snapshot_get(self, snapshot_id, db=None, cur=None): | ||||
"""Get the content, possibly partial, of a snapshot with the given id | """Get the content, possibly partial, of a snapshot with the given id | ||||
The branches of the snapshot are iterated in the lexicographical | The branches of the snapshot are iterated in the lexicographical | ||||
▲ Show 20 Lines • Show All 689 Lines • Show Last 20 Lines |