/// <summary>Create an empty entry at the specified stage.</summary> /// <remarks>Create an empty entry at the specified stage.</remarks> /// <param name="newPath">name of the cache entry, in the standard encoding.</param> /// <param name="stage">the stage index of the new entry.</param> /// <exception cref="System.ArgumentException"> /// If the path starts or ends with "/", or contains "//" either /// "\0". These sequences are not permitted in a git tree object /// or DirCache file. Or if /// <code>stage</code> /// is outside of the /// range 0..3, inclusive. /// </exception> public DirCacheEntry(byte[] newPath, int stage) { if (!IsValidPath(newPath)) { throw new InvalidPathException(ToString(newPath)); } if (stage < 0 || 3 < stage) { throw new ArgumentException(MessageFormat.Format(JGitText.Get().invalidStageForPath , stage, ToString(newPath))); } info = new byte[INFO_LEN]; infoOffset = 0; path = newPath; int flags = ((stage & unchecked ((int)(0x3))) << 12); if (path.Length < NAME_MASK) { flags |= path.Length; } else { flags |= NAME_MASK; } NB.EncodeInt16(info, infoOffset + P_FLAGS, flags); }
/// <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); }
/// <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)); }