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())); }
@Override public void funnel(RevCommit from, PrimitiveSink into) { funnel(into, from.getTreeId(), from.getParentIds(), from.getMessage(), from.getAuthor(), from.getCommitter()); }
private String fmt(RevCommit c) { String msg = c.getMessage(); if (msg.length() > 30) { msg = msg.substring(0, 30) + "..."; } return String.format("%s (%s)", c.getId().toString().substring(0, 8), msg); }
@Override public void callback(Supplier<RevObject> supplier) { RevObject object = supplier.get(); progress.setProgress(progress.getProgress() + 1); if (object instanceof RevCommit) { RevCommit commit = (RevCommit) object; toSend.remove(commit.getId()); roots.removeAll(commit.getParentIds()); roots.add(commit.getId()); } } };
private void assertCommit(RevCommit commit, @Nullable ObjectId parentId, String author, String message) { assertNotNull(commit); assertEquals(parentId == null ? 0 : 1, commit.getParentIds().size()); assertEquals(parentId, commit.parentN(0).orNull()); assertNotNull(commit.getTreeId()); assertNotNull(commit.getId()); if (author != null) { assertEquals(author, commit.getAuthor().getName().get()); } if (message != null) { assertEquals(message, commit.getMessage()); } assertNotNull(repo.getTree(commit.getTreeId())); assertEquals(commit.getId(), getRepository().getRef(Ref.HEAD).get().getObjectId()); }
/** * @param left the left {@link RevCommit} */ public FindCommonAncestor setLeft(RevCommit left) { this.left = left.getId(); return this; }
@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); }
@Test public void testSquashAtBranchTip() throws Exception { List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3); List<RevCommit> commits = Lists.newArrayList(); for (Feature f : features) { insertAndAdd(f); final RevCommit commit = geogig.command(CommitOp.class).call(); commits.add(commit); } geogig.command(SquashOp.class).setSince(commits.get(1)).setUntil(commits.get(5)).call(); Iterator<RevCommit> log = geogig.command(LogOp.class).call(); ArrayList<RevCommit> logentries = Lists.newArrayList(log); assertEquals(2, logentries.size()); RevCommit squashedCommit = logentries.get(0); RevCommit presquashCommit = logentries.get(1); assertEquals(commits.get(5).getTreeId(), squashedCommit.getTreeId()); assertEquals(commits.get(1).getMessage(), squashedCommit.getMessage()); assertEquals(commits.get(5).getAuthor().getTimestamp(), squashedCommit.getAuthor().getTimestamp()); assertEquals(commits.get(0).getTreeId(), presquashCommit.getTreeId()); }
@Test public void testCommitUsingCommit() throws Exception { insertAndAdd(points1); final RevCommit commit = geogig.command(CommitOp.class) .setCommitter("anothercommitter", "anothercommitter@boundlessgeo.com").call(); insertAndAdd(points2); RevCommit commit2 = geogig.command(CommitOp.class).setCommit(commit).call(); assertEquals(commit.getMessage(), commit2.getMessage()); assertEquals(commit.getAuthor(), commit2.getAuthor()); assertNotSame(commit.getCommitter(), commit2.getCommitter()); }
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); }
@Test public void testEmptyCommit() throws Exception { CommitOp commitCommand = geogig.command(CommitOp.class); RevCommit commit = commitCommand.setAllowEmpty(true).call(); assertNotNull(commit); assertNotNull(commit.getParentIds()); assertEquals(0, commit.getParentIds().size()); assertFalse(commit.parentN(0).isPresent()); assertNotNull(commit.getId()); ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get(); assertEquals(commit.getId(), commitId); }
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 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 testCommitWithExplicitNullAuthorEmail() throws Exception { CommitOp commitCommand = geogig.command(CommitOp.class); commitCommand.setAuthor("John Doe", null); commitCommand.setAllowEmpty(true); RevCommit commit = commitCommand.call(); assertFalse(commit.getAuthor().getEmail().isPresent()); assertEquals("groldan", commit.getCommitter().getName().get()); assertEquals("groldan@boundlessgeo.com", commit.getCommitter().getEmail().get()); assertEquals("John Doe", commit.getAuthor().getName().get()); }
private String messageTitle(RevCommit commit) { String message = Optional.fromNullable(commit.getMessage()).or(""); int newline = message.indexOf('\n'); return newline == -1 ? message : message.substring(0, newline); }
public @Override void findSuccessors(final Object object, final List<Object> successors, ObjectStore database) { if (object instanceof RevCommit) { final RevCommit commit = (RevCommit) object; Iterator<RevCommit> parents = database.getAll(commit.getParentIds(), NOOP_LISTENER, RevCommit.class); parents.forEachRemaining((o) -> successors.add(o)); } }
@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 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()); }
@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()); }
@Override protected Optional<RevCommit> _call() { Preconditions.checkState(date != null); long time = date.getTime(); Iterator<RevCommit> iter = command(LogOp.class).setFirstParentOnly(true).call(); while (iter.hasNext()) { RevCommit commit = iter.next(); if (commit.getCommitter().getTimestamp() < time) { return Optional.of(commit); } } return Optional.absent(); }