comparison src/org/tmatesoft/hg/core/HgIncomingCommand.java @ 628:6526d8adbc0f

Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 22 May 2013 15:52:31 +0200
parents 2f9ed6bcefa2
children 822f3a83ff57
comparison
equal deleted inserted replaced
627:5153eb73b18d 628:6526d8adbc0f
1 /* 1 /*
2 * Copyright (c) 2011-2012 TMate Software Ltd 2 * Copyright (c) 2011-2013 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
29 import org.tmatesoft.hg.internal.RepositoryComparator; 29 import org.tmatesoft.hg.internal.RepositoryComparator;
30 import org.tmatesoft.hg.internal.RepositoryComparator.BranchChain; 30 import org.tmatesoft.hg.internal.RepositoryComparator.BranchChain;
31 import org.tmatesoft.hg.repo.HgBundle; 31 import org.tmatesoft.hg.repo.HgBundle;
32 import org.tmatesoft.hg.repo.HgChangelog; 32 import org.tmatesoft.hg.repo.HgChangelog;
33 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; 33 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
34 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
35 import org.tmatesoft.hg.repo.HgInvalidStateException; 34 import org.tmatesoft.hg.repo.HgInvalidStateException;
35 import org.tmatesoft.hg.repo.HgParentChildMap;
36 import org.tmatesoft.hg.repo.HgRemoteRepository; 36 import org.tmatesoft.hg.repo.HgRemoteRepository;
37 import org.tmatesoft.hg.repo.HgRepository; 37 import org.tmatesoft.hg.repo.HgRepository;
38 import org.tmatesoft.hg.repo.HgRuntimeException; 38 import org.tmatesoft.hg.repo.HgRuntimeException;
39 import org.tmatesoft.hg.repo.HgParentChildMap;
40 import org.tmatesoft.hg.util.CancelledException; 39 import org.tmatesoft.hg.util.CancelledException;
41 import org.tmatesoft.hg.util.ProgressSupport; 40 import org.tmatesoft.hg.util.ProgressSupport;
42 41
43 /** 42 /**
44 * Command to find out changes available in a remote repository, missing locally. 43 * Command to find out changes available in a remote repository, missing locally.
136 */ 135 */
137 public void executeFull(final HgChangesetHandler handler) throws HgCallbackTargetException, HgException, CancelledException { 136 public void executeFull(final HgChangesetHandler handler) throws HgCallbackTargetException, HgException, CancelledException {
138 if (handler == null) { 137 if (handler == null) {
139 throw new IllegalArgumentException("Delegate can't be null"); 138 throw new IllegalArgumentException("Delegate can't be null");
140 } 139 }
141 final List<Nodeid> common = getCommon();
142 HgBundle changegroup = remoteRepo.getChanges(common);
143 final ProgressSupport ps = getProgressSupport(handler); 140 final ProgressSupport ps = getProgressSupport(handler);
144 try { 141 try {
142 final List<Nodeid> common = getCommon();
143 HgBundle changegroup = remoteRepo.getChanges(common);
145 final ChangesetTransformer transformer = new ChangesetTransformer(localRepo, handler, getParentHelper(), ps, getCancelSupport(handler, true)); 144 final ChangesetTransformer transformer = new ChangesetTransformer(localRepo, handler, getParentHelper(), ps, getCancelSupport(handler, true));
146 transformer.limitBranches(branches); 145 transformer.limitBranches(branches);
147 changegroup.changes(localRepo, new HgChangelog.Inspector() { 146 changegroup.changes(localRepo, new HgChangelog.Inspector() {
148 private int localIndex; 147 private int localIndex;
149 private final HgParentChildMap<HgChangelog> parentHelper; 148 private final HgParentChildMap<HgChangelog> parentHelper;
152 parentHelper = getParentHelper(); 151 parentHelper = getParentHelper();
153 // new revisions, if any, would be added after all existing, and would get numbered started with last+1 152 // new revisions, if any, would be added after all existing, and would get numbered started with last+1
154 localIndex = localRepo.getChangelog().getRevisionCount(); 153 localIndex = localRepo.getChangelog().getRevisionCount();
155 } 154 }
156 155
157 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { 156 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) throws HgRuntimeException {
158 if (parentHelper.knownNode(nodeid)) { 157 if (parentHelper.knownNode(nodeid)) {
159 if (!common.contains(nodeid)) { 158 if (!common.contains(nodeid)) {
160 throw new HgInvalidStateException("Bundle shall not report known nodes other than roots we've supplied"); 159 throw new HgInvalidStateException("Bundle shall not report known nodes other than roots we've supplied");
161 } 160 }
162 return; 161 return;
170 } finally { 169 } finally {
171 ps.done(); 170 ps.done();
172 } 171 }
173 } 172 }
174 173
175 private RepositoryComparator getComparator() throws HgInvalidControlFileException, CancelledException { 174 private RepositoryComparator getComparator() throws CancelledException, HgRuntimeException {
176 if (remoteRepo == null) { 175 if (remoteRepo == null) {
177 throw new IllegalArgumentException("Shall specify remote repository to compare against", null); 176 throw new IllegalArgumentException("Shall specify remote repository to compare against", null);
178 } 177 }
179 if (comparator == null) { 178 if (comparator == null) {
180 comparator = new RepositoryComparator(getParentHelper(), remoteRepo); 179 comparator = new RepositoryComparator(getParentHelper(), remoteRepo);
181 // comparator.compare(context); // XXX meanwhile we use distinct path to calculate common 180 // comparator.compare(context); // XXX meanwhile we use distinct path to calculate common
182 } 181 }
183 return comparator; 182 return comparator;
184 } 183 }
185 184
186 private HgParentChildMap<HgChangelog> getParentHelper() throws HgInvalidControlFileException { 185 private HgParentChildMap<HgChangelog> getParentHelper() throws HgRuntimeException {
187 if (parentHelper == null) { 186 if (parentHelper == null) {
188 parentHelper = new HgParentChildMap<HgChangelog>(localRepo.getChangelog()); 187 parentHelper = new HgParentChildMap<HgChangelog>(localRepo.getChangelog());
189 parentHelper.init(); 188 parentHelper.init();
190 } 189 }
191 return parentHelper; 190 return parentHelper;
192 } 191 }
193 192
194 private List<BranchChain> getMissingBranches() throws HgRemoteConnectionException, HgInvalidControlFileException, CancelledException { 193 private List<BranchChain> getMissingBranches() throws HgRemoteConnectionException, CancelledException, HgRuntimeException {
195 if (missingBranches == null) { 194 if (missingBranches == null) {
196 missingBranches = getComparator().calculateMissingBranches(); 195 missingBranches = getComparator().calculateMissingBranches();
197 } 196 }
198 return missingBranches; 197 return missingBranches;
199 } 198 }
200 199
201 private List<Nodeid> getCommon() throws HgRemoteConnectionException, HgInvalidControlFileException, CancelledException { 200 private List<Nodeid> getCommon() throws HgRemoteConnectionException, CancelledException, HgRuntimeException {
202 // return getComparator(context).getCommon(); 201 // return getComparator(context).getCommon();
203 final LinkedHashSet<Nodeid> common = new LinkedHashSet<Nodeid>(); 202 final LinkedHashSet<Nodeid> common = new LinkedHashSet<Nodeid>();
204 // XXX common can be obtained from repoCompare, but at the moment it would almost duplicate work of calculateMissingBranches 203 // XXX common can be obtained from repoCompare, but at the moment it would almost duplicate work of calculateMissingBranches
205 // once I refactor latter, common shall be taken from repoCompare. 204 // once I refactor latter, common shall be taken from repoCompare.
206 RepositoryComparator repoCompare = getComparator(); 205 RepositoryComparator repoCompare = getComparator();