Java Code Examples for org.eclipse.jgit.dircache.DirCacheEntry#setLength()
The following examples show how to use
org.eclipse.jgit.dircache.DirCacheEntry#setLength() .
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: ResolveMerger.java From onedev with MIT License | 5 votes |
/** * adds a new path with the specified stage to the index builder * * @param path * @param p * @param stage * @param lastMod * @param len * @return the entry which was added to the index */ private DirCacheEntry add(byte[] path, CanonicalTreeParser p, int stage, Instant lastMod, long len) { if (p != null && !p.getEntryFileMode().equals(FileMode.TREE)) { DirCacheEntry e = new DirCacheEntry(path, stage); e.setFileMode(p.getEntryFileMode()); e.setObjectId(p.getEntryObjectId()); e.setLastModified(lastMod); e.setLength(len); builder.add(e); return e; } return null; }
Example 2
Source File: ResolveMerger.java From onedev with MIT License | 5 votes |
/** * adds a entry to the index builder which is a copy of the specified * DirCacheEntry * * @param e * the entry which should be copied * * @return the entry which was added to the index */ private DirCacheEntry keep(DirCacheEntry e) { DirCacheEntry newEntry = new DirCacheEntry(e.getRawPath(), e.getStage()); newEntry.setFileMode(e.getFileMode()); newEntry.setObjectId(e.getObjectId()); newEntry.setLastModified(e.getLastModifiedInstant()); newEntry.setLength(e.getLength()); builder.add(newEntry); return newEntry; }
Example 3
Source File: ResetTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testResetConflict () throws Exception { File file = new File(workDir, "file"); write(file, "init"); File[] files = new File[] { file }; add(files); commit(files); DirCache index = repository.lockDirCache(); DirCacheBuilder builder = index.builder(); DirCacheEntry e = index.getEntry(file.getName()); DirCacheEntry e1 = new DirCacheEntry(file.getName(), 1); e1.setCreationTime(e.getCreationTime()); e1.setFileMode(e.getFileMode()); e1.setLastModified(e.getLastModified()); e1.setLength(e.getLength()); e1.setObjectId(e.getObjectId()); builder.add(e1); builder.finish(); builder.commit(); GitClient client = getClient(workDir); Map<File, GitStatus> status = client.getStatus(files, NULL_PROGRESS_MONITOR); assertTrue(status.get(file).isConflict()); assertEquals(GitConflictDescriptor.Type.BOTH_DELETED, status.get(file).getConflictDescriptor().getType()); client.reset(files, "HEAD", true, NULL_PROGRESS_MONITOR); status = client.getStatus(files, NULL_PROGRESS_MONITOR); assertFalse(status.get(file).isConflict()); }
Example 4
Source File: ResolveMerger.java From onedev with MIT License | 4 votes |
/** * Updates the index after a content merge has happened. If no conflict has * occurred this includes persisting the merged content to the object * database. In case of conflicts this method takes care to write the * correct stages to the index. * * @param base * @param ours * @param theirs * @param result * @param attributes * @throws FileNotFoundException * @throws IOException */ private void updateIndex(CanonicalTreeParser base, CanonicalTreeParser ours, CanonicalTreeParser theirs, MergeResult<RawText> result, Attributes attributes) throws FileNotFoundException, IOException { TemporaryBuffer rawMerged = null; try { rawMerged = doMerge(result); File mergedFile = inCore ? null : writeMergedFile(rawMerged, attributes); if (result.containsConflicts()) { // A conflict occurred, the file will contain conflict markers // the index will be populated with the three stages and the // workdir (if used) contains the halfway merged content. add(tw.getRawPath(), base, DirCacheEntry.STAGE_1, EPOCH, 0); add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2, EPOCH, 0); add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, EPOCH, 0); mergeResults.put(tw.getPathString(), result); return; } // No conflict occurred, the file will contain fully merged content. // The index will be populated with the new merged version. DirCacheEntry dce = new DirCacheEntry(tw.getPathString()); // Set the mode for the new content. Fall back to REGULAR_FILE if // we can't merge modes of OURS and THEIRS. int newMode = mergeFileModes(tw.getRawMode(0), tw.getRawMode(1), tw.getRawMode(2)); dce.setFileMode(newMode == FileMode.MISSING.getBits() ? FileMode.REGULAR_FILE : FileMode.fromBits(newMode)); if (mergedFile != null) { dce.setLastModified( nonNullRepo().getFS().lastModifiedInstant(mergedFile)); dce.setLength((int) mergedFile.length()); } dce.setObjectId(insertMergeResult(rawMerged, attributes)); builder.add(dce); } finally { if (rawMerged != null) { rawMerged.destroy(); } } }
Example 5
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() + "'"); } }