/// <exception cref="System.IO.IOException"></exception>
        private void ReceivePack(ProgressMonitor monitor)
        {
            OnReceivePack();
            InputStream input = @in;

            if (sideband)
            {
                input = new SideBandInputStream(input, monitor, GetMessageWriter());
            }
            ObjectInserter ins = local.NewObjectInserter();

            try
            {
                PackParser parser = ins.NewPackParser(input);
                parser.SetAllowThin(thinPack);
                parser.SetObjectChecking(transport.IsCheckFetchedObjects());
                parser.SetLockMessage(lockMessage);
                packLock = parser.Parse(monitor);
                ins.Flush();
            }
            finally
            {
                ins.Release();
            }
        }
Пример #2
0
 /// <exception cref="NGit.Errors.TransportException"></exception>
 protected internal override void DoFetch(ProgressMonitor monitor, ICollection <Ref
                                                                                > want, ICollection <ObjectId> have)
 {
     VerifyPrerequisites();
     try
     {
         ObjectInserter ins = transport.local.NewObjectInserter();
         try
         {
             PackParser parser = ins.NewPackParser(bin);
             parser.SetAllowThin(true);
             parser.SetObjectChecking(transport.IsCheckFetchedObjects());
             parser.SetLockMessage(lockMessage);
             packLock = parser.Parse(NullProgressMonitor.INSTANCE);
             ins.Flush();
         }
         finally
         {
             ins.Release();
         }
     }
     catch (IOException err)
     {
         Close();
         throw new TransportException(transport.uri, err.Message, err);
     }
     catch (RuntimeException err)
     {
         Close();
         throw new TransportException(transport.uri, err.Message, err);
     }
 }
Пример #3
0
 private void UnlockPack()
 {
     if (packLock != null)
     {
         packLock.Unlock();
         packLock = null;
     }
 }
Пример #4
0
        private void ReceivePack(ProgressMonitor monitor)
        {
            IndexPack ip = IndexPack.Create(local, _sideband ? pckIn.sideband(monitor) : inStream);

            ip.setFixThin(_thinPack);
            ip.setObjectChecking(transport.CheckFetchedObjects);
            ip.index(monitor);
            _packLock = ip.renameAndOpenPack(_lockMessage);
        }
            public void DownloadPack(ProgressMonitor monitor)
            {
                Stream    s  = _connection.open("pack/" + PackName);
                IndexPack ip = IndexPack.Create(_local, s);

                ip.setFixThin(false);
                ip.setObjectChecker(_objCheck);
                ip.index(monitor);
                PackLock keep = ip.renameAndOpenPack(_lockMessage);

                if (keep != null)
                {
                    _packLocks.Add(keep);
                }
            }
Пример #6
0
 protected override void doFetch(ProgressMonitor monitor, List <Ref> want, List <ObjectId> have)
 {
     verifyPrerequisites();
     try
     {
         IndexPack ip = newIndexPack();
         ip.index(monitor);
         packLock = ip.renameAndOpenPack(lockMessage);
     }
     catch (IOException err)
     {
         Close();
         throw new TransportException(transport.Uri, err.Message, err);
     }
 }
        private void ReceivePack(ProgressMonitor monitor)
        {
            Stream input = inStream;

            if (_sideband)
            {
                input = new SideBandInputStream(input, monitor);
            }
            IndexPack ip = IndexPack.Create(local, input);

            ip.setFixThin(_thinPack);
            ip.setObjectChecking(transport.CheckFetchedObjects);
            ip.index(monitor);
            _packLock = ip.renameAndOpenPack(_lockMessage);
        }
Пример #8
0
        private void receivePack()
        {
            IndexPack ip = IndexPack.Create(db, raw);

            ip.setFixThin(true);
            ip.setObjectChecking(isCheckReceivedObjects());
            ip.index(new NullProgressMonitor());

            // [caytchen] TODO: reflect gitsharp
            string lockMsg = "jgit receive-pack";

            if (getRefLogIdent() != null)
            {
                lockMsg += " from " + getRefLogIdent().ToExternalString();
            }
            packLock = ip.renameAndOpenPack(lockMsg);
        }
