Esempio n. 1
0
        /// <exception cref="System.IO.IOException"></exception>
        private byte[] Open(DiffEntry.Side side, DiffEntry entry)
        {
            if (entry.GetMode(side) == FileMode.MISSING)
            {
                return(EMPTY);
            }
            if (entry.GetMode(side).GetObjectType() != Constants.OBJ_BLOB)
            {
                return(EMPTY);
            }
            if (IsBinary())
            {
                return(BINARY);
            }
            AbbreviatedObjectId id = entry.GetId(side);

            if (!id.IsComplete)
            {
                ICollection <ObjectId> ids = reader.Resolve(id);
                if (ids.Count == 1)
                {
                    id = AbbreviatedObjectId.FromObjectId(ids.Iterator().Next());
                    switch (side)
                    {
                    case DiffEntry.Side.OLD:
                    {
                        entry.oldId = id;
                        break;
                    }

                    case DiffEntry.Side.NEW:
                    {
                        entry.newId = id;
                        break;
                    }
                    }
                }
                else
                {
                    if (ids.Count == 0)
                    {
                        throw new MissingObjectException(id, Constants.OBJ_BLOB);
                    }
                    else
                    {
                        throw new AmbiguousObjectException(id, ids);
                    }
                }
            }
            try
            {
                ObjectLoader ldr = source.Open(side, entry);
                return(ldr.GetBytes(binaryFileThreshold));
            }
            catch (LargeObjectException.ExceedsLimit)
            {
                return(BINARY);
            }
            catch (LargeObjectException.ExceedsByteArrayLimit)
            {
                return(BINARY);
            }
            catch (LargeObjectException.OutOfMemory)
            {
                return(BINARY);
            }
            catch (LargeObjectException tooBig)
            {
                tooBig.SetObjectId(id.ToObjectId());
                throw;
            }
        }