Package org.locationtech.geogig.repository

Examples of org.locationtech.geogig.repository.Repository


            final String id = (String) request.getAttributes().get("id");
            final ObjectId oid = ObjectId.valueOf(id);

            GeoGIG geogig = ggit.get();
            Repository repository = geogig.getRepository();
            boolean blobExists = repository.blobExists(oid);
            if (blobExists) {
                ObjectResource objectResource = new ObjectResource(oid, geogig);
                objectResource.init(getContext(), request, response);
                return objectResource;
            }
View Full Code Here


            this.ggit = ggit;
        }

        @Override
        public void write(OutputStream out) throws IOException {
            Repository repository = ggit.getRepository();
            RevObject rawObject = repository.objectDatabase().get(oid);
            serialFac.createObjectWriter(rawObject.getType()).write(rawObject, out);
        }
View Full Code Here

                }
            }

            Request request = getRequest();
            final GeoGIG ggit = getGeogig(request).get();
            final Repository repository = ggit.getRepository();
            final Deduplicator deduplicator = ggit.command(CreateDeduplicator.class).call();

            BinaryPackedObjects packer = new BinaryPackedObjects(repository.stagingDatabase());
            Representation rep = new RevObjectBinaryRepresentation(packer, want, have, deduplicator);
            Response response = getResponse();
            response.setEntity(rep);
        }
View Full Code Here

            command(UpdateRef.class).setName(Ref.ORIG_HEAD)
                    .setNewValue(currHead.get().getObjectId()).call();

            // Here we prepare the files with the info about the commits to apply in reverse
            List<RevCommit> commitsToRevert = Lists.newArrayList();
            Repository repository = repository();
            for (ObjectId id : commits) {
                Preconditions.checkArgument(repository.commitExists(id),
                        "Commit was not found in the repository: " + id.toString());
                RevCommit commit = repository.getCommit(id);
                commitsToRevert.add(commit);
            }
            createRevertCommitsInfoFiles(commitsToRevert);

        }
