public abstract void VisitFile(FileTreeEntry f);
Exemplo n.º 2
0
        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 += ObjectId.ObjectIdLength;
                nextIndex++;
            }

            temp = new TreeEntry[nextIndex];
            rawPtr = 0;
            nextIndex = 0;
            while (rawPtr < rawSize)
            {
                int c = raw[rawPtr++];
                if (c < '0' || c > '7')
                    throw new CorruptObjectException(this.Id, "invalid entry mode");
                int mode = c - '0';
                for (; ; )
                {
                    c = raw[rawPtr++];
                    if (' ' == c)
                        break;
                    else if (c < '0' || c > '7')
                        throw new CorruptObjectException(this.Id, "invalid mode");
                    mode <<= 3;
                    mode += c - '0';
                }

                int nameLen = 0;
                while (raw[rawPtr + nameLen] != 0)
                    nameLen++;
                byte[] name = new byte[nameLen];
                Array.Copy(raw, rawPtr, name, 0, nameLen);
                rawPtr += nameLen + 1;

                ObjectId id = ObjectId.FromRaw(raw, rawPtr);
                rawPtr += ObjectId.ObjectIdLength;

                TreeEntry ent;
                if (FileMode.RegularFile.Equals(mode))
                    ent = new FileTreeEntry(this, id, name, false);
                else if (FileMode.ExecutableFile.Equals(mode))
                    ent = new FileTreeEntry(this, id, name, true);
                else if (FileMode.Tree.Equals(mode))
                {
                    ent = new Tree(this, id, name);
                }
                else if (FileMode.Symlink.Equals(mode))
                    ent = new SymlinkTreeEntry(this, id, name);
                else
                    throw new CorruptObjectException(this.Id, "Invalid mode: "
                            + Convert.ToString(mode, 8));
                temp[nextIndex++] = ent;
            }

            _contents = temp;
        }
Exemplo n.º 3
0
 public override void VisitFile(FileTreeEntry f)
 {
     f.Id = ow.WriteBlob(PathUtil.CombineFilePath(GetCurrentDirectory(), f.Name));
 }
Exemplo n.º 4
0
        public FileTreeEntry AddFile(byte[] s, int offset)
        {
            int slash;
            int p;

            for (slash = offset; slash < s.Length && s[slash] != '/'; slash++)
            {
                // search for path component terminator
                // [henon] body is empty by intention!
            }

            EnsureLoaded();
            byte xlast = (byte)(slash < s.Length ? '/' : 0);
            p = BinarySearch(_contents, s, xlast, offset, slash);
            if (p >= 0 && slash < s.Length && _contents[p] is Tree)
                return ((Tree)_contents[p]).AddFile(s, slash + 1);

            byte[] newName = SubString(s, offset, slash);
            if (p >= 0)
                throw new EntryExistsException(Constants.CHARSET.GetString(newName));
            else if (slash < s.Length)
            {
                Tree t = new Tree(this, newName);
                InsertEntry(p, t);
                return t.AddFile(s, slash + 1);
            }
            else
            {
                FileTreeEntry f = new FileTreeEntry(this, null, newName, false);
                InsertEntry(p, f);
                return f;
            }
        }
Exemplo n.º 5
0
 public void VisitFile(FileTreeEntry f)
 {
     f.SetModified();
 }