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

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

Introduction

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

Prototype

String R_HEADS

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

Click Source Link

Document

Prefix for branch refs

Usage

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

License:Open Source License

@Override
protected int drawLabel(int x, int y, Ref ref) {
    String txt;//from www .ja  va  2  s . co  m
    String name = ref.getName();
    if (name.startsWith(Constants.R_HEADS)) {
        g.setBackground(sys_green);
        txt = name.substring(Constants.R_HEADS.length());
    } else if (name.startsWith(Constants.R_REMOTES)) {
        g.setBackground(sys_gray);
        txt = name.substring(Constants.R_REMOTES.length());
    } else if (name.startsWith(Constants.R_TAGS)) {
        g.setBackground(sys_yellow);
        txt = name.substring(Constants.R_TAGS.length());
    } else {
        // Whatever this would be
        g.setBackground(sys_white);
        if (name.startsWith(Constants.R_REFS))
            txt = name.substring(Constants.R_REFS.length());
        else
            txt = name; // HEAD and such
    }

    // Make peeled objects, i.e. via annotated tags come out in a paler color
    Color peeledColor = null;
    if (ref.getPeeledObjectId() == null || !ref.getPeeledObjectId().equals(ref.getObjectId())) {
        peeledColor = new Color(g.getDevice(), ColorUtil.blend(g.getBackground().getRGB(), sys_white.getRGB()));
        g.setBackground(peeledColor);
    }

    if (txt.length() > 12)
        txt = txt.substring(0, 11) + "\u2026"; // ellipsis "" (in UTF-8) //$NON-NLS-1$

    Point textsz = g.stringExtent(txt);
    int arc = textsz.y / 2;
    final int texty = (y * 2 - textsz.y) / 2;

    // Draw backgrounds
    g.fillRoundRectangle(cellX + x + 1, cellY + texty - 1, textsz.x + 3, textsz.y + 1, arc, arc);
    g.setForeground(sys_black);
    g.drawString(txt, cellX + x + 2, cellY + texty, true);
    g.setLineWidth(2);

    // And a two color shaded border, blend with whatever background there already is
    g.setAlpha(128);
    g.setForeground(sys_gray);
    g.drawRoundRectangle(cellX + x, cellY + texty - 2, textsz.x + 5, textsz.y + 3, arc, arc);
    g.setLineWidth(2);
    g.setForeground(sys_black);
    g.drawRoundRectangle(cellX + x + 1, cellY + texty - 1, textsz.x + 3, textsz.y + 1, arc, arc);
    g.setAlpha(255);

    if (peeledColor != null)
        peeledColor.dispose();
    return 8 + textsz.x;
}

From source file:org.eclipse.egit.ui.internal.pull.PullWizard.java

License:Open Source License

private void configureNewRemote(URIish uri) throws URISyntaxException, IOException {
    StoredConfig config = repository.getConfig();
    String remoteName = this.page.getRemoteConfig().getName();
    RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
    remoteConfig.addURI(uri);//  ww  w. j av a 2s  .c  o  m
    RefSpec defaultFetchSpec = new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + "*", //$NON-NLS-1$
            Constants.R_REMOTES + remoteName + "/*"); //$NON-NLS-1$
    remoteConfig.addFetchRefSpec(defaultFetchSpec);
    remoteConfig.update(config);
    config.save();
}

From source file:org.eclipse.egit.ui.internal.pull.PullWizard.java

License:Open Source License

private void configureUpstream() throws IOException {
    String fullBranch = this.repository.getFullBranch();
    if (fullBranch == null || !fullBranch.startsWith(Constants.R_HEADS)) {
        // Don't configure upstream for detached HEAD
        return;//from w  w  w .j a  v  a2s .com
    }
    String remoteName = this.page.getRemoteConfig().getName();
    String fullRemoteBranchName = this.page.getFullRemoteReference();

    String localBranchName = this.repository.getBranch();
    StoredConfig config = repository.getConfig();
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_REMOTE,
            remoteName);
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_MERGE,
            fullRemoteBranchName);
    BranchRebaseMode rebaseMode = this.page.getUpstreamConfig();
    if (rebaseMode != null) {
        config.setEnum(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName,
                ConfigConstants.CONFIG_KEY_REBASE, rebaseMode);
    }

    config.save();
}

