Top Description Fields Constructors Methods
org.eclipse.jgit.dircache

public Class DirCacheEntry

extends Object
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8

A single file (or stage of a file) in a org.eclipse.jgit.dircache.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

Modifier and TypeField and Description
private static final int
private static final int
private static final int
private byte
inCoreFlags

Flags which are never stored to disk.

private final byte[]
info

(Possibly shared) header information storage.

private static final int
private static final int
private final int
infoOffset

First location within info where our header starts.

private static final int
private static final int
NAME_MASK

Mask applied to data in P_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
pack-priv final byte[]
path

Our encoded path name, from the root of the repository.

private static final int
public static final int
STAGE_0

The standard (fully merged) stage for an entry.

public static final int
STAGE_1

The base tree revision for an entry.

public static final int
STAGE_2

The first tree revision (usually called "ours").

public static final int
STAGE_3

The second tree revision (usually called "theirs").

private static final int
UPDATE_NEEDED

In-core flag signaling that the entry should be considered as modified.

Constructor Summary

AccessConstructor and Description
pack-priv
DirCacheEntry(byte[] sharedInfo, MutableInteger infoAt, InputStream in, MessageDigest md, Instant smudge, DirCache.DirCacheVersion version, DirCacheEntry previous)

public
DirCacheEntry(String
name of the cache entry.
newPath
)

Create an empty entry at stage 0.

public
DirCacheEntry(String
name of the cache entry.
newPath
,
int
the stage index of the new entry.
stage
)

Create an empty entry at the specified stage.

public
DirCacheEntry(byte[]
name of the cache entry, in the standard encoding.
newPath
)

Create an empty entry at stage 0.

public
DirCacheEntry(byte[]
name of the cache entry, in the standard encoding.
path
,
int
the stage index of the new entry.
stage
)

Create an empty entry at the specified stage.

public
DirCacheEntry(DirCacheEntry
entry to clone.
src
)

Duplicate DirCacheEntry with same path and copied info.

Method Summary

Modifier and TypeMethod and Description
private static void
checkPath(byte[] path)

public void
copyMetaData(DirCacheEntry
the entry to copy ObjectId and meta fields from.
src
)

Copy the ObjectId and other meta fields from an existing entry.

