/** * @return */ RevTree getTypeTree() { String refSpec = getRootRef() + ":" + getTypeTreePath(); Context commandLocator = getCommandLocator(); Optional<RevTree> ref = commandLocator.command(RevObjectParse.class).setRefSpec(refSpec) .call(RevTree.class); Preconditions.checkState(ref.isPresent(), "Ref %s not found on working tree", refSpec); return ref.get(); }
/** * Retrieves an object with the specified id from the remote. * * @param objectId the object to get * @return the fetched object */ @Override protected Optional<RevObject> getObject(ObjectId objectId) { return remoteRepo.command(RevObjectParse.class).setObjectId(objectId).call(); }
private RevObject resolve(@Nullable String refSpec, @Nullable RevTree tree, @NonNull ObjectStore source) throws NoSuchElementException { if (tree == null) { Optional<RevObject> obj = command(RevObjectParse.class).setSource(source) .setRefSpec(refSpec).call(); if (!obj.isPresent()) { try { ObjectId id = ObjectId.valueOf(refSpec); if (id.isNull() || RevTree.EMPTY_TREE_ID.equals(id)) { return RevTree.EMPTY; } } catch (IllegalArgumentException ignore) { // } throw new NoSuchElementException( String.format("%s does not resolve to an object", refSpec)); } return obj.get(); } return tree; } }
private Optional<RevFeature> getFeatureFromRefSpec() { Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref) .call(RevObject.class); if (!revObject.isPresent()) { // let's try to see if it is a feature in the working tree NodeRef.checkValidPath(ref); Optional<NodeRef> elementRef = command(FindTreeChild.class) .setParent(workingTree().getTree()).setChildPath(ref).call(); Preconditions.checkArgument(elementRef.isPresent(), "Invalid reference: %s", ref); ObjectId id = elementRef.get().getObjectId(); revObject = command(RevObjectParse.class).setObjectId(id).call(RevObject.class); } if (revObject.isPresent()) { Preconditions.checkArgument(TYPE.FEATURE.equals(revObject.get().getType()), "%s does not resolve to a feature", ref); return Optional.of(RevFeature.class.cast(revObject.get())); } else { return Optional.absent(); } }
/** * Executes the command. * * @return an {@code Optional} that contains the Node if it was found, or * {@link Optional#absent()} if it wasn't */ @Override protected Optional<NodeRef> _call() { checkNotNull(childPath, "childPath"); if (source == null) { this.source = objectDatabase(); } final RevTree tree; if (parent == null) { ObjectId rootTreeId = command(ResolveTreeish.class).setSource(source) .setTreeish(Ref.HEAD).call().get(); if (rootTreeId.isNull()) { return Optional.absent(); } tree = command(RevObjectParse.class).setSource(source).setObjectId(rootTreeId) .call(RevTree.class).get(); } else { tree = parent.get(); } final String path = childPath; final String parentPath = this.parentPath == null ? "" : this.parentPath; DepthSearch depthSearch = new DepthSearch(source); Optional<NodeRef> childRef = depthSearch.find(tree, parentPath, path); return childRef; }
/** * @return the resolved object id * @throws IllegalArgumentException if the provided refspec doesn't resolve to any known object * @see RevObject */ @Override protected Optional<RevObject> _call() throws IllegalArgumentException { return call(RevObject.class); }
private Optional<RevFeature> getFeatureFromRefSpec() { Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref) .call(RevObject.class); if (!revObject.isPresent()) { // let's try to see if it is a feature in the working tree NodeRef.checkValidPath(ref); Optional<NodeRef> elementRef = command(FindTreeChild.class) .setParent(workingTree().getTree()).setChildPath(ref).call(); Preconditions.checkArgument(elementRef.isPresent(), "Invalid reference: %s", ref); ObjectId id = elementRef.get().getObjectId(); revObject = command(RevObjectParse.class).setObjectId(id).call(RevObject.class); } if (revObject.isPresent()) { Preconditions.checkArgument(TYPE.FEATURE.equals(revObject.get().getType()), "%s does not resolve to a feature", ref); return Optional.of(RevFeature.class.cast(revObject.get())); } else { return Optional.absent(); } }
/** * Executes the command. * * @return an {@code Optional} that contains the Node if it was found, or * {@link Optional#absent()} if it wasn't */ @Override protected Optional<NodeRef> _call() { checkNotNull(childPath, "childPath"); if (source == null) { this.source = objectDatabase(); } final RevTree tree; if (parent == null) { ObjectId rootTreeId = command(ResolveTreeish.class).setSource(source) .setTreeish(Ref.HEAD).call().get(); if (rootTreeId.isNull()) { return Optional.absent(); } tree = command(RevObjectParse.class).setSource(source).setObjectId(rootTreeId) .call(RevTree.class).get(); } else { tree = parent.get(); } final String path = childPath; final String parentPath = this.parentPath == null ? "" : this.parentPath; DepthSearch depthSearch = new DepthSearch(source); Optional<NodeRef> childRef = depthSearch.find(tree, parentPath, path); return childRef; }
/** * @return the resolved object id * @throws IllegalArgumentException if the provided refspec doesn't resolve to any known object * @see RevObject */ @Override protected Optional<RevObject> _call() throws IllegalArgumentException { return call(RevObject.class); }
/** * @return */ RevTree getTypeTree() { String refSpec = getRootRef() + ":" + getTypeTreePath(); Context commandLocator = getCommandLocator(); Optional<RevTree> ref = commandLocator.command(RevObjectParse.class).setRefSpec(refSpec) .call(RevTree.class); Preconditions.checkState(ref.isPresent(), "Ref %s not found on working tree", refSpec); return ref.get(); }
/** * Retrieves an object with the specified id from the remote. * * @param objectId the object to get * @return the fetched object */ @Override protected Optional<RevObject> getObject(ObjectId objectId) { return remoteRepo.command(RevObjectParse.class).setObjectId(objectId).call(); }
assertEquals(3, list.size()); Optional<RevFeature> feature = geogig.command(RevObjectParse.class) .setRefSpec("WORK_HEAD:table1/feature1").call(RevFeature.class); assertTrue(feature.isPresent()); ImmutableList<Optional<Object>> values = feature.get().getValues(); .setObjectId(set.iterator().next()).call(RevFeatureType.class); assertTrue(featureType.isPresent()); assertEquals("table1", featureType.get().getName().getLocalPart());
@Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(paths.size() < 2, "Only one refspec allowed"); checkParameter(!paths.isEmpty(), "A refspec must be specified"); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); String path = paths.get(0); Optional<RevObject> obj; RevObjectParse cmd = geogig.command(RevObjectParse.class).setRefSpec(path); obj = cmd.call(); if (!obj.isPresent()) { obj = cmd.setSource(geogig.getContext().indexDatabase()).call(); } checkParameter(obj.isPresent(), "refspec did not resolve to any object."); if (binary) { RevObjectSerializer factory = DataStreamRevObjectSerializerV1.INSTANCE; factory.write(obj.get(), System.out); } else { CharSequence s = geogig.command(CatObject.class) .setObject(Suppliers.ofInstance(obj.get())).call(); console.println(s); } }
@Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(commits.size() == 2, "Two commit references must be provided"); Console 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()); }
/** * @param treeId the tree to retrieve * @return the {@link RevTree} referred to by the given {@link ObjectId} */ @Override public RevTree getTree(ObjectId treeId) { return command(RevObjectParse.class).setObjectId(treeId).call(RevTree.class).get(); }
@Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(paths.size() < 2, "Only one refspec allowed"); checkParameter(!paths.isEmpty(), "A refspec must be specified"); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); String path = paths.get(0); Optional<RevObject> obj; RevObjectParse cmd = geogig.command(RevObjectParse.class).setRefSpec(path); obj = cmd.call(); if (!obj.isPresent()) { obj = cmd.setSource(geogig.getContext().indexDatabase()).call(); } checkParameter(obj.isPresent(), "refspec did not resolve to any object."); if (binary) { ObjectSerializingFactory factory = DataStreamSerializationFactoryV1.INSTANCE; factory.write(obj.get(), System.out); } else { CharSequence s = geogig.command(CatObject.class) .setObject(Suppliers.ofInstance(obj.get())).call(); console.println(s); } }
/** * Executes the tag removal operation. * * @return the tag to remove * */ @Override protected RevTag _call() throws RuntimeException { String fullPath = Ref.TAGS_PREFIX + name; Optional<RevObject> revTag = command(RevObjectParse.class).setRefSpec(fullPath).call(); Preconditions.checkArgument(revTag.isPresent(), "Wrong tag name: " + name); Preconditions.checkArgument(revTag.get().getType().equals(RevObject.TYPE.TAG), name + " does not resolve to a tag"); UpdateRef updateRef = command(UpdateRef.class).setName(fullPath).setDelete(true) .setReason("Delete tag " + name); Optional<Ref> tagRef = updateRef.call(); checkState(tagRef.isPresent()); return (RevTag) revTag.get(); }
/** * @param treeId the tree to retrieve * @return the {@link RevTree} referred to by the given {@link ObjectId} */ @Override public RevTree getTree(ObjectId treeId) { return command(RevObjectParse.class).setObjectId(treeId).call(RevTree.class).get(); }
@Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(paths.size() < 2, "Only one refspec allowed"); checkParameter(!paths.isEmpty(), "A refspec must be specified"); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); String path = paths.get(0); Optional<RevObject> obj; RevObjectParse cmd = geogig.command(RevObjectParse.class).setRefSpec(path); obj = cmd.call(); if (!obj.isPresent()) { obj = cmd.setSource(geogig.getContext().indexDatabase()).call(); } checkParameter(obj.isPresent(), "refspec did not resolve to any object."); if (binary) { ObjectSerializingFactory factory = DataStreamSerializationFactoryV1.INSTANCE; factory.write(obj.get(), System.out); } else { CharSequence s = geogig.command(CatObject.class) .setObject(Suppliers.ofInstance(obj.get())).call(); console.println(s); } }
private Set<String> resolveExportLayerRefSpecs() { final String refSpec = fromNullable(commitIsh).or(Ref.HEAD); Optional<RevCommit> commit = command(RevObjectParse.class).setRefSpec(refSpec) .call(RevCommit.class); checkArgument(commit.isPresent(), "RefSpec doesn't resolve to a commit: '%s'", refSpec); final List<NodeRef> featureTreeRefs = Lists.newArrayList( command(LsTreeOp.class).setReference(commit.get().getTreeId().toString()) .setStrategy(Strategy.TREES_ONLY).call()); final Set<String> exportLayers; final Set<String> repoLayers = Sets .newHashSet(Iterables.transform(featureTreeRefs, (n) -> n.name())); if (treePaths == null || treePaths.isEmpty()) { exportLayers = repoLayers; } else { final Set<String> requestedLayers = Sets.newHashSet(treePaths); final Set<String> nonExistentLayers = Sets.difference(requestedLayers, repoLayers); checkArgument(nonExistentLayers.isEmpty(), "The following requested layers do not exist in %s: %s", refSpec, nonExistentLayers); exportLayers = requestedLayers; } final String commitId = commit.get().getId().toString() + ":"; return Sets.newHashSet(Iterables.transform(exportLayers, (s) -> commitId + s)); }