|
|
@ -72,7 +72,6 @@ import org.eclipse.jgit.ignore.IgnoreRule; |
|
|
|
import org.eclipse.jgit.internal.JGitText; |
|
|
|
import org.eclipse.jgit.internal.JGitText; |
|
|
|
import org.eclipse.jgit.lib.Constants; |
|
|
|
import org.eclipse.jgit.lib.Constants; |
|
|
|
import org.eclipse.jgit.lib.CoreConfig; |
|
|
|
import org.eclipse.jgit.lib.CoreConfig; |
|
|
|
import org.eclipse.jgit.lib.CoreConfig.AutoCRLF; |
|
|
|
|
|
|
|
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.Repository; |
|
|
|
import org.eclipse.jgit.lib.Repository; |
|
|
@ -129,6 +128,9 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { |
|
|
|
/** Repository that is the root level being iterated over */ |
|
|
|
/** Repository that is the root level being iterated over */ |
|
|
|
protected Repository repository; |
|
|
|
protected Repository repository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Cached canonical length, initialized from {@link #idBuffer()} */ |
|
|
|
|
|
|
|
private long canonLen = -1; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new iterator with no parent. |
|
|
|
* Create a new iterator with no parent. |
|
|
|
* |
|
|
|
* |
|
|
@ -320,9 +322,24 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { |
|
|
|
state.initializeDigestAndReadBuffer(); |
|
|
|
state.initializeDigestAndReadBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
final long len = e.getLength(); |
|
|
|
final long len = e.getLength(); |
|
|
|
if (!mightNeedCleaning()) |
|
|
|
InputStream filteredIs = possiblyFilteredInputStream(e, is, len); |
|
|
|
return computeHash(is, len); |
|
|
|
return computeHash(filteredIs, canonLen); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
safeClose(is); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (IOException err) { |
|
|
|
|
|
|
|
// Can't read the file? Don't report the failure either.
|
|
|
|
|
|
|
|
return zeroid; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private InputStream possiblyFilteredInputStream(final Entry e, |
|
|
|
|
|
|
|
final InputStream is, final long len) throws IOException { |
|
|
|
|
|
|
|
InputStream filteredIs; |
|
|
|
|
|
|
|
if (!mightNeedCleaning()) { |
|
|
|
|
|
|
|
filteredIs = is; |
|
|
|
|
|
|
|
canonLen = len; |
|
|
|
|
|
|
|
} else { |
|
|
|
if (len <= MAXIMUM_FILE_SIZE_TO_READ_FULLY) { |
|
|
|
if (len <= MAXIMUM_FILE_SIZE_TO_READ_FULLY) { |
|
|
|
ByteBuffer rawbuf = IO.readWholeStream(is, (int) len); |
|
|
|
ByteBuffer rawbuf = IO.readWholeStream(is, (int) len); |
|
|
|
byte[] raw = rawbuf.array(); |
|
|
|
byte[] raw = rawbuf.array(); |
|
|
@ -332,29 +349,26 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { |
|
|
|
raw = rawbuf.array(); |
|
|
|
raw = rawbuf.array(); |
|
|
|
n = rawbuf.limit(); |
|
|
|
n = rawbuf.limit(); |
|
|
|
} |
|
|
|
} |
|
|
|
return computeHash(new ByteArrayInputStream(raw, 0, n), n); |
|
|
|
filteredIs = new ByteArrayInputStream(raw, 0, n); |
|
|
|
} |
|
|
|
canonLen = n; |
|
|
|
|
|
|
|
} else { |
|
|
|
if (isBinary(e)) |
|
|
|
if (isBinary(e)) { |
|
|
|
return computeHash(is, len); |
|
|
|
filteredIs = is; |
|
|
|
|
|
|
|
canonLen = len; |
|
|
|
final long canonLen; |
|
|
|
} else { |
|
|
|
final InputStream lenIs = filterClean(e.openInputStream()); |
|
|
|
final InputStream lenIs = filterClean(e |
|
|
|
|
|
|
|
.openInputStream()); |
|
|
|
try { |
|
|
|
try { |
|
|
|
canonLen = computeLength(lenIs); |
|
|
|
canonLen = computeLength(lenIs); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
safeClose(lenIs); |
|
|
|
safeClose(lenIs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
filteredIs = filterClean(is); |
|
|
|
return computeHash(filterClean(is), canonLen); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
safeClose(is); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (IOException err) { |
|
|
|
|
|
|
|
// Can't read the file? Don't report the failure either.
|
|
|
|
|
|
|
|
return zeroid; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return filteredIs; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void safeClose(final InputStream in) { |
|
|
|
private static void safeClose(final InputStream in) { |
|
|
|
try { |
|
|
|
try { |
|
|
@ -441,9 +455,11 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void next(final int delta) throws CorruptObjectException { |
|
|
|
public void next(final int delta) throws CorruptObjectException { |
|
|
|
ptr += delta; |
|
|
|
ptr += delta; |
|
|
|
if (!eof()) |
|
|
|
if (!eof()) { |
|
|
|
|
|
|
|
canonLen = -1; |
|
|
|
parseEntry(); |
|
|
|
parseEntry(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void back(final int delta) throws CorruptObjectException { |
|
|
|
public void back(final int delta) throws CorruptObjectException { |
|
|
@ -462,7 +478,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the byte length of this entry. |
|
|
|
* Get the raw byte length of this entry. |
|
|
|
* |
|
|
|
* |
|
|
|
* @return size of this file, in bytes. |
|
|
|
* @return size of this file, in bytes. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -470,6 +486,29 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { |
|
|
|
return current().getLength(); |
|
|
|
return current().getLength(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Get the filtered input length of this entry |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return size of the content, in bytes |
|
|
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public long getEntryContentLength() throws IOException { |
|
|
|
|
|
|
|
if (canonLen == -1) { |
|
|
|
|
|
|
|
long rawLen = getEntryLength(); |
|
|
|
|
|
|
|
if (rawLen == 0) |
|
|
|
|
|
|
|
canonLen = 0; |
|
|
|
|
|
|
|
InputStream is = current().openInputStream(); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// canonLen gets updated here
|
|
|
|
|
|
|
|
possiblyFilteredInputStream(current(), is, current() |
|
|
|
|
|
|
|
.getLength()); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
safeClose(is); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return canonLen; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the last modified time of this entry. |
|
|
|
* Get the last modified time of this entry. |
|
|
|
* |
|
|
|
* |
|
|
@ -498,12 +537,10 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public InputStream openEntryStream() throws IOException { |
|
|
|
public InputStream openEntryStream() throws IOException { |
|
|
|
InputStream rawis = current().openInputStream(); |
|
|
|
InputStream rawis = current().openInputStream(); |
|
|
|
InputStream is; |
|
|
|
if (mightNeedCleaning()) |
|
|
|
if (getOptions().getAutoCRLF() != AutoCRLF.FALSE) |
|
|
|
return filterClean(rawis); |
|
|
|
is = new EolCanonicalizingInputStream(rawis, true); |
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
is = rawis; |
|
|
|
return rawis; |
|
|
|
return is; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|