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.dialogs.RenameBranchDialog.java

License:Open Source License

@Override
protected void refNameSelected(String refName) {
    boolean tagSelected = refName != null && refName.startsWith(Constants.R_TAGS);

    boolean branchSelected = refName != null
            && (refName.startsWith(Constants.R_HEADS) || refName.startsWith(Constants.R_REMOTES));

    getButton(Window.OK).setEnabled(branchSelected || tagSelected);
}

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

License:Open Source License

private List<Ref> getRemoteRefs() {
    if (remoteRefs == null) {
        URIish uriToCheck;/* w  ww. j a  v a 2  s .co m*/
        List<Ref> proposals = new ArrayList<Ref>();
        uriToCheck = config.getURIs().get(0);
        final ListRemoteOperation lop = new ListRemoteOperation(repository, uriToCheck,
                Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT));
        try {
            new ProgressMonitorDialog(getShell()).run(false, true, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask(UIText.FetchSourcePage_GettingRemoteRefsTaskname,
                            IProgressMonitor.UNKNOWN);
                    lop.run(monitor);
                    monitor.done();
                }
            });
            for (Ref ref : lop.getRemoteRefs()) {
                if (ref.getName().startsWith(Constants.R_HEADS) || ref.getName().startsWith(Constants.R_TAGS))
                    proposals.add(ref);
            }
            Collections.sort(proposals, new Comparator<Ref>() {
                public int compare(Ref o1, Ref o2) {
                    return o1.getName().compareTo(o2.getName());
                }
            });
            this.remoteRefs = proposals;
        } catch (IllegalStateException e) {
            setErrorMessage(e.getMessage());
        } catch (InvocationTargetException e) {
            setErrorMessage(e.getMessage());
        } catch (InterruptedException e) {
            setErrorMessage(e.getMessage());
        }
    }
    return remoteRefs;
}

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

License:Open Source License

/**
 * @param shell//from w w  w. j  a v a2  s . co  m
 * @param repository
 * @param config
 * @param showBranchInfo
 *            should be true if this is used for upstream configuration; if
 *            false, branch information will be hidden in the dialog
 */
private SimpleConfigureFetchDialog(Shell shell, Repository repository, RemoteConfig config,
        boolean showBranchInfo) {
    super(shell);
    setHelpAvailable(false);
    setShellStyle(getShellStyle() | SWT.SHELL_TRIM);
    this.repository = repository;
    this.config = config;
    this.showBranchInfo = showBranchInfo;

    // Add default fetch ref spec if this is a new remote config
    if (config.getFetchRefSpecs().isEmpty() && !repository.getConfig()
            .getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION).contains(config.getName())) {
        StringBuilder defaultRefSpec = new StringBuilder();
        defaultRefSpec.append('+');
        defaultRefSpec.append(Constants.R_HEADS);
        defaultRefSpec.append('*').append(':');
        defaultRefSpec.append(Constants.R_REMOTES);
        defaultRefSpec.append(config.getName());
        defaultRefSpec.append(RefSpec.WILDCARD_SUFFIX);
        config.addFetchRefSpec(new RefSpec(defaultRefSpec.toString()));
    }
}

From source file:org.eclipse.egit.ui.internal.gerrit.ConfigureGerritWizard.java

License:Open Source License

