aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2014-11-24 20:05:34 -0800
committerShawn Pearce <sop@google.com>2014-11-25 10:21:48 -0800
commitf31323745f90aeb8f0b9bd0df4248363fc284bfe (patch)
treebbadcc9e5827f9d1d96e5f86128ef9cf852d2f5c
parent7865d7100e2a5f9d02f6679daada0c64ae14935f (diff)
downloadjgit-f31323745f90aeb8f0b9bd0df4248363fc284bfe.tar.gz
jgit-f31323745f90aeb8f0b9bd0df4248363fc284bfe.zip
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
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java25
2 files changed, 16 insertions, 11 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
index 53d672d7f3..7f58a1cbed 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
@@ -213,7 +213,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
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);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
index 645de2704e..98a1c8ca4b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
@@ -607,7 +607,8 @@ public class DirCache {
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 class DirCache {
}
}
- 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,14 +671,18 @@ public class DirCache {
}
if (writeTree) {
- final TemporaryBuffer bb = new TemporaryBuffer.LocalFile();
- tree.write(tmp, bb);
- bb.close();
-
- NB.encodeInt32(tmp, 0, EXT_TREE);
- NB.encodeInt32(tmp, 4, (int) bb.length());
- dos.write(tmp, 0, 8);
- bb.writeTo(dos, null);
+ TemporaryBuffer bb = new TemporaryBuffer.LocalFile(dir, 5 << 20);
+ try {
+ tree.write(tmp, bb);
+ bb.close();
+
+ NB.encodeInt32(tmp, 0, EXT_TREE);
+ 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);