try {
result.setAdvertisedRefs(transport.getURI(), conn.getRefsMap());
final Set<Ref> matched = new HashSet<Ref>();
for (final RefSpec spec : toFetch) {
if (spec.getSource() == null)
throw new TransportException(MessageFormat.format(
JGitText.get().sourceRefNotSpecifiedForRefspec, spec));
if (spec.isWildcard())
expandWildcard(spec, matched);
else
expandSingle(spec, matched);
}
Collection<Ref> additionalTags = Collections.<Ref> emptyList();
final TagOpt tagopt = transport.getTagOpt();
if (tagopt == TagOpt.AUTO_FOLLOW)
additionalTags = expandAutoFollowTags();
else if (tagopt == TagOpt.FETCH_TAGS)
expandFetchTags();
final boolean includedTags;
if (!askFor.isEmpty() && !askForIsComplete()) {
fetchObjects(monitor);
includedTags = conn.didFetchIncludeTags();
// Connection was used for object transfer. If we
// do another fetch we must open a new connection.
//
closeConnection(result);
} else {
includedTags = false;
}
if (tagopt == TagOpt.AUTO_FOLLOW && !additionalTags.isEmpty()) {
// There are more tags that we want to follow, but
// not all were asked for on the initial request.
//
have.addAll(askFor.keySet());
askFor.clear();
for (final Ref r : additionalTags) {
ObjectId id = r.getPeeledObjectId();
if (id == null)
id = r.getObjectId();
if (transport.local.hasObject(id))
wantTag(r);
}
if (!askFor.isEmpty() && (!includedTags || !askForIsComplete())) {
reopenConnection();
if (!askFor.isEmpty())
fetchObjects(monitor);
}
}
} finally {
closeConnection(result);
}
final RevWalk walk = new RevWalk(transport.local);
try {
if (monitor instanceof BatchingProgressMonitor) {
((BatchingProgressMonitor) monitor).setDelayStart(
250, TimeUnit.MILLISECONDS);
}
monitor.beginTask(JGitText.get().updatingReferences, localUpdates.size());
if (transport.isRemoveDeletedRefs())
deleteStaleTrackingRefs(result, walk);
for (TrackingRefUpdate u : localUpdates) {
try {
monitor.update(1);
u.update(walk);
result.add(u);
} catch (IOException err) {
throw new TransportException(MessageFormat.format(JGitText
.get().failureUpdatingTrackingRef,
u.getLocalName(), err.getMessage()), err);
}
}
monitor.endTask();
} finally {
walk.release();
}
if (!fetchHeadUpdates.isEmpty()) {
try {
updateFETCH_HEAD(result);
} catch (IOException err) {
throw new TransportException(MessageFormat.format(
JGitText.get().failureUpdatingFETCH_HEAD, err.getMessage()), err);
}
}
}