org.eclipse.jgit.dircache
Class DirCacheEntry

java.lang.Object
  extended by org.eclipse.jgit.dircache.DirCacheEntry

public class DirCacheEntry
extends java.lang.Object

A single file (or stage of a file) in a 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
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").
 
Constructor Summary
DirCacheEntry(byte[] newPath)
          Create an empty entry at stage 0.
DirCacheEntry(byte[] newPath, int stage)
          Create an empty entry at the specified stage.
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.
 
Method Summary
 void copyMetaData(DirCacheEntry src)
          Copy the ObjectId and other meta fields from an existing entry.
 FileMode getFileMode()
          Obtain the FileMode for this entry.
 long getLastModified()
          Get the cached last modification date of this file, in milliseconds.
 int getLength()
          Get the cached size (in bytes) of this file.
 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.
 int getStage()
          Get the stage of this entry.
 boolean isAssumeValid()
          Is this entry always thought to be unmodified?
 void setAssumeValid(boolean assume)
          Set the assume valid flag for this entry,
 void setFileMode(FileMode mode)
          Set the file mode for this entry.
 void setLastModified(long when)
          Set the cached last modification date of this file, using milliseconds.
 void setLength(int 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
Constructor Detail

DirCacheEntry

public DirCacheEntry(java.lang.String newPath)
Create an empty entry at stage 0.

Parameters:
newPath - name of the cache entry.

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.

DirCacheEntry

public DirCacheEntry(byte[] newPath)
Create an empty entry at stage 0.

Parameters:
newPath - name of the cache entry, in the standard encoding.

DirCacheEntry

public DirCacheEntry(byte[] newPath,
                     int stage)
Create an empty entry at the specified stage.

Parameters:
newPath - name of the cache entry, in the standard encoding.
stage - the stage index of the new entry.
Method Detail

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.

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.

getRawMode

public int getRawMode()
Obtain the raw FileMode bits for this entry.

Returns:
mode bits for the entry.
See Also:
FileMode.fromBits(int)

getFileMode

public FileMode getFileMode()
Obtain the FileMode 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.

getLastModified

public long getLastModified()
Get 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).

setLastModified

public void setLastModified(long when)
Set the cached last modification date of this file, using milliseconds.

Parameters:
when - new cached modification date of the file, in milliseconds.

getLength

public int getLength()
Get the cached size (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.

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.

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 be ObjectId.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.

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.