Пример #9
0
            /// <exception cref="System.IO.IOException"></exception>
            internal virtual void DownloadPack(ProgressMonitor monitor)
            {
                string name = "pack/" + this.packName;

                WalkRemoteObjectDatabase.FileStream s = this.connection.Open(name);
                PackParser parser = this._enclosing.inserter.NewPackParser(s.@in);

                parser.SetAllowThin(false);
                parser.SetObjectChecker(this._enclosing.objCheck);
                parser.SetLockMessage(this._enclosing.lockMessage);
                PackLock Lock = parser.Parse(monitor);

                if (Lock != null)
                {
                    this._enclosing.packLocks.AddItem(Lock);
                }
                this._enclosing.inserter.Flush();
            }
Пример #10
0
        private void receivePack()
        {
            indexPack = IndexPack.Create(db, rawInput);
            indexPack.setFixThin(true);
            indexPack.setNeedNewObjectIds(needNewObjectIds);
            indexPack.setNeedBaseObjectIds(needBaseObjectIds);
            indexPack.setObjectChecking(isCheckReceivedObjects());
            indexPack.index(NullProgressMonitor.Instance);

            //  TODO: [caytchen] reflect gitsharp
            string lockMsg = "jgit receive-pack";

            if (getRefLogIdent() != null)
            {
                lockMsg += " from " + getRefLogIdent().ToExternalString();
            }
            packLock = indexPack.renameAndOpenPack(lockMsg);
        }
 private void receivePack(ProgressMonitor monitor)
 {
     IndexPack ip;
     ip = IndexPack.create(local, sideband ? pckIn.sideband(monitor) : stream);
     ip.setFixThin(thinPack);
     ip.setObjectChecking(transport.CheckFetchedObjects);
     ip.index(monitor);
     packLock = ip.renameAndOpenPack(lockMessage);
 }
