comparison src/org/tmatesoft/hg/core/HgOutgoingCommand.java @ 215:41a778e3fd31

Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 17 May 2011 00:56:54 +0200
parents 63c9fed4369e
children 6d1804fe0ed7
comparison
equal deleted inserted replaced
214:4252faa556cd 215:41a778e3fd31
22 22
23 import org.tmatesoft.hg.internal.RepositoryComparator; 23 import org.tmatesoft.hg.internal.RepositoryComparator;
24 import org.tmatesoft.hg.repo.HgChangelog; 24 import org.tmatesoft.hg.repo.HgChangelog;
25 import org.tmatesoft.hg.repo.HgRemoteRepository; 25 import org.tmatesoft.hg.repo.HgRemoteRepository;
26 import org.tmatesoft.hg.repo.HgRepository; 26 import org.tmatesoft.hg.repo.HgRepository;
27 import org.tmatesoft.hg.util.CancelSupport;
27 import org.tmatesoft.hg.util.CancelledException; 28 import org.tmatesoft.hg.util.CancelledException;
29 import org.tmatesoft.hg.util.ProgressSupport;
28 30
29 /** 31 /**
30 * Command to find out changes made in a local repository and missing at remote repository. 32 * Command to find out changes made in a local repository and missing at remote repository.
31 * 33 *
32 * @author Artem Tikhomirov 34 * @author Artem Tikhomirov
33 * @author TMate Software Ltd. 35 * @author TMate Software Ltd.
34 */ 36 */
35 public class HgOutgoingCommand { 37 public class HgOutgoingCommand extends HgAbstractCommand<HgOutgoingCommand> {
36 38
37 private final HgRepository localRepo; 39 private final HgRepository localRepo;
38 private HgRemoteRepository remoteRepo; 40 private HgRemoteRepository remoteRepo;
39 @SuppressWarnings("unused") 41 @SuppressWarnings("unused")
40 private boolean includeSubrepo; 42 private boolean includeSubrepo;
88 90
89 /** 91 /**
90 * Lightweight check for outgoing changes. 92 * Lightweight check for outgoing changes.
91 * Reported changes are from any branch (limits set by {@link #branch(String)} are not taken into account. 93 * Reported changes are from any branch (limits set by {@link #branch(String)} are not taken into account.
92 * 94 *
93 * @param context
94 * @return list on local nodes known to be missing at remote server 95 * @return list on local nodes known to be missing at remote server
95 */ 96 */
96 public List<Nodeid> executeLite(Object context) throws HgException, CancelledException { 97 public List<Nodeid> executeLite() throws HgRemoteConnectionException, CancelledException {
97 return getComparator(context).getLocalOnlyRevisions(); 98 final ProgressSupport ps = getProgressSupport(null);
99 try {
100 ps.start(10);
101 return getComparator(new ProgressSupport.Sub(ps, 5), getCancelSupport(null)).getLocalOnlyRevisions();
102 } finally {
103 ps.done();
104 }
98 } 105 }
99 106
100 /** 107 /**
101 * Complete information about outgoing changes 108 * Complete information about outgoing changes
102 * 109 *
103 * @param handler delegate to process changes 110 * @param handler delegate to process changes
104 */ 111 */
105 public void executeFull(final HgChangesetHandler handler) throws HgException, CancelledException { 112 public void executeFull(final HgChangesetHandler handler) throws HgRemoteConnectionException, HgCallbackTargetException, CancelledException {
106 if (handler == null) { 113 if (handler == null) {
107 throw new IllegalArgumentException("Delegate can't be null"); 114 throw new IllegalArgumentException("Delegate can't be null");
108 } 115 }
109 ChangesetTransformer inspector = new ChangesetTransformer(localRepo, handler, getParentHelper()); 116 final ProgressSupport ps = getProgressSupport(handler);
110 inspector.limitBranches(branches); 117 final CancelSupport cs = getCancelSupport(handler);
111 getComparator(handler).visitLocalOnlyRevisions(inspector); 118 try {
119 ps.start(-1);
120 ChangesetTransformer inspector = new ChangesetTransformer(localRepo, handler, getParentHelper(), ps, cs);
121 inspector.limitBranches(branches);
122 getComparator(new ProgressSupport.Sub(ps, 1), cs).visitLocalOnlyRevisions(inspector);
123 inspector.checkFailure();
124 } finally {
125 ps.done();
126 }
112 } 127 }
113 128
114 private RepositoryComparator getComparator(Object context) throws HgException, CancelledException { 129 private RepositoryComparator getComparator(ProgressSupport ps, CancelSupport cs) throws HgRemoteConnectionException, CancelledException {
115 if (remoteRepo == null) { 130 if (remoteRepo == null) {
116 throw new IllegalArgumentException("Shall specify remote repository to compare against"); 131 throw new IllegalArgumentException("Shall specify remote repository to compare against");
117 } 132 }
118 if (comparator == null) { 133 if (comparator == null) {
119 comparator = new RepositoryComparator(getParentHelper(), remoteRepo); 134 comparator = new RepositoryComparator(getParentHelper(), remoteRepo);
120 comparator.compare(context); 135 comparator.compare(ps, cs);
121 } 136 }
122 return comparator; 137 return comparator;
123 } 138 }
124 139
125 private HgChangelog.ParentWalker getParentHelper() { 140 private HgChangelog.ParentWalker getParentHelper() {