Example usage for org.eclipse.jgit.lib Repository shortenRefName

List of usage examples for org.eclipse.jgit.lib Repository shortenRefName

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository shortenRefName.

Prototype

@NonNull
public static String shortenRefName(String refName) 

Source Link

Document

Get a shortened more user friendly ref name

Usage

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

License:Open Source License

@Override
protected IContributionItem[] getContributionItems() {
    List<IContributionItem> res = new ArrayList<>();

    if (this.handlerService != null) {
        Repository repository = SelectionUtils.getRepository(handlerService.getCurrentState());

        if (repository != null) {
            try {
                String ref = repository.getFullBranch();
                String menuLabel = UIText.PushMenu_PushHEAD;
                if (ref != null && ref.startsWith(Constants.R_HEADS)) {
                    menuLabel = NLS.bind(UIText.PushMenu_PushBranch, Repository.shortenRefName(ref));
                }//from ww  w  .  ja v a2 s.c  o m
                CommandContributionItemParameter params = new CommandContributionItemParameter(
                        this.serviceLocator, getClass().getName(), ActionCommands.PUSH_BRANCH_ACTION,
                        CommandContributionItem.STYLE_PUSH);
                params.label = menuLabel;
                CommandContributionItem item = new CommandContributionItem(params);
                res.add(item);
            } catch (IOException ex) {
                Activator.handleError(ex.getLocalizedMessage(), ex, false);
            }
        }
    }
    return res.toArray(new IContributionItem[res.size()]);
}

From source file:org.eclipse.egit.ui.internal.branch.BranchResultDialog.java

License:Open Source License

/**
 * @param shell/*from ww w .  ja  v  a 2  s  .c o  m*/
 * @param repository
 * @param result
 * @param target
 */
private BranchResultDialog(Shell shell, Repository repository, CheckoutResult result, String target) {
    super(shell, UIText.BranchResultDialog_CheckoutConflictsTitle, INFO,
            NLS.bind(UIText.BranchResultDialog_CheckoutConflictsMessage, Repository.shortenRefName(target)),
            MessageDialog.INFORMATION, new String[] {}, -1);
    setShellStyle(getShellStyle() | SWT.SHELL_TRIM);
    this.repository = repository;
    this.result = result;
}

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

License:Open Source License

private List<Ref> getTags() {
    Repository repository = getCommit().getRepository();
    List<Ref> tags = new ArrayList<Ref>(repository.getTags().values());
    Collections.sort(tags, new Comparator<Ref>() {

        public int compare(Ref r1, Ref r2) {
            return Repository.shortenRefName(r1.getName())
                    .compareToIgnoreCase(Repository.shortenRefName(r2.getName()));
        }//from   ww  w.j a v a 2 s.c o  m
    });
    return tags;
}

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

License:Open Source License

private void fillTags(FormToolkit toolkit, List<Ref> tags) {
    for (Control child : tagLabelArea.getChildren())
        child.dispose();/*from w w w .j ava  2  s. c  o m*/

    GridLayoutFactory.fillDefaults().spacing(1, 1).numColumns(tags.size()).applyTo(tagLabelArea);

    for (Ref tag : tags) {
        ObjectId id = tag.getPeeledObjectId();
        boolean annotated = id != null;
        if (id == null)
            id = tag.getObjectId();
        CLabel tagLabel = new CLabel(tagLabelArea, SWT.NONE);
        toolkit.adapt(tagLabel, false, false);
        if (annotated)
            tagLabel.setImage(getImage(UIIcons.TAG_ANNOTATED));
        else
            tagLabel.setImage(getImage(UIIcons.TAG));
        tagLabel.setText(Repository.shortenRefName(tag.getName()));
    }
}

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

License:Open Source License

private void createBranchesArea(Composite parent, FormToolkit toolkit, int span) {
    branchSection = createSection(parent, toolkit, span);
    branchSection.setText(UIText.CommitEditorPage_SectionBranchesEmpty);
    Composite branchesArea = createSectionClient(branchSection, toolkit);

    branchViewer = new TableViewer(toolkit.createTable(branchesArea, SWT.V_SCROLL | SWT.H_SCROLL));
    GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 50).applyTo(branchViewer.getControl());
    branchViewer.setSorter(new ViewerSorter());
    branchViewer.setLabelProvider(new GitLabelProvider() {

        public String getText(Object element) {
            return Repository.shortenRefName(super.getText(element));
        }/*www.  j  av a  2 s.  c om*/

    });
    branchViewer.setContentProvider(ArrayContentProvider.getInstance());
    branchViewer.getTable().setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);

    updateSectionClient(branchSection, branchesArea, toolkit);
}

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

License:Open Source License

