public void truncate() { synchronized (delegate) { delegate.truncate(); } }
public boolean exists(final ObjectId commitId) { synchronized (delegate) { return delegate.exists(commitId); } }
public int getDepth(final ObjectId commitId) { synchronized (delegate) { return delegate.getDepth(commitId); } }
@Test public void testTruncate() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); database.put(rootId, ImmutableList.of()); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); database.put(commit1, ImmutableList.of(rootId)); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); database.put(commit2, ImmutableList.of(commit1, rootId)); assertTrue(database.exists(rootId)); assertTrue(database.exists(commit1)); assertTrue(database.exists(commit2)); assertNotNull(database.getNode(rootId)); assertNotNull(database.getNode(commit1)); assertNotNull(database.getNode(commit2)); assertEquals(1, database.getDepth(commit2)); database.truncate(); // not using getNode for assertions cause it's contract is not well defined for an invalid // argument and implementations behave differently. Created an issue to fix it. // assertNull(database.getNode(rootId)); // assertNull(database.getNode(commit1)); // assertNull(database.getNode(commit2)); // assertEquals(0, database.getDepth(commit2)); assertFalse(database.exists(rootId)); assertFalse(database.exists(commit1)); assertFalse(database.exists(commit2)); }
GraphDatabase graphDatabase = local.graphDatabase(); ObjectStore objectDatabase = local.objectDatabase(); graphDatabase.put(commit.getId(), commit.getParentIds()); ObjectId mappedCommit = graphDatabase.getMapping(commit.getParentIds().get(0)); graphDatabase.map(commit.getId(), mappedCommit); Optional<ObjectId> treeId = local.command(ResolveTreeish.class) .setTreeish(mappedCommit).call(); graphDatabase.map(commit.getId(), ObjectId.NULL); List<ObjectId> newParents = new LinkedList<ObjectId>(); for (ObjectId parentCommitId : commit.getParentIds()) { newParents.add(graphDatabase.getMapping(parentCommitId)); graphDatabase.setProperty(mapped.getId(), GraphDatabase.SPARSE_FLAG, "true"); graphDatabase.map(mapped.getId(), commit.getId()); graphDatabase.map(commit.getId(), mapped.getId()); } else if (allowEmpty) { RevCommitBuilder builder = RevCommit.builder().init(commit); List<ObjectId> newParents = new LinkedList<>(); for (ObjectId parentCommitId : commit.getParentIds()) { newParents.add(graphDatabase.getMapping(parentCommitId)); graphDatabase.setProperty(mapped.getId(), GraphDatabase.SPARSE_FLAG, "true");
ObjectId rootId = RevObjectTestSupport.hashString("root"); ImmutableList<ObjectId> parents = ImmutableList.of(); database.put(rootId, parents); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); parents = ImmutableList.of(rootId); database.put(commit1, parents); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); parents = ImmutableList.of(commit1); database.put(commit2, parents); ImmutableList<ObjectId> children = database.getChildren(commit2); parents = database.getParents(commit2); assertTrue(database.exists(commit2)); assertEquals("Size of " + children, 0, children.size()); assertEquals(1, parents.size()); assertEquals(commit1, parents.get(0)); children = database.getChildren(commit1); parents = database.getParents(commit1); assertTrue(database.exists(commit1)); assertEquals(1, children.size()); assertEquals(commit2, children.get(0)); assertEquals(1, parents.size()); assertEquals(rootId, parents.get(0)); children = database.getChildren(rootId); parents = database.getParents(rootId); assertTrue(database.exists(rootId)); assertEquals(1, children.size()); assertEquals(commit1, children.get(0));
@Test public void testProperties() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); ImmutableList<ObjectId> parents = ImmutableList.of(); database.put(rootId, parents); database.setProperty(rootId, GraphDatabase.SPARSE_FLAG, "true"); assertTrue(database.getNode(rootId).isSparse()); }
@Test public void testMapNode() throws IOException { ObjectId commitId = RevObjectTestSupport.hashString("commitId"); ObjectId mappedId = RevObjectTestSupport.hashString("mapped"); database.put(commitId, new ImmutableList.Builder<ObjectId>().build()); database.map(mappedId, commitId); ObjectId mapping = database.getMapping(mappedId); assertEquals(commitId + " : " + mappedId + " : " + mapping, commitId, mapping); // update mapping ObjectId commitId2 = RevObjectTestSupport.hashString("commitId2"); database.map(mappedId, commitId2); mapping = database.getMapping(mappedId); assertEquals(commitId2 + " : " + mappedId + " : " + mapping, commitId2, mapping); }
newParents.add(0, from.graphDatabase().getMapping(parentId)); continue; newParents.add(from.graphDatabase().getMapping(parentId)); parent = from.graphDatabase().getMapping(newParents.get(0)); if (line != null) { ObjectId remoteCommitId = ObjectId.valueOf(line); from.graphDatabase().map(commit.getId(), remoteCommitId); from.graphDatabase().map(remoteCommitId, commit.getId());
public ObjectId getMapping(ObjectId commitId) { synchronized (delegate) { return delegate.getMapping(commitId); } }
public ImmutableList<ObjectId> getParents(ObjectId commitId) throws IllegalArgumentException { synchronized (delegate) { return delegate.getParents(commitId); } }
@Test public void testGetParents() { ObjectId rootId = RevObjectTestSupport.hashString("root"); database.put(rootId, ImmutableList.of()); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); database.put(commit1, ImmutableList.of(rootId)); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); database.put(commit2, ImmutableList.of(commit1, rootId)); ImmutableList<ObjectId> parents = database.getParents(rootId); assertEquals(0, parents.size()); parents = database.getParents(commit1); assertEquals(1, parents.size()); assertTrue(parents.contains(rootId)); parents = database.getParents(commit2); assertEquals(2, parents.size()); assertEquals(commit1, parents.get(0)); assertEquals(rootId, parents.get(1)); parents = database.getParents(RevObjectTestSupport.hashString("nonexistent")); assertEquals(0, parents.size()); }
public boolean put(ObjectId commitId, ImmutableList<ObjectId> parentIds) { synchronized (delegate) { return delegate.put(commitId, parentIds); } }
public void setProperty(ObjectId commitId, String propertyName, String propertyValue) { synchronized (delegate) { delegate.setProperty(commitId, propertyName, propertyValue); } }
@Test public void testGetChildren() { ObjectId rootId = RevObjectTestSupport.hashString("root"); database.put(rootId, ImmutableList.of()); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); database.put(commit1, ImmutableList.of(rootId)); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); database.put(commit2, ImmutableList.of(commit1, rootId)); ImmutableList<ObjectId> children = database.getChildren(rootId); assertEquals(2, children.size()); assertTrue(children.contains(commit1)); assertTrue(children.contains(commit2)); children = database.getChildren(commit1); assertEquals(1, children.size()); assertTrue(children.contains(commit2)); children = database.getChildren(commit2); assertEquals(0, children.size()); children = database.getChildren(RevObjectTestSupport.hashString("nonexistent")); assertEquals(0, children.size()); }
public void map(ObjectId mapped, ObjectId original) { synchronized (delegate) { delegate.map(mapped, original); } }
public ImmutableList<ObjectId> getChildren(ObjectId commitId) throws IllegalArgumentException { synchronized (delegate) { return delegate.getChildren(commitId); } }
public void close() { synchronized (delegate) { delegate.close(); } }
@Test public void testTruncate() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); database.put(rootId, ImmutableList.of()); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); database.put(commit1, ImmutableList.of(rootId)); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); database.put(commit2, ImmutableList.of(commit1, rootId)); assertTrue(database.exists(rootId)); assertTrue(database.exists(commit1)); assertTrue(database.exists(commit2)); assertNotNull(database.getNode(rootId)); assertNotNull(database.getNode(commit1)); assertNotNull(database.getNode(commit2)); assertEquals(1, database.getDepth(commit2)); database.truncate(); // not using getNode for assertions cause it's contract is not well defined for an invalid // argument and implementations behave differently. Created an issue to fix it. // assertNull(database.getNode(rootId)); // assertNull(database.getNode(commit1)); // assertNull(database.getNode(commit2)); // assertEquals(0, database.getDepth(commit2)); assertFalse(database.exists(rootId)); assertFalse(database.exists(commit1)); assertFalse(database.exists(commit2)); }