protected void showFetchResult(Transport.Transport tn, FetchResult r)
        {
            bool shownURI = false;
            foreach (TrackingRefUpdate u in r.TrackingRefUpdates)
            {
                if (!verbose && u.Result == RefUpdate.RefUpdateResult.NoChange)
                    continue;

                char type = shortTypeOf(u.Result);
                string longType = longTypeOf(u);
                string src = AbbreviateRef(u.RemoteName, false);
                string dst = AbbreviateRef(u.LocalName, true);

                if (!shownURI)
                {
                    streamOut.Write("From ");
                    streamOut.WriteLine(tn.Uri);
                    shownURI = true;
                }

                streamOut.WriteLine(" " + type + " " + longType + " " + src + " -> " + dst);
            }
        }
Esempio n. 2
0
        internal virtual void execute(ProgressMonitor monitor, FetchResult result)
        {
            _askFor.Clear();
            _localUpdates.Clear();
            _fetchHeadUpdates.Clear();
            _packLocks.Clear();

            try
            {
                executeImp(monitor, result);
            }
            finally
            {
                foreach (PackLock @lock in _packLocks)
                {
                    if (@lock != null)
                        @lock.Unlock();
                }
            }
        }
Esempio n. 3
0
        private void updateFETCH_HEAD(FetchResult result)
        {
            LockFile @lock = new LockFile(new FileInfo(Path.Combine(_transport.Local.Directory.FullName, "FETCH_HEAD")));
            try
            {
                if (@lock.Lock())
                {
                    StreamWriter w = new StreamWriter(@lock.GetOutputStream());

                    try
                    {
                        foreach (FetchHeadRecord h in _fetchHeadUpdates)
                        {
                            h.Write(w);
                            result.Add(h);
                        }
                    }
                    finally
                    {
                        w.Close();
                    }

                    @lock.Commit();
                }
            }
            finally
            {
                @lock.Unlock();
            }
        }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        private void deleteTrackingRef(FetchResult result, Repository db, RevWalk.RevWalk walk, RefSpec spec, Ref localRef)
        {
            string name = localRef.Name;
            try
            {
                TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.Source, true, ObjectId.ZeroId, "deleted");
                result.Add(u);
                if (_transport.DryRun)
                {
                    return;
                }

                u.Delete(walk);

                switch (u.Result)
                {
                    case RefUpdate.RefUpdateResult.New:
                    case RefUpdate.RefUpdateResult.NoChange:
                    case RefUpdate.RefUpdateResult.FastForward:
                    case RefUpdate.RefUpdateResult.Forced:
                        break;

                    default:
                        throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name + ": " + u.Result.ToString());
                }
            }
            catch (System.IO.IOException e)
            {
                throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name, e);
            }
        }
Esempio n. 6
0
 private void deleteStaleTrackingRefs(FetchResult result, RevWalk.RevWalk walk)
 {
     Repository db = _transport.Local;
     foreach (Ref @ref in db.getAllRefs().Values)
     {
         string refname = @ref.Name;
         foreach (RefSpec spec in _toFetch)
         {
             if (spec.MatchDestination(refname))
             {
                 RefSpec s = spec.ExpandFromDestination(refname);
                 if (result.GetAdvertisedRef(s.Source) == null)
                 {
                     deleteTrackingRef(result, db, walk, s, @ref);
                 }
             }
         }
     }
 }
Esempio n. 7
0
 private static Ref guessHEAD(FetchResult result)
 {
     Ref idHEAD = result.GetAdvertisedRef(Constants.HEAD);
     List<Ref> availableRefs = new List<Ref>();
     Ref head = null;
     foreach (Ref r in result.AdvertisedRefs.Values)
     {
         string n = r.Name;
         if (!n.StartsWith(Constants.R_HEADS))
             continue;
         availableRefs.Add(r);
         if (idHEAD == null || head != null)
             continue;
         if (r.ObjectId.Equals(idHEAD.ObjectId))
             head = r;
     }
     availableRefs.Sort(RefComparator.INSTANCE);
     if (idHEAD != null && head == null)
         head = idHEAD;
     return head;
 }