/// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="NGit.Diff.SimilarityIndex.TableFullException"></exception>
        private SimilarityIndex Hash(DiffEntry.Side side, DiffEntry ent)
        {
            SimilarityIndex r = new SimilarityIndex();

            r.Hash(reader.Open(side, ent));
            r.Sort();
            return(r);
        }
コード例 #2
0
ファイル: ContentSource.cs プロジェクト: TetradogOther/NGit
            /// <summary>Open the object.</summary>
            /// <remarks>Open the object.</remarks>
            /// <param name="side">which side of the entry to read (OLD or NEW).</param>
            /// <param name="ent">the entry to examine.</param>
            /// <returns>
            /// a loader that can supply the content of the file. The loader
            /// must be used before another loader can be obtained from this
            /// same source.
            /// </returns>
            /// <exception cref="System.IO.IOException">the file cannot be accessed.</exception>
            public ObjectLoader Open(DiffEntry.Side side, DiffEntry ent)
            {
                switch (side)
                {
                case DiffEntry.Side.OLD:
                {
                    return(oldSource.Open(ent.oldPath, ent.oldId.ToObjectId()));
                }

                case DiffEntry.Side.NEW:
                {
                    return(newSource.Open(ent.newPath, ent.newId.ToObjectId()));
                }

                default:
                {
                    throw new ArgumentException();
                }
                }
            }
コード例 #3
0
 /// <summary>Get the object id.</summary>
 /// <remarks>Get the object id.</remarks>
 /// <param name="side">the side of the id to get.</param>
 /// <returns>the object id; null if there is no index line</returns>
 public virtual AbbreviatedObjectId GetId(DiffEntry.Side side)
 {
     return(side == DiffEntry.Side.OLD ? GetOldId() : GetNewId());
 }
コード例 #4
0
 /// <summary>Get the mode associated with this file.</summary>
 /// <remarks>Get the mode associated with this file.</remarks>
 /// <param name="side">which mode to obtain.</param>
 /// <returns>the mode.</returns>
 public virtual FileMode GetMode(DiffEntry.Side side)
 {
     return(side == DiffEntry.Side.OLD ? GetOldMode() : GetNewMode());
 }
コード例 #5
0
 /// <summary>Get the path associated with this file.</summary>
 /// <remarks>Get the path associated with this file.</remarks>
 /// <param name="side">which path to obtain.</param>
 /// <returns>name for this file.</returns>
 public virtual string GetPath(DiffEntry.Side side)
 {
     return(side == DiffEntry.Side.OLD ? GetOldPath() : GetNewPath());
 }
コード例 #6
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;
            }
        }
 /// <exception cref="System.IO.IOException"></exception>
 private long Size(DiffEntry.Side side, DiffEntry ent)
 {
     return(reader.Size(side, ent));
 }