/// <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);
        }
 /// <exception cref="System.IO.IOException"></exception>
 private int CalculateModifyScore(ContentSource.Pair reader, DiffEntry d)
 {
     try
     {
         SimilarityIndex src = new SimilarityIndex();
         src.Hash(reader.Open(DiffEntry.Side.OLD, d));
         src.Sort();
         SimilarityIndex dst = new SimilarityIndex();
         dst.Hash(reader.Open(DiffEntry.Side.NEW, d));
         dst.Sort();
         return(src.Score(dst, 100));
     }
     catch (SimilarityIndex.TableFullException)
     {
         // If either table overflowed while being constructed, don't allow
         // the pair to be broken. Returning 1 higher than breakScore will
         // ensure its not similar, but not quite dissimilar enough to break.
         //
         overRenameLimit = true;
         return(breakScore + 1);
     }
 }
Exemple #3
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;
            }
        }