Search in sources :

Example 11 with TagNode

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

the class RepositoriesViewContentProvider method createTagNode.

private TagNode createTagNode(RepositoryTreeNode parentNode, Repository repo, Ref ref, RevObject revObject, RevObject peeledObject) {
    boolean annotated = (revObject instanceof RevTag);
    if (peeledObject instanceof RevCommit) {
        RevCommit commit = (RevCommit) peeledObject;
        String id = commit.getId().name();
        String message = commit.getShortMessage();
        return new TagNode(parentNode, repo, ref, annotated, id, message);
    } else {
        // $NON-NLS-1$ //$NON-NLS-2$
        return new TagNode(parentNode, repo, ref, annotated, "", "");
    }
}
Also used : RevTag(org.eclipse.jgit.revwalk.RevTag) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 12 with TagNode

use of org.eclipse.egit.ui.internal.repository.tree.TagNode 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 13 with TagNode

use of org.eclipse.egit.ui.internal.repository.tree.TagNode 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 14 with TagNode

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

the class PushTagsWizard method getRefSpecs.

private List<RefSpec> getRefSpecs() {
    List<RefSpec> specs = new ArrayList<>();
    String prefix;
    if (pushTagsPage.isForceUpdateSelected())
        // $NON-NLS-1$
        prefix = "+";
    else
        // $NON-NLS-1$
        prefix = "";
    for (TagNode tag : pushTagsPage.getSelectedTags()) {
        String refName = tag.getObject().getName();
        RefSpec spec = new RefSpec(prefix + refName);
        specs.add(spec);
    }
    return specs;
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) ArrayList(java.util.ArrayList) TagNode(org.eclipse.egit.ui.internal.repository.tree.TagNode)

Aggregations

TagNode (org.eclipse.egit.ui.internal.repository.tree.TagNode)14 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)10 ArrayList (java.util.ArrayList)5 RefNode (org.eclipse.egit.ui.internal.repository.tree.RefNode)5 Ref (org.eclipse.jgit.lib.Ref)5 Repository (org.eclipse.jgit.lib.Repository)5 IOException (java.io.IOException)4 FileNode (org.eclipse.egit.ui.internal.repository.tree.FileNode)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 File (java.io.File)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 AdditionalRefNode (org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode)2 StashedCommitNode (org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 RevObject (org.eclipse.jgit.revwalk.RevObject)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2