public RevTag readTag(@Nullable ObjectId id, DataInput in) throws IOException { final ObjectId commitId = readObjectId(in); final String name = in.readUTF(); final String message = in.readUTF(); final RevPerson tagger = readRevPerson(in); RevTag tag; if (id == null) { tag = RevTagBuilder.create(ObjectId.NULL, name, commitId, message, tagger); id = new HashObject().setObject(tag).call(); } tag = RevTagBuilder.create(id, name, commitId, message, tagger); return tag; }
static RevTree build(final long size, final int childTreeCount, @Nullable ImmutableList<Node> trees, @Nullable ImmutableList<Node> features, @Nullable ImmutableSortedMap<Integer, Bucket> buckets) { ObjectId id = HashObject.hashTree(trees, features, buckets); return RevTreeImpl.create(id, size, childTreeCount, trees, features, buckets); }
public static ObjectId hashTree(@Nullable List<Node> trees, @Nullable List<Node> features, @Nullable Iterable<Bucket> buckets) { final List<Node> t = trees == null ? ImmutableList.of() : trees; final List<Node> f = features == null ? ImmutableList.of() : features; final Iterable<Bucket> b = buckets == null ? Collections.emptySet() : buckets; return hash(h -> HashObjectFunnels.tree(h, t, f, b)); }
hashCommand = new HashObject(); hashCommand.setContext(mockCommandLocator); when(mockCommandLocator.command(eq(DescribeFeatureType.class))) .thenReturn(new DescribeFeatureType());
public RevFeature build() { ObjectId id = HashObject.hashFeature(values); return new RevFeatureImpl(id, new ArrayList<>(values)); }
public static RevTag build(String name, ObjectId commitId, String message, RevPerson tagger) { ObjectId id = HashObject.hashTag(name, commitId, message, tagger); return create(id, name, commitId, message, tagger); } }
/** * Builds a {@link RevFeatureType} for the given feature type, computing its id throuh * {@link HashObject} */ public static RevFeatureType build(FeatureType featureType) { checkNotNull(featureType); featureType = adapt(featureType); ObjectId id = HashObject.hashFeatureType(featureType); return RevFeatureTypeBuilder.create(id, featureType); }
public RevCommit build() { if (treeId == null) { throw new IllegalStateException("No tree id set"); } final ObjectId treeId = this.treeId; final ImmutableList<ObjectId> parentIds = ImmutableList.copyOf(this.parentIds); final RevPerson author = RevPersonBuilder.build(this.author, authorEmail, getAuthorTimestamp(), getAuthorTimeZoneOffset()); final RevPerson committer = RevPersonBuilder.build(this.committer, committerEmail, getCommitterTimestamp(), getCommitterTimeZoneOffset()); final String commitMessage = this.message == null ? "" : this.message; final ObjectId commitId = HashObject.hashCommit(treeId, parentIds, author, committer, commitMessage); return new RevCommitImpl(commitId, treeId, parentIds, author, committer, commitMessage); }
hashCommand = new HashObject(); hashCommand.setContext(mockCommandLocator); when(mockCommandLocator.command(eq(DescribeFeatureType.class))) .thenReturn(new DescribeFeatureType());
@Override public RevFeature readFeature(@Nullable ObjectId id, DataInput in) throws IOException { // <HEADER> // - unsigned varint: number of attributes final int attrCount = readUnsignedVarInt(in); // - unsigned varint: size of <DATA> final int dataSize = readUnsignedVarInt(in); // - unsigned varint[number of attributes]: attribute offsets (starting form zero at // <DATA>, not including the header) final int[] dataOffsets = new int[attrCount]; for (int i = 0; i < attrCount; i++) { dataOffsets[i] = readUnsignedVarInt(in); } // <DATA> byte[] data = new byte[dataSize]; in.readFully(data); LazyRevFeature f = new LazyRevFeature(id, dataOffsets, data, valueEncoder); if (id == null) { id = HashObject.hashFeature(f.values()); f.id = id; } return f; }
public RevCommit readCommit(@Nullable ObjectId id, DataInput in) throws IOException { final ObjectId treeId = readObjectId(in); final int nParents = readUnsignedVarInt(in); final Builder<ObjectId> parentListBuilder = ImmutableList.builder(); for (int i = 0; i < nParents; i++) { ObjectId parentId = readObjectId(in); parentListBuilder.add(parentId); } final RevPerson author = readRevPerson(in); final RevPerson committer = readRevPerson(in); final String message = in.readUTF(); ObjectId commitId = id; if (id == null) { commitId = ObjectId.NULL; } RevCommit commit = CommitBuilder.create(commitId, treeId, parentListBuilder.build(), author, committer, message); if (id == null) { commitId = new HashObject().setObject(commit).call(); commit = CommitBuilder.create(commitId, treeId, parentListBuilder.build(), author, committer, message); } return commit; }
public static RevTree createLeafTree(long size, Collection<Node> features, Collection<Node> trees) { Preconditions.checkNotNull(features); Preconditions.checkNotNull(trees); ImmutableList<Node> featuresList = ImmutableList.of(); ImmutableList<Node> treesList = ImmutableList.of(); if (!features.isEmpty()) { featuresList = NODE_STORAGE_ORDER.immutableSortedCopy(features); } if (!trees.isEmpty()) { treesList = NODE_STORAGE_ORDER.immutableSortedCopy(trees); } final ObjectId id = HashObject.hashTree(treesList, featuresList, null); return RevTreeBuilder.create(id, size, trees.size(), treesList, featuresList, null); }
@Deprecated public static ObjectId hashTree(@Nullable List<Node> trees, @Nullable List<Node> features, @Nullable SortedMap<Integer, Bucket> buckets) { final List<Node> t = trees == null ? ImmutableList.of() : trees; final List<Node> f = features == null ? ImmutableList.of() : features; final Iterable<Bucket> b = buckets == null ? Collections.emptySet() : buckets.values(); return hash(h -> HashObjectFunnels.tree(h, t, f, b)); }
@Override public RevFeature readFeature(@Nullable ObjectId id, DataInput in) throws IOException { // <HEADER> // - unsigned varint: number of attributes final int attrCount = readUnsignedVarInt(in); // - unsigned varint: size of <DATA> final int dataSize = readUnsignedVarInt(in); // - unsigned varint[number of attributes]: attribute offsets (starting form zero at // <DATA>, not including the header) final int[] dataOffsets = new int[attrCount]; for (int i = 0; i < attrCount; i++) { dataOffsets[i] = readUnsignedVarInt(in); } // <DATA> byte[] data = new byte[dataSize]; in.readFully(data); LazyRevFeature f = new LazyRevFeature(id, dataOffsets, data, valueEncoder); if (id == null) { id = HashObject.hashFeature(f.values()); f.id = id; } return f; }
private void assertHashing(final RevTree orig) { final byte[] encoded = RevTreeFormat.encode(orig); assertNotNull(encoded); RevTree decoded = RevTreeFormat.decode(null, encoded); ObjectId expected = new HashObject().setObject(orig).call(); ObjectId actual = new HashObject().setObject(decoded).call(); assertEqualsFully(orig, decoded); assertEquals(expected, actual); }
private RevTree createNodeTree(long size, int numTrees, TreeMap<Integer, Bucket> buckets) { ImmutableSortedMap<Integer, Bucket> innerTrees = ImmutableSortedMap.copyOf(buckets); final ObjectId id = HashObject.hashTree(null, null, innerTrees); return RevTreeBuilder.create(id, size, numTrees, null, null, innerTrees); }