diff --git a/java/src/main/java/org/softwareheritage/graph/SwhLabel.java b/java/src/main/java/org/softwareheritage/graph/SwhLabel.java new file mode 100644 --- /dev/null +++ b/java/src/main/java/org/softwareheritage/graph/SwhLabel.java @@ -0,0 +1,17 @@ +package org.softwareheritage.graph; + +/** + * Wrapper class to store the edge labels of the graph. + * + * @author The Software Heritage developers + */ +public class SwhLabel { + public int permissionId; + public long filenameId; + + public SwhLabel(int permissionId, long filenameId) + { + this.permissionId = permissionId; + this.filenameId = filenameId; + } +} diff --git a/java/src/main/java/org/softwareheritage/graph/SwhPerm.java b/java/src/main/java/org/softwareheritage/graph/SwhPerm.java new file mode 100644 --- /dev/null +++ b/java/src/main/java/org/softwareheritage/graph/SwhPerm.java @@ -0,0 +1,81 @@ +package org.softwareheritage.graph; + +/** + * Permission types present in the Software Heritage graph. + * + * @author The Software Heritage developers + */ + +public class SwhPerm { + public enum Type { + CONTENT, + EXECUTABLE_CONTENT, + SYMLINK, + DIRECTORY, + REVISION; + + public static Type fromInt(int intType) { + switch (intType) { + case 0: + return CONTENT; + case 1: + return EXECUTABLE_CONTENT; + case 2: + return SYMLINK; + case 3: + return DIRECTORY; + case 4: + return REVISION; + } + return null; + } + + public static int toInt(Type type) { + switch (type) { + case CONTENT: + return 0; + case EXECUTABLE_CONTENT: + return 1; + case SYMLINK: + return 2; + case DIRECTORY: + return 3; + case REVISION: + return 4; + } + throw new IllegalArgumentException("Unknown node type: " + type); + } + + public static Type fromOct(int octType) { + switch (octType) { + case 0100644: + return CONTENT; + case 0100755: + return EXECUTABLE_CONTENT; + case 0120000: + return SYMLINK; + case 0040000: + return DIRECTORY; + case 0160000: + return REVISION; + } + return null; + } + + public static int toOct(Type type) { + switch (type) { + case CONTENT: + return 0100644; + case EXECUTABLE_CONTENT: + return 0100755; + case SYMLINK: + return 0120000; + case DIRECTORY: + return 0040000; + case REVISION: + return 0160000; + } + throw new IllegalArgumentException("Unknown node type: " + type); + } + } +} diff --git a/java/src/main/java/org/softwareheritage/graph/maps/LabelMapBuilder.java b/java/src/main/java/org/softwareheritage/graph/maps/LabelMapBuilder.java --- a/java/src/main/java/org/softwareheritage/graph/maps/LabelMapBuilder.java +++ b/java/src/main/java/org/softwareheritage/graph/maps/LabelMapBuilder.java @@ -4,7 +4,6 @@ import it.unimi.dsi.big.webgraph.LazyLongIterator; import it.unimi.dsi.big.webgraph.labelling.ArcLabelledImmutableGraph; import it.unimi.dsi.big.webgraph.labelling.BitStreamArcLabelledImmutableGraph; -import it.unimi.dsi.big.webgraph.labelling.FixedWidthIntLabel; import it.unimi.dsi.big.webgraph.labelling.FixedWidthIntListLabel; import it.unimi.dsi.fastutil.BigArrays; import it.unimi.dsi.fastutil.Size64; @@ -20,6 +19,8 @@ import it.unimi.dsi.big.webgraph.NodeIterator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.softwareheritage.graph.SwhPerm; +import org.softwareheritage.graph.SwhLabel; import java.io.*; import java.nio.charset.StandardCharsets; @@ -99,18 +100,23 @@ static void computeLabelMap(String graphPath, String debugPath, String tmpDir) throws IOException { - // Compute intermediate representation in the format "