Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123587
D4976.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Subscribers
None
D4976.diff
View Options
diff --git a/swh/storage/algos/origin.py b/swh/storage/algos/origin.py
--- a/swh/storage/algos/origin.py
+++ b/swh/storage/algos/origin.py
@@ -1,9 +1,9 @@
-# Copyright (C) 2019-2020 The Software Heritage developers
+# Copyright (C) 2019-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-from typing import Iterator, List, Optional, Tuple
+from typing import Iterator, List, Optional
from swh.core.api.classes import stream_results
from swh.model.model import Origin, OriginVisit, OriginVisitStatus
@@ -30,7 +30,7 @@
type: Optional[str] = None,
allowed_statuses: Optional[List[str]] = None,
require_snapshot: bool = False,
-) -> Optional[Tuple[OriginVisit, OriginVisitStatus]]:
+) -> Optional[OriginVisitStatus]:
"""Get the latest origin visit (and status) of an origin. Optionally, a combination of
criteria can be provided, origin type, allowed statuses or if a visit has a
snapshot.
@@ -61,7 +61,7 @@
allowed_statuses=allowed_statuses,
require_snapshot=require_snapshot,
)
- result: Optional[Tuple[OriginVisit, OriginVisitStatus]] = None
+ result: Optional[OriginVisitStatus] = None
if visit:
assert visit.visit is not None
visit_status = storage.origin_visit_status_get_latest(
@@ -71,7 +71,7 @@
require_snapshot=require_snapshot,
)
if visit_status:
- result = visit, visit_status
+ result = visit_status
return result
diff --git a/swh/storage/algos/snapshot.py b/swh/storage/algos/snapshot.py
--- a/swh/storage/algos/snapshot.py
+++ b/swh/storage/algos/snapshot.py
@@ -81,14 +81,12 @@
The snapshot object if one is found matching the criteria or None.
"""
- visit_and_status = origin_get_latest_visit_status(
+ visit_status = origin_get_latest_visit_status(
storage, origin, allowed_statuses=allowed_statuses, require_snapshot=True,
)
-
- if not visit_and_status:
+ if not visit_status:
return None
- _, visit_status = visit_and_status
snapshot_id = visit_status.snapshot
if not snapshot_id:
return None
diff --git a/swh/storage/tests/algos/test_origin.py b/swh/storage/tests/algos/test_origin.py
--- a/swh/storage/tests/algos/test_origin.py
+++ b/swh/storage/tests/algos/test_origin.py
@@ -159,26 +159,24 @@
)
# Two visits, both with no snapshot, take the most recent
- actual_ov1, actual_ovs12 = origin_get_latest_visit_status(
+ actual_ovs12 = origin_get_latest_visit_status(
swh_storage, origin1.url, type=sample_data.type_visit1
)
- assert isinstance(actual_ov1, OriginVisit)
assert isinstance(actual_ovs12, OriginVisitStatus)
- assert actual_ov1.origin == ov1.origin
- assert actual_ov1.visit == ov1.visit
- assert actual_ov1.type == sample_data.type_visit1
assert actual_ovs12 == ovs12
+ assert actual_ovs12.origin == ov1.origin
+ assert actual_ovs12.visit == ov1.visit
+ assert actual_ovs12.type == sample_data.type_visit1
# take the most recent visit with type_visit2
- actual_ov2, actual_ovs22 = origin_get_latest_visit_status(
+ actual_ovs22 = origin_get_latest_visit_status(
swh_storage, origin2.url, type=sample_data.type_visit2
)
- assert isinstance(actual_ov2, OriginVisit)
assert isinstance(actual_ovs22, OriginVisitStatus)
- assert actual_ov2.origin == ov2.origin
- assert actual_ov2.visit == ov2.visit
- assert actual_ov2.type == sample_data.type_visit2
assert actual_ovs22 == ovs22
+ assert actual_ovs22.origin == ov2.origin
+ assert actual_ovs22.visit == ov2.visit
+ assert actual_ovs22.type == sample_data.type_visit2
def test_origin_get_latest_visit_status_filter_status(swh_storage, sample_data):
@@ -196,38 +194,37 @@
)
# only 1 partial for that visit
- actual_ov1, actual_ovs11 = origin_get_latest_visit_status(
+ actual_ovs11 = origin_get_latest_visit_status(
swh_storage, origin1.url, allowed_statuses=["partial"]
)
- assert actual_ov1.origin == ov1.origin
- assert actual_ov1.visit == ov1.visit
- assert actual_ov1.type == sample_data.type_visit1
assert actual_ovs11 == ovs11
+ assert actual_ovs11.origin == ov1.origin
+ assert actual_ovs11.visit == ov1.visit
+ assert actual_ovs11.type == sample_data.type_visit1
# both status exist, take the latest one
- actual_ov1, actual_ovs12 = origin_get_latest_visit_status(
+ actual_ovs12 = origin_get_latest_visit_status(
swh_storage, origin1.url, allowed_statuses=["partial", "ongoing"]
)
- assert actual_ov1.origin == ov1.origin
- assert actual_ov1.visit == ov1.visit
- assert actual_ov1.type == sample_data.type_visit1
assert actual_ovs12 == ovs12
+ assert actual_ovs12.origin == ov1.origin
+ assert actual_ovs12.visit == ov1.visit
+ assert actual_ovs12.type == sample_data.type_visit1
- assert isinstance(actual_ov1, OriginVisit)
assert isinstance(actual_ovs12, OriginVisitStatus)
- assert actual_ov1.origin == ov1.origin
- assert actual_ov1.visit == ov1.visit
- assert actual_ov1.type == sample_data.type_visit1
assert actual_ovs12 == ovs12
+ assert actual_ovs12.origin == ov1.origin
+ assert actual_ovs12.visit == ov1.visit
+ assert actual_ovs12.type == sample_data.type_visit1
# take the most recent visit with type_visit2
- actual_ov2, actual_ovs22 = origin_get_latest_visit_status(
+ actual_ovs22 = origin_get_latest_visit_status(
swh_storage, origin2.url, allowed_statuses=["full"]
)
- assert actual_ov2.origin == ov2.origin
- assert actual_ov2.visit == ov2.visit
- assert actual_ov2.type == sample_data.type_visit2
assert actual_ovs22 == ovs22
+ assert actual_ovs22.origin == ov2.origin
+ assert actual_ovs22.visit == ov2.visit
+ assert actual_ovs22.type == sample_data.type_visit2
def test_origin_get_latest_visit_status_filter_snapshot(swh_storage, sample_data):
@@ -243,13 +240,13 @@
)
# visit status with partial status visit elected
- actual_ov2, actual_ovs22 = origin_get_latest_visit_status(
+ actual_ovs22 = origin_get_latest_visit_status(
swh_storage, origin2.url, require_snapshot=True
)
- assert actual_ov2.origin == ov2.origin
- assert actual_ov2.visit == ov2.visit
- assert actual_ov2.type == ov2.type
assert actual_ovs22 == ovs22
+ assert actual_ovs22.origin == ov2.origin
+ assert actual_ovs22.visit == ov2.visit
+ assert actual_ovs22.type == ov2.type
date_now = now()
@@ -259,13 +256,13 @@
)
# Requiring the latest visit with a snapshot, we still find the previous visit
- ov2, ovs22 = origin_get_latest_visit_status(
+ ovs22 = origin_get_latest_visit_status(
swh_storage, origin2.url, require_snapshot=True
)
- assert actual_ov2.origin == ov2.origin
- assert actual_ov2.visit == ov2.visit
- assert actual_ov2.type == ov2.type
assert actual_ovs22 == ovs22
+ assert actual_ovs22.origin == ov2.origin
+ assert actual_ovs22.visit == ov2.visit
+ assert actual_ovs22.type == ov2.type
def test_iter_origin_visits(swh_storage, sample_data):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 11:58 AM (17 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3215302
Attached To
D4976: storage: Make origin_get_latest_visit_status return OriginVisitStatus
Event Timeline
Log In to Comment