Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.ObjectId


    }

    public static OSMLogEntry valueOf(String s) {
        String[] tokens = s.split("\t");
        Preconditions.checkArgument(tokens.length == 3, "wrong OSM log entry definition: %s", s);
        ObjectId id = ObjectId.valueOf(tokens[0]);
        try {
            long changeset = Long.parseLong(tokens[1]);
            long timestamp = Long.parseLong(tokens[2]);
            return new OSMLogEntry(id, changeset, timestamp);
        } catch (NumberFormatException e) {
View Full Code Here


    @Override
    protected Optional<OSMReport> _call() {

        checkNotNull(urlOrFilepath);

        ObjectId oldTreeId = workingTree().getTree().getId();

        File osmDataFile = null;
        final InputStream osmDataStream;
        if (urlOrFilepath.startsWith("http")) {
            osmDataStream = downloadFile();
        } else {
            osmDataFile = new File(urlOrFilepath);
            Preconditions.checkArgument(osmDataFile.exists(), "File does not exist: "
                    + urlOrFilepath);
            try {
                osmDataStream = new BufferedInputStream(new FileInputStream(osmDataFile),
                        1024 * 1024);
            } catch (FileNotFoundException e) {
                throw Throwables.propagate(e);
            }
        }

        ProgressListener progressListener = getProgressListener();
        progressListener.setDescription("Importing into GeoGig repo...");

        EntityConverter converter = new EntityConverter();

        OSMReport report;
        try {
            report = parseDataFileAndInsert(osmDataFile, osmDataStream, converter);
        } finally {
            Closeables.closeQuietly(osmDataStream);
        }

        if (!progressListener.isCanceled() && report != null) {
            ObjectId newTreeId = workingTree().getTree().getId();
            if (!noRaw) {
                if (mapping != null || filter != null) {
                    progressListener.setDescription("Staging features...");
                    command(AddOp.class).setProgressListener(progressListener).call();
                    progressListener.setDescription("Committing features...");
View Full Code Here

        final Ref headRef = currHead.get();
        checkState(headRef instanceof SymRef,//
                "HEAD is in a dettached state, cannot commit. Create a branch from it before committing");

        final String currentBranch = ((SymRef) headRef).getTarget();
        final ObjectId currHeadCommitId = headRef.getObjectId();

        Supplier<RevTree> oldRoot = resolveOldRoot();
        if (!currHeadCommitId.isNull()) {
            if (amend) {
                RevCommit headCommit = command(RevObjectParse.class).setObjectId(currHeadCommitId)
                        .call(RevCommit.class).get();
                parents.addAll(headCommit.getParentIds());
                if (message == null || message.isEmpty()) {
                    message = headCommit.getMessage();
                }
                RevTree commitTree = command(RevObjectParse.class)
                        .setObjectId(headCommit.getTreeId()).call(RevTree.class).get();
                oldRoot = Suppliers.ofInstance(commitTree);
            } else {
                parents.add(0, currHeadCommitId);
            }
        } else {
            Preconditions.checkArgument(!amend,
                    "Cannot amend. There is no previous commit to amend");
        }

        // additional operations in case we are committing after a conflicted merge
        final Optional<Ref> mergeHead = command(RefParse.class).setName(Ref.MERGE_HEAD).call();
        if (mergeHead.isPresent()) {
            ObjectId mergeCommitId = mergeHead.get().getObjectId();
            if (!mergeCommitId.isNull()) {
                parents.add(mergeCommitId);
            }
            if (message == null) {
                message = command(ReadMergeCommitMessageOp.class).call();
            }
        }

        ObjectId newTreeId;
        {
            WriteTree2 writeTree = command(WriteTree2.class);
            writeTree.setOldRoot(oldRoot).setProgressListener(subProgress(writeTreeProgress));
            if (!pathFilters.isEmpty()) {
                writeTree.setPathFilter(pathFilters);
            }
            newTreeId = writeTree.call();
        }

        if (getProgressListener().isCanceled()) {
            return null;
        }

        final ObjectId currentRootTreeId = command(ResolveTreeish.class)
                .setTreeish(currHeadCommitId).call().or(RevTree.EMPTY_TREE_ID);
        if (currentRootTreeId.equals(newTreeId)) {
            if (!allowEmpty) {
                throw new NothingToCommitException("Nothing to commit after " + currHeadCommitId);
            }
        }
View Full Code Here

    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));
View Full Code Here

        try {
            lines = Files.readLines(file, Charsets.UTF_8);
        } catch (IOException e) {
            throw new IllegalStateException("Cannot create squash commit info file");
        }
        ObjectId id = ObjectId.valueOf(lines.get(0).split("\t")[1].trim());
        String commitString = Joiner.on("\n").join(lines.subList(1, lines.size()));
        ByteArrayInputStream stream = new ByteArrayInputStream(
                commitString.getBytes(Charsets.UTF_8));
        ObjectReader<RevCommit> reader = new TextSerializationFactory().createCommitReader();
        RevCommit revCommit = reader.read(id, stream);
View Full Code Here

                        RevTree newRoot = treeBuilder.build();
                        stagingDatabase().put(newRoot);
                        workingTree().updateWorkHead(newRoot.getId());
                    } else {

                        ObjectId metadataId = ObjectId.NULL;
                        Optional<NodeRef> parentNode = command(FindTreeChild.class)
                                .setParent(workingTree().getTree())
                                .setChildPath(node.get().getParentPath()).setIndex(true).call();
                        RevTreeBuilder treeBuilder = null;
                        if (parentNode.isPresent()) {
                            metadataId = parentNode.get().getMetadataId();
                            Optional<RevTree> parsed = command(RevObjectParse.class).setObjectId(
                                    parentNode.get().getNode().getObjectId()).call(RevTree.class);
                            checkState(parsed.isPresent(),
                                    "Parent tree couldn't be found in the repository.");
                            treeBuilder = new RevTreeBuilder(stagingDatabase(), parsed.get());
                            treeBuilder.remove(node.get().getNode().getName());
                        } else {
                            treeBuilder = new RevTreeBuilder(stagingDatabase());
                        }
                        treeBuilder.put(node.get().getNode());
                        ObjectId newTreeId = command(WriteBack.class)
                                .setAncestor(
                                        workingTree().getTree().builder(stagingDatabase()))
                                .setChildPath(node.get().getParentPath()).setToIndex(true)
                                .setTree(treeBuilder.build()).setMetadataId(metadataId).call();
                        workingTree().updateWorkHead(newTreeId);
                    }
                }
            }

        } else {
            if (!conflicts.isEmpty()) {
                if (!(force)) {
                    StringBuilder msg = new StringBuilder();
                    for (Conflict conflict : conflicts) {
                        msg.append("error: " + conflict.getPath() + " needs merge.\n");
                    }
                    msg.append("You need to resolve your index first.\n");
                    throw new CheckoutException(msg.toString(), StatusCode.UNMERGED_PATHS);
                }
            }
            Optional<Ref> targetRef = Optional.absent();
            Optional<ObjectId> targetCommitId = Optional.absent();
            Optional<ObjectId> targetTreeId = Optional.absent();
            targetRef = command(RefParse.class).setName(branchOrCommit).call();
            if (targetRef.isPresent()) {
                ObjectId commitId = targetRef.get().getObjectId();
                if (targetRef.get().getName().startsWith(Ref.REMOTES_PREFIX)) {
                    String remoteName = targetRef.get().getName();
                    remoteName = remoteName.substring(Ref.REMOTES_PREFIX.length(), targetRef.get()
                            .getName().lastIndexOf("/"));

                    if (branchOrCommit.contains(remoteName + '/')) {
                        RevCommit commit = command(RevObjectParse.class).setObjectId(commitId)
                                .call(RevCommit.class).get();

                        targetTreeId = Optional.of(commit.getTreeId());
                        targetCommitId = Optional.of(commit.getId());
                        targetRef = Optional.absent();
                    } else {

                        Ref branch = command(BranchCreateOp.class)
                                .setName(targetRef.get().localName())
                                .setSource(commitId.toString()).call();

                        command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET)
                                .setScope(ConfigScope.LOCAL)
                                .setName("branches." + branch.localName() + ".remote")
                                .setValue(remoteName).call();

                        command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET)
                                .setScope(ConfigScope.LOCAL)
                                .setName("branches." + branch.localName() + ".merge")
                                .setValue(targetRef.get().getName()).call();

                        targetRef = Optional.of(branch);
                        result.setResult(CheckoutResult.Results.CHECKOUT_REMOTE_BRANCH);
                        result.setRemoteName(remoteName);
                    }
                }

                if (commitId.isNull()) {
                    targetTreeId = Optional.of(ObjectId.NULL);
                    targetCommitId = Optional.of(ObjectId.NULL);
                } else {
                    Optional<RevCommit> parsed = command(RevObjectParse.class)
                            .setObjectId(commitId).call(RevCommit.class);
                    checkState(parsed.isPresent());
                    checkState(parsed.get() instanceof RevCommit);
                    RevCommit commit = parsed.get();
                    targetCommitId = Optional.of(commit.getId());
                    targetTreeId = Optional.of(commit.getTreeId());
                }
            } else {
                final Optional<ObjectId> addressed = command(RevParse.class).setRefSpec(
                        branchOrCommit).call();
                checkArgument(addressed.isPresent(), "source '" + branchOrCommit
                        + "' not found in repository");

                RevCommit commit = command(RevObjectParse.class).setObjectId(addressed.get())
                        .call(RevCommit.class).get();

                targetTreeId = Optional.of(commit.getTreeId());
                targetCommitId = Optional.of(commit.getId());
            }
            if (targetTreeId.isPresent()) {
                if (!force) {
                    if (!index().isClean() || !workingTree().isClean()) {
                        throw new CheckoutException(StatusCode.LOCAL_CHANGES_NOT_COMMITTED);
                    }
                }
                // update work tree
                ObjectId treeId = targetTreeId.get();
                workingTree().updateWorkHead(treeId);
                index().updateStageHead(treeId);
                result.setNewTree(treeId);
                if (targetRef.isPresent()) {
                    // update HEAD
                    Ref target = targetRef.get();
                    String refName;
                    if (target instanceof SymRef) {// beware of cyclic refs, peel symrefs
                        refName = ((SymRef) target).getTarget();
                    } else {
                        refName = target.getName();
                    }
                    command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(refName).call();
                    result.setNewRef(targetRef.get());
                    result.setOid(targetCommitId.get());
                    result.setResult(CheckoutResult.Results.CHECKOUT_LOCAL_BRANCH);
                } else {
                    // set HEAD to a dettached state
                    ObjectId commitId = targetCommitId.get();
                    command(UpdateRef.class).setName(Ref.HEAD).setNewValue(commitId).call();
                    result.setOid(commitId);
                    result.setResult(CheckoutResult.Results.DETACHED_HEAD);
                }
                Optional<Ref> ref = command(RefParse.class).setName(Ref.MERGE_HEAD).call();
View Full Code Here

        if (remoteRef instanceof SymRef) {
            String targetBranch = Ref.localName(((SymRef) remoteRef).getTarget());
            String newTarget = Ref.REMOTES_PREFIX + remote.getName() + "/" + targetBranch;
            command(UpdateSymRef.class).setName(refName).setNewValue(newTarget).call();
        } else {
            ObjectId effectiveId = remoteRef.getObjectId();

            if (remote.getMapped() && !repository().commitExists(remoteRef.getObjectId())) {
                effectiveId = graphDatabase().getMapping(effectiveId);
                updatedRef = new Ref(remoteRef.getName(), effectiveId);
            }
View Full Code Here

    private CommitBuilder testCommit;

    @Before
    public void before() {
        this.factory = getObjectSerializingFactory();
        ObjectId treeId = ObjectId.forString("treeid");
        testCommit = testCommit(treeId, "groldan", "groldan@boundlessgeo.com", 5000L, "jd",
                "jd@lmnsolutions.com", 10000L, "test message", ObjectId.forString("first parent"));
    }
View Full Code Here

        String committerEmail = "mleslie@boundlessgeo.com";
        builder.setCommitterEmail(committerEmail);
        builder.setCommitterTimestamp(currentTime);
        builder.setCommitterTimeZoneOffset(timeZoneOffset);

        ObjectId treeId = ObjectId.forString("Fake tree");
        builder.setTreeId(treeId);

        ObjectId parent1 = ObjectId.forString("Parent 1 of fake commit");
        ObjectId parent2 = ObjectId.forString("Parent 2 of fake commit");
        List<ObjectId> parents = Arrays.asList(parent1, parent2);
        builder.setParentIds(parents);

        RevCommit cmtIn = builder.build();
        assertNotNull(cmtIn);
View Full Code Here

        }

        public void run() {
            try {
                for (int i = 0; i < 100; i++) {
                    ObjectId root = ObjectId.forString(key + "_commit_" + i);
                    ObjectId commit = ObjectId.forString(key + "_commit_" + (i + 1));
                    database.put(commit, ImmutableList.of(root));
                }
            } catch (Exception e) {
                errorLog.offer(e.toString());
            }
View Full Code Here

TOP

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

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.