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.history.CommitInfoBuilder.java

License:Open Source License

private String formatHeadRef(Ref ref) {
    final String name = ref.getName();
    if (name.startsWith(Constants.R_HEADS))
        return name.substring(Constants.R_HEADS.length());
    else if (name.startsWith(Constants.R_REMOTES))
        return name.substring(Constants.R_REMOTES.length());
    return name;/*from ww  w  . j  av a 2 s  .  c  om*/
}

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

License:Open Source License

@Override
public void create() {
    super.create();
    getButton(OK).setEnabled(false);//from  w  w w.j ava  2  s.c  o  m
    try {
        PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.beginTask(UIText.CommitSelectionDialog_BuildingCommitListMessage,
                            IProgressMonitor.UNKNOWN);
                    SWTWalk currentWalk = new SWTWalk(repository);
                    currentWalk.setTreeFilter(createTreeFilter());
                    currentWalk.sort(RevSort.COMMIT_TIME_DESC, true);
                    currentWalk.sort(RevSort.BOUNDARY, true);
                    highlightFlag = currentWalk.newFlag("highlight"); //$NON-NLS-1$
                    allCommits.source(currentWalk);

                    try {

                        if (Activator.getDefault().getPreferenceStore()
                                .getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_ALL_BRANCHES)) {
                            markStartAllRefs(currentWalk, Constants.R_HEADS);
                            markStartAllRefs(currentWalk, Constants.R_REMOTES);
                        } else
                            currentWalk.markStart(currentWalk.parseCommit(repository.resolve(Constants.HEAD)));
                        for (;;) {
                            final int oldsz = allCommits.size();
                            allCommits.fillTo(oldsz + BATCH_SIZE - 1);

                            if (monitor.isCanceled() || oldsz == allCommits.size())
                                break;
                            String taskName = NLS.bind(UIText.CommitSelectionDialog_FoundCommitsMessage,
                                    Integer.valueOf(allCommits.size()));
                            monitor.setTaskName(taskName);

                        }
                    } catch (IOException e) {
                        throw new InvocationTargetException(e);
                    }
                    getShell().getDisplay().asyncExec(new Runnable() {
                        public void run() {
                            updateUi();
                        }
                    });
                    if (monitor.isCanceled())
                        throw new InterruptedException();
                } finally {
                    monitor.done();
                }
            }
        });
    } catch (InvocationTargetException e) {
        setErrorMessage(e.getCause().getMessage());
    } catch (InterruptedException e) {
        setMessage(UIText.CommitSelectionDialog_IncompleteListMessage, IMessageProvider.WARNING);
    }
}

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

License:Open Source License

