comparison src/org/tmatesoft/hg/core/HgIncomingCommand.java @ 427:31a89587eb04

FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 29 Mar 2012 17:14:35 +0200
parents 9c9c442b5f2e
children 1fc0da631200
comparison
equal deleted inserted replaced
426:063b0663495a 427:31a89587eb04
27 27
28 import org.tmatesoft.hg.internal.RepositoryComparator; 28 import org.tmatesoft.hg.internal.RepositoryComparator;
29 import org.tmatesoft.hg.internal.RepositoryComparator.BranchChain; 29 import org.tmatesoft.hg.internal.RepositoryComparator.BranchChain;
30 import org.tmatesoft.hg.repo.HgBundle; 30 import org.tmatesoft.hg.repo.HgBundle;
31 import org.tmatesoft.hg.repo.HgChangelog; 31 import org.tmatesoft.hg.repo.HgChangelog;
32 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
32 import org.tmatesoft.hg.repo.HgInvalidControlFileException; 33 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
33 import org.tmatesoft.hg.repo.HgInvalidFileException;
34 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
35 import org.tmatesoft.hg.repo.HgInvalidStateException; 34 import org.tmatesoft.hg.repo.HgInvalidStateException;
36 import org.tmatesoft.hg.repo.HgRemoteRepository; 35 import org.tmatesoft.hg.repo.HgRemoteRepository;
37 import org.tmatesoft.hg.repo.HgRepository; 36 import org.tmatesoft.hg.repo.HgRepository;
37 import org.tmatesoft.hg.repo.HgRuntimeException;
38 import org.tmatesoft.hg.util.CancelledException; 38 import org.tmatesoft.hg.util.CancelledException;
39 import org.tmatesoft.hg.util.ProgressSupport; 39 import org.tmatesoft.hg.util.ProgressSupport;
40 40
41 /** 41 /**
42 * Command to find out changes available in a remote repository, missing locally. 42 * Command to find out changes available in a remote repository, missing locally.
101 * Lightweight check for incoming changes, gives only list of revisions to pull. 101 * Lightweight check for incoming changes, gives only list of revisions to pull.
102 * Reported changes are from any branch (limits set by {@link #branch(String)} are not taken into account. 102 * Reported changes are from any branch (limits set by {@link #branch(String)} are not taken into account.
103 * 103 *
104 * @return list of nodes present at remote and missing locally 104 * @return list of nodes present at remote and missing locally
105 * @throws HgRemoteConnectionException when failed to communicate with remote repository 105 * @throws HgRemoteConnectionException when failed to communicate with remote repository
106 * @throws HgInvalidControlFileException if access to revlog index/data entry failed 106 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
107 * @throws CancelledException if execution of the command was cancelled 107 * @throws CancelledException if execution of the command was cancelled
108 */ 108 */
109 public List<Nodeid> executeLite() throws HgRemoteConnectionException, HgInvalidControlFileException, CancelledException { 109 public List<Nodeid> executeLite() throws HgException, CancelledException {
110 LinkedHashSet<Nodeid> result = new LinkedHashSet<Nodeid>(); 110 try {
111 RepositoryComparator repoCompare = getComparator(); 111 LinkedHashSet<Nodeid> result = new LinkedHashSet<Nodeid>();
112 for (BranchChain bc : getMissingBranches()) { 112 RepositoryComparator repoCompare = getComparator();
113 List<Nodeid> missing = repoCompare.visitBranches(bc); 113 for (BranchChain bc : getMissingBranches()) {
114 HashSet<Nodeid> common = new HashSet<Nodeid>(); // ordering is irrelevant 114 List<Nodeid> missing = repoCompare.visitBranches(bc);
115 repoCompare.collectKnownRoots(bc, common); 115 HashSet<Nodeid> common = new HashSet<Nodeid>(); // ordering is irrelevant
116 // missing could only start with common elements. Once non-common, rest is just distinct branch revision trails. 116 repoCompare.collectKnownRoots(bc, common);
117 for (Iterator<Nodeid> it = missing.iterator(); it.hasNext() && common.contains(it.next()); it.remove()) ; 117 // missing could only start with common elements. Once non-common, rest is just distinct branch revision trails.
118 result.addAll(missing); 118 for (Iterator<Nodeid> it = missing.iterator(); it.hasNext() && common.contains(it.next()); it.remove()) ;
119 } 119 result.addAll(missing);
120 ArrayList<Nodeid> rv = new ArrayList<Nodeid>(result); 120 }
121 return rv; 121 ArrayList<Nodeid> rv = new ArrayList<Nodeid>(result);
122 return rv;
123 } catch (HgRuntimeException ex) {
124 throw new HgLibraryFailureException(ex);
125 }
122 } 126 }
123 127
124 /** 128 /**
125 * Full information about incoming changes 129 * Full information about incoming changes
126 * 130 *
127 * @throws HgRemoteConnectionException when failed to communicate with remote repository
128 * @throws HgInvalidControlFileException if access to revlog index/data entry failed
129 * @throws HgInvalidFileException to indicate failure working with locally downloaded changes in a bundle file
130 * @throws HgCallbackTargetException to re-throw exception from the handler 131 * @throws HgCallbackTargetException to re-throw exception from the handler
132 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
131 * @throws CancelledException if execution of the command was cancelled 133 * @throws CancelledException if execution of the command was cancelled
132 */ 134 */
133 public void executeFull(final HgChangesetHandler handler) throws HgRemoteConnectionException, HgInvalidControlFileException, HgInvalidFileException, HgCallbackTargetException, CancelledException { 135 public void executeFull(final HgChangesetHandler handler) throws HgCallbackTargetException, HgException, CancelledException {
134 if (handler == null) { 136 if (handler == null) {
135 throw new IllegalArgumentException("Delegate can't be null"); 137 throw new IllegalArgumentException("Delegate can't be null");
136 } 138 }
137 final List<Nodeid> common = getCommon(); 139 final List<Nodeid> common = getCommon();
138 HgBundle changegroup = remoteRepo.getChanges(common); 140 HgBundle changegroup = remoteRepo.getChanges(common);
159 } 161 }
160 transformer.next(localIndex++, nodeid, cset); 162 transformer.next(localIndex++, nodeid, cset);
161 } 163 }
162 }); 164 });
163 transformer.checkFailure(); 165 transformer.checkFailure();
166 } catch (HgRuntimeException ex) {
167 throw new HgLibraryFailureException(ex);
164 } finally { 168 } finally {
165 ps.done(); 169 ps.done();
166 } 170 }
167 } 171 }
168 172