# HG changeset patch # User Artem Tikhomirov # Date 1296787029 -3600 # Node ID b1d6208fb5178552727a86f550fd1ab340eddefa # Parent b19f0ac5ee627ebf99435f85c1990740869fd9bd Conditionally apply filters to file content diff -r b19f0ac5ee62 -r b1d6208fb517 src/org/tmatesoft/hg/core/CatCommand.java --- a/src/org/tmatesoft/hg/core/CatCommand.java Fri Feb 04 03:23:47 2011 +0100 +++ b/src/org/tmatesoft/hg/core/CatCommand.java Fri Feb 04 03:37:09 2011 +0100 @@ -80,6 +80,6 @@ } else { revToExtract = localRevision; } - dataFile.content(revToExtract, sink); + dataFile.content(revToExtract, sink, true); } } diff -r b19f0ac5ee62 -r b1d6208fb517 src/org/tmatesoft/hg/internal/KeywordFilter.java --- a/src/org/tmatesoft/hg/internal/KeywordFilter.java Fri Feb 04 03:23:47 2011 +0100 +++ b/src/org/tmatesoft/hg/internal/KeywordFilter.java Fri Feb 04 03:37:09 2011 +0100 @@ -115,7 +115,7 @@ // not to run into such situation throw new IllegalStateException("Try src buffer of a greater size"); } - rv = ByteBuffer.allocate(keywordStart - x); + rv = ByteBuffer.allocate(keywordStart - copyFrom); } // copy all from source till latest possible kw start copySlice(src, copyFrom, keywordStart, rv); diff -r b19f0ac5ee62 -r b1d6208fb517 src/org/tmatesoft/hg/repo/HgDataFile.java --- a/src/org/tmatesoft/hg/repo/HgDataFile.java Fri Feb 04 03:23:47 2011 +0100 +++ b/src/org/tmatesoft/hg/repo/HgDataFile.java Fri Feb 04 03:37:09 2011 +0100 @@ -25,6 +25,7 @@ import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.core.Path; +import org.tmatesoft.hg.internal.FilterByteChannel; import org.tmatesoft.hg.internal.RevlogStream; import org.tmatesoft.hg.util.ByteChannel; @@ -73,15 +74,18 @@ return content(TIP); } - public void content(int revision, ByteChannel sink) throws /*TODO typed*/Exception { + /*XXX not sure applyFilters is the best way to do, perhaps, callers shall add filters themselves?*/ + public void content(int revision, ByteChannel sink, boolean applyFilters) throws /*TODO typed*/Exception { byte[] content = content(revision); ByteBuffer buf = ByteBuffer.allocate(512); int left = content.length; int offset = 0; + ByteChannel _sink = applyFilters ? new FilterByteChannel(sink, getRepo().getFiltersFromRepoToWorkingDir(getPath())) : sink; do { buf.put(content, offset, Math.min(left, buf.remaining())); buf.flip(); - int consumed = sink.write(buf); + // XXX I may not rely on returned number of bytes but track change in buf position instead. + int consumed = _sink.write(buf); buf.compact(); offset += consumed; left -= consumed; diff -r b19f0ac5ee62 -r b1d6208fb517 test/org/tmatesoft/hg/test/TestByteChannel.java --- a/test/org/tmatesoft/hg/test/TestByteChannel.java Fri Feb 04 03:23:47 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestByteChannel.java Fri Feb 04 03:37:09 2011 +0100 @@ -33,7 +33,7 @@ public static void main(String[] args) throws Exception { RepositoryFacade rf = new RepositoryFacade(); rf.init(); - HgDataFile file = rf.getRepository().getFileNode("TODO"); + HgDataFile file = rf.getRepository().getFileNode("src/org/tmatesoft/hg/internal/KeywordFilter.java"); for (int i = file.getRevisionCount() - 1; i >= 0; i--) { System.out.print("Content for revision:" + i); compareContent(file, i); @@ -45,7 +45,7 @@ private static void compareContent(HgDataFile file, int rev) throws Exception { byte[] oldAccess = file.content(rev); ByteArrayChannel ch = new ByteArrayChannel(); - file.content(rev, ch); + file.content(rev, ch, false); byte[] newAccess = ch.toArray(); Assert.assertArrayEquals(oldAccess, newAccess); // don't trust anyone (even JUnit)