Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/FNCacheFile.java @ 705:b4242b7e7dfe
Merge command: implement conflict resolution alternatives
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 15 Aug 2013 18:43:50 +0200 |
parents | fba85bc1dfb8 |
children |
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.util.ArrayList; |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
539
diff
changeset
|
28 import java.util.List; |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
30 import org.tmatesoft.hg.core.HgIOException; |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.util.Path; |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 /** |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
539
diff
changeset
|
34 * Append-only fncache support |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
539
diff
changeset
|
35 * |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * <blockquote> |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * 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
|
38 * </blockquote> |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 * @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
|
40 * |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
539
diff
changeset
|
41 * |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 * @author Artem Tikhomirov |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 * @author TMate Software Ltd. |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 */ |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 public class FNCacheFile { |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 private final Internals repo; |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
539
diff
changeset
|
48 // private final List<Path> files; |
616
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
49 private final List<Path> addedDotI; |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
50 private final List<Path> addedDotD; |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
51 private final FNCachePathHelper pathHelper; |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 public FNCacheFile(Internals internalRepo) { |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 repo = internalRepo; |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
539
diff
changeset
|
55 // files = new ArrayList<Path>(); |
616
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
56 pathHelper = new FNCachePathHelper(); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
57 addedDotI = new ArrayList<Path>(5); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
58 addedDotD = new ArrayList<Path>(5); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 } |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
539
diff
changeset
|
61 /* |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
539
diff
changeset
|
62 * 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
|
63 public void read(Path.Source pathFactory) throws IOException { |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 File f = fncacheFile(); |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 files.clear(); |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 if (!f.exists()) { |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 return; |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 } |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 ArrayList<String> entries = new ArrayList<String>(); |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 // 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
|
71 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
|
72 for (String e : entries) { |
624
507602cb4fb3
FIXMEs and TODOs: pay some technical debt
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
616
diff
changeset
|
73 // 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
|
74 files.add(pathFactory.path(e)); |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 } |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 } |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
539
diff
changeset
|
77 */ |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
79 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
|
80 if (addedDotI.isEmpty() && addedDotD.isEmpty()) { |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 return; |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 } |
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
|
83 File f = repo.getRepositoryFile(FNCache); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 f.getParentFile().mkdirs(); |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
664
diff
changeset
|
85 final EncodingHelper fnEncoder = repo.buildFileNameEncodingHelper(); |
616
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
86 ArrayList<CharBuffer> added = new ArrayList<CharBuffer>(); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
87 for (Path p : addedDotI) { |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
88 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
|
89 } |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
90 for (Path p : addedDotD) { |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
91 // 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
|
92 // 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
|
93 CharSequence cs = pathHelper.rewrite(p); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
94 CharBuffer cb = CharBuffer.allocate(cs.length()); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
95 cb.append(cs); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
96 cb.put(cs.length()-1, 'd'); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
97 cb.flip(); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
98 added.add(cb); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
99 } |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
100 FileOutputStream fos = null; |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
101 f = tr.prepare(f); |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
102 try { |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
103 fos = new FileOutputStream(f, true); |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
104 FileChannel fncacheFile = fos.getChannel(); |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
105 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
|
106 for (CharBuffer b : added) { |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
664
diff
changeset
|
107 fncacheFile.write(fnEncoder.toFNCache(b)); |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
108 fncacheFile.write(lf); |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
109 lf.rewind(); |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
110 } |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
111 fncacheFile.force(true); |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
112 tr.done(f); |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
113 } catch (IOException ex) { |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
114 tr.failure(f, ex); |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
115 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
|
116 } finally { |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
117 new FileUtils(repo.getLog(), this).closeQuietly(fos, f); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 } |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
119 |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 } |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 |
616
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
122 public void addIndex(Path p) { |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
123 addedDotI.add(p); |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
124 } |
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 public void addData(Path p) { |
5e0313485eef
encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
559
diff
changeset
|
127 addedDotD.add(p); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 } |
663
46b56864b483
Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
129 |
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 * 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
|
132 */ |
46b56864b483
Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
133 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
|
134 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
|
135 private FNCacheFile fncache; |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
136 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
|
137 |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
138 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
|
139 repo = internalRepo; |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
140 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
|
141 } |
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 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
|
144 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
|
145 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
|
146 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
|
147 } |
46b56864b483
Pull: phase2 - update phases from remote, fncache with added files. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
647
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 } |
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 |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
155 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
|
156 if (fncache != null) { |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
663
diff
changeset
|
157 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
|
158 } |
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 } |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 } |