public override void Select(StoredObjectRepresentation @ref)
        {
            LocalObjectRepresentation ptr = (LocalObjectRepresentation)@ref;

            this.pack   = ptr.pack;
            this.offset = ptr.offset;
            this.length = ptr.length;
        }
示例#2
0
 public override bool HasObject(ObjectToPack obj, StoredObjectRepresentation rep)
 {
     try
     {
         LocalObjectRepresentation local = (LocalObjectRepresentation)rep;
         foreach (PackFile pack in GetPacks())
         {
             if (local.pack == pack)
             {
                 return(true);
             }
         }
         return(false);
     }
     catch (FileNotFoundException)
     {
         return(false);
     }
 }
示例#3
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);
     }
 }
示例#4
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)));
            }
            }
        }