コード例 #1
0
ファイル: DirCacheEntry.cs プロジェクト: shoff/ngit
        /// <summary>Copy the ObjectId and other meta fields from an existing entry.</summary>
        /// <remarks>
        /// Copy the ObjectId and other meta fields from an existing entry.
        /// <p>
        /// This method copies everything except the path from one entry to another,
        /// supporting renaming.
        /// </remarks>
        /// <param name="src">the entry to copy ObjectId and meta fields from.</param>
        public virtual void CopyMetaData(NGit.Dircache.DirCacheEntry src)
        {
            int pLen = NB.DecodeUInt16(info, infoOffset + P_FLAGS) & NAME_MASK;

            System.Array.Copy(src.info, src.infoOffset, info, infoOffset, INFO_LEN);
            NB.EncodeInt16(info, infoOffset + P_FLAGS, pLen | NB.DecodeUInt16(info, infoOffset
                                                                              + P_FLAGS) & ~NAME_MASK);
        }
コード例 #2
0
ファイル: DirCacheEntry.cs プロジェクト: TetradogOther/NGit
 private int GetExtendedFlags()
 {
     if (IsExtended)
     {
         return(NB.DecodeUInt16(info, infoOffset + P_FLAGS2) << 16);
     }
     else
     {
         return(0);
     }
 }
コード例 #3
0
ファイル: DirCacheEntry.cs プロジェクト: TetradogOther/NGit
        /// <summary>Copy the ObjectId and other meta fields from an existing entry.</summary>
        /// <remarks>
        /// Copy the ObjectId and other meta fields from an existing entry.
        /// <p>
        /// This method copies everything except the path and possibly stage from one
        /// entry to another, supporting renaming.
        /// </remarks>
        /// <param name="src">the entry to copy ObjectId and meta fields from.</param>
        /// <param name="keepStage">if true, the stage attribute will not be copied</param>
        internal virtual void CopyMetaData(NGit.Dircache.DirCacheEntry src, bool keepStage
                                           )
        {
            int origflags = NB.DecodeUInt16(info, infoOffset + P_FLAGS);
            int newflags  = NB.DecodeUInt16(src.info, src.infoOffset + P_FLAGS);

            System.Array.Copy(src.info, src.infoOffset, info, infoOffset, INFO_LEN);
            int pLen = origflags & NAME_MASK;
            int SHIFTED_STAGE_MASK = unchecked ((int)(0x3)) << 12;
            int pStageShifted;

            if (keepStage)
            {
                pStageShifted = origflags & SHIFTED_STAGE_MASK;
            }
            else
            {
                pStageShifted = newflags & SHIFTED_STAGE_MASK;
            }
            NB.EncodeInt16(info, infoOffset + P_FLAGS, pStageShifted | pLen | (newflags & ~NAME_MASK
                                                                               & ~SHIFTED_STAGE_MASK));
        }
コード例 #4
0
ファイル: DirCacheEntry.cs プロジェクト: TetradogOther/NGit
        /// <exception cref="System.IO.IOException"></exception>
        internal DirCacheEntry(byte[] sharedInfo, MutableInteger infoAt, InputStream @in,
                               MessageDigest md, int smudge_s, int smudge_ns)
        {
            // private static final int P_CTIME_NSEC = 4;
            // private static final int P_MTIME_NSEC = 12;
            // private static final int P_DEV = 16;
            // private static final int P_INO = 20;
            // private static final int P_UID = 28;
            // private static final int P_GID = 32;
            info       = sharedInfo;
            infoOffset = infoAt.value;
            IOUtil.ReadFully(@in, info, infoOffset, INFO_LEN);
            int len;

            if (IsExtended)
            {
                len = INFO_LEN_EXTENDED;
                IOUtil.ReadFully(@in, info, infoOffset + INFO_LEN, INFO_LEN_EXTENDED - INFO_LEN);
                if ((GetExtendedFlags() & ~EXTENDED_FLAGS) != 0)
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().DIRCUnrecognizedExtendedFlags
                                                               , GetExtendedFlags().ToString()));
                }
            }
            else
            {
                len = INFO_LEN;
            }
            infoAt.value += len;
            md.Update(info, infoOffset, len);
            int pathLen = NB.DecodeUInt16(info, infoOffset + P_FLAGS) & NAME_MASK;
            int skipped = 0;

            if (pathLen < NAME_MASK)
            {
                path = new byte[pathLen];
                IOUtil.ReadFully(@in, path, 0, pathLen);
                md.Update(path, 0, pathLen);
            }
            else
            {
                ByteArrayOutputStream tmp = new ByteArrayOutputStream();
                {
                    byte[] buf = new byte[NAME_MASK];
                    IOUtil.ReadFully(@in, buf, 0, NAME_MASK);
                    tmp.Write(buf);
                }
                for (; ;)
                {
                    int c = @in.Read();
                    if (c < 0)
                    {
                        throw new EOFException(JGitText.Get().shortReadOfBlock);
                    }
                    if (c == 0)
                    {
                        break;
                    }
                    tmp.Write(c);
                }
                path    = tmp.ToByteArray();
                pathLen = path.Length;
                skipped = 1;
                // we already skipped 1 '\0' above to break the loop.
                md.Update(path, 0, pathLen);
                md.Update(unchecked ((byte)0));
            }
            // Index records are padded out to the next 8 byte alignment
            // for historical reasons related to how C Git read the files.
            //
            int actLen = len + pathLen;
            int expLen = (actLen + 8) & ~7;
            int padLen = expLen - actLen - skipped;

            if (padLen > 0)
            {
                IOUtil.SkipFully(@in, padLen);
                md.Update(nullpad, 0, padLen);
            }
            if (MightBeRacilyClean(smudge_s, smudge_ns))
            {
                SmudgeRacilyClean();
            }
        }