@Override
public void create() {
    super.create();
    setTitle(UIText.BranchRenameDialog_Title);
    String oldName = branchToRename.getName();
    String prefix;//  w w  w .  jav  a2  s .  c om
    if (oldName.startsWith(Constants.R_HEADS))
        prefix = Constants.R_HEADS;
    else if (oldName.startsWith(Constants.R_REMOTES))
        prefix = Constants.R_REMOTES;
    else
        prefix = null;
    String shortName = null;
    if (prefix != null) {
        shortName = Repository.shortenRefName(branchToRename.getName());
        setMessage(NLS.bind(UIText.BranchRenameDialog_Message, shortName));
        final IInputValidator inputValidator = ValidationUtils.getRefNameInputValidator(repository, prefix,
                true);
        name.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                String error = inputValidator.isValid(name.getText());
                setErrorMessage(error);
                getButton(OK).setEnabled(error == null);
            }
        });
    } else
        setErrorMessage(NLS.bind(UIText.BranchRenameDialog_WrongPrefixErrorMessage, oldName));

    if (shortName != null) {
        name.setText(shortName);
        name.setSelection(0, shortName.length());
    }

    getButton(OK).setEnabled(false);
}

From source file:org.eclipse.egit.ui.internal.fetch.FetchDestinationPage.java

License:Open Source License

@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    if (visible) {
        FetchSourcePage fsp = (FetchSourcePage) getWizard().getPreviousPage(this);
        String sourceString = fsp.getSource();
        sourceText.setText(sourceString);
        if (sourceString.length() > 0) {
            destinationText.setText(/*w  w w .j av a 2 s.c o m*/
                    Constants.R_REMOTES + config.getName() + '/' + Repository.shortenRefName(sourceString));
        }
        destinationText.setFocus();
    }
}

From source file:org.eclipse.egit.ui.internal.history.command.DeleteTagOnCommitHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Repository repository = getRepository(event);
    if (repository == null)
        return null;

    final Shell shell = getPart(event).getSite().getShell();
    IStructuredSelection selection = getSelection(event);
    List<Ref> tags = getTagsOfCommit(selection);

    // this should have been checked by isEnabled()
    if (tags.isEmpty())
        return null;

    // show a dialog in case there are multiple tags on the selected commit
    final List<Ref> tagsToDelete;
    if (tags.size() > 1) {
        BranchSelectionDialog<Ref> dialog = new BranchSelectionDialog<>(shell, tags,
                UIText.DeleteTagOnCommitHandler_SelectTagDialogTitle,
                UIText.DeleteTagOnCommitHandler_SelectTagDialogMessage, SWT.MULTI);
        if (dialog.open() != Window.OK)
            return null;
        tagsToDelete = dialog.getSelectedNodes();
    } else {/* w  ww .  j a  v  a  2s  .c o m*/
        String tagName = Repository.shortenRefName(tags.get(0).getName());
        String message = MessageFormat.format(UIText.DeleteTagCommand_messageConfirmSingleTag, tagName);
        boolean confirmed = MessageDialog.openConfirm(shell, UIText.DeleteTagCommand_titleConfirm, message);
        if (!confirmed)
            return null;
        tagsToDelete = tags;
    }

    try {
        deleteTagsAsTask(shell, repository, tagsToDelete);
    } catch (InvocationTargetException e1) {
        Activator.handleError(UIText.RepositoriesView_TagDeletionFailureMessage, e1.getCause(), true);
    } catch (InterruptedException e1) {
        // ignore
    }

    return null;
}

From source file:org.eclipse.egit.ui.internal.history.FindToolbarJob.java

License:Open Source License

