org.eclipse.jgit.util.TemporaryBuffer Java Examples

The following examples show how to use org.eclipse.jgit.util.TemporaryBuffer. 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 6 votes vote down vote up
/**
 * Writes merged file content to the working tree.
 *
 * @param rawMerged
 *            the raw merged content
 * @param attributes
 *            the files .gitattributes entries
 * @return the working tree file to which the merged content was written.
 * @throws FileNotFoundException
 * @throws IOException
 */
private File writeMergedFile(TemporaryBuffer rawMerged,
		Attributes attributes)
		throws FileNotFoundException, IOException {
	File workTree = nonNullRepo().getWorkTree();
	FS fs = nonNullRepo().getFS();
	File of = new File(workTree, tw.getPathString());
	File parentFolder = of.getParentFile();
	if (!fs.exists(parentFolder)) {
		parentFolder.mkdirs();
	}
	EolStreamType streamType = EolStreamTypeUtil.detectStreamType(
			OperationType.CHECKOUT_OP, workingTreeOptions,
			attributes);
	try (OutputStream os = EolStreamTypeUtil.wrapOutputStream(
			new BufferedOutputStream(new FileOutputStream(of)),
			streamType)) {
		rawMerged.writeTo(os, null);
	}
	return of;
}
 
Example #2
Source File: ResolveMerger.java    From onedev with MIT License 6 votes vote down vote up
private TemporaryBuffer doMerge(MergeResult<RawText> result)
		throws IOException {
	TemporaryBuffer.LocalFile buf = new TemporaryBuffer.LocalFile(
			db != null ? nonNullRepo().getDirectory() : null, inCoreLimit);
	boolean success = false;
	try {
		new MergeFormatter().formatMerge(buf, result,
				Arrays.asList(commitNames), UTF_8);
		buf.close();
		success = true;
	} finally {
		if (!success) {
			buf.destroy();
		}
	}
	return buf;
}
 
Example #3
Source File: ResolveMerger.java    From onedev with MIT License 5 votes vote down vote up
private ObjectId insertMergeResult(TemporaryBuffer buf,
		Attributes attributes) throws IOException {
	InputStream in = buf.openInputStream();
	try (LfsInputStream is = LfsFactory.getInstance().applyCleanFilter(
			getRepository(), in,
			buf.length(), attributes.get(Constants.ATTR_MERGE))) {
		return getObjectInserter().insert(OBJ_BLOB, is.getLength(), is);
	}
}
 
Example #4
Source File: ResolveMerger.java    From onedev with MIT License 4 votes vote down vote up
/**
 * 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: HttpDelegatingCredentialsProvider.java    From gitflow-incremental-builder with MIT License 4 votes vote down vote up
private String bufferToString(TemporaryBuffer buffer) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    buffer.writeTo(baos, null);
    return baos.toString(Charset.defaultCharset().name());
}
 
Example #6
Source File: PreemptiveAuthHttpClientConnection.java    From git-client-plugin with MIT License 4 votes vote down vote up
public void setBuffer(TemporaryBuffer buffer) {
    this.entity = new TemporaryBufferEntity(buffer);
}
 
Example #7
Source File: PreemptiveAuthHttpClientConnection.java    From git-client-plugin with MIT License 4 votes vote down vote up
public void setFixedLengthStreamingMode(int contentLength) {
    if (entity != null)
        throw new IllegalArgumentException();
    entity = new TemporaryBufferEntity(new TemporaryBuffer.LocalFile(null));
    entity.setContentLength(contentLength);
}
 
Example #8
Source File: PreemptiveAuthHttpClientConnection.java    From git-client-plugin with MIT License 4 votes vote down vote up
public OutputStream getOutputStream() throws IOException {
    if (entity == null)
        entity = new TemporaryBufferEntity(new TemporaryBuffer.LocalFile(null));
    return entity.getBuffer();
}
 
Example #9
Source File: PreemptiveAuthHttpClientConnection.java    From git-client-plugin with MIT License 4 votes vote down vote up
public void setChunkedStreamingMode(int chunklen) {
    if (entity == null)
        entity = new TemporaryBufferEntity(new TemporaryBuffer.LocalFile(null));
    entity.setChunked(true);
}