DirCache: Buffer TREE extension to $GIT_DIR
Increase the in-memory buffer for the TREE extension to 5 MiB, and overflow to $GIT_DIR instead of /tmp. Using a larger buffer reduces the chances a repository will overflow and need to spool the extension to disk. Using $GIT_DIR allows the TREE extension contents to have the same file system protections as the final $GIT_DIR/index. Wrap the entire thing in a try/finally to ensure the temp file is deleted from disk after the block has finished using it. To avoid dangling NFS files, LocalFile.destroy() does close the local file before deleting it. Change-Id: I8f871181a4689e3ebf0cdd4fd1769333cf7546c3
This commit is contained in:
parent
7865d7100e
commit
f31323745f
|
@ -213,7 +213,7 @@ public void testReadWriteV3() throws Exception {
|
|||
assertV3TreeEntry(9, "newfile.txt", false, true, dc);
|
||||
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
dc.writeTo(bos);
|
||||
dc.writeTo(null, bos);
|
||||
final byte[] indexBytes = bos.toByteArray();
|
||||
final byte[] expectedBytes = IO.readFully(file);
|
||||
assertArrayEquals(expectedBytes, indexBytes);
|
||||
|
|
|
@ -607,7 +607,8 @@ public void write() throws IOException {
|
|||
final LockFile tmp = myLock;
|
||||
requireLocked(tmp);
|
||||
try {
|
||||
writeTo(new SafeBufferedOutputStream(tmp.getOutputStream()));
|
||||
writeTo(liveFile.getParentFile(),
|
||||
new SafeBufferedOutputStream(tmp.getOutputStream()));
|
||||
} catch (IOException err) {
|
||||
tmp.unlock();
|
||||
throw err;
|
||||
|
@ -620,7 +621,7 @@ public void write() throws IOException {
|
|||
}
|
||||
}
|
||||
|
||||
void writeTo(final OutputStream os) throws IOException {
|
||||
void writeTo(File dir, final OutputStream os) throws IOException {
|
||||
final MessageDigest foot = Constants.newMessageDigest();
|
||||
final DigestOutputStream dos = new DigestOutputStream(os, foot);
|
||||
|
||||
|
@ -670,7 +671,8 @@ void writeTo(final OutputStream os) throws IOException {
|
|||
}
|
||||
|
||||
if (writeTree) {
|
||||
final TemporaryBuffer bb = new TemporaryBuffer.LocalFile();
|
||||
TemporaryBuffer bb = new TemporaryBuffer.LocalFile(dir, 5 << 20);
|
||||
try {
|
||||
tree.write(tmp, bb);
|
||||
bb.close();
|
||||
|
||||
|
@ -678,6 +680,9 @@ void writeTo(final OutputStream os) throws IOException {
|
|||
NB.encodeInt32(tmp, 4, (int) bb.length());
|
||||
dos.write(tmp, 0, 8);
|
||||
bb.writeTo(dos, null);
|
||||
} finally {
|
||||
bb.destroy();
|
||||
}
|
||||
}
|
||||
writeIndexChecksum = foot.digest();
|
||||
os.write(writeIndexChecksum);
|
||||
|
|
Loading…
Reference in New Issue