Class DirCacheEntry
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 TypeFieldDescriptionprivate static final int
private static final int
private static final int
private byte
Flags which are never stored to disk.private final byte[]
(Possibly shared) header information storage.private static final int
private static final int
private final int
First location withininfo
where our header starts.private static final int
private static final int
Mask applied to data inP_FLAGS
to get the name length.private static final byte[]
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
(package private) final byte[]
Our encoded path name, from the root of the repository.private static final int
static 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").private static final int
In-core flag signaling that the entry should be considered as modified. -
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
(byte[] sharedInfo, MutableInteger infoAt, InputStream in, MessageDigest md, Instant smudge, DirCache.DirCacheVersion version, DirCacheEntry previous) 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 TypeMethodDescriptionprivate static void
checkPath
(byte[] path) void
Copy the ObjectId and other meta fields from an existing entry.(package private) void
copyMetaData
(DirCacheEntry src, boolean keepStage) Copy the ObjectId and other meta fields from an existing entry.private long
decodeTS
(int pIdx) private Instant
decodeTSInstant
(int pIdx) private void
encodeTS
(int pIdx, long when) private void
long
Get the cached creation time of this file, in milliseconds.private int
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.(package private) static int
getMaximumInfoLength
(boolean extended) 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.(package private) final byte[]
idBuffer()
(package private) final int
idOffset()
boolean
Is this entry always thought to be unmodified?(package private) boolean
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?private int
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.(package private) void
setFileMode
(int mode) 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()
(package private) static String
toString
(byte[] path) (package private) void
write
(OutputStream os, DirCache.DirCacheVersion version, DirCacheEntry previous)
-
Field Details
-
nullpad
private static final byte[] nullpad -
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:
-
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_MASKMask applied to data inP_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_NEEDEDIn-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 infoOffsetFirst location withininfo
where our header starts. -
path
final byte[] pathOur encoded path name, from the root of the repository. -
inCoreFlags
private byte inCoreFlagsFlags 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
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
-
readNulTerminatedString
- Throws:
IOException
-
write
void write(OutputStream os, DirCache.DirCacheVersion version, DirCacheEntry previous) throws IOException - Throws:
IOException
-
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
-
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 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.
-
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.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.
-
copyMetaData
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
-
encodeTS
private void encodeTS(int pIdx, long when) -
encodeTS
-
getExtendedFlags
private int getExtendedFlags() -
checkPath
private static void checkPath(byte[] path) -
toString
-
getMaximumInfoLength
static int getMaximumInfoLength(boolean extended)
-
getLastModifiedInstant()
instead