@Override
protected IStatus run(IProgressMonitor monitor) {
    findResults.clear();/*from w w  w.ja  v a 2  s  . co m*/

    if (pattern == null || pattern.isEmpty() || fileRevisions == null || fileRevisions.length == 0) {
        return Status.OK_STATUS;
    }
    String findPattern = pattern;
    if (ignoreCase) {
        findPattern = pattern.toLowerCase();
    }

    int totalRevisions = fileRevisions.length;
    SubMonitor progress = SubMonitor.convert(monitor, totalRevisions);
    for (int i = 0; i < totalRevisions; i++) {
        if (progress.isCanceled()) {
            return Status.CANCEL_STATUS;
        }
        if (findResults.size() >= MAX_RESULTS) {
            findResults.setOverflow();
            break;
        }

        // Finds for the pattern in the revision history.
        SWTCommit revision = fileRevisions[i];
        try {
            revision.parseBody();
        } catch (IOException e) {
            Activator.logError("Error parsing body", e); //$NON-NLS-1$
            continue;
        }

        if (findInCommitId && find(findPattern, revision.getId().name())) {
            if (progress.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            findResults.add(i, revision);
            continue;
        }
        if (findInComments && find(findPattern, revision.getFullMessage())) {
            if (progress.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            findResults.add(i, revision);
            continue;
        }

        if (findInAuthor && (find(findPattern, revision.getAuthorIdent().getName())
                || find(findPattern, revision.getAuthorIdent().getEmailAddress()))) {
            if (progress.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            findResults.add(i, revision);
            continue;
        }

        if (findInCommitter && (find(findPattern, revision.getCommitterIdent().getName())
                || find(findPattern, revision.getCommitterIdent().getEmailAddress()))) {
            if (progress.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            findResults.add(i, revision);
            continue;
        }

        if (findInReference) {
            for (int j = 0; j < revision.getRefCount(); j++) {
                if (progress.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                Ref ref = revision.getRef(j);
                String refName = ref.getName();
                refName = Repository.shortenRefName(refName);
                if (find(findPattern, refName)) {
                    if (progress.isCanceled()) {
                        return Status.CANCEL_STATUS;
                    }
                    findResults.add(i, revision);
                    break;
                }
            }
        }
        progress.worked(1);
    }
    return progress.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
}

From source file:org.eclipse.egit.ui.internal.history.FindToolbarThread.java

License:Open Source License

private void execFind() {
    // If it isn't the last event, just ignore it.
    if (currentThreadIx < globalThreadIx) {
        return;/*from   www.j  ava 2s.c o m*/
    }

    FindResults findResults = toolbar.findResults;
    findResults.clear();

    boolean maxResultsOverflow = false;
    if (pattern.length() > 0 && fileRevisions != null) {
        String findPattern = pattern;
        if (ignoreCase) {
            findPattern = pattern.toLowerCase();
        }

        long lastUIUpdate = System.currentTimeMillis();

        int totalRevisions = fileRevisions.length;
        int totalMatches = 0;
        boolean notFound = true;
        for (int i = 0; i < totalRevisions; i++) {
            // If a new find event was generated, ends the current thread.
            if (toolbar.getDisplay().isDisposed() || currentThreadIx < globalThreadIx) {
                return;
            }

            // Updates the toolbar with in process info.
            if (System.currentTimeMillis() - lastUIUpdate > 500) {
                final int percentage = (int) (((i + 1F) / totalRevisions) * 100);
                toolbar.getDisplay().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        if (toolbar.isDisposed()) {
                            return;
                        }
                        toolbar.progressUpdate(percentage);
                    }
                });
                lastUIUpdate = System.currentTimeMillis();
            }

            // Finds for the pattern in the revision history.
            notFound = true;
            SWTCommit revision = fileRevisions[i];
            try {
                revision.parseBody();
            } catch (IOException e) {
                Activator.error("Error parsing body", e); //$NON-NLS-1$
                continue;
            }

            if (findInCommitId) {
                String contentId = revision.getId().name();
                if (contentId != null) {
                    if (ignoreCase) {
                        contentId = contentId.toLowerCase();
                    }
                    if (contentId.indexOf(findPattern) != -1) {
                        totalMatches++;
                        findResults.add(i, revision);
                        notFound = false;
                    }
                }
            }

            if (findInComments && notFound) {
                String comment = revision.getFullMessage();
                if (comment != null) {
                    if (ignoreCase) {
                        comment = comment.toLowerCase();
                    }
                    if (comment.indexOf(findPattern) != -1) {
                        totalMatches++;
                        findResults.add(i, revision);
                        notFound = false;
                    }
                }
            }

            if (findInAuthor && notFound) {
                String author = revision.getAuthorIdent().getName();
                if (author != null) {
                    if (ignoreCase) {
                        author = author.toLowerCase();
                    }
                    if (author.indexOf(findPattern) != -1) {
                        totalMatches++;
                        findResults.add(i, revision);
                        notFound = false;
                    }
                }
                if (notFound) {
                    String email = revision.getAuthorIdent().getEmailAddress();
                    if (email != null) {
                        if (ignoreCase) {
                            email = email.toLowerCase();
                        }
                        if (email.indexOf(findPattern) != -1) {
                            totalMatches++;
                            findResults.add(i, revision);
                            notFound = false;
                        }
                    }
                }
            }

            if (findInCommitter && notFound) {
                String committer = revision.getCommitterIdent().getName();
                if (committer != null) {
                    if (ignoreCase) {
                        committer = committer.toLowerCase();
                    }
                    if (committer.indexOf(findPattern) != -1) {
                        totalMatches++;
                        findResults.add(i, revision);
                        notFound = false;
                    }
                }
                if (notFound) {
                    String email = revision.getCommitterIdent().getEmailAddress();
                    if (email != null) {
                        if (ignoreCase) {
                            email = email.toLowerCase();
                        }
                        if (email.indexOf(findPattern) != -1) {
                            totalMatches++;
                            findResults.add(i, revision);
                            notFound = false;
                        }
                    }
                }
            }

            if (findInReference && notFound) {
                if (revision.getRefCount() > 0) {
                    for (int j = 0; j < revision.getRefCount(); j++) {
                        Ref ref = revision.getRef(j);
                        String refName = ref.getName();
                        refName = Repository.shortenRefName(refName);
                        if (ignoreCase)
                            refName = refName.toLowerCase();
                        if (refName.indexOf(findPattern) != -1) {
                            totalMatches++;
                            findResults.add(i, revision);
                            notFound = false;
                        }
                    }
                }
            }

            if (totalMatches == MAX_RESULTS) {
                maxResultsOverflow = true;
                break;
            }
        }

    }

    // Updates the toolbar with the result find info.
    final boolean overflow = maxResultsOverflow;
    toolbar.getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            if (toolbar.isDisposed()) {
                return;
            }
            toolbar.findCompletionUpdate(pattern, overflow);
        }
    });
}