comparison src/org/tmatesoft/hg/repo/HgBundle.java @ 295:981f9f50bb6c

Issue 11: Error log facility. SessionContext to share common facilities
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Sep 2011 05:35:32 +0200
parents 9fb50c04f03c
children 694ebabb5cb3
comparison
equal deleted inserted replaced
294:32890bab7209 295:981f9f50bb6c
21 import java.util.LinkedList; 21 import java.util.LinkedList;
22 import java.util.List; 22 import java.util.List;
23 23
24 import org.tmatesoft.hg.core.HgBadStateException; 24 import org.tmatesoft.hg.core.HgBadStateException;
25 import org.tmatesoft.hg.core.HgException; 25 import org.tmatesoft.hg.core.HgException;
26 import org.tmatesoft.hg.core.HgInvalidFileException;
26 import org.tmatesoft.hg.core.Nodeid; 27 import org.tmatesoft.hg.core.Nodeid;
27 import org.tmatesoft.hg.internal.ByteArrayChannel; 28 import org.tmatesoft.hg.internal.ByteArrayChannel;
28 import org.tmatesoft.hg.internal.ByteArrayDataAccess; 29 import org.tmatesoft.hg.internal.ByteArrayDataAccess;
29 import org.tmatesoft.hg.internal.DataAccess; 30 import org.tmatesoft.hg.internal.DataAccess;
30 import org.tmatesoft.hg.internal.DataAccessProvider; 31 import org.tmatesoft.hg.internal.DataAccessProvider;
91 /** 92 /**
92 * Get changes recorded in the bundle that are missing from the supplied repository. 93 * Get changes recorded in the bundle that are missing from the supplied repository.
93 * @param hgRepo repository that shall possess base revision for this bundle 94 * @param hgRepo repository that shall possess base revision for this bundle
94 * @param inspector callback to get each changeset found 95 * @param inspector callback to get each changeset found
95 */ 96 */
96 public void changes(final HgRepository hgRepo, final HgChangelog.Inspector inspector) throws HgException, IOException { 97 public void changes(final HgRepository hgRepo, final HgChangelog.Inspector inspector) throws HgInvalidFileException {
97 Inspector bundleInsp = new Inspector() { 98 Inspector bundleInsp = new Inspector() {
98 DigestHelper dh = new DigestHelper(); 99 DigestHelper dh = new DigestHelper();
99 boolean emptyChangelog = true; 100 boolean emptyChangelog = true;
100 private DataAccess prevRevContent; 101 private DataAccess prevRevContent;
101 private int revisionIndex; 102 private int revisionIndex;
178 179
179 }; 180 };
180 inspectChangelog(bundleInsp); 181 inspectChangelog(bundleInsp);
181 } 182 }
182 183
183 public void dump() throws IOException { 184 public void dump() throws HgException {
184 Dump dump = new Dump(); 185 Dump dump = new Dump();
185 inspectAll(dump); 186 inspectAll(dump);
186 System.out.println("Total files:" + dump.names.size()); 187 System.out.println("Total files:" + dump.names.size());
187 for (String s : dump.names) { 188 for (String s : dump.names) {
188 System.out.println(s); 189 System.out.println(s);
244 } 245 }
245 return true; 246 return true;
246 } 247 }
247 } 248 }
248 249
249 public void inspectChangelog(Inspector inspector) throws IOException { 250 public void inspectChangelog(Inspector inspector) throws HgInvalidFileException {
250 if (inspector == null) { 251 if (inspector == null) {
251 throw new IllegalArgumentException(); 252 throw new IllegalArgumentException();
252 } 253 }
253 DataAccess da = getDataStream(); 254 DataAccess da = null;
254 try { 255 try {
256 da = getDataStream();
255 internalInspectChangelog(da, inspector); 257 internalInspectChangelog(da, inspector);
258 } catch (IOException ex) {
259 throw new HgInvalidFileException("Bundle.inspectChangelog failed", ex, bundleFile);
256 } finally { 260 } finally {
257 da.done(); 261 if (da != null) {
258 } 262 da.done();
259 } 263 }
260 264 }
261 public void inspectManifest(Inspector inspector) throws IOException { 265 }
266
267 public void inspectManifest(Inspector inspector) throws HgInvalidFileException {
262 if (inspector == null) { 268 if (inspector == null) {
263 throw new IllegalArgumentException(); 269 throw new IllegalArgumentException();
264 } 270 }
265 DataAccess da = getDataStream(); 271 DataAccess da = null;
266 try { 272 try {
273 da = getDataStream();
267 if (da.isEmpty()) { 274 if (da.isEmpty()) {
268 return; 275 return;
269 } 276 }
270 skipGroup(da); // changelog 277 skipGroup(da); // changelog
271 internalInspectManifest(da, inspector); 278 internalInspectManifest(da, inspector);
279 } catch (IOException ex) {
280 throw new HgInvalidFileException("Bundle.inspectManifest failed", ex, bundleFile);
272 } finally { 281 } finally {
273 da.done(); 282 if (da != null) {
274 } 283 da.done();
275 } 284 }
276 285 }
277 public void inspectFiles(Inspector inspector) throws IOException { 286 }
287
288 public void inspectFiles(Inspector inspector) throws HgInvalidFileException {
278 if (inspector == null) { 289 if (inspector == null) {
279 throw new IllegalArgumentException(); 290 throw new IllegalArgumentException();
280 } 291 }
281 DataAccess da = getDataStream(); 292 DataAccess da = null;
282 try { 293 try {
294 da = getDataStream();
283 if (da.isEmpty()) { 295 if (da.isEmpty()) {
284 return; 296 return;
285 } 297 }
286 skipGroup(da); // changelog 298 skipGroup(da); // changelog
287 if (da.isEmpty()) { 299 if (da.isEmpty()) {
288 return; 300 return;
289 } 301 }
290 skipGroup(da); // manifest 302 skipGroup(da); // manifest
291 internalInspectFiles(da, inspector); 303 internalInspectFiles(da, inspector);
304 } catch (IOException ex) {
305 throw new HgInvalidFileException("Bundle.inspectFiles failed", ex, bundleFile);
292 } finally { 306 } finally {
293 da.done(); 307 if (da != null) {
294 } 308 da.done();
295 } 309 }
296 310 }
297 public void inspectAll(Inspector inspector) throws IOException { 311 }
312
313 public void inspectAll(Inspector inspector) throws HgInvalidFileException {
298 if (inspector == null) { 314 if (inspector == null) {
299 throw new IllegalArgumentException(); 315 throw new IllegalArgumentException();
300 } 316 }
301 DataAccess da = getDataStream(); 317 DataAccess da = null;
302 try { 318 try {
319 da = getDataStream();
303 internalInspectChangelog(da, inspector); 320 internalInspectChangelog(da, inspector);
304 internalInspectManifest(da, inspector); 321 internalInspectManifest(da, inspector);
305 internalInspectFiles(da, inspector); 322 internalInspectFiles(da, inspector);
323 } catch (IOException ex) {
324 throw new HgInvalidFileException("Bundle.inspectAll failed", ex, bundleFile);
306 } finally { 325 } finally {
307 da.done(); 326 if (da != null) {
327 da.done();
328 }
308 } 329 }
309 } 330 }
310 331
311 private void internalInspectChangelog(DataAccess da, Inspector inspector) throws IOException { 332 private void internalInspectChangelog(DataAccess da, Inspector inspector) throws IOException {
312 if (da.isEmpty()) { 333 if (da.isEmpty()) {