@Override public RevObject get(ObjectId id) throws IllegalArgumentException { return subject.get().get(id); }
protected @Override java.util.Optional<RevCommit> _call() { Preconditions.checkNotNull(commitIsh, "commit-ish not provided"); final ObjectId id = context.command(RevParse.class).setRefSpec(commitIsh).call().orNull(); RevCommit commit = null; if (id != null) { ObjectDatabase db = context.objectDatabase(); RevObject obj = db.get(id); switch (obj.getType()) { case COMMIT: commit = (RevCommit) obj; break; case TAG: commit = db.getCommit(((RevTag) obj).getCommitId()); break; default: throw new IllegalArgumentException( String.format("'%s' resolves to a %s, not a comit", obj.getType())); } } return Optional.ofNullable(commit); }
@Override public RevObject get(ObjectId id) throws IllegalArgumentException { return subject.get().get(id); }
@Override public <T extends RevObject> T get(ObjectId id, Class<T> type) throws IllegalArgumentException { return subject.get().get(id, type); }
@Override public <T extends RevObject> T get(ObjectId id, Class<T> type) throws IllegalArgumentException { return subject.get().get(id, type); }
public RevObject getRevObject(RepositoryProvider provider, String repoName, ObjectId oid) { Repository repository = getRepository(provider, repoName); if (repository != null) { return repository.objectDatabase().get(oid); } return null; }
/** * Determines if a commit with the given {@link ObjectId} exists in the object database. * * @param id the id to look for * @return true if the object was found, false otherwise */ @Override public boolean commitExists(final ObjectId id) { try { RevObject revObject = context().objectDatabase().get(id); return revObject instanceof RevCommit; } catch (IllegalArgumentException e) { return false; } }
/** * Determines if a commit with the given {@link ObjectId} exists in the object database. * * @param id the id to look for * @return true if the object was found, false otherwise */ @Override public boolean commitExists(final ObjectId id) { try { RevObject revObject = context().objectDatabase().get(id); return revObject instanceof RevCommit; } catch (IllegalArgumentException e) { return false; } }
@Test public void testCreateNewRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); verify(injector, times(1)).repository(); verify(mockUpdateRef, times(1)).setName(eq(Ref.MASTER)); verify(mockUpdateRef, times(1)).setName(eq(Ref.WORK_HEAD)); verify(mockUpdateRef, times(1)).setName(eq(Ref.STAGE_HEAD)); verify(mockUpdateRef, times(1)).setNewValue(eq(ObjectId.NULL)); verify(mockUpdateRef, times(2)).setNewValue(eq(RevTree.EMPTY_TREE_ID)); verify(mockUpdateRef, times(3)).setReason(anyString()); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).setName(eq(Ref.HEAD)); verify(mockUpdateSymRef, times(1)).setNewValue(eq(Ref.MASTER)); verify(mockUpdateSymRef, times(1)).call(); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
@Test public void testCreateNewRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); verify(injector, times(1)).repository(); verify(mockUpdateRef, times(1)).setName(eq(Ref.MASTER)); verify(mockUpdateRef, times(1)).setName(eq(Ref.WORK_HEAD)); verify(mockUpdateRef, times(1)).setName(eq(Ref.STAGE_HEAD)); verify(mockUpdateRef, times(1)).setNewValue(eq(ObjectId.NULL)); verify(mockUpdateRef, times(2)).setNewValue(eq(RevTree.EMPTY_TREE_ID)); verify(mockUpdateRef, times(3)).setReason(anyString()); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).setName(eq(Ref.HEAD)); verify(mockUpdateSymRef, times(1)).setNewValue(eq(Ref.MASTER)); verify(mockUpdateSymRef, times(1)).call(); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
private void copy(Bounded nodeOrBucket) { if (nodeOrBucket != null) { ObjectId objectId = nodeOrBucket.getObjectId(); if (!RevTree.EMPTY_TREE_ID.equals(objectId)) { RevObject object = leftSource.get(objectId); rightSource.put(object); } } }
private void copy(Bounded nodeOrBucket) { if (nodeOrBucket != null) { ObjectId objectId = nodeOrBucket.getObjectId(); if (!RevTree.EMPTY_TREE_ID.equals(objectId)) { RevObject object = leftSource.get(objectId); rightSource.put(object); } } }
private int depth(RevTree deepTree, int currDepth) { if (deepTree.bucketsSize() == 0) { return currDepth; } int depth = currDepth; for (Bucket bucket : deepTree.getBuckets()) { RevTree bucketTree = odb.get(bucket.getObjectId(), RevTree.class); int d = depth(bucketTree, currDepth + 1); depth = Math.max(depth, d); } return depth; }
@Test public void testReinitializeExistingRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).call(); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); Ref master = new Ref(Ref.MASTER, RevObjectTestSupport.hashString("hash me")); when(mockRefParse.call()).thenReturn(Optional.of(master)); Context injector = mock(Context.class); when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse); when(injector.platform()).thenReturn(platform); when(injector.repository()).thenReturn(mockRepo); init.setContext(injector); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); verify(injector, never()).command(eq(UpdateRef.class)); verify(injector, never()).command(eq(UpdateSymRef.class)); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
@Test public void testReinitializeExistingRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).call(); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); Ref master = new Ref(Ref.MASTER, RevObjectTestSupport.hashString("hash me")); when(mockRefParse.call()).thenReturn(Optional.of(master)); Context injector = mock(Context.class); when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse); when(injector.platform()).thenReturn(platform); when(injector.repository()).thenReturn(mockRepo); init.setContext(injector); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); verify(injector, never()).command(eq(UpdateRef.class)); verify(injector, never()).command(eq(UpdateSymRef.class)); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
private NodeRef filter(NodeRef node) { if (node == null) { return null; } RevObject object = sourceRepo.objectDatabase().get(node.getObjectId()); RevObject metadata = null; if (!node.getMetadataId().isNull()) { metadata = sourceRepo.objectDatabase().get(node.getMetadataId()); } if (node.getType() == TYPE.FEATURE) { if (trackingObject(object.getId())) { // We are already tracking this object, continue to do so return node; } RevFeatureType revFeatureType = (RevFeatureType) metadata; if (!repoFilter.filterObject(revFeatureType, node.getParentPath(), object)) { return null; } } processObject(object); processObject(metadata); return node; }
private NodeRef filter(NodeRef node) { if (node == null) { return null; } RevObject object = sourceRepo.objectDatabase().get(node.getObjectId()); RevObject metadata = null; if (!node.getMetadataId().isNull()) { metadata = sourceRepo.objectDatabase().get(node.getMetadataId()); } if (node.getType() == TYPE.FEATURE) { if (trackingObject(object.getId())) { // We are already tracking this object, continue to do so return node; } RevFeatureType revFeatureType = (RevFeatureType) metadata; if (!repoFilter.filterObject(revFeatureType, node.getParentPath(), object)) { return null; } } processObject(object); processObject(metadata); return node; }
private int depth(RevTree deepTree, int currDepth) { if (deepTree.buckets().isEmpty()) { return currDepth; } int depth = currDepth; for (Bucket bucket : deepTree.buckets().values()) { RevTree bucketTree = odb.get(bucket.getObjectId(), RevTree.class); int d = depth(bucketTree, currDepth + 1); depth = Math.max(depth, d); } return depth; }
@Test public void testAmendNoChanges() throws Exception { final ObjectId id = insertAndAdd(points1); final RevCommit commit1 = geogig.command(CommitOp.class).setMessage("Message").call(); { assertCommit(commit1, null, null, null); assertEquals(id, repo.getRootTreeChild(appendChild(pointsName, idP1)).get().getObjectId()); assertNotNull(repo.objectDatabase().get(id)); } exception.expect(IllegalArgumentException.class); exception.expectMessage( "You must specify a new commit message, timestamp, or commit to reuse when amending a commit with no changes."); geogig.command(CommitOp.class).setAmend(true).call(); }
@Test public void testAmendNoChanges() throws Exception { final ObjectId id = insertAndAdd(points1); final RevCommit commit1 = geogig.command(CommitOp.class).setMessage("Message").call(); { assertCommit(commit1, null, null, null); assertEquals(id, repo.getRootTreeChild(appendChild(pointsName, idP1)).get().getObjectId()); assertNotNull(repo.objectDatabase().get(id)); } exception.expect(IllegalArgumentException.class); exception.expectMessage( "You must specify a new commit message, timestamp, or commit to reuse when amending a commit with no changes."); geogig.command(CommitOp.class).setAmend(true).call(); }