Merge "Quickfix for AutoCRLF handling"
This commit is contained in:
commit
db29665e64
|
@ -111,7 +111,7 @@ public void testAddExistingSingleFile() throws IOException, NoFilepatternExcepti
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddExistingSingleFileWithNewLine() throws IOException,
|
public void testAddExistingSingleSmallFileWithNewLine() throws IOException,
|
||||||
NoFilepatternException {
|
NoFilepatternException {
|
||||||
File file = new File(db.getWorkTree(), "a.txt");
|
File file = new File(db.getWorkTree(), "a.txt");
|
||||||
FileUtils.createNewFile(file);
|
FileUtils.createNewFile(file);
|
||||||
|
@ -134,6 +134,35 @@ public void testAddExistingSingleFileWithNewLine() throws IOException,
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddExistingSingleMediumSizeFileWithNewLine()
|
||||||
|
throws IOException, NoFilepatternException {
|
||||||
|
File file = new File(db.getWorkTree(), "a.txt");
|
||||||
|
FileUtils.createNewFile(file);
|
||||||
|
StringBuilder data = new StringBuilder();
|
||||||
|
for (int i = 0; i < 1000; ++i) {
|
||||||
|
data.append("row1\r\nrow2");
|
||||||
|
}
|
||||||
|
String crData = data.toString();
|
||||||
|
PrintWriter writer = new PrintWriter(file);
|
||||||
|
writer.print(crData);
|
||||||
|
writer.close();
|
||||||
|
String lfData = data.toString().replaceAll("\r", "");
|
||||||
|
Git git = new Git(db);
|
||||||
|
db.getConfig().setString("core", null, "autocrlf", "false");
|
||||||
|
git.add().addFilepattern("a.txt").call();
|
||||||
|
assertEquals("[a.txt, mode:100644, content:" + data + "]",
|
||||||
|
indexState(CONTENT));
|
||||||
|
db.getConfig().setString("core", null, "autocrlf", "true");
|
||||||
|
git.add().addFilepattern("a.txt").call();
|
||||||
|
assertEquals("[a.txt, mode:100644, content:" + lfData + "]",
|
||||||
|
indexState(CONTENT));
|
||||||
|
db.getConfig().setString("core", null, "autocrlf", "input");
|
||||||
|
git.add().addFilepattern("a.txt").call();
|
||||||
|
assertEquals("[a.txt, mode:100644, content:" + lfData + "]",
|
||||||
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddExistingSingleBinaryFile() throws IOException,
|
public void testAddExistingSingleBinaryFile() throws IOException,
|
||||||
NoFilepatternException {
|
NoFilepatternException {
|
||||||
|
|
|
@ -109,6 +109,29 @@ protected byte[] buffer() {
|
||||||
return tempBuffer;
|
return tempBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static private final int tempBufSize;
|
||||||
|
static {
|
||||||
|
String s = System.getProperty("jgit.tempbufmaxsize");
|
||||||
|
if (s != null)
|
||||||
|
tempBufSize = Integer.parseInt(s);
|
||||||
|
else
|
||||||
|
tempBufSize = 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param hintSize
|
||||||
|
* @return a temporary byte array for use by the caller
|
||||||
|
*/
|
||||||
|
protected byte[] buffer(long hintSize) {
|
||||||
|
if (hintSize >= tempBufSize)
|
||||||
|
tempBuffer = new byte[0];
|
||||||
|
else if (tempBuffer == null)
|
||||||
|
tempBuffer = new byte[(int) hintSize];
|
||||||
|
else if (tempBuffer.length < hintSize)
|
||||||
|
tempBuffer = new byte[(int) hintSize];
|
||||||
|
return tempBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
/** @return digest to help compute an ObjectId */
|
/** @return digest to help compute an ObjectId */
|
||||||
protected MessageDigest digest() {
|
protected MessageDigest digest() {
|
||||||
digest.reset();
|
digest.reset();
|
||||||
|
@ -172,7 +195,7 @@ public ObjectId idFor(int objectType, long length, InputStream in)
|
||||||
md.update((byte) ' ');
|
md.update((byte) ' ');
|
||||||
md.update(Constants.encodeASCII(length));
|
md.update(Constants.encodeASCII(length));
|
||||||
md.update((byte) 0);
|
md.update((byte) 0);
|
||||||
byte[] buf = buffer();
|
byte[] buf = buffer(length);
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
int n = in.read(buf, 0, (int) Math.min(length, buf.length));
|
int n = in.read(buf, 0, (int) Math.min(length, buf.length));
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
|
|
|
@ -116,7 +116,7 @@ public ObjectId insert(int type, byte[] data, int off, int len)
|
||||||
@Override
|
@Override
|
||||||
public ObjectId insert(int type, long len, InputStream in)
|
public ObjectId insert(int type, long len, InputStream in)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
byte[] buf = buffer();
|
byte[] buf = buffer(len);
|
||||||
if (len <= buf.length) {
|
if (len <= buf.length) {
|
||||||
IO.readFully(in, buf, 0, (int) len);
|
IO.readFully(in, buf, 0, (int) len);
|
||||||
return insert(type, buf, 0, (int) len);
|
return insert(type, buf, 0, (int) len);
|
||||||
|
|
|
@ -95,8 +95,8 @@ public ObjectId insert(int type, byte[] data, int off, int len)
|
||||||
@Override
|
@Override
|
||||||
public ObjectId insert(final int type, long len, final InputStream is)
|
public ObjectId insert(final int type, long len, final InputStream is)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (len <= buffer().length) {
|
byte[] buf = buffer(len);
|
||||||
byte[] buf = buffer();
|
if (len <= buf.length) {
|
||||||
int actLen = IO.readFully(is, buf, 0);
|
int actLen = IO.readFully(is, buf, 0);
|
||||||
return insert(type, buf, 0, actLen);
|
return insert(type, buf, 0, actLen);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue