idBuffer() public method

public idBuffer ( ) : byte[]
return byte[]
Ejemplo n.º 1
0
        public override byte[] idBuffer()
        {
            if (_currentSubtree != null)
            {
                return(SubtreeId);
            }

            if (_currentEntry != null)
            {
                return(_currentEntry.idBuffer());
            }

            return(ZeroId);
        }
Ejemplo n.º 2
0
        ///	<summary>
        /// Write (if necessary) this tree to the object store.
        ///	</summary>
        ///	<param name="cacheEntry">the complete cache from DirCache.</param>
        ///	<param name="cIdx">
        /// first position of <code>cache</code> that is a member of this
        /// tree. The path of <code>cache[cacheIdx].path</code> for the
        /// range <code>[0,pathOff-1)</code> matches the complete path of
        /// this tree, from the root of the repository. </param>
        ///	<param name="pathOffset">
        /// number of bytes of <code>cache[cacheIdx].path</code> that
        /// matches this tree's path. The value at array position
        /// <code>cache[cacheIdx].path[pathOff-1]</code> is always '/' if
        /// <code>pathOff</code> is > 0.
        /// </param>
        ///	<param name="ow">
        /// the writer to use when serializing to the store.
        /// </param>
        ///	<returns>identity of this tree.</returns>
        ///	<exception cref="UnmergedPathException">
        /// one or more paths contain higher-order stages (stage > 0),
        /// which cannot be stored in a tree object.
        /// </exception>
        ///	<exception cref="IOException">
        /// an unexpected error occurred writing to the object store.
        /// </exception>
        public ObjectId writeTree(DirCacheEntry[] cacheEntry, int cIdx, int pathOffset, ObjectWriter ow)
        {
            if (_id == null)
            {
                int endIdx   = cIdx + _entrySpan;
                int size     = ComputeSize(cacheEntry, cIdx, pathOffset, ow);
                var @out     = new MemoryStream(size);
                int childIdx = 0;
                int entryIdx = cIdx;

                while (entryIdx < endIdx)
                {
                    DirCacheEntry e  = cacheEntry[entryIdx];
                    byte[]        ep = e.Path;
                    if (childIdx < _childCount)
                    {
                        DirCacheTree st = _children[childIdx];
                        if (st.contains(ep, pathOffset, ep.Length))
                        {
                            FileMode.Tree.CopyTo(@out);
                            @out.Write(new[] { (byte)' ' }, 0, 1);
                            @out.Write(st._encodedName, 0, st._encodedName.Length);
                            @out.Write(new[] { (byte)0 }, 0, 1);
                            st._id.copyRawTo(@out);

                            entryIdx += st._entrySpan;
                            childIdx++;
                            continue;
                        }
                    }

                    e.getFileMode().CopyTo(@out);
                    @out.Write(new[] { (byte)' ' }, 0, 1);
                    @out.Write(ep, pathOffset, ep.Length - pathOffset);
                    @out.Write(new byte[] { 0 }, 0, 1);
                    @out.Write(e.idBuffer(), e.idOffset(), Constants.OBJECT_ID_LENGTH);
                    entryIdx++;
                }

                _id = ow.WriteCanonicalTree(@out.ToArray());
            }

            return(_id);
        }