Example usage for org.eclipse.jgit.lib Constants R_REMOTES

List of usage examples for org.eclipse.jgit.lib Constants R_REMOTES

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants R_REMOTES.

Prototype

String R_REMOTES

To view the source code for org.eclipse.jgit.lib Constants R_REMOTES.

Click Source Link

Document

Prefix for remotes refs

Usage

From source file:org.eclipse.egit.ui.internal.actions.SynchronizeWithAction.java

License:Open Source License

private SyncRepoEntity getLocalSyncRepo(Repository repo) {
    Set<String> allRefs = repo.getAllRefs().keySet();
    SyncRepoEntity local = new SyncRepoEntity(UIText.SynchronizeWithAction_localRepoName);
    for (String ref : allRefs) {
        if (!ref.startsWith(Constants.R_REMOTES)) {
            String name = ref.substring(ref.lastIndexOf('/') + 1);
            local.addRef(new SyncRefEntity(name, ref));
        }/*from w w w .  j a  va2s .  c  o  m*/
    }
    return local;
}

From source file:org.eclipse.egit.ui.internal.actions.SynchronizeWithAction.java

License:Open Source License

private Collection<Ref> getRemoteRef(RefDatabase refDb, String remoteName) throws InvocationTargetException {
    try {//  www  .j  av a2  s . co m
        return refDb.getRefs(Constants.R_REMOTES + remoteName + "/").values(); //$NON-NLS-1$
    } catch (IOException e) {
        throw new InvocationTargetException(e);
    }
}

From source file:org.eclipse.egit.ui.internal.actions.SynchronizeWithActionHandler.java

License:Open Source License

private Collection<Ref> getRemoteRef(RefDatabase refDb, String remoteName) throws IOException {
    return refDb.getRefs(Constants.R_REMOTES + remoteName + "/").values(); //$NON-NLS-1$
}

From source file:org.eclipse.egit.ui.internal.actions.SynchronizeWithMenu.java

License:Open Source License

@Override
public void fill(final Menu menu, int index) {
    if (srv == null)
        return;/*from  w  w  w .  ja v  a  2s . co m*/
    final IResource selectedResource = getSelection();
    if (selectedResource == null || selectedResource.isLinked(IResource.CHECK_ANCESTORS))
        return;

    RepositoryMapping mapping = RepositoryMapping.getMapping(selectedResource.getProject());
    if (mapping == null)
        return;

    final Repository repo = mapping.getRepository();
    if (repo == null)
        return;

    List<Ref> refs = new LinkedList<Ref>();
    RefDatabase refDatabase = repo.getRefDatabase();
    try {
        refs.addAll(refDatabase.getAdditionalRefs());
    } catch (IOException e) {
        // do nothing
    }
    try {
        refs.addAll(refDatabase.getRefs(RefDatabase.ALL).values());
    } catch (IOException e) {
        // do nothing
    }
    Collections.sort(refs, CommonUtils.REF_ASCENDING_COMPARATOR);
    String currentBranch;
    try {
        currentBranch = repo.getFullBranch();
    } catch (IOException e) {
        currentBranch = ""; //$NON-NLS-1$
    }

    int count = 0;
    String oldName = null;
    int refsLength = R_REFS.length();
    int tagsLength = R_TAGS.substring(refsLength).length();
    for (Ref ref : refs) {
        final String name = ref.getName();
        if (name.equals(Constants.HEAD) || name.equals(currentBranch) || excludeTag(ref, repo))
            continue;
        if (name.startsWith(R_REFS) && oldName != null
                && !oldName.regionMatches(refsLength, name, refsLength, tagsLength))
            new MenuItem(menu, SWT.SEPARATOR);

        MenuItem item = new MenuItem(menu, SWT.PUSH);
        item.setText(name);
        if (name.startsWith(Constants.R_TAGS))
            item.setImage(tagImage);
        else if (name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_REMOTES))
            item.setImage(branchImage);

        item.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent event) {
                GitSynchronizeData data;
                try {
                    data = new GitSynchronizeData(repo, HEAD, name, true);
                    if (!(selectedResource instanceof IProject)) {
                        HashSet<IContainer> containers = new HashSet<IContainer>();
                        containers.add((IContainer) selectedResource);
                        data.setIncludedPaths(containers);
                    }

                    GitModelSynchronize.launch(data, new IResource[] { selectedResource });
                } catch (IOException e) {
                    Activator.logError(e.getMessage(), e);
                }
            }
        });

        if (++count == MAX_NUM_MENU_ENTRIES)
            break;
        oldName = name;
    }

    if (count > 1)
        new MenuItem(menu, SWT.SEPARATOR);

    MenuItem custom = new MenuItem(menu, SWT.PUSH);
    custom.setText(UIText.SynchronizeWithMenu_custom);
    custom.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            GitSynchronizeWizard gitWizard = new GitSynchronizeWizard();
            WizardDialog wizard = new WizardDialog(menu.getShell(), gitWizard);
            wizard.create();
            wizard.open();
        }
    });
}

