use of org.eclipse.jgit.treewalk.WorkingTreeOptions in project egit by eclipse.
the class CompareUtils method setIndexEntryContents.
/**
* Set contents on index entry of specified path. Line endings of contents
* are canonicalized if configured.
*
* @param repository
* @param gitPath
* @param newContent
* content with working directory line endings
*/
private static void setIndexEntryContents(final Repository repository, final String gitPath, final byte[] newContent) {
DirCache cache = null;
try {
cache = repository.lockDirCache();
DirCacheEditor editor = cache.editor();
if (newContent.length == 0) {
editor.add(new DirCacheEditor.DeletePath(gitPath));
} else {
int length;
byte[] content;
WorkingTreeOptions workingTreeOptions = repository.getConfig().get(WorkingTreeOptions.KEY);
AutoCRLF autoCRLF = workingTreeOptions.getAutoCRLF();
switch(autoCRLF) {
case FALSE:
content = newContent;
length = newContent.length;
break;
case INPUT:
case TRUE:
AutoLFInputStream in = new AutoLFInputStream(new ByteArrayInputStream(newContent), true);
// Canonicalization should lead to same or shorter length
// (CRLF to LF), so we don't have to expand the byte[].
content = new byte[newContent.length];
length = IO.readFully(in, content, 0);
break;
default:
throw new IllegalArgumentException(// $NON-NLS-1$
"Unknown autocrlf option " + autoCRLF);
}
editor.add(new DirCacheEntryEditor(gitPath, repository, content, length));
}
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();
}
}
use of org.eclipse.jgit.treewalk.WorkingTreeOptions in project egit by eclipse.
the class GitBlobStorage method open.
private InputStream open() throws IOException, CoreException, IncorrectObjectTypeException {
if (blobId == null)
return new ByteArrayInputStream(new byte[0]);
try {
WorkingTreeOptions workingTreeOptions = db.getConfig().get(WorkingTreeOptions.KEY);
final InputStream objectInputStream = db.open(blobId, Constants.OBJ_BLOB).openStream();
switch(workingTreeOptions.getAutoCRLF()) {
case INPUT:
// 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));
}
}
Aggregations