/** * @param pathFilter if specified, only changes that match the filter will be returned * @return an iterator for all of the differences between the work tree and the index based on * the path filter. */ @Override public AutoCloseableIterator<DiffEntry> getUnstaged(final @Nullable String pathFilter) { AutoCloseableIterator<DiffEntry> unstaged = context.command(DiffWorkTree.class) .setFilter(pathFilter).setReportTrees(true).call(); return unstaged; }
/** * @return the tree referenced by the old ref, or the head of the index. */ private RevTree getOldTree() { final String oldVersion = Optional.fromNullable(refSpec).or(Ref.STAGE_HEAD); Optional<ObjectId> headTreeId = command(ResolveTreeish.class).setTreeish(oldVersion).call(); Preconditions.checkArgument(headTreeId.isPresent(), "Refspec " + oldVersion + " does not resolve to a tree"); final RevTree headTree; headTree = command(RevObjectParse.class).setObjectId(headTreeId.get()).call(RevTree.class) .get(); return headTree; }
/** * @see java.util.concurrent.Callable#call() */ protected WorkingTree _call() { if (path != null) { // check that is a valid path NodeRef.checkValidPath(path); Optional<NodeRef> ref = command(FindTreeChild.class).setParent(workingTree().getTree()) .setChildPath(path).call(); Preconditions.checkArgument(ref.isPresent(), "pathspec '%s' did not match any tree", path); Preconditions.checkArgument(ref.get().getType() == TYPE.TREE, "pathspec '%s' did not resolve to a tree", path); } try (final AutoCloseableIterator<DiffEntry> unstaged = command(DiffWorkTree.class) .setFilter(path).call()) { final Iterator<DiffEntry> added = filter(unstaged, new Predicate<DiffEntry>() { @Override public boolean apply(@Nullable DiffEntry input) { return input.changeType().equals(ChangeType.ADDED); } }); workingTree().delete(transform(added, (de) -> de.newPath()), getProgressListener()); } return workingTree(); }
} else if (newRefSpec == null) { DiffWorkTree workTreeIndexDiff = command(DiffWorkTree.class).setFilter(pathFilter) .setReportTrees(reportTrees).setPreserveIterationOrder(preserveIterationOrder); if (oldRefSpec != null) { workTreeIndexDiff.setOldVersion(oldRefSpec); iterator = workTreeIndexDiff.call(); } else {
/** * Implements {@link Supplier#get()} by deferring to {@link #call()} * * @see #call() */ @Override public AutoCloseableIterator<DiffEntry> get() { return call(); }
/** * If no {@link #setOldVersion(String) old version} was set, returns the differences between the * working tree and the index, otherwise the differences between the working tree and the * specified revision. * * @return an iterator to a set of differences between the two trees * @see DiffEntry */ @Override protected AutoCloseableIterator<DiffEntry> _call() { final Optional<String> ref = Optional.fromNullable(refSpec); final RevTree oldTree = ref.isPresent() ? getOldTree() : stagingArea().getTree(); final RevTree newTree = workingTree().getTree(); DiffTree diff = command(DiffTree.class).setReportTrees(this.reportTrees) .setOldTree(oldTree.getId()).setNewTree(newTree.getId()).setMaxDiffs(limit) .setPreserveIterationOrder(preserveIterationOrder); if (this.pathFilter != null) { diff.setPathFilter(ImmutableList.of(pathFilter)); } return diff.call(); }
@Override public void write(ResponseWriter writer) throws Exception { writer.start(); if (!currHead.isPresent()) { writer.writeErrors("Repository has no HEAD."); } else { if (currHead.get() instanceof SymRef) { final SymRef headRef = (SymRef) currHead.get(); writer.writeHeaderElements("branch", Ref.localName(headRef.getTarget())); } } writer.writeStaged(geogig.command(DiffIndex.class).addFilter(pathFilter), offset, limit); writer.writeUnstaged(geogig.command(DiffWorkTree.class).setFilter(pathFilter), offset, limit); writer.writeUnmerged(geogig.command(ConflictsQueryOp.class).call(), offset, limit); writer.finish(); } });
@Override protected StatusSummary _call() { WorkingTree workTree = workingTree(); StagingArea index = stagingArea(); StatusSummary summary = new StatusSummary(); summary.countStaged = index.countStaged(null).count(); summary.countUnstaged = workTree.countUnstaged(null).count(); summary.countConflicted = index.countConflicted(null); final Long limit = this.limit == null ? null : this.limit; if (limit == null || limit.longValue() > 0) { if (summary.countStaged > 0) { summary.staged = command(DiffIndex.class).setMaxDiffs(limit).setReportTrees(true); } if (summary.countUnstaged > 0) { summary.unstaged = command(DiffWorkTree.class).setMaxDiffs(limit) .setReportTrees(true); } if (summary.countConflicted > 0) { summary.conflicts = command(ConflictsQueryOp.class); } } return summary; }
} else if (newRefSpec == null) { DiffWorkTree workTreeIndexDiff = command(DiffWorkTree.class).setFilter(pathFilter) .setReportTrees(reportTrees).setPreserveIterationOrder(preserveIterationOrder); if (oldRefSpec != null) { workTreeIndexDiff.setOldVersion(oldRefSpec); iterator = workTreeIndexDiff.call(); } else {
/** * Implements {@link Supplier#get()} by deferring to {@link #call()} * * @see #call() */ @Override public AutoCloseableIterator<DiffEntry> get() { return call(); }
/** * If no {@link #setOldVersion(String) old version} was set, returns the differences between the * working tree and the index, otherwise the differences between the working tree and the * specified revision. * * @return an iterator to a set of differences between the two trees * @see DiffEntry */ @Override protected AutoCloseableIterator<DiffEntry> _call() { final Optional<String> ref = Optional.fromNullable(refSpec); final RevTree oldTree = ref.isPresent() ? getOldTree() : stagingArea().getTree(); final RevTree newTree = workingTree().getTree(); DiffTree diff = command(DiffTree.class).setReportTrees(this.reportTrees) .setOldTree(oldTree.getId()).setNewTree(newTree.getId()).setMaxDiffs(limit) .setPreserveIterationOrder(preserveIterationOrder); if (this.pathFilter != null) { diff.setPathFilter(ImmutableList.of(pathFilter)); } return diff.call(); }
@Override protected StatusSummary _call() { WorkingTree workTree = workingTree(); StagingArea index = stagingArea(); StatusSummary summary = new StatusSummary(); summary.countStaged = index.countStaged(null).count(); summary.countUnstaged = workTree.countUnstaged(null).count(); summary.countConflicted = index.countConflicted(null); final Long limit = this.limit == null ? null : this.limit; if (limit == null || limit.longValue() > 0) { if (summary.countStaged > 0) { summary.staged = command(DiffIndex.class).setMaxDiffs(limit).setReportTrees(true); } if (summary.countUnstaged > 0) { summary.unstaged = command(DiffWorkTree.class).setMaxDiffs(limit) .setReportTrees(true); } if (summary.countConflicted > 0) { summary.conflicts = command(ConflictsQueryOp.class); } } return summary; }
/** * @param pathFilter if specified, only changes that match the filter will be returned * @return an iterator for all of the differences between the work tree and the index based on * the path filter. */ @Override public AutoCloseableIterator<DiffEntry> getUnstaged(final @Nullable String pathFilter) { AutoCloseableIterator<DiffEntry> unstaged = context.command(DiffWorkTree.class) .setFilter(pathFilter).setReportTrees(true).call(); return unstaged; }
/** * Writes unstaged changes to the stream. * * @param setFilter the configured {@link DiffWorkTree} command * @param start the change number to start writing from * @param length the number of changes to write * @throws StreamWriterException */ public void writeUnstaged(DiffWorkTree setFilter, int start, int length) throws StreamWriterException { writeDiffEntries("unstaged", start, length, setFilter.call()); }
/** * @return the tree referenced by the old ref, or the head of the index. */ private RevTree getOldTree() { final String oldVersion = Optional.fromNullable(refSpec).or(Ref.STAGE_HEAD); Optional<ObjectId> headTreeId = command(ResolveTreeish.class).setTreeish(oldVersion).call(); Preconditions.checkArgument(headTreeId.isPresent(), "Refspec " + oldVersion + " does not resolve to a tree"); final RevTree headTree; headTree = command(RevObjectParse.class).setObjectId(headTreeId.get()).call(RevTree.class) .get(); return headTree; }
@Test public void testClean() throws Exception { insert(points1, points2, points3); geogig.command(CleanOp.class).call(); try (AutoCloseableIterator<DiffEntry> deleted = geogig.command(DiffWorkTree.class).call()) { ArrayList<DiffEntry> list = Lists.newArrayList(deleted); // Check that all the features have been deleted assertEquals(0, list.size()); } }