Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException"></exception>
        internal override long GetObjectSize1(WindowCursor curs, AnyObjectId objectId)
        {
            ObjectDirectory.PackList pList = packList.Get();
            for (; ;)
            {
                foreach (PackFile p in pList.packs)
                {
                    try
                    {
                        long sz = p.GetObjectSize(curs, objectId);
                        if (0 <= sz)
                        {
                            return(sz);
                        }
                    }
                    catch (PackMismatchException)
                    {
                        // Pack was modified; refresh the entire pack list.
                        //
                        pList = ScanPacks(pList);
                        goto SEARCH_continue;
                    }
                    catch (IOException)
                    {
                        // Assume the pack is corrupted.
                        //
                        RemovePack(p);
                    }
                }
                return(-1);

                SEARCH_continue :;
            }
            SEARCH_break :;
        }
Exemplo n.º 2
0
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public override ObjectStream OpenStream()
        {
            WindowCursor wc = new WindowCursor(db);
            InputStream  @in;

            try
            {
                @in = new PackInputStream(pack, objectOffset + headerLength, wc);
            }
            catch (IOException)
            {
                // If the pack file cannot be pinned into the cursor, it
                // probably was repacked recently. Go find the object
                // again and open the stream from that location instead.
                //
                return(wc.Open(GetObjectId(), type).OpenStream());
            }
            @in = new BufferedInputStream(new InflaterInputStream(@in, wc.Inflater(), 8192),
                                          8192);
            //
            //
            //
            //
            //
            return(new ObjectStream.Filter(type, size, @in));
        }
Exemplo n.º 3
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual int GetObjectType(WindowCursor curs, long pos)
        {
            byte[] ib = curs.tempId;
            for (; ;)
            {
                ReadFully(pos, ib, 0, 20, curs);
                int c    = ib[0] & unchecked ((int)(0xff));
                int type = (c >> 4) & 7;
                switch (type)
                {
                case Constants.OBJ_COMMIT:
                case Constants.OBJ_TREE:
                case Constants.OBJ_BLOB:
                case Constants.OBJ_TAG:
                {
                    return(type);
                }

                case Constants.OBJ_OFS_DELTA:
                {
                    int p = 1;
                    while ((c & unchecked ((int)(0x80))) != 0)
                    {
                        c = ib[p++] & unchecked ((int)(0xff));
                    }
                    c = ib[p++] & unchecked ((int)(0xff));
                    long ofs = c & 127;
                    while ((c & 128) != 0)
                    {
                        ofs  += 1;
                        c     = ib[p++] & unchecked ((int)(0xff));
                        ofs <<= 7;
                        ofs  += (c & 127);
                    }
                    pos = pos - ofs;
                    continue;
                    goto case Constants.OBJ_REF_DELTA;
                }

                case Constants.OBJ_REF_DELTA:
                {
                    int p = 1;
                    while ((c & unchecked ((int)(0x80))) != 0)
                    {
                        c = ib[p++] & unchecked ((int)(0xff));
                    }
                    ReadFully(pos + p, ib, 0, 20, curs);
                    pos = FindDeltaBase(ObjectId.FromRaw(ib));
                    continue;
                    goto default;
                }

                default:
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().unknownObjectType, Sharpen.Extensions.ValueOf
                                                                   (type)));
                }
                }
            }
        }
Exemplo n.º 4
0
        /// <exception cref="System.IO.IOException"></exception>
        internal ObjectLoader OpenObjectImpl1(WindowCursor curs, AnyObjectId objectId)
        {
            ObjectLoader ldr;

            ldr = OpenObject1(curs, objectId);
            if (ldr != null)
            {
                return(ldr);
            }
            foreach (FileObjectDatabase.AlternateHandle alt in MyAlternates())
            {
                ldr = alt.db.OpenObjectImpl1(curs, objectId);
                if (ldr != null)
                {
                    return(ldr);
                }
            }
            if (TryAgain1())
            {
                ldr = OpenObject1(curs, objectId);
                if (ldr != null)
                {
                    return(ldr);
                }
            }
            return(null);
        }
Exemplo n.º 5
0
 public _DeltaStream_223(ObjectLoader @base, WindowCursor wc, InputStream baseArg1
                         ) : base(baseArg1)
 {
     this.@base    = @base;
     this.wc       = wc;
     this.baseSize = NGit.Storage.File.LargePackedDeltaObject.SIZE_UNKNOWN;
 }
Exemplo n.º 6
0
 public override int GetType()
 {
     if (type == Constants.OBJ_BAD)
     {
         WindowCursor wc = new WindowCursor(db);
         try
         {
             type = pack.GetObjectType(wc, objectOffset);
         }
         catch (IOException)
         {
             // If the pack file cannot be pinned into the cursor, it
             // probably was repacked recently. Go find the object
             // again and get the type from that location instead.
             //
             try
             {
                 type = wc.Open(GetObjectId()).GetType();
             }
             catch (IOException)
             {
             }
         }
         finally
         {
             // "He's dead, Jim." We just can't discover the type
             // and the interface isn't supposed to be lazy here.
             // Report an invalid type code instead, callers will
             // wind up bailing out with an error at some point.
             wc.Release();
         }
     }
     return(type);
 }
