List of usage examples for org.eclipse.jgit.lib Constants OBJ_BLOB
int OBJ_BLOB
To view the source code for org.eclipse.jgit.lib Constants OBJ_BLOB.
Click Source Link
From source file:org.eclipse.egit.ui.internal.synchronize.model.GitModelObjectContainer.java
License:Open Source License
/** * * @param tw instance of {@link TreeWalk} that should be used * @param ancestorNth// ww w. j ava2 s .c om * @param baseNth * @param actualNth * @return {@link GitModelObject} instance of given parameters * @throws IOException */ protected GitModelObject getModelObject(TreeWalk tw, int ancestorNth, int baseNth, int actualNth) throws IOException { String objName = tw.getNameString(); ObjectId objBaseId; if (baseNth > -1) objBaseId = tw.getObjectId(baseNth); else objBaseId = ObjectId.zeroId(); ObjectId objRemoteId = tw.getObjectId(actualNth); ObjectId objAncestorId = tw.getObjectId(ancestorNth); int objectType = tw.getFileMode(actualNth).getObjectType(); if (objectType == Constants.OBJ_BLOB) return new GitModelBlob(this, getBaseCommit(), objAncestorId, objBaseId, objRemoteId, objName); else if (objectType == Constants.OBJ_TREE) return new GitModelTree(this, getBaseCommit(), objAncestorId, objBaseId, objRemoteId, objName); return null; }
From source file:org.eclipse.emf.compare.egit.internal.merge.RecursiveModelMerger.java
License:Open Source License
/** * Add files modified by model mergers to the index. * * @throws CorruptObjectException/* w w w . j a v a 2 s . c om*/ * @throws MissingObjectException * @throws IncorrectObjectTypeException * @throws IOException */ private void indexModelMergedFiles() throws CorruptObjectException, MissingObjectException, IncorrectObjectTypeException, IOException { TreeWalk syncingTreeWalk = new TreeWalk(getRepository()); try { syncingTreeWalk.addTree(new DirCacheIterator(dircache)); syncingTreeWalk.addTree(new FileTreeIterator(getRepository())); syncingTreeWalk.setRecursive(true); syncingTreeWalk.setFilter(PathFilterGroup.createFromStrings(makeInSync)); String lastAdded = null; while (syncingTreeWalk.next()) { String path = syncingTreeWalk.getPathString(); if (path.equals(lastAdded)) { continue; } WorkingTreeIterator workingTree = syncingTreeWalk.getTree(1, WorkingTreeIterator.class); DirCacheIterator dirCache = syncingTreeWalk.getTree(0, DirCacheIterator.class); if (dirCache == null && workingTree != null && workingTree.isEntryIgnored()) { // nothing to do on this one } else if (workingTree != null) { if (dirCache == null || dirCache.getDirCacheEntry() == null || !dirCache.getDirCacheEntry().isAssumeValid()) { final DirCacheEntry dce = new DirCacheEntry(path); final FileMode mode = workingTree.getIndexFileMode(dirCache); dce.setFileMode(mode); if (FileMode.GITLINK != mode) { dce.setLength(workingTree.getEntryLength()); dce.setLastModified(workingTree.getEntryLastModified()); InputStream is = workingTree.openEntryStream(); try { dce.setObjectId(getObjectInserter().insert(Constants.OBJ_BLOB, workingTree.getEntryContentLength(), is)); } finally { is.close(); } } else { dce.setObjectId(workingTree.getEntryObjectId()); } builder.add(dce); lastAdded = path; } else { builder.add(dirCache.getDirCacheEntry()); } } else if (dirCache != null && FileMode.GITLINK == dirCache.getEntryFileMode()) { builder.add(dirCache.getDirCacheEntry()); } } } finally { syncingTreeWalk.close(); } }
From source file:org.eclipse.mylyn.internal.gerrit.ui.egit.GitFileRevisionUtils.java
License:Open Source License
public static IFileRevision getFileRevision(final Repository repository, final IFileVersion reviewFileVersion) { IFileRevision gitFileRevision = null; if (reviewFileVersion != null && reviewFileVersion.getPath() != null) { //Get SHA-1 for the file revision to look for the correct file revision in the Git repository ObjectInserter inserter = repository.newObjectInserter(); String id = inserter.idFor(Constants.OBJ_BLOB, CompareUtil.getContent(reviewFileVersion)).getName(); inserter.release();// ww w. jav a2s .co m if (id != null) { final ObjectId objId = ObjectId.fromString(id); if (objId != null) { final IPath path = Path.fromPortableString(reviewFileVersion.getPath()); gitFileRevision = new org.eclipse.team.core.history.provider.FileRevision() { public IFileRevision withAllProperties(IProgressMonitor monitor) throws CoreException { return this; } public boolean isPropertyMissing() { return false; } public IStorage getStorage(IProgressMonitor monitor) throws CoreException { return getFileRevisionStorage(null, repository, path, objId); } public String getName() { return path.lastSegment(); } }; } } } return gitFileRevision; }
From source file:org.eclipse.mylyn.internal.gerrit.ui.egit.GitFileRevisionUtils.java
License:Open Source License
private static InputStream getBlobContent(final IProgressMonitor monitor, final Repository repository, final ObjectId objId) throws CoreException { InputStream resStream = null; try {// w w w . ja va2s. c o m resStream = repository.open(objId, Constants.OBJ_BLOB).openStream(); } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage())); } return resStream; }
From source file:org.eclipse.mylyn.internal.git.core.GitArtifact.java
License:Open Source License
@Override public IFileRevision getFileRevision(IProgressMonitor monitor) { try {//from w w w.j a v a 2s. com final IPath path = Path.fromPortableString(getPath()); return new FileRevision() { public IFileRevision withAllProperties(IProgressMonitor monitor) throws CoreException { return this; } public boolean isPropertyMissing() { return false; } public IStorage getStorage(IProgressMonitor monitor) throws CoreException { return new IStorage() { @SuppressWarnings("rawtypes") public Object getAdapter(Class adapter) { return null; } public boolean isReadOnly() { return true; } public String getName() { return path.lastSegment(); } public IPath getFullPath() { return path; } public InputStream getContents() throws CoreException { try { return repository.getRepository() .open(ObjectId.fromString(getId()), Constants.OBJ_BLOB).openStream(); } catch (Exception e) { e.printStackTrace(); throw new CoreException( new Status(IStatus.ERROR, GitConnector.PLUGIN_ID, e.getMessage())); } } }; } public String getName() { return path.lastSegment(); } }; } catch (Exception e) { e.printStackTrace(); return null; } }
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 w w .j ava2 s . com 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 a v 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.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 InputStream getBlobContent(IProgressMonitor monitor, String id) throws ReviewsFileStorageException { InputStream resStream = null; if (id == null) { return null; }/*w ww . ja va 2s . c om*/ try { ObjectId objId = ObjectId.fromString(id); resStream = fRepository.open(objId, Constants.OBJ_BLOB).openStream(); } catch (Exception e) { throw new ReviewsFileStorageException(e); } return resStream; }
From source file:org.eclipse.mylyn.reviews.r4e.core.rfs.ReviewsRFSProxy.java
License:Open Source License
public String blobIdFor(byte[] content) { String id = fInserter.idFor(Constants.OBJ_BLOB, content).getName(); fInserter.release(); 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;//from ww w. j a v a 2 s .c o m 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; }