void initAndStartRevWalk(boolean forceNewWalk) throws IllegalStateException {
    try {//from ww  w . j a  va2s . c o  m
        if (trace)
            GitTraceLocation.getTrace().traceEntry(GitTraceLocation.HISTORYVIEW.getLocation());

        cancelRefreshJob();
        Repository db = input.getRepository();
        AnyObjectId headId;
        try {
            headId = db.resolve(Constants.HEAD);
        } catch (IOException e) {
            throw new IllegalStateException(NLS.bind(UIText.GitHistoryPage_errorParsingHead,
                    Activator.getDefault().getRepositoryUtil().getRepositoryName(db)));
        }
        if (headId == null)
            throw new IllegalStateException(NLS.bind(UIText.GitHistoryPage_errorParsingHead,
                    Activator.getDefault().getRepositoryUtil().getRepositoryName(db)));

        List<String> paths = buildFilterPaths(input.getItems(), input.getFileList(), db);

        if (forceNewWalk || pathChange(pathFilters, paths) || currentWalk == null
                || !headId.equals(currentHeadId)) {
            // TODO Do not dispose SWTWalk just because HEAD changed
            // In theory we should be able to update the graph and
            // not dispose of the SWTWalk, even if HEAD was reset to
            // HEAD^1 and the old HEAD commit should not be visible.
            //
            currentHeadId = headId;
            if (currentWalk != null)
                currentWalk.release();
            currentWalk = new SWTWalk(db);
            currentWalk.sort(RevSort.COMMIT_TIME_DESC, true);
            currentWalk.sort(RevSort.BOUNDARY, true);
            highlightFlag = currentWalk.newFlag("highlight"); //$NON-NLS-1$
        } else {
            currentWalk.reset();
        }

        try {
            if (store.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_ALL_BRANCHES)) {
                markStartAllRefs(Constants.R_HEADS);
                markStartAllRefs(Constants.R_REMOTES);
            } else
                currentWalk.markStart(currentWalk.parseCommit(headId));
        } catch (IOException e) {
            throw new IllegalStateException(NLS.bind(UIText.GitHistoryPage_errorReadingHeadCommit, headId,
                    db.getDirectory().getAbsolutePath()), e);
        }

        final TreeWalk fileWalker = new TreeWalk(db);
        fileWalker.setRecursive(true);
        if (paths.size() > 0) {
            pathFilters = paths;
            currentWalk.setTreeFilter(
                    AndTreeFilter.create(PathFilterGroup.createFromStrings(paths), TreeFilter.ANY_DIFF));
            fileWalker.setFilter(currentWalk.getTreeFilter().clone());

        } else {
            pathFilters = null;
            currentWalk.setTreeFilter(TreeFilter.ALL);
            fileWalker.setFilter(TreeFilter.ANY_DIFF);
        }
        fileViewer.setTreeWalk(db, fileWalker);
        fileViewer.refresh();
        fileViewer.addSelectionChangedListener(commentViewer);
        commentViewer.setTreeWalk(fileWalker);
        commentViewer.setDb(db);
        commentViewer.refresh();

        final SWTCommitList list;
        list = new SWTCommitList(graph.getControl().getDisplay());
        list.source(currentWalk);
        final GenerateHistoryJob rj = new GenerateHistoryJob(this, list);
        rj.addJobChangeListener(new JobChangeAdapter() {
            @Override
            public void done(final IJobChangeEvent event) {
                final Control graphctl = graph.getControl();
                if (job != rj || graphctl.isDisposed())
                    return;
                graphctl.getDisplay().asyncExec(new Runnable() {
                    public void run() {
                        if (job == rj)
                            job = null;
                    }
                });
            }
        });
        job = rj;
        if (trace)
            GitTraceLocation.getTrace().trace(GitTraceLocation.HISTORYVIEW.getLocation(),
                    "Scheduling GenerateHistoryJob"); //$NON-NLS-1$
        schedule(rj);
    } finally {
        if (trace)
            GitTraceLocation.getTrace().traceExit(GitTraceLocation.HISTORYVIEW.getLocation());

    }
}

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;//w ww .ja  v  a 2  s .com
    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);/*w  ww.java  2  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();
}

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();/*from w  w  w  .ja va 2 s. c  o  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 void setDefaultUpstreamConfig() {
    String branchName = Repository.shortenRefName(this.fullBranch);
    BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName);
    boolean alreadyConfigured = branchConfig.getMerge() != null;
    BranchRebaseMode config;/*  ww  w .  j a  v  a2  s  . c o m*/
    if (alreadyConfigured) {
        config = PullCommand.getRebaseMode(branchName, repository.getConfig());
    } else {
        config = CreateLocalBranchOperation.getDefaultUpstreamConfig(repository,
                Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + branchName); //$NON-NLS-1$
    }
    this.upstreamConfig = config;
}

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

License:Open Source License

private static boolean isValidRemoteName(String remoteName) {
    String testRef = Constants.R_REMOTES + remoteName + "/test"; //$NON-NLS-1$
    return Repository.isValidRefName(testRef);
}

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

License:Open Source License

private void setDefaultUpstreamConfig() {
    if (this.ref != null) {
        String branchName = Repository.shortenRefName(ref.getName());
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName);
        boolean alreadyConfigured = branchConfig.getMerge() != null;
        BranchRebaseMode config;/*  ww  w  .  ja v  a  2  s. c  om*/
        if (alreadyConfigured) {
            config = PullCommand.getRebaseMode(branchName, repository.getConfig());
        } else {
            config = CreateLocalBranchOperation.getDefaultUpstreamConfig(repository,
                    Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + branchName); //$NON-NLS-1$
        }
        this.upstreamConfig = config;
        this.upstreamConfigComponent.setUpstreamConfig(this.upstreamConfig);
    }
}

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  w  w. ja  va  2 s  .co  m
        return ""; //$NON-NLS-1$
    }
}