diff --git a/java/server/src/main/java/org/softwareheritage/graph/Node.java b/java/server/src/main/java/org/softwareheritage/graph/Node.java --- a/java/server/src/main/java/org/softwareheritage/graph/Node.java +++ b/java/server/src/main/java/org/softwareheritage/graph/Node.java @@ -22,6 +22,8 @@ CNT, /** Directory node */ DIR, + /** Origin node */ + ORI, /** Release node */ REL, /** Revision node */ @@ -43,10 +45,12 @@ case 1: return DIR; case 2: - return REL; + return ORI; case 3: - return REV; + return REL; case 4: + return REV; + case 5: return SNP; } return null; @@ -60,6 +64,9 @@ * @see org.softwareheritage.graph.Node.Type */ public static Node.Type fromStr(String strType) { + if (!strType.matches("cnt|dir|ori|rel|rev|snp")) { + throw new IllegalArgumentException("Unknown node type: " + strType); + } return Node.Type.valueOf(strType.toUpperCase()); } diff --git a/java/server/src/main/java/org/softwareheritage/graph/SwhId.java b/java/server/src/main/java/org/softwareheritage/graph/SwhId.java --- a/java/server/src/main/java/org/softwareheritage/graph/SwhId.java +++ b/java/server/src/main/java/org/softwareheritage/graph/SwhId.java @@ -39,11 +39,7 @@ throw new IllegalArgumentException("Expected SWH ID format to be 'swh:1:type:hash', got: " + swhId); } - String type = parts[2]; - if (!type.matches("cnt|dir|rel|rev|snp")) { - throw new IllegalArgumentException("Unknown SWH ID type in: " + swhId); - } - this.type = Node.Type.fromStr(type); + this.type = Node.Type.fromStr(parts[2]); this.hash = parts[3]; if (!hash.matches("[0-9a-f]{" + HASH_LENGTH + "}")) { diff --git a/java/server/src/test/dataset/example.edges.csv b/java/server/src/test/dataset/example.edges.csv --- a/java/server/src/test/dataset/example.edges.csv +++ b/java/server/src/test/dataset/example.edges.csv @@ -20,3 +20,4 @@ swh:1:rel:0000000000000000000000000000000000000019 swh:1:rev:0000000000000000000000000000000000000018 swh:1:snp:0000000000000000000000000000000000000020 swh:1:rev:0000000000000000000000000000000000000009 swh:1:snp:0000000000000000000000000000000000000020 swh:1:rel:0000000000000000000000000000000000000010 +swh:1:ori:0000000000000000000000000000000000000021 swh:1:snp:0000000000000000000000000000000000000020 diff --git a/java/server/src/test/dataset/img/example.dot b/java/server/src/test/dataset/img/example.dot --- a/java/server/src/test/dataset/img/example.dot +++ b/java/server/src/test/dataset/img/example.dot @@ -71,4 +71,12 @@ 20 -> 09; 20 -> 10; } + + subgraph cluster_ori { + label="Origins"; + node [shape=egg]; + 21 [label="ori:0x21"]; + + 21 -> 20; + } } diff --git a/java/server/src/test/dataset/output/example-transposed.graph b/java/server/src/test/dataset/output/example-transposed.graph --- a/java/server/src/test/dataset/output/example-transposed.graph +++ b/java/server/src/test/dataset/output/example-transposed.graph @@ -1 +1 @@ -®—I¯'ÉâR_?¢REïîJI­ñ5Ü \ No newline at end of file +[:é5Ñ5YK¦ë+Çä_&¼Nº]/W«¥Ü \ No newline at end of file diff --git a/java/server/src/test/dataset/output/example-transposed.obl b/java/server/src/test/dataset/output/example-transposed.obl index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ expectedLeaves2 = new ArrayList<>(); - expectedLeaves2.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); + expectedLeaves2.add(new SwhId("swh:1:ori:0000000000000000000000000000000000000021")); expectedLeaves2.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000019")); GraphTest.assertEqualsAnyOrder(expectedLeaves2, endpoint.leaves(src2)); } diff --git a/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java b/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java --- a/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java @@ -15,7 +15,7 @@ Graph graph = getGraph(); ArrayList expectedNodes = new ArrayList<>(); - SwhId src1 = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhId src1 = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); GraphTest.assertEqualsAnyOrder(expectedNodes, endpoint1.neighbors(src1)); @@ -63,6 +63,12 @@ ArrayList expectedNodes4 = new ArrayList<>(); expectedNodes4.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000013")); GraphTest.assertEqualsAnyOrder(expectedNodes4, endpoint4.neighbors(src4)); + + SwhId src5 = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + Endpoint endpoint5 = new Endpoint(graph, "backward", "*"); + ArrayList expectedNodes5 = new ArrayList<>(); + expectedNodes5.add(new SwhId("swh:1:ori:0000000000000000000000000000000000000021")); + GraphTest.assertEqualsAnyOrder(expectedNodes5, endpoint5.neighbors(src5)); } @Test diff --git a/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java b/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java --- a/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java @@ -26,7 +26,7 @@ @Test public void forwardFromRoot() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); ArrayList paths = endpoint.visitPaths(swhId); ArrayList nodes = endpoint.visitNodes(swhId); @@ -34,6 +34,7 @@ ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", @@ -41,6 +42,7 @@ )); expectedPaths.add( new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", @@ -48,6 +50,7 @@ )); expectedPaths.add( new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", @@ -56,6 +59,7 @@ )); expectedPaths.add( new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", @@ -64,6 +68,7 @@ )); expectedPaths.add( new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003", @@ -72,6 +77,7 @@ )); expectedPaths.add( new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", @@ -80,6 +86,7 @@ )); expectedPaths.add( new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", @@ -88,6 +95,7 @@ )); expectedPaths.add( new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", @@ -97,6 +105,7 @@ )); expectedPaths.add( new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", @@ -106,6 +115,7 @@ )); expectedPaths.add( new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", @@ -184,7 +194,7 @@ @Test public void backwardFromRoot() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "backward", "*"); ArrayList paths = endpoint.visitPaths(swhId); ArrayList nodes = endpoint.visitNodes(swhId); @@ -192,7 +202,7 @@ ArrayList expectedPaths = new ArrayList(); expectedPaths.add( new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020" + "swh:1:ori:0000000000000000000000000000000000000021" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); @@ -255,7 +265,8 @@ "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:snp:0000000000000000000000000000000000000020" + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:ori:0000000000000000000000000000000000000021" )); expectedPaths.add( new SwhPath( @@ -264,7 +275,8 @@ "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:snp:0000000000000000000000000000000000000020" + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:ori:0000000000000000000000000000000000000021" )); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); @@ -479,11 +491,12 @@ @Test public void forwardFromRootNodesOnly() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); ArrayList nodes = endpoint.visitNodes(swhId); ArrayList expectedNodes = new ArrayList(); + expectedNodes.add(new SwhId("swh:1:ori:0000000000000000000000000000000000000021")); expectedNodes.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); expectedNodes.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000009"));