Search in sources :

Example 1 with RefsChangedListener

use of org.eclipse.jgit.events.RefsChangedListener 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

HashMap (java.util.HashMap)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 RefsChangedEvent (org.eclipse.jgit.events.RefsChangedEvent)1 RefsChangedListener (org.eclipse.jgit.events.RefsChangedListener)1 Ref (org.eclipse.jgit.lib.Ref)1