Class DirCacheEntry
- java.lang.Object
-
- org.eclipse.jgit.dircache.DirCacheEntry
-
public class DirCacheEntry extends java.lang.Object
A single file (or stage of a file) in aDirCache
.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
Fields Modifier and Type Field Description private static int
ASSUME_VALID
private static int
EXTENDED
private static int
EXTENDED_FLAGS
private byte
inCoreFlags
Flags which are never stored to disk.private byte[]
info
(Possibly shared) header information storage.private static int
INFO_LEN
private static int
INFO_LEN_EXTENDED
private int
infoOffset
First location withininfo
where our header starts.private static int
INTENT_TO_ADD
private static int
NAME_MASK
Mask applied to data inP_FLAGS
to get the name length.private static byte[]
nullpad
private static int
P_CTIME
private static int
P_FLAGS
private static int
P_FLAGS2
private static int
P_MODE
private static int
P_MTIME
private static int
P_OBJECTID
private static int
P_SIZE
(package private) byte[]
path
Our encoded path name, from the root of the repository.private static int
SKIP_WORKTREE
static int
STAGE_0
The standard (fully merged) stage for an entry.static int
STAGE_1
The base tree revision for an entry.static int
STAGE_2
The first tree revision (usually called "ours").static int
STAGE_3
The second tree revision (usually called "theirs").private static int
UPDATE_NEEDED
In-core flag signaling that the entry should be considered as modified.
-
Constructor Summary
Constructors Constructor Description DirCacheEntry(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, java.io.InputStream in, java.security.MessageDigest md, java.time.Instant smudge)
DirCacheEntry(java.lang.String newPath)
Create an empty entry at stage 0.DirCacheEntry(java.lang.String newPath, int stage)
Create an empty entry at the specified stage.DirCacheEntry(DirCacheEntry src)
Duplicate DirCacheEntry with same path and copied info.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static void
checkPath(byte[] path)
void
copyMetaData(DirCacheEntry src)
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 java.time.Instant
decodeTSInstant(int pIdx)
private void
encodeTS(int pIdx, long when)
private void
encodeTS(int pIdx, java.time.Instant when)
long
getCreationTime()
Get the cached creation time of this file, in milliseconds.private int
getExtendedFlags()
FileMode
getFileMode()
Obtain theFileMode
for this entry.long
getLastModified()
Deprecated.usegetLastModifiedInstant()
insteadjava.time.Instant
getLastModifiedInstant()
Get the cached last modification date of this file.int
getLength()
Get the cached size (mod 4 GB) (in bytes) of this file.(package private) static int
getMaximumInfoLength(boolean extended)
ObjectId
getObjectId()
Obtain the ObjectId for the entry.java.lang.String
getPathString()
Get the entry's complete path.int
getRawMode()
Obtain the rawFileMode
bits for this entry.byte[]
getRawPath()
Get a copy of the entry's raw path bytes.int
getStage()
Get the stage of this entry.(package private) byte[]
idBuffer()
(package private) int
idOffset()
boolean
isAssumeValid()
Is this entry always thought to be unmodified?(package private) boolean
isExtended()
boolean
isIntentToAdd()
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
isSkipWorkTree()
Returns whether this entry should be skipped from the working tree.boolean
isSmudged()
Check whether this entry has been smudged or notboolean
isUpdateNeeded()
Whether this entry should be checked for changesboolean
mightBeRacilyClean(int smudge_s, int smudge_ns)
Deprecated.usemightBeRacilyClean(Instant)
insteadboolean
mightBeRacilyClean(java.time.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.(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(java.time.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
setObjectId(AnyObjectId id)
Set the ObjectId for the entry.void
setObjectIdFromRaw(byte[] bs, int p)
Set the ObjectId for the entry from the raw binary representation.void
setUpdateNeeded(boolean updateNeeded)
Set whether this entry must be checked for changesvoid
smudgeRacilyClean()
Force this entry to no longer match its working tree file.java.lang.String
toString()
(package private) static java.lang.String
toString(byte[] path)
(package private) void
write(java.io.OutputStream os)
-
-
-
Field Detail
-
nullpad
private static final byte[] nullpad
-
STAGE_0
public static final int STAGE_0
The standard (fully merged) stage for an entry.- See Also:
- Constant Field Values
-
STAGE_1
public static final int STAGE_1
The base tree revision for an entry.- See Also:
- Constant Field Values
-
STAGE_2
public static final int STAGE_2
The first tree revision (usually called "ours").- See Also:
- Constant Field Values
-
STAGE_3
public static final int STAGE_3
The second tree revision (usually called "theirs").- See Also:
- Constant Field Values
-
P_CTIME
private static final int P_CTIME
- See Also:
- Constant Field Values
-
P_MTIME
private static final int P_MTIME
- See Also:
- Constant Field Values
-
P_MODE
private static final int P_MODE
- See Also:
- Constant Field Values
-
P_SIZE
private static final int P_SIZE
- See Also:
- Constant Field Values
-
P_OBJECTID
private static final int P_OBJECTID
- See Also:
- Constant Field Values
-
P_FLAGS
private static final int P_FLAGS
- See Also:
- Constant Field Values
-
P_FLAGS2
private static final int P_FLAGS2
- See Also:
- Constant Field Values
-
NAME_MASK
private static final int NAME_MASK
Mask applied to data inP_FLAGS
to get the name length.- See Also:
- Constant Field Values
-
INTENT_TO_ADD
private static final int INTENT_TO_ADD
- See Also:
- Constant Field Values
-
SKIP_WORKTREE
private static final int SKIP_WORKTREE
- See Also:
- Constant Field Values
-
EXTENDED_FLAGS
private static final int EXTENDED_FLAGS
- See Also:
- Constant Field Values
-
INFO_LEN
private static final int INFO_LEN
- See Also:
- Constant Field Values
-
INFO_LEN_EXTENDED
private static final int INFO_LEN_EXTENDED
- See Also:
- Constant Field Values
-
EXTENDED
private static final int EXTENDED
- See Also:
- Constant Field Values
-
ASSUME_VALID
private static final int ASSUME_VALID
- See Also:
- Constant Field Values
-
UPDATE_NEEDED
private static final int UPDATE_NEEDED
In-core flag signaling that the entry should be considered as modified.- See Also:
- Constant Field Values
-
info
private final byte[] info
(Possibly shared) header information storage.
-
infoOffset
private final int infoOffset
First location withininfo
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 Detail
-
DirCacheEntry
DirCacheEntry(byte[] sharedInfo, MutableInteger infoAt, java.io.InputStream in, java.security.MessageDigest md, java.time.Instant smudge) throws java.io.IOException
- Throws:
java.io.IOException
-
DirCacheEntry
public DirCacheEntry(java.lang.String newPath)
Create an empty entry at stage 0.- Parameters:
newPath
- name of the cache entry.- Throws:
java.lang.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(java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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(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 Detail
-
write
void write(java.io.OutputStream os) throws java.io.IOException
- Throws:
java.io.IOException
-
mightBeRacilyClean
@Deprecated public final boolean mightBeRacilyClean(int smudge_s, int smudge_ns)
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
public final boolean mightBeRacilyClean(java.time.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 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.
-
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:
FileMode.fromBits(int)
-
getFileMode
public FileMode getFileMode()
Obtain theFileMode
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:
java.lang.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 public long 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
public java.time.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.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
public void setLastModified(java.time.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 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
public java.lang.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 java.lang.String toString()
Use for debugging only !
- Overrides:
toString
in classjava.lang.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 java.time.Instant decodeTSInstant(int pIdx)
-
encodeTS
private void encodeTS(int pIdx, long when)
-
encodeTS
private void encodeTS(int pIdx, java.time.Instant when)
-
getExtendedFlags
private int getExtendedFlags()
-
checkPath
private static void checkPath(byte[] path)
-
toString
static java.lang.String toString(byte[] path)
-
getMaximumInfoLength
static int getMaximumInfoLength(boolean extended)
-
-