use of org.eclipse.jgit.treewalk.WorkingTreeIterator in project egit by eclipse.
the class IndexDiffCacheEntry method calcIndexDiffDataFull.
private IndexDiffData calcIndexDiffDataFull(IProgressMonitor monitor, String jobName, Repository repository) throws IOException {
EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(monitor);
IndexDiff newIndexDiff;
WorkingTreeIterator iterator = IteratorService.createInitialIterator(repository);
if (iterator == null)
// workspace is closed
return null;
newIndexDiff = new IndexDiff(repository, Constants.HEAD, iterator);
newIndexDiff.diff(jgitMonitor, 0, 0, jobName);
return new IndexDiffData(newIndexDiff);
}
use of org.eclipse.jgit.treewalk.WorkingTreeIterator in project egit by eclipse.
the class CommitUI method getIndexDiff.
/**
* Calculates a fresh {@link IndexDiff} for the given repository.
*
* @param repository
* to compute the {@link IndexDiff} for
* @param selectedProjects
* of the repository; used to get an estimate for the progress
* monitor; may be empty
* @param monitor
* for progress reporting and cancellation
* @return the {@link IndexDiff}
* @throws IOException
* if an error occurred
* @throws OperationCanceledException
* if the operation was cancelled
*/
public static IndexDiff getIndexDiff(Repository repository, IProject[] selectedProjects, IProgressMonitor monitor) throws IOException, OperationCanceledException {
SubMonitor progress = SubMonitor.convert(monitor, UIText.CommitActionHandler_calculatingChanges, 1000);
EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(progress);
CountingVisitor counter = new CountingVisitor();
for (IProject p : selectedProjects) {
try {
p.accept(counter);
} catch (CoreException e) {
// ignore
}
}
WorkingTreeIterator it = IteratorService.createInitialIterator(repository);
if (it == null) {
// Workspace is closed
throw new OperationCanceledException();
}
IndexDiff diff = new IndexDiff(repository, Constants.HEAD, it);
diff.diff(jgitMonitor, counter.count, 0, NLS.bind(UIText.CommitActionHandler_repository, repository.getDirectory().getPath()));
if (progress.isCanceled()) {
throw new OperationCanceledException();
}
return diff;
}
use of org.eclipse.jgit.treewalk.WorkingTreeIterator in project egit by eclipse.
the class IgnoreOperation method pruneFolder.
private void pruneFolder(IPath folder, Collection<String> files, IProgressMonitor monitor) throws IOException {
if (files.isEmpty()) {
return;
}
Repository repository = Activator.getDefault().getRepositoryCache().getRepository(folder);
if (repository == null || repository.isBare()) {
files.clear();
return;
}
WorkingTreeIterator treeIterator = IteratorService.createInitialIterator(repository);
if (treeIterator == null) {
files.clear();
return;
}
IPath repoRelativePath = folder.makeRelativeTo(new Path(repository.getWorkTree().getAbsolutePath()));
if (repoRelativePath.equals(folder)) {
files.clear();
return;
}
Collection<String> repoRelative = new HashSet<>(files.size());
for (String file : files) {
repoRelative.add(repoRelativePath.append(file).toPortableString());
}
// Remove all entries,then re-add only those found during the tree walk
// that are not ignored already
files.clear();
try (TreeWalk walk = new TreeWalk(repository)) {
walk.addTree(treeIterator);
walk.setFilter(PathFilterGroup.createFromStrings(repoRelative));
while (walk.next()) {
if (monitor.isCanceled()) {
return;
}
WorkingTreeIterator workingTreeIterator = walk.getTree(0, WorkingTreeIterator.class);
if (repoRelative.contains(walk.getPathString())) {
if (!workingTreeIterator.isEntryIgnored()) {
files.add(walk.getNameString());
}
} else if (workingTreeIterator.getEntryFileMode().equals(FileMode.TREE)) {
walk.enterSubtree();
}
}
}
}
Aggregations