Mercurial > hg4j
comparison src/org/tmatesoft/hg/core/HgCloneCommand.java @ 539:9edfd5a223b8
Commit: handle empty repository case
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Wed, 13 Feb 2013 18:44:58 +0100 |
| parents | 243202f1bda5 |
| children | e4ee4bf4c7d0 |
comparison
equal
deleted
inserted
replaced
| 538:dd4f6311af52 | 539:9edfd5a223b8 |
|---|---|
| 24 import java.io.File; | 24 import java.io.File; |
| 25 import java.io.FileOutputStream; | 25 import java.io.FileOutputStream; |
| 26 import java.io.IOException; | 26 import java.io.IOException; |
| 27 import java.util.ArrayList; | 27 import java.util.ArrayList; |
| 28 import java.util.Collections; | 28 import java.util.Collections; |
| 29 import java.util.LinkedList; | |
| 30 import java.util.TreeMap; | 29 import java.util.TreeMap; |
| 31 | 30 |
| 32 import org.tmatesoft.hg.internal.ByteArrayDataAccess; | 31 import org.tmatesoft.hg.internal.ByteArrayDataAccess; |
| 33 import org.tmatesoft.hg.internal.DataAccess; | 32 import org.tmatesoft.hg.internal.DataAccess; |
| 34 import org.tmatesoft.hg.internal.DataAccessProvider; | 33 import org.tmatesoft.hg.internal.DataAccessProvider; |
| 35 import org.tmatesoft.hg.internal.DataSerializer; | 34 import org.tmatesoft.hg.internal.DataSerializer; |
| 36 import org.tmatesoft.hg.internal.DigestHelper; | 35 import org.tmatesoft.hg.internal.DigestHelper; |
| 36 import org.tmatesoft.hg.internal.FNCacheFile; | |
| 37 import org.tmatesoft.hg.internal.Internals; | |
| 37 import org.tmatesoft.hg.internal.Lifecycle; | 38 import org.tmatesoft.hg.internal.Lifecycle; |
| 38 import org.tmatesoft.hg.internal.RepoInitializer; | 39 import org.tmatesoft.hg.internal.RepoInitializer; |
| 39 import org.tmatesoft.hg.internal.RevlogCompressor; | 40 import org.tmatesoft.hg.internal.RevlogCompressor; |
| 40 import org.tmatesoft.hg.internal.RevlogStreamWriter; | 41 import org.tmatesoft.hg.internal.RevlogStreamWriter; |
| 41 import org.tmatesoft.hg.repo.HgBundle; | 42 import org.tmatesoft.hg.repo.HgBundle; |
| 47 import org.tmatesoft.hg.repo.HgRemoteRepository; | 48 import org.tmatesoft.hg.repo.HgRemoteRepository; |
| 48 import org.tmatesoft.hg.repo.HgRepository; | 49 import org.tmatesoft.hg.repo.HgRepository; |
| 49 import org.tmatesoft.hg.repo.HgRuntimeException; | 50 import org.tmatesoft.hg.repo.HgRuntimeException; |
| 50 import org.tmatesoft.hg.util.CancelSupport; | 51 import org.tmatesoft.hg.util.CancelSupport; |
| 51 import org.tmatesoft.hg.util.CancelledException; | 52 import org.tmatesoft.hg.util.CancelledException; |
| 53 import org.tmatesoft.hg.util.Path; | |
| 52 import org.tmatesoft.hg.util.PathRewrite; | 54 import org.tmatesoft.hg.util.PathRewrite; |
| 53 import org.tmatesoft.hg.util.ProgressSupport; | 55 import org.tmatesoft.hg.util.ProgressSupport; |
| 54 | 56 |
| 55 /** | 57 /** |
| 56 * WORK IN PROGRESS, DO NOT USE | 58 * WORK IN PROGRESS, DO NOT USE |
| 153 private DataAccess prevRevContent; | 155 private DataAccess prevRevContent; |
| 154 private final DigestHelper dh = new DigestHelper(); | 156 private final DigestHelper dh = new DigestHelper(); |
| 155 // recently processed nodes last, so that index in the array may be used as a linkRevision or baseRevision | 157 // recently processed nodes last, so that index in the array may be used as a linkRevision or baseRevision |
| 156 private final ArrayList<Nodeid> revisionSequence = new ArrayList<Nodeid>(); | 158 private final ArrayList<Nodeid> revisionSequence = new ArrayList<Nodeid>(); |
| 157 | 159 |
| 158 private final LinkedList<String> fncacheFiles = new LinkedList<String>(); | 160 private FNCacheFile fncacheFile; |
| 159 private RepoInitializer repoInit; | 161 private RepoInitializer repoInit; |
| 160 private Lifecycle.Callback lifecycleCallback; | 162 private Lifecycle.Callback lifecycleCallback; |
| 161 private CancelledException cancelException; | 163 private CancelledException cancelException; |
| 162 | 164 |
| 163 private RevlogStreamWriter.HeaderWriter revlogHeader = new RevlogStreamWriter.HeaderWriter(true); | 165 private RevlogStreamWriter.HeaderWriter revlogHeader = new RevlogStreamWriter.HeaderWriter(true); |
| 174 revlogDataZip = new RevlogCompressor(sessionCtx); | 176 revlogDataZip = new RevlogCompressor(sessionCtx); |
| 175 } | 177 } |
| 176 | 178 |
| 177 public void initEmptyRepository() throws IOException { | 179 public void initEmptyRepository() throws IOException { |
| 178 repoInit.initEmptyRepository(hgDir); | 180 repoInit.initEmptyRepository(hgDir); |
| 181 try { | |
| 182 assert (repoInit.getRequires() & FNCACHE) != 0; | |
| 183 fncacheFile = new FNCacheFile(Internals.getInstance(new HgLookup(ctx).detect(hgDir))); | |
| 184 } catch (HgRepositoryNotFoundException ex) { | |
| 185 // SHALL NOT HAPPEN provided we initialized empty repository successfully | |
| 186 // TODO perhaps, with WriteDownMate moving to a more appropriate location, | |
| 187 // we could instantiate HgRepository (or Internals) by other means, without exception? | |
| 188 throw new IOException("Can't access fncache for newly created repository", ex); | |
| 189 } | |
| 179 } | 190 } |
| 180 | 191 |
| 181 public void complete() throws IOException { | 192 public void complete() throws IOException { |
| 182 FileOutputStream fncacheFile = new FileOutputStream(new File(hgDir, "store/fncache")); | 193 fncacheFile.write(); |
| 183 for (String s : fncacheFiles) { | |
| 184 fncacheFile.write(s.getBytes()); | |
| 185 fncacheFile.write(0x0A); // http://mercurial.selenic.com/wiki/fncacheRepoFormat | |
| 186 } | |
| 187 fncacheFile.close(); | |
| 188 } | 194 } |
| 189 | 195 |
| 190 public void changelogStart() { | 196 public void changelogStart() { |
| 191 try { | 197 try { |
| 192 revlogHeader.offset(0).baseRevision(-1); | 198 revlogHeader.offset(0).baseRevision(-1); |
| 235 | 241 |
| 236 public void fileStart(String name) { | 242 public void fileStart(String name) { |
| 237 try { | 243 try { |
| 238 revlogHeader.offset(0).baseRevision(-1); | 244 revlogHeader.offset(0).baseRevision(-1); |
| 239 revisionSequence.clear(); | 245 revisionSequence.clear(); |
| 240 fncacheFiles.add("data/" + name + ".i"); // TODO post-1.0 this is pure guess, | 246 fncacheFile.add(Path.create(name)); |
| 241 // need to investigate more how filenames are kept in fncache | |
| 242 File file = new File(hgDir, filename = storagePathHelper.rewrite(name).toString()); | 247 File file = new File(hgDir, filename = storagePathHelper.rewrite(name).toString()); |
| 243 file.getParentFile().mkdirs(); | 248 file.getParentFile().mkdirs(); |
| 244 indexFile = new FileOutputStream(file); | 249 indexFile = new FileOutputStream(file); |
| 245 } catch (IOException ex) { | 250 } catch (IOException ex) { |
| 246 String m = String.format("Failed to write file %s", filename); | 251 String m = String.format("Failed to write file %s", filename); |
