Beispiel #1
0
        private int BinarySearchLevelTwo(AnyObjectId objId, int levelOne)
        {
            int[] data = _names[levelOne];
            var   high = (int)((uint)(_offset32[levelOne].Length) >> 2);

            if (high == 0)
            {
                return(-1);
            }

            int low = 0;

            do
            {
                var mid  = (int)((uint)(low + high) >> 1);
                int mid4 = mid << 2;

                int cmp = objId.CompareTo(data, mid4 + mid);
                if (cmp < 0)
                {
                    high = mid;
                }
                else if (cmp == 0)
                {
                    return(mid);
                }
                else
                {
                    low = mid + 1;
                }
            } while (low < high);
            return(-1);
        }
Beispiel #2
0
        private ObjectLoader OpenObjectImpl1(WindowCursor curs,
                                             AnyObjectId objectId)
        {
            ObjectLoader ldr = openObject1(curs, objectId);

            if (ldr != null)
            {
                return(ldr);
            }

            foreach (ObjectDatabase alt in getAlternates())
            {
                ldr = alt.OpenObjectImpl1(curs, objectId);
                if (ldr != null)
                {
                    return(ldr);
                }
            }

            if (tryAgain1())
            {
                ldr = openObject1(curs, objectId);
                if (ldr != null)
                {
                    return(ldr);
                }
            }

            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Compares this abbreviation to a full object id.
        /// </summary>
        /// <param name="other">the other object id.</param>
        /// <returns>
        /// Return &lt;0 if this abbreviation names an object that is less than
        /// <code>other</code>; 0 if this abbreviation exactly matches the
        /// first <see cref="Length"/> digits of <code>other.name()</code>;
        /// &gt;0 if this abbreviation names an object that is after
        /// <code>other</code>.
        /// </returns>
        public int prefixCompare(AnyObjectId other)
        {
            int cmp = NB.CompareUInt32(_w1, mask(1, other.W1));

            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = NB.CompareUInt32(_w2, mask(2, other.W2));
            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = NB.CompareUInt32(_w3, mask(3, other.W3));
            if (cmp != 0)
            {
                return(cmp);
            }

            cmp = NB.CompareUInt32(_w4, mask(4, other.W4));
            if (cmp != 0)
            {
                return(cmp);
            }

            return(NB.CompareUInt32(_w5, mask(5, other.W5)));
        }
Beispiel #4
0
 public override bool hasObject1(AnyObjectId objectId)
 {
     if (_unpackedObjects.Get(objectId) != null)
     {
         return(true); // known to be loose
     }
     return(base.hasObject1(objectId));
 }
Beispiel #5
0
 public override ObjectLoader openObject2(WindowCursor curs, String objectName,
                                          AnyObjectId objectId)
 {
     if (_unpackedObjects.Get(objectId) == null)
     {
         return(null);
     }
     return(base.openObject2(curs, objectName, objectId));
 }
Beispiel #6
0
        /// <summary>
        /// Compute the location of a loose object file.
        /// </summary>
        /// <param name="objectId">Identity of the loose object to map to the directory.</param>
        /// <returns>Location of the object, if it were to exist as a loose object.</returns>
        public FileInfo fileFor(AnyObjectId objectId)
        {
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }

            return(fileFor(objectId.Name));
        }
Beispiel #7
0
        public override bool Equals(object obj)
        {
            AnyObjectId a = (obj as AnyObjectId);

            if (a != null)
            {
                return(Equals(a));
            }
            return(false);
        }
Beispiel #8
0
        private RefUpdateResult updateImpl(RevWalk.RevWalk walk, Store store)
        {
            RevObject newObj;
            RevObject oldObj;

            if (getRefDatabase().isNameConflicting(Name))
            {
                return(RefUpdateResult.LOCK_FAILURE);
            }
            try
            {
                if (!tryLock(true))
                {
                    return(RefUpdateResult.LOCK_FAILURE);
                }
                if (expValue != null)
                {
                    ObjectId o;
                    o = oldValue != null ? oldValue : ObjectId.ZeroId;
                    if (!AnyObjectId.equals(expValue, o))
                    {
                        return(RefUpdateResult.LOCK_FAILURE);
                    }
                }
                if (oldValue == null)
                {
                    return(store.execute(RefUpdateResult.NEW));
                }

                newObj = safeParse(walk, newValue);
                oldObj = safeParse(walk, oldValue);
                if (newObj == oldObj)
                {
                    return(store.execute(RefUpdateResult.NO_CHANGE));
                }

                if (newObj is RevCommit && oldObj is RevCommit)
                {
                    if (walk.isMergedInto((RevCommit)oldObj, (RevCommit)newObj))
                    {
                        return(store.execute(RefUpdateResult.FAST_FORWARD));
                    }
                }

                if (IsForceUpdate)
                {
                    return(store.execute(RefUpdateResult.FORCED));
                }
                return(RefUpdateResult.REJECTED);
            }
            finally
            {
                unlock();
            }
        }
