public class DirCacheEntry
extends java.lang.Object
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.
Modifier and Type | Field and 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 within
info where our header starts. |
private static int |
INTENT_TO_ADD |
private static int |
NAME_MASK
Mask applied to data in
P_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 and 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(DirCacheEntry src)
Duplicate DirCacheEntry with same path and copied info.
|
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.
|
Modifier and Type | Method and 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,
java.time.Instant when) |
private void |
encodeTS(int pIdx,
long when) |
long |
getCreationTime()
Get the cached creation time of this file, in milliseconds.
|
private int |
getExtendedFlags() |
FileMode |
getFileMode()
Obtain the
FileMode for this entry. |
long |
getLastModified()
Deprecated.
use
getLastModifiedInstant() instead |
java.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 raw
FileMode 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 not
|
boolean |
isUpdateNeeded()
Whether this entry should be checked for changes
|
boolean |
mightBeRacilyClean(java.time.Instant smudge)
Is it possible for this entry to be accidentally assumed clean?
|
boolean |
mightBeRacilyClean(int smudge_s,
int smudge_ns)
Deprecated.
use
mightBeRacilyClean(Instant) instead |
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.
|
(package private) void |
setFileMode(int mode) |
void |
setLastModified(java.time.Instant when)
Set the cached last modification date of this file.
|
void |
setLastModified(long when)
Deprecated.
use
setLastModified(Instant) instead |
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 changes
|
void |
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) |
private static final byte[] nullpad
public static final int STAGE_0
public static final int STAGE_1
public static final int STAGE_2
public static final int STAGE_3
private static final int P_CTIME
private static final int P_MTIME
private static final int P_MODE
private static final int P_SIZE
private static final int P_OBJECTID
private static final int P_FLAGS
private static final int P_FLAGS2
private static final int NAME_MASK
P_FLAGS
to get the name length.private static final int INTENT_TO_ADD
private static final int SKIP_WORKTREE
private static final int EXTENDED_FLAGS
private static final int INFO_LEN
private static final int INFO_LEN_EXTENDED
private static final int EXTENDED
private static final int ASSUME_VALID
private static final int UPDATE_NEEDED
private final byte[] info
private final int infoOffset
info
where our header starts.final byte[] path
private byte inCoreFlags
DirCacheEntry(byte[] sharedInfo, MutableInteger infoAt, java.io.InputStream in, java.security.MessageDigest md, java.time.Instant smudge) throws java.io.IOException
java.io.IOException
public DirCacheEntry(java.lang.String newPath)
newPath
- name of the cache entry.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.public DirCacheEntry(java.lang.String newPath, int stage)
newPath
- name of the cache entry.stage
- the stage index of the new entry.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 if stage
is outside of the
range 0..3, inclusive.public DirCacheEntry(byte[] newPath)
newPath
- name of the cache entry, in the standard encoding.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.public DirCacheEntry(byte[] path, int stage)
path
- name of the cache entry, in the standard encoding.stage
- the stage index of the new entry.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 if stage
is outside of the
range 0..3, inclusive.public DirCacheEntry(DirCacheEntry src)
The same path buffer is reused (avoiding copying), however a new info buffer is created and its contents are copied.
src
- entry to clone.void write(java.io.OutputStream os) throws java.io.IOException
java.io.IOException
@Deprecated public final boolean mightBeRacilyClean(int smudge_s, int smudge_ns)
mightBeRacilyClean(Instant)
insteadThe "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.
smudge_s
- seconds component of the index's last modified time.smudge_ns
- nanoseconds component of the index's last modified time.public final boolean mightBeRacilyClean(java.time.Instant smudge)
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.
smudge
- index's last modified time.public final void smudgeRacilyClean()
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.
public final boolean isSmudged()
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.
true
if the entry is smudged, false
otherwisefinal byte[] idBuffer()
final int idOffset()
public boolean isAssumeValid()
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.
public void setAssumeValid(boolean assume)
assume
- true to ignore apparent modifications; false to look at last
modified to detect file modifications.public boolean isUpdateNeeded()
true
if this entry should be checked for changespublic void setUpdateNeeded(boolean updateNeeded)
updateNeeded
- whether this entry must be checked for changespublic int getStage()
Entries have one of 4 possible stages: 0-3.
public boolean isSkipWorkTree()
public boolean isIntentToAdd()
public boolean isMerged()
public int getRawMode()
FileMode
bits for this entry.FileMode.fromBits(int)
public FileMode getFileMode()
FileMode
for this entry.public void setFileMode(FileMode mode)
mode
- the new mode constant.java.lang.IllegalArgumentException
- If mode
is
FileMode.MISSING
,
FileMode.TREE
, or any other type
code not permitted in a tree object.void setFileMode(int mode)
public long getCreationTime()
public void setCreationTime(long when)
when
- new cached creation time of the file, in milliseconds.@Deprecated public long getLastModified()
getLastModifiedInstant()
insteadOne 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.
public java.time.Instant getLastModifiedInstant()
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.
@Deprecated public void setLastModified(long when)
setLastModified(Instant)
insteadwhen
- new cached modification date of the file, in milliseconds.public void setLastModified(java.time.Instant when)
when
- new cached modification date of the file.public int getLength()
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.
public void setLength(int sz)
sz
- new cached size of the file, as bytes. If the file is larger
than 2G, cast it to (int) before calling this method.public void setLength(long sz)
sz
- new cached size of the file, as bytes.public ObjectId getObjectId()
Using this method to compare ObjectId values between entries is inefficient as it causes memory allocation.
public void setObjectId(AnyObjectId id)
id
- new object identifier for the entry. May be
ObjectId.zeroId()
to remove the
current identifier.public void setObjectIdFromRaw(byte[] bs, int p)
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.public java.lang.String getPathString()
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.
public byte[] getRawPath()
public java.lang.String toString()
Use for debugging only !
toString
in class java.lang.Object
public void copyMetaData(DirCacheEntry src)
This method copies everything except the path from one entry to another, supporting renaming.
src
- the entry to copy ObjectId and meta fields from.void copyMetaData(DirCacheEntry src, boolean keepStage)
This method copies everything except the path and possibly stage from one entry to another, supporting renaming.
src
- the entry to copy ObjectId and meta fields from.keepStage
- if true, the stage attribute will not be copiedboolean isExtended()
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)
private int getExtendedFlags()
private static void checkPath(byte[] path)
static java.lang.String toString(byte[] path)
static int getMaximumInfoLength(boolean extended)