Transfers object data through a dumb transport. Implementations are responsible for resolving path names relative to the objects/ subdirectory of a single remote Git repository or naked object database and make the content available as a Java input stream for reading during fetch. The actual object traversal logic to determine the names of files to retrieve is handled through the generic, protocol independent WalkFetchConnection.
Inheritance: IDisposable
        public WalkFetchConnection(IWalkTransport t, WalkRemoteObjectDatabase w)
        {
            _idBuffer = new MutableObjectId();
            _objectDigest = Constants.newMessageDigest();

            var wt = (Transport)t;
            _local = wt.Local;
            _objCheck = wt.CheckFetchedObjects ? new ObjectChecker() : null;

            _remotes = new List<WalkRemoteObjectDatabase> { w };

            _unfetchedPacks = new LinkedList<RemotePack>();
            _packsConsidered = new List<string>();

            _noPacksYet = new LinkedList<WalkRemoteObjectDatabase>();
            _noPacksYet.AddFirst(w);

            _noAlternatesYet = new LinkedList<WalkRemoteObjectDatabase>();
            _noAlternatesYet.AddFirst(w);

            _fetchErrors = new Dictionary<ObjectId, List<Exception>>();
            _packLocks = new List<PackLock>(4);

            _revWalk = new RevWalk.RevWalk(_local);
            _treeWalk = new TreeWalk.TreeWalk(_local);

            COMPLETE = _revWalk.newFlag("COMPLETE");
            IN_WORK_QUEUE = _revWalk.newFlag("IN_WORK_QUEUE");
            LOCALLY_SEEN = _revWalk.newFlag("LOCALLY_SEEN");

            _localCommitQueue = new DateRevQueue();
            _workQueue = new LinkedList<ObjectId>();
        }
 public WalkPushConnection(IWalkTransport walkTransport, WalkRemoteObjectDatabase w)
 {
     var t = (Transport) walkTransport;
     _local = t.Local;
     _uri = t.Uri;
     _dest = w;
 }
        public WalkPushConnection(IWalkTransport walkTransport, WalkRemoteObjectDatabase w)
        {
            var t = (Transport)walkTransport;

            _local = t.Local;
            _uri   = t.Uri;
            _dest  = w;
        }
Exemple #4
0
 private bool DownloadLooseObject(AnyObjectId id, string looseName, WalkRemoteObjectDatabase remote)
 {
     try
     {
         byte[] compressed = remote.open(looseName).toArray();
         VerifyLooseObject(id, compressed);
         SaveLooseObject(id, compressed);
         return(true);
     }
     catch (FileNotFoundException e)
     {
         RecordError(id, e);
         return(false);
     }
     catch (IOException e)
     {
         throw new TransportException("Cannot download " + id.Name, e);
     }
 }
 private bool DownloadLooseObject(AnyObjectId id, string looseName, WalkRemoteObjectDatabase remote)
 {
     try
     {
         byte[] compressed = remote.open(looseName).toArray();
         VerifyLooseObject(id, compressed);
         SaveLooseObject(id, compressed);
         return(true);
     }
     catch (FileNotFoundException e)
     {
         // Not available in a loose format from this alternate?
         // Try another strategy to get the object.
         //
         RecordError(id, e);
         return(false);
     }
     catch (IOException e)
     {
         throw new TransportException("Cannot download " + id.Name, e);
     }
 }
Exemple #6
0
        public WalkFetchConnection(IWalkTransport t, WalkRemoteObjectDatabase w)
        {
            _idBuffer     = new MutableObjectId();
            _objectDigest = Constants.newMessageDigest();

            var wt = (Transport)t;

            _local    = wt.Local;
            _objCheck = wt.CheckFetchedObjects ? new ObjectChecker() : null;

            _remotes = new List <WalkRemoteObjectDatabase> {
                w
            };

            _unfetchedPacks  = new LinkedList <RemotePack>();
            _packsConsidered = new List <string>();

            _noPacksYet = new LinkedList <WalkRemoteObjectDatabase>();
            _noPacksYet.AddFirst(w);

            _noAlternatesYet = new LinkedList <WalkRemoteObjectDatabase>();
            _noAlternatesYet.AddFirst(w);

            _fetchErrors = new Dictionary <ObjectId, List <Exception> >();
            _packLocks   = new List <PackLock>(4);

            _revWalk  = new RevWalk.RevWalk(_local);
            _treeWalk = new TreeWalk.TreeWalk(_local);

            COMPLETE      = _revWalk.newFlag("COMPLETE");
            IN_WORK_QUEUE = _revWalk.newFlag("IN_WORK_QUEUE");
            LOCALLY_SEEN  = _revWalk.newFlag("LOCALLY_SEEN");

            _localCommitQueue = new DateRevQueue();
            _workQueue        = new LinkedList <ObjectId>();
        }
