Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.GeoGIG


    @Override
    public void runInternal(GeogigCLI cli) throws IOException {
        checkParameter(commits.size() == 2, "Two commit references must be provided");

        ConsoleReader console = cli.getConsole();
        GeoGIG geogig = cli.getGeogig();

        Optional<RevObject> left = geogig.command(RevObjectParse.class).setRefSpec(commits.get(0))
                .call();
        checkParameter(left.isPresent(), commits.get(0) + " does not resolve to any object.");
        checkParameter(left.get() instanceof RevCommit, commits.get(0)
                + " does not resolve to a commit");
        Optional<RevObject> right = geogig.command(RevObjectParse.class).setRefSpec(commits.get(1))
                .call();
        checkParameter(right.isPresent(), commits.get(1) + " does not resolve to any object.");
        checkParameter(right.get() instanceof RevCommit, commits.get(1)
                + " does not resolve to a commit");
        Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class)
                .setLeft((RevCommit) left.get()).setRight((RevCommit) right.get()).call();
        checkParameter(ancestor.isPresent(), "No common ancestor was found.");

        console.print(ancestor.get().toString());
    }
View Full Code Here


        if (treeStats && describe) {
            throw new CommandFailedException(
                    "Cannot use --describe and --tree-stats simultaneously");
        }

        GeoGIG geogig = cli.getGeogig();

        org.locationtech.geogig.api.plumbing.DiffTree diff = geogig
                .command(org.locationtech.geogig.api.plumbing.DiffTree.class);

        String oldVersion = resolveOldVersion();
        String newVersion = resolveNewVersion();

        diff.setOldVersion(oldVersion).setNewVersion(newVersion);

        Iterator<DiffEntry> diffEntries;
        if (paths.isEmpty()) {
            diffEntries = diff.setProgressListener(cli.getProgressListener()).call();
        } else {
            diffEntries = Iterators.emptyIterator();
            for (String path : paths) {
                Iterator<DiffEntry> moreEntries = diff.setPathFilter(path)
                        .setProgressListener(cli.getProgressListener()).call();
                diffEntries = Iterators.concat(diffEntries, moreEntries);
            }
        }

        DiffEntry diffEntry;
        HashMap<String, Long[]> stats = Maps.newHashMap();
        while (diffEntries.hasNext()) {
            diffEntry = diffEntries.next();
            StringBuilder sb = new StringBuilder();
            String path = diffEntry.newPath() != null ? diffEntry.newPath() : diffEntry.oldPath();

            if (describe) {
                sb.append(diffEntry.changeType().toString().charAt(0)).append(' ').append(path)
                        .append(LINE_BREAK);

                if (diffEntry.changeType() == ChangeType.MODIFIED) {
                    FeatureDiff featureDiff = geogig.command(DiffFeature.class)
                            .setNewVersion(Suppliers.ofInstance(diffEntry.getNewObject()))
                            .setOldVersion(Suppliers.ofInstance(diffEntry.getOldObject())).call();
                    Map<PropertyDescriptor, AttributeDiff> diffs = featureDiff.getDiffs();
                    HashSet<PropertyDescriptor> diffDescriptors = Sets.newHashSet(diffs.keySet());
                    NodeRef noderef = diffEntry.changeType() != ChangeType.REMOVED ? diffEntry
                            .getNewObject() : diffEntry.getOldObject();
                    RevFeatureType featureType = geogig.command(RevObjectParse.class)
                            .setObjectId(noderef.getMetadataId()).call(RevFeatureType.class).get();
                    Optional<RevObject> obj = geogig.command(RevObjectParse.class)
                            .setObjectId(noderef.objectId()).call();
                    RevFeature feature = (RevFeature) obj.get();
                    ImmutableList<Optional<Object>> values = feature.getValues();
                    ImmutableList<PropertyDescriptor> descriptors = featureType.sortedDescriptors();
                    int idx = 0;
                    for (PropertyDescriptor descriptor : descriptors) {
                        if (diffs.containsKey(descriptor)) {
                            AttributeDiff ad = diffs.get(descriptor);
                            sb.append(ad.getType().toString().charAt(0) + " "
                                    + descriptor.getName().toString() + LINE_BREAK);
                            if (!ad.getType().equals(TYPE.ADDED)) {
                                Object value = ad.getOldValue().orNull();
                                sb.append(TextValueSerializer.asString(Optional.fromNullable(value)));
                                sb.append(LINE_BREAK);
                            }
                            if (!ad.getType().equals(TYPE.REMOVED)) {
                                Object value = ad.getNewValue().orNull();
                                sb.append(TextValueSerializer.asString(Optional.fromNullable(value)));
                                sb.append(LINE_BREAK);
                            }
                            diffDescriptors.remove(descriptor);
                        } else {
                            sb.append("U ").append(descriptor.getName().toString())
                                    .append(LINE_BREAK);
                            sb.append(TextValueSerializer.asString(values.get(idx))).append(
                                    LINE_BREAK);
                        }
                        idx++;
                    }
                    for (PropertyDescriptor descriptor : diffDescriptors) {
                        AttributeDiff ad = diffs.get(descriptor);
                        sb.append(ad.getType().toString().charAt(0) + " "
                                + descriptor.getName().toString() + LINE_BREAK);
                        if (!ad.getType().equals(TYPE.ADDED)) {
                            Object value = ad.getOldValue().orNull();
                            sb.append(TextValueSerializer.asString(Optional.fromNullable(value)));
                            sb.append(LINE_BREAK);
                        }
                        if (!ad.getType().equals(TYPE.REMOVED)) {
                            Object value = ad.getNewValue().orNull();
                            sb.append(TextValueSerializer.asString(Optional.fromNullable(value)));
                            sb.append(LINE_BREAK);
                        }
                    }
                } else {
                    NodeRef noderef = diffEntry.changeType() == ChangeType.ADDED ? diffEntry
                            .getNewObject() : diffEntry.getOldObject();
                    RevFeatureType featureType = geogig.command(RevObjectParse.class)
                            .setObjectId(noderef.getMetadataId()).call(RevFeatureType.class).get();
                    Optional<RevObject> obj = geogig.command(RevObjectParse.class)
                            .setObjectId(noderef.objectId()).call();
                    RevFeature feature = (RevFeature) obj.get();
                    ImmutableList<Optional<Object>> values = feature.getValues();
                    int i = 0;
                    for (Optional<Object> value : values) {
View Full Code Here

    /**
     * Executes the rev-parse command using the provided options.
     */
    @Override
    protected void runInternal(GeogigCLI cli) throws IOException {
        GeoGIG geogig = cli.getGeogig();

        if (!refSpecs.isEmpty()) {
            checkParameter(!(resolve_geogig_dir || is_inside_work_tree),
                    "if refSpec is given, --resolve-geogig-dir or --is-inside-work-tree shall not be specified");
            ConsoleReader console = cli.getConsole();
            for (String refSpec : this.refSpecs) {
                Optional<ObjectId> resolved = geogig
                        .command(org.locationtech.geogig.api.plumbing.RevParse.class)
                        .setRefSpec(refSpec).call();
                checkParameter(resolved.isPresent(), "fatal: ambiguous argument '%s': "
                        + "unknown revision or path not in the working tree.", refSpec);
                console.println(resolved.get().toString());
            }
            console.flush();
            return;
        }

        boolean closeIt = false;
        if (null == geogig) {
            geogig = cli.newGeoGIG(Hints.readOnly());
            closeIt = true;
        }
        try {
            if (resolve_geogig_dir) {
                resolveGeogigDir(cli.getConsole(), geogig);
            } else if (is_inside_work_tree) {
                isInsideWorkTree(cli.getConsole(), geogig);
            }
        } finally {
            if (closeIt) {
                geogig.close();
            }
        }
    }
View Full Code Here

    @Override
    public void runInternal(GeogigCLI cli) throws IOException {

        ConsoleReader console = cli.getConsole();
        GeoGIG geogig = cli.getGeogig();

        ForEachRef op = geogig.command(ForEachRef.class);

        Predicate<Ref> filter = new Predicate<Ref>() {
            @Override
            public boolean apply(Ref ref) {
                String name = ref.getName();
View Full Code Here

    public void runInternal(GeogigCLI cli) throws IOException {
        checkParameter(paths.size() < 2, "Only one refspec allowed");
        checkParameter(!paths.isEmpty(), "A refspec must be specified");

        ConsoleReader console = cli.getConsole();
        GeoGIG geogig = cli.getGeogig();

        String path = paths.get(0);

        Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(path).call();
        checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
        if (binary) {
            ObjectSerializingFactory factory = DataStreamSerializationFactoryV1.INSTANCE;
            ObjectWriter<RevObject> writer = factory.createObjectWriter(obj.get().getType());
            writer.write(obj.get(), System.out);
        } else {
            CharSequence s = geogig.command(CatObject.class)
                    .setObject(Suppliers.ofInstance(obj.get())).call();
            console.println(s);
        }
    }
View Full Code Here

    @Override
    public void runInternal(GeogigCLI cli) throws IOException {
        checkParameter(limit >= 0, "Limit must be 0 or greater.");

        ConsoleReader console = cli.getConsole();
        GeoGIG geogig = cli.getGeogig();

        StatusOp op = geogig.command(StatusOp.class);
        StatusSummary summary = op.call();

        final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
        checkParameter(currHead.isPresent(), "Repository has no HEAD.");

        if (currHead.get() instanceof SymRef) {
            final SymRef headRef = (SymRef) currHead.get();
            console.println("# On branch " + Ref.localName(headRef.getTarget()));
View Full Code Here

     * Executes the config command using the provided options.
     */
    @Override
    public void runInternal(GeogigCLI cli) throws IOException {

        GeoGIG geogig = cli.getGeogig();
        boolean closeIt = geogig == null;
        if (closeIt) {
            // we're not in a repository, need a geogig anyways to run the global commands
            geogig = cli.newGeoGIG(Hints.readOnly());
        }

        try {
            String name = null;
            String value = null;
            if (nameValuePair != null && !nameValuePair.isEmpty()) {
                name = nameValuePair.get(0);
                value = buildValueString();
            }

            ConfigAction action = resolveConfigAction();

            if (action == ConfigAction.CONFIG_NO_ACTION) {
                printUsage(cli);
                throw new CommandFailedException();
            }
            if (global && local) {
                printUsage(cli);
                throw new CommandFailedException();
            }
            ConfigScope scope = ConfigScope.DEFAULT;

            if (global) {
                scope = ConfigScope.GLOBAL;
            } else if (local) {
                scope = ConfigScope.LOCAL;
            }

            final Optional<Map<String, String>> commandResult = geogig.command(ConfigOp.class)
                    .setScope(scope).setAction(action).setName(name).setValue(value).call();

            if (commandResult.isPresent()) {
                switch (action) {
                case CONFIG_GET: {
                    cli.getConsole().println(commandResult.get().get(name));
                    break;
                }
                case CONFIG_LIST: {
                    Iterator<Map.Entry<String, String>> it = commandResult.get().entrySet()
                            .iterator();
                    while (it.hasNext()) {
                        Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next();
                        cli.getConsole().println(pairs.getKey() + "=" + pairs.getValue());
                    }
                    break;
                }
                default:
                    break;
                }
            }
        } catch (ConfigException e) {
            // These mirror 'git config' status codes. Some of these are unused,
            // since we don't have regex support yet.
            switch (e.statusCode) {
            case INVALID_LOCATION:
                // TODO: This could probably be more descriptive.
                throw new CommandFailedException("The config location is invalid", e);
            case CANNOT_WRITE:
                throw new CommandFailedException("Cannot write to the config", e);
            case SECTION_OR_NAME_NOT_PROVIDED:
                throw new InvalidParameterException("No section or name was provided", e);
            case SECTION_OR_KEY_INVALID:
                throw new InvalidParameterException("The section or key is invalid", e);
            case OPTION_DOES_NOT_EXIST:
                throw new InvalidParameterException("Tried to unset an option that does not exist",
                        e);
            case MULTIPLE_OPTIONS_MATCH:
                throw new InvalidParameterException(
                        "Tried to unset/set an option for which multiple lines match", e);
            case INVALID_REGEXP:
                throw new InvalidParameterException("Tried to use an invalid regexp", e);
            case USERHOME_NOT_SET:
                throw new InvalidParameterException(
                        "Used --global option without $HOME being properly set", e);
            case TOO_MANY_ACTIONS:
                throw new InvalidParameterException("Tried to use more than one action at a time",
                        e);
            case MISSING_SECTION:
                throw new InvalidParameterException(
                        "Could not find a section with the name provided", e);
            case TOO_MANY_ARGS:
                throw new InvalidParameterException("Too many arguments provided.", e);
            }
        } finally {
            if (closeIt) {
                geogig.close();
            }
        }
    }
View Full Code Here

    @Override
    protected void runInternal(GeogigCLI cli) throws IOException {
        checkParameter(commits.size() > 0 || abort || continueRevert,
                "nothing specified for reverting");

        final GeoGIG geogig = cli.getGeogig();
        RevertOp revert = geogig.command(RevertOp.class);

        for (String st : commits) {
            Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(st).call();
            checkParameter(commitId.isPresent(), "Couldn't resolve '" + st
                    + "' to a commit, aborting revert.");
            revert.addCommit(Suppliers.ofInstance(commitId.get()));
        }
        try {
View Full Code Here

     */
    @Override
    public void runInternal(GeogigCLI cli) {
        checkParameter(commits.size() == 2, "2 commit references must be supplied");

        final GeoGIG geogig = cli.getGeogig();

        Optional<ObjectId> sinceId = geogig.command(RevParse.class).setRefSpec(commits.get(0))
                .call();
        checkParameter(sinceId.isPresent(), "'since' reference cannot be found");
        checkParameter(geogig.getRepository().commitExists(sinceId.get()),
                "'since' reference does not resolve to a commit");
        RevCommit sinceCommit = geogig.getRepository().getCommit(sinceId.get());

        Optional<ObjectId> untilId = geogig.command(RevParse.class).setRefSpec(commits.get(1))
                .call();
        checkParameter(untilId.isPresent(), "'until' reference cannot be found");
        checkParameter(geogig.getRepository().commitExists(untilId.get()),
                "'until' reference does not resolve to a commit");
        RevCommit untilCommit = geogig.getRepository().getCommit(untilId.get());

        geogig.command(SquashOp.class).setSince(sinceCommit).setUntil(untilCommit)
                .setMessage(message).call();
    }
View Full Code Here

        checkParameter(!(skip && continueRebase), "Cannot use both --skip and --continue");
        checkParameter(!(skip && abort), "Cannot use both --skip and --abort");
        checkParameter(!(abort && continueRebase), "Cannot use both --abort and --continue");

        GeoGIG geogig = cli.getGeogig();
        RebaseOp rebase = geogig.command(RebaseOp.class).setSkip(skip).setContinue(continueRebase)
                .setAbort(abort).setSquashMessage(squash);
        rebase.setProgressListener(cli.getProgressListener());

        if (arguments == null || arguments.size() == 0) {
            if (abort || skip || continueRebase) {
            } else {
                // Rebase onto remote branch
                throw new UnsupportedOperationException("remote branch rebase not yet supported");
            }
        } else {
            checkParameter(arguments.size() < 3, "Too many arguments specified.");
            if (arguments.size() == 2) {
                // Make sure branch is valid
                Optional<ObjectId> branchRef = geogig.command(RevParse.class)
                        .setRefSpec(arguments.get(1)).call();
                checkParameter(branchRef.isPresent(), "The branch reference could not be resolved.");
                // Checkout <branch> prior to rebase
                try {
                    geogig.command(CheckoutOp.class).setSource(arguments.get(1)).call();
                } catch (CheckoutException e) {
                    throw new CommandFailedException(e.getMessage(), e);
                }

            }

            Optional<Ref> upstreamRef = geogig.command(RefParse.class).setName(arguments.get(0))
                    .call();
            checkParameter(upstreamRef.isPresent(), "The upstream reference could not be resolved.");
            rebase.setUpstream(Suppliers.ofInstance(upstreamRef.get().getObjectId()));
        }

        if (onto != null) {
            Optional<ObjectId> ontoId = geogig.command(RevParse.class).setRefSpec(onto).call();
            checkParameter(ontoId.isPresent(), "The onto reference could not be resolved.");
            rebase.setOnto(Suppliers.ofInstance(ontoId.get()));
        }

        try {
View Full Code Here

TOP

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

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.