Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/SubrepoManager.java @ 348:a0864b2892cd
Expose errors reading mercurial control files with exception
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Thu, 24 Nov 2011 02:57:03 +0100 |
| parents | 981f9f50bb6c |
| children | 9c9c442b5f2e |
comparison
equal
deleted
inserted
replaced
| 347:8da7ade36c57 | 348:a0864b2892cd |
|---|---|
| 25 import java.util.HashMap; | 25 import java.util.HashMap; |
| 26 import java.util.LinkedList; | 26 import java.util.LinkedList; |
| 27 import java.util.List; | 27 import java.util.List; |
| 28 import java.util.Map; | 28 import java.util.Map; |
| 29 | 29 |
| 30 import org.tmatesoft.hg.repo.HgInternals; | 30 import org.tmatesoft.hg.core.HgInvalidControlFileException; |
| 31 import org.tmatesoft.hg.repo.HgRepository; | 31 import org.tmatesoft.hg.repo.HgRepository; |
| 32 import org.tmatesoft.hg.repo.HgSubrepoLocation; | 32 import org.tmatesoft.hg.repo.HgSubrepoLocation; |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * | 35 * |
| 44 public SubrepoManager(HgRepository hgRepo) { | 44 public SubrepoManager(HgRepository hgRepo) { |
| 45 assert hgRepo != null; | 45 assert hgRepo != null; |
| 46 repo = hgRepo; | 46 repo = hgRepo; |
| 47 } | 47 } |
| 48 | 48 |
| 49 private List<HgSubrepoLocation> readActualState() { | 49 private List<HgSubrepoLocation> readActualState() throws HgInvalidControlFileException { |
| 50 File hgsubFile = new File(repo.getWorkingDir(), ".hgsub"); | 50 File hgsubFile = new File(repo.getWorkingDir(), ".hgsub"); |
| 51 if (!hgsubFile.canRead()) { | 51 if (!hgsubFile.canRead()) { |
| 52 return Collections.emptyList(); | 52 return Collections.emptyList(); |
| 53 } | 53 } |
| 54 Map<String, String> state; // path -> revision | |
| 55 File hgstateFile = null; | |
| 54 try { | 56 try { |
| 55 Map<String, String> state; // path -> revision | 57 hgstateFile = new File(repo.getWorkingDir(), ".hgsubstate"); |
| 56 File hgstateFile = new File(repo.getWorkingDir(), ".hgsubstate"); | |
| 57 if (hgstateFile.canRead()) { | 58 if (hgstateFile.canRead()) { |
| 58 state = readState(new BufferedReader(new FileReader(hgstateFile))); | 59 state = readState(new BufferedReader(new FileReader(hgstateFile))); |
| 59 } else { | 60 } else { |
| 60 state = Collections.emptyMap(); | 61 state = Collections.emptyMap(); |
| 61 } | 62 } |
| 63 } catch (IOException ex) { | |
| 64 throw new HgInvalidControlFileException("Subrepo state read failed", ex, hgstateFile); | |
| 65 } | |
| 66 try { | |
| 62 BufferedReader br = new BufferedReader(new FileReader(hgsubFile)); | 67 BufferedReader br = new BufferedReader(new FileReader(hgsubFile)); |
| 63 return readConfig(br, state); | 68 return readConfig(br, state); |
| 64 } catch (IOException ex) { | 69 } catch (IOException ex) { |
| 65 HgInternals.getContext(repo).getLog().error(getClass(), ex, "Subrepo state read failed"); | 70 throw new HgInvalidControlFileException("Subrepo state read failed", ex, hgsubFile); |
| 66 } | 71 } |
| 67 return Collections.emptyList(); | |
| 68 } | 72 } |
| 69 | 73 |
| 70 private List<HgSubrepoLocation> readConfig(BufferedReader br, Map<String, String> substate) throws IOException { | 74 private List<HgSubrepoLocation> readConfig(BufferedReader br, Map<String, String> substate) throws IOException { |
| 71 try { | 75 try { |
| 72 String line; | 76 String line; |
| 119 br.close(); | 123 br.close(); |
| 120 } | 124 } |
| 121 return rv; | 125 return rv; |
| 122 } | 126 } |
| 123 | 127 |
| 128 /*public to allow access from HgRepository, otherwise package-local*/ | |
| 129 public void read() throws HgInvalidControlFileException { | |
| 130 subRepos = readActualState(); | |
| 131 } | |
| 132 | |
| 124 public List<HgSubrepoLocation> all(/*int revision, or TIP|WC*/) { | 133 public List<HgSubrepoLocation> all(/*int revision, or TIP|WC*/) { |
| 125 if (subRepos == null) { | 134 assert subRepos != null; |
| 126 subRepos = readActualState(); | |
| 127 } | |
| 128 return subRepos; | 135 return subRepos; |
| 129 } | 136 } |
| 130 } | 137 } |
