List of usage examples for org.eclipse.jgit.lib Repository resolve
@Nullable public ObjectId resolve(String revstr) throws AmbiguousObjectException, IncorrectObjectTypeException, RevisionSyntaxException, IOException
From source file:org.eclipse.egit.ui.internal.actions.CommitAction.java
License:Open Source License
private void loadPreviousCommit() { IProject project = getProjectsForSelectedResources()[0]; Repository repo = RepositoryMapping.getMapping(project).getRepository(); try {//from www.ja va 2 s . c o m ObjectId parentId = repo.resolve(Constants.HEAD); if (parentId != null) previousCommit = repo.mapCommit(parentId); } catch (IOException e) { Utils.handleError(getTargetPart().getSite().getShell(), e, UIText.CommitAction_errorDuringCommit, UIText.CommitAction_errorRetrievingCommit); } }
From source file:org.eclipse.egit.ui.internal.actions.CommitActionHandler.java
License:Open Source License
private void loadPreviousCommit(ExecutionEvent event) throws ExecutionException { IProject project = getProjectsForSelectedResources(event)[0]; Repository repo = RepositoryMapping.getMapping(project).getRepository(); try {/*w ww. j av a 2s . co m*/ ObjectId parentId = repo.resolve(Constants.HEAD); if (parentId != null) previousCommit = new RevWalk(repo).parseCommit(parentId); } catch (IOException e) { Activator.handleError(UIText.CommitAction_errorRetrievingCommit, e, true); } }
From source file:org.eclipse.egit.ui.internal.actions.PushBranchActionHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { Repository repository = getRepository(true, event); try {//w w w. ja v a 2 s. c om PushBranchWizard wizard = null; Ref ref = getBranchRef(repository); if (ref != null) { wizard = new PushBranchWizard(repository, ref); } else { ObjectId id = repository.resolve(repository.getFullBranch()); wizard = new PushBranchWizard(repository, id); } WizardDialog dlg = new WizardDialog(getShell(event), wizard); dlg.open(); } catch (IOException ex) { Activator.handleError(ex.getLocalizedMessage(), ex, false); } return null; }
From source file:org.eclipse.egit.ui.internal.commit.CommitHelper.java
License:Open Source License
private static RevCommit getHeadCommit(Repository repository) { RevCommit headCommit = null;//w w w . j a va 2 s . co m try { ObjectId parentId = repository.resolve(Constants.HEAD); if (parentId != null) headCommit = new RevWalk(repository).parseCommit(parentId); } catch (IOException e) { Activator.handleError(UIText.CommitAction_errorRetrievingCommit, e, true); } return headCommit; }
From source file:org.eclipse.egit.ui.internal.commit.CommitSelectionDialog.java
License:Open Source License
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException { String pattern = itemsFilter.getPattern(); Repository[] repositories = getRepositories(); progressMonitor.beginTask(UIText.CommitSelectionDialog_TaskSearching, repositories.length); for (Repository repository : repositories) { try {/*w w w. j av a 2s . c o m*/ ObjectId commitId; if (ObjectId.isId(pattern)) commitId = ObjectId.fromString(pattern); else commitId = repository.resolve(itemsFilter.getPattern()); if (commitId != null) { RevWalk walk = new RevWalk(repository); walk.setRetainBody(true); RevCommit commit = walk.parseCommit(commitId); contentProvider.add(new RepositoryCommit(repository, commit), itemsFilter); } } catch (RevisionSyntaxException ignored) { // Ignore and advance } catch (IOException ignored) { // Ignore and advance } progressMonitor.worked(1); } }
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;/*w w w . ja 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.CompareTreeView.java
License:Open Source License
private void buildTrees(final boolean buildMaps) { final Object[] wsExpaneded = tree.getExpandedElements(); final ISelection wsSel = tree.getSelection(); tree.setInput(null);/*w ww . j av a2s . co m*/ if (baseVersion == null) { tree.setContentProvider(new WorkbenchTreeContentProvider()); tree.setComparator(new WorkbenchTreeComparator()); tree.setLabelProvider(new WorkbenchTreeLabelProvider()); } else { tree.setContentProvider(new PathNodeContentProvider()); tree.setComparator(new PathNodeTreeComparator()); tree.setLabelProvider(new PathNodeLabelProvider()); } for (IWorkbenchAction action : actionsToDispose) action.setEnabled(false); showEquals = Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.TREE_COMPARE_SHOW_EQUALS); final Repository repo; if (input instanceof IResource[]) { repositoryMapping = RepositoryMapping.getMapping(((IResource[]) input)[0]); if (repositoryMapping == null || repositoryMapping.getRepository() == null) return; repo = repositoryMapping.getRepository(); } else if (input instanceof Repository) { repo = (Repository) input; } else return; final RevCommit baseCommit; final RevCommit compareCommit; RevWalk rw = new RevWalk(repo); try { ObjectId commitId = repo.resolve(compareVersion); compareCommit = commitId != null ? rw.parseCommit(commitId) : null; if (baseVersion == null) baseCommit = null; else { commitId = repo.resolve(baseVersion); baseCommit = rw.parseCommit(commitId); } } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); return; } finally { rw.release(); } showBusy(true); try { // this does the hard work... new ProgressMonitorDialog(getViewSite().getShell()).run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (buildMaps) buildMaps(repo, baseCommit, compareCommit, monitor); PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { tree.setInput(input); tree.setExpandedElements(wsExpaneded); tree.setSelection(wsSel); updateControls(); } }); } catch (IOException e) { throw new InvocationTargetException(e); } } }); } catch (InvocationTargetException e) { Activator.handleError(e.getTargetException().getMessage(), e.getTargetException(), true); } catch (InterruptedException e) { input = null; } finally { showBusy(false); } }
From source file:org.eclipse.egit.ui.internal.history.command.AbstractHistoryCommandHandler.java
License:Open Source License
/** * @param event//from w ww . j ava 2 s .c o m * @return the tags * @throws ExecutionException */ protected List<RevTag> getRevTags(ExecutionEvent event) throws ExecutionException { Repository repo = getRepository(event); Collection<Ref> revTags = repo.getTags().values(); List<RevTag> tags = new ArrayList<RevTag>(); RevWalk walk = new RevWalk(repo); for (Ref ref : revTags) { try { tags.add(walk.parseTag(repo.resolve(ref.getName()))); } catch (IOException e) { throw new ExecutionException(e.getMessage(), e); } } return tags; }
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;/*from w w w . j a v a 2s. 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.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;//from w w w. ja va 2 s . c om 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; }