Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/origin.py
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | def origin_add( | ||||
provenance: ProvenanceInterface, | provenance: ProvenanceInterface, | ||||
archive: ArchiveInterface, | archive: ArchiveInterface, | ||||
origins: List[OriginEntry], | origins: List[OriginEntry], | ||||
) -> None: | ) -> None: | ||||
for origin in origins: | for origin in origins: | ||||
provenance.origin_add(origin) | provenance.origin_add(origin) | ||||
origin.retrieve_revisions(archive) | origin.retrieve_revisions(archive) | ||||
for revision in origin.revisions: | for revision in origin.revisions: | ||||
graph = HistoryGraph(provenance, archive, revision) | graph = HistoryGraph(archive, revision) | ||||
origin_add_revision(provenance, origin, graph) | origin_add_revision(provenance, origin, graph) | ||||
provenance.flush() | provenance.flush() | ||||
@statsd.timed(metric=ORIGIN_DURATION_METRIC, tags={"method": "process_revision"}) | @statsd.timed(metric=ORIGIN_DURATION_METRIC, tags={"method": "process_revision"}) | ||||
def origin_add_revision( | def origin_add_revision( | ||||
provenance: ProvenanceInterface, | provenance: ProvenanceInterface, | ||||
origin: OriginEntry, | origin: OriginEntry, | ||||
graph: HistoryGraph, | graph: HistoryGraph, | ||||
) -> None: | ) -> None: | ||||
# XXX: simplified version of the origin-revision algorithm. This is generating flat | |||||
# models for the history of all head revisions. No previous result is reused now! | |||||
# The previous implementation was missing some paths from origins to certain | |||||
# revisions due to a wrong reuse logic. | |||||
# head is treated separately since it should always be added to the given origin | # head is treated separately since it should always be added to the given origin | ||||
check_preferred_origin(provenance, origin, graph.head.entry) | check_preferred_origin(provenance, origin, graph.head) | ||||
provenance.revision_add_to_origin(origin, graph.head.entry) | provenance.revision_add_to_origin(origin, graph.head) | ||||
visited = {graph.head} | visited = {graph.head} | ||||
# head's history should be recursively iterated starting from its parents | # head's history should be recursively iterated starting from its parents | ||||
stack = list(graph.parents[graph.head]) | stack = list(graph.parents[graph.head]) | ||||
while stack: | while stack: | ||||
current = stack.pop() | current = stack.pop() | ||||
check_preferred_origin(provenance, origin, current.entry) | check_preferred_origin(provenance, origin, current) | ||||
# create a link between it and the head, and recursively walk its history | # create a link between it and the head, and recursively walk its history | ||||
provenance.revision_add_before_revision(graph.head.entry, current.entry) | provenance.revision_add_before_revision(graph.head, current) | ||||
visited.add(current) | visited.add(current) | ||||
for parent in graph.parents[current]: | for parent in graph.parents[current]: | ||||
if parent not in visited: | if parent not in visited: | ||||
stack.append(parent) | stack.append(parent) | ||||
@statsd.timed(metric=ORIGIN_DURATION_METRIC, tags={"method": "check_preferred_origin"}) | @statsd.timed(metric=ORIGIN_DURATION_METRIC, tags={"method": "check_preferred_origin"}) | ||||
def check_preferred_origin( | def check_preferred_origin( | ||||
Show All 9 Lines |