/// <exception cref="System.IO.IOException"></exception>
        private void ReadTree(byte[] raw)
        {
            int rawSize = raw.Length;
            int rawPtr  = 0;

            TreeEntry[] temp;
            int         nextIndex = 0;

            while (rawPtr < rawSize)
            {
                while (rawPtr < rawSize && raw[rawPtr] != 0)
                {
                    rawPtr++;
                }
                rawPtr++;
                rawPtr += Constants.OBJECT_ID_LENGTH;
                nextIndex++;
            }
            temp      = new TreeEntry[nextIndex];
            rawPtr    = 0;
            nextIndex = 0;
            while (rawPtr < rawSize)
            {
                int c = raw[rawPtr++];
                if (c < '0' || c > '7')
                {
                    throw new CorruptObjectException(GetId(), JGitText.Get().corruptObjectInvalidEntryMode
                                                     );
                }
                int mode = c - '0';
                for (; ;)
                {
                    c = raw[rawPtr++];
                    if (' ' == c)
                    {
                        break;
                    }
                    else
                    {
                        if (c < '0' || c > '7')
                        {
                            throw new CorruptObjectException(GetId(), JGitText.Get().corruptObjectInvalidMode
                                                             );
                        }
                    }
                    mode <<= 3;
                    mode  += c - '0';
                }
                int nameLen = 0;
                while (raw[rawPtr + nameLen] != 0)
                {
                    nameLen++;
                }
                byte[] name = new byte[nameLen];
                System.Array.Copy(raw, rawPtr, name, 0, nameLen);
                rawPtr += nameLen + 1;
                ObjectId id = ObjectId.FromRaw(raw, rawPtr);
                rawPtr += Constants.OBJECT_ID_LENGTH;
                TreeEntry ent;
                if (FileMode.REGULAR_FILE.Equals(mode))
                {
                    ent = new FileTreeEntry(this, id, name, false);
                }
                else
                {
                    if (FileMode.EXECUTABLE_FILE.Equals(mode))
                    {
                        ent = new FileTreeEntry(this, id, name, true);
                    }
                    else
                    {
                        if (FileMode.TREE.Equals(mode))
                        {
                            ent = new NGit.Tree(this, id, name);
                        }
                        else
                        {
                            if (FileMode.SYMLINK.Equals(mode))
                            {
                                ent = new SymlinkTreeEntry(this, id, name);
                            }
                            else
                            {
                                if (FileMode.GITLINK.Equals(mode))
                                {
                                    ent = new GitlinkTreeEntry(this, id, name);
                                }
                                else
                                {
                                    throw new CorruptObjectException(GetId(), MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode2
                                                                                                   , Sharpen.Extensions.ToOctalString(mode)));
                                }
                            }
                        }
                    }
                }
                temp[nextIndex++] = ent;
            }
            contents = temp;
        }
Esempio n. 2
0
		/// <exception cref="System.IO.IOException"></exception>
		public override void VisitSymlink(SymlinkTreeEntry s)
		{
			if (s.IsModified())
			{
				throw new SymlinksNotSupportedException(MessageFormat.Format(JGitText.Get().symlinkCannotBeWrittenAsTheLinkTarget
					, s.GetFullName()));
			}
		}
Esempio n. 3
0
		/// <exception cref="System.IO.IOException"></exception>
		private void ReadTree(byte[] raw)
		{
			int rawSize = raw.Length;
			int rawPtr = 0;
			TreeEntry[] temp;
			int nextIndex = 0;
			while (rawPtr < rawSize)
			{
				while (rawPtr < rawSize && raw[rawPtr] != 0)
				{
					rawPtr++;
				}
				rawPtr++;
				rawPtr += Constants.OBJECT_ID_LENGTH;
				nextIndex++;
			}
			temp = new TreeEntry[nextIndex];
			rawPtr = 0;
			nextIndex = 0;
			while (rawPtr < rawSize)
			{
				int c = raw[rawPtr++];
				if (c < '0' || c > '7')
				{
					throw new CorruptObjectException(GetId(), JGitText.Get().corruptObjectInvalidEntryMode
						);
				}
				int mode = c - '0';
				for (; ; )
				{
					c = raw[rawPtr++];
					if (' ' == c)
					{
						break;
					}
					else
					{
						if (c < '0' || c > '7')
						{
							throw new CorruptObjectException(GetId(), JGitText.Get().corruptObjectInvalidMode
								);
						}
					}
					mode <<= 3;
					mode += c - '0';
				}
				int nameLen = 0;
				while (raw[rawPtr + nameLen] != 0)
				{
					nameLen++;
				}
				byte[] name = new byte[nameLen];
				System.Array.Copy(raw, rawPtr, name, 0, nameLen);
				rawPtr += nameLen + 1;
				ObjectId id = ObjectId.FromRaw(raw, rawPtr);
				rawPtr += Constants.OBJECT_ID_LENGTH;
				TreeEntry ent;
				if (FileMode.REGULAR_FILE.Equals(mode))
				{
					ent = new FileTreeEntry(this, id, name, false);
				}
				else
				{
					if (FileMode.EXECUTABLE_FILE.Equals(mode))
					{
						ent = new FileTreeEntry(this, id, name, true);
					}
					else
					{
						if (FileMode.TREE.Equals(mode))
						{
							ent = new NGit.Tree(this, id, name);
						}
						else
						{
							if (FileMode.SYMLINK.Equals(mode))
							{
								ent = new SymlinkTreeEntry(this, id, name);
							}
							else
							{
								if (FileMode.GITLINK.Equals(mode))
								{
									ent = new GitlinkTreeEntry(this, id, name);
								}
								else
								{
									throw new CorruptObjectException(GetId(), MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode2
										, Sharpen.Extensions.ToOctalString(mode)));
								}
							}
						}
					}
				}
				temp[nextIndex++] = ent;
			}
			contents = temp;
		}
		public abstract void VisitSymlink(SymlinkTreeEntry arg1);