Пример #12
0
        /// <summary>
        /// Rename the pack to it's final name and location and open it.
        /// <para/>
        /// If the call completes successfully the repository this IndexPack instance
        /// was created with will have the objects in the pack available for reading
        /// and use, without needing to scan for packs.
        /// </summary>
        /// <param name="lockMessage">
        /// message to place in the pack-*.keep file. If null, no lock
        /// will be created, and this method returns null.
        /// </param>
        /// <returns>the pack lock object, if lockMessage is not null.</returns>
        public PackLock renameAndOpenPack(string lockMessage)
        {
            if (!_keepEmpty && _entryCount == 0)
            {
                CleanupTemporaryFiles();
                return(null);
            }

            MessageDigest d       = Constants.newMessageDigest();
            var           oeBytes = new byte[Constants.OBJECT_ID_LENGTH];

            for (int i = 0; i < _entryCount; i++)
            {
                PackedObjectInfo oe = _entries[i];
                oe.copyRawTo(oeBytes, 0);
                d.Update(oeBytes);
            }

            string name      = ObjectId.FromRaw(d.Digest()).Name;
            var    packDir   = PathUtil.CombineDirectoryPath(_repo.ObjectsDirectory, "pack");
            var    finalPack = PathUtil.CombineFilePath(packDir, "pack-" + GetPackFileName(name));
            var    finalIdx  = PathUtil.CombineFilePath(packDir, "pack-" + GetIndexFileName(name));
            var    keep      = new PackLock(finalPack);

            if (!packDir.Exists && !packDir.Mkdirs() && !packDir.Exists)
            {
                // The objects/pack directory isn't present, and we are unable
                // to create it. There is no way to move this pack in.
                //
                CleanupTemporaryFiles();
                throw new IOException("Cannot Create " + packDir);
            }

            if (finalPack.Exists)
            {
                // If the pack is already present we should never replace it.
                //
                CleanupTemporaryFiles();
                return(null);
            }

            if (lockMessage != null)
            {
                // If we have a reason to create a keep file for this pack, do
                // so, or fail fast and don't put the pack in place.
                //
                try
                {
                    if (!keep.Lock(lockMessage))
                    {
                        throw new IOException("Cannot lock pack in " + finalPack);
                    }
                }
                catch (IOException)
                {
                    CleanupTemporaryFiles();
                    throw;
                }
            }

            if (!_dstPack.RenameTo(finalPack.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                throw new IOException("Cannot move pack to " + finalPack);
            }

            if (!_dstIdx.RenameTo(finalIdx.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                finalPack.DeleteFile();
                //if (finalPack.Exists)
                // TODO: [caytchen]  finalPack.deleteOnExit();
                throw new IOException("Cannot move index to " + finalIdx);
            }

            try
            {
                _repo.OpenPack(finalPack, finalIdx);
            }
            catch (IOException)
            {
                keep.Unlock();
                finalPack.DeleteFile();
                finalIdx.DeleteFile();
                throw;
            }

            return(lockMessage != null ? keep : null);
        }
Пример #13
0
 private void UnlockPack()
 {
     if (packLock != null)
     {
         packLock.Unlock();
         packLock = null;
     }
 }
Пример #14
0
        private void receivePack()
        {
            IndexPack ip = IndexPack.Create(db, raw);
            ip.setFixThin(true);
            ip.setObjectChecking(isCheckReceivedObjects());
            ip.index(new NullProgressMonitor());

            // [caytchen] TODO: reflect gitsharp
            string lockMsg = "jgit receive-pack";
            if (getRefLogIdent() != null)
                lockMsg += " from " + getRefLogIdent().ToExternalString();
            packLock = ip.renameAndOpenPack(lockMsg);
        }
Пример #15
0
        public PackLock renameAndOpenPack(string lockMessage)
        {
            if (!_keepEmpty && _entryCount == 0)
            {
                CleanupTemporaryFiles();
                return(null);
            }

            MessageDigest d       = Constants.newMessageDigest();
            var           oeBytes = new byte[Constants.OBJECT_ID_LENGTH];

            for (int i = 0; i < _entryCount; i++)
            {
                PackedObjectInfo oe = _entries[i];
                oe.copyRawTo(oeBytes, 0);
                d.Update(oeBytes);
            }

            string name      = ObjectId.FromRaw(d.Digest()).Name;
            var    packDir   = new DirectoryInfo(Path.Combine(_repo.ObjectsDirectory.ToString(), "pack"));
            var    finalPack = new FileInfo(Path.Combine(packDir.ToString(), "pack-" + GetPackFileName(name)));
            var    finalIdx  = new FileInfo(Path.Combine(packDir.ToString(), "pack-" + GetIndexFileName(name)));
            var    keep      = new PackLock(finalPack);

            if (!packDir.Exists && !packDir.Mkdirs() && !packDir.Exists)
            {
                CleanupTemporaryFiles();
                throw new IOException("Cannot Create " + packDir);
            }

            if (finalPack.Exists)
            {
                CleanupTemporaryFiles();
                return(null);
            }

            if (lockMessage != null)
            {
                try
                {
                    if (!keep.Lock(lockMessage))
                    {
                        throw new IOException("Cannot lock pack in " + finalPack);
                    }
                }
                catch (IOException)
                {
                    CleanupTemporaryFiles();
                    throw;
                }
            }

            if (!_dstPack.RenameTo(finalPack.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                throw new IOException("Cannot move pack to " + finalPack);
            }

            if (!_dstIdx.RenameTo(finalIdx.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                finalPack.Delete();
                //if (finalPack.Exists)
                // TODO: [caytchen]  finalPack.deleteOnExit();
                throw new IOException("Cannot move index to " + finalIdx);
            }

            try
            {
                _repo.OpenPack(finalPack, finalIdx);
            }
            catch (IOException)
            {
                keep.Unlock();
                finalPack.Delete();
                finalIdx.Delete();
                throw;
            }

            return(lockMessage != null ? keep : null);
        }
Пример #16
0
        public PackLock renameAndOpenPack(string lockMessage)
        {
            if (!_keepEmpty && _entryCount == 0)
            {
                CleanupTemporaryFiles();
                return null;
            }

            MessageDigest d = Constants.newMessageDigest();
            var oeBytes = new byte[Constants.OBJECT_ID_LENGTH];
            for (int i = 0; i < _entryCount; i++)
            {
                PackedObjectInfo oe = _entries[i];
                oe.copyRawTo(oeBytes, 0);
                d.Update(oeBytes);
            }

            string name = ObjectId.FromRaw(d.Digest()).Name;
            var packDir = new DirectoryInfo(Path.Combine(_repo.ObjectsDirectory.ToString(), "pack"));
            var finalPack = new FileInfo(Path.Combine(packDir.ToString(), "pack-" + GetPackFileName(name)));
            var finalIdx = new FileInfo(Path.Combine(packDir.ToString(), "pack-" + GetIndexFileName(name)));
            var keep = new PackLock(finalPack);

            if (!packDir.Exists && !packDir.Mkdirs() && !packDir.Exists)
            {
                CleanupTemporaryFiles();
                throw new IOException("Cannot Create " + packDir);
            }

            if (finalPack.Exists)
            {
                CleanupTemporaryFiles();
                return null;
            }

            if (lockMessage != null)
            {
                try
                {
                    if (!keep.Lock(lockMessage))
                    {
                        throw new IOException("Cannot lock pack in " + finalPack);
                    }
                }
                catch (IOException)
                {
                    CleanupTemporaryFiles();
                    throw;
                }
            }

            if (!_dstPack.RenameTo(finalPack.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                throw new IOException("Cannot move pack to " + finalPack);
            }

            if (!_dstIdx.RenameTo(finalIdx.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                finalPack.Delete();
                //if (finalPack.Exists)
                // TODO: [caytchen]  finalPack.deleteOnExit();
                throw new IOException("Cannot move index to " + finalIdx);
            }

            try
            {
                _repo.OpenPack(finalPack, finalIdx);
            }
            catch (IOException)
            {
                keep.Unlock();
                finalPack.Delete();
                finalIdx.Delete();
                throw;
            }

            return lockMessage != null ? keep : null;
        }
Пример #17
0
 protected override void doFetch(ProgressMonitor monitor, List<Ref> want, List<ObjectId> have)
 {
     verifyPrerequisites();
     try
     {
         IndexPack ip = newIndexPack();
         ip.index(monitor);
         packLock = ip.renameAndOpenPack(lockMessage);
     }
     catch (IOException err)
     {
         Close();
         throw new TransportException(transport.Uri, err.Message, err);
     }
 }
Пример #18
0
        /// <summary>
        /// Rename the pack to it's final name and location and open it.
        /// <para/>
        /// If the call completes successfully the repository this IndexPack instance
        /// was created with will have the objects in the pack available for reading
        /// and use, without needing to scan for packs.
        /// </summary>
        /// <param name="lockMessage">
        /// message to place in the pack-*.keep file. If null, no lock
        /// will be created, and this method returns null.
        /// </param>
        /// <returns>the pack lock object, if lockMessage is not null.</returns>
        public PackLock renameAndOpenPack(string lockMessage)
        {
            if (!_keepEmpty && _entryCount == 0)
            {
                CleanupTemporaryFiles();
                return null;
            }

            MessageDigest d = Constants.newMessageDigest();
            var oeBytes = new byte[Constants.OBJECT_ID_LENGTH];
            for (int i = 0; i < _entryCount; i++)
            {
                PackedObjectInfo oe = _entries[i];
                oe.copyRawTo(oeBytes, 0);
                d.Update(oeBytes);
            }

            string name = ObjectId.FromRaw(d.Digest()).Name;
            var packDir = new DirectoryInfo(Path.Combine(_repo.ObjectsDirectory.ToString(), "pack"));
            var finalPack = new FileInfo(Path.Combine(packDir.ToString(), "pack-" + GetPackFileName(name)));
            var finalIdx = new FileInfo(Path.Combine(packDir.ToString(), "pack-" + GetIndexFileName(name)));
            var keep = new PackLock(finalPack);

            if (!packDir.Exists && !packDir.Mkdirs() && !packDir.Exists)
            {
                // The objects/pack directory isn't present, and we are unable
                // to create it. There is no way to move this pack in.
                //
                CleanupTemporaryFiles();
                throw new IOException("Cannot Create " + packDir);
            }

            if (finalPack.Exists)
            {
                // If the pack is already present we should never replace it.
                //
                CleanupTemporaryFiles();
                return null;
            }

            if (lockMessage != null)
            {
                // If we have a reason to create a keep file for this pack, do
                // so, or fail fast and don't put the pack in place.
                //
                try
                {
                    if (!keep.Lock(lockMessage))
                    {
                        throw new IOException("Cannot lock pack in " + finalPack);
                    }
                }
                catch (IOException)
                {
                    CleanupTemporaryFiles();
                    throw;
                }
            }

            if (!_dstPack.RenameTo(finalPack.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                throw new IOException("Cannot move pack to " + finalPack);
            }

            if (!_dstIdx.RenameTo(finalIdx.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                finalPack.Delete();
                //if (finalPack.Exists)
                // TODO: [caytchen]  finalPack.deleteOnExit();
                throw new IOException("Cannot move index to " + finalIdx);
            }

            try
            {
                _repo.OpenPack(finalPack, finalIdx);
            }
            catch (IOException)
            {
                keep.Unlock();
                finalPack.Delete();
                finalIdx.Delete();
                throw;
            }

            return lockMessage != null ? keep : null;
        }