示例#1
0
 /// <summary>
 /// Perform push operation between local and remote repository - set remote
 /// refs appropriately, send needed objects and update local tracking refs.
 /// </summary>
 /// <remarks>
 /// Perform push operation between local and remote repository - set remote
 /// refs appropriately, send needed objects and update local tracking refs.
 /// <p>
 /// When
 /// <see cref="Transport.IsDryRun()">Transport.IsDryRun()</see>
 /// is true, result of this operation is
 /// just estimation of real operation result, no real action is performed.
 /// </remarks>
 /// <param name="monitor">progress monitor used for feedback about operation.</param>
 /// <returns>result of push operation with complete status description.</returns>
 /// <exception cref="System.NotSupportedException">when push operation is not supported by provided transport.
 ///     </exception>
 /// <exception cref="NGit.Errors.TransportException">
 /// when some error occurred during operation, like I/O, protocol
 /// error, or local database consistency error.
 /// </exception>
 internal virtual PushResult Execute(ProgressMonitor monitor)
 {
     try
     {
         monitor.BeginTask(PROGRESS_OPENING_CONNECTION, ProgressMonitor.UNKNOWN);
         PushResult res = new PushResult();
         connection = transport.OpenPush();
         try
         {
             res.SetAdvertisedRefs(transport.GetURI(), connection.GetRefsMap());
             res.SetRemoteUpdates(toPush);
             monitor.EndTask();
             IDictionary <string, RemoteRefUpdate> preprocessed = PrepareRemoteUpdates();
             if (transport.IsDryRun())
             {
                 ModifyUpdatesForDryRun();
             }
             else
             {
                 if (!preprocessed.IsEmpty())
                 {
                     connection.Push(monitor, preprocessed);
                 }
             }
         }
         finally
         {
             connection.Close();
             res.AddMessages(connection.GetMessages());
         }
         if (!transport.IsDryRun())
         {
             UpdateTrackingRefs();
         }
         foreach (RemoteRefUpdate rru in toPush.Values)
         {
             TrackingRefUpdate tru = rru.GetTrackingRefUpdate();
             if (tru != null)
             {
                 res.Add(tru);
             }
         }
         return(res);
     }
     finally
     {
         walker.Release();
     }
 }
 internal WalkPushConnection(WalkTransport walkTransport, WalkRemoteObjectDatabase
                             w)
 {
     transport = (NGit.Transport.Transport)walkTransport;
     local     = transport.local;
     uri       = transport.GetURI();
     dest      = w;
 }
示例#3
0
        /// <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);
                }
            }
        }
		internal WalkPushConnection(WalkTransport walkTransport, WalkRemoteObjectDatabase
			 w)
		{
			transport = (NGit.Transport.Transport)walkTransport;
			local = transport.local;
			uri = transport.GetURI();
			dest = w;
		}
示例#5
0
        /// <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);
                }
            }
        }