comparison src/org/tmatesoft/hg/internal/DirstateBuilder.java @ 617:65c01508f002

Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 15 May 2013 20:10:09 +0200
parents bd5926e24aa3
children 6526d8adbc0f
comparison
equal deleted inserted replaced
616:5e0313485eef 617:65c01508f002
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.internal; 17 package org.tmatesoft.hg.internal;
18 18
19 import static org.tmatesoft.hg.repo.HgRepositoryFiles.Dirstate;
20 import static org.tmatesoft.hg.repo.HgRepositoryFiles.UndoDirstate;
21
19 import java.io.File; 22 import java.io.File;
20 import java.io.FileOutputStream; 23 import java.io.FileOutputStream;
21 import java.io.IOException; 24 import java.io.IOException;
22 import java.nio.ByteBuffer; 25 import java.nio.ByteBuffer;
23 import java.nio.channels.FileChannel; 26 import java.nio.channels.FileChannel;
30 import org.tmatesoft.hg.repo.HgDirstate; 33 import org.tmatesoft.hg.repo.HgDirstate;
31 import org.tmatesoft.hg.repo.HgDirstate.EntryKind; 34 import org.tmatesoft.hg.repo.HgDirstate.EntryKind;
32 import org.tmatesoft.hg.repo.HgDirstate.Record; 35 import org.tmatesoft.hg.repo.HgDirstate.Record;
33 import org.tmatesoft.hg.repo.HgInvalidStateException; 36 import org.tmatesoft.hg.repo.HgInvalidStateException;
34 import org.tmatesoft.hg.repo.HgManifest.Flags; 37 import org.tmatesoft.hg.repo.HgManifest.Flags;
35 import org.tmatesoft.hg.repo.HgRepositoryFiles;
36 import org.tmatesoft.hg.util.Path; 38 import org.tmatesoft.hg.util.Path;
37 39
38 /** 40 /**
39 * Facility to build a dirstate file as described in {@linkplain http://mercurial.selenic.com/wiki/DirState} 41 * Facility to build a dirstate file as described in {@linkplain http://mercurial.selenic.com/wiki/DirState}
40 * 42 *
147 bb.clear(); 149 bb.clear();
148 } 150 }
149 } 151 }
150 } 152 }
151 153
152 public void serialize() throws HgIOException { 154 public void serialize(Transaction tr) throws HgIOException {
153 File dirstateFile = hgRepo.getRepositoryFile(HgRepositoryFiles.Dirstate); 155 File dirstateFile = tr.prepare(hgRepo.getRepositoryFile(Dirstate), hgRepo.getRepositoryFile(UndoDirstate));
154 try { 156 try {
155 FileChannel dirstate = new FileOutputStream(dirstateFile).getChannel(); 157 FileChannel dirstate = new FileOutputStream(dirstateFile).getChannel();
156 serialize(dirstate); 158 serialize(dirstate);
157 dirstate.close(); 159 dirstate.close();
160 tr.done(dirstateFile);
158 } catch (IOException ex) { 161 } catch (IOException ex) {
162 tr.failure(dirstateFile, ex);
159 throw new HgIOException("Can't write down new directory state", ex, dirstateFile); 163 throw new HgIOException("Can't write down new directory state", ex, dirstateFile);
160 } 164 }
161 } 165 }
162 166
163 public void fillFrom(DirstateReader dirstate) { 167 public void fillFrom(DirstateReader dirstate) {