Exemplo n.º 7
0
 /// <exception cref="System.IO.IOException"></exception>
 /// <exception cref="ICSharpCode.SharpZipLib.SharpZipBaseException"></exception>
 private byte[] Decompress(long position, int sz, WindowCursor curs)
 {
     byte[] dstbuf;
     try
     {
         dstbuf = new byte[sz];
     }
     catch (OutOfMemoryException)
     {
         // The size may be larger than our heap allows, return null to
         // let the caller know allocation isn't possible and it should
         // use the large object streaming approach instead.
         //
         // For example, this can occur when sz is 640 MB, and JRE
         // maximum heap size is only 256 MB. Even if the JRE has
         // 200 MB free, it cannot allocate a 640 MB byte array.
         return(null);
     }
     if (curs.Inflate(this, position, dstbuf, 0) != sz)
     {
         throw new EOFException(MessageFormat.Format(JGitText.Get().shortCompressedStreamAt
                                                     , Sharpen.Extensions.ValueOf(position)));
     }
     return(dstbuf);
 }
Exemplo n.º 8
0
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public override ObjectStream OpenStream()
        {
            // If the object was recently unpacked, its available loose.
            // The loose format is going to be faster to access than a
            // delta applied on top of a base. Use that whenever we can.
            //
            ObjectId     myId = GetObjectId();
            WindowCursor wc   = new WindowCursor(db);
            ObjectLoader ldr  = db.OpenObject2(wc, myId.Name, myId);

            if (ldr != null)
            {
                return(ldr.OpenStream());
            }
            InputStream @in = Open(wc);

            @in = new BufferedInputStream(@in, 8192);
            // While we inflate the object, also deflate it back as a loose
            // object. This will later be cleaned up by a gc pass, but until
            // then we will reuse the loose form by the above code path.
            //
            int  myType = GetType();
            long mySize = GetSize();
            ObjectDirectoryInserter odi = ((ObjectDirectoryInserter)db.NewInserter());
            FilePath             tmp    = odi.NewTempFile();
            DeflaterOutputStream dOut   = odi.Compress(new FileOutputStream(tmp));

            odi.WriteHeader(dOut, myType, mySize);
            @in = new TeeInputStream(@in, dOut);
            return(new _Filter_195(this, odi, wc, tmp, myId, myType, mySize, @in));
        }
Exemplo n.º 9
0
 /// <exception cref="System.IO.IOException"></exception>
 internal virtual void CopyPackAsIs(PackOutputStream @out, bool validate, WindowCursor
                                    curs)
 {
     // Pin the first window, this ensures the length is accurate.
     curs.Pin(this, 0);
     curs.CopyPackAsIs(this, length, validate, @out);
 }
Exemplo n.º 10
0
        /// <exception cref="System.IO.IOException"></exception>
        internal long GetObjectSizeImpl1(WindowCursor curs, AnyObjectId objectId)
        {
            long sz;

            sz = GetObjectSize1(curs, objectId);
            if (0 <= sz)
            {
                return(sz);
            }
            foreach (FileObjectDatabase.AlternateHandle alt in MyAlternates())
            {
                sz = alt.db.GetObjectSizeImpl1(curs, objectId);
                if (0 <= sz)
                {
                    return(sz);
                }
            }
            if (TryAgain1())
            {
                sz = GetObjectSize1(curs, objectId);
                if (0 <= sz)
                {
                    return(sz);
                }
            }
            return(-1);
        }
Exemplo n.º 11
0
 /// <exception cref="System.IO.IOException"></exception>
 internal virtual void CopyAsIs(PackOutputStream @out, bool validate, WindowCursor
                                wc)
 {
     foreach (PackFile pack in GetPacks())
     {
         pack.CopyPackAsIs(@out, validate, wc);
     }
 }
Exemplo n.º 12
0
 /// <exception cref="System.IO.IOException"></exception>
 internal virtual void CopyAsIs(PackOutputStream @out, bool validate, WindowCursor
                                wc)
 {
     foreach (string packName in packNames)
     {
         GetPackFile(packName).CopyPackAsIs(@out, validate, wc);
     }
 }
Exemplo n.º 13
0
 /// <exception cref="System.IO.IOException"></exception>
 internal override long GetObjectSize1(WindowCursor curs, AnyObjectId objectId)
 {
     if (unpackedObjects.Contains(objectId))
     {
         return(wrapped.GetObjectSize2(curs, objectId.Name, objectId));
     }
     return(wrapped.GetObjectSize1(curs, objectId));
 }
Exemplo n.º 14
0
 /// <exception cref="System.IO.IOException"></exception>
 private void ReadFully(long position, byte[] dstbuf, int dstoff, int cnt, WindowCursor
                        curs)
 {
     if (curs.Copy(this, position, dstbuf, dstoff, cnt) != cnt)
     {
         throw new EOFException();
     }
 }
Exemplo n.º 15
0
		/// <exception cref="System.IO.IOException"></exception>
		internal PackInputStream(PackFile pack, long pos, WindowCursor wc)
		{
			this.pack = pack;
			this.pos = pos;
			this.wc = wc;
			// Pin the first window, to ensure the pack is open and valid.
			//
			wc.Pin(pack, pos);
		}
