Search in sources :

Example 1 with IndexDiffCache

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);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) Collection(java.util.Collection) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) Map(java.util.Map)

Example 2 with IndexDiffCache

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);
}
Also used : IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) RepositoryCacheRule(org.eclipse.egit.ui.internal.RepositoryCacheRule) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File) Test(org.junit.Test)

Example 3 with IndexDiffCache

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;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) Collection(java.util.Collection) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData)

Example 4 with IndexDiffCache

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);
        }
    }
}
Also used : IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) File(java.io.File)

Example 5 with IndexDiffCache

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;
}
Also used : IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)

Aggregations

IndexDiffCache (org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)17 IndexDiffCacheEntry (org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry)8 Repository (org.eclipse.jgit.lib.Repository)8 File (java.io.File)5 Collection (java.util.Collection)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 IProject (org.eclipse.core.resources.IProject)3 IndexDiffData (org.eclipse.egit.core.internal.indexdiff.IndexDiffData)3 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 IFolder (org.eclipse.core.resources.IFolder)2 IResource (org.eclipse.core.resources.IResource)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 CommitOperation (org.eclipse.egit.core.op.CommitOperation)2 ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)2 SWTBotTree (org.eclipse.swtbot.swt.finder.widgets.SWTBotTree)2 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)2 Test (org.junit.Test)2