Beispiel #9
0
        public override long FindCRC32(AnyObjectId objId)
        {
            int levelOne = objId.GetFirstByte();
            int levelTwo = BinarySearchLevelTwo(objId, levelOne);

            if (levelTwo == -1)
            {
                throw new MissingObjectException(objId.Copy(), ObjectType.Unknown);
            }

            return(NB.DecodeUInt32(_crc32[levelOne], levelTwo << 2));
        }
Beispiel #10
0
        protected AnyObjectId(AnyObjectId other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            W1 = other.W1;
            W2 = other.W2;
            W3 = other.W3;
            W4 = other.W4;
            W5 = other.W5;
        }
Beispiel #11
0
        public static bool equals(AnyObjectId firstObjectId, AnyObjectId secondObjectId)
        {
            if (firstObjectId == secondObjectId)
            {
                return(true);
            }

            return(firstObjectId.W2 == secondObjectId.W2 &&
                   firstObjectId.W3 == secondObjectId.W3 &&
                   firstObjectId.W4 == secondObjectId.W4 &&
                   firstObjectId.W5 == secondObjectId.W5 &&
                   firstObjectId.W1 == secondObjectId.W1);
        }
Beispiel #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">SHA-1 of an object.</param>
        /// <returns>
        /// A <see cref="ObjectLoader"/> for accessing the data of the named
        /// object, or null if the object does not exist.
        /// </returns>
        public ObjectLoader OpenObject(AnyObjectId id)
        {
            var wc = new WindowCursor();

            try
            {
                return(OpenObject(wc, id));
            }
            finally
            {
                wc.Release();
            }
        }
Beispiel #13
0
 private bool hasObjectImpl1(AnyObjectId objectId)
 {
     if (hasObject1(objectId))
     {
         return(true);
     }
     foreach (ObjectDatabase alt in getAlternates())
     {
         if (alt.hasObjectImpl1(objectId))
         {
             return(true);
         }
     }
     return(tryAgain1() && hasObject1(objectId));
 }
Beispiel #14
0
 private static RevObject SafeParse(RevWalk.RevWalk rw, AnyObjectId id)
 {
     try
     {
         return(id != null?rw.parseAny(id) : null);
     }
     catch (MissingObjectException)
     {
         // We can expect some objects to be missing, like if we are
         // trying to force a deletion of a branch and the object it
         // points to has been pruned from the database due to freak
         // corruption accidents (it happens with 'git new-work-dir').
         //
         return(null);
     }
 }
Beispiel #15
0
        public override long FindOffset(AnyObjectId objId)
        {
            int levelOne = objId.GetFirstByte();
            int levelTwo = BinarySearchLevelTwo(objId, levelOne);

            if (levelTwo == -1)
            {
                return(-1);
            }

            long p = NB.DecodeUInt32(_offset32[levelOne], levelTwo << 2);

            if ((p & IS_O64) != 0)
            {
                return(NB.DecodeUInt64(_offset64, (8 * (int)(p & ~IS_O64))));
            }

            return(p);
        }
Beispiel #16
0
        private ObjectLoader OpenObjectImpl2(WindowCursor curs, string objectName, AnyObjectId objectId)
        {
            ObjectLoader ldr = openObject2(curs, objectName, objectId);

            if (ldr != null)
            {
                return(ldr);
            }

            foreach (ObjectDatabase alt in getAlternates())
            {
                ldr = alt.OpenObjectImpl2(curs, objectName, objectId);
                if (ldr != null)
                {
                    return(ldr);
                }
            }

            return(null);
        }
        private void Decompress(AnyObjectId id, Inflater inf, int p)
        {
            try
            {
                while (!inf.IsFinished)
                {
                    p += inf.Inflate(_bytes, p, _objectSize - p);
                }
            }
            catch (IOException dfe)
            {
                var coe = new CorruptObjectException(id, "bad stream", dfe);
                throw coe;
            }

            if (p != _objectSize)
            {
                throw new CorruptObjectException(id, "incorrect Length");
            }
        }
