Package org.locationtech.geogig.repository

Examples of org.locationtech.geogig.repository.Repository


                index().updateStageHead(upstream.get());
                getProgressListener().complete();
                return true;
            }

            Repository repository = repository();
            final RevCommit headCommit = repository.getCommit(headRef.getObjectId());
            final RevCommit targetCommit = repository.getCommit(upstream.get());

            command(UpdateRef.class).setName(Ref.ORIG_HEAD).setNewValue(headCommit.getId());

            Optional<ObjectId> ancestorCommit = command(FindCommonAncestor.class)
                    .setLeft(headCommit).setRight(targetCommit)
View Full Code Here


     *        committing. If false, it commits the currently staged changes, ignoring the changes in
     *        the commit and using just its author and message
     */
    private void applyCommit(RevCommit commitToApply, boolean useCommitChanges) {

        Repository repository = repository();
        Platform platform = platform();
        if (useCommitChanges) {
            ObjectId parentTreeId;
            ObjectId parentCommitId = ObjectId.NULL;
            if (commitToApply.getParentIds().size() > 0) {
                parentCommitId = commitToApply.getParentIds().get(0);
            }
            parentTreeId = ObjectId.NULL;
            if (repository.commitExists(parentCommitId)) {
                parentTreeId = repository.getCommit(parentCommitId).getTreeId();
            }
            // get changes
            Iterator<DiffEntry> diff = command(DiffTree.class).setOldTree(parentTreeId)
                    .setNewTree(commitToApply.getTreeId()).setReportTrees(true).call();

            // see if there are conflicts
            MergeScenarioReport report = command(ReportCommitConflictsOp.class).setCommit(
                    commitToApply).call();
            if (report.getConflicts().isEmpty()) {
                // stage changes
                index().stage(getProgressListener(), diff, 0);

                // write new tree
                ObjectId newTreeId = command(WriteTree2.class).call();

                long timestamp = platform.currentTimeMillis();
                // Create new commit
                CommitBuilder builder = new CommitBuilder(commitToApply);
                builder.setParentIds(Arrays.asList(rebaseHead));
                builder.setTreeId(newTreeId);
                builder.setCommitterTimestamp(timestamp);
                builder.setCommitterTimeZoneOffset(platform.timeZoneOffset(timestamp));

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

                rebaseHead = newCommit.getId();

                command(UpdateRef.class).setName(currentBranch).setNewValue(rebaseHead).call();
                command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(currentBranch).call();

                workingTree().updateWorkHead(newTreeId);
                index().updateStageHead(newTreeId);

            } else {
                Iterator<DiffEntry> unconflicted = report.getUnconflicted().iterator();
                // stage unconflicted changes
                index().stage(getProgressListener(), unconflicted, 0);
                workingTree().updateWorkHead(index().getTree().getId());

                // mark conflicted elements
                command(ConflictsWriteOp.class).setConflicts(report.getConflicts()).call();

                // created exception message
                StringBuilder msg = new StringBuilder();
                msg.append("error: could not apply ");
                msg.append(commitToApply.getId().toString().substring(0, 7));
                msg.append(" " + commitToApply.getMessage() + "\n");

                for (Conflict conflict : report.getConflicts()) {
                    msg.append("CONFLICT: conflict in " + conflict.getPath() + "\n");
                }

                File branchFile = new File(getRebaseFolder(), "branch");
                try {
                    Files.write(currentBranch, branchFile, Charsets.UTF_8);
                } catch (IOException e) {
                    throw new IllegalStateException("Cannot create current branch info file");
                }

                throw new RebaseConflictsException(msg.toString());

            }
        } else {
            // write new tree
            ObjectId newTreeId = command(WriteTree2.class).call();

            long timestamp = platform.currentTimeMillis();
            // Create new commit
            CommitBuilder builder = new CommitBuilder(commitToApply);
            builder.setParentIds(Arrays.asList(rebaseHead));
            builder.setTreeId(newTreeId);
            builder.setCommitterTimestamp(timestamp);
            builder.setCommitterTimeZoneOffset(platform.timeZoneOffset(timestamp));

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

            rebaseHead = newCommit.getId();

            command(UpdateRef.class).setName(currentBranch).setNewValue(rebaseHead).call();
            command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(currentBranch).call();
View Full Code Here

     * @param commitId the commit id of commit from the sparse repository
     * @param from the sparse repository
     * @param to the full repository
     */
    protected void pushSparseCommit(ObjectId commitId) {
        Repository from = localRepository;
        Repository to = remoteGeoGig.getRepository();
        Optional<RevObject> object = from.command(RevObjectParse.class).setObjectId(commitId)
                .call();
        if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
            RevCommit commit = (RevCommit) object.get();
            ObjectId parent = ObjectId.NULL;
            List<ObjectId> newParents = new LinkedList<ObjectId>();
            for (int i = 0; i < commit.getParentIds().size(); i++) {
                ObjectId parentId = commit.getParentIds().get(i);
                if (i != 0) {
                    Optional<ObjectId> commonAncestor = from.command(FindCommonAncestor.class)
                            .setLeftId(commit.getParentIds().get(0)).setRightId(parentId).call();
                    if (commonAncestor.isPresent()) {
                        if (from.command(CheckSparsePath.class).setStart(parentId)
                                .setEnd(commonAncestor.get()).call()) {
                            // This should be the base commit to preserve the sparse changes that
                            // were filtered
                            // out.
                            newParents.add(0, from.graphDatabase().getMapping(parentId));
                            continue;
                        }
                    }
                }
                newParents.add(from.graphDatabase().getMapping(parentId));
            }
            if (newParents.size() > 0) {
                parent = from.graphDatabase().getMapping(newParents.get(0));
            }
            Iterator<DiffEntry> diffIter = from.command(DiffOp.class).setNewVersion(commitId)
                    .setOldVersion(parent).setReportTrees(true).call();

            LocalCopyingDiffIterator changes = new LocalCopyingDiffIterator(diffIter, from, to);

            RevTree rootTree = RevTree.EMPTY;

            if (newParents.size() > 0) {
                ObjectId mappedCommit = newParents.get(0);

                Optional<ObjectId> treeId = to.command(ResolveTreeish.class)
                        .setTreeish(mappedCommit).call();
                if (treeId.isPresent()) {
                    rootTree = to.getTree(treeId.get());
                }
            }

            // Create new commit
            ObjectId newTreeId = to.command(WriteTree.class)
                    .setOldRoot(Suppliers.ofInstance(rootTree))
                    .setDiffSupplier(Suppliers.ofInstance((Iterator<DiffEntry>) changes)).call();

            CommitBuilder builder = new CommitBuilder(commit);
            builder.setParentIds(newParents);
            builder.setTreeId(newTreeId);

            RevCommit mapped = builder.build();
            to.objectDatabase().put(mapped);

            from.graphDatabase().map(commit.getId(), mapped.getId());
            from.graphDatabase().map(mapped.getId(), commit.getId());

        }
View Full Code Here

    }

    protected void walkHead(final ObjectId newHeadId, final boolean fetch,
            final ProgressListener progress) {

        Repository from = localRepository;
        Repository to = remoteGeoGig.getRepository();
        if (fetch) {
            Repository tmp = to;
            to = from;
            from = tmp;
        }
        final ObjectDatabase fromDb = from.objectDatabase();
        final ObjectDatabase toDb = to.objectDatabase();
View Full Code Here

        final ScriptEngine engine = factory.getEngineByExtension(ext);

        try {
            Map<String, Object> params = getParamMap(operation);
            engine.put(PARAMS, params);
            Repository repo = operation.command(ResolveRepository.class).call();
            GeoGigAPI api = new GeoGigAPI(repo);
            engine.put(GEOGIG, api);
            engine.eval(new FileReader(scriptFile));
            Object map = engine.get(PARAMS);
            setParamMap((Map<String, Object>) map, operation);
View Full Code Here

        try {
            geogig = new GeoGIG(repositoryDirectory);
        } catch (RuntimeException e) {
            throw new IOException(e.getMessage(), e);
        }
        Repository repository = geogig.getRepository();
        if (null == repository) {
            if (create != null && create.booleanValue()) {
                return createNewDataStore(params);
            }
View Full Code Here

        }

        GeoGIG geogig = new GeoGIG(repositoryRoot);

        try {
            Repository repository = geogig.getOrCreateRepository();
            Preconditions.checkState(repository != null);
        } catch (RuntimeException e) {
            throw new IOException(e);
        }
View Full Code Here

     *
     * @param commitId the commit to push
     */
    @Override
    protected void pushSparseCommit(ObjectId commitId) {
        Repository from = localRepository;
        Optional<RevObject> object = from.command(RevObjectParse.class).setObjectId(commitId)
                .call();
        if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
            RevCommit commit = (RevCommit) object.get();
            ObjectId parent = ObjectId.NULL;
            List<ObjectId> newParents = new LinkedList<ObjectId>();
            for (int i = 0; i < commit.getParentIds().size(); i++) {
                ObjectId parentId = commit.getParentIds().get(i);
                if (i != 0) {
                    Optional<ObjectId> commonAncestor = from.command(FindCommonAncestor.class)
                            .setLeftId(commit.getParentIds().get(0)).setRightId(parentId).call();
                    if (commonAncestor.isPresent()) {
                        if (from.command(CheckSparsePath.class).setStart(parentId)
                                .setEnd(commonAncestor.get()).call()) {
                            // This should be the base commit to preserve changes that were filtered
                            // out.
                            newParents.add(0, from.graphDatabase().getMapping(parentId));
                            continue;
                        }
                    }
                }
                newParents.add(from.graphDatabase().getMapping(parentId));
            }
            if (newParents.size() > 0) {
                parent = from.graphDatabase().getMapping(newParents.get(0));
            }
            Iterator<DiffEntry> diffIter = from.command(DiffOp.class).setNewVersion(commitId)
                    .setOldVersion(parent).setReportTrees(true).call();

            // connect and send packed changes
            final URL resourceURL;
            try {
                resourceURL = new URL(repositoryURL.toString() + "/repo/applychanges");
            } catch (MalformedURLException e) {
                throw Throwables.propagate(e);
            }

            final HttpURLConnection connection;
            final OutputStream out;
            try {
                connection = (HttpURLConnection) resourceURL.openConnection();
                connection.setDoOutput(true);
                connection.setDoInput(true);
                out = connection.getOutputStream();
                // pack the commit object
                final ObjectSerializingFactory factory = DataStreamSerializationFactoryV1.INSTANCE;
                final ObjectWriter<RevCommit> commitWriter = factory
                        .createObjectWriter(TYPE.COMMIT);
                commitWriter.write(commit, out);

                // write the new parents
                out.write(newParents.size());
                for (ObjectId parentId : newParents) {
                    out.write(parentId.getRawValue());
                }

                // pack the changes
                BinaryPackedChanges changes = new BinaryPackedChanges(from);
                changes.write(out, diffIter);
            } catch (IOException e) {
                throw Throwables.propagate(e);
            }

            final InputStream in;
            try {
                in = connection.getInputStream();
                BufferedReader rd = new BufferedReader(new InputStreamReader(in));

                String line = rd.readLine();
                if (line != null) {
                    ObjectId remoteCommitId = ObjectId.valueOf(line);
                    from.graphDatabase().map(commit.getId(), remoteCommitId);
                    from.graphDatabase().map(remoteCommitId, commit.getId());
                }

            } catch (IOException e) {
                throw Throwables.propagate(e);
            }
View Full Code Here

        geogigCLI.close();
        GeoGIG geogig = geogigCLI.newGeoGIG(Hints.readWrite());
        Preconditions.checkNotNull(geogig);
        List<ObjectId> ids = Lists.newArrayListWithCapacity(features.length);
        try {
            Repository repository = geogig.getRepository();
            final WorkingTree workTree = repository.workingTree();
            for (Feature f : features) {
                Name name = f.getType().getName();
                String parentPath = name.getLocalPart();
                Node ref = workTree.insert(parentPath, f);
                ObjectId objectId = ref.getObjectId();
View Full Code Here

        final File targetDir = this.targetDir == null ? workingDirectory : this.targetDir;
        if (!targetDir.exists() && !targetDir.mkdirs()) {
            throw new IllegalArgumentException("Can't create directory "
                    + targetDir.getAbsolutePath());
        }
        Repository repository;
        try {
            platform.setWorkingDir(targetDir);
            repository = callInternal();
        } finally {
            // restore current directory
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.