Search in sources :

Example 1 with RefsChangedEvent

use of org.eclipse.jgit.events.RefsChangedEvent in project egit by eclipse.

the class StashDropOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor pm) throws CoreException {
            StashDropCommand command = Git.wrap(repo).stashDrop();
            command.setStashRef(index);
            try {
                command.call();
                repo.fireEvent(new RefsChangedEvent());
            } catch (JGitInternalException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } catch (GitAPIException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) RefsChangedEvent(org.eclipse.jgit.events.RefsChangedEvent) StashDropCommand(org.eclipse.jgit.api.StashDropCommand)

Example 2 with RefsChangedEvent

use of org.eclipse.jgit.events.RefsChangedEvent in project egit by eclipse.

the class RepositoriesViewContentProvider method getRefs.

private synchronized Map<String, Ref> getRefs(final Repository repo, final String prefix) throws IOException {
    Map<String, Ref> allRefs = branchRefs.get(repo);
    if (allRefs == null) {
        allRefs = repo.getRefDatabase().getRefs(RefDatabase.ALL);
        branchRefs.put(repo, allRefs);
        if (refsChangedListeners.get(repo) == null) {
            RefsChangedListener listener = new RefsChangedListener() {

                @Override
                public void onRefsChanged(RefsChangedEvent event) {
                    synchronized (RepositoriesViewContentProvider.this) {
                        branchRefs.remove(repo);
                    }
                }
            };
            refsChangedListeners.put(repo, repo.getListenerList().addRefsChangedListener(listener));
        }
    }
    if (prefix.equals(RefDatabase.ALL))
        return allRefs;
    Map<String, Ref> filtered = new HashMap<>();
    for (Map.Entry<String, Ref> entry : allRefs.entrySet()) {
        if (entry.getKey().startsWith(prefix))
            filtered.put(entry.getKey(), entry.getValue());
    }
    return filtered;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) RefsChangedEvent(org.eclipse.jgit.events.RefsChangedEvent) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) RefsChangedListener(org.eclipse.jgit.events.RefsChangedListener)

Aggregations

RefsChangedEvent (org.eclipse.jgit.events.RefsChangedEvent)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 StashDropCommand (org.eclipse.jgit.api.StashDropCommand)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 JGitInternalException (org.eclipse.jgit.api.errors.JGitInternalException)1 RefsChangedListener (org.eclipse.jgit.events.RefsChangedListener)1 Ref (org.eclipse.jgit.lib.Ref)1 TeamException (org.eclipse.team.core.TeamException)1