private String getProposedTargetBranch() {
    List<RefSpec> pushRefSpecs = remoteConfig.getPushRefSpecs();
    String destination = null;// w w w  .  j a  v  a2s .co m
    if (pushRefSpecs.size() > 0) {
        destination = pushRefSpecs.get(0).getDestination();
        if (destination.startsWith(Constants.R_HEADS))
            destination = destination.substring(Constants.R_HEADS.length());
        else if (destination.startsWith("refs/for/")) //$NON-NLS-1$
            destination = destination.substring("refs/for/".length()); //$NON-NLS-1$
    }
    return destination;
}

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

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    PlotCommit commit = (PlotCommit) getSelection(getPage()).getFirstElement();
    Repository repo = getRepository(event);
    List<Ref> availableBranches = new ArrayList<Ref>();

    final BranchOperation op;

    try {/*ww  w  .  jav a2 s . c  o m*/
        Map<String, Ref> localBranches = repo.getRefDatabase().getRefs(Constants.R_HEADS);
        for (Ref branch : localBranches.values()) {
            if (branch.getLeaf().getObjectId().equals(commit.getId())) {
                availableBranches.add(branch);
            }
        }
    } catch (IOException e) {
        // ignore here
    }

    if (availableBranches.isEmpty())
        op = new BranchOperation(repo, commit.getId());
    else if (availableBranches.size() == 1)
        op = new BranchOperation(repo, availableBranches.get(0).getName());
    else {
        List<RefNode> nodes = new ArrayList<RefNode>();
        RepositoryNode repoNode = new RepositoryNode(null, repo);
        for (Ref ref : availableBranches) {
            nodes.add(new RefNode(repoNode, repo, ref));
        }
        BranchMessageDialog dlg = new BranchMessageDialog(HandlerUtil.getActiveShellChecked(event), nodes);
        if (dlg.open() == Window.OK) {
            op = new BranchOperation(repo, dlg.getSelectedNode().getObject().getName());
        } else {
            op = null;
        }
    }

    if (op == null)
        return null;

    // for the sake of UI responsiveness, let's start a job
    Job job = new Job(NLS.bind(UIText.RepositoriesView_CheckingOutMessage, commit.getId().name())) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {

            IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                public void run(IProgressMonitor myMonitor) throws CoreException {
                    op.execute(myMonitor);
                }
            };

            try {
                ResourcesPlugin.getWorkspace().run(wsr, ResourcesPlugin.getWorkspace().getRoot(),
                        IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e1) {
                return Activator.createErrorStatus(e1.getMessage(), e1);
            }

            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (family.equals(JobFamilies.CHECKOUT))
                return true;
            return super.belongsTo(family);
        }
    };

    job.setUser(true);
    job.schedule();
    return null;
}

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

License:Open Source License

private List<Ref> getBranchesOfCommit(GitHistoryPage page, final Repository repo, boolean hideCurrentBranch)
        throws IOException {
    final List<Ref> branchesOfCommit = new ArrayList<Ref>();
    IStructuredSelection selection = getSelection(page);
    if (selection.isEmpty())
        return branchesOfCommit;
    PlotCommit commit = (PlotCommit) selection.getFirstElement();
    String head = repo.getFullBranch();

    int refCount = commit.getRefCount();
    for (int i = 0; i < refCount; i++) {
        Ref ref = commit.getRef(i);
        String refName = ref.getName();
        if (hideCurrentBranch && head != null && refName.equals(head))
            continue;
        if (refName.startsWith(Constants.R_HEADS) || refName.startsWith(Constants.R_REMOTES))
            branchesOfCommit.add(ref);//from w  w w  . j a  v a 2  s  .c  om
    }
    return branchesOfCommit;
}

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

License:Open Source License

private List<Ref> getBranchesOfCommit(GitHistoryPage page) {
    final List<Ref> branchesOfCommit = new ArrayList<Ref>();
    IStructuredSelection selection = getSelection(page);
    if (selection.isEmpty())
        return branchesOfCommit;
    PlotCommit commit = (PlotCommit) selection.getFirstElement();

    int refCount = commit.getRefCount();
    for (int i = 0; i < refCount; i++) {
        Ref ref = commit.getRef(i);
        String refName = ref.getName();
        if (refName.startsWith(Constants.R_HEADS) || refName.startsWith(Constants.R_REMOTES))
            branchesOfCommit.add(ref);/*from   ww  w . ja  v a 2s.com*/
    }
    return branchesOfCommit;
}

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   w w w  . j ava 2s. co m
}

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);// ww  w .j a  v  a 2 s  .  com
    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 {//  w ww.  j  a v  a2 s  .  c om
        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());

    }
}