Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.RevTree


    public void stage(final ProgressListener progress, final Iterator<DiffEntry> unstaged,
            final long numChanges) {
        int i = 0;
        progress.started();

        final RevTree currentIndexHead = getTree();

        Map<String, RevTreeBuilder> parentTress = Maps.newHashMap();
        Map<String, ObjectId> parentMetadataIds = Maps.newHashMap();
        Set<String> removedTrees = Sets.newHashSet();
        StagingDatabase database = getDatabase();
        while (unstaged.hasNext()) {
            final DiffEntry diff = unstaged.next();
            final String fullPath = diff.oldPath() == null ? diff.newPath() : diff.oldPath();
            final String parentPath = NodeRef.parentPath(fullPath);
            /*
             * TODO: revisit, ideally the list of diff entries would come with one single entry for
             * the whole removed tree instead of that one and every single children of it.
             */
            if (removedTrees.contains(parentPath)) {
                continue;
            }
            if (null == parentPath) {
                // it is the root tree that's been changed, update head and ignore anything else
                ObjectId newRoot = diff.newObjectId();
                updateStageHead(newRoot);
                progress.setProgress(100f);
                progress.complete();
                return;
            }
            RevTreeBuilder parentTree = getParentTree(currentIndexHead, parentPath, parentTress,
                    parentMetadataIds);

            i++;
            progress.setProgress((float) (i * 100) / numChanges);

            NodeRef oldObject = diff.getOldObject();
            NodeRef newObject = diff.getNewObject();
            if (newObject == null) {
                // Delete
                parentTree.remove(oldObject.name());
                if (TYPE.TREE.equals(oldObject.getType())) {
                    removedTrees.add(oldObject.path());
                }
            } else if (oldObject == null) {
                // Add
                Node node = newObject.getNode();
                parentTree.put(node);
                parentMetadataIds.put(newObject.path(), newObject.getMetadataId());
            } else {
                // Modify
                Node node = newObject.getNode();
                parentTree.put(node);
            }

            database.removeConflict(null, fullPath);
        }

        ObjectId newRootTree = currentIndexHead.getId();

        for (Map.Entry<String, RevTreeBuilder> entry : parentTress.entrySet()) {
            String changedTreePath = entry.getKey();
            RevTreeBuilder changedTreeBuilder = entry.getValue();
            RevTree changedTree = changedTreeBuilder.build();
            ObjectId parentMetadataId = parentMetadataIds.get(changedTreePath);
            if (NodeRef.ROOT.equals(changedTreePath)) {
                // root
                database.put(changedTree);
                newRootTree = changedTree.getId();
            } else {
                // parentMetadataId = parentMetadataId == null ?
                Supplier<RevTreeBuilder> rootTreeSupplier = getTreeSupplier();
                newRootTree = context.command(WriteBack.class).setAncestor(rootTreeSupplier)
                        .setChildPath(changedTreePath).setMetadataId(parentMetadataId)
View Full Code Here


        final SimpleFeatureStore targetStore = getTargetStore();

        final String refspec = resolveRefSpec();
        final String treePath = refspec.substring(refspec.indexOf(':') + 1);
        final RevTree rootTree = resolveRootTree(refspec);
        final NodeRef typeTreeRef = resolTypeTreeRef(refspec, treePath, rootTree);

        final ObjectId defaultMetadataId = typeTreeRef.getMetadataId();

        final RevTree typeTree = database.getTree(typeTreeRef.objectId());

        final ProgressListener progressListener = getProgressListener();

        progressListener.started();
        progressListener.setDescription("Exporting from " + path + " to "
View Full Code Here

                refspec.substring(0, refspec.indexOf(':'))).call();

        checkArgument(rootTreeId.isPresent(), "Invalid tree spec: %s",
                refspec.substring(0, refspec.indexOf(':')));

        RevTree rootTree = stagingDatabase().getTree(rootTreeId.get());
        return rootTree;
    }
View Full Code Here

     * @param path the path to the {@code Node} to search for
     * @return an {@link Optional} of the {@code Node} if it was found, or {@link Optional#absent()}
     *         if it wasn't found.
     */
    public Optional<NodeRef> find(final ObjectId rootTreeId, final String path) {
        RevTree tree = objectDb.get(rootTreeId, RevTree.class);
        if (tree == null) {
            return null;
        }
        return find(tree, path);
    }
View Full Code Here

        final List<String> parentSteps = Lists.newArrayList(Splitter.on(PATH_SEPARATOR)
                .omitEmptyStrings().split(parentPath));
        List<String> childSteps = Lists.newArrayList(Splitter.on(PATH_SEPARATOR).split(childPath));
        childSteps = childSteps.subList(parentSteps.size(), childSteps.size());

        RevTree subTree = parent;
        ObjectId metadataId = ObjectId.NULL;
        for (int i = 0; i < childSteps.size() - 1; i++) {
            String directChildName = childSteps.get(i);
            Optional<Node> subtreeRef = getDirectChild(subTree, directChildName, 0);
            if (!subtreeRef.isPresent()) {
View Full Code Here

        ImmutableSortedMap<Integer, Bucket> buckets = parent.buckets().get();
        Bucket subtreeBucket = buckets.get(bucket);
        if (subtreeBucket == null) {
            return Optional.absent();
        }
        RevTree subtree = objectDb.get(subtreeBucket.id(), RevTree.class);
        return getDirectChild(subtree, directChildName, subtreesDepth + 1);
    }
View Full Code Here

                        object = geogig.command(RevObjectParse.class)
                                .setObjectId(commit.getTreeId()).call();
                        Optional<NodeRef> node = Optional.absent();
                        if (object.isPresent()) {
                            RevTree tree = (RevTree) object.get();
                            node = geogig.command(FindTreeChild.class).setParent(tree)
                                    .setChildPath(input.getPath()).call();
                        } else {
                            throw new CommandSpecException("Couldn't resolve commit's treeId");
                        }
View Full Code Here

    protected  SimpleFeatureStore _call() {

        final SimpleFeatureStore targetStore = getTargetStore();

        final String refspec = old ? oldRef : newRef;
        final RevTree rootTree = resolveRootTree(refspec);
        final NodeRef typeTreeRef = resolTypeTreeRef(refspec, path, rootTree);
        final ObjectId defaultMetadataId = typeTreeRef.getMetadataId();

        final ProgressListener progressListener = getProgressListener();
View Full Code Here

    private RevTree resolveRootTree(final String refspec) {
        Optional<ObjectId> rootTreeId = command(ResolveTreeish.class).setTreeish(refspec).call();

        checkArgument(rootTreeId.isPresent(), "Invalid tree spec: %s", refspec);

        RevTree rootTree = stagingDatabase().getTree(rootTreeId.get());
        return rootTree;
    }
View Full Code Here

     */
    public synchronized RevTree getTree() {
        Optional<ObjectId> workTreeId = context.command(ResolveTreeish.class)
                .setTreeish(Ref.WORK_HEAD).call();

        RevTree workTree = RevTree.EMPTY;

        if (workTreeId.isPresent()) {
            if (!workTreeId.get().equals(RevTree.EMPTY_TREE_ID)) {
                workTree = context.stagingDatabase().getTree(workTreeId.get());
            }
        } else {
            // Work tree was not resolved, update it to the head.
            Optional<ObjectId> headTreeId = context.command(ResolveTreeish.class)
                    .setTreeish(Ref.HEAD).call();

            if (headTreeId.isPresent() && !headTreeId.get().equals(RevTree.EMPTY_TREE_ID)) {
                workTree = context.objectDatabase().getTree(headTreeId.get());
                updateWorkHead(workTree.getId());
            }
        }
        Preconditions.checkState(workTree != null);
        return workTree;
    }
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.api.RevTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.