示例#1
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual LocalObjectRepresentation Representation(WindowCursor curs, AnyObjectId
                                                                  objectId)
        {
            long pos = Idx().FindOffset(objectId);

            if (pos < 0)
            {
                return(null);
            }
            byte[] ib = curs.tempId;
            ReadFully(pos, ib, 0, 20, curs);
            int c        = ib[0] & unchecked ((int)(0xff));
            int p        = 1;
            int typeCode = (c >> 4) & 7;

            while ((c & unchecked ((int)(0x80))) != 0)
            {
                c = ib[p++] & unchecked ((int)(0xff));
            }
            long len = (FindEndOffset(pos) - pos);

            switch (typeCode)
            {
            case Constants.OBJ_COMMIT:
            case Constants.OBJ_TREE:
            case Constants.OBJ_BLOB:
            case Constants.OBJ_TAG:
            {
                return(LocalObjectRepresentation.NewWhole(this, pos, len - p));
            }

            case Constants.OBJ_OFS_DELTA:
            {
                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);
                }
                ofs = pos - ofs;
                return(LocalObjectRepresentation.NewDelta(this, pos, len - p, ofs));
            }

            case Constants.OBJ_REF_DELTA:
            {
                len -= p;
                len -= Constants.OBJECT_ID_LENGTH;
                ReadFully(pos + p, ib, 0, 20, curs);
                ObjectId id = ObjectId.FromRaw(ib);
                return(LocalObjectRepresentation.NewDelta(this, pos, len, id));
            }

            default:
            {
                throw new IOException(MessageFormat.Format(JGitText.Get().unknownObjectType, Sharpen.Extensions.ValueOf
                                                               (typeCode)));
            }
            }
        }