Browse Source

Fix checking out large files

DirCacheCheckout needs to use ObjectLoader.copyTo to avoid loading the
complete content of a large file into the JVM heap.

Bug: 321097
Change-Id: I967590b6f233fd1c83d873075db01d653208b3b9
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
CC: Chris Aniszczyk <caniszczyk@gmail.com>
CC: Christian Halstrick <christian.halstrick@sap.com>
stable-0.10
Shawn O. Pearce 14 years ago
parent
commit
61db0e4787
  1. 17
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java

17
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java vendored

@ -45,8 +45,6 @@ package org.eclipse.jgit.dircache;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -59,7 +57,6 @@ import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.IndexWriteException; import org.eclipse.jgit.errors.IndexWriteException;
import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
@ -836,21 +833,11 @@ public class DirCacheCheckout {
public static void checkoutEntry(final Repository repo, File f, DirCacheEntry entry, public static void checkoutEntry(final Repository repo, File f, DirCacheEntry entry,
boolean config_filemode) throws IOException { boolean config_filemode) throws IOException {
ObjectLoader ol = repo.open(entry.getObjectId()); ObjectLoader ol = repo.open(entry.getObjectId());
if (ol == null)
throw new MissingObjectException(entry.getObjectId(),
Constants.TYPE_BLOB);
byte[] bytes = ol.getCachedBytes();
File parentDir = f.getParentFile(); File parentDir = f.getParentFile();
File tmpFile = File.createTempFile("._" + f.getName(), null, parentDir); File tmpFile = File.createTempFile("._" + f.getName(), null, parentDir);
FileChannel channel = new FileOutputStream(tmpFile).getChannel(); FileOutputStream channel = new FileOutputStream(tmpFile);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
try { try {
int j = channel.write(buffer); ol.copyTo(channel);
if (j != bytes.length)
throw new IOException(MessageFormat.format(
JGitText.get().couldNotWriteFile, tmpFile));
} finally { } finally {
channel.close(); channel.close();
} }

Loading…
Cancel
Save