List of usage examples for org.eclipse.jgit.lib Constants R_HEADS
String R_HEADS
To view the source code for org.eclipse.jgit.lib Constants R_HEADS.
Click Source Link
From source file:org.eclipse.egit.ui.internal.clone.SourceBranchPage.java
License:Open Source License
private void revalidateImpl(final RepositorySelection newRepoSelection) { if (label.isDisposed() || !isCurrentPage()) return;/*w w w . j ava 2 s . c om*/ final ListRemoteOperation listRemoteOp; try { final URIish uri = newRepoSelection.getURI(); final Repository db = new FileRepository(new File("/tmp")); //$NON-NLS-1$ int timeout = Activator.getDefault().getPreferenceStore() .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); listRemoteOp = new ListRemoteOperation(db, uri, timeout); if (credentials != null) listRemoteOp.setCredentialsProvider( new UsernamePasswordCredentialsProvider(credentials.getUser(), credentials.getPassword())); getContainer().run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { listRemoteOp.run(monitor); } }); } catch (InvocationTargetException e) { Throwable why = e.getCause(); transportError(why.getMessage()); ErrorDialog.openError(getShell(), UIText.SourceBranchPage_transportError, UIText.SourceBranchPage_cannotListBranches, new Status(IStatus.ERROR, Activator.getPluginId(), 0, why.getMessage(), why.getCause())); return; } catch (IOException e) { transportError(UIText.SourceBranchPage_cannotCreateTemp); return; } catch (InterruptedException e) { transportError(UIText.SourceBranchPage_remoteListingCancelled); return; } final Ref idHEAD = listRemoteOp.getRemoteRef(Constants.HEAD); head = null; for (final Ref r : listRemoteOp.getRemoteRefs()) { final String n = r.getName(); if (!n.startsWith(Constants.R_HEADS)) continue; availableRefs.add(r); if (idHEAD == null || head != null) continue; if (r.getObjectId().equals(idHEAD.getObjectId())) head = r; } Collections.sort(availableRefs, new Comparator<Ref>() { public int compare(final Ref o1, final Ref o2) { return o1.getName().compareTo(o2.getName()); } }); if (idHEAD != null && head == null) { head = idHEAD; availableRefs.add(0, idHEAD); } validatedRepoSelection = newRepoSelection; refsViewer.setInput(availableRefs); refsViewer.setAllChecked(true); checkPage(); checkForEmptyRepo(); }
From source file:org.eclipse.egit.ui.internal.commit.CommitEditorPage.java
License:Open Source License
private List<Ref> loadBranches() { Repository repository = getCommit().getRepository(); RevCommit commit = getCommit().getRevCommit(); RevWalk revWalk = new RevWalk(repository); try {/* w w w .j a va 2 s .c om*/ Map<String, Ref> refsMap = new HashMap<String, Ref>(); refsMap.putAll(repository.getRefDatabase().getRefs(Constants.R_HEADS)); refsMap.putAll(repository.getRefDatabase().getRefs(Constants.R_REMOTES)); return RevWalkUtils.findBranchesReachableFrom(commit, revWalk, refsMap.values()); } catch (IOException e) { Activator.handleError(e.getMessage(), e, false); return Collections.emptyList(); } }
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 a va2s . c om * {@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); }); }
From source file:org.eclipse.egit.ui.internal.components.RefContentAssistProvider.java
License:Open Source License
/** * @param source whether we want proposals for the source or the destination of the operation * @param pushMode whether the operation is a push or a fetch * @return a list of all refs for the given mode. *//*from ww w.ja v a 2 s . c om*/ public List<Ref> getRefsForContentAssist(boolean source, boolean pushMode) { if (source) { if (sourceRefs != null) return sourceRefs; } else if (destinationRefs != null) return destinationRefs; List<Ref> result = new ArrayList<Ref>(); try { boolean local = pushMode == source; if (!local) { final ListRemoteOperation lop = new ListRemoteOperation(repo, uri, Activator.getDefault() .getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT)); new ProgressMonitorDialog(shell).run(false, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(UIText.RefSpecDialog_GettingRemoteRefsMonitorMessage, IProgressMonitor.UNKNOWN); lop.run(monitor); monitor.done(); } }); for (Ref ref : lop.getRemoteRefs()) if (ref.getName().startsWith(Constants.R_HEADS) || (!pushMode && ref.getName().startsWith(Constants.R_TAGS))) result.add(ref); } else if (pushMode) for (Ref ref : repo.getRefDatabase().getRefs(RefDatabase.ALL).values()) { if (ref.getName().startsWith(Constants.R_REMOTES)) continue; result.add(ref); } else for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_REMOTES).values()) result.add(ref); } catch (RuntimeException e) { throw e; } catch (Exception e) { Activator.handleError(e.getMessage(), e, true); return result; } if (source) sourceRefs = result; else destinationRefs = result; return result; }
From source file:org.eclipse.egit.ui.internal.components.RefSpecPanel.java
License:Open Source License
private static List<RefContentProposal> createProposalsFilteredRemote( final List<RefContentProposal> proposals) { final List<RefContentProposal> result = new ArrayList<RefContentProposal>(); for (final RefContentProposal p : proposals) { final String content = p.getContent(); if (content.equals(Constants.HEAD) || content.startsWith(Constants.R_HEADS)) result.add(p);// w w w. j a v a 2 s . c om } return result; }
From source file:org.eclipse.egit.ui.internal.components.RefSpecPanel.java
License:Open Source License
private void tryAutoCompleteSrcToDst() { final String src = creationSrcCombo.getText(); final String dst = creationDstCombo.getText(); if (src == null || src.length() == 0) return;// www . j a va 2s . c om if (dst != null && dst.length() > 0) { // dst is already there, just fix wildcards if needed final String newDst; if (RefSpec.isWildcard(src)) newDst = wildcardSpecComponent(dst); else newDst = unwildcardSpecComponent(dst, src); creationDstCombo.setText(newDst); return; } if (!isValidRefExpression(src)) { // no way to be smarter than user here return; } // dst is empty, src is ref or wildcard, so we can rewrite it as user // would perhaps if (pushSpecs) creationDstCombo.setText(src); else { for (final RefSpec spec : predefinedConfigured) { if (spec.matchSource(src)) { final String newDst = spec.expandFromSource(src).getDestination(); creationDstCombo.setText(newDst); return; } } if (remoteName != null && src.startsWith(Constants.R_HEADS)) { final String newDst = Constants.R_REMOTES + remoteName + '/' + src.substring(Constants.R_HEADS.length()); creationDstCombo.setText(newDst); } } }
From source file:org.eclipse.egit.ui.internal.components.RefSpecPanel.java
License:Open Source License
private List<RefContentProposal> createProposalsFilteredLocal(final List<RefContentProposal> proposals) { final List<RefContentProposal> result = new ArrayList<RefContentProposal>(); for (final RefContentProposal p : proposals) { final String content = p.getContent(); if (pushSpecs) { if (content.equals(Constants.HEAD) || content.startsWith(Constants.R_HEADS)) result.add(p);//from w w w .j ava 2 s . c om } else { if (content.startsWith(Constants.R_REMOTES)) result.add(p); } } return result; }
From source file:org.eclipse.egit.ui.internal.components.SimplePushSpecPage.java
License:Open Source License
/** * pre-fills the destination box with a remote ref name if one exists that * matches the local branch name.//from ww w .j a va2 s . c o m */ protected void updateDestinationField() { setMessage(NLS.bind(UIText.SimplePushSpecPage_message, sourceName)); String checkRemote = sourceName; if (sourceName.startsWith(Constants.R_HEADS)) { try { BranchTrackingStatus status = BranchTrackingStatus.of(repository, sourceName.substring(Constants.R_HEADS.length())); if (status != null) { // calculate the name of the branch on the other side. checkRemote = status.getRemoteTrackingBranch(); checkRemote = Constants.R_HEADS + checkRemote.substring(checkRemote.indexOf('/', Constants.R_REMOTES.length() + 1) + 1); setMessage( NLS.bind(UIText.SimplePushSpecPage_pushAheadInfo, new Object[] { sourceName, Integer.valueOf(status.getAheadCount()), status.getRemoteTrackingBranch() }), IStatus.INFO); } } catch (Exception e) { // ignore and continue... } if (assist == null) { if (checkRemote != null) remoteRefName.setText(checkRemote); return; } if (checkRemote == null) checkRemote = sourceName; for (Ref ref : assist.getRefsForContentAssist(false, true)) if (ref.getName().equals(checkRemote)) remoteRefName.setText(checkRemote); } }
From source file:org.eclipse.egit.ui.internal.dialogs.AbstractBranchSelectionDialog.java
License:Open Source License
/** * Set the selection to a {@link Ref} if possible * * @param refName/*w w w. jav a 2 s.c o m*/ * the name of the {@link Ref} * @return <code>true</code> if the {@link Ref} with the given name was * found */ protected boolean markRef(String refName) { // selects the entry specified by the name if (refName == null) return false; RepositoryTreeNode node; try { if (refName.startsWith(Constants.R_HEADS)) { Ref ref = this.repo.getRef(refName); node = new RefNode(localBranches, this.repo, ref); } else { String mappedRef = Activator.getDefault().getRepositoryUtil().mapCommitToRef(this.repo, refName, false); if (mappedRef != null && mappedRef.startsWith(Constants.R_REMOTES)) { Ref ref = this.repo.getRef(mappedRef); node = new RefNode(remoteBranches, this.repo, ref); } else if (mappedRef != null && mappedRef.startsWith(Constants.R_TAGS)) { Ref ref = this.repo.getRef(mappedRef); node = new TagNode(tags, this.repo, ref); } else { return false; } } } catch (IOException e) { return false; } branchTree.setSelection(new StructuredSelection(node), true); return true; }
From source file:org.eclipse.egit.ui.internal.dialogs.BranchConfigurationDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite main = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().numColumns(2).applyTo(main); GridDataFactory.fillDefaults().grab(true, false).indent(5, 5).applyTo(main); Label branchLabel = new Label(main, SWT.NONE); branchLabel.setText(UIText.BranchConfigurationDialog_UpstreamBranchLabel); branchText = new Combo(main, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(branchText); try {// w ww.ja v a 2s .co m for (Ref ref : myRepository.getRefDatabase().getRefs(Constants.R_HEADS).values()) branchText.add(ref.getName()); for (Ref ref : myRepository.getRefDatabase().getRefs(Constants.R_REMOTES).values()) branchText.add(ref.getName()); } catch (IOException e) { Activator.logError(UIText.BranchConfigurationDialog_ExceptionGettingRefs, e); } Label remoteLabel = new Label(main, SWT.NONE); remoteLabel.setText(UIText.BranchConfigurationDialog_RemoteLabel); remoteText = new Combo(main, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(remoteText); // TODO do we have a constant somewhere? remoteText.add("."); //$NON-NLS-1$ for (String remote : myConfig.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION)) remoteText.add(remote); rebase = new Button(main, SWT.CHECK); GridDataFactory.fillDefaults().span(2, 1).applyTo(rebase); rebase.setText(UIText.BranchConfigurationDialog_RebaseLabel); String branch = myConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName, ConfigConstants.CONFIG_KEY_MERGE); if (branch == null) branch = ""; //$NON-NLS-1$ branchText.setText(branch); String remote = myConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName, ConfigConstants.CONFIG_KEY_REMOTE); if (remote == null) remote = ""; //$NON-NLS-1$ remoteText.setText(remote); boolean rebaseFlag = myConfig.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName, ConfigConstants.CONFIG_KEY_REBASE, false); rebase.setSelection(rebaseFlag); applyDialogFont(main); // return result; return main; }