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

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

Introduction

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

Prototype

public static String normalizeBranchName(String name) 

Source Link

Document

Normalizes the passed branch name into a possible valid branch name.

Usage

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

License:Open Source License

private String normalizeBranchName(String name) {
    String normalized = Repository.normalizeBranchName(name);
    if (normalized.length() > 30)
        normalized = normalized.substring(0, 30);
    return normalized;
}

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

License:Open Source License

/**
 * Creates a new {@link BranchNameNormalizer}.
 *
 * @param text//  w w w  .  j  av  a 2  s  . c o  m
 *            {@link Text} to operate on
 * @param tooltipText
 *            to show on the bulb decorator
 */
public BranchNameNormalizer(Text text, String tooltipText) {
    KeyStroke stroke = UIUtils
            .getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
    if (stroke == null) {
        stroke = KeyStroke.getInstance(SWT.MOD1, ' ');
    }
    decorator = UIUtils.addBulbDecorator(text, MessageFormat.format(tooltipText, stroke.format()));
    decorator.hide();
    ContentProposalAdapter proposer = new ContentProposalAdapter(text, new TextContentAdapter(), (c, p) -> {
        if (c.isEmpty() || Repository.isValidRefName(Constants.R_HEADS + c)) {
            return null;
        }
        String normalized = Repository.normalizeBranchName(c);
        if (normalized == null || normalized.isEmpty()) {
            return new ContentProposal[0];
        }
        return new ContentProposal[] { new ContentProposal(normalized) };
    }, stroke, BRANCH_NAME_NORMALIZER_ACTIVATION_CHARS);
    proposer.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    text.addVerifyListener(e -> e.text = e.text.replaceAll(REGEX_BLANK, UNDERSCORE));
    text.addModifyListener(e -> {
        String input = text.getText();
        boolean doProposeCorrection = !input.isEmpty() && !Repository.isValidRefName(Constants.R_HEADS + input);
        setVisible(doProposeCorrection);
    });
}