예제 #1
0
파일: PackFileV2.cs 프로젝트: henon/dotgit
        public PackObject GetObjectWithOffset(GitObjectReader reader, int uncompressedSize)
        {
            Debug.WriteLine("Fetching object with offset: {0}".FormatWith(reader.Position));

              // Read first byte, it contains the type and 4 bits of object length
              byte buffer = reader.ReadByte();
              ObjectType type = (ObjectType)((buffer >> 4) & 7);
              long size = buffer & 0xf;

              // Read byte while 8th bit is 1.
              int bitCount = 4;
              while ((buffer & 0x80) != 0) // >> 7 == 1);
              {
            buffer = reader.ReadByte();

            size |= ((long)buffer & 0x7f) << bitCount;
            bitCount += 7;
              }

              if (type == ObjectType.RefDelta)
              {
            return new REFDelta(size, type, reader);
              }
              else if (type == ObjectType.OFSDelta)
              {
            return new OFSDelta(size, type, reader);
              }
              else
              {
            return new Undeltified(size, type, Zlib.Decompress(reader.ReadToEnd()));
              }
        }
예제 #2
0
파일: PackFileV2.cs 프로젝트: henon/dotgit
        private void VerifyPack()
        {
            using (GitObjectReader reader = new GitObjectReader(File.OpenRead(Path)))
              {
            string header;
            int version, numberOfObjects;

            header = reader.ReadBytes(4).GetString();
            version = reader.ReadBytes(4).Sum(b => b);
            numberOfObjects = reader.ReadBytes(4).Sum(b => b);

            if (Version != version)
              throw new PackFileException(String.Format("Bad version number {0}. Was expecting {1}", version, Version), Path);

            if (HEADER != header)
              throw new PackFileException("Invalid header for pack-file. Needs to be: 'PACK'", Path);
              }
        }