View Full Code Here

    }

    private boolean applyNextCommit(boolean useCommitChanges) {
        File rebaseFolder = getRevertFolder();
        File nextFile = new File(rebaseFolder, "next");
        Repository repository = repository();
        try {
            String idx = Files.readFirstLine(nextFile, Charsets.UTF_8);
            File commitFile = new File(rebaseFolder, idx);
            if (commitFile.exists()) {
                String commitId = Files.readFirstLine(commitFile, Charsets.UTF_8);
                RevCommit commit = repository.getCommit(ObjectId.valueOf(commitId));
                List<Conflict> conflicts = Lists.newArrayList();
                if (useCommitChanges) {
                    conflicts = applyRevertedChanges(commit);
                }
                if (createCommit && conflicts.isEmpty()) {
                    createCommit(commit);
                } else {
                    workingTree().updateWorkHead(repository.index().getTree().getId());
                    if (!conflicts.isEmpty()) {
                        // mark conflicted elements
                        command(ConflictsWriteOp.class).setConflicts(conflicts).call();

                        // created exception message
View Full Code Here

        ObjectId parentCommitId = ObjectId.NULL;
        if (commit.getParentIds().size() > 0) {
            parentCommitId = commit.getParentIds().get(0);
        }
        ObjectId parentTreeId = ObjectId.NULL;
        Repository repository = repository();
        if (repository.commitExists(parentCommitId)) {
            parentTreeId = repository.getCommit(parentCommitId).getTreeId();
        }

        // get changes (in reverse)
        Iterator<DiffEntry> reverseDiff = command(DiffTree.class).setNewTree(parentTreeId)
                .setOldTree(commit.getTreeId()).setReportTrees(false).call();

        ObjectId headTreeId = repository.getCommit(revertHead).getTreeId();
        final RevTree headTree = repository.getTree(headTreeId);

        ArrayList<Conflict> conflicts = new ArrayList<Conflict>();
        DiffEntry diff;
        while (reverseDiff.hasNext()) {
            diff = reverseDiff.next();
View Full Code Here

     */
    private long insertChanges(GeogigCLI cli, final Iterator<Change> changes,
            @Nullable Envelope featureFilter) throws IOException {

        final GeoGIG geogig = cli.getGeogig();
        final Repository repository = geogig.getRepository();
        final WorkingTree workTree = repository.workingTree();

        Map<Long, Coordinate> thisChangePointCache = new LinkedHashMap<Long, Coordinate>() {
            /** serialVersionUID */
            private static final long serialVersionUID = 1277795218777240552L;

View Full Code Here

        }

        Preconditions.checkState(!ObjectId.NULL.equals(commit.get()),
                "Commit could not be resolved.");

        Repository repository = repository();
        RevCommit oldCommit = repository.getCommit(commit.get());

        if (patterns.size() > 0) {
            for (String pattern : patterns) {
                DiffTree diffOp = command(DiffTree.class)
                        .setOldTree(repository.index().getTree().getId())
                        .setNewTree(oldCommit.getTreeId()).setPathFilter(pattern);

                Iterator<DiffEntry> diff = diffOp.call();

                final long numChanges = Iterators.size(diffOp.call());
                if (numChanges == 0) {
                    // We are reseting to the current version, so there is nothing to do. However,
                    // if we are in a conflict state, the conflict should be removed and calling
                    // stage() will not do it, so we do it here
                    repository.stagingDatabase().removeConflict(null, pattern);
                } else {
                    repository.index().stage(subProgress((1.f / patterns.size()) * 100.f), diff,
                            numChanges);
                }
            }
        } else {
            if (mode == ResetMode.NONE) {
View Full Code Here

        Preconditions.checkNotNull(since);
        Preconditions.checkNotNull(until);

        GraphDatabase graphDb = graphDatabase();
        Repository repository = repository();
        Platform platform = platform();

        final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
        Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't squash.");
        Preconditions.checkState(currHead.get() instanceof SymRef,
                "Can't squash from detached HEAD");
        final SymRef headRef = (SymRef) currHead.get();
        final String currentBranch = headRef.getTarget();

        Preconditions.checkState(index().isClean() && workingTree().isClean(),
                "You must have a clean working tree and index to perform a squash.");

        Optional<ObjectId> ancestor = command(FindCommonAncestor.class).setLeft(since)
                .setRight(until).call();
        Preconditions.checkArgument(ancestor.isPresent(),
                "'since' and 'until' command do not have a common ancestor");
        Preconditions.checkArgument(ancestor.get().equals(since.getId()),
                "Commits provided in wrong order");

        Preconditions.checkArgument(!since.getParentIds().isEmpty(),
                "'since' commit has no parents");

        // we get a a list of commits to apply on top of the squashed commits
        List<RevCommit> commits = getCommitsAfterUntil();

        ImmutableSet<Ref> refs = command(ForEachRef.class).setPrefixFilter(Ref.HEADS_PREFIX).call();

        // we create a list of all parents of those squashed commits, in case they are
        // merge commits. The resulting commit will have all these parents
        //
        // While iterating the set of commits to squash, we check that there are no branch starting
        // points among them. Any commit with more than one child causes an exception to be thrown,
        // since the squash operation does not support squashing those commits

        Iterator<RevCommit> toSquash = command(LogOp.class).setSince(since.getParentIds().get(0))
                .setUntil(until.getId()).setFirstParentOnly(true).call();
        List<ObjectId> firstParents = Lists.newArrayList();
        List<ObjectId> secondaryParents = Lists.newArrayList();
        final List<ObjectId> squashedIds = Lists.newArrayList();
        RevCommit commitToSquash = until;
        while (toSquash.hasNext()) {
            commitToSquash = toSquash.next();
            squashedIds.add(commitToSquash.getId());
            Preconditions
                    .checkArgument(
                            graphDb.getChildren(commitToSquash.getId()).size() < 2,
                            "The commits to squash include a branch starting point. Squashing that type of commit is not supported.");
            for (Ref ref : refs) {
                // In case a branch has been created but no commit has been made on it and the
                // starting commit has just one child
                Preconditions
                        .checkArgument(
                                !ref.getObjectId().equals(commitToSquash.getId())
                                        || ref.getObjectId().equals(currHead.get().getObjectId())
                                        || commitToSquash.getParentIds().size() > 1,
                                "The commits to squash include a branch starting point. Squashing that type of commit is not supported.");
            }
            ImmutableList<ObjectId> parentIds = commitToSquash.getParentIds();
            for (int i = 1; i < parentIds.size(); i++) {
                secondaryParents.add(parentIds.get(i));
            }
            firstParents.add(parentIds.get(0));
        }
        Preconditions.checkArgument(since.equals(commitToSquash),
                "Cannot reach 'since' from 'until' commit through first parentage");

        // We do the same check in the children commits
        for (RevCommit commit : commits) {
            Preconditions
                    .checkArgument(
                            graphDb.getChildren(commit.getId()).size() < 2,
                            "The commits after the ones to squash include a branch starting point. This scenario is not supported.");
            for (Ref ref : refs) {
                // In case a branch has been created but no commit has been made on it
                Preconditions
                        .checkArgument(
                                !ref.getObjectId().equals(commit.getId())
                                        || ref.getObjectId().equals(currHead.get().getObjectId())
                                        || commit.getParentIds().size() > 1,
                                "The commits after the ones to squash include a branch starting point. This scenario is not supported.");
            }
        }

        ObjectId newHead;
        // rewind the head
        newHead = since.getParentIds().get(0);
        command(ResetOp.class).setCommit(Suppliers.ofInstance(newHead)).setMode(ResetMode.HARD)
                .call();

        // add the current HEAD as first parent of the resulting commit
        // parents.add(0, newHead);

        // Create new commit
        List<ObjectId> parents = Lists.newArrayList();
        parents.addAll(firstParents);
        parents.addAll(secondaryParents);
        ObjectId endTree = until.getTreeId();
        CommitBuilder builder = new CommitBuilder(until);
        Collection<ObjectId> filteredParents = Collections2.filter(parents,
                new Predicate<ObjectId>() {
                    @Override
                    public boolean apply(@Nullable ObjectId id) {
                        return !squashedIds.contains(id);
                    }

                });

        builder.setParentIds(Lists.newArrayList(filteredParents));
        builder.setTreeId(endTree);
        if (message == null) {
            message = since.getMessage();
        }
        long timestamp = platform.currentTimeMillis();
        builder.setMessage(message);
        builder.setCommitter(resolveCommitter());
        builder.setCommitterEmail(resolveCommitterEmail());
        builder.setCommitterTimestamp(timestamp);
        builder.setCommitterTimeZoneOffset(platform.timeZoneOffset(timestamp));
        builder.setAuthorTimestamp(until.getAuthor().getTimestamp());

        RevCommit newCommit = builder.build();
        repository.objectDatabase().put(newCommit);

        newHead = newCommit.getId();
        ObjectId newTreeId = newCommit.getTreeId();

        command(UpdateRef.class).setName(currentBranch).setNewValue(newHead).call();
View Full Code Here

            if (!applies) {
                return false;
            }
            if (paths != null) {
                applies = false;
                final Repository repository = repository();
                // did this commit touch any of the paths?
                RevTree commitTree = repository.getTree(commit.getTreeId());
                ObjectId currentValue, parentValue;
                for (String path : paths) {
                    currentValue = getPathHash(commitTree, path);
                    // See if the new value is different from any of the parents.
                    int parentIndex = 0;
                    do {
                        ObjectId parentId = commit.parentN(parentIndex++).or(ObjectId.NULL);
                        if (parentId.isNull() || !repository.commitExists(parentId)) {
                            // we have reached the bottom of a shallow clone or the end of history.
                            if (!currentValue.isNull()) {
                                applies = true;
                                break;
                            }
                        } else {
                            RevCommit otherCommit = repository.getCommit(parentId);
                            RevTree parentTree = repository.getTree(otherCommit.getTreeId());
                            parentValue = getPathHash(parentTree, path);
                            if (!parentValue.equals(currentValue)) {
                                applies = true;
                                break;
                            }
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.repository.Repository

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.