Search in sources :

Example 11 with IndexDiffCache

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.

the class ShowBlameActionHandlerTest method createJavaProjectAndCommitToRepository.

private IJavaProject createJavaProjectAndCommitToRepository() throws Exception {
    Repository myRepository = createLocalTestRepository(REPO1);
    File gitDir = myRepository.getDirectory();
    IJavaProject jProject = createJavaProject(myRepository, JAVA_PROJECT_NAME);
    IProject project = jProject.getProject();
    try {
        new ConnectProviderOperation(project, gitDir).execute(null);
    } catch (Exception e) {
        Activator.logError("Failed to connect project to repository", e);
    }
    assertConnected(project);
    // Check in at least the java file
    IFolder folder = project.getFolder(SRC_FOLDER_NAME).getFolder(PACKAGE_NAME);
    IFile file = folder.getFile(JAVA_FILE_NAME);
    IFile[] commitables = new IFile[] { file };
    ArrayList<IFile> untracked = new ArrayList<IFile>();
    untracked.addAll(Arrays.asList(commitables));
    // commit to master
    CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
    op.execute(null);
    // Make sure cache entry is already listening for changes
    IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
    cache.getIndexDiffCacheEntry(lookupRepository(gitDir));
    return jProject;
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) Repository(org.eclipse.jgit.lib.Repository) IJavaProject(org.eclipse.jdt.core.IJavaProject) CommitOperation(org.eclipse.egit.core.op.CommitOperation) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with IndexDiffCache

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.

the class DeletePathsOperationTest method initIndexDiffCache.

private static void initIndexDiffCache(Repository repository) throws Exception {
    IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
    IndexDiffCacheEntry cacheEntry = cache.getIndexDiffCacheEntry(repository);
    assertNotNull(cacheEntry);
    Job.getJobManager().join(JobFamilies.INDEX_DIFF_CACHE_UPDATE, null);
}
Also used : IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)

Example 13 with IndexDiffCache

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.

the class Activator method start.

@Override
public void start(final BundleContext context) throws Exception {
    super.start(context);
    pluginId = context.getBundle().getSymbolicName();
    Config.setTypedConfigGetter(new ReportingTypedConfigGetter());
    // we want to be notified about debug options changes
    Dictionary<String, String> props = new Hashtable<String, String>(4);
    props.put(DebugOptions.LISTENER_SYMBOLICNAME, pluginId);
    context.registerService(DebugOptionsListener.class.getName(), this, props);
    setupSSH(context);
    setupProxy(context);
    repositoryCache = new RepositoryCache();
    indexDiffCache = new IndexDiffCache();
    try {
        GitProjectData.reconfigureWindowCache();
    } catch (RuntimeException e) {
        logError(CoreText.Activator_ReconfigureWindowCacheError, e);
    }
    GitProjectData.attachToWorkspace();
    repositoryUtil = new RepositoryUtil();
    secureStore = new EGitSecureStore(SecurePreferencesFactory.getDefault());
    registerAutoShareProjects();
    registerAutoIgnoreDerivedResources();
    registerPreDeleteResourceChangeListener();
    registerMergeStrategyRegistryListener();
}
Also used : Hashtable(java.util.Hashtable) EGitSecureStore(org.eclipse.egit.core.securestorage.EGitSecureStore) DebugOptionsListener(org.eclipse.osgi.service.debug.DebugOptionsListener) ReportingTypedConfigGetter(org.eclipse.egit.core.internal.ReportingTypedConfigGetter) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)

Example 14 with IndexDiffCache

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.

the class RepositoryCache method prune.

private void prune() {
    List<File> toRemove = new ArrayList<>();
    synchronized (repositoryCache) {
        for (Iterator<Map.Entry<File, Reference<Repository>>> i = repositoryCache.entrySet().iterator(); i.hasNext(); ) {
            Map.Entry<File, Reference<Repository>> entry = i.next();
            Repository repository = entry.getValue().get();
            if (repository == null || !repository.getDirectory().exists()) {
                i.remove();
                toRemove.add(entry.getKey());
            }
        }
    }
    IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
    if (cache != null) {
        for (File f : toRemove) {
            cache.remove(f);
        }
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Reference(java.lang.ref.Reference) WeakReference(java.lang.ref.WeakReference) ArrayList(java.util.ArrayList) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with IndexDiffCache

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.

the class GitMoveDeleteHook method deleteFile.

@Override
public boolean deleteFile(final IResourceTree tree, final IFile file, final int updateFlags, final IProgressMonitor monitor) {
    if (!org.eclipse.egit.core.Activator.autoStageDeletion()) {
        return false;
    }
    // Linked resources are not files, hence not tracked by git
    if (file.isLinked())
        return false;
    final boolean force = (updateFlags & IResource.FORCE) == IResource.FORCE;
    if (!force && !tree.isSynchronized(file, IResource.DEPTH_ZERO))
        return false;
    final RepositoryMapping map = RepositoryMapping.getMapping(file);
    if (map == null)
        return false;
    String repoRelativePath = map.getRepoRelativePath(file);
    IndexDiffCache indexDiffCache = Activator.getDefault().getIndexDiffCache();
    IndexDiffCacheEntry indexDiffCacheEntry = indexDiffCache.getIndexDiffCacheEntry(map.getRepository());
    if (indexDiffCacheEntry == null) {
        return false;
    }
    IndexDiffData indexDiff = indexDiffCacheEntry.getIndexDiff();
    if (indexDiff != null) {
        if (indexDiff.getUntracked().contains(repoRelativePath))
            return false;
        if (indexDiff.getIgnoredNotInIndex().contains(repoRelativePath))
            return false;
    }
    if (!file.exists())
        return false;
    if (file.isDerived())
        return false;
    DirCache dirc = null;
    try {
        dirc = map.getRepository().lockDirCache();
        final int first = dirc.findEntry(repoRelativePath);
        if (first < 0) {
            dirc.unlock();
            return false;
        }
        final DirCacheBuilder edit = dirc.builder();
        if (first > 0)
            edit.keep(0, first);
        final int next = dirc.nextEntry(first);
        if (next < dirc.getEntryCount())
            edit.keep(next, dirc.getEntryCount() - next);
        if (!edit.commit())
            tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, null));
        tree.standardDeleteFile(file, updateFlags, monitor);
    } catch (LockFailedException e) {
        // FIXME The index is currently locked. This notably happens during
        // rebase operations. auto-staging deletions should be queued... and
        // the queued job will have to double-check whether the file has
        // truly been deleted or if it was only deleted to be replaced by
        // another version.
        // This hook only exists to automatically add changes to the index.
        // If the index is currently locked, do not accept the
        // responsibility of deleting the file, return false to tell the
        // workspace it can continue with the standard deletion. The user
        // will have to stage the deletion later on _if_ this was truly
        // needed, which won't happen for calls triggered by merge
        // operations from the merge strategies.
        Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.getPluginId(), MessageFormat.format(CoreText.MoveDeleteHook_cannotAutoStageDeletion, file.getLocation())));
        return FINISH_FOR_ME;
    } catch (IOException e) {
        tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, e));
    } finally {
        if (dirc != null)
            dirc.unlock();
    }
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DirCache(org.eclipse.jgit.dircache.DirCache) DirCacheBuilder(org.eclipse.jgit.dircache.DirCacheBuilder) LockFailedException(org.eclipse.jgit.errors.LockFailedException) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IOException(java.io.IOException) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData)

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