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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The standard (fully merged) stage for an entry.static final int
The base tree revision for an entry.static final int
The first tree revision (usually called "ours").static final int
The second tree revision (usually called "theirs"). -
Constructor Summary
ConstructorsConstructorDescriptionDirCacheEntry
(byte[] newPath) Create an empty entry at stage 0.DirCacheEntry
(byte[] path, int stage) Create an empty entry at the specified stage.DirCacheEntry
(String newPath) Create an empty entry at stage 0.DirCacheEntry
(String newPath, int stage) Create an empty entry at the specified stage.Duplicate DirCacheEntry with same path and copied info. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Copy the ObjectId and other meta fields from an existing entry.long
Get the cached creation time of this file, in milliseconds.Obtain theFileMode
for this entry.long
Deprecated.Get the cached last modification date of this file.int
Get the cached size (mod 4 GB) (in bytes) of this file.Obtain the ObjectId for the entry.Get the entry's complete path.int
Obtain the rawFileMode
bits for this entry.byte[]
Get a copy of the entry's raw path bytes.int
getStage()
Get the stage of this entry.boolean
Is this entry always thought to be unmodified?boolean
Returns whether this entry is intent to be added to the Index.boolean
isMerged()
Returns whether this entry is in the fully-merged stage (0).boolean
Returns whether this entry should be skipped from the working tree.final boolean
Check whether this entry has been smudged or notboolean
Whether this entry should be checked for changesfinal boolean
mightBeRacilyClean
(int smudge_s, int smudge_ns) Deprecated.usemightBeRacilyClean(Instant)
insteadfinal boolean
mightBeRacilyClean
(Instant smudge) Is it possible for this entry to be accidentally assumed clean?void
setAssumeValid
(boolean assume) Set the assume valid flag for this entry,void
setCreationTime
(long when) Set the cached creation time of this file, using milliseconds.void
setFileMode
(FileMode mode) Set the file mode for this entry.void
setLastModified
(long when) Deprecated.usesetLastModified(Instant)
insteadvoid
setLastModified
(Instant when) Set the cached last modification date of this file.void
setLength
(int sz) Set the cached size (in bytes) of this file.void
setLength
(long sz) Set the cached size (in bytes) of this file.void
Set the ObjectId for the entry.void
setObjectIdFromRaw
(byte[] bs, int p) Set the ObjectId for the entry from the raw binary representation.void
setStage
(int stage) Sets the stage of an entry.void
setUpdateNeeded
(boolean updateNeeded) Set whether this entry must be checked for changesfinal void
Force this entry to no longer match its working tree file.toString()
-
Field Details
-
STAGE_0
public static final int STAGE_0The standard (fully merged) stage for an entry.- See Also:
-
STAGE_1
public static final int STAGE_1The base tree revision for an entry.- See Also:
-
STAGE_2
public static final int STAGE_2The first tree revision (usually called "ours").- See Also:
-
STAGE_3
public static final int STAGE_3The second tree revision (usually called "theirs").- See Also:
-
-
Constructor Details
-
DirCacheEntry
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
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 ifstage
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 ifstage
is outside of the range 0..3, inclusive.
-
DirCacheEntry
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
-
mightBeRacilyClean
Deprecated.usemightBeRacilyClean(Instant)
insteadIs 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
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 notIf 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
-
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 rawFileMode
bits for this entry.- Returns:
- mode bits for the entry.
- See Also:
-
getFileMode
Obtain theFileMode
for this entry.- Returns:
- the file mode singleton for this entry.
-
setFileMode
Set the file mode for this entry.- Parameters:
mode
- the new mode constant.- Throws:
IllegalArgumentException
- Ifmode
isFileMode.MISSING
,FileMode.TREE
, or any other type code not permitted in a tree object.
-
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.usegetLastModifiedInstant()
insteadGet 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
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.usesetLastModified(Instant)
insteadSet the cached last modification date of this file, using milliseconds.- Parameters:
when
- new cached modification date of the file, in milliseconds.
-
setLastModified
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
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
Set the ObjectId for the entry.- Parameters:
id
- new object identifier for the entry. May beObjectId.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
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
Use for debugging only !
-
copyMetaData
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.
-
getLastModifiedInstant()
instead