Java Code Examples for org.eclipse.jgit.dircache.DirCacheEntry#getObjectId()
The following examples show how to use
org.eclipse.jgit.dircache.DirCacheEntry#getObjectId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Index.java From orion.server with Eclipse Public License 1.0 | 5 votes |
public ObjectStream toObjectStream() throws IOException { DirCache cache = db.readDirCache(); DirCacheEntry entry = cache.getEntry(pattern); if (entry == null) { return null; } try { ObjectId blobId = entry.getObjectId(); return db.open(blobId, Constants.OBJ_BLOB).openStream(); } catch (MissingObjectException e) { return null; } }
Example 2
Source File: GitManagerImpl.java From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public ConflictFile queryConflictFile(Workspace ws, String path, boolean base64) throws Exception { GitStatus status = status(ws, ws.getRelativePath(path)); String relativePath = ws.getRelativePath(path).toString(); if (!status.equals(GitStatus.CONFLICTION)) { throw new GitOperationException(format("status of %s is not confliction", path)); } String basePath = path + CONFLIX_FILE_BASE_SUFFIX; String localPath = path + CONFLIX_FILE_LOCAL_SUFFIX; String remotePath = path + CONFLIX_FILE_REMOTE_SUFFIX; if (!ws.exists(basePath) || !ws.exists(localPath) || !ws.exists(remotePath)) { Repository repository = getRepository(ws.getSpaceKey()); DirCacheEntry[] entries = findEntrys(repository, relativePath); ObjectId local = null, remote = null, base = null; for (DirCacheEntry entry : entries) { if (entry.getStage() == DirCacheEntry.STAGE_1) base = entry.getObjectId(); else if (entry.getStage() == DirCacheEntry.STAGE_2) local = entry.getObjectId(); else if (entry.getStage() == DirCacheEntry.STAGE_3) remote = entry.getObjectId(); } generate_conflict_files(ws, base, local, remote, path); } ConflictFile response = new ConflictFile(); response.setBase(ws.read(basePath, ws.getEncoding(), base64)); response.setLocal(ws.read(localPath, ws.getEncoding(), base64)); response.setRemote(ws.read(remotePath, ws.getEncoding(), base64)); return response; }
Example 3
Source File: AddTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testAddSymlink () throws Exception { if (isWindows()) { return; } String path = "folder/file"; File f = new File(workDir, path); f.getParentFile().mkdir(); write(f, "file"); add(f); commit(f); Thread.sleep(1100); // try with commandline client File link = new File(workDir, "link"); runExternally(workDir, Arrays.asList("ln", "-s", path, link.getName())); long ts = Files.readAttributes(Paths.get(link.getAbsolutePath()), BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS).lastModifiedTime().toMillis(); runExternally(workDir, Arrays.asList("git", "add", link.getName())); DirCacheEntry e = repository.readDirCache().getEntry(link.getName()); assertEquals(FileMode.SYMLINK, e.getFileMode()); ObjectId id = e.getObjectId(); assertTrue((ts - 1000) < e.getLastModified() && (ts + 1000) > e.getLastModified()); try(ObjectReader reader = repository.getObjectDatabase().newReader()) { assertTrue(reader.has(e.getObjectId())); byte[] bytes = reader.open(e.getObjectId()).getBytes(); assertEquals(path, RawParseUtils.decode(bytes)); // now with internal File link2 = new File(workDir, "link2"); Files.createSymbolicLink(Paths.get(link2.getAbsolutePath()), Paths.get(path)); ts = Files.readAttributes(Paths.get(link2.getAbsolutePath()), BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS).lastModifiedTime().toMillis(); getClient(workDir).add(new File[]{link2}, NULL_PROGRESS_MONITOR); DirCacheEntry e2 = repository.readDirCache().getEntry(link2.getName()); assertEquals(FileMode.SYMLINK, e2.getFileMode()); assertEquals(id, e2.getObjectId()); assertEquals(0, e2.getLength()); assertTrue((ts - 1000) < e2.getLastModified() && (ts + 1000) > e2.getLastModified()); assertTrue(reader.has(e2.getObjectId())); bytes = reader.open(e2.getObjectId()).getBytes(); assertEquals(path, RawParseUtils.decode(bytes)); } }
Example 4
Source File: GitIndexEntry.java From git-code-format-maven-plugin with MIT License | 4 votes |
private void doFormat(DirCacheEntry dirCacheEntry, CodeFormatter formatter) { LineRanges lineRanges = computeLineRanges(dirCacheEntry); if (lineRanges.isAll()) { log.info("Formatting '" + dirCacheEntry.getPathString() + "'"); } else { log.info("Formatting lines " + lineRanges + " of '" + dirCacheEntry.getPathString() + "'"); } try (TemporaryFile temporaryFormattedFile = TemporaryFile.create(log, dirCacheEntry.getPathString() + ".formatted")) { ObjectId unformattedObjectId = dirCacheEntry.getObjectId(); log.debug("Unformatted object id is '" + unformattedObjectId + "'"); ObjectDatabase objectDatabase = repository.getObjectDatabase(); ObjectLoader objectLoader = objectDatabase.open(unformattedObjectId); logObjectContent(objectLoader, dirCacheEntry.getPathString() + ".unformatted"); try (InputStream content = objectLoader.openStream(); OutputStream formattedContent = temporaryFormattedFile.newOutputStream()) { formatter.format(content, lineRanges, formattedContent); } long formattedSize = temporaryFormattedFile.size(); ObjectId formattedObjectId; try (InputStream formattedContent = temporaryFormattedFile.newInputStream(); ObjectInserter objectInserter = objectDatabase.newInserter()) { formattedObjectId = objectInserter.insert(OBJ_BLOB, formattedSize, formattedContent); objectInserter.flush(); } log.debug("Formatted size is " + formattedSize); dirCacheEntry.setLength(formattedSize); log.debug("Formatted object id is '" + formattedObjectId + "'"); dirCacheEntry.setObjectId(formattedObjectId); } catch (IOException e) { throw new MavenGitCodeFormatException(e); } if (lineRanges.isAll()) { log.info("Formatted '" + dirCacheEntry.getPathString() + "'"); } else { log.info("Formatted lines " + lineRanges + " of '" + dirCacheEntry.getPathString() + "'"); } }