Exemplo n.º 16
0
 /// <exception cref="System.IO.IOException"></exception>
 internal PackInputStream(PackFile pack, long pos, WindowCursor wc)
 {
     this.pack = pack;
     this.pos  = pos;
     this.wc   = wc;
     // Pin the first window, to ensure the pack is open and valid.
     //
     wc.Pin(pack, pos);
 }
Exemplo n.º 17
0
		public override void SetUp()
		{
			base.SetUp();
			WindowCacheConfig cfg = new WindowCacheConfig();
			cfg.SetStreamFileThreshold(streamThreshold);
			WindowCache.Reconfigure(cfg);
			repo = CreateBareRepository();
			wc = (WindowCursor)repo.NewObjectReader();
		}
Exemplo n.º 18
0
 /// <exception cref="System.IO.IOException"></exception>
 internal override ObjectLoader OpenObject2(WindowCursor curs, string objectName,
                                            AnyObjectId objectId)
 {
     if (unpackedObjects.Contains(objectId))
     {
         return(wrapped.OpenObject2(curs, objectName, objectId));
     }
     return(null);
 }
Exemplo n.º 19
0
 internal virtual ObjectLoader Large(PackFile pack, WindowCursor wc)
 {
     PackFile.Delta d = this;
     while (d.next != null)
     {
         d = d.next;
     }
     return(d.NewLargeLoader(pack, wc));
 }
Exemplo n.º 20
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual long GetObjectSize(WindowCursor curs, AnyObjectId objectId)
        {
            long sz = GetObjectSizeImpl1(curs, objectId);

            if (0 <= sz)
            {
                return(sz);
            }
            return(GetObjectSizeImpl2(curs, objectId.Name, objectId));
        }
Exemplo n.º 21
0
        public override void SetUp()
        {
            base.SetUp();
            WindowCacheConfig cfg = new WindowCacheConfig();

            cfg.SetStreamFileThreshold(streamThreshold);
            WindowCache.Reconfigure(cfg);
            repo = CreateBareRepository();
            wc   = (WindowCursor)repo.NewObjectReader();
        }
Exemplo n.º 22
0
 public _Filter_195(LargePackedDeltaObject _enclosing, ObjectDirectoryInserter odi
                    , WindowCursor wc, FilePath tmp, ObjectId myId, int baseArg1, long baseArg2, InputStream
                    baseArg3) : base(baseArg1, baseArg2, baseArg3)
 {
     this._enclosing = _enclosing;
     this.odi        = odi;
     this.wc         = wc;
     this.tmp        = tmp;
     this.myId       = myId;
 }
Exemplo n.º 23
0
 /// <exception cref="System.IO.IOException"></exception>
 /// <exception cref="ICSharpCode.SharpZipLib.SharpZipBaseException"></exception>
 internal virtual byte[] GetDeltaHeader(WindowCursor wc, long pos)
 {
     // The delta stream starts as two variable length integers. If we
     // assume they are 64 bits each, we need 16 bytes to encode them,
     // plus 2 extra bytes for the variable length overhead. So 18 is
     // the longest delta instruction header.
     //
     byte[] hdr = new byte[18];
     wc.Inflate(this, pos, hdr, 0);
     return(hdr);
 }
Exemplo n.º 24
0
		/// <summary>Parse an object from the unpacked object format.</summary>
		/// <remarks>Parse an object from the unpacked object format.</remarks>
		/// <param name="raw">complete contents of the compressed object.</param>
		/// <param name="id">
		/// expected ObjectId of the object, used only for error reporting
		/// in exceptions.
		/// </param>
		/// <returns>loader to read the inflated contents.</returns>
		/// <exception cref="System.IO.IOException">the object cannot be parsed.</exception>
		public static ObjectLoader Parse(byte[] raw, AnyObjectId id)
		{
			WindowCursor wc = new WindowCursor(null);
			try
			{
				return Open(new ByteArrayInputStream(raw), null, id, wc);
			}
			finally
			{
				wc.Release();
			}
		}
Exemplo n.º 25
0
        /// <summary>Parse an object from the unpacked object format.</summary>
        /// <remarks>Parse an object from the unpacked object format.</remarks>
        /// <param name="raw">complete contents of the compressed object.</param>
        /// <param name="id">
        /// expected ObjectId of the object, used only for error reporting
        /// in exceptions.
        /// </param>
        /// <returns>loader to read the inflated contents.</returns>
        /// <exception cref="System.IO.IOException">the object cannot be parsed.</exception>
        public static ObjectLoader Parse(byte[] raw, AnyObjectId id)
        {
            WindowCursor wc = new WindowCursor(null);

            try
            {
                return(Open(new ByteArrayInputStream(raw), null, id, wc));
            }
            finally
            {
                wc.Release();
            }
        }
Exemplo n.º 26
0
 /// <exception cref="System.IO.IOException"></exception>
 /// <exception cref="NGit.Errors.StoredObjectRepresentationNotAvailableException"></exception>
 internal void CopyAsIs(PackOutputStream @out, LocalObjectToPack src, bool validate
                        , WindowCursor curs)
 {
     BeginCopyAsIs(src);
     try
     {
         CopyAsIs2(@out, src, validate, curs);
     }
     finally
     {
         EndCopyAsIs();
     }
 }
