Class DirCacheEntry

java.lang.Object
org.eclipse.jgit.dircache.DirCacheEntry

public class DirCacheEntry extends Object
A single file (or stage of a file) in a DirCache.

An entry represents exactly one stage of a file. If a file path is unmerged then multiple DirCacheEntry instances may appear for the same path name.

  • Field Details

    • nullpad

      private static final byte[] nullpad
    • STAGE_0

      public static final int STAGE_0
      The standard (fully merged) stage for an entry.
      See Also:
    • STAGE_1

      public static final int STAGE_1
      The base tree revision for an entry.
      See Also:
    • STAGE_2

      public static final int STAGE_2
      The first tree revision (usually called "ours").
      See Also:
    • STAGE_3

      public static final int STAGE_3
      The second tree revision (usually called "theirs").
      See Also:
    • P_CTIME

      private static final int P_CTIME
      See Also:
    • P_MTIME

      private static final int P_MTIME
      See Also:
    • P_MODE

      private static final int P_MODE
      See Also:
    • P_SIZE

      private static final int P_SIZE
      See Also:
    • P_OBJECTID

      private static final int P_OBJECTID
      See Also:
    • P_FLAGS

      private static final int P_FLAGS
      See Also:
    • P_FLAGS2

      private static final int P_FLAGS2
      See Also:
    • NAME_MASK

      private static final int NAME_MASK
      Mask applied to data in P_FLAGS to get the name length.
      See Also:
    • INTENT_TO_ADD

      private static final int INTENT_TO_ADD
      See Also:
    • SKIP_WORKTREE

      private static final int SKIP_WORKTREE
      See Also:
    • EXTENDED_FLAGS

      private static final int EXTENDED_FLAGS
      See Also:
    • INFO_LEN

      private static final int INFO_LEN
      See Also:
    • INFO_LEN_EXTENDED

      private static final int INFO_LEN_EXTENDED
      See Also:
    • EXTENDED

      private static final int EXTENDED
      See Also:
    • ASSUME_VALID

      private static final int ASSUME_VALID
      See Also:
    • UPDATE_NEEDED

      private static final int UPDATE_NEEDED
      In-core flag signaling that the entry should be considered as modified.
      See Also:
    • info

      private final byte[] info
      (Possibly shared) header information storage.
    • infoOffset

      private final int infoOffset
      First location within info where our header starts.
    • path

      final byte[] path
      Our encoded path name, from the root of the repository.
    • inCoreFlags

      private byte inCoreFlags
      Flags which are never stored to disk.
  • Constructor Details

    • DirCacheEntry

      DirCacheEntry(byte[] sharedInfo, MutableInteger infoAt, InputStream in, MessageDigest md, Instant smudge, DirCache.DirCacheVersion version, DirCacheEntry previous) throws IOException
      Throws:
      IOException
    • DirCacheEntry

      public DirCacheEntry(String newPath)
      Create an empty entry at stage 0.
      Parameters:
      newPath - name of the cache entry.
      Throws:
      IllegalArgumentException - If the path starts or ends with "/", or contains "//" either "\0". These sequences are not permitted in a git tree object or DirCache file.
    • DirCacheEntry

      public DirCacheEntry(String newPath, int stage)
      Create an empty entry at the specified stage.
      Parameters:
      newPath - name of the cache entry.
      stage - the stage index of the new entry.
      Throws:
      IllegalArgumentException - 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 stage is outside of the range 0..3, inclusive.
    • DirCacheEntry

      public DirCacheEntry(byte[] newPath)
      Create an empty entry at stage 0.
      Parameters:
      newPath - name of the cache entry, in the standard encoding.
      Throws:
      IllegalArgumentException - If the path starts or ends with "/", or contains "//" either "\0". These sequences are not permitted in a git tree object or DirCache file.
    • DirCacheEntry

      public DirCacheEntry(byte[] path, int stage)
      Create an empty entry at the specified stage.
      Parameters:
      path - name of the cache entry, in the standard encoding.
      stage - the stage index of the new entry.
      Throws:
      IllegalArgumentException - 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 stage is outside of the range 0..3, inclusive.
    • DirCacheEntry

      public DirCacheEntry(DirCacheEntry src)
      Duplicate DirCacheEntry with same path and copied info.

      The same path buffer is reused (avoiding copying), however a new info buffer is created and its contents are copied.

      Parameters:
      src - entry to clone.
      Since:
      4.2
  • Method Details

    • readNulTerminatedString

      private int readNulTerminatedString(InputStream in, OutputStream out) throws IOException
      Throws:
      IOException
    • write

      void write(OutputStream os, DirCache.DirCacheVersion version, DirCacheEntry previous) throws IOException
      Throws:
      IOException
    • mightBeRacilyClean

      @Deprecated public final boolean mightBeRacilyClean(int smudge_s, int smudge_ns)
      Deprecated.
      Is it possible for this entry to be accidentally assumed clean?

      The "racy git" problem happens when a work file can be updated faster than the filesystem records file modification timestamps. It is possible for an application to edit a work file, update the index, then edit it again before the filesystem will give the work file a new modification timestamp. This method tests to see if file was written out at the same time as the index.

      Parameters:
      smudge_s - seconds component of the index's last modified time.
      smudge_ns - nanoseconds component of the index's last modified time.
      Returns:
      true if extra careful checks should be used.
    • mightBeRacilyClean

      public final boolean mightBeRacilyClean(Instant smudge)
      Is it possible for this entry to be accidentally assumed clean?

      The "racy git" problem happens when a work file can be updated faster than the filesystem records file modification timestamps. It is possible for an application to edit a work file, update the index, then edit it again before the filesystem will give the work file a new modification timestamp. This method tests to see if file was written out at the same time as the index.

      Parameters:
      smudge - index's last modified time.
      Returns:
      true if extra careful checks should be used.
      Since:
      5.1.9
    • smudgeRacilyClean

      public final void smudgeRacilyClean()
      Force this entry to no longer match its working tree file.

      This avoids the "racy git" problem by making this index entry no longer match the file in the working directory. Later git will be forced to compare the file content to ensure the file matches the working tree.

    • isSmudged

      public final boolean isSmudged()
      Check whether this entry has been smudged or not

      If a blob has length 0 we know its id, see Constants.EMPTY_BLOB_ID. If an entry has length 0 and an ID different from the one for empty blob we know this entry was smudged.

      Returns:
      true if the entry is smudged, false otherwise
    • idBuffer

      final byte[] idBuffer()
    • idOffset

      final int idOffset()
    • isAssumeValid

      public boolean isAssumeValid()
      Is this entry always thought to be unmodified?

      Most entries in the index do not have this flag set. Users may however set them on if the file system stat() costs are too high on this working directory, such as on NFS or SMB volumes.

      Returns:
      true if we must assume the entry is unmodified.
    • setAssumeValid

      public void setAssumeValid(boolean assume)
      Set the assume valid flag for this entry,
      Parameters:
      assume - true to ignore apparent modifications; false to look at last modified to detect file modifications.
    • isUpdateNeeded

      public boolean isUpdateNeeded()
      Whether this entry should be checked for changes
      Returns:
      true if this entry should be checked for changes
    • setUpdateNeeded

      public void setUpdateNeeded(boolean updateNeeded)
      Set whether this entry must be checked for changes
      Parameters:
      updateNeeded - whether this entry must be checked for changes
    • getStage

      public int getStage()
      Get the stage of this entry.

      Entries have one of 4 possible stages: 0-3.

      Returns:
      the stage of this entry.
    • setStage

      public void setStage(int stage)
      Sets the stage of an entry.
      Parameters:
      stage - to set, in the range [0..3]
      Throws:
      IllegalArgumentException - if the stage is outside the range [0..3]
      Since:
      5.10
    • isSkipWorkTree

      public boolean isSkipWorkTree()
      Returns whether this entry should be skipped from the working tree.
      Returns:
      true if this entry should be skipepd.
    • isIntentToAdd

      public boolean isIntentToAdd()
      Returns whether this entry is intent to be added to the Index.
      Returns:
      true if this entry is intent to add.
    • isMerged

      public boolean isMerged()
      Returns whether this entry is in the fully-merged stage (0).
      Returns:
      true if this entry is merged
      Since:
      2.2
    • getRawMode

      public int getRawMode()
      Obtain the raw FileMode bits for this entry.
      Returns:
      mode bits for the entry.
      See Also:
    • getFileMode

      public FileMode getFileMode()
      Obtain the FileMode for this entry.
      Returns:
      the file mode singleton for this entry.
    • setFileMode

      public void setFileMode(FileMode mode)
      Set the file mode for this entry.
      Parameters:
      mode - the new mode constant.
      Throws:
      IllegalArgumentException - If mode is FileMode.MISSING, FileMode.TREE, or any other type code not permitted in a tree object.
    • setFileMode

      void setFileMode(int mode)
    • getCreationTime

      public long getCreationTime()
      Get the cached creation time of this file, in milliseconds.
      Returns:
      cached creation time of this file, in milliseconds since the Java epoch (midnight Jan 1, 1970 UTC).
    • setCreationTime

      public void setCreationTime(long when)
      Set the cached creation time of this file, using milliseconds.
      Parameters:
      when - new cached creation time of the file, in milliseconds.
    • getLastModified

      @Deprecated public long getLastModified()
      Deprecated.
      Get the cached last modification date of this file, in milliseconds.

      One of the indicators that the file has been modified by an application changing the working tree is if the last modification time for the file differs from the time stored in this entry.

      Returns:
      last modification time of this file, in milliseconds since the Java epoch (midnight Jan 1, 1970 UTC).
    • getLastModifiedInstant

      public Instant getLastModifiedInstant()
      Get the cached last modification date of this file.

      One of the indicators that the file has been modified by an application changing the working tree is if the last modification time for the file differs from the time stored in this entry.

      Returns:
      last modification time of this file.
      Since:
      5.1.9
    • setLastModified

      @Deprecated public void setLastModified(long when)
      Deprecated.
      Set the cached last modification date of this file, using milliseconds.
      Parameters:
      when - new cached modification date of the file, in milliseconds.
    • setLastModified

      public void setLastModified(Instant when)
      Set the cached last modification date of this file.
      Parameters:
      when - new cached modification date of the file.
      Since:
      5.1.9
    • getLength

      public int getLength()
      Get the cached size (mod 4 GB) (in bytes) of this file.

      One of the indicators that the file has been modified by an application changing the working tree is if the size of the file (in bytes) differs from the size stored in this entry.

      Note that this is the length of the file in the working directory, which may differ from the size of the decompressed blob if work tree filters are being used, such as LF<->CRLF conversion.

      Note also that for very large files, this is the size of the on-disk file truncated to 32 bits, i.e. modulo 4294967296. If that value is larger than 2GB, it will appear negative.

      Returns:
      cached size of the working directory file, in bytes.
    • setLength

      public void setLength(int sz)
      Set the cached size (in bytes) of this file.
      Parameters:
      sz - new cached size of the file, as bytes. If the file is larger than 2G, cast it to (int) before calling this method.
    • setLength

      public void setLength(long sz)
      Set the cached size (in bytes) of this file.
      Parameters:
      sz - new cached size of the file, as bytes.
    • getObjectId

      public ObjectId getObjectId()
      Obtain the ObjectId for the entry.

      Using this method to compare ObjectId values between entries is inefficient as it causes memory allocation.

      Returns:
      object identifier for the entry.
    • setObjectId

      public void setObjectId(AnyObjectId id)
      Set the ObjectId for the entry.
      Parameters:
      id - new object identifier for the entry. May be ObjectId.zeroId() to remove the current identifier.
    • setObjectIdFromRaw

      public void setObjectIdFromRaw(byte[] bs, int p)
      Set the ObjectId for the entry from the raw binary representation.
      Parameters:
      bs - the raw byte buffer to read from. At least 20 bytes after p must be available within this byte array.
      p - position to read the first byte of data from.
    • getPathString

      public String getPathString()
      Get the entry's complete path.

      This method is not very efficient and is primarily meant for debugging and final output generation. Applications should try to avoid calling it, and if invoked do so only once per interesting entry, where the name is absolutely required for correct function.

      Returns:
      complete path of the entry, from the root of the repository. If the entry is in a subtree there will be at least one '/' in the returned string.
    • getRawPath

      public byte[] getRawPath()
      Get a copy of the entry's raw path bytes.
      Returns:
      raw path bytes.
      Since:
      3.4
    • toString

      public String toString()

      Use for debugging only !

      Overrides:
      toString in class Object
    • copyMetaData

      public void copyMetaData(DirCacheEntry src)
      Copy the ObjectId and other meta fields from an existing entry.

      This method copies everything except the path from one entry to another, supporting renaming.

      Parameters:
      src - the entry to copy ObjectId and meta fields from.
    • copyMetaData

      void copyMetaData(DirCacheEntry src, boolean keepStage)
      Copy the ObjectId and other meta fields from an existing entry.

      This method copies everything except the path and possibly stage from one entry to another, supporting renaming.

      Parameters:
      src - the entry to copy ObjectId and meta fields from.
      keepStage - if true, the stage attribute will not be copied
    • isExtended

      boolean isExtended()
      Returns:
      true if the entry contains extended flags.
    • decodeTS

      private long decodeTS(int pIdx)
    • decodeTSInstant

      private Instant decodeTSInstant(int pIdx)
    • encodeTS

      private void encodeTS(int pIdx, long when)
    • encodeTS

      private void encodeTS(int pIdx, Instant when)
    • getExtendedFlags

      private int getExtendedFlags()
    • checkPath

      private static void checkPath(byte[] path)
    • toString

      static String toString(byte[] path)
    • getMaximumInfoLength

      static int getMaximumInfoLength(boolean extended)