pack-priv void
copyMetaData(DirCacheEntry
the entry to copy ObjectId and meta fields from.
src
,
boolean
if true, the stage attribute will not be copied
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
encodeTS(int pIdx, Instant when)

public long

Returns:

cached creation time of this file, in milliseconds since the Java epoch (midnight Jan 1, 1970 UTC).
getCreationTime
()

Get the cached creation time of this file, in milliseconds.

private int
public FileMode

Returns:

the file mode singleton for this entry.
getFileMode
()

Obtain the org.eclipse.jgit.lib.FileMode for this entry.

public Instant

Returns:

last modification time of this file.
getLastModifiedInstant
()

Get the cached last modification date of this file.

public int

Returns:

cached size of the working directory file, in bytes.
getLength
()

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

pack-priv static int
getMaximumInfoLength(boolean extended)

public ObjectId

Returns:

object identifier for the entry.
getObjectId
()

Obtain the ObjectId for the entry.

public String

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.
getPathString
()

Get the entry's complete path.

public int

Returns:

mode bits for the entry.
getRawMode
()

Obtain the raw org.eclipse.jgit.lib.FileMode bits for this entry.

public byte[]

Returns:

raw path bytes.
getRawPath
()

Get a copy of the entry's raw path bytes.

public int

Returns:

the stage of this entry.
getStage
()

Get the stage of this entry.

pack-priv final byte[]
pack-priv final int
public boolean

Returns:

true if we must assume the entry is unmodified.
isAssumeValid
()

Is this entry always thought to be unmodified?

pack-priv boolean

Returns:

true if the entry contains extended flags.
isExtended
()

Whether the entry contains extended flags

public boolean

Returns:

true if this entry is intent to add.
isIntentToAdd
()

Returns whether this entry is intent to be added to the Index.

public boolean

Returns:

true if this entry is merged
isMerged
()

Returns whether this entry is in the fully-merged stage (0).

public boolean

Returns:

true if this entry should be skipepd.
isSkipWorkTree
()

Returns whether this entry should be skipped from the working tree.

public final boolean

Returns:

true if the entry is smudged, false otherwise
isSmudged
()

Check whether this entry has been smudged or not

If a blob has length 0 we know its id, see org.eclipse.jgit.lib.Constants#EMPTY_BLOB_ID.

public boolean

Returns:

true if this entry should be checked for changes
isUpdateNeeded
()

Whether this entry should be checked for changes

public final boolean

Returns:

true if extra careful checks should be used.
mightBeRacilyClean
(Instant
index's last modified time.
smudge
)

Is it possible for this entry to be accidentally assumed clean?

private int
public void
setAssumeValid(boolean
true to ignore apparent modifications; false to look at last modified to detect file modifications.
assume
)

Set the assume valid flag for this entry,

public void
setCreationTime(long
new cached creation time of the file, in milliseconds.
when
)

Set the cached creation time of this file, using milliseconds.

public void
setFileMode(FileMode
the new mode constant.
mode
)

Set the file mode for this entry.

pack-priv void
setFileMode(int mode)

public void
setLastModified(Instant
new cached modification date of the file.
when
)

Set the cached last modification date of this file.

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

Set the cached size (in bytes) of this file.

public void
setLength(long
new cached size of the file, as bytes.
sz
)

Set the cached size (in bytes) of this file.

public void
setObjectId(AnyObjectId
new object identifier for the entry. May be org.eclipse.jgit.lib.ObjectId#zeroId() to remove the current identifier.
id
)

Set the ObjectId for the entry.

public void
setObjectIdFromRaw(byte[]
the raw byte buffer to read from. At least 20 bytes after p must be available within this byte array.
bs
,
int
position to read the first byte of data from.
p
)

Set the ObjectId for the entry from the raw binary representation.

public void
setStage(int
to set, in the range [0..3]
stage
)

Sets the stage of an entry.

public void
setUpdateNeeded(boolean
whether this entry must be checked for changes
updateNeeded
)

Set whether this entry must be checked for changes

public final void
smudgeRacilyClean()

Force this entry to no longer match its working tree file.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv static String
toString(byte[] path)

pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ASSUME_VALIDback to summary
private static final int ASSUME_VALID
EXTENDEDback to summary
private static final int EXTENDED
EXTENDED_FLAGSback to summary
private static final int EXTENDED_FLAGS
inCoreFlagsback to summary
private byte inCoreFlags

Flags which are never stored to disk.

infoback to summary
private final byte[] info

(Possibly shared) header information storage.

INFO_LENback to summary
private static final int INFO_LEN
INFO_LEN_EXTENDEDback to summary
private static final int INFO_LEN_EXTENDED
infoOffsetback to summary
private final int infoOffset

First location within info where our header starts.

INTENT_TO_ADDback to summary
private static final int INTENT_TO_ADD
NAME_MASKback to summary
private static final int NAME_MASK

Mask applied to data in P_FLAGS to get the name length.

nullpadback to summary
private static final byte[] nullpad
P_CTIMEback to summary
private static final int P_CTIME
P_FLAGSback to summary
private static final int P_FLAGS
P_FLAGS2back to summary
private static final int P_FLAGS2
P_MODEback to summary
private static final int P_MODE
P_MTIMEback to summary
private static final int P_MTIME
P_OBJECTIDback to summary
private static final int P_OBJECTID
P_SIZEback to summary
private static final int P_SIZE
pathback to summary
pack-priv final byte[] path

Our encoded path name, from the root of the repository.

SKIP_WORKTREEback to summary
private static final int SKIP_WORKTREE
STAGE_0back to summary
public static final int STAGE_0

The standard (fully merged) stage for an entry.

STAGE_1back to summary
public static final int STAGE_1

The base tree revision for an entry.

STAGE_2back to summary
public static final int STAGE_2

The first tree revision (usually called "ours").

STAGE_3back to summary
public static final int STAGE_3

The second tree revision (usually called "theirs").

UPDATE_NEEDEDback to summary
private static final int UPDATE_NEEDED

In-core flag signaling that the entry should be considered as modified.

Constructor Detail

DirCacheEntryback to summary
pack-priv DirCacheEntry(byte[] sharedInfo, MutableInteger infoAt, InputStream in, MessageDigest md, Instant smudge, DirCache.DirCacheVersion version, DirCacheEntry previous) throws IOException
DirCacheEntryback to summary
public DirCacheEntry(String newPath)

Create an empty entry at stage 0.

Parameters
newPath:String

name of the cache entry.

Exceptions
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.
DirCacheEntryback to summary
public DirCacheEntry(String newPath, int stage)

Create an empty entry at the specified stage.

Parameters
newPath:String

name of the cache entry.

stage:int

the stage index of the new entry.

Exceptions
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.
DirCacheEntryback to summary
public DirCacheEntry(byte[] newPath)

Create an empty entry at stage 0.

Parameters
newPath:byte[]

name of the cache entry, in the standard encoding.

Exceptions
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.
DirCacheEntryback to summary
public DirCacheEntry(byte[] path, int stage)

Create an empty entry at the specified stage.

Parameters
path:byte[]

name of the cache entry, in the standard encoding.

stage:int

the stage index of the new entry.

Annotations
@SuppressWarnings:boxing
Exceptions
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.
DirCacheEntryback to summary
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:DirCacheEntry

entry to clone.

Since
4.2

Method Detail

checkPathback to summary
private static void checkPath(byte[] path)
copyMetaDataback to summary
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:DirCacheEntry

the entry to copy ObjectId and meta fields from.

copyMetaDataback to summary
pack-priv 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:DirCacheEntry

the entry to copy ObjectId and meta fields from.

keepStage:boolean

if true, the stage attribute will not be copied

decodeTSback to summary
private long decodeTS(int pIdx)
decodeTSInstantback to summary
private Instant decodeTSInstant(int pIdx)
encodeTSback to summary
private void encodeTS(int pIdx, long when)
encodeTSback to summary
private void encodeTS(int pIdx, Instant when)
getCreationTimeback to summary
public long getCreationTime()

Get the cached creation time of this file, in milliseconds.

Returns:long

cached creation time of this file, in milliseconds since the Java epoch (midnight Jan 1, 1970 UTC).

getExtendedFlagsback to summary
private int getExtendedFlags()
getFileModeback to summary
public FileMode getFileMode()

Obtain the org.eclipse.jgit.lib.FileMode for this entry.

Returns:FileMode

the file mode singleton for this entry.

getLastModifiedInstantback to summary
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:Instant

last modification time of this file.

Since
5.1.9
getLengthback to summary
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:int

cached size of the working directory file, in bytes.

getMaximumInfoLengthback to summary
pack-priv static int getMaximumInfoLength(boolean extended)
getObjectIdback to summary
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:ObjectId

object identifier for the entry.

getPathStringback to summary
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:String

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.

getRawModeback to summary
public int getRawMode()

Obtain the raw org.eclipse.jgit.lib.FileMode bits for this entry.

Returns:int

mode bits for the entry.

See Also
FileMode#fromBits(int)
getRawPathback to summary
public byte[] getRawPath()

Get a copy of the entry's raw path bytes.

Returns:byte[]

raw path bytes.

Since
3.4
getStageback to summary
public int getStage()

Get the stage of this entry.

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

Returns:int

the stage of this entry.

idBufferback to summary
pack-priv final byte[] idBuffer()
idOffsetback to summary
pack-priv final int idOffset()
isAssumeValidback to summary
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:boolean

true if we must assume the entry is unmodified.

isExtendedback to summary
pack-priv boolean isExtended()

Whether the entry contains extended flags

Returns:boolean

true if the entry contains extended flags.

isIntentToAddback to summary
public boolean isIntentToAdd()

Returns whether this entry is intent to be added to the Index.

Returns:boolean

true if this entry is intent to add.

isMergedback to summary
public boolean isMerged()

Returns whether this entry is in the fully-merged stage (0).

Returns:boolean

true if this entry is merged

Since
2.2
isSkipWorkTreeback to summary
public boolean isSkipWorkTree()

Returns whether this entry should be skipped from the working tree.

Returns:boolean

true if this entry should be skipepd.

isSmudgedback to summary
public final boolean isSmudged()

Check whether this entry has been smudged or not

If a blob has length 0 we know its id, see org.eclipse.jgit.lib.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:boolean

true if the entry is smudged, false otherwise

isUpdateNeededback to summary
public boolean isUpdateNeeded()

Whether this entry should be checked for changes

Returns:boolean

true if this entry should be checked for changes

mightBeRacilyCleanback to summary
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:Instant

index's last modified time.

Returns:boolean

true if extra careful checks should be used.

Annotations
@SuppressWarnings:JavaInstantGetSecondsGetNano
Since
5.1.9
readNulTerminatedStringback to summary
private int readNulTerminatedString(InputStream in, OutputStream out) throws IOException
setAssumeValidback to summary
public void setAssumeValid(boolean assume)

Set the assume valid flag for this entry,

Parameters
assume:boolean

true to ignore apparent modifications; false to look at last modified to detect file modifications.

setCreationTimeback to summary
public void setCreationTime(long when)

Set the cached creation time of this file, using milliseconds.

Parameters
when:long

new cached creation time of the file, in milliseconds.

setFileModeback to summary
public void setFileMode(FileMode mode)

Set the file mode for this entry.

Parameters
mode:FileMode

the new mode constant.

Exceptions
IllegalArgumentException:
If mode is org.eclipse.jgit.lib.FileMode#MISSING, org.eclipse.jgit.lib.FileMode#TREE, or any other type code not permitted in a tree object.
setFileModeback to summary
pack-priv void setFileMode(int mode)
setLastModifiedback to summary
public void setLastModified(Instant when)

Set the cached last modification date of this file.

Parameters
when:Instant

new cached modification date of the file.

Since
5.1.9
setLengthback to summary
public void setLength(int sz)

Set the cached size (in bytes) of this file.

Parameters
sz:int

new cached size of the file, as bytes. If the file is larger than 2G, cast it to (int) before calling this method.

setLengthback to summary
public void setLength(long sz)

Set the cached size (in bytes) of this file.

Parameters
sz:long

new cached size of the file, as bytes.

setObjectIdback to summary
public void setObjectId(AnyObjectId id)

Set the ObjectId for the entry.

Parameters
id:AnyObjectId

new object identifier for the entry. May be org.eclipse.jgit.lib.ObjectId#zeroId() to remove the current identifier.

setObjectIdFromRawback to summary
public void setObjectIdFromRaw(byte[] bs, int p)

Set the ObjectId for the entry from the raw binary representation.

Parameters
bs:byte[]

the raw byte buffer to read from. At least 20 bytes after p must be available within this byte array.

p:int

position to read the first byte of data from.

setStageback to summary
public void setStage(int stage)

Sets the stage of an entry.

Parameters
stage:int

to set, in the range [0..3]

Exceptions
IllegalArgumentException:
if the stage is outside the range [0..3]
Since
5.10
setUpdateNeededback to summary
public void setUpdateNeeded(boolean updateNeeded)

Set whether this entry must be checked for changes

Parameters
updateNeeded:boolean

whether this entry must be checked for changes

smudgeRacilyCleanback to summary
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.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Use for debugging only !

Returns:String

a string representation of the object

Annotations
@SuppressWarnings:nls
@Override
toStringback to summary
pack-priv static String toString(byte[] path)
writeback to summary
pack-priv void write(OutputStream os, DirCache.DirCacheVersion version, DirCacheEntry previous) throws IOException