public RevCommit build(@NonNull ObjectId treeId, @NonNull List<ObjectId> parents, @NonNull RevPerson author, @NonNull RevPerson committer, @NonNull String message) { final ObjectId commitId = HashObjectFunnels.hashCommit(treeId, parents, author, committer, message); return RevObjectFactory.defaultInstance().createCommit(commitId, treeId, ImmutableList.copyOf(parents), author, committer, message); } }
public static RevCommit readCommit(ObjectId id, DataInput in) throws IOException { byte tag = in.readByte(); if (tag != COMMIT_TREE_REF) { throw new IllegalArgumentException("Commit should include a tree ref"); } final ObjectId treeId = ObjectId.readFrom(in); final Builder<ObjectId> parentListBuilder = ImmutableList.builder(); while (true) { tag = in.readByte(); if (tag != COMMIT_PARENT_REF) { break; } else { parentListBuilder.add(ObjectId.readFrom(in)); } } if (tag != COMMIT_AUTHOR_PREFIX) { throw new IllegalArgumentException( "Expected AUTHOR element following parent ids in commit"); } final RevPerson author = readRevPerson(in); tag = in.readByte(); if (tag != COMMIT_COMMITTER_PREFIX) { throw new IllegalArgumentException( "Expected COMMITTER element following author in commit"); } final RevPerson committer = readRevPerson(in); final String message = in.readUTF(); return RevObjectFactory.defaultInstance().createCommit(id, treeId, parentListBuilder.build(), author, committer, message); }
private void testCommit(ObjectId id, ObjectId treeId, List<ObjectId> parents, RevPerson author, RevPerson committer, String message) { RevCommit actual = factory.createCommit(id, treeId, parents, author, committer, message); assertNotNull(actual); final RevCommit expected = DEFAULT.createCommit(id, treeId, parents, author, committer, message); RevObjectTestUtil.deepEquals(expected, actual); }
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(); final List<ObjectId> parents = parentListBuilder.build(); RevCommit commit; if (id == null) { commit = RevCommit.builder().build(treeId, parents, author, committer, message); } else { commit = RevObjectFactory.defaultInstance().createCommit(id, treeId, parents, author, committer, message); } return commit; }