Esempio n. 1
0
 /// <exception cref="NGit.Errors.MissingObjectException"></exception>
 /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 private RevObject EnterTree(RevObject obj)
 {
     ObjectWalk.TreeVisit tv = NewTreeVisit(obj);
     tv.parent = currVisit;
     currVisit = tv;
     return(obj);
 }
Esempio n. 2
0
 public override void Dispose()
 {
     base.Dispose();
     pendingObjects = new BlockObjQueue();
     firstCommit    = null;
     lastCommit     = null;
     currVisit      = null;
     freeVisit      = null;
 }
Esempio n. 3
0
        /// <summary>Get the current object's path hash code.</summary>
        /// <remarks>
        /// Get the current object's path hash code.
        /// <p>
        /// This method computes a hash code on the fly for this path, the hash is
        /// suitable to cluster objects that may have similar paths together.
        /// </remarks>
        /// <returns>path hash code; any integer may be returned.</returns>
        public virtual int GetPathHashCode()
        {
            ObjectWalk.TreeVisit tv = currVisit;
            if (tv == null)
            {
                return(0);
            }
            int nameEnd = tv.nameEnd;

            if (nameEnd == 0)
            {
                // When nameEnd == 0 the subtree is itself the current path
                // being visited. The name hash must be obtained from its
                // parent tree. If there is no parent, this is a root tree with
                // a hash code of 0.
                tv = tv.parent;
                if (tv == null)
                {
                    return(0);
                }
                nameEnd = tv.nameEnd;
            }
            byte[] buf;
            int    ptr;

            if (16 <= (nameEnd - tv.namePtr))
            {
                buf = tv.buf;
                ptr = nameEnd - 16;
            }
            else
            {
                nameEnd = pathLen;
                if (nameEnd == 0)
                {
                    nameEnd = UpdatePathBuf(currVisit);
                    pathLen = nameEnd;
                }
                buf = pathBuf;
                ptr = Math.Max(0, nameEnd - 16);
            }
            int hash = 0;

            for (; ptr < nameEnd; ptr++)
            {
                byte c = buf[ptr];
                if (c != ' ')
                {
                    hash = ((int)(((uint)hash) >> 2)) + (c << 24);
                }
            }
            return(hash);
        }
Esempio n. 4
0
 protected internal override void Reset(int retainFlags)
 {
     base.Reset(retainFlags);
     foreach (RevObject obj in rootObjects)
     {
         obj.flags &= ~IN_PENDING;
     }
     rootObjects    = new AList <RevObject>();
     pendingObjects = new BlockObjQueue();
     firstCommit    = null;
     lastCommit     = null;
     currVisit      = null;
     freeVisit      = null;
 }
Esempio n. 5
0
 /// <exception cref="NGit.Errors.LargeObjectException"></exception>
 /// <exception cref="NGit.Errors.MissingObjectException"></exception>
 /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 private ObjectWalk.TreeVisit NewTreeVisit(RevObject obj)
 {
     ObjectWalk.TreeVisit tv = freeVisit;
     if (tv != null)
     {
         freeVisit  = tv.parent;
         tv.ptr     = 0;
         tv.namePtr = 0;
         tv.nameEnd = 0;
         tv.pathLen = 0;
     }
     else
     {
         tv = new ObjectWalk.TreeVisit();
     }
     tv.obj = obj;
     tv.buf = reader.Open(obj, Constants.OBJ_TREE).GetCachedBytes();
     return(tv);
 }
