Пример #1
0
        /// <exception cref="System.IO.IOException"></exception>
        internal override void Resolve(ICollection <ObjectId> matches, AbbreviatedObjectId
                                       id, int matchLimit)
        {
            int[] data = names[id.FirstByte];
            int   max  = (int)(((uint)offset32[id.FirstByte].Length) >> 2);
            int   high = max;

            if (high == 0)
            {
                return;
            }
            int low = 0;

            do
            {
                int p   = (int)(((uint)(low + high)) >> 1);
                int cmp = id.PrefixCompare(data, IdOffset(p));
                if (cmp < 0)
                {
                    high = p;
                }
                else
                {
                    if (cmp == 0)
                    {
                        // We may have landed in the middle of the matches.  Move
                        // backwards to the start of matches, then walk forwards.
                        //
                        while (0 < p && id.PrefixCompare(data, IdOffset(p - 1)) == 0)
                        {
                            p--;
                        }
                        for (; p < max && id.PrefixCompare(data, IdOffset(p)) == 0; p++)
                        {
                            matches.AddItem(ObjectId.FromRaw(data, IdOffset(p)));
                            if (matches.Count > matchLimit)
                            {
                                break;
                            }
                        }
                        return;
                    }
                    else
                    {
                        low = p + 1;
                    }
                }
            }while (low < high);
        }
Пример #2
0
        /// <exception cref="System.IO.IOException"></exception>
        internal override void Resolve(ICollection <ObjectId> matches, AbbreviatedObjectId
                                       id)
        {
            // Go through the packs once. If we didn't find any resolutions
            // scan for new packs and check once more.
            //
            int oldSize = matches.Count;

            ObjectDirectory.PackList pList = packList.Get();
            for (; ;)
            {
                foreach (PackFile p in pList.packs)
                {
                    try
                    {
                        p.Resolve(matches, id, RESOLVE_ABBREV_LIMIT);
                    }
                    catch (IOException)
                    {
                        // Assume the pack is corrupted.
                        //
                        RemovePack(p);
                    }
                    if (matches.Count > RESOLVE_ABBREV_LIMIT)
                    {
                        return;
                    }
                }
                if (matches.Count == oldSize)
                {
                    ObjectDirectory.PackList nList = ScanPacks(pList);
                    if (nList == pList || nList.packs.Length == 0)
                    {
                        break;
                    }
                    pList = nList;
                    continue;
                }
                break;
            }
            string fanOut = Sharpen.Runtime.Substring(id.Name, 0, 2);

            string[] entries = new FilePath(GetDirectory(), fanOut).List();
            if (entries != null)
            {
                foreach (string e in entries)
                {
                    if (e.Length != Constants.OBJECT_ID_STRING_LENGTH - 2)
                    {
                        continue;
                    }
                    try
                    {
                        ObjectId entId = ObjectId.FromString(fanOut + e);
                        if (id.PrefixCompare(entId) == 0)
                        {
                            matches.AddItem(entId);
                        }
                    }
                    catch (ArgumentException)
                    {
                        continue;
                    }
                    if (matches.Count > RESOLVE_ABBREV_LIMIT)
                    {
                        return;
                    }
                }
            }
            foreach (FileObjectDatabase.AlternateHandle alt in MyAlternates())
            {
                alt.db.Resolve(matches, id);
                if (matches.Count > RESOLVE_ABBREV_LIMIT)
                {
                    return;
                }
            }
        }