Beispiel #18
0
        /// <summary>
        /// Open an object from this database.
        /// <para />
        /// Alternates (if present) are searched automatically.
        /// </summary>
        /// <param name="curs">
        /// Temporary working space associated with the calling thread.
        /// </param>
        /// <param name="objectId">Identity of the object to open.</param>
        /// <returns>
        /// A <see cref="ObjectLoader"/> for accessing the data of the named
        /// object, or null if the object does not exist.
        /// </returns>
        public ObjectLoader openObject(WindowCursor curs, AnyObjectId objectId)
        {
            if (objectId == null)
            {
                return(null);
            }

            ObjectLoader ldr = OpenObjectImpl1(curs, objectId);

            if (ldr != null)
            {
                return(ldr);
            }

            ldr = OpenObjectImpl2(curs, objectId.Name, objectId);
            if (ldr != null)
            {
                return(ldr);
            }
            return(null);
        }
Beispiel #19
0
        public override long FindOffset(AnyObjectId objId)
        {
            int levelOne = objId.GetFirstByte();

            byte[] data = _idxdata[levelOne];
            if (data == null)
            {
                return(-1);
            }

            int high = data.Length / (4 + AnyObjectId.ObjectIdLength);
            int low  = 0;

            do
            {
                int mid = (low + high) / 2;
                int pos = ((4 + AnyObjectId.ObjectIdLength) * mid) + 4;
                int cmp = objId.CompareTo(data, pos);
                if (cmp < 0)
                {
                    high = mid;
                }
                else if (cmp == 0)
                {
                    uint b0 = data[pos - 4] & (uint)0xff;
                    uint b1 = data[pos - 3] & (uint)0xff;
                    uint b2 = data[pos - 2] & (uint)0xff;
                    uint b3 = data[pos - 1] & (uint)0xff;
                    return((((long)b0) << 24) | (b1 << 16) | (b2 << 8) | (b3));
                }
                else
                {
                    low = mid + 1;
                }
            } while (low < high);
            return(-1);
        }
Beispiel #20
0
        public override ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId)
        {
            PackList pList = _packList.get();

            while (true)
            {
SEARCH:
                foreach (PackFile p in pList.packs)
                {
                    try
                    {
                        PackedObjectLoader ldr = p.Get(curs, objectId);
                        if (ldr != null)
                        {
                            ldr.Materialize(curs);
                            return(ldr);
                        }
                    }
                    catch (PackMismatchException)
                    {
                        // Pack was modified; refresh the entire pack list.
                        //
                        pList = ScanPacks(pList);
                        goto SEARCH;
                    }
                    catch (IOException)
                    {
                        // Assume the pack is corrupted.
                        //
                        RemovePack(p);
                    }
                }

                return(null);
            }
        }
Beispiel #21
0
        public override bool hasObject1(AnyObjectId objectId)
        {
            foreach (PackFile p in _packList.get().packs)
            {
                try
                {
                    if (p.HasObject(objectId))
                    {
                        return(true);
                    }
                }
                catch (IOException)
                {
                    // The hasObject call should have only touched the index,
                    // so any failure here indicates the index is unreadable
                    // by this process, and the pack is likewise not readable.
                    //
                    RemovePack(p);
                    continue;
                }
            }

            return(false);
        }
Beispiel #22
0
 public override long FindCRC32(AnyObjectId objId)
 {
     throw new NotSupportedException();
 }
 /// <summary>
 /// Lookup an existing mapping.
 /// </summary>
 /// <param name="toFind">the object identifier to find.</param>
 /// <returns>the instance mapped to toFind, or null if no mapping exists.</returns>
 public TObject Get(AnyObjectId toFind)
 {
     return(this.SingleOrDefault(x => AnyObjectId.equals(toFind.ToObjectId(), x.ToObjectId())));
 }
Beispiel #24
0
 public ObjectToPack(AnyObjectId src, int type)
     : base(src)
 {
     _flags |= type << 1;
 }
Beispiel #25
0
 public bool willInclude(AnyObjectId id)
 {
     return(_objectsMap.Get(id) != null);
 }
Beispiel #26
0
 public override ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId)
 {
     return(_objectDatabase.openObject1(curs, objectId));
 }
Beispiel #27
0
 public override bool hasObject1(AnyObjectId objectId)
 {
     return(_objectDatabase.hasObject1(objectId));
 }
Beispiel #28
0
 public override void OpenObjectInAllPacksImplementation(ICollection <PackedObjectLoader> @out, WindowCursor windowCursor, AnyObjectId objectId)
 {
     _objectDatabase.OpenObjectInAllPacksImplementation(@out, windowCursor, objectId);
 }
Beispiel #29
0
 public override ObjectLoader openObject2(WindowCursor curs, string objectName, AnyObjectId objectId)
 {
     return(_objectDatabase.openObject2(curs, objectName, objectId));
 }
Beispiel #30
0
 public MutableObjectId(AnyObjectId src)
     : base(src)
 {
 }