Simplify implementation of WorkingTreeIterator

All the filtering in WorkingTreeIterator is for check-in, i.e., clean
filtering. The implementation was in some parts too general, passing
around an OperationType. But since it's always CHECKIN_OP, that's not
actually necessary.

Change-Id: I73f8bc059e485a073e456962868f52b3a3db4fc1
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
Thomas Wolf 2022-02-13 23:24:14 +01:00
parent d73b7cdeb4
commit 69ef598bd9
1 changed files with 16 additions and 29 deletions

View File

@ -2,7 +2,7 @@
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
* Copyright (C) 2010, Christian Halstrick <christian.halstrick@sap.com> * Copyright (C) 2010, Christian Halstrick <christian.halstrick@sap.com>
* Copyright (C) 2010, Matthias Sohn <matthias.sohn@sap.com> * Copyright (C) 2010, Matthias Sohn <matthias.sohn@sap.com>
* Copyright (C) 2012-2021, Robin Rosenberg and others * Copyright (C) 2012, 2022, Robin Rosenberg and others
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at * terms of the Eclipse Distribution License v. 1.0 which is available at
@ -387,8 +387,8 @@ private byte[] idBufferBlob(Entry e) {
state.initializeReadBuffer(); state.initializeReadBuffer();
final long len = e.getLength(); final long len = e.getLength();
InputStream filteredIs = possiblyFilteredInputStream(e, is, len, InputStream filteredIs = possiblyFilteredInputStream(e, is,
OperationType.CHECKIN_OP); len);
return computeHash(filteredIs, canonLen); return computeHash(filteredIs, canonLen);
} finally { } finally {
safeClose(is); safeClose(is);
@ -400,23 +400,18 @@ private byte[] idBufferBlob(Entry e) {
} }
private InputStream possiblyFilteredInputStream(final Entry e, private InputStream possiblyFilteredInputStream(final Entry e,
final InputStream is, final long len) throws IOException { final InputStream is, final long len)
return possiblyFilteredInputStream(e, is, len, null);
}
private InputStream possiblyFilteredInputStream(final Entry e,
final InputStream is, final long len, OperationType opType)
throws IOException { throws IOException {
if (getCleanFilterCommand() == null if (getCleanFilterCommand() == null
&& getEolStreamType(opType) == EolStreamType.DIRECT) { && getEolStreamType(
OperationType.CHECKIN_OP) == EolStreamType.DIRECT) {
canonLen = len; canonLen = len;
return is; return is;
} }
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);
rawbuf = filterClean(rawbuf.array(), rawbuf.limit(), opType); rawbuf = filterClean(rawbuf.array(), rawbuf.limit());
canonLen = rawbuf.limit(); canonLen = rawbuf.limit();
return new ByteArrayInputStream(rawbuf.array(), 0, (int) canonLen); return new ByteArrayInputStream(rawbuf.array(), 0, (int) canonLen);
} }
@ -426,14 +421,13 @@ && getEolStreamType(opType) == EolStreamType.DIRECT) {
return is; return is;
} }
final InputStream lenIs = filterClean(e.openInputStream(), final InputStream lenIs = filterClean(e.openInputStream());
opType);
try { try {
canonLen = computeLength(lenIs); canonLen = computeLength(lenIs);
} finally { } finally {
safeClose(lenIs); safeClose(lenIs);
} }
return filterClean(is, opType); return filterClean(is);
} }
private static void safeClose(InputStream in) { private static void safeClose(InputStream in) {
@ -455,23 +449,20 @@ private static boolean isBinary(Entry entry) throws IOException {
} }
} }
private ByteBuffer filterClean(byte[] src, int n, OperationType opType) private ByteBuffer filterClean(byte[] src, int n)
throws IOException { throws IOException {
InputStream in = new ByteArrayInputStream(src); InputStream in = new ByteArrayInputStream(src);
try { try {
return IO.readWholeStream(filterClean(in, opType), n); return IO.readWholeStream(filterClean(in), n);
} finally { } finally {
safeClose(in); safeClose(in);
} }
} }
private InputStream filterClean(InputStream in) throws IOException { private InputStream filterClean(InputStream in)
return filterClean(in, null);
}
private InputStream filterClean(InputStream in, OperationType opType)
throws IOException { throws IOException {
in = handleAutoCRLF(in, opType); in = EolStreamTypeUtil.wrapInputStream(in,
getEolStreamType(OperationType.CHECKIN_OP));
String filterCommand = getCleanFilterCommand(); String filterCommand = getCleanFilterCommand();
if (filterCommand != null) { if (filterCommand != null) {
if (FilterCommandRegistry.isRegistered(filterCommand)) { if (FilterCommandRegistry.isRegistered(filterCommand)) {
@ -509,11 +500,6 @@ filterCommand, getEntryPathString(),
return in; return in;
} }
private InputStream handleAutoCRLF(InputStream in, OperationType opType)
throws IOException {
return EolStreamTypeUtil.wrapInputStream(in, getEolStreamType(opType));
}
/** /**
* Returns the working tree options used by this iterator. * Returns the working tree options used by this iterator.
* *
@ -664,7 +650,8 @@ public Instant getEntryLastModifiedInstant() {
public InputStream openEntryStream() throws IOException { public InputStream openEntryStream() throws IOException {
InputStream rawis = current().openInputStream(); InputStream rawis = current().openInputStream();
if (getCleanFilterCommand() == null if (getCleanFilterCommand() == null
&& getEolStreamType() == EolStreamType.DIRECT) { && getEolStreamType(
OperationType.CHECKIN_OP) == EolStreamType.DIRECT) {
return rawis; return rawis;
} }
return filterClean(rawis); return filterClean(rawis);