Mercurial > jhg
diff 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 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/FNCacheFile.java Mon Feb 25 18:41:44 2013 +0100 +++ b/src/org/tmatesoft/hg/internal/FNCacheFile.java Mon Feb 25 19:48:20 2013 +0100 @@ -21,27 +21,35 @@ import java.io.IOException; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.List; import org.tmatesoft.hg.util.Path; /** + * Append-only fncache support + * * <blockquote> * 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). * </blockquote> * @see http://mercurial.selenic.com/wiki/fncacheRepoFormat + * + * * @author Artem Tikhomirov * @author TMate Software Ltd. */ public class FNCacheFile { private final Internals repo; - private final ArrayList<Path> files; +// private final List<Path> files; + private List<Path> added; public FNCacheFile(Internals internalRepo) { repo = internalRepo; - files = new ArrayList<Path>(); +// files = new ArrayList<Path>(); } + /* + * For append-only option, we don't care reading the original content public void read(Path.Source pathFactory) throws IOException { File f = fncacheFile(); files.clear(); @@ -52,20 +60,22 @@ // names in fncache are in local encoding, shall translate to unicode new LineReader(f, repo.getSessionContext().getLog(), repo.getFilenameEncoding()).read(new LineReader.SimpleLineCollector(), entries); for (String e : entries) { + // FIXME plain wrong, need either to decode paths and strip off .i/.d or (if keep names as is) change write() files.add(pathFactory.path(e)); } } + */ public void write() throws IOException { - if (files.isEmpty()) { + if (added == null || added.isEmpty()) { return; } File f = fncacheFile(); f.getParentFile().mkdirs(); final Charset filenameEncoding = repo.getFilenameEncoding(); - FileOutputStream fncacheFile = new FileOutputStream(f); - for (Path p : files) { - 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? + FileOutputStream fncacheFile = new FileOutputStream(f, true); + for (Path p : added) { + String s = "data/" + p.toString() + ".i"; // TODO post-1.0 this is plain wrong. (a) need .d files, too; (b) what about dh/ location? fncacheFile.write(s.getBytes(filenameEncoding)); fncacheFile.write(0x0A); // http://mercurial.selenic.com/wiki/fncacheRepoFormat } @@ -73,7 +83,10 @@ } public void add(Path p) { - files.add(p); + if (added == null) { + added = new ArrayList<Path>(); + } + added.add(p); } private File fncacheFile() {