Exemplo n.º 27
0
 /// <exception cref="System.IO.IOException"></exception>
 internal static long GetSize(InputStream @in, AnyObjectId id, WindowCursor wc)
 {
     try
     {
         @in = Buffer(@in);
         @in.Mark(20);
         byte[] hdr = new byte[64];
         IOUtil.ReadFully(@in, hdr, 0, 2);
         if (IsStandardFormat(hdr))
         {
             @in.Reset();
             Inflater    inf   = wc.Inflater();
             InputStream zIn   = Inflate(@in, inf);
             int         avail = ReadSome(zIn, hdr, 0, 64);
             if (avail < 5)
             {
                 throw new CorruptObjectException(id, JGitText.Get().corruptObjectNoHeader);
             }
             MutableInteger p = new MutableInteger();
             Constants.DecodeTypeString(id, hdr, unchecked ((byte)' '), p);
             long size = RawParseUtils.ParseLongBase10(hdr, p.value, p);
             if (size < 0)
             {
                 throw new CorruptObjectException(id, JGitText.Get().corruptObjectNegativeSize);
             }
             return(size);
         }
         else
         {
             ReadSome(@in, hdr, 2, 18);
             int  c     = hdr[0] & unchecked ((int)(0xff));
             long size  = c & 15;
             int  shift = 4;
             int  p     = 1;
             while ((c & unchecked ((int)(0x80))) != 0)
             {
                 c      = hdr[p++] & unchecked ((int)(0xff));
                 size  += ((long)(c & unchecked ((int)(0x7f)))) << shift;
                 shift += 7;
             }
             return(size);
         }
     }
     catch (SharpZipBaseException)
     {
         throw new CorruptObjectException(id, JGitText.Get().corruptObjectBadStream);
     }
 }
Exemplo n.º 28
0
        /// <exception cref="System.IO.IOException"></exception>
        internal override ObjectLoader OpenObject1(WindowCursor curs, AnyObjectId objectId
                                                   )
        {
            if (unpackedObjectCache.IsUnpacked(objectId))
            {
                ObjectLoader ldr = OpenObject2(curs, objectId.Name, objectId);
                if (ldr != null)
                {
                    return(ldr);
                }
                else
                {
                    unpackedObjectCache.Remove(objectId);
                }
            }
            ObjectDirectory.PackList pList = packList.Get();
            for (; ;)
            {
                foreach (PackFile p in pList.packs)
                {
                    try
                    {
                        ObjectLoader ldr = p.Get(curs, objectId);
                        if (ldr != null)
                        {
                            return(ldr);
                        }
                    }
                    catch (PackMismatchException)
                    {
                        // Pack was modified; refresh the entire pack list.
                        //
                        pList = ScanPacks(pList);
                        goto SEARCH_continue;
                    }
                    catch (IOException)
                    {
                        // Assume the pack is corrupted.
                        //
                        RemovePack(p);
                    }
                }
                return(null);

                SEARCH_continue :;
            }
            SEARCH_break :;
        }
Exemplo n.º 29
0
        /// <summary>Open an object from this database.</summary>
        /// <remarks>
        /// Open an object from this database.
        /// <p>
        /// Alternates (if present) are searched automatically.
        /// </remarks>
        /// <param name="curs">temporary working space associated with the calling thread.</param>
        /// <param name="objectId">identity of the object to open.</param>
        /// <returns>
        /// a
        /// <see cref="NGit.ObjectLoader">NGit.ObjectLoader</see>
        /// for accessing the data of the named
        /// object, or null if the object does not exist.
        /// </returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        internal virtual ObjectLoader OpenObject(WindowCursor curs, AnyObjectId objectId)
        {
            ObjectLoader ldr;

            ldr = OpenObjectImpl1(curs, objectId);
            if (ldr != null)
            {
                return(ldr);
            }
            ldr = OpenObjectImpl2(curs, objectId.Name, objectId);
            if (ldr != null)
            {
                return(ldr);
            }
            return(null);
        }
Exemplo n.º 30
0
        /// <exception cref="System.IO.IOException"></exception>
        internal ObjectLoader OpenObjectImpl2(WindowCursor curs, string objectName, AnyObjectId
                                              objectId)
        {
            ObjectLoader ldr;

            ldr = OpenObject2(curs, objectName, objectId);
            if (ldr != null)
            {
                return(ldr);
            }
            foreach (FileObjectDatabase.AlternateHandle alt in MyAlternates())
            {
                ldr = alt.db.OpenObjectImpl2(curs, objectName, objectId);
                if (ldr != null)
                {
                    return(ldr);
                }
            }
            return(null);
        }
Exemplo n.º 31
0
        /// <exception cref="System.IO.IOException"></exception>
        internal long GetObjectSizeImpl2(WindowCursor curs, string objectName, AnyObjectId
                                         objectId)
        {
            long sz;

            sz = GetObjectSize2(curs, objectName, objectId);
            if (0 <= sz)
            {
                return(sz);
            }
            foreach (FileObjectDatabase.AlternateHandle alt in MyAlternates())
            {
                sz = alt.db.GetObjectSizeImpl2(curs, objectName, objectId);
                if (0 <= sz)
                {
                    return(sz);
                }
            }
            return(-1);
        }
