comparison src/org/tmatesoft/hg/internal/FNCacheFile.java @ 559:6ca3d0c5b4bc

Commit: tests and fixes for defects discovered
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 25 Feb 2013 19:48:20 +0100
parents 9edfd5a223b8
children 5e0313485eef
comparison
equal deleted inserted replaced
558:154718ae23ed 559:6ca3d0c5b4bc
19 import java.io.File; 19 import java.io.File;
20 import java.io.FileOutputStream; 20 import java.io.FileOutputStream;
21 import java.io.IOException; 21 import java.io.IOException;
22 import java.nio.charset.Charset; 22 import java.nio.charset.Charset;
23 import java.util.ArrayList; 23 import java.util.ArrayList;
24 import java.util.List;
24 25
25 import org.tmatesoft.hg.util.Path; 26 import org.tmatesoft.hg.util.Path;
26 27
27 /** 28 /**
29 * Append-only fncache support
30 *
28 * <blockquote> 31 * <blockquote>
29 * The fncache file contains the paths of all filelog files in the store as encoded by mercurial.filelog.encodedir. The paths are separated by '\n' (LF). 32 * The fncache file contains the paths of all filelog files in the store as encoded by mercurial.filelog.encodedir. The paths are separated by '\n' (LF).
30 * </blockquote> 33 * </blockquote>
31 * @see http://mercurial.selenic.com/wiki/fncacheRepoFormat 34 * @see http://mercurial.selenic.com/wiki/fncacheRepoFormat
35 *
36 *
32 * @author Artem Tikhomirov 37 * @author Artem Tikhomirov
33 * @author TMate Software Ltd. 38 * @author TMate Software Ltd.
34 */ 39 */
35 public class FNCacheFile { 40 public class FNCacheFile {
36 41
37 private final Internals repo; 42 private final Internals repo;
38 private final ArrayList<Path> files; 43 // private final List<Path> files;
44 private List<Path> added;
39 45
40 public FNCacheFile(Internals internalRepo) { 46 public FNCacheFile(Internals internalRepo) {
41 repo = internalRepo; 47 repo = internalRepo;
42 files = new ArrayList<Path>(); 48 // files = new ArrayList<Path>();
43 } 49 }
44 50
51 /*
52 * For append-only option, we don't care reading the original content
45 public void read(Path.Source pathFactory) throws IOException { 53 public void read(Path.Source pathFactory) throws IOException {
46 File f = fncacheFile(); 54 File f = fncacheFile();
47 files.clear(); 55 files.clear();
48 if (!f.exists()) { 56 if (!f.exists()) {
49 return; 57 return;
50 } 58 }
51 ArrayList<String> entries = new ArrayList<String>(); 59 ArrayList<String> entries = new ArrayList<String>();
52 // names in fncache are in local encoding, shall translate to unicode 60 // names in fncache are in local encoding, shall translate to unicode
53 new LineReader(f, repo.getSessionContext().getLog(), repo.getFilenameEncoding()).read(new LineReader.SimpleLineCollector(), entries); 61 new LineReader(f, repo.getSessionContext().getLog(), repo.getFilenameEncoding()).read(new LineReader.SimpleLineCollector(), entries);
54 for (String e : entries) { 62 for (String e : entries) {
63 // FIXME plain wrong, need either to decode paths and strip off .i/.d or (if keep names as is) change write()
55 files.add(pathFactory.path(e)); 64 files.add(pathFactory.path(e));
56 } 65 }
57 } 66 }
67 */
58 68
59 public void write() throws IOException { 69 public void write() throws IOException {
60 if (files.isEmpty()) { 70 if (added == null || added.isEmpty()) {
61 return; 71 return;
62 } 72 }
63 File f = fncacheFile(); 73 File f = fncacheFile();
64 f.getParentFile().mkdirs(); 74 f.getParentFile().mkdirs();
65 final Charset filenameEncoding = repo.getFilenameEncoding(); 75 final Charset filenameEncoding = repo.getFilenameEncoding();
66 FileOutputStream fncacheFile = new FileOutputStream(f); 76 FileOutputStream fncacheFile = new FileOutputStream(f, true);
67 for (Path p : files) { 77 for (Path p : added) {
68 String s = "data/" + p.toString() + ".i"; // TODO post-1.0 this is plain wrong. (a) likely need .d files, too; (b) what about dh/ location? 78 String s = "data/" + p.toString() + ".i"; // TODO post-1.0 this is plain wrong. (a) need .d files, too; (b) what about dh/ location?
69 fncacheFile.write(s.getBytes(filenameEncoding)); 79 fncacheFile.write(s.getBytes(filenameEncoding));
70 fncacheFile.write(0x0A); // http://mercurial.selenic.com/wiki/fncacheRepoFormat 80 fncacheFile.write(0x0A); // http://mercurial.selenic.com/wiki/fncacheRepoFormat
71 } 81 }
72 fncacheFile.close(); 82 fncacheFile.close();
73 } 83 }
74 84
75 public void add(Path p) { 85 public void add(Path p) {
76 files.add(p); 86 if (added == null) {
87 added = new ArrayList<Path>();
88 }
89 added.add(p);
77 } 90 }
78 91
79 private File fncacheFile() { 92 private File fncacheFile() {
80 return repo.getFileFromStoreDir("fncache"); 93 return repo.getFileFromStoreDir("fncache");
81 } 94 }