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; } }
private RevCommitBuilder testCommit(ObjectId treeId, String author, String authorEmail, long authorTimestamp, String committer, String committerEmail, long committerTimestamp, String message, ObjectId... parentIds) { RevCommitBuilder b = RevCommit.builder(); b.treeId(treeId); b.author(author); b.authorEmail(authorEmail); b.committer(committer); b.committerEmail(committerEmail); b.message(message); b.authorTimestamp(authorTimestamp); b.committerTimestamp(committerTimestamp); if (parentIds != null) { b.parentIds(Lists.newArrayList(parentIds)); } return b; }
@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); }
parents.addAll(secondaryParents); ObjectId endTree = until.getTreeId(); RevCommitBuilder builder = RevCommit.builder().init(until); Collection<ObjectId> filteredParents = Collections2.filter(parents, new Predicate<ObjectId>() { builder.parentIds(Lists.newArrayList(filteredParents)); builder.treeId(endTree); if (message == null) { message = since.getMessage(); builder.message(message); builder.committer(resolveCommitter()); builder.committerEmail(resolveCommitterEmail()); builder.committerTimestamp(timestamp); builder.committerTimeZoneOffset(platform.timeZoneOffset(timestamp)); builder.authorTimestamp(until.getAuthor().getTimestamp()); RevCommit newCommit = builder.build(); repository.objectDatabase().put(newCommit);
ObjectId head = squashedId; for (RevCommit commit : commits) { RevCommitBuilder builder = RevCommit.builder().init(commit); Function<ObjectId, ObjectId> fn = new Function<ObjectId, ObjectId>() { @Override builder.parentIds(Lists.newArrayList(parents)); builder.treeId(commit.getTreeId()); long timestamp = platform.currentTimeMillis(); builder.committerTimestamp(timestamp); builder.committerTimeZoneOffset(platform.timeZoneOffset(timestamp)); RevCommit newCommit = builder.build(); replacedCommits.put(commit.getId(), newCommit.getId()); objectDatabase().put(newCommit);
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; }
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; }
RevCommitBuilder builder = RevCommit.builder().init(commit); List<ObjectId> newParents = new LinkedList<ObjectId>(); for (ObjectId parentCommitId : commit.getParentIds()) { newParents.add(graphDatabase.getMapping(parentCommitId)); builder.parentIds(newParents); builder.treeId(newTreeId); RevCommit mapped = builder.build(); objectDatabase.put(mapped); RevCommitBuilder builder = RevCommit.builder().init(commit); List<ObjectId> newParents = new LinkedList<>(); for (ObjectId parentCommitId : commit.getParentIds()) { newParents.add(graphDatabase.getMapping(parentCommitId)); builder.parentIds(newParents); builder.treeId(rootTree.getId()); builder.message(PLACEHOLDER_COMMIT_MESSAGE); RevCommit mapped = builder.build(); objectDatabase.put(mapped);
RevCommitBuilder builder = RevCommit.builder().init(commitToApply); builder.parentIds(Arrays.asList(rebaseHead)); builder.treeId(newTreeId); builder.committerTimestamp(timestamp); builder.committerTimeZoneOffset(platform.timeZoneOffset(timestamp)); RevCommit newCommit = builder.build(); repository.objectDatabase().put(newCommit); RevCommitBuilder builder = RevCommit.builder().init(commitToApply); builder.parentIds(Arrays.asList(rebaseHead)); builder.treeId(newTreeId); builder.committerTimestamp(timestamp); builder.committerTimeZoneOffset(platform.timeZoneOffset(timestamp)); RevCommit newCommit = builder.build(); repository.objectDatabase().put(newCommit);
@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); }
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); }
builder.author(author.getName().orNull()); builder.authorEmail(author.getEmail().orNull()); builder.authorTimestamp(author.getTimestamp()); builder.authorTimeZoneOffset(author.getTimeZoneOffset()); builder.committer(committer.getName().orNull()); builder.committerEmail(committer.getEmail().orNull()); builder.committerTimestamp(committer.getTimestamp()); builder.committerTimeZoneOffset(committer.getTimeZoneOffset()); builder.message(message); builder.parentIds(parentIds); builder.treeId(ObjectId.valueOf(tree)); RevCommit commit = builder.build(); return commit;