public @Override void findSuccessors(final Object object, final List<Object> successors, ObjectStore database) { if (object instanceof RevCommit) { successors.add(database.getTree(((RevCommit) object).getTreeId())); } }
public static String toString(@NonNull RevCommit c) { return String.format("%s(%s)[tree:%s, parents:%s, msg:%s, author:%s, committer:%s]", c.getClass().getSimpleName(), // toShortString(c.getId()), // toShortString(c.getTreeId()), // c.getParentIds().stream().map(RevObjects::toShortString) .collect(Collectors.toList()), // c.getMessage(), // toShortString(c.getAuthor()), // toShortString(c.getCommitter())); }
private RevTree resolveTree(RevObject o, ObjectStore source) { if (o instanceof RevTree) { return (RevTree) o; } if (o instanceof RevCommit) { return source.getTree(((RevCommit) o).getTreeId()); } if (o instanceof RevTag) { return resolveTree(source.getCommit(((RevTag) o).getCommitId()), source); } throw new IllegalArgumentException("Object does not resolve to a tree"); }
private int write(@NonNull RevCommit c, @NonNull FlatBufferBuilder builder) { return writeCommit(builder, c.getTreeId(), c.getParentIds(), c.getAuthor(), c.getCommitter(), c.getMessage()); }
public void writeCommit(RevCommit commit, DataOutput data) throws IOException { data.write(commit.getTreeId().getRawValue()); final int nParents = commit.getParentIds().size(); writeUnsignedVarInt(nParents, data); for (ObjectId pId : commit.getParentIds()) { data.write(pId.getRawValue()); } writePerson(commit.getAuthor(), data); writePerson(commit.getCommitter(), data); data.writeUTF(commit.getMessage()); }
/** * Equality is based on author, committer, message, parent ids, and tree id. * * @see AbstractRevObject#equals(java.lang.Object) */ @Override public boolean equals(Object o) { if (!(o instanceof RevCommit) && !super.equals(o)) { return false; } RevCommit c = (RevCommit) o; return equal(getAuthor(), c.getAuthor()) && equal(getCommitter(), c.getCommitter()) && equal(getMessage(), c.getMessage()) && equal(getParentIds(), c.getParentIds()) && equal(getTreeId(), c.getTreeId()); }
@Override protected void print(RevCommit commit, Writer w) throws IOException { println(w, "tree\t", commit.getTreeId().toString()); print(w, "parents\t"); for (Iterator<ObjectId> it = commit.getParentIds().iterator(); it.hasNext();) { print(w, it.next().toString()); if (it.hasNext()) { print(w, " "); } } println(w); printPerson(w, "author", commit.getAuthor()); printPerson(w, "committer", commit.getCommitter()); println(w, "message\t", Optional.fromNullable(commit.getMessage()).or("")); w.flush(); }
@Override public void funnel(RevCommit from, PrimitiveSink into) { funnel(into, from.getTreeId(), from.getParentIds(), from.getMessage(), from.getAuthor(), from.getCommitter()); }
/** * @return the {@link ObjectId} of the root tree */ @Override public ObjectId getRootTreeId() { // find the root tree ObjectId commitId = command(RevParse.class).setRefSpec(Ref.HEAD).call().get(); if (commitId.isNull()) { return commitId; } RevCommit commit = command(RevObjectParse.class).setRefSpec(commitId.toString()) .call(RevCommit.class).get(); ObjectId treeId = commit.getTreeId(); return treeId; }
@Override public void funnel(RevCommit from, PrimitiveSink into) { funnel(into, from.getTreeId(), from.getParentIds(), from.getMessage(), from.getAuthor(), from.getCommitter()); }
/** * @return the {@link ObjectId} of the root tree */ @Override public ObjectId getRootTreeId() { // find the root tree ObjectId commitId = command(RevParse.class).setRefSpec(Ref.HEAD).call().get(); if (commitId.isNull()) { return commitId; } RevCommit commit = command(RevObjectParse.class).setRefSpec(commitId.toString()) .call(RevCommit.class).get(); ObjectId treeId = commit.getTreeId(); return treeId; }
public void writeCommit(RevCommit commit, DataOutput data) throws IOException { commit.getTreeId().writeTo(data); final int nParents = commit.getParentIds().size(); writeUnsignedVarInt(nParents, data); for (ObjectId pId : commit.getParentIds()) { pId.writeTo(data); } writePerson(commit.getAuthor(), data); writePerson(commit.getCommitter(), data); data.writeUTF(commit.getMessage()); }
@Test public void testCommitWithDeletedTree() throws Exception { insertAndAdd(points1, points2); insertAndAdd(lines1, lines2); final RevCommit commit1 = geogig.command(CommitOp.class).call(); final RevTree tree1 = geogig.command(RevObjectParse.class).setObjectId(commit1.getTreeId()) .call(RevTree.class).get(); assertEquals(2, tree1.trees().size()); WorkingTree workingTree = geogig.getRepository().workingTree(); workingTree.delete(pointsName); geogig.command(AddOp.class).call(); final RevCommit commit2 = geogig.command(CommitOp.class).call(); RevTree tree2 = geogig.command(RevObjectParse.class).setObjectId(commit2.getTreeId()) .call(RevTree.class).get(); assertEquals(1, tree2.trees().size()); }
public static void deepEquals(@NonNull RevCommit expected, @NonNull RevCommit actual) { assertEquals(TYPE.COMMIT, actual.getType()); assertEquals(expected.getId(), actual.getId()); assertEquals(expected.getCommitter(), actual.getCommitter()); assertEquals(expected.getAuthor(), actual.getAuthor()); assertEquals(expected.getMessage(), actual.getMessage()); assertEquals(expected.getParentIds(), actual.getParentIds()); assertEquals(expected.getTreeId(), actual.getTreeId()); assertEquals(expected.getType(), actual.getType()); }
@Test public void testCommitEmptyTreeOnEmptyRepo() throws Exception { WorkingTree workingTree = geogig.getRepository().workingTree(); final String emptyTreeName = "emptyTree"; workingTree.createTypeTree(emptyTreeName, pointsType); geogig.command(AddOp.class).addPattern(emptyTreeName).call(); CommitOp commitCommand = geogig.command(CommitOp.class); RevCommit commit = commitCommand.call(); assertNotNull(commit); RevTree head = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()) .call(RevTree.class).get(); Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(emptyTreeName) .setParent(head).call(); assertTrue(ref.isPresent()); }
@Test public void testCommitEmptyTreeOnEmptyRepo() throws Exception { WorkingTree workingTree = geogig.getRepository().workingTree(); final String emptyTreeName = "emptyTree"; workingTree.createTypeTree(emptyTreeName, pointsType); geogig.command(AddOp.class).addPattern(emptyTreeName).call(); CommitOp commitCommand = geogig.command(CommitOp.class); RevCommit commit = commitCommand.call(); assertNotNull(commit); RevTree head = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()) .call(RevTree.class).get(); Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(emptyTreeName) .setParent(head).call(); assertTrue(ref.isPresent()); }
@Test public void testCheckoutBranchWithForceOptionAndChangesInTheIndex() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); Ref branch1 = geogig.command(BranchCreateOp.class).setName("branch1").call(); insertAndAdd(points2); CheckoutResult result = geogig.command(CheckoutOp.class).setSource("branch1").setForce(true) .call(); assertEquals(c1.getTreeId(), result.getNewTree()); assertTrue(geogig.command(RefParse.class).setName(Ref.HEAD).call().get() instanceof SymRef); assertEquals(branch1.getName(), ((SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get()) .getTarget()); }
@Test public void testCheckoutBranchWithForceOptionAndChangesInTheIndex() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); Ref branch1 = geogig.command(BranchCreateOp.class).setName("branch1").call(); insertAndAdd(points2); CheckoutResult result = geogig.command(CheckoutOp.class).setSource("branch1").setForce(true) .call(); assertEquals(c1.getTreeId(), result.getNewTree()); assertTrue(geogig.command(RefParse.class).setName(Ref.HEAD).call().get() instanceof SymRef); assertEquals(branch1.getName(), ((SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get()) .getTarget()); }
@Test public void testCreateBranchFromSomethingOtherThanCommit() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("Commit1").call(); insertAndAdd(points2); geogig.command(CommitOp.class).setMessage("Commit2").call(); insertAndAdd(points3); geogig.command(CommitOp.class).setMessage("Commit3").call(); exception.expect(IllegalArgumentException.class); geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true) .setSource(c1.getTreeId().toString()).call(); }
@Test public void testCreateBranchFromSomethingOtherThanCommit() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("Commit1").call(); insertAndAdd(points2); geogig.command(CommitOp.class).setMessage("Commit2").call(); insertAndAdd(points3); geogig.command(CommitOp.class).setMessage("Commit3").call(); exception.expect(IllegalArgumentException.class); geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true) .setSource(c1.getTreeId().toString()).call(); }