Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgBranches.java @ 628:6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Wed, 22 May 2013 15:52:31 +0200 |
| parents | 5c68567b3645 |
| children | 12a4f60ea972 a5cf64f2e7e4 |
comparison
equal
deleted
inserted
replaced
| 627:5153eb73b18d | 628:6526d8adbc0f |
|---|---|
| 38 import java.util.regex.Pattern; | 38 import java.util.regex.Pattern; |
| 39 | 39 |
| 40 import org.tmatesoft.hg.core.Nodeid; | 40 import org.tmatesoft.hg.core.Nodeid; |
| 41 import org.tmatesoft.hg.internal.ChangelogMonitor; | 41 import org.tmatesoft.hg.internal.ChangelogMonitor; |
| 42 import org.tmatesoft.hg.internal.Experimental; | 42 import org.tmatesoft.hg.internal.Experimental; |
| 43 import org.tmatesoft.hg.internal.FileUtils; | |
| 43 import org.tmatesoft.hg.internal.Internals; | 44 import org.tmatesoft.hg.internal.Internals; |
| 44 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; | 45 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
| 45 import org.tmatesoft.hg.util.ProgressSupport; | 46 import org.tmatesoft.hg.util.ProgressSupport; |
| 46 | 47 |
| 47 /** | 48 /** |
| 66 File branchheadsCache = getCacheFile(); | 67 File branchheadsCache = getCacheFile(); |
| 67 int lastInCache = -1; | 68 int lastInCache = -1; |
| 68 if (!branchheadsCache.canRead()) { | 69 if (!branchheadsCache.canRead()) { |
| 69 return lastInCache; | 70 return lastInCache; |
| 70 } | 71 } |
| 71 BufferedReader br = null; | 72 BufferedReader br = null; // TODO replace with LineReader |
| 72 final Pattern spacePattern = Pattern.compile(" "); | 73 final Pattern spacePattern = Pattern.compile(" "); |
| 73 try { | 74 try { |
| 74 final LinkedHashMap<String, List<Nodeid>> branchHeads = new LinkedHashMap<String, List<Nodeid>>(); | 75 final LinkedHashMap<String, List<Nodeid>> branchHeads = new LinkedHashMap<String, List<Nodeid>>(); |
| 75 br = new BufferedReader(new FileReader(branchheadsCache)); | 76 br = new BufferedReader(new FileReader(branchheadsCache)); |
| 76 String line = br.readLine(); | 77 String line = br.readLine(); |
| 109 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); | 110 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); |
| 110 // FALL THROUGH to return -1 indicating no cache information | 111 // FALL THROUGH to return -1 indicating no cache information |
| 111 } catch (NumberFormatException ex) { | 112 } catch (NumberFormatException ex) { |
| 112 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); | 113 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); |
| 113 // FALL THROUGH | 114 // FALL THROUGH |
| 114 } catch (HgInvalidControlFileException ex) { | 115 } catch (HgRuntimeException ex) { |
| 115 // shall not happen, thus log as error | 116 // if happens, log error and pretend there's no cache |
| 116 repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); | |
| 117 // FALL THROUGH | |
| 118 } catch (HgInvalidRevisionException ex) { | |
| 119 repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); | 117 repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); |
| 120 // FALL THROUGH | 118 // FALL THROUGH |
| 121 } finally { | 119 } finally { |
| 122 if (br != null) { | 120 new FileUtils(repo.getSessionContext().getLog()).closeQuietly(br); |
| 123 try { | |
| 124 br.close(); | |
| 125 } catch (IOException ex) { | |
| 126 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); // ignore | |
| 127 } | |
| 128 } | |
| 129 } | 121 } |
| 130 return -1; // deliberately not lastInCache, to avoid anything but -1 when 1st line was read and there's error is in lines 2..end | 122 return -1; // deliberately not lastInCache, to avoid anything but -1 when 1st line was read and there's error is in lines 2..end |
| 131 } | 123 } |
| 132 | 124 |
| 133 void collect(final ProgressSupport ps) throws HgInvalidControlFileException { | 125 void collect(final ProgressSupport ps) throws HgRuntimeException { |
| 134 branches.clear(); | 126 branches.clear(); |
| 135 final HgRepository repo = internalRepo.getRepo(); | 127 final HgRepository repo = internalRepo.getRepo(); |
| 136 ps.start(1 + repo.getChangelog().getRevisionCount() * 2); | 128 ps.start(1 + repo.getChangelog().getRevisionCount() * 2); |
| 137 // | 129 // |
| 138 int lastCached = readCache(); | 130 int lastCached = readCache(); |
| 284 private File getCacheFile() { | 276 private File getCacheFile() { |
| 285 // prior to 1.8 used to be .hg/branchheads.cache | 277 // prior to 1.8 used to be .hg/branchheads.cache |
| 286 return internalRepo.getFileFromRepoDir("cache/branchheads"); | 278 return internalRepo.getFileFromRepoDir("cache/branchheads"); |
| 287 } | 279 } |
| 288 | 280 |
| 289 /*package-local*/ void reloadIfChanged(ProgressSupport ps) throws HgInvalidControlFileException { | 281 /*package-local*/ void reloadIfChanged(ProgressSupport ps) throws HgRuntimeException { |
| 290 if (repoChangeTracker.isChanged()) { | 282 if (repoChangeTracker.isChanged()) { |
| 291 collect(ps); | 283 collect(ps); |
| 292 } | 284 } |
| 293 } | 285 } |
| 294 | 286 |
| 311 // proper BI in #collect() | 303 // proper BI in #collect() |
| 312 BranchInfo(String branchName, Nodeid[] branchHeads) { | 304 BranchInfo(String branchName, Nodeid[] branchHeads) { |
| 313 this(branchName, Nodeid.NULL, branchHeads); | 305 this(branchName, Nodeid.NULL, branchHeads); |
| 314 } | 306 } |
| 315 | 307 |
| 316 void validate(HgChangelog clog, HgRevisionMap<HgChangelog> rmap) throws HgInvalidControlFileException { | 308 void validate(HgChangelog clog, HgRevisionMap<HgChangelog> rmap) throws HgRuntimeException { |
| 317 int[] localCset = new int[heads.size()]; | 309 int[] localCset = new int[heads.size()]; |
| 318 int i = 0; | 310 int i = 0; |
| 319 for (Nodeid h : heads) { | 311 for (Nodeid h : heads) { |
| 320 localCset[i++] = rmap.revisionIndex(h); | 312 localCset[i++] = rmap.revisionIndex(h); |
| 321 } | 313 } |
