Use copyTo during checkout of files to working tree
This way we can stream a large file through memory, rather than loading the entire thing into a single contiguous byte array. Change-Id: I3ada2856af2bf518f072edec242667a486fb0df1 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
a0fd06e5c2
commit
d04b7972d8
|
@ -874,16 +874,15 @@ public void checkout(File wd) throws IOException {
|
||||||
*/
|
*/
|
||||||
public void checkoutEntry(File wd, Entry e) throws IOException {
|
public void checkoutEntry(File wd, Entry e) throws IOException {
|
||||||
ObjectLoader ol = db.open(e.sha1, Constants.OBJ_BLOB);
|
ObjectLoader ol = db.open(e.sha1, Constants.OBJ_BLOB);
|
||||||
byte[] bytes = ol.getBytes();
|
|
||||||
File file = new File(wd, e.getName());
|
File file = new File(wd, e.getName());
|
||||||
file.delete();
|
file.delete();
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
FileChannel channel = new FileOutputStream(file).getChannel();
|
FileOutputStream dst = new FileOutputStream(file);
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
try {
|
||||||
int j = channel.write(buffer);
|
ol.copyTo(dst);
|
||||||
if (j != bytes.length)
|
} finally {
|
||||||
throw new IOException(MessageFormat.format(JGitText.get().couldNotWriteFile, file));
|
dst.close();
|
||||||
channel.close();
|
}
|
||||||
if (config_filemode() && File_hasExecute()) {
|
if (config_filemode() && File_hasExecute()) {
|
||||||
if (FileMode.EXECUTABLE_FILE.equals(e.mode)) {
|
if (FileMode.EXECUTABLE_FILE.equals(e.mode)) {
|
||||||
if (!File_canExecute(file))
|
if (!File_canExecute(file))
|
||||||
|
|
Loading…
Reference in New Issue