From source file:org.eclipse.egit.ui.internal.pull.PullWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    try {/*  ww  w. j  a v  a 2  s .  c  o  m*/
        this.remoteConfigs = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
        Collections.sort(remoteConfigs, new Comparator<RemoteConfig>() {
            @Override
            public int compare(RemoteConfig first, RemoteConfig second) {
                return String.CASE_INSENSITIVE_ORDER.compare(first.getName(), second.getName());
            }
        });
        setDefaultUpstreamConfig();
    } catch (URISyntaxException e) {
        this.remoteConfigs = new ArrayList<>();
        handleError(e);
    }

    Composite res = new Composite(parent, SWT.NONE);
    res.setLayout(new GridLayout(3, false));

    Label remoteLabel = new Label(res, SWT.NONE);
    remoteLabel.setText(UIText.PushBranchPage_RemoteLabel);

    this.remoteSelectionCombo = new RemoteSelectionCombo(res, SWT.NONE, SelectionType.PUSH);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(remoteSelectionCombo);
    setRemoteConfigs();
    remoteSelectionCombo.addRemoteSelectionListener(new IRemoteSelectionListener() {
        @Override
        public void remoteSelected(RemoteConfig rc) {
            remoteConfig = rc;
            setRefAssist(rc);
            checkPage();
        }
    });

    Button newRemoteButton = new Button(res, SWT.PUSH);
    newRemoteButton.setText(UIText.PushBranchPage_NewRemoteButton);
    GridDataFactory.fillDefaults().applyTo(newRemoteButton);
    newRemoteButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            showNewRemoteDialog();
        }
    });

    Label branchNameLabel = new Label(res, SWT.NONE);
    branchNameLabel.setText(UIText.PullWizardPage_referenceLabel);
    branchNameLabel.setToolTipText(UIText.PullWizardPage_referenceTooltip);

    remoteBranchNameText = new Text(res, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(remoteBranchNameText);
    UIUtils.addRefContentProposalToText(remoteBranchNameText, this.repository, () -> {
        if (PullWizardPage.this.assist != null) {
            return PullWizardPage.this.assist.getRefsForContentAssist(false, true);
        }
        return Collections.emptyList();
    });
    remoteBranchNameText.setText(getSuggestedBranchName());
    remoteBranchNameText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });

    this.upstreamConfigComponent = new BranchRebaseModeCombo(res);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).align(SWT.BEGINNING, SWT.CENTER)
            .applyTo(upstreamConfigComponent.getViewer().getCombo());
    this.upstreamConfigComponent.getViewer()
            .addSelectionChangedListener((event) -> upstreamConfig = upstreamConfigComponent.getRebaseMode());
    if (upstreamConfig != null) {
        upstreamConfigComponent.setRebaseMode(upstreamConfig);
    }
    if (this.fullBranch != null && this.fullBranch.startsWith(Constants.R_HEADS)) {
        this.rememberConfigForBranch = new Button(res, SWT.CHECK);
        GridData checkboxLayoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1);
        checkboxLayoutData.verticalIndent = 20;
        this.rememberConfigForBranch.setText(UIText.UpstreamConfigComponent_ConfigureUpstreamCheck);
        this.rememberConfigForBranch.setToolTipText(UIText.UpstreamConfigComponent_ConfigureUpstreamToolTip);
        this.rememberConfigForBranch.setLayoutData(checkboxLayoutData);
        this.rememberConfigForBranch.setSelection(this.configureUpstream);
        this.rememberConfigForBranch.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                configureUpstream = rememberConfigForBranch.getSelection();
                checkPage();
            }
        });
    }

    setPageComplete(isPageComplete());
    setControl(res);
}

From source file:org.eclipse.egit.ui.internal.pull.PullWizardPage.java

License:Open Source License

