private void DeleteTrackingRef(FetchResult result, BatchRefUpdate batch, RefSpec spec, Ref localRef) { if (localRef.GetObjectId() == null) { return; } TrackingRefUpdate update = new TrackingRefUpdate(true, spec.GetSource(), localRef .GetName(), localRef.GetObjectId(), ObjectId.ZeroId); result.Add(update); batch.AddCommand(update.AsReceiveCommand()); }
/// <exception cref="NGit.Errors.TransportException"></exception> private void DeleteTrackingRef(FetchResult result, Repository db, RevWalk walk, RefSpec spec, Ref localRef) { string name = localRef.GetName(); try { TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.GetSource(), true, ObjectId .ZeroId, "deleted"); result.Add(u); if (transport.IsDryRun()) { return; } u.Delete(walk); switch (u.GetResult()) { case RefUpdate.Result.NEW: case RefUpdate.Result.NO_CHANGE: case RefUpdate.Result.FAST_FORWARD: case RefUpdate.Result.FORCED: { break; } default: { throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get ().cannotDeleteStaleTrackingRef2, name, u.GetResult().ToString())); } } } catch (IOException e) { throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get ().cannotDeleteStaleTrackingRef, name), e); } }
/// <exception cref="System.IO.IOException"></exception> private void UpdateFETCH_HEAD(FetchResult result) { FilePath meta = transport.local.Directory; if (meta == null) { return; } LockFile Lock = new LockFile(new FilePath(meta, "FETCH_HEAD"), transport.local.FileSystem ); try { if (Lock.Lock()) { TextWriter w = new OutputStreamWriter(Lock.GetOutputStream()); try { foreach (FetchHeadRecord h in fetchHeadUpdates) { h.Write(w); result.Add(h); } } finally { w.Close(); } Lock.Commit(); } } finally { Lock.Unlock(); } }
/// <exception cref="System.NotSupportedException"></exception> /// <exception cref="NGit.Errors.TransportException"></exception> private void ExecuteImp(ProgressMonitor monitor, FetchResult result) { conn = transport.OpenFetch(); try { result.SetAdvertisedRefs(transport.GetURI(), conn.GetRefsMap()); ICollection <Ref> matched = new HashSet <Ref>(); foreach (RefSpec spec in toFetch) { if (spec.GetSource() == null) { throw new TransportException(MessageFormat.Format(JGitText.Get().sourceRefNotSpecifiedForRefspec , spec)); } if (spec.IsWildcard()) { ExpandWildcard(spec, matched); } else { ExpandSingle(spec, matched); } } ICollection <Ref> additionalTags = Sharpen.Collections.EmptyList <Ref>(); TagOpt tagopt = transport.GetTagOpt(); if (tagopt == TagOpt.AUTO_FOLLOW) { additionalTags = ExpandAutoFollowTags(); } else { if (tagopt == TagOpt.FETCH_TAGS) { ExpandFetchTags(); } } bool 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. // Sharpen.Collections.AddAll(have, askFor.Keys); askFor.Clear(); foreach (Ref r in additionalTags) { ObjectId id = r.GetPeeledObjectId(); if (id == null || transport.local.HasObject(id)) { WantTag(r); } } if (!askFor.IsEmpty() && (!includedTags || !AskForIsComplete())) { ReopenConnection(); if (!askFor.IsEmpty()) { FetchObjects(monitor); } } } } finally { CloseConnection(result); } RevWalk walk = new RevWalk(transport.local); try { if (transport.IsRemoveDeletedRefs()) { DeleteStaleTrackingRefs(result, walk); } foreach (TrackingRefUpdate u in localUpdates) { try { u.Update(walk); result.Add(u); } catch (IOException err) { throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingTrackingRef , u.GetLocalName(), err.Message), err); } } } finally { walk.Release(); } if (!fetchHeadUpdates.IsEmpty()) { try { UpdateFETCH_HEAD(result); } catch (IOException err) { throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingFETCH_HEAD , err.Message), err); } } }
/// <exception cref="System.NotSupportedException"></exception> /// <exception cref="NGit.Errors.TransportException"></exception> private void ExecuteImp(ProgressMonitor monitor, FetchResult result) { conn = transport.OpenFetch(); try { result.SetAdvertisedRefs(transport.GetURI(), conn.GetRefsMap()); ICollection<Ref> matched = new HashSet<Ref>(); foreach (RefSpec spec in toFetch) { if (spec.GetSource() == null) { throw new TransportException(MessageFormat.Format(JGitText.Get().sourceRefNotSpecifiedForRefspec , spec)); } if (spec.IsWildcard()) { ExpandWildcard(spec, matched); } else { ExpandSingle(spec, matched); } } ICollection<Ref> additionalTags = Sharpen.Collections.EmptyList<Ref>(); TagOpt tagopt = transport.GetTagOpt(); if (tagopt == TagOpt.AUTO_FOLLOW) { additionalTags = ExpandAutoFollowTags(); } else { if (tagopt == TagOpt.FETCH_TAGS) { ExpandFetchTags(); } } bool 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. // Sharpen.Collections.AddAll(have, askFor.Keys); askFor.Clear(); foreach (Ref r in 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); } RevWalk walk = new RevWalk(transport.local); try { if (monitor is BatchingProgressMonitor) { ((BatchingProgressMonitor)monitor).SetDelayStart(250, TimeUnit.MILLISECONDS); } monitor.BeginTask(JGitText.Get().updatingReferences, localUpdates.Count); if (transport.IsRemoveDeletedRefs()) { DeleteStaleTrackingRefs(result, walk); } foreach (TrackingRefUpdate u in 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.Message), 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.Message), err); } } }
/// <exception cref="System.NotSupportedException"></exception> /// <exception cref="NGit.Errors.TransportException"></exception> private void ExecuteImp(ProgressMonitor monitor, FetchResult result) { conn = transport.OpenFetch(); try { result.SetAdvertisedRefs(transport.GetURI(), conn.GetRefsMap()); ICollection<Ref> matched = new HashSet<Ref>(); foreach (RefSpec spec in toFetch) { if (spec.GetSource() == null) { throw new TransportException(MessageFormat.Format(JGitText.Get().sourceRefNotSpecifiedForRefspec , spec)); } if (spec.IsWildcard()) { ExpandWildcard(spec, matched); } else { ExpandSingle(spec, matched); } } ICollection<Ref> additionalTags = Sharpen.Collections.EmptyList<Ref>(); TagOpt tagopt = transport.GetTagOpt(); if (tagopt == TagOpt.AUTO_FOLLOW) { additionalTags = ExpandAutoFollowTags(); } else { if (tagopt == TagOpt.FETCH_TAGS) { ExpandFetchTags(); } } bool 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. // Sharpen.Collections.AddAll(have, askFor.Keys); askFor.Clear(); foreach (Ref r in 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); } BatchRefUpdate batch = transport.local.RefDatabase.NewBatchUpdate().SetAllowNonFastForwards (true).SetRefLogMessage("fetch", true); RevWalk walk = new RevWalk(transport.local); try { if (monitor is BatchingProgressMonitor) { ((BatchingProgressMonitor)monitor).SetDelayStart(250, TimeUnit.MILLISECONDS); } if (transport.IsRemoveDeletedRefs()) { DeleteStaleTrackingRefs(result, batch); } foreach (TrackingRefUpdate u in localUpdates) { result.Add(u); batch.AddCommand(u.AsReceiveCommand()); } foreach (ReceiveCommand cmd in batch.GetCommands()) { cmd.UpdateType(walk); if (cmd.GetType() == ReceiveCommand.Type.UPDATE_NONFASTFORWARD && cmd is TrackingRefUpdate.Command && !((TrackingRefUpdate.Command)cmd).CanForceUpdate()) { cmd.SetResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD); } } if (transport.IsDryRun()) { foreach (ReceiveCommand cmd_1 in batch.GetCommands()) { if (cmd_1.GetResult() == ReceiveCommand.Result.NOT_ATTEMPTED) { cmd_1.SetResult(ReceiveCommand.Result.OK); } } } else { batch.Execute(walk, monitor); } } catch (IOException err) { throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingTrackingRef , GetFirstFailedRefName(batch), err.Message), err); } finally { walk.Release(); } if (!fetchHeadUpdates.IsEmpty()) { try { UpdateFETCH_HEAD(result); } catch (IOException err) { throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingFETCH_HEAD , err.Message), err); } } }
/// <exception cref="System.NotSupportedException"></exception> /// <exception cref="NGit.Errors.TransportException"></exception> private void ExecuteImp(ProgressMonitor monitor, FetchResult result) { conn = transport.OpenFetch(); try { result.SetAdvertisedRefs(transport.GetURI(), conn.GetRefsMap()); ICollection <Ref> matched = new HashSet <Ref>(); foreach (RefSpec spec in toFetch) { if (spec.GetSource() == null) { throw new TransportException(MessageFormat.Format(JGitText.Get().sourceRefNotSpecifiedForRefspec , spec)); } if (spec.IsWildcard()) { ExpandWildcard(spec, matched); } else { ExpandSingle(spec, matched); } } ICollection <Ref> additionalTags = Sharpen.Collections.EmptyList <Ref>(); TagOpt tagopt = transport.GetTagOpt(); if (tagopt == TagOpt.AUTO_FOLLOW) { additionalTags = ExpandAutoFollowTags(); } else { if (tagopt == TagOpt.FETCH_TAGS) { ExpandFetchTags(); } } bool 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. // Sharpen.Collections.AddAll(have, askFor.Keys); askFor.Clear(); foreach (Ref r in 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); } BatchRefUpdate batch = transport.local.RefDatabase.NewBatchUpdate().SetAllowNonFastForwards (true).SetRefLogMessage("fetch", true); RevWalk walk = new RevWalk(transport.local); try { if (monitor is BatchingProgressMonitor) { ((BatchingProgressMonitor)monitor).SetDelayStart(250, TimeUnit.MILLISECONDS); } if (transport.IsRemoveDeletedRefs()) { DeleteStaleTrackingRefs(result, batch); } foreach (TrackingRefUpdate u in localUpdates) { result.Add(u); batch.AddCommand(u.AsReceiveCommand()); } foreach (ReceiveCommand cmd in batch.GetCommands()) { cmd.UpdateType(walk); if (cmd.GetType() == ReceiveCommand.Type.UPDATE_NONFASTFORWARD && cmd is TrackingRefUpdate.Command && !((TrackingRefUpdate.Command)cmd).CanForceUpdate()) { cmd.SetResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD); } } if (transport.IsDryRun()) { foreach (ReceiveCommand cmd_1 in batch.GetCommands()) { if (cmd_1.GetResult() == ReceiveCommand.Result.NOT_ATTEMPTED) { cmd_1.SetResult(ReceiveCommand.Result.OK); } } } else { batch.Execute(walk, monitor); } } catch (IOException err) { throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingTrackingRef , GetFirstFailedRefName(batch), err.Message), err); } finally { walk.Release(); } if (!fetchHeadUpdates.IsEmpty()) { try { UpdateFETCH_HEAD(result); } catch (IOException err) { throw new TransportException(MessageFormat.Format(JGitText.Get().failureUpdatingFETCH_HEAD , err.Message), err); } } }