Mercurial > jhg
comparison src/org/tmatesoft/hg/core/HgAnnotateCommand.java @ 581:0890628ed51e
Progress/cancel support in new commands
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 22 Apr 2013 16:02:17 +0200 |
parents | c4fd1037bc6f |
children | 90df078d6418 |
comparison
equal
deleted
inserted
replaced
580:bd5926e24aa3 | 581:0890628ed51e |
---|---|
28 import org.tmatesoft.hg.internal.FileAnnotation.LineInspector; | 28 import org.tmatesoft.hg.internal.FileAnnotation.LineInspector; |
29 import org.tmatesoft.hg.repo.HgBlameFacility.BlockData; | 29 import org.tmatesoft.hg.repo.HgBlameFacility.BlockData; |
30 import org.tmatesoft.hg.repo.HgBlameFacility; | 30 import org.tmatesoft.hg.repo.HgBlameFacility; |
31 import org.tmatesoft.hg.repo.HgDataFile; | 31 import org.tmatesoft.hg.repo.HgDataFile; |
32 import org.tmatesoft.hg.repo.HgRepository; | 32 import org.tmatesoft.hg.repo.HgRepository; |
33 import org.tmatesoft.hg.util.CancelSupport; | |
33 import org.tmatesoft.hg.util.CancelledException; | 34 import org.tmatesoft.hg.util.CancelledException; |
34 import org.tmatesoft.hg.util.Path; | 35 import org.tmatesoft.hg.util.Path; |
36 import org.tmatesoft.hg.util.ProgressSupport; | |
35 | 37 |
36 /** | 38 /** |
37 * WORK IN PROGRESS. UNSTABLE API | 39 * WORK IN PROGRESS. UNSTABLE API |
38 * | 40 * |
39 * 'hg annotate' counterpart, report origin revision and file line-by-line | 41 * 'hg annotate' counterpart, report origin revision and file line-by-line |
95 throw new IllegalArgumentException(); | 97 throw new IllegalArgumentException(); |
96 } | 98 } |
97 if (file == null) { | 99 if (file == null) { |
98 throw new HgBadArgumentException("Command needs file argument", null); | 100 throw new HgBadArgumentException("Command needs file argument", null); |
99 } | 101 } |
102 final ProgressSupport progress = getProgressSupport(inspector); | |
103 final CancelSupport cancellation = getCancelSupport(inspector, true); | |
104 cancellation.checkCancelled(); | |
105 progress.start(2); | |
100 HgDataFile df = repo.getFileNode(file); | 106 HgDataFile df = repo.getFileNode(file); |
101 if (!df.exists()) { | 107 if (!df.exists()) { |
102 return; | 108 return; |
103 } | 109 } |
104 final int changesetStart = followRename ? 0 : df.getChangesetRevisionIndex(0); | 110 final int changesetStart = followRename ? 0 : df.getChangesetRevisionIndex(0); |
105 Collector c = new Collector(); | 111 Collector c = new Collector(); |
106 FileAnnotation fa = new FileAnnotation(c); | 112 FileAnnotation fa = new FileAnnotation(c); |
107 HgBlameFacility af = new HgBlameFacility(df); | 113 HgBlameFacility af = new HgBlameFacility(df); |
108 af.annotate(changesetStart, annotateRevision.get(), fa, HgIterateDirection.NewToOld); | 114 af.annotate(changesetStart, annotateRevision.get(), fa, HgIterateDirection.NewToOld); |
115 progress.worked(1); | |
116 ProgressSupport.Sub subProgress = new ProgressSupport.Sub(progress, 1); | |
109 LineImpl li = new LineImpl(); | 117 LineImpl li = new LineImpl(); |
110 for (int i = 0; i < c.lineRevisions.length; i++) { | 118 for (int i = 0; i < c.lineRevisions.length; i++) { |
111 li.init(i+1, c.lineRevisions[i], c.line(i)); | 119 li.init(i+1, c.lineRevisions[i], c.line(i)); |
112 inspector.next(li); | 120 inspector.next(li); |
121 subProgress.worked(1); | |
122 cancellation.checkCancelled(); | |
113 } | 123 } |
124 subProgress.done(); | |
125 progress.done(); | |
114 } | 126 } |
115 | 127 |
116 /** | 128 /** |
117 * Callback to receive annotated lines | 129 * Callback to receive annotated lines |
118 */ | 130 */ |