comparison src/org/tmatesoft/hg/core/HgIncomingCommand.java @ 366:189dc6dc1c3e

Use exceptions to expose errors reading mercurial data
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Dec 2011 04:43:18 +0100
parents d68dcb3b5f49
children 9517df1ef7ec
comparison
equal deleted inserted replaced
365:3572fcb06473 366:189dc6dc1c3e
98 * Lightweight check for incoming changes, gives only list of revisions to pull. 98 * Lightweight check for incoming changes, gives only list of revisions to pull.
99 * Reported changes are from any branch (limits set by {@link #branch(String)} are not taken into account. 99 * Reported changes are from any branch (limits set by {@link #branch(String)} are not taken into account.
100 * 100 *
101 * @return list of nodes present at remote and missing locally 101 * @return list of nodes present at remote and missing locally
102 * @throws HgRemoteConnectionException when failed to communicate with remote repository 102 * @throws HgRemoteConnectionException when failed to communicate with remote repository
103 * @throws HgInvalidControlFileException FIXME
103 * @throws CancelledException 104 * @throws CancelledException
104 */ 105 */
105 public List<Nodeid> executeLite() throws HgRemoteConnectionException, CancelledException { 106 public List<Nodeid> executeLite() throws HgRemoteConnectionException, HgInvalidControlFileException, CancelledException {
106 LinkedHashSet<Nodeid> result = new LinkedHashSet<Nodeid>(); 107 LinkedHashSet<Nodeid> result = new LinkedHashSet<Nodeid>();
107 RepositoryComparator repoCompare = getComparator(); 108 RepositoryComparator repoCompare = getComparator();
108 for (BranchChain bc : getMissingBranches()) { 109 for (BranchChain bc : getMissingBranches()) {
109 List<Nodeid> missing = repoCompare.visitBranches(bc); 110 List<Nodeid> missing = repoCompare.visitBranches(bc);
110 HashSet<Nodeid> common = new HashSet<Nodeid>(); // ordering is irrelevant 111 HashSet<Nodeid> common = new HashSet<Nodeid>(); // ordering is irrelevant
119 120
120 /** 121 /**
121 * Full information about incoming changes 122 * Full information about incoming changes
122 * 123 *
123 * @throws HgRemoteConnectionException when failed to communicate with remote repository 124 * @throws HgRemoteConnectionException when failed to communicate with remote repository
125 * @throws HgInvalidControlFileException FIXME
124 * @throws HgInvalidFileException to indicate failure working with locally downloaded changes in a bundle file 126 * @throws HgInvalidFileException to indicate failure working with locally downloaded changes in a bundle file
125 * @throws HgCallbackTargetException to re-throw exception from the handler 127 * @throws HgCallbackTargetException to re-throw exception from the handler
126 * @throws CancelledException 128 * @throws CancelledException
127 */ 129 */
128 public void executeFull(final HgChangesetHandler handler) throws HgRemoteConnectionException, HgInvalidFileException, HgCallbackTargetException, CancelledException { 130 public void executeFull(final HgChangesetHandler handler) throws HgRemoteConnectionException, HgInvalidControlFileException, HgInvalidFileException, HgCallbackTargetException, CancelledException {
129 if (handler == null) { 131 if (handler == null) {
130 throw new IllegalArgumentException("Delegate can't be null"); 132 throw new IllegalArgumentException("Delegate can't be null");
131 } 133 }
132 final List<Nodeid> common = getCommon(); 134 final List<Nodeid> common = getCommon();
133 HgBundle changegroup = remoteRepo.getChanges(common); 135 HgBundle changegroup = remoteRepo.getChanges(common);
159 } finally { 161 } finally {
160 ps.done(); 162 ps.done();
161 } 163 }
162 } 164 }
163 165
164 private RepositoryComparator getComparator() throws CancelledException { 166 private RepositoryComparator getComparator() throws HgInvalidControlFileException, CancelledException {
165 if (remoteRepo == null) { 167 if (remoteRepo == null) {
166 throw new IllegalArgumentException("Shall specify remote repository to compare against", null); 168 throw new IllegalArgumentException("Shall specify remote repository to compare against", null);
167 } 169 }
168 if (comparator == null) { 170 if (comparator == null) {
169 comparator = new RepositoryComparator(getParentHelper(), remoteRepo); 171 comparator = new RepositoryComparator(getParentHelper(), remoteRepo);
170 // comparator.compare(context); // XXX meanwhile we use distinct path to calculate common 172 // comparator.compare(context); // XXX meanwhile we use distinct path to calculate common
171 } 173 }
172 return comparator; 174 return comparator;
173 } 175 }
174 176
175 private HgChangelog.ParentWalker getParentHelper() { 177 private HgChangelog.ParentWalker getParentHelper() throws HgInvalidControlFileException {
176 if (parentHelper == null) { 178 if (parentHelper == null) {
177 parentHelper = localRepo.getChangelog().new ParentWalker(); 179 parentHelper = localRepo.getChangelog().new ParentWalker();
178 parentHelper.init(); 180 parentHelper.init();
179 } 181 }
180 return parentHelper; 182 return parentHelper;
181 } 183 }
182 184
183 private List<BranchChain> getMissingBranches() throws HgRemoteConnectionException, CancelledException { 185 private List<BranchChain> getMissingBranches() throws HgRemoteConnectionException, HgInvalidControlFileException, CancelledException {
184 if (missingBranches == null) { 186 if (missingBranches == null) {
185 missingBranches = getComparator().calculateMissingBranches(); 187 missingBranches = getComparator().calculateMissingBranches();
186 } 188 }
187 return missingBranches; 189 return missingBranches;
188 } 190 }
189 191
190 private List<Nodeid> getCommon() throws HgRemoteConnectionException, CancelledException { 192 private List<Nodeid> getCommon() throws HgRemoteConnectionException, HgInvalidControlFileException, CancelledException {
191 // return getComparator(context).getCommon(); 193 // return getComparator(context).getCommon();
192 final LinkedHashSet<Nodeid> common = new LinkedHashSet<Nodeid>(); 194 final LinkedHashSet<Nodeid> common = new LinkedHashSet<Nodeid>();
193 // XXX common can be obtained from repoCompare, but at the moment it would almost duplicate work of calculateMissingBranches 195 // XXX common can be obtained from repoCompare, but at the moment it would almost duplicate work of calculateMissingBranches
194 // once I refactor latter, common shall be taken from repoCompare. 196 // once I refactor latter, common shall be taken from repoCompare.
195 RepositoryComparator repoCompare = getComparator(); 197 RepositoryComparator repoCompare = getComparator();