comparison src/org/tmatesoft/hg/internal/CommitFacility.java @ 664:ae2d439fbed3

Utilize transaction when writing fncache. Better HgIOException
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 10 Jul 2013 19:33:51 +0200
parents 4fd317a2fecf
children fba85bc1dfb8
comparison
equal deleted inserted replaced
663:46b56864b483 664:ae2d439fbed3
140 } 140 }
141 // 141 //
142 saveCommitMessage(message); 142 saveCommitMessage(message);
143 // 143 //
144 // Register new/changed 144 // Register new/changed
145 LinkedHashMap<Path, RevlogStream> newlyAddedFiles = new LinkedHashMap<Path, RevlogStream>(); 145 FNCacheFile.Mediator fncache = new FNCacheFile.Mediator(repo, transaction);
146 ArrayList<Path> touchInDirstate = new ArrayList<Path>(); 146 ArrayList<Path> touchInDirstate = new ArrayList<Path>();
147 for (Pair<HgDataFile, DataSource> e : files.values()) { 147 for (Pair<HgDataFile, DataSource> e : files.values()) {
148 HgDataFile df = e.first(); 148 HgDataFile df = e.first();
149 DataSource bds = e.second(); 149 DataSource bds = e.second();
150 Pair<Integer, Integer> fp = fileParents.get(df.getPath()); 150 Pair<Integer, Integer> fp = fileParents.get(df.getPath());
151 if (fp == null) { 151 if (fp == null) {
152 // NEW FILE 152 // NEW FILE
153 fp = new Pair<Integer, Integer>(NO_REVISION, NO_REVISION); 153 fp = new Pair<Integer, Integer>(NO_REVISION, NO_REVISION);
154 } 154 }
155 RevlogStream contentStream = repo.getImplAccess().getStream(df); 155 RevlogStream contentStream = repo.getImplAccess().getStream(df);
156 if (!df.exists()) { 156 final boolean isNewFile = !df.exists();
157 newlyAddedFiles.put(df.getPath(), contentStream);
158 }
159 RevlogStreamWriter fileWriter = new RevlogStreamWriter(repo, contentStream, transaction); 157 RevlogStreamWriter fileWriter = new RevlogStreamWriter(repo, contentStream, transaction);
160 Nodeid fileRev = fileWriter.addRevision(bds, clogRevisionIndex, fp.first(), fp.second()).second(); 158 Nodeid fileRev = fileWriter.addRevision(bds, clogRevisionIndex, fp.first(), fp.second()).second();
161 newManifestRevision.put(df.getPath(), fileRev); 159 newManifestRevision.put(df.getPath(), fileRev);
162 touchInDirstate.add(df.getPath()); 160 touchInDirstate.add(df.getPath());
161 if (isNewFile) {
162 // registerNew shall go after fileWriter.addRevision as it needs to know if data is inlined or not
163 fncache.registerNew(df.getPath(), contentStream);
164 }
163 } 165 }
164 // 166 //
165 // Manifest 167 // Manifest
166 final ManifestEntryBuilder manifestBuilder = new ManifestEntryBuilder(repo.buildFileNameEncodingHelper()); 168 final ManifestEntryBuilder manifestBuilder = new ManifestEntryBuilder(repo.buildFileNameEncodingHelper());
167 for (Map.Entry<Path, Nodeid> me : newManifestRevision.entrySet()) { 169 for (Map.Entry<Path, Nodeid> me : newManifestRevision.entrySet()) {
176 changelogBuilder.branch(branch == null ? DEFAULT_BRANCH_NAME : branch); 178 changelogBuilder.branch(branch == null ? DEFAULT_BRANCH_NAME : branch);
177 changelogBuilder.user(String.valueOf(user)); 179 changelogBuilder.user(String.valueOf(user));
178 changelogBuilder.manifest(manifestRev).comment(message); 180 changelogBuilder.manifest(manifestRev).comment(message);
179 RevlogStreamWriter changelogWriter = new RevlogStreamWriter(repo, repo.getImplAccess().getChangelogStream(), transaction); 181 RevlogStreamWriter changelogWriter = new RevlogStreamWriter(repo, repo.getImplAccess().getChangelogStream(), transaction);
180 Nodeid changesetRev = changelogWriter.addRevision(changelogBuilder, clogRevisionIndex, p1Commit, p2Commit).second(); 182 Nodeid changesetRev = changelogWriter.addRevision(changelogBuilder, clogRevisionIndex, p1Commit, p2Commit).second();
181 // TODO move fncache update to an external facility, along with dirstate and bookmark update 183 // TODO move dirstate and bookmark update update to an external facility
182 if (!newlyAddedFiles.isEmpty() && repo.fncacheInUse()) { 184 fncache.complete();
183 FNCacheFile fncache = new FNCacheFile(repo);
184 for (Path p : newlyAddedFiles.keySet()) {
185 fncache.addIndex(p);
186 if (!newlyAddedFiles.get(p).isInlineData()) {
187 fncache.addData(p);
188 }
189 }
190 try {
191 fncache.write();
192 } catch (IOException ex) {
193 // see comment above for fnchache.read()
194 repo.getLog().dump(getClass(), Error, ex, "Failed to write fncache, error ignored");
195 }
196 }
197 String oldBranchValue = DirstateReader.readBranch(repo); 185 String oldBranchValue = DirstateReader.readBranch(repo);
198 String newBranchValue = branch == null ? DEFAULT_BRANCH_NAME : branch; 186 String newBranchValue = branch == null ? DEFAULT_BRANCH_NAME : branch;
199 if (!oldBranchValue.equals(newBranchValue)) { 187 if (!oldBranchValue.equals(newBranchValue)) {
200 // prepare undo.branch as described in http://mercurial.selenic.com/wiki/FileFormats#undo..2A 188 // prepare undo.branch as described in http://mercurial.selenic.com/wiki/FileFormats#undo..2A
201 File branchFile = transaction.prepare(repo.getRepositoryFile(Branch), repo.getRepositoryFile(UndoBranch)); 189 File branchFile = transaction.prepare(repo.getRepositoryFile(Branch), repo.getRepositoryFile(UndoBranch));