Exemple #7
0
 public PushRefWriter(IEnumerable <Ref> refs, WalkRemoteObjectDatabase dest)
     : base(refs)
 {
     _dest = dest;
 }
 public PushRefWriter(IEnumerable<Ref> refs, WalkRemoteObjectDatabase dest)
     : base(refs)
 {
     _dest = dest;
 }
            public RemotePack(string lockMessage, List<PackLock> packLocks, ObjectChecker oC, Repository r, WalkRemoteObjectDatabase c, string pn)
            {
                _lockMessage = lockMessage;
                _packLocks = packLocks;
                _objCheck = oC;
                _local = r;
                DirectoryInfo objdir = _local.ObjectsDirectory;
                _connection = c;
                PackName = pn;
                _idxName = IndexPack.GetIndexFileName(PackName.Slice(0, PackName.Length - 5));

                string tn = _idxName;
                if (tn.StartsWith("pack-"))
                {
                    tn = tn.Substring(5);
                }

                if (tn.EndsWith(IndexPack.IndexSuffix))
                {
                    tn = tn.Slice(0, tn.Length - 4);
                }

                TmpIdx = new FileInfo(Path.Combine(objdir.ToString(), "walk-" + tn + ".walkidx"));
            }
 private bool DownloadLooseObject(AnyObjectId id, string looseName, WalkRemoteObjectDatabase remote)
 {
     try
     {
         byte[] compressed = remote.open(looseName).toArray();
         VerifyLooseObject(id, compressed);
         SaveLooseObject(id, compressed);
         return true;
     }
     catch (FileNotFoundException e)
     {
         RecordError(id, e);
         return false;
     }
     catch (IOException e)
     {
         throw new TransportException("Cannot download " + id.Name, e);
     }
 }
            public RemotePack(string lockMessage, List <PackLock> packLocks, ObjectChecker oC, Repository r, WalkRemoteObjectDatabase c, string pn)
            {
                _lockMessage = lockMessage;
                _packLocks   = packLocks;
                _objCheck    = oC;
                _local       = r;
                DirectoryInfo objdir = _local.ObjectsDirectory;

                _connection = c;
                PackName    = pn;
                _idxName    = IndexPack.GetIndexFileName(PackName.Slice(0, PackName.Length - 5));

                string tn = _idxName;

                if (tn.StartsWith("pack-"))
                {
                    tn = tn.Substring(5);
                }

                if (tn.EndsWith(IndexPack.IndexSuffix))
                {
                    tn = tn.Slice(0, tn.Length - 4);
                }

                TmpIdx = new FileInfo(Path.Combine(objdir.ToString(), "walk-" + tn + ".walkidx"));
            }
        private void DownloadObject(ProgressMonitor pm, AnyObjectId id)
        {
            if (_local.HasObject(id))
            {
                return;
            }

            while (true)
            {
                // Try a pack file we know about, but don't have yet. Odds are
                // that if it has this object, it has others related to it so
                // getting the pack is a good bet.
                //
                if (DownloadPackedObject(pm, id))
                {
                    return;
                }

                // Search for a loose object over all alternates, starting
                // from the one we last successfully located an object through.
                //
                string idStr     = id.Name;
                string subdir    = idStr.Slice(0, 2);
                string file      = idStr.Substring(2);
                string looseName = subdir + "/" + file;

                for (int i = _lastRemoteIdx; i < _remotes.Count; i++)
                {
                    if (DownloadLooseObject(id, looseName, _remotes[i]))
                    {
                        _lastRemoteIdx = i;
                        return;
                    }
                }

                for (int i = 0; i < _lastRemoteIdx; i++)
                {
                    if (DownloadLooseObject(id, looseName, _remotes[i]))
                    {
                        _lastRemoteIdx = i;
                        return;
                    }
                }

                // Try to obtain more pack information and search those.
                //
                while (_noPacksYet.Count > 0)
                {
                    WalkRemoteObjectDatabase wrr = _noPacksYet.First.Value;
                    _noPacksYet.RemoveFirst();
                    ICollection <string> packNameList;
                    try
                    {
                        pm.BeginTask("Listing packs", ProgressMonitor.UNKNOWN);
                        packNameList = wrr.getPackNames();
                    }
                    catch (IOException e)
                    {
                        // Try another repository.
                        //
                        RecordError(id, e);
                        continue;
                    }
                    finally
                    {
                        pm.EndTask();
                    }

                    if (packNameList == null || packNameList.Count == 0)
                    {
                        continue;
                    }
                    foreach (string packName in packNameList)
                    {
                        bool contains = _packsConsidered.Contains(packName);
                        _packsConsidered.Add(packName);
                        if (!contains)
                        {
                            _unfetchedPacks.AddLast(new RemotePack(_lockMessage, _packLocks, _objCheck, _local, wrr, packName));
                        }
                    }
                    if (DownloadPackedObject(pm, id))
                    {
                        return;
                    }
                }

                // Try to expand the first alternate we haven't expanded yet.
                //
                ICollection <WalkRemoteObjectDatabase> al = ExpandOneAlternate(id, pm);
                if (al != null && al.Count > 0)
                {
                    foreach (WalkRemoteObjectDatabase alt in al)
                    {
                        _remotes.Add(alt);
                        _noPacksYet.AddLast(alt);
                        _noAlternatesYet.AddLast(alt);
                    }
                    continue;
                }

                // We could not obtain the object. There may be reasons why.
                //
                List <Exception> failures = _fetchErrors.get(id.Copy());

                var te = new TransportException("Cannot get " + id.Name + ".");

                if (failures != null && failures.Count > 0)
                {
                    te = failures.Count == 1 ?
                         new TransportException("Cannot get " + id.Name + ".", failures[0]) :
                         new TransportException("Cannot get " + id.Name + ".", new CompoundException(failures));
                }

                throw te;
            }
        }
