comparison src/org/tmatesoft/hg/internal/WorkingDirFileWriter.java @ 526:2f9ed6bcefa2

Initial support for Revert command with accompanying minor refactoring
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 15 Jan 2013 17:07:19 +0100
parents 0be5be8d57e9
children becd2a1310a2
comparison
equal deleted inserted replaced
525:0be5be8d57e9 526:2f9ed6bcefa2
21 import java.io.IOException; 21 import java.io.IOException;
22 import java.nio.ByteBuffer; 22 import java.nio.ByteBuffer;
23 import java.nio.channels.FileChannel; 23 import java.nio.channels.FileChannel;
24 24
25 import org.tmatesoft.hg.repo.HgDataFile; 25 import org.tmatesoft.hg.repo.HgDataFile;
26 import org.tmatesoft.hg.repo.HgRepository;
27 import org.tmatesoft.hg.util.ByteChannel; 26 import org.tmatesoft.hg.util.ByteChannel;
28 import org.tmatesoft.hg.util.CancelledException; 27 import org.tmatesoft.hg.util.CancelledException;
28 import org.tmatesoft.hg.util.LogFacility.Severity;
29 import org.tmatesoft.hg.util.Path; 29 import org.tmatesoft.hg.util.Path;
30 import org.tmatesoft.hg.util.LogFacility.Severity;
31 30
32 /** 31 /**
33 * 32 *
34 * @author Artem Tikhomirov 33 * @author Artem Tikhomirov
35 * @author TMate Software Ltd. 34 * @author TMate Software Ltd.
36 */ 35 */
37 public class WorkingDirFileWriter implements ByteChannel { 36 public class WorkingDirFileWriter implements ByteChannel {
38 37
39 38
40 private final HgRepository repo; 39 private final Internals hgRepo;
41 private File dest; 40 private File dest;
42 private FileChannel destChannel; 41 private FileChannel destChannel;
43 private int totalBytesWritten; 42 private int totalBytesWritten;
44 43
45 public WorkingDirFileWriter(HgRepository hgRepo) { 44 public WorkingDirFileWriter(Internals internalRepo) {
46 repo = hgRepo; 45 hgRepo = internalRepo;
47 } 46 }
48 47
49 public void processFile(HgDataFile df, int fileRevIndex) throws IOException { 48 public void processFile(HgDataFile df, int fileRevIndex) throws IOException {
50 try { 49 try {
51 prepare(df.getPath()); 50 prepare(df.getPath());
52 df.contentWithFilters(fileRevIndex, this); 51 df.contentWithFilters(fileRevIndex, this);
53 } catch (CancelledException ex) { 52 } catch (CancelledException ex) {
54 repo.getSessionContext().getLog().dump(getClass(), Severity.Error, ex, "Our impl doesn't throw cancellation"); 53 hgRepo.getSessionContext().getLog().dump(getClass(), Severity.Error, ex, "Our impl doesn't throw cancellation");
55 } 54 }
56 finish(); 55 finish();
57 } 56 }
58 57
59 public void prepare(Path fname) throws IOException { 58 public void prepare(Path fname) throws IOException {
60 String fpath = fname.toString(); 59 String fpath = fname.toString();
61 dest = new File(repo.getWorkingDir(), fpath); 60 dest = new File(hgRepo.getRepo().getWorkingDir(), fpath);
62 if (fpath.indexOf('/') != -1) { 61 if (fpath.indexOf('/') != -1) {
63 dest.getParentFile().mkdirs(); 62 dest.getParentFile().mkdirs();
64 } 63 }
65 destChannel = new FileOutputStream(dest).getChannel(); 64 destChannel = new FileOutputStream(dest).getChannel();
66 totalBytesWritten = 0; 65 totalBytesWritten = 0;