comparison src/org/tmatesoft/hg/repo/HgDataFile.java @ 121:b1d6208fb517

Conditionally apply filters to file content
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 04 Feb 2011 03:37:09 +0100
parents c0cc2535462c
children 645829962785
comparison
equal deleted inserted replaced
120:b19f0ac5ee62 121:b1d6208fb517
23 import java.util.Collection; 23 import java.util.Collection;
24 import java.util.TreeMap; 24 import java.util.TreeMap;
25 25
26 import org.tmatesoft.hg.core.Nodeid; 26 import org.tmatesoft.hg.core.Nodeid;
27 import org.tmatesoft.hg.core.Path; 27 import org.tmatesoft.hg.core.Path;
28 import org.tmatesoft.hg.internal.FilterByteChannel;
28 import org.tmatesoft.hg.internal.RevlogStream; 29 import org.tmatesoft.hg.internal.RevlogStream;
29 import org.tmatesoft.hg.util.ByteChannel; 30 import org.tmatesoft.hg.util.ByteChannel;
30 31
31 32
32 33
71 72
72 public byte[] content() { 73 public byte[] content() {
73 return content(TIP); 74 return content(TIP);
74 } 75 }
75 76
76 public void content(int revision, ByteChannel sink) throws /*TODO typed*/Exception { 77 /*XXX not sure applyFilters is the best way to do, perhaps, callers shall add filters themselves?*/
78 public void content(int revision, ByteChannel sink, boolean applyFilters) throws /*TODO typed*/Exception {
77 byte[] content = content(revision); 79 byte[] content = content(revision);
78 ByteBuffer buf = ByteBuffer.allocate(512); 80 ByteBuffer buf = ByteBuffer.allocate(512);
79 int left = content.length; 81 int left = content.length;
80 int offset = 0; 82 int offset = 0;
83 ByteChannel _sink = applyFilters ? new FilterByteChannel(sink, getRepo().getFiltersFromRepoToWorkingDir(getPath())) : sink;
81 do { 84 do {
82 buf.put(content, offset, Math.min(left, buf.remaining())); 85 buf.put(content, offset, Math.min(left, buf.remaining()));
83 buf.flip(); 86 buf.flip();
84 int consumed = sink.write(buf); 87 // XXX I may not rely on returned number of bytes but track change in buf position instead.
88 int consumed = _sink.write(buf);
85 buf.compact(); 89 buf.compact();
86 offset += consumed; 90 offset += consumed;
87 left -= consumed; 91 left -= consumed;
88 } while (left > 0); 92 } while (left > 0);
89 } 93 }