Esempio n. 6
0
        private int UpdatePathBuf(ObjectWalk.TreeVisit tv)
        {
            if (tv == null)
            {
                return(0);
            }
            // If nameEnd == 0 this tree has not yet contributed an entry.
            // Update only for the parent, which if null will be empty.
            int nameEnd = tv.nameEnd;

            if (nameEnd == 0)
            {
                return(UpdatePathBuf(tv.parent));
            }
            int ptr = tv.pathLen;

            if (ptr == 0)
            {
                ptr = UpdatePathBuf(tv.parent);
                if (ptr == pathBuf.Length)
                {
                    GrowPathBuf(ptr);
                }
                if (ptr != 0)
                {
                    pathBuf[ptr++] = (byte)('/');
                }
                tv.pathLen = ptr;
            }
            int namePtr = tv.namePtr;
            int nameLen = nameEnd - namePtr;
            int end     = ptr + nameLen;

            while (pathBuf.Length < end)
            {
                GrowPathBuf(ptr);
            }
            System.Array.Copy(tv.buf, namePtr, pathBuf, ptr, nameLen);
            return(end);
        }
Esempio n. 7
0
		private void ReleaseTreeVisit(ObjectWalk.TreeVisit tv)
		{
			tv.buf = null;
			tv.parent = freeVisit;
			freeVisit = tv;
		}
Esempio n. 8
0
		/// <exception cref="NGit.Errors.LargeObjectException"></exception>
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private ObjectWalk.TreeVisit NewTreeVisit(RevObject obj)
		{
			ObjectWalk.TreeVisit tv = freeVisit;
			if (tv != null)
			{
				freeVisit = tv.parent;
				tv.ptr = 0;
				tv.namePtr = 0;
				tv.nameEnd = 0;
				tv.pathLen = 0;
			}
			else
			{
				tv = new ObjectWalk.TreeVisit();
			}
			tv.obj = obj;
			tv.buf = reader.Open(obj, Constants.OBJ_TREE).GetCachedBytes();
			return tv;
		}
Esempio n. 9
0
		protected internal override void Reset(int retainFlags)
		{
			base.Reset(retainFlags);
			foreach (RevObject obj in rootObjects)
			{
				obj.flags &= ~IN_PENDING;
			}
			rootObjects = new AList<RevObject>();
			pendingObjects = new BlockObjQueue();
			firstCommit = null;
			lastCommit = null;
			currVisit = null;
			freeVisit = null;
		}
Esempio n. 10
0
		public override void Dispose()
		{
			base.Dispose();
			pendingObjects = new BlockObjQueue();
			firstCommit = null;
			lastCommit = null;
			currVisit = null;
			freeVisit = null;
		}
Esempio n. 11
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private RevObject EnterTree(RevObject obj)
		{
			ObjectWalk.TreeVisit tv = NewTreeVisit(obj);
			tv.parent = currVisit;
			currVisit = tv;
			return obj;
		}