private void showNewRemoteDialog() {
    AddRemoteWizard wizard = new AddRemoteWizard(repository);
    WizardDialog dialog = new WizardDialog(getShell(), wizard);
    int result = dialog.open();
    if (result == Window.OK) {
        URIish uri = wizard.getUri();/*  ww  w  .j ava2 s . co m*/
        String remoteName = wizard.getRemoteName();
        try {
            StoredConfig repoConfig = repository.getConfig();
            RemoteConfig newRemoteConfig = new RemoteConfig(repoConfig, remoteName);
            newRemoteConfig.addURI(uri);
            RefSpec defaultFetchSpec = new RefSpec().setForceUpdate(true).setSourceDestination(
                    Constants.R_HEADS + "*", //$NON-NLS-1$
                    Constants.R_REMOTES + remoteName + "/*"); //$NON-NLS-1$
            newRemoteConfig.addFetchRefSpec(defaultFetchSpec);
            newRemoteConfig.update(repoConfig);
            repoConfig.save();
            List<RemoteConfig> allRemoteConfigs = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
            remoteSelectionCombo.setItems(allRemoteConfigs);
            // find the new remote in the list, as the initial
            // newRemoteConfig object
            // isn't what's stored and returned by getAllRemoteConfigs
            for (RemoteConfig current : allRemoteConfigs) {
                if (newRemoteConfig.getName().equals(current.getName())) {
                    setSelectedRemote(current);
                }
            }
        } catch (URISyntaxException ex) {
            Activator.logError(ex.getMessage(), ex);
        } catch (IOException ex) {
            Activator.logError(ex.getMessage(), ex);
        }
    }
}

From source file:org.eclipse.egit.ui.internal.pull.PullWizardPage.java

License:Open Source License

private String getSuggestedBranchName() {
    if (fullBranch != null) {
        String branchName = Repository.shortenRefName(fullBranch);
        StoredConfig config = repository.getConfig();
        BranchConfig branchConfig = new BranchConfig(config, branchName);
        String merge = branchConfig.getMerge();
        if (!branchConfig.isRemoteLocal() && merge != null && merge.startsWith(Constants.R_HEADS)) {
            return Repository.shortenRefName(merge);
        }/*w ww.  j  a va2 s  .  com*/
    }
    return ""; //$NON-NLS-1$
}

From source file:org.eclipse.egit.ui.internal.pull.PullWizardPage.java

License:Open Source License

/**
 * @return the chosen short name of the branch on the remote
 *///from www  . j  a  v  a  2 s  .com
String getFullRemoteReference() {
    if (!remoteBranchNameText.getText().startsWith(Constants.R_REFS))
        return Constants.R_HEADS + remoteBranchNameText.getText();
    else
        return remoteBranchNameText.getText();
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchPage.java

License:Open Source License

private void checkPage() {
    try {//from   w  w  w . jav a2 s  .c  o m
        if (remoteConfig == null) {
            setErrorMessage(UIText.PushBranchPage_ChooseRemoteError);
            return;
        }
        String branchName = remoteBranchNameText.getText();
        if (branchName.length() == 0) {
            setErrorMessage(
                    MessageFormat.format(UIText.PushBranchPage_ChooseBranchNameError, remoteConfig.getName()));
            return;
        }
        if (!Repository.isValidRefName(Constants.R_HEADS + branchName)) {
            setErrorMessage(UIText.PushBranchPage_InvalidBranchNameError);
            return;
        }
        if (getUpstreamConfig() != null && hasDifferentUpstreamConfiguration()) {
            setMessage(UIText.PushBranchPage_UpstreamConfigOverwriteWarning, IMessageProvider.WARNING);
        } else {
            setMessage(UIText.PushBranchPage_PageMessage);
        }
        setErrorMessage(null);
    } finally {
        setPageComplete(getErrorMessage() == null);
    }
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchPage.java

License:Open Source License

private String getSuggestedBranchName() {
    if (ref != null && !ref.getName().startsWith(Constants.R_REMOTES)) {
        StoredConfig config = repository.getConfig();
        String branchName = Repository.shortenRefName(ref.getName());

        BranchConfig branchConfig = new BranchConfig(config, branchName);
        String merge = branchConfig.getMerge();
        if (!branchConfig.isRemoteLocal() && merge != null && merge.startsWith(Constants.R_HEADS))
            return Repository.shortenRefName(merge);

        return branchName;
    } else {//from  w  ww  .  j a v a2s .  c o  m
        return ""; //$NON-NLS-1$
    }
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchWizard.java

License:Open Source License

private void configureNewRemote(URIish uri) throws URISyntaxException, IOException {
    StoredConfig config = repository.getConfig();
    String remoteName = getRemoteName();
    RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
    remoteConfig.addURI(uri);/* w  w  w  . j  a  v  a2  s  . c o m*/
    RefSpec defaultFetchSpec = new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + "*", //$NON-NLS-1$
            Constants.R_REMOTES + remoteName + "/*"); //$NON-NLS-1$
    remoteConfig.addFetchRefSpec(defaultFetchSpec);
    remoteConfig.update(config);
    config.save();
}