comparison src/org/tmatesoft/hg/repo/Revlog.java @ 607:66f1cc23b906

Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 07 May 2013 16:52:46 +0200
parents c3505001a42a
children e1b29756f901
comparison
equal deleted inserted replaced
606:5daa42067e7c 607:66f1cc23b906
54 54
55 private final HgRepository repo; 55 private final HgRepository repo;
56 protected final RevlogStream content; 56 protected final RevlogStream content;
57 protected final boolean useRevisionLookup; 57 protected final boolean useRevisionLookup;
58 protected RevisionLookup revisionLookup; 58 protected RevisionLookup revisionLookup;
59 private final RevlogStream.Observer revisionLookupCleaner;
59 60
60 protected Revlog(HgRepository hgRepo, RevlogStream contentStream, boolean needRevisionLookup) { 61 protected Revlog(HgRepository hgRepo, RevlogStream contentStream, boolean needRevisionLookup) {
61 if (hgRepo == null) { 62 if (hgRepo == null) {
62 throw new IllegalArgumentException(); 63 throw new IllegalArgumentException();
63 } 64 }
65 throw new IllegalArgumentException(); 66 throw new IllegalArgumentException();
66 } 67 }
67 repo = hgRepo; 68 repo = hgRepo;
68 content = contentStream; 69 content = contentStream;
69 useRevisionLookup = needRevisionLookup; 70 useRevisionLookup = needRevisionLookup;
71 if (needRevisionLookup) {
72 revisionLookupCleaner = new RevlogStream.Observer() {
73
74 public void reloaded(RevlogStream src) {
75 revisionLookup = null;
76 }
77 };
78 } else {
79 revisionLookupCleaner = null;
80 }
70 } 81 }
71 82
72 // invalid Revlog 83 // invalid Revlog
73 protected Revlog(HgRepository hgRepo) { 84 protected Revlog(HgRepository hgRepo) {
74 repo = hgRepo; 85 repo = hgRepo;
75 content = null; 86 content = null;
76 useRevisionLookup = false; 87 useRevisionLookup = false;
88 revisionLookupCleaner = null;
77 } 89 }
78 90
79 public final HgRepository getRepo() { 91 public final HgRepository getRepo() {
80 return repo; 92 return repo;
81 } 93 }
160 return revision; 172 return revision;
161 } 173 }
162 174
163 private int doFindWithCache(Nodeid nid) { 175 private int doFindWithCache(Nodeid nid) {
164 if (useRevisionLookup) { 176 if (useRevisionLookup) {
165 if (revisionLookup == null) { 177 if (revisionLookup == null || content.shallDropDerivedCaches()) {
166 revisionLookup = RevisionLookup.createFor(content); 178 content.detach(revisionLookupCleaner);
179 setRevisionLookup(RevisionLookup.createFor(content));
167 } 180 }
168 return revisionLookup.findIndex(nid); 181 return revisionLookup.findIndex(nid);
169 } else { 182 } else {
170 return content.findRevisionIndex(nid); 183 return content.findRevisionIndex(nid);
171 } 184 }
185 }
186
187 /**
188 * use selected helper for revision lookup, register appropriate listeners to clear cache on revlog changes
189 * @param rl not <code>null</code>
190 */
191 protected void setRevisionLookup(RevisionLookup rl) {
192 assert rl != null;
193 revisionLookup = rl;
194 content.attach(revisionLookupCleaner);
172 } 195 }
173 196
174 /** 197 /**
175 * Note, {@link Nodeid#NULL} nodeid is not reported as known in any revlog. 198 * Note, {@link Nodeid#NULL} nodeid is not reported as known in any revlog.
176 * 199 *