Search in sources :

Example 31 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class RepositoriesView method selectAndReveal.

private void selectAndReveal(Map<Repository, Collection<String>> pathsByRepo) {
    final List<RepositoryTreeNode> nodesToShow = new ArrayList<>();
    for (Map.Entry<Repository, Collection<String>> entry : pathsByRepo.entrySet()) {
        Repository repository = entry.getKey();
        for (String repoPath : entry.getValue()) {
            final RepositoryTreeNode node = getNodeForPath(repository, repoPath);
            if (node != null) {
                nodesToShow.add(node);
            }
        }
    }
    selectReveal(new StructuredSelection(nodesToShow));
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Collection(java.util.Collection) Map(java.util.Map)

Example 32 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class RepositoriesViewContentProvider method getTagsChildren.

private Object[] getTagsChildren(RepositoryTreeNode parentNode, Repository repo) {
    List<RepositoryTreeNode<Ref>> nodes = new ArrayList<>();
    try (RevWalk walk = new RevWalk(repo)) {
        walk.setRetainBody(true);
        Map<String, Ref> tagRefs = getRefs(repo, Constants.R_TAGS);
        for (Ref tagRef : tagRefs.values()) {
            ObjectId objectId = tagRef.getLeaf().getObjectId();
            RevObject revObject = walk.parseAny(objectId);
            RevObject peeledObject = walk.peel(revObject);
            TagNode tagNode = createTagNode(parentNode, repo, tagRef, revObject, peeledObject);
            nodes.add(tagNode);
        }
    } catch (IOException e) {
        return handleException(e, parentNode);
    }
    return nodes.toArray();
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) ObjectId(org.eclipse.jgit.lib.ObjectId) RevObject(org.eclipse.jgit.revwalk.RevObject) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Example 33 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class RepositoriesViewLabelProvider method getStyledText.

@Override
public StyledString getStyledText(Object element) {
    if (!(element instanceof RepositoryTreeNode))
        return null;
    RepositoryTreeNode node = (RepositoryTreeNode) element;
    switch(node.getType()) {
        case REPO:
            if (node.getParent() != null && node.getParent().getType() == RepositoryTreeNodeType.SUBMODULES)
                return getStyledTextForSubmodule(node);
            return GitLabels.getStyledLabelExtendedSafe(node.getObject());
        case ADDITIONALREF:
            Ref ref = (Ref) node.getObject();
            // shorten the name
            StyledString refName = new StyledString(Repository.shortenRefName(ref.getName()));
            ObjectId refId;
            if (ref.isSymbolic()) {
                refName.append(' ');
                refName.append('[', StyledString.DECORATIONS_STYLER);
                refName.append(ref.getLeaf().getName(), StyledString.DECORATIONS_STYLER);
                refName.append(']', StyledString.DECORATIONS_STYLER);
                refId = ref.getLeaf().getObjectId();
            } else
                refId = ref.getObjectId();
            refName.append(' ');
            RevCommit commit = getLatestCommit(node);
            if (commit != null)
                refName.append(abbreviate(commit), StyledString.QUALIFIER_STYLER).append(' ').append(commit.getShortMessage(), StyledString.QUALIFIER_STYLER);
            else
                refName.append(abbreviate(refId), StyledString.QUALIFIER_STYLER);
            return refName;
        case WORKINGDIR:
            StyledString dirString = new StyledString(UIText.RepositoriesView_WorkingDir_treenode);
            // $NON-NLS-1$
            dirString.append(" - ", StyledString.QUALIFIER_STYLER);
            dirString.append(node.getRepository().getWorkTree().getAbsolutePath(), StyledString.QUALIFIER_STYLER);
            return dirString;
        case REF:
            StyledString styled = null;
            String nodeText = getSimpleText(node);
            if (nodeText != null) {
                styled = new StyledString(nodeText);
                if (verboseBranchMode) {
                    RevCommit latest = getLatestCommit(node);
                    if (latest != null)
                        styled.append(' ').append(abbreviate(latest), StyledString.QUALIFIER_STYLER).append(' ').append(latest.getShortMessage(), StyledString.QUALIFIER_STYLER);
                }
            }
            return styled;
        case TAG:
            return getStyledTextForTag((TagNode) node);
        case STASHED_COMMIT:
            return getStyledTextForCommit((StashedCommitNode) node);
        case SUBMODULES:
            return getStyledTextForSubmodules((SubmodulesNode) node);
        case PUSH:
        // fall through
        case FETCH:
        // fall through
        case FILE:
        // fall through
        case FOLDER:
        // fall through
        case BRANCHES:
        // fall through
        case LOCAL:
        // fall through
        case REMOTETRACKING:
        // fall through
        case BRANCHHIERARCHY:
        // fall through
        case TAGS:
        // fall through;
        case ADDITIONALREFS:
        // fall through
        case REMOTES:
        // fall through
        case REMOTE:
        // fall through
        case STASH:
        // fall through
        case ERROR:
            {
                String label = getSimpleText(node);
                if (label != null)
                    return new StyledString(label);
            }
    }
    return null;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) ObjectId(org.eclipse.jgit.lib.ObjectId) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 34 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class RepositoriesViewLabelProvider method decorateImage.

private Image decorateImage(final Image image, Object element) {
    RepositoryTreeNode node = (RepositoryTreeNode) element;
    switch(node.getType()) {
        case TAG:
        // fall through
        case ADDITIONALREF:
        // fall through
        case REF:
            // if the branch or tag is checked out,
            // we want to decorate the corresponding
            // node with a little check indicator
            String refName = ((Ref) node.getObject()).getName();
            Ref leaf = ((Ref) node.getObject()).getLeaf();
            String branchName;
            String compareString;
            try {
                branchName = node.getRepository().getFullBranch();
                if (branchName == null)
                    return image;
                if (refName.startsWith(Constants.R_HEADS)) {
                    // local branch: HEAD would be on the branch
                    compareString = refName;
                } else if (refName.startsWith(Constants.R_TAGS)) {
                    // tag: HEAD would be on the commit id to which the tag is
                    // pointing
                    TagNode tagNode = (TagNode) node;
                    compareString = tagNode.getCommitId();
                } else if (refName.startsWith(Constants.R_REMOTES)) {
                    // remote branch: HEAD would be on the commit id to which
                    // the branch is pointing
                    ObjectId id = node.getRepository().resolve(refName);
                    if (id == null)
                        return image;
                    try (RevWalk rw = new RevWalk(node.getRepository())) {
                        RevCommit commit = rw.parseCommit(id);
                        compareString = commit.getId().name();
                    }
                } else if (refName.equals(Constants.HEAD)) {
                    return getDecoratedImage(image);
                } else {
                    String leafname = leaf.getName();
                    if (leafname.startsWith(Constants.R_REFS) && leafname.equals(node.getRepository().getFullBranch())) {
                        return getDecoratedImage(image);
                    }
                    ObjectId objectId = leaf.getObjectId();
                    if (objectId != null && objectId.equals(node.getRepository().resolve(Constants.HEAD))) {
                        return getDecoratedImage(image);
                    }
                    // some other symbolic reference
                    return image;
                }
            } catch (IOException e1) {
                return image;
            }
            if (compareString != null && compareString.equals(branchName)) {
                return getDecoratedImage(image);
            }
            return image;
        default:
            return image;
    }
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) ObjectId(org.eclipse.jgit.lib.ObjectId) StyledString(org.eclipse.jface.viewers.StyledString) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 35 with RepositoryTreeNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode in project egit by eclipse.

the class RepositoryPropertySourceProvider method getPropertySource.

@Override
public IPropertySource getPropertySource(Object object) {
    if (object == lastObject)
        return lastRepositorySource;
    if (!(object instanceof RepositoryTreeNode))
        return null;
    registerDisposal();
    removeListener();
    RepositoryTreeNode node = (RepositoryTreeNode) object;
    listenerHandle = node.getRepository().getListenerList().addConfigChangedListener(new ConfigChangedListener() {

        @Override
        public void onConfigChanged(ConfigChangedEvent event) {
            // force a refresh of the page
            lastObject = null;
            myPage.getSite().getShell().getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    myPage.setPropertySourceProvider(RepositoryPropertySourceProvider.this);
                }
            });
        }
    });
    if (node.getType() == RepositoryTreeNodeType.REPO) {
        lastObject = object;
        checkChangeType(SourceType.REPOSITORY);
        lastRepositorySource = new RepositoryPropertySource((Repository) node.getObject(), myPage);
        return lastRepositorySource;
    } else if (node.getType() == RepositoryTreeNodeType.REMOTE) {
        lastObject = object;
        checkChangeType(SourceType.REMOTE);
        lastRepositorySource = new RepositoryRemotePropertySource(node.getRepository().getConfig(), (String) node.getObject(), myPage);
        return lastRepositorySource;
    } else if (node.getType() == RepositoryTreeNodeType.FETCH || node.getType() == RepositoryTreeNodeType.PUSH)
        return getPropertySource(node.getParent());
    else if (node.getType() == RepositoryTreeNodeType.REF) {
        lastObject = object;
        Ref ref = (Ref) node.getObject();
        if (ref.getName().startsWith(Constants.R_HEADS) || ref.getName().startsWith(Constants.R_REMOTES)) {
            checkChangeType(SourceType.BRANCH);
            Repository repository = AdapterUtils.adapt(node, Repository.class);
            lastRepositorySource = new BranchPropertySource(repository, ref.getName(), myPage);
            return lastRepositorySource;
        }
        return null;
    } else
        return null;
}
Also used : ConfigChangedListener(org.eclipse.jgit.events.ConfigChangedListener) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) ConfigChangedEvent(org.eclipse.jgit.events.ConfigChangedEvent)

Aggregations

RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)46 Repository (org.eclipse.jgit.lib.Repository)17 Ref (org.eclipse.jgit.lib.Ref)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)11 ArrayList (java.util.ArrayList)10 TagNode (org.eclipse.egit.ui.internal.repository.tree.TagNode)10 IOException (java.io.IOException)9 File (java.io.File)8 IResource (org.eclipse.core.resources.IResource)7 RefNode (org.eclipse.egit.ui.internal.repository.tree.RefNode)6 IPath (org.eclipse.core.runtime.IPath)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 RevObject (org.eclipse.jgit.revwalk.RevObject)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)3 Path (org.eclipse.core.runtime.Path)3 Job (org.eclipse.core.runtime.jobs.Job)3 FileNode (org.eclipse.egit.ui.internal.repository.tree.FileNode)3 RemoteNode (org.eclipse.egit.ui.internal.repository.tree.RemoteNode)3 StashedCommitNode (org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode)3