private void closeConnection() { if (_connection != null) { _connection.Close(); _connection = null; } }
private void reopenConnection() { if (_connection != null) { return; } _connection = _transport.openFetch(); // Since we opened a new connection we cannot be certain // that the system we connected to has the same exact set // of objects available (think round-robin DNS and mirrors // that aren't updated at the same time). // // We rebuild our askFor list using only the refs that the // new connection has offered to us. // IDictionary <ObjectId, Ref> avail = new Dictionary <ObjectId, Ref>(); foreach (Ref r in _connection.Refs) { if (avail.ContainsKey(r.ObjectId)) { avail[r.ObjectId] = r; } else { avail.Add(r.ObjectId, r); } } ICollection <Ref> wants = new List <Ref>(_askFor.Values); _askFor.Clear(); foreach (Ref want in wants) { Ref newRef = avail[want.ObjectId]; if (newRef != null) { _askFor.Add(newRef.ObjectId, newRef); } else { removeFetchHeadRecord(want.ObjectId); removeTrackingRefUpdate(want.ObjectId); } } }
private void reopenConnection() { if (_connection != null) { return; } _connection = _transport.openFetch(); // Since we opened a new connection we cannot be certain // that the system we connected to has the same exact set // of objects available (think round-robin DNS and mirrors // that aren't updated at the same time). // // We rebuild our askFor list using only the refs that the // new connection has offered to us. // IDictionary<ObjectId, Ref> avail = new Dictionary<ObjectId, Ref>(); foreach (Ref r in _connection.Refs) { avail.Add(r.ObjectId, r); } ICollection<Ref> wants = new List<Ref>(_askFor.Values); _askFor.Clear(); foreach (Ref want in wants) { Ref newRef = avail[want.ObjectId]; if (newRef != null) { _askFor.Add(newRef.ObjectId, newRef); } else { removeFetchHeadRecord(want.ObjectId); removeTrackingRefUpdate(want.ObjectId); } } }
private void executeImp(ProgressMonitor monitor, FetchResult result) { _connection = _transport.openFetch(); try { result.SetAdvertisedRefs(_transport.Uri, _connection.RefsMap); HashSet<Ref> matched = new HashSet<Ref>(); foreach (RefSpec spec in _toFetch) { if (spec.Source == null) throw new TransportException("Source ref not specified for refspec: " + spec); if (spec.Wildcard) { expandWildcard(spec, matched); } else { expandSingle(spec, matched); } } ICollection<Ref> additionalTags = new Collection<Ref>(); TagOpt tagopt = _transport.TagOpt; if (tagopt == TagOpt.AUTO_FOLLOW) { additionalTags = expandAutoFollowTags(); } else if (tagopt == TagOpt.FETCH_TAGS) { expandFetchTags(); } bool includedTags; if (_askFor.Count != 0 && !askForIsComplete()) { fetchObjects(monitor); includedTags = _connection.DidFetchIncludeTags; // Connection was used for object transfer. If we // do another fetch we must open a new connection. // closeConnection(); } else { includedTags = false; } if (tagopt == TagOpt.AUTO_FOLLOW && additionalTags.Count != 0) { // There are more tags that we want to follow, but // not all were asked for on the initial request. foreach(ObjectId key in _askFor.Keys) { _have.Add(key); } _askFor.Clear(); foreach (Ref r in additionalTags) { ObjectId id = r.PeeledObjectId; if (id == null || _transport.Local.HasObject(id)) { wantTag(r); } } if (_askFor.Count != 0 && (!includedTags || !askForIsComplete())) { reopenConnection(); if (_askFor.Count != 0) { fetchObjects(monitor); } } } } finally { closeConnection(); } RevWalk.RevWalk walk = new RevWalk.RevWalk(_transport.Local); if (_transport.RemoveDeletedRefs) { deleteStaleTrackingRefs(result, walk); } foreach (TrackingRefUpdate u in _localUpdates) { try { u.Update(walk); result.Add(u); } catch (IOException err) { throw new TransportException("Failure updating tracking ref " + u.LocalName + ": " + err.Message, err); } } if (_fetchHeadUpdates.Count != 0) { try { updateFETCH_HEAD(result); } catch (IOException err) { throw new TransportException("Failure updating FETCH_HEAD: " + err.Message, err); } } }
private void executeImp(ProgressMonitor monitor, FetchResult result) { _connection = _transport.openFetch(); try { result.SetAdvertisedRefs(_transport.Uri, _connection.RefsMap); HashSet <Ref> matched = new HashSet <Ref>(); foreach (RefSpec spec in _toFetch) { if (spec.Source == null) { throw new TransportException("Source ref not specified for refspec: " + spec); } if (spec.Wildcard) { expandWildcard(spec, matched); } else { expandSingle(spec, matched); } } ICollection <Ref> additionalTags = new Collection <Ref>(); TagOpt tagopt = _transport.TagOpt; if (tagopt == TagOpt.AUTO_FOLLOW) { additionalTags = expandAutoFollowTags(); } else if (tagopt == TagOpt.FETCH_TAGS) { expandFetchTags(); } bool includedTags; if (_askFor.Count != 0 && !askForIsComplete()) { fetchObjects(monitor); includedTags = _connection.DidFetchIncludeTags; // Connection was used for object transfer. If we // do another fetch we must open a new connection. // closeConnection(); } else { includedTags = false; } if (tagopt == TagOpt.AUTO_FOLLOW && additionalTags.Count != 0) { // There are more tags that we want to follow, but // not all were asked for on the initial request. foreach (ObjectId key in _askFor.Keys) { _have.Add(key); } _askFor.Clear(); foreach (Ref r in additionalTags) { ObjectId id = r.PeeledObjectId; if (id == null || _transport.Local.HasObject(id)) { wantTag(r); } } if (_askFor.Count != 0 && (!includedTags || !askForIsComplete())) { reopenConnection(); if (_askFor.Count != 0) { fetchObjects(monitor); } } } } finally { closeConnection(); } using (RevWalk.RevWalk walk = new RevWalk.RevWalk(_transport.Local)) { if (_transport.RemoveDeletedRefs) { deleteStaleTrackingRefs(result, walk); } foreach (TrackingRefUpdate u in _localUpdates) { try { u.Update(walk); result.Add(u); } catch (IOException err) { throw new TransportException("Failure updating tracking ref " + u.LocalName + ": " + err.Message, err); } } } if (_fetchHeadUpdates.Count != 0) { try { updateFETCH_HEAD(result); } catch (IOException err) { throw new TransportException("Failure updating FETCH_HEAD: " + err.Message, err); } } }