|
|
|
@ -44,8 +44,6 @@
|
|
|
|
|
package org.eclipse.jgit.diff; |
|
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStream; |
|
|
|
@ -93,10 +91,6 @@ public abstract class ContentSource {
|
|
|
|
|
* @return a content source wrapping the iterator. |
|
|
|
|
*/ |
|
|
|
|
public static ContentSource create(WorkingTreeIterator iterator) { |
|
|
|
|
if (iterator instanceof FileTreeIterator) { |
|
|
|
|
FileTreeIterator i = (FileTreeIterator) iterator; |
|
|
|
|
return new FileSource(i.getDirectory()); |
|
|
|
|
} |
|
|
|
|
return new WorkingTreeSource(iterator); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -158,6 +152,7 @@ public abstract class ContentSource {
|
|
|
|
|
|
|
|
|
|
WorkingTreeSource(WorkingTreeIterator iterator) { |
|
|
|
|
this.tw = new TreeWalk((ObjectReader) null); |
|
|
|
|
this.tw.setRecursive(true); |
|
|
|
|
this.iterator = iterator; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -218,57 +213,6 @@ public abstract class ContentSource {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static class FileSource extends ContentSource { |
|
|
|
|
private final File root; |
|
|
|
|
|
|
|
|
|
FileSource(File root) { |
|
|
|
|
this.root = root; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public long size(String path, ObjectId id) throws IOException { |
|
|
|
|
return new File(root, path).length(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ObjectLoader open(String path, ObjectId id) throws IOException { |
|
|
|
|
final File p = new File(root, path); |
|
|
|
|
if (!p.isFile()) |
|
|
|
|
throw new FileNotFoundException(path); |
|
|
|
|
return new ObjectLoader() { |
|
|
|
|
@Override |
|
|
|
|
public long getSize() { |
|
|
|
|
return p.length(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int getType() { |
|
|
|
|
return Constants.OBJ_BLOB; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ObjectStream openStream() throws MissingObjectException, |
|
|
|
|
IOException { |
|
|
|
|
final FileInputStream in = new FileInputStream(p); |
|
|
|
|
final long sz = in.getChannel().size(); |
|
|
|
|
final int type = getType(); |
|
|
|
|
final BufferedInputStream b = new BufferedInputStream(in); |
|
|
|
|
return new ObjectStream.Filter(type, sz, b); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean isLarge() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public byte[] getCachedBytes() throws LargeObjectException { |
|
|
|
|
throw new LargeObjectException(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** A pair of sources to access the old and new sides of a DiffEntry. */ |
|
|
|
|
public static final class Pair { |
|
|
|
|
private final ContentSource oldSource; |
|
|
|
|