From source file:org.eclipse.egit.ui.internal.commit.CommitEditorPage.java

License:Open Source License

private List<Ref> loadBranches() {
    Repository repository = getCommit().getRepository();
    RevCommit commit = getCommit().getRevCommit();
    RevWalk revWalk = new RevWalk(repository);
    try {// w ww. j a va 2  s .c  o  m
        Map<String, Ref> refsMap = new HashMap<String, Ref>();
        refsMap.putAll(repository.getRefDatabase().getRefs(Constants.R_HEADS));
        refsMap.putAll(repository.getRefDatabase().getRefs(Constants.R_REMOTES));
        return RevWalkUtils.findBranchesReachableFrom(commit, revWalk, refsMap.values());
    } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, false);
        return Collections.emptyList();
    }
}

From source file:org.eclipse.egit.ui.internal.components.RefContentAssistProvider.java

License:Open Source License

/**
 * @param source whether we want proposals for the source or the destination of the operation
 * @param pushMode whether the operation is a push or a fetch
 * @return a list of all refs for the given mode.
 *//*from w w w .  jav a 2s. c  om*/
public List<Ref> getRefsForContentAssist(boolean source, boolean pushMode) {
    if (source) {
        if (sourceRefs != null)
            return sourceRefs;
    } else if (destinationRefs != null)
        return destinationRefs;

    List<Ref> result = new ArrayList<Ref>();
    try {
        boolean local = pushMode == source;
        if (!local) {
            final ListRemoteOperation lop = new ListRemoteOperation(repo, uri, Activator.getDefault()
                    .getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT));

            new ProgressMonitorDialog(shell).run(false, true, new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask(UIText.RefSpecDialog_GettingRemoteRefsMonitorMessage,
                            IProgressMonitor.UNKNOWN);
                    lop.run(monitor);
                    monitor.done();
                }
            });
            for (Ref ref : lop.getRemoteRefs())
                if (ref.getName().startsWith(Constants.R_HEADS)
                        || (!pushMode && ref.getName().startsWith(Constants.R_TAGS)))
                    result.add(ref);

        } else if (pushMode)
            for (Ref ref : repo.getRefDatabase().getRefs(RefDatabase.ALL).values()) {
                if (ref.getName().startsWith(Constants.R_REMOTES))
                    continue;
                result.add(ref);
            }
        else
            for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_REMOTES).values())
                result.add(ref);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        Activator.handleError(e.getMessage(), e, true);
        return result;
    }
    if (source)
        sourceRefs = result;
    else
        destinationRefs = result;
    return result;
}

From source file:org.eclipse.egit.ui.internal.components.RefSpecPanel.java

License:Open Source License

private void tryAutoCompleteSrcToDst() {
    final String src = creationSrcCombo.getText();
    final String dst = creationDstCombo.getText();

    if (src == null || src.length() == 0)
        return;//from  w w  w. j a va  2  s. co  m

    if (dst != null && dst.length() > 0) {
        // dst is already there, just fix wildcards if needed
        final String newDst;
        if (RefSpec.isWildcard(src))
            newDst = wildcardSpecComponent(dst);
        else
            newDst = unwildcardSpecComponent(dst, src);
        creationDstCombo.setText(newDst);
        return;
    }

    if (!isValidRefExpression(src)) {
        // no way to be smarter than user here
        return;
    }

    // dst is empty, src is ref or wildcard, so we can rewrite it as user
    // would perhaps
    if (pushSpecs)
        creationDstCombo.setText(src);
    else {
        for (final RefSpec spec : predefinedConfigured) {
            if (spec.matchSource(src)) {
                final String newDst = spec.expandFromSource(src).getDestination();
                creationDstCombo.setText(newDst);
                return;
            }
        }
        if (remoteName != null && src.startsWith(Constants.R_HEADS)) {
            final String newDst = Constants.R_REMOTES + remoteName + '/'
                    + src.substring(Constants.R_HEADS.length());
            creationDstCombo.setText(newDst);
        }
    }
}