Exemple #13
0
        private void DownloadObject(ProgressMonitor pm, AnyObjectId id)
        {
            if (_local.HasObject(id))
            {
                return;
            }

            while (true)
            {
                if (DownloadPackedObject(pm, id))
                {
                    return;
                }

                string idStr     = id.Name;
                string subdir    = idStr.Slice(0, 2);
                string file      = idStr.Substring(2);
                string looseName = subdir + "/" + file;

                for (int i = _lastRemoteIdx; i < _remotes.Count; i++)
                {
                    if (DownloadLooseObject(id, looseName, _remotes[i]))
                    {
                        _lastRemoteIdx = i;
                        return;
                    }
                }

                for (int i = 0; i < _lastRemoteIdx; i++)
                {
                    if (DownloadLooseObject(id, looseName, _remotes[i]))
                    {
                        _lastRemoteIdx = i;
                        return;
                    }
                }

                while (_noPacksYet.Count > 0)
                {
                    WalkRemoteObjectDatabase wrr = _noPacksYet.First.Value;
                    _noPacksYet.RemoveFirst();
                    List <string> packNameList;
                    try
                    {
                        pm.BeginTask("Listing packs", ProgressMonitor.UNKNOWN);
                        packNameList = wrr.getPackNames();
                    }
                    catch (IOException e)
                    {
                        RecordError(id, e);
                        continue;
                    }
                    finally
                    {
                        pm.EndTask();
                    }

                    if (packNameList == null || packNameList.Count == 0)
                    {
                        continue;
                    }
                    foreach (string packName in packNameList)
                    {
                        if (!_packsConsidered.Contains(packName))
                        {
                            _packsConsidered.Add(packName);
                            _unfetchedPacks.AddLast(new RemotePack(_lockMessage, _packLocks, _objCheck, _local, wrr, packName));
                        }
                    }
                    if (DownloadPackedObject(pm, id))
                    {
                        return;
                    }
                }

                List <WalkRemoteObjectDatabase> al = ExpandOneAlternate(id, pm);
                if (al != null && al.Count > 0)
                {
                    foreach (WalkRemoteObjectDatabase alt in al)
                    {
                        _remotes.Add(alt);
                        _noPacksYet.AddLast(alt);
                        _noAlternatesYet.AddLast(alt);
                    }
                    continue;
                }

                List <Exception> failures = null;
                if (_fetchErrors.ContainsKey(id.Copy()))
                {
                    failures = _fetchErrors[id.Copy()];
                }

                TransportException te = null;
                if (failures != null && failures.Count > 0)
                {
                    te = failures.Count == 1 ?
                         new TransportException("Cannot get " + id.Name + ".", failures[0]) :
                         new TransportException("Cannot get " + id.Name + ".", new CompoundException(failures));
                }

                if (te == null)
                {
                    te = new TransportException("Cannot get " + id.Name + ".");
                }

                throw te;
            }
        }
 private bool DownloadLooseObject(AnyObjectId id, string looseName, WalkRemoteObjectDatabase remote)
 {
     try
     {
         byte[] compressed = remote.open(looseName).toArray();
         VerifyLooseObject(id, compressed);
         SaveLooseObject(id, compressed);
         return true;
     }
     catch (FileNotFoundException e)
     {
         // Not available in a loose format from this alternate?
         // Try another strategy to get the object.
         //
         RecordError(id, e);
         return false;
     }
     catch (IOException e)
     {
         throw new TransportException("Cannot download " + id.Name, e);
     }
 }