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; }
public RevCommit build() { if (treeId == null) { throw new IllegalStateException("No tree id set"); } if (platform == null) { platform = new DefaultPlatform(); } final long now = platform.currentTimeMillis(); final int tzOffset = platform.timeZoneOffset(now); long committerTs = committerTimestamp == null ? now : committerTimestamp; int committerOffset = committerTimeZoneOffset == null ? tzOffset : committerTimeZoneOffset; long authorTs = authorTimestamp == null ? committerTs : authorTimestamp; int authorOffset = authorTimeZoneOffset == null ? committerOffset : authorTimeZoneOffset; final ObjectId treeId = this.treeId; final ImmutableList<ObjectId> parentIds = this.parentIds == null ? ImmutableList.of() : ImmutableList.copyOf(this.parentIds); final RevPerson author = RevPerson.builder().build(this.author, authorEmail, authorTs, authorOffset); final RevPerson committer = RevPerson.builder().build(this.committer, committerEmail, committerTs, committerOffset); final String commitMessage = this.message == null ? "" : this.message; return build(treeId, parentIds, author, committer, commitMessage); }
@Test public void testCommitSerialization() throws IOException { RevCommit commit = testCommit.build(); testCommit(commit); }
public void testBuildEmpty() throws Exception { RevCommitBuilder b = RevCommit.builder(); try { b.build(); fail("expected IllegalStateException on null tree id"); } catch (IllegalStateException e) { assertTrue(e.getMessage().contains("tree")); } }
@Test public void testCommitSerializationMultipleLinesMessage() throws IOException { testCommit.message("this\n is a \n multiple lines\n message"); RevCommit commit = testCommit.build(); testCommit(commit); }
@Test public void testCommitSerializationNoMessage() throws IOException { testCommit.message(null); RevCommit commit = testCommit.build(); testCommit(commit); }
@Test public void testCommitSerializationNoParents() throws IOException { testCommit.parentIds(null); RevCommit commit = testCommit.build(); testCommit(commit); }
builder.parentIds(parentIds); builder.treeId(ObjectId.valueOf(tree)); RevCommit commit = builder.build(); return commit;
@Test public void testCommitSerializationNoCommitter() throws IOException { testCommit.committer(null); testCommit.committerEmail(null); RevCommit commit = testCommit.build(); testCommit(commit); }
@Test public void testCommitSerializationNoAuthor() throws IOException { testCommit.author(null); testCommit.authorEmail(null); RevCommit commit = testCommit.build(); testCommit(commit); }
@Test public void testCommitSerializationMultipleParents() throws IOException { testCommit.parentIds(ImmutableList.of(RevObjectTestSupport.hashString("parent1"), RevObjectTestSupport.hashString("parent2"), RevObjectTestSupport.hashString("parent3"), RevObjectTestSupport.hashString("parent4"))); RevCommit commit = testCommit.build(); testCommit(commit); }
builder.committerTimeZoneOffset(platform.timeZoneOffset(timestamp)); RevCommit newCommit = builder.build(); replacedCommits.put(commit.getId(), newCommit.getId()); objectDatabase().put(newCommit);
public static List<RevCommit> createCommits(final int numCommits, @Nullable Platform platform) { LinkedList<RevCommit> commits = new LinkedList<>(); // much faster way of creating several fake commits than running CommitOp N times RevCommitBuilder builder = RevCommit.builder().platform(platform); long timeStamp = System.currentTimeMillis(); builder.author("gabe").authorEmail("gabe@example.com").committer("me") .committerEmail("me@too.com").committerTimestamp(timeStamp) .committerTimeZoneOffset(-1).authorTimestamp(timeStamp).authorTimeZoneOffset(-3) .treeId(RevTree.EMPTY_TREE_ID); ObjectId parent = null; for (int i = 1; i <= numCommits; i++) { ++timeStamp; builder.authorTimestamp(timeStamp).committerTimestamp(timeStamp); List<ObjectId> parents = parent == null ? null : ImmutableList.of(parent); RevCommit commit = builder.parentIds(parents).message("commit " + i).build(); commits.addFirst(commit); parent = commit.getId(); } return commits; } }
@Test public void testPassingNullToSetParentIds() throws Exception { RevCommitBuilder b = RevCommit.builder(); b.author("groldan"); b.authorEmail("groldan@boundlessgeo.com"); b.committer("jdeolive"); b.committerEmail("jdeolive@boundlessgeo.com"); b.message("cool this works"); b.authorTimestamp(1000L); ObjectId treeId = hashString("fake tree content"); b.treeId(treeId); b.parentIds(null); assertEquals(ImmutableList.of(), b.build().getParentIds()); }
@Test public void testNoAuthorTimeStamp() throws Exception { RevCommitBuilder b = RevCommit.builder(); b.author("groldan"); b.authorEmail("groldan@boundlessgeo.com"); b.committer("jdeolive"); b.committerEmail("jdeolive@boundlessgeo.com"); b.committerTimestamp(1000L); b.message("cool this works"); b.treeId(hashString("some tree id")); assertEquals(1000, b.build().getAuthor().getTimestamp()); }
@Test public void testNoMessage() throws Exception { RevCommitBuilder b = RevCommit.builder(); b.author("groldan"); b.authorEmail("groldan@boundlessgeo.com"); b.committer("jdeolive"); b.committerEmail("jdeolive@boundlessgeo.com"); b.message(null); b.authorTimestamp(1000L); ObjectId treeId = hashString("fake tree content"); b.treeId(treeId); ObjectId parentId1 = hashString("fake parent content 1"); ObjectId parentId2 = hashString("fake parent content 2"); List<ObjectId> parentIds = ImmutableList.of(parentId1, parentId2); b.parentIds(parentIds); assertEquals(null, b.message()); RevCommit commit2 = b.build(); assertEquals("", commit2.getMessage()); }
private void createCommit(RevCommit commit) { // write new tree ObjectId newTreeId = command(WriteTree2.class).call(); long timestamp = platform().currentTimeMillis(); String committerName = resolveCommitter(); String committerEmail = resolveCommitterEmail(); // Create new commit RevCommitBuilder builder = RevCommit.builder(); builder.parentIds(Arrays.asList(revertHead)); builder.treeId(newTreeId); builder.committerTimestamp(timestamp); builder.message( "Revert '" + commit.getMessage() + "'\nThis reverts " + commit.getId().toString()); builder.committer(committerName); builder.committerEmail(committerEmail); builder.author(committerName); builder.authorEmail(committerEmail); RevCommit newCommit = builder.build(); objectDatabase().put(newCommit); revertHead = newCommit.getId(); command(UpdateRef.class).setName(currentBranch).setNewValue(revertHead).call(); command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(currentBranch).call(); workingTree().updateWorkHead(newTreeId); stagingArea().updateStageHead(newTreeId); }
private RevTree createHeadTree(NodeRef... treeRefs) { RevTree root = createFromRefs(objectDb, treeRefs); objectDb.put(root); RevCommitBuilder cb = RevCommit.builder().platform(geogig.getPlatform()); ObjectId treeId = root.getId(); RevCommit commit = cb.treeId(treeId).committer("Gabriel Roldan").author("Gabriel Roldan") .build(); objectDb.put(commit); SymRef head = (SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get(); final String currentBranch = head.getTarget(); geogig.command(UpdateRef.class).setName(currentBranch).setNewValue(commit.getId()).call(); verifyRepositoryTree(NodeRef.ROOT, treeId); verifyTreeStructure(treeId, treeRefs); return root; }
@Test public void testCommitBuilder() throws Exception { RevCommitBuilder b = RevCommit.builder(); b.author("groldan"); b.authorEmail("groldan@boundlessgeo.com"); b.committer("jdeolive"); b.committerEmail("jdeolive@boundlessgeo.com"); b.message("cool this works"); b.authorTimestamp(1000L); ObjectId treeId = hashString("fake tree content"); b.treeId(treeId); ObjectId parentId1 = hashString("fake parent content 1"); ObjectId parentId2 = hashString("fake parent content 2"); List<ObjectId> parentIds = ImmutableList.of(parentId1, parentId2); b.parentIds(parentIds); RevCommit commit1 = b.build(); RevCommitBuilder builder = RevCommit.builder().init(commit1); assertEquals("groldan", builder.author()); assertEquals("jdeolive", builder.committer()); assertEquals("groldan@boundlessgeo.com", builder.authorEmail()); assertEquals("jdeolive@boundlessgeo.com", builder.committerEmail()); assertEquals(commit1.getMessage(), builder.message()); assertEquals(commit1.getParentIds(), builder.parentIds()); assertEquals(commit1.getTreeId(), builder.treeId()); assertEquals(commit1.getAuthor().getTimestamp(), builder.authorTimestamp().longValue()); RevCommit commit2 = builder.build(); assertEquals(commit1, commit2); }
b.parentIds(parentIds); RevCommit build = b.build(); assertNotNull(build.getId()); assertFalse(build.getId().isNull());