Example #1
0
 private static string GetFirstFailedRefName(BatchRefUpdate batch)
 {
     foreach (ReceiveCommand cmd in batch.GetCommands())
     {
         if (cmd.GetResult() != ReceiveCommand.Result.OK)
         {
             return(cmd.GetRefName());
         }
     }
     return(string.Empty);
 }
Example #2
0
        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());
        }
Example #3
0
 /// <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);
                 }
             }
         }
     }
 }
Example #4
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);
                }
            }
        }