Exemplo n.º 32
0
 public override long GetSize()
 {
     if (size == SIZE_UNKNOWN)
     {
         WindowCursor wc = new WindowCursor(db);
         try
         {
             byte[] b = pack.GetDeltaHeader(wc, objectOffset + headerLength);
             size = BinaryDelta.GetResultSize(b);
         }
         catch (SharpZipBaseException)
         {
         }
         catch (IOException)
         {
             // The zlib stream for the delta is corrupt. We probably
             // cannot access the object. Keep the size negative and
             // report that bogus result to the caller.
             // If the pack file cannot be pinned into the cursor, it
             // probably was repacked recently. Go find the object
             // again and get the size from that location instead.
             //
             try
             {
                 size = wc.Open(GetObjectId()).GetSize();
             }
             catch (IOException)
             {
             }
         }
         finally
         {
             // "He's dead, Jim." We just can't discover the size
             // and the interface isn't supposed to be lazy here.
             // Report an invalid type code instead, callers will
             // wind up bailing out with an error at some point.
             wc.Release();
         }
     }
     return(size);
 }
Exemplo n.º 33
0
 /// <exception cref="System.IO.IOException"></exception>
 internal override long GetObjectSize2(WindowCursor curs, string objectName, AnyObjectId
                                       objectId)
 {
     try
     {
         FilePath        path = FileFor(objectName);
         FileInputStream @in  = new FileInputStream(path);
         try
         {
             return(UnpackedObject.GetSize(@in, objectId, curs));
         }
         finally
         {
             @in.Close();
         }
     }
     catch (FileNotFoundException)
     {
         return(-1);
     }
 }
		/// <exception cref="System.IO.IOException"></exception>
		internal override long GetObjectSize2(WindowCursor curs, string objectName, AnyObjectId
			 objectId)
		{
			if (unpackedObjects.Contains(objectId))
			{
				return wrapped.GetObjectSize2(curs, objectName, objectId);
			}
			return -1;
		}
Exemplo n.º 35
0
		/// <exception cref="System.IO.IOException"></exception>
		internal override long GetObjectSize1(WindowCursor curs, AnyObjectId objectId)
		{
			ObjectDirectory.PackList pList = packList.Get();
			for (; ; )
			{
				foreach (PackFile p in pList.packs)
				{
					try
					{
						long sz = p.GetObjectSize(curs, objectId);
						if (0 <= sz)
						{
							return sz;
						}
					}
					catch (PackMismatchException)
					{
						// Pack was modified; refresh the entire pack list.
						//
						pList = ScanPacks(pList);
						goto SEARCH_continue;
					}
					catch (IOException)
					{
						// Assume the pack is corrupted.
						//
						RemovePack(p);
					}
				}
				return -1;
SEARCH_continue: ;
			}
SEARCH_break: ;
		}
Exemplo n.º 36
0
		/// <exception cref="System.IO.IOException"></exception>
		internal static long GetSize(InputStream @in, AnyObjectId id, WindowCursor wc)
		{
			try
			{
				@in = Buffer(@in);
				@in.Mark(20);
				byte[] hdr = new byte[64];
				IOUtil.ReadFully(@in, hdr, 0, 2);
				if (IsStandardFormat(hdr))
				{
					@in.Reset();
					Inflater inf = wc.Inflater();
					InputStream zIn = Inflate(@in, inf);
					int avail = ReadSome(zIn, hdr, 0, 64);
					if (avail < 5)
					{
						throw new CorruptObjectException(id, JGitText.Get().corruptObjectNoHeader);
					}
					MutableInteger p = new MutableInteger();
					Constants.DecodeTypeString(id, hdr, unchecked((byte)' '), p);
					long size = RawParseUtils.ParseLongBase10(hdr, p.value, p);
					if (size < 0)
					{
						throw new CorruptObjectException(id, JGitText.Get().corruptObjectNegativeSize);
					}
					return size;
				}
				else
				{
					ReadSome(@in, hdr, 2, 18);
					int c = hdr[0] & unchecked((int)(0xff));
					long size = c & 15;
					int shift = 4;
					int p = 1;
					while ((c & unchecked((int)(0x80))) != 0)
					{
						c = hdr[p++] & unchecked((int)(0xff));
						size += (c & unchecked((int)(0x7f))) << shift;
						shift += 7;
					}
					return size;
				}
			}
			catch (SharpZipBaseException)
			{
				throw new CorruptObjectException(id, JGitText.Get().corruptObjectBadStream);
			}
		}
Exemplo n.º 37
0
		/// <exception cref="System.IO.IOException"></exception>
		internal abstract ObjectLoader OpenObject1(WindowCursor curs, AnyObjectId objectId
			);
Exemplo n.º 38
0
		/// <exception cref="System.IO.IOException"></exception>
		internal abstract ObjectLoader OpenObject2(WindowCursor curs, string objectName, 
			AnyObjectId objectId);
Exemplo n.º 39
0
		/// <exception cref="System.IO.IOException"></exception>
		internal abstract long GetObjectSize2(WindowCursor curs, string objectName, AnyObjectId
			 objectId);
Exemplo n.º 40
0
		/// <exception cref="System.IO.IOException"></exception>
		internal abstract void SelectObjectRepresentation(PackWriter packer, ObjectToPack
			 otp, WindowCursor curs);