Esempio n. 12
0
		/// <summary>Pop the next most recent object.</summary>
		/// <remarks>Pop the next most recent object.</remarks>
		/// <returns>next most recent object; null if traversal is over.</returns>
		/// <exception cref="NGit.Errors.MissingObjectException">
		/// one or or more of the next objects are not available from the
		/// object database, but were thought to be candidates for
		/// traversal. This usually indicates a broken link.
		/// </exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException">
		/// one or or more of the objects in a tree do not match the type
		/// indicated.
		/// </exception>
		/// <exception cref="System.IO.IOException">a pack file or loose object could not be read.
		/// 	</exception>
		public virtual RevObject NextObject()
		{
			pathLen = 0;
			ObjectWalk.TreeVisit tv = currVisit;
			while (tv != null)
			{
				byte[] buf = tv.buf;
				for (int ptr = tv.ptr; ptr < buf.Length; )
				{
					int startPtr = ptr;
					ptr = FindObjectId(buf, ptr);
					idBuffer.FromRaw(buf, ptr);
					ptr += ID_SZ;
					RevObject obj = objects.Get(idBuffer);
					if (obj != null && (obj.flags & SEEN) != 0)
					{
						continue;
					}
					int mode = ParseMode(buf, startPtr, ptr, tv);
					int flags;
					switch ((int)(((uint)mode) >> TYPE_SHIFT))
					{
						case TYPE_FILE:
						case TYPE_SYMLINK:
						{
							if (obj == null)
							{
								obj = new RevBlob(idBuffer);
								obj.flags = SEEN;
								objects.Add(obj);
								return obj;
							}
							if (!(obj is RevBlob))
							{
								throw new IncorrectObjectTypeException(obj, Constants.OBJ_BLOB);
							}
							obj.flags = flags = obj.flags | SEEN;
							if ((flags & UNINTERESTING) == 0)
							{
								return obj;
							}
							if (boundary)
							{
								return obj;
							}
							continue;
							goto case TYPE_TREE;
						}

						case TYPE_TREE:
						{
							if (obj == null)
							{
								obj = new RevTree(idBuffer);
								obj.flags = SEEN;
								objects.Add(obj);
								return EnterTree(obj);
							}
							if (!(obj is RevTree))
							{
								throw new IncorrectObjectTypeException(obj, Constants.OBJ_TREE);
							}
							obj.flags = flags = obj.flags | SEEN;
							if ((flags & UNINTERESTING) == 0)
							{
								return EnterTree(obj);
							}
							if (boundary)
							{
								return EnterTree(obj);
							}
							continue;
							goto case TYPE_GITLINK;
						}

						case TYPE_GITLINK:
						{
							continue;
							goto default;
						}

						default:
						{
							throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
								, string.Format("%o", Sharpen.Extensions.ValueOf(mode)), idBuffer.Name, RawParseUtils
								.Decode(buf, tv.namePtr, tv.nameEnd), tv.obj));
						}
					}
				}
				currVisit = tv.parent;
				ReleaseTreeVisit(tv);
				tv = currVisit;
			}
			for (; ; )
			{
				RevObject o = pendingObjects.Next();
				if (o == null)
				{
					reader.WalkAdviceEnd();
					return null;
				}
				int flags = o.flags;
				if ((flags & SEEN) != 0)
				{
					continue;
				}
				flags |= SEEN;
				o.flags = flags;
				if ((flags & UNINTERESTING) == 0 | boundary)
				{
					if (o is RevTree)
					{
						tv = NewTreeVisit(o);
						tv.parent = null;
						currVisit = tv;
					}
					return o;
				}
			}
		}
Esempio n. 13
0
 private void ReleaseTreeVisit(ObjectWalk.TreeVisit tv)
 {
     tv.buf    = null;
     tv.parent = freeVisit;
     freeVisit = tv;
 }
Esempio n. 14
0
        private static int ParseMode(byte[] buf, int startPtr, int recEndPtr, ObjectWalk.TreeVisit
                                     tv)
        {
            int mode = buf[startPtr] - '0';

            for (; ;)
            {
                byte c = buf[++startPtr];
                if (' ' == c)
                {
                    break;
                }
                mode <<= 3;
                mode  += c - '0';
                c      = buf[++startPtr];
                if (' ' == c)
                {
                    break;
                }
                mode <<= 3;
                mode  += c - '0';
                c      = buf[++startPtr];
                if (' ' == c)
                {
                    break;
                }
                mode <<= 3;
                mode  += c - '0';
                c      = buf[++startPtr];
                if (' ' == c)
                {
                    break;
                }
                mode <<= 3;
                mode  += c - '0';
                c      = buf[++startPtr];
                if (' ' == c)
                {
                    break;
                }
                mode <<= 3;
                mode  += c - '0';
                c      = buf[++startPtr];
                if (' ' == c)
                {
                    break;
                }
                mode <<= 3;
                mode  += c - '0';
                c      = buf[++startPtr];
                if (' ' == c)
                {
                    break;
                }
                mode <<= 3;
                mode  += c - '0';
            }
            tv.ptr     = recEndPtr;
            tv.namePtr = startPtr + 1;
            tv.nameEnd = recEndPtr - (ID_SZ + 1);
            return(mode);
        }
