diff src/org/tmatesoft/hg/core/HgAnnotateCommand.java @ 582:90df078d6418

Delegate cancel to original support, do not implement CancelSupport ourselves
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 22 Apr 2013 19:17:29 +0200
parents 0890628ed51e
children ed243b668502
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgAnnotateCommand.java	Mon Apr 22 16:02:17 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgAnnotateCommand.java	Mon Apr 22 19:17:29 2013 +0200
@@ -108,11 +108,13 @@
 			return;
 		}
 		final int changesetStart = followRename ? 0 : df.getChangesetRevisionIndex(0);
-		Collector c = new Collector();
+		Collector c = new Collector(cancellation);
 		FileAnnotation fa = new FileAnnotation(c);
 		HgBlameFacility af = new HgBlameFacility(df);
 		af.annotate(changesetStart, annotateRevision.get(), fa, HgIterateDirection.NewToOld);
 		progress.worked(1);
+		c.throwIfCancelled();
+		cancellation.checkCancelled();
 		ProgressSupport.Sub subProgress = new ProgressSupport.Sub(progress, 1);
 		LineImpl li = new LineImpl();
 		for (int i = 0; i < c.lineRevisions.length; i++) {
@@ -150,11 +152,17 @@
 	private static class Collector implements LineInspector {
 		private int[] lineRevisions;
 		private byte[][] lines;
+		private final CancelSupport cancelSupport;
+		private CancelledException cancelEx;
 		
-		Collector() {
+		Collector(CancelSupport cancellation) {
+			cancelSupport = cancellation;
 		}
 		
 		public void line(int lineNumber, int changesetRevIndex, BlockData lineContent, LineDescriptor ld) {
+			if (cancelEx != null) {
+				return;
+			}
 			if (lineRevisions == null) {
 				lineRevisions = new int [ld.totalLines()];
 				Arrays.fill(lineRevisions, NO_REVISION);
@@ -162,11 +170,22 @@
 			}
 			lineRevisions[lineNumber] = changesetRevIndex;
 			lines[lineNumber] = lineContent.asArray();
+			try {
+				cancelSupport.checkCancelled();
+			} catch (CancelledException ex) {
+				cancelEx = ex;
+			}
 		}
 		
 		public byte[] line(int i) {
 			return lines[i];
 		}
+		
+		public void throwIfCancelled() throws CancelledException {
+			if (cancelEx != null) {
+				throw cancelEx;
+			}
+		}
 	}