Reuse Merger's ObjectReader from ResolveMerger

The base Merger class already has a single ObjectReader instance that
it handles releasing as necessary, so creating new readers is not
necessary.

Change-Id: I990ec43af7df448c7825fc1b10e62eadaa3e0c2a
This commit is contained in:
Dave Borowitz 2013-05-01 15:47:23 -07:00 committed by Shawn Pearce
parent 06ab442b05
commit e06082c171
1 changed files with 19 additions and 26 deletions

View File

@ -81,7 +81,6 @@
import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.ConfigConstants;
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.ObjectReader;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.treewalk.AbstractTreeIterator; import org.eclipse.jgit.treewalk.AbstractTreeIterator;
@ -309,29 +308,24 @@ protected boolean mergeImpl() throws IOException {
} }
private void checkout() throws NoWorkTreeException, IOException { private void checkout() throws NoWorkTreeException, IOException {
ObjectReader r = db.getObjectDatabase().newReader(); for (Map.Entry<String, DirCacheEntry> entry : toBeCheckedOut
try { .entrySet()) {
for (Map.Entry<String, DirCacheEntry> entry : toBeCheckedOut File f = new File(db.getWorkTree(), entry.getKey());
.entrySet()) { createDir(f.getParentFile());
File f = new File(db.getWorkTree(), entry.getKey()); DirCacheCheckout.checkoutEntry(db, f, entry.getValue(), reader);
createDir(f.getParentFile()); modifiedFiles.add(entry.getKey());
DirCacheCheckout.checkoutEntry(db, f, entry.getValue(), r); }
modifiedFiles.add(entry.getKey()); // Iterate in reverse so that "folder/file" is deleted before
} // "folder". Otherwise this could result in a failing path because
// Iterate in reverse so that "folder/file" is deleted before // of a non-empty directory, for which delete() would fail.
// "folder". Otherwise this could result in a failing path because for (int i = toBeDeleted.size() - 1; i >= 0; i--) {
// of a non-empty directory, for which delete() would fail. String fileName = toBeDeleted.get(i);
for (int i = toBeDeleted.size() - 1; i >= 0; i--) { File f = new File(db.getWorkTree(), fileName);
String fileName = toBeDeleted.get(i); if (!f.delete())
File f = new File(db.getWorkTree(), fileName); if (!f.isDirectory())
if (!f.delete()) failingPaths.put(fileName,
if (!f.isDirectory()) MergeFailureReason.COULD_NOT_DELETE);
failingPaths.put(fileName, modifiedFiles.add(fileName);
MergeFailureReason.COULD_NOT_DELETE);
modifiedFiles.add(fileName);
}
} finally {
r.release();
} }
} }
@ -368,7 +362,6 @@ protected void cleanUp() throws NoWorkTreeException,
} }
DirCache dc = db.readDirCache(); DirCache dc = db.readDirCache();
ObjectReader or = db.getObjectDatabase().newReader();
Iterator<String> mpathsIt=modifiedFiles.iterator(); Iterator<String> mpathsIt=modifiedFiles.iterator();
while(mpathsIt.hasNext()) { while(mpathsIt.hasNext()) {
String mpath=mpathsIt.next(); String mpath=mpathsIt.next();
@ -378,7 +371,7 @@ protected void cleanUp() throws NoWorkTreeException,
FileOutputStream fos = new FileOutputStream(new File( FileOutputStream fos = new FileOutputStream(new File(
db.getWorkTree(), mpath)); db.getWorkTree(), mpath));
try { try {
or.open(entry.getObjectId()).copyTo(fos); reader.open(entry.getObjectId()).copyTo(fos);
} finally { } finally {
fos.close(); fos.close();
} }