diff --git a/swh/provenance/graph.py b/swh/provenance/graph.py --- a/swh/provenance/graph.py +++ b/swh/provenance/graph.py @@ -70,16 +70,15 @@ ) while stack: current = stack.pop() - if not current.visited: - current.entry.retrieve_parents(archive) - - for rev in current.entry.parents: - node = current.add_parent( - rev, - visited=provenance.revision_visited(rev), - in_history=provenance.revision_in_history(rev), - ) - stack.append(node) + + current.entry.retrieve_parents(archive) + for rev in current.entry.parents: + node = current.add_parent( + rev, + visited=provenance.revision_visited(rev), + in_history=provenance.revision_in_history(rev), + ) + stack.append(node) logging.debug( f"History graph for revision {revision.id.hex()} successfully created!" ) diff --git a/swh/provenance/origin.py b/swh/provenance/origin.py --- a/swh/provenance/origin.py +++ b/swh/provenance/origin.py @@ -71,6 +71,11 @@ origin: OriginEntry, graph: HistoryNode, ) -> 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 = graph.entry check_preferred_origin(provenance, origin, head) @@ -82,16 +87,10 @@ current = stack.pop() check_preferred_origin(provenance, origin, current.entry) - if current.visited: - # if current revision was already visited just add it to the current origin - # and stop recursion (its history has already been flattened) - provenance.revision_add_to_origin(origin, current.entry) - else: - # if current revision was not visited before create a link between it and - # the head, and recursively walk its history - provenance.revision_add_before_revision(head, current.entry) - for parent in current.parents: - stack.append(parent) + # create a link between it and the head, and recursively walk its history + provenance.revision_add_before_revision(head, current.entry) + for parent in current.parents: + stack.append(parent) def check_preferred_origin( diff --git a/swh/provenance/tests/data/generate_repo.py b/swh/provenance/tests/data/generate_repo.py --- a/swh/provenance/tests/data/generate_repo.py +++ b/swh/provenance/tests/data/generate_repo.py @@ -66,7 +66,7 @@ # move at the proper (first) parent position, if any check_call(["git", "checkout", parents[0]], stdout=PIPE) - # give a branch name (the msg) to each commit to make it esier to + # give a branch name (the msg) to each commit to make it easier to # navigate in history check_call(["git", "checkout", "-b", rev_d["msg"]], stdout=PIPE) diff --git a/swh/provenance/tests/data/history_graphs_with-merges_visits-01.yaml b/swh/provenance/tests/data/history_graphs_with-merges_visits-01.yaml --- a/swh/provenance/tests/data/history_graphs_with-merges_visits-01.yaml +++ b/swh/provenance/tests/data/history_graphs_with-merges_visits-01.yaml @@ -1,12 +1,12 @@ # History graph for snapshot with branches: R01 -- origin: "https://with-merges" +- origin: "https://repo_with_merges/1/" snapshot: "e2520f0dbf34c92754f00c5a60241dfa7d612868" graphs: - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" parents: - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" # History graph for snapshot with branches: R03 and R06 -- origin: "https://with-merges" +- origin: "https://repo_with_merges/1/" snapshot: "e2520f0dbf34c92754f00c5a60241dfa7d612868" graphs: - rev: "20f4da0f48609d9f7f908ebbcac3b3741a0f25cb" @@ -15,12 +15,19 @@ parents: - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True - rev: "72d92d41a9095db2dd6b8fb1c62d92c8251753ff" parents: - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True # History graph for snapshot with branches: R05 and R06 -- origin: "https://with-merges" +- origin: "https://repo_with_merges/2/" snapshot: "e2520f0dbf34c92754f00c5a60241dfa7d612868" graphs: - rev: "65e58853df939b318c106c4c1f55acaf8b41c74c" @@ -29,27 +36,154 @@ parents: - rev: "20f4da0f48609d9f7f908ebbcac3b3741a0f25cb" visited: True + parents: + - rev: "1c533587277731236616cac0d44f3b46c1da0f8a" + in_history: True + parents: + - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True + visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True - rev: "72d92d41a9095db2dd6b8fb1c62d92c8251753ff" visited: True + parents: + - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True + visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True # History graph for snapshot with branches: R06 and R07 -- origin: "https://with-merges" +- origin: "https://repo_with_merges/1/" snapshot: "e2520f0dbf34c92754f00c5a60241dfa7d612868" graphs: - rev: "72d92d41a9095db2dd6b8fb1c62d92c8251753ff" visited: True + parents: + - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True + visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True - rev: "fff0089fad98e8f5b46ec5c9025a20a602851ba6" parents: - rev: "20f4da0f48609d9f7f908ebbcac3b3741a0f25cb" + in_history: True + visited: True + parents: + - rev: "1c533587277731236616cac0d44f3b46c1da0f8a" + in_history: True + parents: + - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True + visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True +# History graph for snapshot with branches: R08 +- origin: "https://repo_with_merges/1/" + snapshot: "e2520f0dbf34c92754f00c5a60241dfa7d612868" + graphs: + - rev: "7c8f29237dded4f9d265e46ec7066503e7858e87" + parents: + - rev: "65e58853df939b318c106c4c1f55acaf8b41c74c" + visited: True + parents: + - rev: "0d66eadcc15e0d7f6cfd4289329a7749a1309982" + in_history: True + parents: + - rev: "20f4da0f48609d9f7f908ebbcac3b3741a0f25cb" + in_history: True + visited: True + parents: + - rev: "1c533587277731236616cac0d44f3b46c1da0f8a" + in_history: True + parents: + - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True + visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True + - rev: "72d92d41a9095db2dd6b8fb1c62d92c8251753ff" visited: True + parents: + - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True + visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True + - rev: "fff0089fad98e8f5b46ec5c9025a20a602851ba6" + visited: True + parents: + - rev: "20f4da0f48609d9f7f908ebbcac3b3741a0f25cb" + in_history: True + visited: True + parents: + - rev: "1c533587277731236616cac0d44f3b46c1da0f8a" + in_history: True + parents: + - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True + visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True # History graph for snapshot with branches: R08 -- origin: "https://with-merges" +- origin: "https://repo_with_merges/2/" snapshot: "e2520f0dbf34c92754f00c5a60241dfa7d612868" graphs: - rev: "7c8f29237dded4f9d265e46ec7066503e7858e87" + visited: True parents: - rev: "65e58853df939b318c106c4c1f55acaf8b41c74c" + in_history: True visited: True + parents: + - rev: "0d66eadcc15e0d7f6cfd4289329a7749a1309982" + in_history: True + parents: + - rev: "20f4da0f48609d9f7f908ebbcac3b3741a0f25cb" + in_history: True + visited: True + parents: + - rev: "1c533587277731236616cac0d44f3b46c1da0f8a" + in_history: True + parents: + - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True + visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True - rev: "72d92d41a9095db2dd6b8fb1c62d92c8251753ff" + in_history: True visited: True + parents: + - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True + visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True - rev: "fff0089fad98e8f5b46ec5c9025a20a602851ba6" + in_history: True visited: True + parents: + - rev: "20f4da0f48609d9f7f908ebbcac3b3741a0f25cb" + in_history: True + visited: True + parents: + - rev: "1c533587277731236616cac0d44f3b46c1da0f8a" + in_history: True + parents: + - rev: "1444db96cbd8cd791abe83527becee73d3c64e86" + in_history: True + visited: True + parents: + - rev: "c0d8929936631ecbcf9147be6b8aa13b13b014e4" + in_history: True