annotate src/org/tmatesoft/hg/internal/FNCacheFile.java @ 665:dde18bc7053b v1.2m1

Test Copy-on-Write transactions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 10 Jul 2013 20:16:37 +0200
parents ae2d439fbed3
children fba85bc1dfb8
rev   line source
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.internal;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepositoryFiles.FNCache;
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
20
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.File;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.FileOutputStream;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.IOException;
616
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
24 import java.nio.ByteBuffer;
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
25 import java.nio.CharBuffer;
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
26 import java.nio.channels.FileChannel;
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.nio.charset.Charset;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import java.util.ArrayList;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
29 import java.util.List;
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
31 import org.tmatesoft.hg.core.HgIOException;
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 import org.tmatesoft.hg.util.Path;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 /**
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
35 * Append-only fncache support
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
36 *
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 * <blockquote>
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 * 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).
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 * </blockquote>
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 * @see http://mercurial.selenic.com/wiki/fncacheRepoFormat
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
41 *
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
42 *
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 * @author Artem Tikhomirov
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 * @author TMate Software Ltd.
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 */
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 public class FNCacheFile {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 private final Internals repo;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
49 // private final List<Path> files;
616
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
50 private final List<Path> addedDotI;
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
51 private final List<Path> addedDotD;
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
52 private final FNCachePathHelper pathHelper;
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 public FNCacheFile(Internals internalRepo) {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 repo = internalRepo;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
56 // files = new ArrayList<Path>();
616
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
57 pathHelper = new FNCachePathHelper();
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
58 addedDotI = new ArrayList<Path>(5);
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
59 addedDotD = new ArrayList<Path>(5);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
62 /*
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
63 * For append-only option, we don't care reading the original content
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 public void read(Path.Source pathFactory) throws IOException {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 File f = fncacheFile();
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 files.clear();
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 if (!f.exists()) {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 return;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 ArrayList<String> entries = new ArrayList<String>();
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 // names in fncache are in local encoding, shall translate to unicode
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 new LineReader(f, repo.getSessionContext().getLog(), repo.getFilenameEncoding()).read(new LineReader.SimpleLineCollector(), entries);
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 for (String e : entries) {
624
507602cb4fb3 FIXMEs and TODOs: pay some technical debt
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 616
diff changeset
74 // XXX plain wrong, need either to decode paths and strip off .i/.d or (if keep names as is) change write()
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 files.add(pathFactory.path(e));
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 }
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
78 */
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
80 public void write(Transaction tr) throws HgIOException {
616
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
81 if (addedDotI.isEmpty() && addedDotD.isEmpty()) {
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 return;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 }
647
c75297c17867 Location of repository files as enumeration, use file constants instead of plain names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
84 File f = repo.getRepositoryFile(FNCache);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 f.getParentFile().mkdirs();
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 final Charset filenameEncoding = repo.getFilenameEncoding();
616
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
87 ArrayList<CharBuffer> added = new ArrayList<CharBuffer>();
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
88 for (Path p : addedDotI) {
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
89 added.add(CharBuffer.wrap(pathHelper.rewrite(p)));
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
90 }
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
91 for (Path p : addedDotD) {
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
92 // XXX FNCachePathHelper always return name of an index file, need to change it into a name of data file,
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
93 // although the approach (to replace last char) is depressingly awful
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
94 CharSequence cs = pathHelper.rewrite(p);
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
95 CharBuffer cb = CharBuffer.allocate(cs.length());
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
96 cb.append(cs);
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
97 cb.put(cs.length()-1, 'd');
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
98 cb.flip();
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
99 added.add(cb);
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
100 }
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
101 FileOutputStream fos = null;
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
102 f = tr.prepare(f);
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
103 try {
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
104 fos = new FileOutputStream(f, true);
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
105 FileChannel fncacheFile = fos.getChannel();
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
106 ByteBuffer lf = ByteBuffer.wrap(new byte[] { 0x0A });
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
107 for (CharBuffer b : added) {
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
108 fncacheFile.write(filenameEncoding.encode(b));
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
109 fncacheFile.write(lf);
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
110 lf.rewind();
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
111 }
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
112 fncacheFile.force(true);
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
113 tr.done(f);
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
114 } catch (IOException ex) {
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
115 tr.failure(f, ex);
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
116 throw new HgIOException("Failed to write fncache", ex, f);
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
117 } finally {
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
118 new FileUtils(repo.getLog(), this).closeQuietly(fos, f);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 }
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
120
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122
616
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
123 public void addIndex(Path p) {
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
124 addedDotI.add(p);
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
125 }
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
126
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
127 public void addData(Path p) {
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 559
diff changeset
128 addedDotD.add(p);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 }
663
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
130
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
131 /**
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
132 * Register new files with fncache if one is enabled for the repo, do nothing otherwise
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
133 */
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
134 public static class Mediator {
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
135 private final Internals repo;
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
136 private FNCacheFile fncache;
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
137 private final Transaction tr;
663
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
138
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
139 public Mediator(Internals internalRepo, Transaction transaction) {
663
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
140 repo = internalRepo;
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
141 tr = transaction;
663
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
142 }
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
143
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
144 public void registerNew(Path f, RevlogStream rs) {
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
145 if (fncache != null || repo.fncacheInUse()) {
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
146 if (fncache == null) {
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
147 fncache = new FNCacheFile(repo);
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
148 }
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
149 fncache.addIndex(f);
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
150 if (!rs.isInlineData()) {
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
151 fncache.addData(f);
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
152 }
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
153 }
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
154 }
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
155
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
156 public void complete() throws HgIOException {
663
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
157 if (fncache != null) {
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 663
diff changeset
158 fncache.write(tr);
663
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
159 }
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
160 }
46b56864b483 Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 647
diff changeset
161 }
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 }