Page MenuHomeSoftware Heritage

D3315.diff
No OneTemporary

D3315.diff

diff --git a/requirements-swh.txt b/requirements-swh.txt
--- a/requirements-swh.txt
+++ b/requirements-swh.txt
@@ -3,5 +3,5 @@
swh.model >= 0.3.0
swh.scheduler >= 0.1.1
swh.search >= 0.0.4
-swh.storage >= 0.3.0
+swh.storage >= 0.6.0
swh.vault >= 0.0.33
diff --git a/swh/web/common/service.py b/swh/web/common/service.py
--- a/swh/web/common/service.py
+++ b/swh/web/common/service.py
@@ -8,11 +8,12 @@
import re
from collections import defaultdict
-from typing import Any, Dict, List, Set, Iterator, Optional, Tuple
+from typing import Any, Dict, List, Set, Iterable, Iterator, Optional, Tuple
from swh.model import hashutil
from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT
from swh.storage.algos import diff, revisions_walker
+from swh.storage.algos.snapshot import snapshot_get_latest
from swh.vault.exc import NotFoundExc as VaultNotFoundExc
from swh.web import config
from swh.web.common import converters
@@ -1003,7 +1004,9 @@
return converters.from_snapshot(snapshot)
-def lookup_latest_origin_snapshot(origin, allowed_statuses=None):
+def lookup_latest_origin_snapshot(
+ origin: str, allowed_statuses: Iterable[str] = None
+) -> Optional[Dict[str, Any]]:
"""Return information about the latest snapshot of an origin.
.. warning:: At most 1000 branches contained in the snapshot
@@ -1019,8 +1022,10 @@
Returns:
A dict filled with the snapshot content.
"""
- snapshot = storage.snapshot_get_latest(origin, allowed_statuses)
- return converters.from_snapshot(snapshot)
+ snp = snapshot_get_latest(
+ storage, origin, allowed_statuses=allowed_statuses, branches_count=1000
+ )
+ return converters.from_snapshot(snp.to_dict()) if snp is not None else None
def lookup_snapshot_branch_name_from_tip_revision(
diff --git a/swh/web/tests/conftest.py b/swh/web/tests/conftest.py
--- a/swh/web/tests/conftest.py
+++ b/swh/web/tests/conftest.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2019 The Software Heritage developers
+# Copyright (C) 2018-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -19,6 +19,7 @@
from swh.model.hashutil import ALGORITHMS, hash_to_bytes
from swh.web.common import converters
from swh.web.tests.data import get_tests_data, override_storages
+from swh.storage.algos.snapshot import snapshot_get_latest
# Used to skip some tests
ctags_json_missing = (
@@ -216,8 +217,8 @@
)
def snapshot_get_latest(self, origin_url):
- snp = self.storage.snapshot_get_latest(origin_url)
- return converters.from_snapshot(snp)
+ snp = snapshot_get_latest(self.storage, origin_url)
+ return converters.from_snapshot(snp.to_dict())
def origin_get(self, origin_info):
origin = self.storage.origin_get(origin_info)
diff --git a/swh/web/tests/data.py b/swh/web/tests/data.py
--- a/swh/web/tests/data.py
+++ b/swh/web/tests/data.py
@@ -19,6 +19,7 @@
from swh.loader.git.from_disk import GitLoaderFromArchive
from swh.search import get_search
from swh.storage.algos.dir_iterators import dir_iterator
+from swh.storage.algos.snapshot import snapshot_get_latest
from swh.web import config
from swh.web.browse.utils import (
get_mimetype_and_encoding_for_content,
@@ -224,15 +225,16 @@
# Get all objects loaded into the test archive
for origin in _TEST_ORIGINS:
- snp = storage.snapshot_get_latest(origin["url"])
- snapshots.add(hash_to_hex(snp["id"]))
- for branch_name, branch_data in snp["branches"].items():
- if branch_data["target_type"] == "revision":
- revisions.add(branch_data["target"])
- elif branch_data["target_type"] == "release":
- release = next(storage.release_get([branch_data["target"]]))
+ snp = snapshot_get_latest(storage, origin["url"])
+ snapshots.add(hash_to_hex(snp.id))
+ for branch_name, branch_data in snp.branches.items():
+ target_type = branch_data.target_type.value
+ if target_type == "revision":
+ revisions.add(branch_data.target)
+ elif target_type == "release":
+ release = next(storage.release_get([branch_data.target]))
revisions.add(release["target"])
- releases.add(hash_to_hex(branch_data["target"]))
+ releases.add(hash_to_hex(branch_data.target))
for rev_log in storage.revision_shortlog(set(revisions)):
rev_id = rev_log[0]
diff --git a/swh/web/tests/strategies.py b/swh/web/tests/strategies.py
--- a/swh/web/tests/strategies.py
+++ b/swh/web/tests/strategies.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2019 The Software Heritage developers
+# Copyright (C) 2018-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -25,6 +25,7 @@
from swh.model.identifiers import directory_identifier
from swh.model.model import Person, Revision, RevisionType, TimestampWithTimezone
from swh.storage.algos.revisions_walker import get_revisions_walker
+from swh.storage.algos.snapshot import snapshot_get_latest
from swh.model.hypothesis_strategies import (
origins as new_origin_strategy,
snapshots as new_snapshot,
@@ -278,8 +279,8 @@
ret = []
tests_data = get_tests_data()
for origin in tests_data["origins"]:
- snapshot = tests_data["storage"].snapshot_get_latest(origin["url"])
- if any([b["target_type"] == "release" for b in snapshot["branches"].values()]):
+ snapshot = snapshot_get_latest(tests_data["storage"], origin["url"])
+ if any([b.target_type.value == "release" for b in snapshot.branches.values()]):
ret.append(origin)
return sampled_from(ret)
@@ -469,12 +470,12 @@
tests_data = get_tests_data()
storage = tests_data["storage"]
origin = random.choice(tests_data["origins"][:-1])
- snapshot = storage.snapshot_get_latest(origin["url"])
- if snapshot["branches"][b"HEAD"]["target_type"] == "alias":
- target = snapshot["branches"][b"HEAD"]["target"]
- head = snapshot["branches"][target]["target"]
+ snapshot = snapshot_get_latest(storage, origin["url"])
+ if snapshot.branches[b"HEAD"].target_type.value == "alias":
+ target = snapshot.branches[b"HEAD"].target
+ head = snapshot.branches[target].target
else:
- head = snapshot["branches"][b"HEAD"]["target"]
+ head = snapshot.branches[b"HEAD"].target
return get_revisions_walker("dfs", storage, head)

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 17, 1:26 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3218241

Event Timeline