Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgRepository.java @ 318:c3d2233ba842
Shall propagate errors to clients, not work around them silently
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 29 Sep 2011 03:35:59 +0200 |
parents | 981f9f50bb6c |
children | a37ce7145c3f |
comparison
equal
deleted
inserted
replaced
317:09628675bcee | 318:c3d2233ba842 |
---|---|
24 import java.util.Collections; | 24 import java.util.Collections; |
25 import java.util.HashMap; | 25 import java.util.HashMap; |
26 import java.util.List; | 26 import java.util.List; |
27 | 27 |
28 import org.tmatesoft.hg.core.HgDataStreamException; | 28 import org.tmatesoft.hg.core.HgDataStreamException; |
29 import org.tmatesoft.hg.core.HgInvalidControlFileException; | |
29 import org.tmatesoft.hg.core.Nodeid; | 30 import org.tmatesoft.hg.core.Nodeid; |
30 import org.tmatesoft.hg.core.SessionContext; | 31 import org.tmatesoft.hg.core.SessionContext; |
31 import org.tmatesoft.hg.internal.ByteArrayChannel; | 32 import org.tmatesoft.hg.internal.ByteArrayChannel; |
32 import org.tmatesoft.hg.internal.ConfigFile; | 33 import org.tmatesoft.hg.internal.ConfigFile; |
33 import org.tmatesoft.hg.internal.DataAccessProvider; | 34 import org.tmatesoft.hg.internal.DataAccessProvider; |
164 this.manifest = new HgManifest(this, content); | 165 this.manifest = new HgManifest(this, content); |
165 } | 166 } |
166 return this.manifest; | 167 return this.manifest; |
167 } | 168 } |
168 | 169 |
169 public HgTags getTags() { | 170 public HgTags getTags() throws HgInvalidControlFileException { |
170 if (tags == null) { | 171 if (tags == null) { |
171 tags = new HgTags(this); | 172 tags = new HgTags(this); |
172 try { | 173 HgDataFile hgTags = getFileNode(".hgtags"); |
173 HgDataFile hgTags = getFileNode(".hgtags"); | 174 if (hgTags.exists()) { |
174 if (hgTags.exists()) { | 175 for (int i = 0; i <= hgTags.getLastRevision(); i++) { // FIXME in fact, would be handy to have walk(start,end) |
175 for (int i = 0; i <= hgTags.getLastRevision(); i++) { // FIXME in fact, would be handy to have walk(start,end) | 176 // method for data files as well, though it looks odd. |
176 // method for data files as well, though it looks odd. | 177 try { |
177 try { | 178 ByteArrayChannel sink = new ByteArrayChannel(); |
178 ByteArrayChannel sink = new ByteArrayChannel(); | 179 hgTags.content(i, sink); |
179 hgTags.content(i, sink); | 180 final String content = new String(sink.toArray(), "UTF8"); |
180 final String content = new String(sink.toArray(), "UTF8"); | 181 tags.readGlobal(new StringReader(content)); |
181 tags.readGlobal(new StringReader(content)); | 182 } catch (CancelledException ex) { |
182 } catch (CancelledException ex) { | 183 // IGNORE, can't happen, we did not configure cancellation |
183 // IGNORE, can't happen, we did not configure cancellation | 184 getContext().getLog().debug(getClass(), ex, null); |
184 getContext().getLog().debug(getClass(), ex, null); | 185 } catch (HgDataStreamException ex) { |
185 } catch (HgDataStreamException ex) { | 186 getContext().getLog().error(getClass(), ex, null); |
186 getContext().getLog().error(getClass(), ex, null); | 187 // FIXME need to react |
187 // FIXME need to react | 188 } catch (IOException ex) { |
188 } catch (IOException ex) { | 189 // UnsupportedEncodingException can't happen (UTF8) |
189 // UnsupportedEncodingException can't happen (UTF8) | 190 // only from readGlobal. Need to reconsider exceptions thrown from there: |
190 // only from readGlobal. Need to reconsider exceptions thrown from there | 191 // BufferedReader wraps String and unlikely to throw IOException, perhaps, log is enough? |
191 getContext().getLog().error(getClass(), ex, null); | 192 getContext().getLog().error(getClass(), ex, null); |
192 // XXX need to decide what to do this. failure to read single revision shall not break complete cycle | 193 // XXX need to decide what to do this. failure to read single revision shall not break complete cycle |
193 } | |
194 } | 194 } |
195 } | 195 } |
196 tags.readGlobal(new File(getWorkingDir(), ".hgtags")); // XXX replace with HgDataFile.workingCopy | 196 } |
197 tags.readLocal(new File(repoDir, "localtags")); | 197 File file2read = null; |
198 try { | |
199 file2read = new File(getWorkingDir(), ".hgtags"); | |
200 tags.readGlobal(file2read); // XXX replace with HgDataFile.workingCopy | |
201 file2read = new File(repoDir, "localtags"); | |
202 tags.readLocal(file2read); | |
198 } catch (IOException ex) { | 203 } catch (IOException ex) { |
199 getContext().getLog().error(getClass(), ex, null); | 204 getContext().getLog().error(getClass(), ex, null); |
205 throw new HgInvalidControlFileException("Failed to read tags", ex, file2read); | |
200 } | 206 } |
201 } | 207 } |
202 return tags; | 208 return tags; |
203 } | 209 } |
204 | 210 |