List of usage examples for org.eclipse.jgit.lib ObjectId getName
public final String getName()
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 .ja v a 2 s .com*/ 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.emf.compare.git.pgm.internal.app.AbstractLogicalApplication.java
License:Open Source License
/** * Simulate a comparison between the two given references and returns back the subscriber that can provide * all computed synchronization information. * //from w w w. j av a 2 s. c om * @param sourceRef * Source reference (i.e. "left" side of the comparison). * @param targetRef * Target reference (i.e. "right" side of the comparison). * @param comparedFile * The file we are comparing (that would be the file right-clicked into the workspace). * @return The created subscriber. */ protected RemoteResourceMappingContext createSubscriberForComparison(Repository repository, ObjectId sourceRef, ObjectId targetRef, IFile comparedFile) throws IOException { final GitSynchronizeData data = new GitSynchronizeData(repository, sourceRef.getName(), targetRef.getName(), false); final GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(dataSet); subscriber.init(new NullProgressMonitor()); return new GitSubscriberResourceMappingContext(subscriber, dataSet); }
From source file:org.eclipse.mylyn.internal.gerrit.ui.egit.GitFileRevisionUtils.java
License:Open Source License
private static IStorage getFileRevisionStorage(final IProgressMonitor monitor, final Repository repository, final IPath path, final ObjectId objId) { return new IStorage() { @SuppressWarnings("rawtypes") public Object getAdapter(Class adapter) { return null; }// w ww. ja v a2 s . co m public boolean isReadOnly() { return true; } public String getName() { return path.lastSegment(); } public IPath getFullPath() { //Here we append the object Id to the path to distinguish it from the path of this file revision //from the workspace file. This is needed to get good AST resolution and navigability. return path.append(Path.fromPortableString(objId.getName())); } public InputStream getContents() throws CoreException { InputStream in = null; try { in = getBlobContent(monitor, repository, objId); } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage())); } return in; } }; }
From source file:org.eclipse.mylyn.internal.git.core.GitConnector.java
License:Open Source License
private String resolveObject(FileRepository repo, String repoRelativePath) throws AmbiguousObjectException, IOException { //Validate//from w w w . ja v a2 s . c o m if (repo == null || repoRelativePath == null) { return null; } ObjectId headCommitId = repo.resolve(Constants.HEAD); String id = null; if (headCommitId != null) { // Not an empty repo RevWalk revWalk = new RevWalk(repo); RevCommit headCommit = revWalk.parseCommit(headCommitId); RevTree headTree = headCommit.getTree(); TreeWalk resourceInRepo = TreeWalk.forPath(repo, repoRelativePath, headTree); if (resourceInRepo != null) { ObjectId objId = resourceInRepo.getObjectId(0); id = objId.getName(); } revWalk.dispose(); } return id; }
From source file:org.eclipse.mylyn.reviews.r4e.core.rfs.ReviewsRFSProxy.java
License:Open Source License
public String registerReviewBlob(final byte[] content) throws ReviewsFileStorageException { String id = null;//from w ww . ja va 2 s .c o m ObjectId objid = null; try { objid = fInserter.insert(Constants.OBJ_BLOB, content); fInserter.flush(); } catch (IOException e) { //Check if the file has been registered in the repository if yes record the id, log the exception and continue //If the id is not registered throw the exception id = blobIdFor(content); InputStream is = getBlobContent(null, id); if (is == null) { //The file was not registered in the local repo throw new ReviewsFileStorageException(e); } else { Activator.fTracer.traceError( "IOException while registering content however it's already available in the local repository, " + e.getMessage()); try { is.close(); } catch (IOException ex) { Activator.fTracer.traceError("IOException while closing probe stream, " + ex.getMessage()); } } } finally { fInserter.release(); } if (objid != null) { id = objid.getName(); } return id; }
From source file:org.eclipse.mylyn.reviews.r4e.core.rfs.ReviewsRFSProxy.java
License:Open Source License
public String registerReviewBlob(final File aFromFile) throws ReviewsFileStorageException { InputStream stream = null;//from w w w .j av a 2s .com try { stream = new FileInputStream(aFromFile); } catch (FileNotFoundException e) { throw new ReviewsFileStorageException(e); } String id = null; ObjectId objid = null; try { objid = fInserter.insert(Constants.OBJ_BLOB, aFromFile.length(), stream); fInserter.flush(); FileSupportCommandFactory.getInstance() .grantWritePermission(fRepository.getDirectory().getAbsolutePath()); } catch (IOException e) { throw new ReviewsFileStorageException(e); } finally { fInserter.release(); try { stream.close(); } catch (IOException e) { StringBuilder sb = new StringBuilder("Exception: " + e.getMessage()); Activator.fTracer.traceDebug(sb.toString()); } } if (objid != null) { id = objid.getName(); } return id; }
From source file:org.eclipse.mylyn.reviews.r4e.core.rfs.ReviewsRFSProxy.java
License:Open Source License
public String blobIdFor(File aFromFile) throws ReviewsFileStorageException { InputStream stream = null;/* ww w. jav a 2 s.com*/ try { stream = new FileInputStream(aFromFile); } catch (FileNotFoundException e) { throw new ReviewsFileStorageException(e); } String id = null; ObjectId objid = null; try { objid = fInserter.idFor(Constants.OBJ_BLOB, aFromFile.length(), stream); FileSupportCommandFactory.getInstance() .grantWritePermission(fRepository.getDirectory().getAbsolutePath()); } catch (IOException e) { throw new ReviewsFileStorageException(e); } finally { fInserter.release(); try { stream.close(); } catch (IOException e) { StringBuilder sb = new StringBuilder("Exception: " + e.getMessage()); Activator.fTracer.traceDebug(sb.toString()); } } if (objid != null) { id = objid.getName(); } return id; }
From source file:org.eclipse.tycho.extras.sourceref.jgit.JGitSourceReferencesProvider.java
License:Open Source License
public String getSourceReferencesHeader(MavenProject project, ScmUrl scmUrl) throws MojoExecutionException { File basedir = project.getBasedir().getAbsoluteFile(); FileRepositoryBuilder builder = new FileRepositoryBuilder().readEnvironment().findGitDir(basedir) .setMustExist(true);/* w ww . j ava 2s . c om*/ Repository repo; Git git; try { repo = builder.build(); git = Git.wrap(repo); } catch (IOException e) { throw new MojoExecutionException("IO exception trying to create git repo ", e); } ObjectId head = resolveHead(repo); StringBuilder result = new StringBuilder(scmUrl.getUrl()); result.append(";path=\""); result.append(getRelativePath(basedir, repo.getWorkTree())); result.append("\""); String tag = findTagForHead(git, head); if (tag != null) { // may contain e.g. spaces, so we quote it result.append(";tag=\""); result.append(tag); result.append("\""); } result.append(";commitId="); result.append(head.getName()); return result.toString(); }
From source file:org.eluder.coveralls.maven.plugin.domain.GitRepository.java
License:Open Source License
private Git.Head getHead(final Repository repository) throws IOException { ObjectId revision = repository.resolve(Constants.HEAD); RevCommit commit = new RevWalk(repository).parseCommit(revision); Git.Head head = new Git.Head(revision.getName(), commit.getAuthorIdent().getName(), commit.getAuthorIdent().getEmailAddress(), commit.getCommitterIdent().getName(), commit.getCommitterIdent().getEmailAddress(), commit.getFullMessage()); return head;// w w w .j ava 2 s .c o m }
From source file:org.flowerplatform.web.git.GitUtils.java
License:Open Source License
public String handleMergeResult(MergeResult mergeResult) { StringBuilder sb = new StringBuilder(); if (mergeResult == null) { return sb.toString(); }/*w ww . j av a2 s .c o m*/ sb.append("Status: "); sb.append(mergeResult.getMergeStatus()); sb.append("\n"); if (mergeResult.getMergedCommits() != null) { sb.append("\nMerged commits: "); sb.append("\n"); for (ObjectId id : mergeResult.getMergedCommits()) { sb.append(id.getName()); sb.append("\n"); } } if (mergeResult.getCheckoutConflicts() != null) { sb.append("\nConflicts: "); sb.append("\n"); for (String conflict : mergeResult.getCheckoutConflicts()) { sb.append(conflict); sb.append("\n"); } } if (mergeResult.getFailingPaths() != null) { sb.append("\nFailing paths: "); sb.append("\n"); for (String path : mergeResult.getFailingPaths().keySet()) { sb.append(path); sb.append(" -> "); sb.append(mergeResult.getFailingPaths().get(path).toString()); sb.append("\n"); } } return sb.toString(); }