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.core.internal.storage.BlobStorage.java
License:Open Source License
private InputStream open() throws IOException, CoreException, IncorrectObjectTypeException { try {/* w ww .j a va 2 s. c om*/ return db.open(blobId, Constants.OBJ_BLOB).openStream(); } catch (MissingObjectException notFound) { throw new CoreException( Activator.error(NLS.bind(CoreText.BlobStorage_blobNotFound, blobId.name(), path), null)); } }
From source file:org.eclipse.egit.core.internal.storage.IndexFileRevisionTest.java
License:Open Source License
private DirCacheEntry entry(String path, int stage, String data) throws IOException { DirCacheEntry entry = new DirCacheEntry(path, stage); entry.setFileMode(FileMode.REGULAR_FILE); ObjectInserter inserter = repository.newObjectInserter(); try {//from ww w . j a v a 2 s .co m ObjectId blob = inserter.insert(Constants.OBJ_BLOB, data.getBytes("UTF-8")); entry.setObjectId(blob); inserter.flush(); } finally { inserter.release(); } return entry; }
From source file:org.eclipse.egit.core.storage.GitBlobStorage.java
License:Open Source License
private InputStream open() throws IOException, CoreException, IncorrectObjectTypeException { if (blobId == null) return new ByteArrayInputStream(new byte[0]); try {/*w w w. j av a 2 s .co m*/ WorkingTreeOptions workingTreeOptions = db.getConfig().get(WorkingTreeOptions.KEY); final InputStream objectInputStream = db.open(blobId, Constants.OBJ_BLOB).openStream(); switch (workingTreeOptions.getAutoCRLF()) { case INPUT: // When autocrlf == input the working tree could be either CRLF or LF, i.e. the comparison // itself should ignore line endings. case FALSE: return objectInputStream; case TRUE: default: return new AutoCRLFInputStream(objectInputStream, true); } } catch (MissingObjectException notFound) { throw new CoreException( Activator.error(NLS.bind(CoreText.BlobStorage_blobNotFound, blobId.name(), path), notFound)); } }
From source file:org.eclipse.egit.core.test.GitTestCase.java
License:Open Source License
protected ObjectId createFile(Repository repository, IProject actProject, String name, String content) throws IOException { File file = new File(actProject.getProject().getLocation().toFile(), name); FileWriter fileWriter = new FileWriter(file); fileWriter.write(content);/*from ww w . ja va 2s.c om*/ fileWriter.close(); byte[] fileContents = IO.readFully(file); ObjectInserter inserter = repository.newObjectInserter(); try { ObjectId objectId = inserter.insert(Constants.OBJ_BLOB, fileContents); inserter.flush(); return objectId; } finally { inserter.release(); } }
From source file:org.eclipse.egit.ui.internal.actions.CompareWithIndexActionHandler.java
License:Open Source License
private ITypedElement getHeadTypedElement(final IFile baseFile) throws IOException { final RepositoryMapping mapping = RepositoryMapping.getMapping(baseFile.getProject()); final Repository repository = mapping.getRepository(); final String gitPath = mapping.getRepoRelativePath(baseFile); DirCache dc = repository.lockDirCache(); final DirCacheEntry entry = dc.getEntry(gitPath); dc.unlock();//from w w w . j av a 2s. c om if (entry == null) { // the file cannot be found in the index return new GitCompareFileRevisionEditorInput.EmptyTypedElement( NLS.bind(UIText.CompareWithIndexAction_FileNotInIndex, baseFile.getName())); } IFileRevision nextFile = GitFileRevision.inIndex(repository, gitPath); final EditableRevision next = new EditableRevision(nextFile); IContentChangeListener listener = new IContentChangeListener() { public void contentChanged(IContentChangeNotifier source) { final byte[] newContent = next.getModifiedContent(); DirCache cache = null; try { cache = repository.lockDirCache(); DirCacheEditor editor = cache.editor(); editor.add(new PathEdit(gitPath) { @Override public void apply(DirCacheEntry ent) { ent.copyMetaData(entry); ObjectInserter inserter = repository.newObjectInserter(); ent.copyMetaData(entry); ent.setLength(newContent.length); ent.setLastModified(System.currentTimeMillis()); InputStream in = new ByteArrayInputStream(newContent); try { ent.setObjectId(inserter.insert(Constants.OBJ_BLOB, newContent.length, in)); inserter.flush(); } catch (IOException ex) { throw new RuntimeException(ex); } finally { try { in.close(); } catch (IOException e) { // ignore here } } } }); try { editor.commit(); } catch (RuntimeException e) { if (e.getCause() instanceof IOException) throw (IOException) e.getCause(); else throw e; } } catch (IOException e) { Activator.handleError(UIText.CompareWithIndexAction_errorOnAddToIndex, e, true); } finally { if (cache != null) cache.unlock(); } } }; next.addContentChangeListener(listener); return next; }
From source file:org.eclipse.egit.ui.internal.commit.RepositoryCommitNote.java
License:Open Source License
/** * Get note text. This method open and read the note blob each time it is * called./* w w w . ja v a 2s. c om*/ * * @return note text or empty string if lookup failed. */ public String getNoteText() { try { ObjectLoader loader = commit.getRepository().open(note.getData(), Constants.OBJ_BLOB); byte[] contents; if (loader.isLarge()) contents = IO.readWholeStream(loader.openStream(), (int) loader.getSize()).array(); else contents = loader.getCachedBytes(); return new String(contents); } catch (IOException e) { Activator.logError("Error loading note text", e); //$NON-NLS-1$ } return ""; //$NON-NLS-1$ }
From source file:org.eclipse.egit.ui.internal.components.RefContentProposal.java
License:Open Source License
public String getDescription() { if (objectId == null) return null; ObjectReader reader = db.newObjectReader(); try {/*w ww . j a v a 2s. c om*/ final ObjectLoader loader = reader.open(objectId); final StringBuilder sb = new StringBuilder(); sb.append(refName); sb.append('\n'); sb.append(reader.abbreviate(objectId).name()); sb.append(" - "); //$NON-NLS-1$ switch (loader.getType()) { case Constants.OBJ_COMMIT: RevCommit c = new RevWalk(db).parseCommit(objectId); appendObjectSummary(sb, UIText.RefContentProposal_commit, c.getAuthorIdent(), c.getFullMessage()); break; case Constants.OBJ_TAG: RevWalk walk = new RevWalk(db); RevTag t = walk.parseTag(objectId); appendObjectSummary(sb, UIText.RefContentProposal_tag, t.getTaggerIdent(), t.getFullMessage()); break; case Constants.OBJ_TREE: sb.append(UIText.RefContentProposal_tree); break; case Constants.OBJ_BLOB: sb.append(UIText.RefContentProposal_blob); break; default: sb.append(UIText.RefContentProposal_unknownObject); } return sb.toString(); } catch (IOException e) { Activator.logError(NLS.bind(UIText.RefContentProposal_errorReadingObject, objectId), e); return null; } finally { reader.release(); } }
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;// www .ja va 2 s . co 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.history.FileDiff.java
License:Open Source License
private RawText getRawText(ObjectId id, ObjectReader reader) throws IOException { if (id.equals(ObjectId.zeroId())) return new RawText(new byte[] {}); ObjectLoader ldr = reader.open(id, Constants.OBJ_BLOB); return new RawText(ldr.getCachedBytes(Integer.MAX_VALUE)); }
From source file:org.eclipse.egit.ui.internal.synchronize.mapping.GitTreeTraversal.java
License:Open Source License
private static IResource[] getResourcesImpl(Repository repo, AnyObjectId baseId, AnyObjectId remoteId, IPath path) {//from ww w . j a v a 2s.c o m if (remoteId.equals(zeroId())) return new IResource[0]; TreeWalk tw = new TreeWalk(repo); List<IResource> result = new ArrayList<IResource>(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); tw.reset(); tw.setRecursive(false); tw.setFilter(TreeFilter.ANY_DIFF); try { tw.addTree(new FileTreeIterator(repo)); if (!baseId.equals(zeroId())) tw.addTree(baseId); int actualNth = tw.addTree(remoteId); while (tw.next()) { int objectType = tw.getFileMode(actualNth).getObjectType(); IPath childPath = path.append(tw.getNameString()); IResource resource = null; if (objectType == Constants.OBJ_BLOB) resource = root.getFileForLocation(childPath); else if (objectType == Constants.OBJ_TREE) resource = root.getContainerForLocation(childPath); if (resource != null) result.add(resource); } } catch (IOException e) { Activator.logError(e.getMessage(), e); } return result.toArray(new IResource[result.size()]); }