Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/graph.py
Show First 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | ) -> IsochroneNode: | ||||
# | # | ||||
# 2. compute the maxdate for each node of the tree that was not found in the DB. | # 2. compute the maxdate for each node of the tree that was not found in the DB. | ||||
# Build the nodes structure | # Build the nodes structure | ||||
root_date = provenance.directory_get_date_in_isochrone_frontier(directory) | root_date = provenance.directory_get_date_in_isochrone_frontier(directory) | ||||
root = IsochroneNode(directory, dbdate=root_date) | root = IsochroneNode(directory, dbdate=root_date) | ||||
stack = [root] | stack = [root] | ||||
fdates: Dict[Sha1Git, datetime] = {} # map {file_id: date} | fdates: Dict[Sha1Git, datetime] = {} # map {file_id: date} | ||||
size = 0 | |||||
while stack: | while stack: | ||||
size += 1 | |||||
current = stack.pop() | current = stack.pop() | ||||
if current.dbdate is None or current.dbdate > revision.date: | if current.dbdate is None or current.dbdate > revision.date: | ||||
# If current directory has an associated date in the isochrone frontier that | # If current directory has an associated date in the isochrone frontier that | ||||
# is greater or equal to the current revision's one, it should be ignored as | # is greater or equal to the current revision's one, it should be ignored as | ||||
# the revision is being processed out of order. | # the revision is being processed out of order. | ||||
if current.dbdate is not None and current.dbdate > revision.date: | if current.dbdate is not None and current.dbdate > revision.date: | ||||
current.invalidate() | current.invalidate() | ||||
Show All 11 Lines | while stack: | ||||
fdates.update(provenance.content_get_early_dates(current.entry.files)) | fdates.update(provenance.content_get_early_dates(current.entry.files)) | ||||
# Precalculate max known date for each node in the graph (only directory nodes are | # Precalculate max known date for each node in the graph (only directory nodes are | ||||
# pushed to the stack). | # pushed to the stack). | ||||
stack = [root] | stack = [root] | ||||
while stack: | while stack: | ||||
size += 1 | |||||
current = stack.pop() | current = stack.pop() | ||||
# Current directory node is known if it already has an assigned date (ie. it was | # Current directory node is known if it already has an assigned date (ie. it was | ||||
# already seen as an isochrone frontier). | # already seen as an isochrone frontier). | ||||
if current.known: | if current.known: | ||||
assert current.maxdate is None | assert current.maxdate is None | ||||
current.maxdate = current.dbdate | current.maxdate = current.dbdate | ||||
else: | else: | ||||
if any(x.maxdate is None for x in current.children): | if any(x.maxdate is None for x in current.children): | ||||
Show All 31 Lines | while stack: | ||||
# possible | # possible | ||||
and all((file.id in fdates) for file in current.entry.files) | and all((file.id in fdates) for file in current.entry.files) | ||||
) | ) | ||||
else: | else: | ||||
# at least one content is being processed out-of-order, then current | # at least one content is being processed out-of-order, then current | ||||
# node should be treated as unknown | # node should be treated as unknown | ||||
current.maxdate = revision.date | current.maxdate = revision.date | ||||
current.known = False | current.known = False | ||||
root.size = size | |||||
return root | return root |