} else {
throw new HgBadArgumentException("Sorry, only clean checkout is supported now, use #clean(true)", null);
}
progress.worked(1);
cancellation.checkCancelled();
final DirstateBuilder dirstateBuilder = new DirstateBuilder(internalRepo);
final CheckoutWorker worker = new CheckoutWorker(internalRepo);
HgManifest.Inspector insp = new HgManifest.Inspector() {
public boolean next(Nodeid nid, Path fname, Flags flags) {
if (worker.next(nid, fname, flags)) {
// Mercurial seems to write "n 0 -1 unset fname" on `hg --clean co -rev <earlier rev>`
// and the reason for 'force lookup' I suspect is a slight chance of simultaneous modification
// of the file by user that doesn't alter its size the very second dirstate is being written
// (or the file is being updated and the update brought in changes that didn't alter the file size -
// with size and timestamp set, later `hg status` won't notice these changes)
// However, as long as we use this class to write clean copies of the files, we can put all the fields
// right away.
int mtime = worker.getLastFileModificationTime();
// Manifest flags are chars (despite octal values `hg manifest --debug` displays),
// while dirstate keeps actual unix flags.
int fmode = worker.getLastFileMode();
dirstateBuilder.recordNormal(fname, fmode, mtime, worker.getLastFileSize());
return true;
}
return false;
}
public boolean end(int manifestRevision) {
return false;
}
public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
return true;
}
};
// checkout tip if no revision set
final int coRevision = revisionToCheckout.get(HgRepository.TIP);
dirstateBuilder.parents(repo.getChangelog().getRevision(coRevision), null);
repo.getManifest().walk(coRevision, coRevision, insp);
worker.checkFailed();
progress.worked(3);
cancellation.checkCancelled();
File dirstateFile = internalRepo.getRepositoryFile(Dirstate);
try {
FileChannel dirstateFileChannel = new FileOutputStream(dirstateFile).getChannel();
dirstateBuilder.serialize(dirstateFileChannel);
dirstateFileChannel.close();
} catch (IOException ex) {
throw new HgIOException("Can't write down new directory state", ex, dirstateFile);
}
progress.worked(1);