Exemplo n.º 41
0
		/// <exception cref="System.IO.IOException"></exception>
		internal static ObjectLoader Open(InputStream @in, FilePath path, AnyObjectId id, 
			WindowCursor wc)
		{
			try
			{
				@in = Buffer(@in);
				@in.Mark(20);
				byte[] hdr = new byte[64];
				IOUtil.ReadFully(@in, hdr, 0, 2);
				if (IsStandardFormat(hdr))
				{
					@in.Reset();
					Inflater inf = wc.Inflater();
					InputStream zIn = Inflate(@in, inf);
					int avail = ReadSome(zIn, hdr, 0, 64);
					if (avail < 5)
					{
						throw new CorruptObjectException(id, JGitText.Get().corruptObjectNoHeader);
					}
					MutableInteger p = new MutableInteger();
					int type = Constants.DecodeTypeString(id, hdr, unchecked((byte)' '), p);
					long size = RawParseUtils.ParseLongBase10(hdr, p.value, p);
					if (size < 0)
					{
						throw new CorruptObjectException(id, JGitText.Get().corruptObjectNegativeSize);
					}
					if (hdr[p.value++] != 0)
					{
						throw new CorruptObjectException(id, JGitText.Get().corruptObjectGarbageAfterSize
							);
					}
					if (path == null && int.MaxValue < size)
					{
						LargeObjectException.ExceedsByteArrayLimit e;
						e = new LargeObjectException.ExceedsByteArrayLimit();
						e.SetObjectId(id);
						throw e;
					}
					if (size < wc.GetStreamFileThreshold() || path == null)
					{
						byte[] data = new byte[(int)size];
						int n = avail - p.value;
						if (n > 0)
						{
							System.Array.Copy(hdr, p.value, data, 0, n);
						}
						IOUtil.ReadFully(zIn, data, n, data.Length - n);
						CheckValidEndOfStream(@in, inf, id, hdr);
						return new ObjectLoader.SmallObject(type, data);
					}
					return new UnpackedObject.LargeObject(type, size, path, id, wc.db);
				}
				else
				{
					ReadSome(@in, hdr, 2, 18);
					int c = hdr[0] & unchecked((int)(0xff));
					int type = (c >> 4) & 7;
					long size = c & 15;
					int shift = 4;
					int p = 1;
					while ((c & unchecked((int)(0x80))) != 0)
					{
						c = hdr[p++] & unchecked((int)(0xff));
						size += (c & unchecked((int)(0x7f))) << shift;
						shift += 7;
					}
					switch (type)
					{
						case Constants.OBJ_COMMIT:
						case Constants.OBJ_TREE:
						case Constants.OBJ_BLOB:
						case Constants.OBJ_TAG:
						{
							// Acceptable types for a loose object.
							break;
						}

						default:
						{
							throw new CorruptObjectException(id, JGitText.Get().corruptObjectInvalidType);
						}
					}
					if (path == null && int.MaxValue < size)
					{
						LargeObjectException.ExceedsByteArrayLimit e;
						e = new LargeObjectException.ExceedsByteArrayLimit();
						e.SetObjectId(id);
						throw e;
					}
					if (size < wc.GetStreamFileThreshold() || path == null)
					{
						@in.Reset();
						IOUtil.SkipFully(@in, p);
						Inflater inf = wc.Inflater();
						InputStream zIn = Inflate(@in, inf);
						byte[] data = new byte[(int)size];
						IOUtil.ReadFully(zIn, data, 0, data.Length);
						CheckValidEndOfStream(@in, inf, id, hdr);
						return new ObjectLoader.SmallObject(type, data);
					}
					return new UnpackedObject.LargeObject(type, size, path, id, wc.db);
				}
			}
			catch (SharpZipBaseException)
			{
				throw new CorruptObjectException(id, JGitText.Get().corruptObjectBadStream);
			}
		}
Exemplo n.º 42
0
		/// <exception cref="System.IO.IOException"></exception>
		internal ObjectLoader OpenObjectImpl2(WindowCursor curs, string objectName, AnyObjectId
			 objectId)
		{
			ObjectLoader ldr;
			ldr = OpenObject2(curs, objectName, objectId);
			if (ldr != null)
			{
				return ldr;
			}
			foreach (FileObjectDatabase.AlternateHandle alt in MyAlternates())
			{
				ldr = alt.db.OpenObjectImpl2(curs, objectName, objectId);
				if (ldr != null)
				{
					return ldr;
				}
			}
			return null;
		}
Exemplo n.º 43
0
		/// <exception cref="System.IO.IOException"></exception>
		internal override ObjectLoader OpenObject2(WindowCursor curs, string objectName, 
			AnyObjectId objectId)
		{
			try
			{
				FilePath path = FileFor(objectName);
				FileInputStream @in = new FileInputStream(path);
				try
				{
					unpackedObjectCache.Add(objectId);
					return UnpackedObject.Open(@in, path, objectId, curs);
				}
				finally
				{
					@in.Close();
				}
			}
			catch (FileNotFoundException)
			{
				unpackedObjectCache.Remove(objectId);
				return null;
			}
		}
