internal PullResult(FetchResult fetchResult, string fetchedFrom, MergeCommandResult mergeResult) { this.fetchResult = fetchResult; this.fetchedFrom = fetchedFrom; this.mergeResult = mergeResult; }
internal PullResult(FetchResult fetchResult, string fetchedFrom, RebaseResult rebaseResult ) { this.fetchResult = fetchResult; this.fetchedFrom = fetchedFrom; this.mergeResult = null; this.rebaseResult = rebaseResult; }
/// <exception cref="NGit.Errors.TransportException"></exception> private void DeleteStaleTrackingRefs(FetchResult result, RevWalk walk) { Repository db = transport.local; foreach (Ref @ref in db.GetAllRefs().Values) { string refname = @ref.GetName(); foreach (RefSpec spec in toFetch) { if (spec.MatchDestination(refname)) { RefSpec s = spec.ExpandFromDestination(refname); if (result.GetAdvertisedRef(s.GetSource()) == null) { DeleteTrackingRef(result, db, walk, s, @ref); } } } } }
/// <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); } } }
private void CloseConnection(FetchResult result) { if (conn != null) { conn.Close(); result.AddMessages(conn.GetMessages()); conn = null; } }
/// <exception cref="System.NotSupportedException"></exception> /// <exception cref="NGit.Errors.TransportException"></exception> internal virtual void Execute(ProgressMonitor monitor, FetchResult result) { askFor.Clear(); localUpdates.Clear(); fetchHeadUpdates.Clear(); packLocks.Clear(); try { ExecuteImp(monitor, result); } finally { try { foreach (PackLock Lock in packLocks) { Lock.Unlock(); } } catch (IOException e) { throw new TransportException(e.Message, e); } } }
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="System.IO.IOException"></exception> private void DeleteStaleTrackingRefs(FetchResult result, BatchRefUpdate batch) { foreach (Ref @ref in LocalRefs().Values) { string refname = @ref.GetName(); foreach (RefSpec spec in toFetch) { if (spec.MatchDestination(refname)) { RefSpec s = spec.ExpandFromDestination(refname); if (result.GetAdvertisedRef(s.GetSource()) == null) { DeleteTrackingRef(result, batch, s, @ref); } } } } }
/// <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); } } }
/// <summary>Fetch objects and refs from the remote repository to the local one.</summary> /// <remarks> /// Fetch objects and refs from the remote repository to the local one. /// <p> /// This is a utility function providing standard fetch behavior. Local /// tracking refs associated with the remote repository are automatically /// updated if this transport was created from a /// <see cref="RemoteConfig">RemoteConfig</see> /// with /// fetch RefSpecs defined. /// </remarks> /// <param name="monitor"> /// progress monitor to inform the user about our processing /// activity. Must not be null. Use /// <see cref="NGit.NullProgressMonitor">NGit.NullProgressMonitor</see> /// if /// progress updates are not interesting or necessary. /// </param> /// <param name="toFetch"> /// specification of refs to fetch locally. May be null or the /// empty collection to use the specifications from the /// RemoteConfig. Source for each RefSpec can't be null. /// </param> /// <returns>information describing the tracking refs updated.</returns> /// <exception cref="System.NotSupportedException"> /// this transport implementation does not support fetching /// objects. /// </exception> /// <exception cref="NGit.Errors.TransportException"> /// the remote connection could not be established or object /// copying (if necessary) failed or update specification was /// incorrect. /// </exception> public virtual FetchResult Fetch(ProgressMonitor monitor, ICollection<RefSpec> toFetch ) { if (toFetch == null || toFetch.IsEmpty()) { // If the caller did not ask for anything use the defaults. // if (fetch.IsEmpty()) { throw new TransportException(JGitText.Get().nothingToFetch); } toFetch = fetch; } else { if (!fetch.IsEmpty()) { // If the caller asked for something specific without giving // us the local tracking branch see if we can update any of // the local tracking branches without incurring additional // object transfer overheads. // ICollection<RefSpec> tmp = new AList<RefSpec>(toFetch); foreach (RefSpec requested in toFetch) { string reqSrc = requested.GetSource(); foreach (RefSpec configured in fetch) { string cfgSrc = configured.GetSource(); string cfgDst = configured.GetDestination(); if (cfgSrc.Equals(reqSrc) && cfgDst != null) { tmp.AddItem(configured); break; } } } toFetch = tmp; } } FetchResult result = new FetchResult(); new FetchProcess(this, toFetch).Execute(monitor, result); return result; }
/// <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); } } }