List of usage examples for org.eclipse.jgit.lib Constants HEAD
String HEAD
To view the source code for org.eclipse.jgit.lib Constants HEAD.
Click Source Link
From source file:org.eclipse.egit.ui.internal.decorators.DecoratableResourceAdapter.java
License:Open Source License
private String getShortBranch() throws IOException { Ref head = repository.getRef(Constants.HEAD); if (head != null && !head.isSymbolic()) { String refString = Activator.getDefault().getRepositoryUtil().mapCommitToRef(repository, repository.getFullBranch(), false); if (refString != null) { return repository.getFullBranch().substring(0, 7) + "... (" + refString + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } else// www. j av a2 s . c o m return repository.getFullBranch().substring(0, 7) + "..."; //$NON-NLS-1$ } return repository.getBranch(); }
From source file:org.eclipse.egit.ui.internal.decorators.GitDocument.java
License:Open Source License
void populate() throws IOException { if (GitTraceLocation.QUICKDIFF.isActive()) GitTraceLocation.getTrace().traceEntry(GitTraceLocation.QUICKDIFF.getLocation(), resource); TreeWalk tw = null;//from w w w .j a v a 2 s . c o m RevWalk rw = null; try { RepositoryMapping mapping = RepositoryMapping.getMapping(resource); if (mapping == null) { setResolved(null, null, null, ""); //$NON-NLS-1$ return; } final String gitPath = mapping.getRepoRelativePath(resource); final Repository repository = mapping.getRepository(); String baseline = GitQuickDiffProvider.baseline.get(repository); if (baseline == null) baseline = Constants.HEAD; ObjectId commitId = repository.resolve(baseline); if (commitId != null) { if (commitId.equals(lastCommit)) { if (GitTraceLocation.QUICKDIFF.isActive()) GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), "(GitDocument) already resolved"); //$NON-NLS-1$ return; } } else { String msg = NLS.bind(UIText.GitDocument_errorResolveQuickdiff, new Object[] { baseline, resource, repository }); Activator.logError(msg, new Throwable()); setResolved(null, null, null, ""); //$NON-NLS-1$ return; } rw = new RevWalk(repository); RevCommit baselineCommit; try { baselineCommit = rw.parseCommit(commitId); } catch (IOException err) { String msg = NLS.bind(UIText.GitDocument_errorLoadCommit, new Object[] { commitId, baseline, resource, repository }); Activator.logError(msg, err); setResolved(null, null, null, ""); //$NON-NLS-1$ return; } RevTree treeId = baselineCommit.getTree(); if (treeId.equals(lastTree)) { if (GitTraceLocation.QUICKDIFF.isActive()) GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), "(GitDocument) already resolved"); //$NON-NLS-1$ return; } tw = TreeWalk.forPath(repository, gitPath, treeId); ObjectId id = tw.getObjectId(0); if (id.equals(ObjectId.zeroId())) { setResolved(null, null, null, ""); //$NON-NLS-1$ String msg = NLS.bind(UIText.GitDocument_errorLoadTree, new Object[] { treeId, baseline, resource, repository }); Activator.logError(msg, new Throwable()); setResolved(null, null, null, ""); //$NON-NLS-1$ return; } if (!id.equals(lastBlob)) { if (GitTraceLocation.QUICKDIFF.isActive()) GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), "(GitDocument) compareTo: " + baseline); //$NON-NLS-1$ ObjectLoader loader = repository.open(id, Constants.OBJ_BLOB); byte[] bytes = loader.getBytes(); String charset; charset = CompareUtils.getResourceEncoding(resource); // Finally we could consider validating the content with respect // to the content. We don't do that here. String s = new String(bytes, charset); setResolved(commitId, treeId, id, s); if (GitTraceLocation.QUICKDIFF.isActive()) GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), "(GitDocument) has reference doc, size=" + s.length() + " bytes"); //$NON-NLS-1$ //$NON-NLS-2$ } else { if (GitTraceLocation.QUICKDIFF.isActive()) GitTraceLocation.getTrace().trace(GitTraceLocation.QUICKDIFF.getLocation(), "(GitDocument) already resolved"); //$NON-NLS-1$ } } finally { if (tw != null) tw.release(); if (rw != null) rw.release(); if (GitTraceLocation.QUICKDIFF.isActive()) GitTraceLocation.getTrace().traceExit(GitTraceLocation.QUICKDIFF.getLocation()); } }
From source file:org.eclipse.egit.ui.internal.dialogs.CommitDialog.java
License:Open Source License
/** Retrieve file status * @param file/* ww w. j a v a 2s . c om*/ * @return file status * @throws IOException */ private static String getFileStatus(IFile file) throws IOException { RepositoryMapping mapping = RepositoryMapping.getMapping(file); String path = mapping.getRepoRelativePath(file); Repository repo = mapping.getRepository(); AdaptableFileTreeIterator fileTreeIterator = new AdaptableFileTreeIterator(repo, ResourcesPlugin.getWorkspace().getRoot()); IndexDiff indexDiff = new IndexDiff(repo, Constants.HEAD, fileTreeIterator); Set<String> repositoryPaths = Collections.singleton(path); indexDiff.setFilter(PathFilterGroup.createFromStrings(repositoryPaths)); indexDiff.diff(); return getFileStatus(path, indexDiff); }
From source file:org.eclipse.egit.ui.internal.dialogs.CreateTagDialog.java
License:Open Source License
private void getRevCommits(Collection<RevCommit> commits) { RevWalk revWalk = new RevWalk(repo); revWalk.sort(RevSort.COMMIT_TIME_DESC, true); revWalk.sort(RevSort.BOUNDARY, true); try {//from w ww. jav a 2s. co m AnyObjectId headId = repo.resolve(Constants.HEAD); if (headId != null) revWalk.markStart(revWalk.parseCommit(headId)); } catch (IOException e) { Activator.logError(UIText.TagAction_errorWhileGettingRevCommits, e); setErrorMessage(UIText.TagAction_errorWhileGettingRevCommits); } // do the walk to get the commits for (RevCommit commit : revWalk) commits.add(commit); }
From source file:org.eclipse.egit.ui.internal.GitLabels.java
License:Open Source License
/** * @param ref//ww w. j a v a 2 s .c o m * @return a description of the ref, or null if the ref does not have a * description */ public static String getRefDescription(Ref ref) { String name = ref.getName(); if (name.equals(Constants.HEAD)) { if (ref.isSymbolic()) return UIText.GitLabelProvider_RefDescriptionHeadSymbolic; else return UIText.GitLabelProvider_RefDescriptionHead; } else if (name.equals(Constants.ORIG_HEAD)) return UIText.GitLabelProvider_RefDescriptionOrigHead; else if (name.equals(Constants.FETCH_HEAD)) return UIText.GitLabelProvider_RefDescriptionFetchHead; else if (name.equals(Constants.R_STASH)) return UIText.GitLabelProvider_RefDescriptionStash; else return null; }
From source file:org.eclipse.egit.ui.internal.history.command.CompareWithWorkingTreeHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection selection = getSelection(getPage()); if (selection.size() == 1) { Iterator<?> it = selection.iterator(); RevCommit commit = (RevCommit) it.next(); Object input = getPage().getInputInternal().getSingleFile(); if (input instanceof IFile) { IFile file = (IFile) input;// w w w. j av a 2 s. c o m final RepositoryMapping mapping = RepositoryMapping.getMapping(file.getProject()); final String gitPath = mapping.getRepoRelativePath(file); ITypedElement right = CompareUtils.getFileRevisionTypedElement(gitPath, commit, mapping.getRepository()); final GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput( SaveableCompareEditorInput.createFileElement(file), right, null); openInCompare(event, in); } if (input instanceof File) { File file = (File) input; // TODO can we create a ITypedElement from the local file? Repository repo = getRepository(event); RevCommit leftCommit; try { leftCommit = new RevWalk(repo).parseCommit(repo.resolve(Constants.HEAD)); } catch (Exception e) { throw new ExecutionException(e.getMessage(), e); } final String gitPath = getRepoRelativePath(repo, file); ITypedElement left = CompareUtils.getFileRevisionTypedElement(gitPath, leftCommit, repo); ITypedElement right = CompareUtils.getFileRevisionTypedElement(gitPath, commit, repo); final GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput(left, right, null); openInCompare(event, in); return null; } } return null; }
From source file:org.eclipse.egit.ui.internal.history.command.MergeHandler.java
License:Open Source License
private boolean canMerge(final Repository repository) { String message = null;/*w w w .java 2s .co m*/ Exception ex = null; try { Ref head = repository.getRef(Constants.HEAD); if (head == null || !head.isSymbolic()) message = UIText.MergeAction_HeadIsNoBranch; else if (!repository.getRepositoryState().equals(RepositoryState.SAFE)) message = NLS.bind(UIText.MergeAction_WrongRepositoryState, repository.getRepositoryState()); } catch (IOException e) { message = e.getMessage(); ex = e; } if (message != null) Activator.handleError(UIText.MergeAction_CannotMerge, ex, true); return (message == null); }
From source file:org.eclipse.egit.ui.internal.history.command.ShowVersionsHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { boolean compareMode = Boolean.TRUE.toString() .equals(event.getParameter(HistoryViewCommands.COMPARE_MODE_PARAM)); IStructuredSelection selection = getSelection(getPage()); if (selection.size() < 1) return null; Object input = getPage().getInputInternal().getSingleFile(); if (input == null) return null; boolean errorOccured = false; List<ObjectId> ids = new ArrayList<ObjectId>(); String gitPath = null;// w ww . j ava 2s. c o m if (input instanceof IFile) { IFile resource = (IFile) input; final RepositoryMapping map = RepositoryMapping.getMapping(resource); gitPath = map.getRepoRelativePath(resource); Iterator<?> it = selection.iterator(); while (it.hasNext()) { RevCommit commit = (RevCommit) it.next(); IFileRevision rev = null; try { rev = CompareUtils.getFileRevision(gitPath, commit, map.getRepository(), null); } catch (IOException e) { Activator.logError(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, gitPath, commit.getId()), e); errorOccured = true; } if (rev != null) { if (compareMode) { ITypedElement right = CompareUtils.getFileRevisionTypedElement(gitPath, commit, map.getRepository()); final GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput( SaveableCompareEditorInput.createFileElement(resource), right, null); try { openInCompare(event, in); } catch (Exception e) { errorOccured = true; } } else { try { EgitUiEditorUtils.openEditor(getPart(event).getSite().getPage(), rev, new NullProgressMonitor()); } catch (CoreException e) { Activator.logError(UIText.GitHistoryPage_openFailed, e); errorOccured = true; } } } else { ids.add(commit.getId()); } } } if (input instanceof File) { File fileInput = (File) input; Repository repo = getRepository(event); gitPath = getRepoRelativePath(repo, fileInput); Iterator<?> it = selection.iterator(); while (it.hasNext()) { RevCommit commit = (RevCommit) it.next(); IFileRevision rev = null; try { rev = CompareUtils.getFileRevision(gitPath, commit, repo, null); } catch (IOException e) { Activator.logError(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, gitPath, commit.getId()), e); errorOccured = true; } if (rev != null) { if (compareMode) { try { ITypedElement left = CompareUtils.getFileRevisionTypedElement(gitPath, new RevWalk(repo).parseCommit(repo.resolve(Constants.HEAD)), repo); ITypedElement right = CompareUtils.getFileRevisionTypedElement(gitPath, commit, repo); final GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput(left, right, null); openInCompare(event, in); } catch (IOException e) { errorOccured = true; } } else { try { EgitUiEditorUtils.openEditor(getPart(event).getSite().getPage(), rev, new NullProgressMonitor()); } catch (CoreException e) { Activator.logError(UIText.GitHistoryPage_openFailed, e); errorOccured = true; } } } else { ids.add(commit.getId()); } } } if (errorOccured) Activator.showError(UIText.GitHistoryPage_openFailed, null); if (ids.size() > 0) { StringBuilder idList = new StringBuilder(""); //$NON-NLS-1$ for (ObjectId objectId : ids) { idList.append(objectId.getName()).append(' '); } MessageDialog.openError(getPart(event).getSite().getShell(), UIText.GitHistoryPage_fileNotFound, NLS.bind(UIText.GitHistoryPage_notContainedInCommits, gitPath, idList.toString())); } return null; }
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 ww . ja 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 {/*from w w w. ja va2 s. co 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()); } }