Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgBranches.java @ 490:b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 16 Aug 2012 17:08:34 +0200 |
parents | 909306e412e2 |
children | 5c68567b3645 |
comparison
equal
deleted
inserted
replaced
489:9c0138cda59a | 490:b3c16d1aede0 |
---|---|
37 import java.util.TreeMap; | 37 import java.util.TreeMap; |
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.Experimental; | 41 import org.tmatesoft.hg.internal.Experimental; |
42 import org.tmatesoft.hg.internal.Internals; | |
42 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; | 43 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
43 import org.tmatesoft.hg.util.ProgressSupport; | 44 import org.tmatesoft.hg.util.ProgressSupport; |
44 | 45 |
45 /** | 46 /** |
46 * | 47 * |
49 */ | 50 */ |
50 public class HgBranches { | 51 public class HgBranches { |
51 | 52 |
52 private final Map<String, BranchInfo> branches = new TreeMap<String, BranchInfo>(); | 53 private final Map<String, BranchInfo> branches = new TreeMap<String, BranchInfo>(); |
53 private final HgRepository repo; | 54 private final HgRepository repo; |
55 private final Internals internalRepo; | |
54 private boolean isCacheActual = false; | 56 private boolean isCacheActual = false; |
55 | 57 |
56 HgBranches(HgRepository hgRepo) { | 58 HgBranches(Internals internals) { |
57 repo = hgRepo; | 59 internalRepo = internals; |
60 repo = internals.getRepo(); // merely a cached value | |
58 } | 61 } |
59 | 62 |
60 private int readCache() { | 63 private int readCache() { |
61 File branchheadsCache = getCacheFile(); | 64 File branchheadsCache = getCacheFile(); |
62 int lastInCache = -1; | 65 int lastInCache = -1; |
99 branches.put(e.getKey(), bi); | 102 branches.put(e.getKey(), bi); |
100 } | 103 } |
101 return lastInCache; | 104 return lastInCache; |
102 } catch (IOException ex) { | 105 } catch (IOException ex) { |
103 // log error, but otherwise do nothing | 106 // log error, but otherwise do nothing |
104 repo.getContext().getLog().dump(getClass(), Warn, ex, null); | 107 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); |
105 // FALL THROUGH to return -1 indicating no cache information | 108 // FALL THROUGH to return -1 indicating no cache information |
106 } catch (NumberFormatException ex) { | 109 } catch (NumberFormatException ex) { |
107 repo.getContext().getLog().dump(getClass(), Warn, ex, null); | 110 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); |
108 // FALL THROUGH | 111 // FALL THROUGH |
109 } catch (HgInvalidControlFileException ex) { | 112 } catch (HgInvalidControlFileException ex) { |
110 // shall not happen, thus log as error | 113 // shall not happen, thus log as error |
111 repo.getContext().getLog().dump(getClass(), Error, ex, null); | 114 repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); |
112 // FALL THROUGH | 115 // FALL THROUGH |
113 } catch (HgInvalidRevisionException ex) { | 116 } catch (HgInvalidRevisionException ex) { |
114 repo.getContext().getLog().dump(getClass(), Error, ex, null); | 117 repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); |
115 // FALL THROUGH | 118 // FALL THROUGH |
116 } finally { | 119 } finally { |
117 if (br != null) { | 120 if (br != null) { |
118 try { | 121 try { |
119 br.close(); | 122 br.close(); |
120 } catch (IOException ex) { | 123 } catch (IOException ex) { |
121 repo.getContext().getLog().dump(getClass(), Warn, ex, null); // ignore | 124 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); // ignore |
122 } | 125 } |
123 } | 126 } |
124 } | 127 } |
125 return -1; // deliberately not lastInCache, to avoid anything but -1 when 1st line was read and there's error is in lines 2..end | 128 return -1; // deliberately not lastInCache, to avoid anything but -1 when 1st line was read and there's error is in lines 2..end |
126 } | 129 } |
273 bw.close(); | 276 bw.close(); |
274 } | 277 } |
275 | 278 |
276 private File getCacheFile() { | 279 private File getCacheFile() { |
277 // prior to 1.8 used to be .hg/branchheads.cache | 280 // prior to 1.8 used to be .hg/branchheads.cache |
278 return new File(repo.getRepositoryRoot(), "cache/branchheads"); | 281 return internalRepo.getFileFromRepoDir("cache/branchheads"); |
279 } | 282 } |
280 | 283 |
281 public static class BranchInfo { | 284 public static class BranchInfo { |
282 private final String name; | 285 private final String name; |
283 private List<Nodeid> heads; | 286 private List<Nodeid> heads; |