Ejemplo n.º 1
0
        private void WriteObject(ObjectToPack otp)
        {
            otp.MarkWantWrite();
            if (otp.IsDeltaRepresentation)
            {
                ObjectToPack deltaBase = otp.DeltaBase;
                Debug.Assert(deltaBase != null || Thin);
                if (deltaBase != null && !deltaBase.IsWritten)
                {
                    if (deltaBase.WantWrite)
                    {
                        otp.ClearDeltaBase();
                        otp.DisposeLoader();
                    }
                    else
                    {
                        WriteObject(deltaBase);
                    }
                }
            }

            Debug.Assert(!otp.IsWritten);

            _pos.resetCRC32();
            otp.Offset = _pos.Length;

            PackedObjectLoader reuse = Open(otp);

            if (reuse != null)
            {
                try
                {
                    if (otp.IsDeltaRepresentation)
                    {
                        WriteDeltaObjectReuse(otp, reuse);
                    }
                    else
                    {
                        WriteObjectHeader(otp.Type, reuse.Size);
                        reuse.CopyRawData(_pos, _buf, _windowCursor);
                    }
                }
                finally
                {
                    reuse.endCopyRawData();
                }
            }
            else if (otp.IsDeltaRepresentation)
            {
                throw new IOException("creating deltas is not implemented");
            }
            else
            {
                WriteWholeObjectDeflate(otp);
            }

            otp.CRC = _pos.getCRC32();
            _writeMonitor.Update(1);
        }
Ejemplo n.º 2
0
        private PackedObjectLoader Open(ObjectToPack otp)
        {
            while (true)
            {
                PackedObjectLoader reuse = otp.UseLoader();
                if (reuse == null)
                {
                    return(null);
                }

                try
                {
                    reuse.beginCopyRawData();
                    return(reuse);
                }
                catch (IOException)
                {
                    otp.ClearDeltaBase();
                    SearchForReuse(new List <PackedObjectLoader>(), otp);
                    continue;
                }
            }
        }