use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.
the class DeletePathsOperation method refreshIndexDiffCache.
private void refreshIndexDiffCache(List<IPath> refreshCachePaths, boolean refreshAll) {
Map<Repository, Collection<String>> resourcesByRepository = ResourceUtil.splitPathsByRepository(refreshCachePaths);
for (Map.Entry<Repository, Collection<String>> entry : resourcesByRepository.entrySet()) {
Repository repository = entry.getKey();
Collection<String> files = entry.getValue();
IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
IndexDiffCacheEntry cacheEntry = cache.getIndexDiffCacheEntry(repository);
if (cacheEntry != null)
if (refreshAll)
cacheEntry.refresh();
else
cacheEntry.refreshFiles(files);
}
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.
the class GitRepositoriesViewRepoDeletionTest method testRemoveRepositoryRemoveFromCachesBug483664.
@Test
public void testRemoveRepositoryRemoveFromCachesBug483664() throws Exception {
Activator.getDefault().getPreferenceStore().setValue(UIPreferences.ALWAYS_USE_STAGING_VIEW, false);
deleteAllProjects();
assertProjectExistence(PROJ1, false);
clearView();
refreshAndWait();
Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryFile);
refreshAndWait();
assertHasRepo(repositoryFile);
SWTBotTree tree = getOrOpenView().bot().tree();
tree.getAllItems()[0].select();
ContextMenuHelper.clickContextMenuSync(tree, myUtil.getPluginLocalizedValue(REMOVE_REPOSITORY_FROM_VIEW_CONTEXT_MENU_LABEL));
TestUtil.joinJobs(JobFamilies.REPOSITORY_DELETE);
refreshAndWait();
assertEmpty();
assertTrue(repositoryFile.exists());
assertTrue(new File(repositoryFile.getParentFile(), PROJ1).isDirectory());
TestUtil.waitForDecorations();
closeGitViews();
TestUtil.waitForJobs(500, 5000);
// Session properties are stored in the Eclipse resource tree as part of
// the resource info. org.eclipse.core.internal.dtree.DataTreeLookup has
// a static LRU cache of lookup instances to avoid excessive strain on
// the garbage collector due to constantly allocating and then
// forgetting instances. These lookup objects may contain things
// recently queried or modified in the resource tree, such as session
// properties. As a result, the session properties of a deleted resource
// remain around a little longer than expected: to be precise, exactly
// 100 more queries on the Eclipse resource tree until the entry
// containing the session property is recycled. We use session
// properties to store the RepositoryMappings, which reference the
// repository.
//
// Make sure we clear that cache:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(PROJ1);
for (int i = 0; i < 101; i++) {
// Number of iterations at least DataTreeLookup.POOL_SIZE!
// Use up one DataTreeLookup instance:
project.create(null);
if (i == 0) {
// Furthermore, the WorkbenchSourceProvider has still a
// reference to the last selection, which is our now long
// removed repository node! Arguably that's a strange thing, but
// strictly speaking, since there is no guarantee _when_ a
// weakly referenced object is removed, not even making
// WorkbenchSourceProvider.lastShowInSelection a WeakReference
// might help. Therefore, let's make sure that the last "show
// in" selection is no longer the RepositoryNode, which also
// still has a reference to the repository. That last "show in"
// selection is set when the "Shown in..." context menu is
// filled, which happens when the project explorer's context
// menu is activated. So we have to open that menu at least once
// with a different selection.
SWTBotTree explorerTree = TestUtil.getExplorerTree();
SWTBotTreeItem projectNode = TestUtil.navigateTo(explorerTree, PROJ1);
projectNode.select();
ContextMenuHelper.isContextMenuItemEnabled(explorerTree, "New");
}
project.delete(true, true, null);
}
TestUtil.waitForJobs(500, 5000);
// And we may have the RepositoryChangeScanner running: use a job
// with a scheduling rule that ensures we have exclusive access.
final String[] results = { null, null };
Job verifier = new Job(testName.getMethodName()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
// for scheduled jobs.
try {
TestUtil.joinJobs(org.eclipse.egit.core.JobFamilies.INDEX_DIFF_CACHE_UPDATE);
// Is this job doing something when the view is hidden?
TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH);
TestUtil.waitForDecorations();
} catch (InterruptedException e) {
results[0] = "Interrupted";
Thread.currentThread().interrupt();
return Status.CANCEL_STATUS;
}
// Finally... Java does not give any guarantees about when
// exactly an only weakly reachable object is finalized and
// garbage collected.
waitForFinalization(5000);
// Experience shows that an explicit garbage collection run very
// often does reclaim only weakly reachable objects and set the
// weak references' referents to null, but not even that can be
// guaranteed! Whether or not it does may also depend on the
// configuration of the JVM (such as through command-line
// arguments).
Repository[] repositories = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().getAllRepositories();
results[0] = Arrays.asList(repositories).toString();
IndexDiffCache indexDiffCache = org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache();
results[1] = indexDiffCache.currentCacheEntries().toString();
return Status.OK_STATUS;
}
};
verifier.setRule(new RepositoryCacheRule());
verifier.setSystem(true);
verifier.schedule();
verifier.join();
List<String> configuredRepos = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil().getConfiguredRepositories();
assertTrue("Expected no configured repositories", configuredRepos.isEmpty());
assertEquals("Expected no cached repositories", "[]", results[0]);
assertEquals("Expected no IndexDiffCache entries", "[]", results[1]);
Activator.getDefault().getPreferenceStore().setValue(UIPreferences.ALWAYS_USE_STAGING_VIEW, true);
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.
the class GitScopeOperation method promptForInputChange.
@Override
protected boolean promptForInputChange(String requestPreviewMessage, IProgressMonitor monitor) {
List<IResource> relevantResources = getRelevantResources();
Map<Repository, Collection<String>> pathsByRepo = ResourceUtil.splitResourcesByRepository(relevantResources);
for (Map.Entry<Repository, Collection<String>> entry : pathsByRepo.entrySet()) {
Repository repository = entry.getKey();
Collection<String> paths = entry.getValue();
IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
if (cache == null)
continue;
IndexDiffCacheEntry cacheEntry = cache.getIndexDiffCacheEntry(repository);
if (cacheEntry == null)
continue;
IndexDiffData indexDiff = cacheEntry.getIndexDiff();
if (indexDiff == null)
continue;
if (hasAnyPathChanged(paths, indexDiff))
return super.promptForInputChange(requestPreviewMessage, monitor);
}
return false;
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.
the class RepositoryCache method clear.
/**
* Removes all cached repositories and their IndexDiffCache entries.
*/
public void clear() {
List<File> gitDirs;
synchronized (repositoryCache) {
gitDirs = new ArrayList<>(repositoryCache.keySet());
repositoryCache.clear();
}
IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
if (cache != null) {
for (File f : gitDirs) {
cache.remove(f);
}
}
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.
the class IndexDiffCacheTest method prepareCacheEntry.
private IndexDiffCacheEntry prepareCacheEntry() {
listenerCalled.set(false);
indexDiffDataResult.set(null);
IndexDiffCache indexDiffCache = Activator.getDefault().getIndexDiffCache();
indexDiffCache.addIndexDiffChangedListener(indexDiffListener);
// This call should trigger an indexDiffChanged event
IndexDiffCacheEntry cacheEntry = indexDiffCache.getIndexDiffCacheEntry(repository);
return cacheEntry;
}
Aggregations