Exemplo n.º 44
0
		/// <exception cref="System.IO.IOException"></exception>
		internal override void SelectObjectRepresentation(PackWriter packer, ObjectToPack
			 otp, WindowCursor curs)
		{
			ObjectDirectory.PackList pList = packList.Get();
			for (; ; )
			{
				foreach (PackFile p in pList.packs)
				{
					try
					{
						LocalObjectRepresentation rep = p.Representation(curs, otp);
						if (rep != null)
						{
							packer.Select(otp, rep);
						}
					}
					catch (PackMismatchException)
					{
						// Pack was modified; refresh the entire pack list.
						//
						pList = ScanPacks(pList);
						goto SEARCH_continue;
					}
					catch (IOException)
					{
						// Assume the pack is corrupted.
						//
						RemovePack(p);
					}
				}
				goto SEARCH_break;
SEARCH_continue: ;
			}
SEARCH_break: ;
			foreach (FileObjectDatabase.AlternateHandle h in MyAlternates())
			{
				h.db.SelectObjectRepresentation(packer, otp, curs);
			}
		}
Exemplo n.º 45
0
		/// <exception cref="System.IO.IOException"></exception>
		internal override long GetObjectSize2(WindowCursor curs, string objectName, AnyObjectId
			 objectId)
		{
			try
			{
				FilePath path = FileFor(objectName);
				FileInputStream @in = new FileInputStream(path);
				try
				{
					return UnpackedObject.GetSize(@in, objectId, curs);
				}
				finally
				{
					@in.Close();
				}
			}
			catch (FileNotFoundException)
			{
				return -1;
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal override void SelectObjectRepresentation(PackWriter packer, ObjectToPack
			 otp, WindowCursor curs)
		{
			wrapped.SelectObjectRepresentation(packer, otp, curs);
		}
Exemplo n.º 47
0
		/// <exception cref="System.IO.IOException"></exception>
		internal long GetObjectSizeImpl1(WindowCursor curs, AnyObjectId objectId)
		{
			long sz;
			sz = GetObjectSize1(curs, objectId);
			if (0 <= sz)
			{
				return sz;
			}
			foreach (FileObjectDatabase.AlternateHandle alt in MyAlternates())
			{
				sz = alt.db.GetObjectSizeImpl1(curs, objectId);
				if (0 <= sz)
				{
					return sz;
				}
			}
			if (TryAgain1())
			{
				sz = GetObjectSize1(curs, objectId);
				if (0 <= sz)
				{
					return sz;
				}
			}
			return -1;
		}
Exemplo n.º 48
0
			public _Filter_195(LargePackedDeltaObject _enclosing, ObjectDirectoryInserter odi
				, WindowCursor wc, FilePath tmp, ObjectId myId, int baseArg1, long baseArg2, InputStream
				 baseArg3) : base(baseArg1, baseArg2, baseArg3)
			{
				this._enclosing = _enclosing;
				this.odi = odi;
				this.wc = wc;
				this.tmp = tmp;
				this.myId = myId;
			}
Exemplo n.º 49
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public override ObjectStream OpenStream()
		{
			WindowCursor wc = new WindowCursor(db);
			InputStream @in;
			try
			{
				@in = new PackInputStream(pack, objectOffset + headerLength, wc);
			}
			catch (IOException)
			{
				// If the pack file cannot be pinned into the cursor, it
				// probably was repacked recently. Go find the object
				// again and open the stream from that location instead.
				//
				return wc.Open(GetObjectId(), type).OpenStream();
			}
			@in = new BufferedInputStream(new InflaterInputStream(@in, wc.Inflater(), 8192), 
				8192);
			//
			//
			//
			//
			//
			return new ObjectStream.Filter(type, size, @in);
		}
Exemplo n.º 50
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
		private InputStream Open(WindowCursor wc)
		{
			InputStream delta;
			try
			{
				delta = new PackInputStream(pack, objectOffset + headerLength, wc);
			}
			catch (IOException)
			{
				// If the pack file cannot be pinned into the cursor, it
				// probably was repacked recently. Go find the object
				// again and open the stream from that location instead.
				//
				return wc.Open(GetObjectId()).OpenStream();
			}
			delta = new InflaterInputStream(delta);
			ObjectLoader @base = pack.Load(wc, baseOffset);
			DeltaStream ds = new _DeltaStream_223(@base, wc, delta);
			// This code path should never be used as DeltaStream
			// is supposed to open the stream first, which would
			// initialize the size for us directly from the stream.
			if (type == Constants.OBJ_BAD)
			{
				if (!(@base is NGit.Storage.File.LargePackedDeltaObject))
				{
					type = @base.GetType();
				}
			}
			if (size == SIZE_UNKNOWN)
			{
				size = ds.GetSize();
			}
			return ds;
		}
Exemplo n.º 51
0
		/// <exception cref="System.IO.IOException"></exception>
		internal abstract long GetObjectSize1(WindowCursor curs, AnyObjectId objectId);
Exemplo n.º 52
0
			public _DeltaStream_223(ObjectLoader @base, WindowCursor wc, InputStream baseArg1
				) : base(baseArg1)
			{
				this.@base = @base;
				this.wc = wc;
				this.baseSize = NGit.Storage.File.LargePackedDeltaObject.SIZE_UNKNOWN;
			}
Exemplo n.º 53
0
		public override int GetType()
		{
			if (type == Constants.OBJ_BAD)
			{
				WindowCursor wc = new WindowCursor(db);
				try
				{
					type = pack.GetObjectType(wc, objectOffset);
				}
				catch (IOException)
				{
					// If the pack file cannot be pinned into the cursor, it
					// probably was repacked recently. Go find the object
					// again and get the type from that location instead.
					//
					try
					{
						type = wc.Open(GetObjectId()).GetType();
					}
					catch (IOException)
					{
					}
				}
				finally
				{
					// "He's dead, Jim." We just can't discover the type
					// and the interface isn't supposed to be lazy here.
					// Report an invalid type code instead, callers will
					// wind up bailing out with an error at some point.
					wc.Release();
				}
			}
			return type;
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal override ObjectLoader OpenObject(WindowCursor curs, AnyObjectId objectId
			)
		{
			return OpenObjectImpl1(curs, objectId);
		}
Exemplo n.º 55
0
		/// <exception cref="System.IO.IOException"></exception>
		internal virtual long GetObjectSize(WindowCursor curs, AnyObjectId objectId)
		{
			long sz = GetObjectSizeImpl1(curs, objectId);
			if (0 <= sz)
			{
				return sz;
			}
			return GetObjectSizeImpl2(curs, objectId.Name, objectId);
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal override ObjectLoader OpenObject2(WindowCursor curs, string objectName, 
			AnyObjectId objectId)
		{
			if (unpackedObjects.Contains(objectId))
			{
				return wrapped.OpenObject2(curs, objectName, objectId);
			}
			return null;
		}
Exemplo n.º 57
0
		public override long GetSize()
		{
			if (size == SIZE_UNKNOWN)
			{
				WindowCursor wc = new WindowCursor(db);
				try
				{
					byte[] b = pack.GetDeltaHeader(wc, objectOffset + headerLength);
					size = BinaryDelta.GetResultSize(b);
				}
				catch (SharpZipBaseException)
				{
				}
				catch (IOException)
				{
					// The zlib stream for the delta is corrupt. We probably
					// cannot access the object. Keep the size negative and
					// report that bogus result to the caller.
					// If the pack file cannot be pinned into the cursor, it
					// probably was repacked recently. Go find the object
					// again and get the size from that location instead.
					//
					try
					{
						size = wc.Open(GetObjectId()).GetSize();
					}
					catch (IOException)
					{
					}
				}
				finally
				{
					// "He's dead, Jim." We just can't discover the size
					// and the interface isn't supposed to be lazy here.
					// Report an invalid type code instead, callers will
					// wind up bailing out with an error at some point.
					wc.Release();
				}
			}
			return size;
		}
Exemplo n.º 58
0
		/// <exception cref="System.IO.IOException"></exception>
		internal override ObjectLoader OpenObject1(WindowCursor curs, AnyObjectId objectId
			)
		{
			if (unpackedObjectCache.IsUnpacked(objectId))
			{
				ObjectLoader ldr = OpenObject2(curs, objectId.Name, objectId);
				if (ldr != null)
				{
					return ldr;
				}
				else
				{
					unpackedObjectCache.Remove(objectId);
				}
			}
			ObjectDirectory.PackList pList = packList.Get();
			for (; ; )
			{
				foreach (PackFile p in pList.packs)
				{
					try
					{
						ObjectLoader ldr = p.Get(curs, objectId);
						if (ldr != null)
						{
							return ldr;
						}
					}
					catch (PackMismatchException)
					{
						// Pack was modified; refresh the entire pack list.
						//
						pList = ScanPacks(pList);
						goto SEARCH_continue;
					}
					catch (IOException)
					{
						// Assume the pack is corrupted.
						//
						RemovePack(p);
					}
				}
				return null;
SEARCH_continue: ;
			}
SEARCH_break: ;
		}
Exemplo n.º 59
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public override ObjectStream OpenStream()
		{
			// If the object was recently unpacked, its available loose.
			// The loose format is going to be faster to access than a
			// delta applied on top of a base. Use that whenever we can.
			//
			ObjectId myId = GetObjectId();
			WindowCursor wc = new WindowCursor(db);
			ObjectLoader ldr = db.OpenObject2(wc, myId.Name, myId);
			if (ldr != null)
			{
				return ldr.OpenStream();
			}
			InputStream @in = Open(wc);
			@in = new BufferedInputStream(@in, 8192);
			// While we inflate the object, also deflate it back as a loose
			// object. This will later be cleaned up by a gc pass, but until
			// then we will reuse the loose form by the above code path.
			//
			int myType = GetType();
			long mySize = GetSize();
			ObjectDirectoryInserter odi = ((ObjectDirectoryInserter)db.NewInserter());
			FilePath tmp = odi.NewTempFile();
			DeflaterOutputStream dOut = odi.Compress(new FileOutputStream(tmp));
			odi.WriteHeader(dOut, myType, mySize);
			@in = new TeeInputStream(@in, dOut);
			return new _Filter_195(this, odi, wc, tmp, myId, myType, mySize, @in);
		}
Exemplo n.º 60
0
		/// <exception cref="System.IO.IOException"></exception>
		internal long GetObjectSizeImpl2(WindowCursor curs, string objectName, AnyObjectId
			 objectId)
		{
			long sz;
			sz = GetObjectSize2(curs, objectName, objectId);
			if (0 <= sz)
			{
				return sz;
			}
			foreach (FileObjectDatabase.AlternateHandle alt in MyAlternates())
			{
				sz = alt.db.GetObjectSizeImpl2(curs, objectName, objectId);
				if (0 <= sz)
				{
					return sz;
				}
			}
			return -1;
		}