From source file:org.eclipse.egit.ui.internal.components.RefSpecPanel.java

License:Open Source License

private List<RefContentProposal> createProposalsFilteredLocal(final List<RefContentProposal> proposals) {
    final List<RefContentProposal> result = new ArrayList<RefContentProposal>();
    for (final RefContentProposal p : proposals) {
        final String content = p.getContent();
        if (pushSpecs) {
            if (content.equals(Constants.HEAD) || content.startsWith(Constants.R_HEADS))
                result.add(p);//from w  w w. j  a  v  a 2  s .com
        } else {
            if (content.startsWith(Constants.R_REMOTES))
                result.add(p);
        }
    }
    return result;
}

From source file:org.eclipse.egit.ui.internal.components.SimplePushSpecPage.java

License:Open Source License

/**
 * pre-fills the destination box with a remote ref name if one exists that
 * matches the local branch name./*from  w  w  w . ja va 2  s.  c o  m*/
 */
protected void updateDestinationField() {
    setMessage(NLS.bind(UIText.SimplePushSpecPage_message, sourceName));
    String checkRemote = sourceName;

    if (sourceName.startsWith(Constants.R_HEADS)) {
        try {
            BranchTrackingStatus status = BranchTrackingStatus.of(repository,
                    sourceName.substring(Constants.R_HEADS.length()));

            if (status != null) {
                // calculate the name of the branch on the other side.
                checkRemote = status.getRemoteTrackingBranch();
                checkRemote = Constants.R_HEADS
                        + checkRemote.substring(checkRemote.indexOf('/', Constants.R_REMOTES.length() + 1) + 1);

                setMessage(
                        NLS.bind(UIText.SimplePushSpecPage_pushAheadInfo, new Object[] { sourceName,
                                Integer.valueOf(status.getAheadCount()), status.getRemoteTrackingBranch() }),
                        IStatus.INFO);
            }
        } catch (Exception e) {
            // ignore and continue...
        }

        if (assist == null) {
            if (checkRemote != null)
                remoteRefName.setText(checkRemote);
            return;
        }

        if (checkRemote == null)
            checkRemote = sourceName;

        for (Ref ref : assist.getRefsForContentAssist(false, true))
            if (ref.getName().equals(checkRemote))
                remoteRefName.setText(checkRemote);
    }
}

From source file:org.eclipse.egit.ui.internal.dialogs.AbstractBranchSelectionDialog.java

License:Open Source License

/**
 * Set the selection to a {@link Ref} if possible
 *
 * @param refName//w ww .  j  a v a2  s  .co m
 *            the name of the {@link Ref}
 * @return <code>true</code> if the {@link Ref} with the given name was
 *         found
 */
protected boolean markRef(String refName) {
    // selects the entry specified by the name
    if (refName == null)
        return false;

    RepositoryTreeNode node;
    try {
        if (refName.startsWith(Constants.R_HEADS)) {
            Ref ref = this.repo.getRef(refName);
            node = new RefNode(localBranches, this.repo, ref);
        } else {
            String mappedRef = Activator.getDefault().getRepositoryUtil().mapCommitToRef(this.repo, refName,
                    false);
            if (mappedRef != null && mappedRef.startsWith(Constants.R_REMOTES)) {
                Ref ref = this.repo.getRef(mappedRef);
                node = new RefNode(remoteBranches, this.repo, ref);
            } else if (mappedRef != null && mappedRef.startsWith(Constants.R_TAGS)) {
                Ref ref = this.repo.getRef(mappedRef);
                node = new TagNode(tags, this.repo, ref);
            } else {
                return false;
            }
        }
    } catch (IOException e) {
        return false;
    }

    branchTree.setSelection(new StructuredSelection(node), true);
    return true;
}