Esempio n. 15
0
        /// <summary>Pop the next most recent object.</summary>
        /// <remarks>Pop the next most recent object.</remarks>
        /// <returns>next most recent object; null if traversal is over.</returns>
        /// <exception cref="NGit.Errors.MissingObjectException">
        /// one or or more of the next objects are not available from the
        /// object database, but were thought to be candidates for
        /// traversal. This usually indicates a broken link.
        /// </exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException">
        /// one or or more of the objects in a tree do not match the type
        /// indicated.
        /// </exception>
        /// <exception cref="System.IO.IOException">a pack file or loose object could not be read.
        ///     </exception>
        public virtual RevObject NextObject()
        {
            pathLen = 0;
            ObjectWalk.TreeVisit tv = currVisit;
            while (tv != null)
            {
                byte[] buf = tv.buf;
                for (int ptr = tv.ptr; ptr < buf.Length;)
                {
                    int startPtr = ptr;
                    ptr = FindObjectId(buf, ptr);
                    idBuffer.FromRaw(buf, ptr);
                    ptr += ID_SZ;
                    RevObject obj = objects.Get(idBuffer);
                    if (obj != null && (obj.flags & SEEN) != 0)
                    {
                        continue;
                    }
                    int mode = ParseMode(buf, startPtr, ptr, tv);
                    int flags;
                    switch ((int)(((uint)mode) >> TYPE_SHIFT))
                    {
                    case TYPE_FILE:
                    case TYPE_SYMLINK:
                    {
                        if (obj == null)
                        {
                            obj       = new RevBlob(idBuffer);
                            obj.flags = SEEN;
                            objects.Add(obj);
                            return(obj);
                        }
                        if (!(obj is RevBlob))
                        {
                            throw new IncorrectObjectTypeException(obj, Constants.OBJ_BLOB);
                        }
                        obj.flags = flags = obj.flags | SEEN;
                        if ((flags & UNINTERESTING) == 0)
                        {
                            return(obj);
                        }
                        if (boundary)
                        {
                            return(obj);
                        }
                        continue;
                        goto case TYPE_TREE;
                    }

                    case TYPE_TREE:
                    {
                        if (obj == null)
                        {
                            obj       = new RevTree(idBuffer);
                            obj.flags = SEEN;
                            objects.Add(obj);
                            return(EnterTree(obj));
                        }
                        if (!(obj is RevTree))
                        {
                            throw new IncorrectObjectTypeException(obj, Constants.OBJ_TREE);
                        }
                        obj.flags = flags = obj.flags | SEEN;
                        if ((flags & UNINTERESTING) == 0)
                        {
                            return(EnterTree(obj));
                        }
                        if (boundary)
                        {
                            return(EnterTree(obj));
                        }
                        continue;
                        goto case TYPE_GITLINK;
                    }

                    case TYPE_GITLINK:
                    {
                        continue;
                        goto default;
                    }

                    default:
                    {
                        throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
                                                                              , string.Format("%o", Sharpen.Extensions.ValueOf(mode)), idBuffer.Name, RawParseUtils
                                                                              .Decode(buf, tv.namePtr, tv.nameEnd), tv.obj));
                    }
                    }
                }
                currVisit = tv.parent;
                ReleaseTreeVisit(tv);
                tv = currVisit;
            }
            for (; ;)
            {
                RevObject o = pendingObjects.Next();
                if (o == null)
                {
                    reader.WalkAdviceEnd();
                    return(null);
                }
                int flags = o.flags;
                if ((flags & SEEN) != 0)
                {
                    continue;
                }
                flags  |= SEEN;
                o.flags = flags;
                if ((flags & UNINTERESTING) == 0 | boundary)
                {
                    if (o is RevTree)
                    {
                        tv        = NewTreeVisit(o);
                        tv.parent = null;
                        currVisit = tv;
                    }
                    return(o);
                }
            }
        }