The index file keeps track of which objects are currently checked out in the working directory, and the last modified time of those working files. Changes in the working directory can be detected by comparing the modification times to the cached modification time within the index file.
Index files are also used during merges, where the merge happens within the index file first, and the working directory is updated as a post-merge step. Conflicts are stored in the index file to allow tool (and human) based resolutions to be easily performed.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| public static enum | DirCache.
DirCache versions |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final Comparator | |
| private int | entryCnt
Number of positions within |
| private static final int | |
| private IndexChangedListener | indexChangedListener
listener to be informed on commit |
| private final File | liveFile
Location of the current version of the index file. |
| private LockFile | myLock
Our active lock (if we hold it); null if we don't have it locked. |
| private static final byte[] | |
| private static final DirCacheEntry[] | |
| private byte[] | readIndexChecksum
index checksum when index was read from disk |
| private Repository | repository
Repository containing this index |
| private static final byte[] | |
| private boolean | skipHash
Whether to skip computing and checking the index checksum |
| private FileSnapshot | snapshot
Keep track of whether the index has changed or not |
| private DirCacheEntry[] | sortedEntries
Individual file index entries, sorted by path name. |
| private DirCacheTree | tree
Cache tree for this index; null if the cache tree is not available. |
| private DirCache. | version
If we read this index from disk, the original format. |
| private byte[] | writeIndexChecksum
index checksum when index was written to disk |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public DirCacheBuilder | |
| public void | |
| pack-priv static int | |
| pack-priv static int | |
| pack-priv static int | |
| public boolean | Returns: true if the commit was successful and the file contains the new data; false if the commit failed and the file remains with the old data.Commit this change and release the lock. |
| public DirCacheEditor | |
| public int | Returns: if >= 0 then the return value is the position of the entry in the index; pass togetEntry(int) to obtain the entry
information. If < 0 the entry does not exist in the index.the path to search for. path)Locate the position a path's entry is at in the index. |
| public int | Returns: if >= 0 then the return value is the position of the entry in the index; pass togetEntry(int) to obtain the entry
information. If < 0 the entry does not exist in the index.the byte array starting with the path to search for. p, int the length of the path in bytes pLen)Locate the position a path's entry is at in the index. |
| pack-priv int | |
| private static String | |
| public DirCacheTree | Returns: the cache tree; null if there is no current cache tree available andbuild was false.if true and the cache tree is not present in the index it will
be generated and returned to the caller. build)Obtain (or build) the current cache tree structure. |
| public DirCacheEntry[] | Returns: all entries recursively contained within the subtree.the subtree path to get all entries within. path)Recursively get all entries within a subtree. |
| public DirCacheEntry | |
| public DirCacheEntry | |
| public int | Returns: number of entries available.Total number of file entries stored in the index. |
| pack-priv DirCache. | |
| public boolean | Returns: true if this index contains unmerged paths. Means: at
least one entry is of a stage different from 0. false
will be returned if all entries are of stage 0.Tells whether this index contains unmerged paths. |
| private static boolean | |
| public boolean | Returns: true if the memory state differs from the index fileWhether the memory state differs from the index file |
| public static DirCache | Returns: a cache representing the contents of the specified index file (if it exists) or an empty cache if the file does not exist.location of the index file on disk. indexLocation, FS the file system abstraction which will be necessary to perform
certain file system operations. fs)Create a new in-core index representation, lock it, and read from disk. |
| public static DirCache | Returns: a cache representing the contents of the specified index file (if it exists) or an empty cache if the file does not exist.repository containing the index to lock and read repository, final IndexChangedListener listener to be informed when DirCache is committed indexChangedListener)Create a new in-core index representation, lock it, and read from disk. |
| public static DirCache | Returns: a cache representing the contents of the specified index file (if it exists) or an empty cache if the file does not exist.location of the index file on disk. indexLocation, final FS the file system abstraction which will be necessary to perform
certain file system operations. fs, IndexChangedListener listener to be informed when DirCache is committed indexChangedListener)Create a new in-core index representation, lock it, and read from disk. |
| public boolean | Returns: true if the lock is now held by the caller; false if it is held by someone else.Try to establish an update lock on the cache file. |
| public static DirCache | Returns: an empty cache which has no backing store file. The cache may not be read or written, but it may be queried and updated (in memory).Create a new empty index which is never stored on disk. |
| private MessageDigest | |
| public int | Returns: position of the next entry whose path is after the input.entry position of the path that should be skipped. position)Determine the next index position past all entries with the same name. |
| pack-priv int | |
| public static DirCache | Returns: a new cache which has no backing store file, but contains the contents oftreeId.reader to access the tree objects from a repository. reader, AnyObjectId tree to read. Must identify a tree, not a tree-ish. treeId)Create a new in memory index read from the contents of a tree. |
| public static DirCache | Returns: a cache representing the contents of the specified index file (if it exists) or an empty cache if the file does not exist.repository containing the index to read repository)Create a new in-core index representation and read an index from disk. |
| public static DirCache | Returns: a cache representing the contents of the specified index file (if it exists) or an empty cache if the file does not exist.location of the index file on disk. indexLocation, FS the file system abstraction which will be necessary to perform
certain file system operations. fs)Create a new in-core index representation and read an index from disk. |
| public void | |
| private void | |
| private void | |
| private void | |
| pack-priv void | |
| private void | |
| private void | |
| pack-priv void | |
| public void | |
| private void | |
| public void | |
| pack-priv void | |
| public ObjectId | Returns: identity for the root tree.the writer to use when serializing to the store. The caller is
responsible for flushing the inserter before trying to use the
returned tree identity. ow)Write all index trees to the object store, returning the root tree. |
| ENT_CMP | back to summary |
|---|---|
| pack-priv static final Comparator<DirCacheEntry> ENT_CMP | |
| entryCnt | back to summary |
|---|---|
| private int entryCnt Number of positions within | |
| EXT_TREE | back to summary |
|---|---|
| private static final int EXT_TREE | |
| indexChangedListener | back to summary |
|---|---|
| private IndexChangedListener indexChangedListener listener to be informed on commit | |
| liveFile | back to summary |
|---|---|
| private final File liveFile Location of the current version of the index file. | |
| myLock | back to summary |
|---|---|
| private LockFile myLock Our active lock (if we hold it); null if we don't have it locked. | |
| NO_CHECKSUM | back to summary |
|---|---|
| private static final byte[] NO_CHECKSUM | |
| NO_ENTRIES | back to summary |
|---|---|
| private static final DirCacheEntry[] NO_ENTRIES | |
| readIndexChecksum | back to summary |
|---|---|
| private byte[] readIndexChecksum index checksum when index was read from disk | |
| repository | back to summary |
|---|---|
| private Repository repository Repository containing this index | |
| SIG_DIRC | back to summary |
|---|---|
| private static final byte[] SIG_DIRC | |
| skipHash | back to summary |
|---|---|
| private boolean skipHash Whether to skip computing and checking the index checksum | |
| snapshot | back to summary |
|---|---|
| private FileSnapshot snapshot Keep track of whether the index has changed or not | |
| sortedEntries | back to summary |
|---|---|
| private DirCacheEntry[] sortedEntries Individual file index entries, sorted by path name. | |
| tree | back to summary |
|---|---|
| private DirCacheTree tree Cache tree for this index; null if the cache tree is not available. | |
| version | back to summary |
|---|---|
| private DirCache. If we read this index from disk, the original format. | |
| writeIndexChecksum | back to summary |
|---|---|
| private byte[] writeIndexChecksum index checksum when index was written to disk | |
| DirCache | back to summary |
|---|---|
| public DirCache(File indexLocation, FS fs) Create a new in-core index representation.
The new index will be empty. Callers may wish to read from the on disk
file first with | |
| builder | back to summary |
|---|---|
| public DirCacheBuilder builder() Create a new builder to update this cache.
Callers should add all entries to the builder, then use
| |
| clear | back to summary |
|---|---|
| public void clear() Empty this index, removing all entries. | |
| cmp | back to summary |
|---|---|
| pack-priv static int cmp(DirCacheEntry a, DirCacheEntry b) | |
| cmp | back to summary |
|---|---|
| pack-priv static int cmp(byte[] aPath, int aLen, DirCacheEntry b) | |
| cmp | back to summary |
|---|---|
| pack-priv static int cmp(final byte[] aPath, final int aLen, final byte[] bPath, final int bLen) | |
| commit | back to summary |
|---|---|
| public boolean commit() Commit this change and release the lock. If this method fails (returns false) the lock is still released.
| |
| editor | back to summary |
|---|---|
| public DirCacheEditor editor() Create a new editor to recreate this cache.
Callers should add commands to the editor, then use
| |
| findEntry | back to summary |
|---|---|
| public int findEntry(String path) Locate the position a path's entry is at in the index. For details refer to #findEntry(byte[], int).
| |
| findEntry | back to summary |
|---|---|
| public int findEntry(byte[] p, int pLen) Locate the position a path's entry is at in the index. If there is at least one entry in the index for this path the position of the lowest stage is returned. Subsequent stages can be identified by testing consecutive entries until the path differs. If no path matches the entry -(position+1) is returned, where position is the location it would have gone within the index.
| |
| findEntry | back to summary |
|---|---|
| pack-priv int findEntry(int low, byte[] p, int pLen) | |
| formatExtensionName | back to summary |
|---|---|
| private static String formatExtensionName(byte[] hdr) | |
| getCacheTree | back to summary |
|---|---|
| public DirCacheTree getCacheTree(boolean build) Obtain (or build) the current cache tree structure. This method can optionally recreate the cache tree, without flushing the tree objects themselves to disk.
| |
| getEntriesWithin | back to summary |
|---|---|
| public DirCacheEntry[] getEntriesWithin(String path) Recursively get all entries within a subtree.
| |
| getEntry | back to summary |
|---|---|
| public DirCacheEntry getEntry(int i) Get a specific entry.
| |
| getEntry | back to summary |
|---|---|
| public DirCacheEntry getEntry(String path) Get a specific entry.
| |
| getEntryCount | back to summary |
|---|---|
| public int getEntryCount() Total number of file entries stored in the index. This count includes unmerged stages for a file entry if the file is currently conflicted in a merge. This means the total number of entries in the index may be up to 3 times larger than the number of files in the working directory. Note that this value counts only files.
| |
| getVersion | back to summary |
|---|---|
| pack-priv DirCache. | |
| hasUnmergedPaths | back to summary |
|---|---|
| public boolean hasUnmergedPaths() Tells whether this index contains unmerged paths.
| |
| is_DIRC | back to summary |
|---|---|
| private static boolean is_DIRC(byte[] hdr) | |
| isOutdated | back to summary |
|---|---|
| public boolean isOutdated() throws IOException Whether the memory state differs from the index file
| |
| lock | back to summary |
|---|---|
| public static DirCache lock(File indexLocation, FS fs) throws CorruptObjectException, IOException Create a new in-core index representation, lock it, and read from disk. The new index will be locked and then read before it is returned to the caller. Read failures are reported as exceptions and therefore prevent the method from returning a partially populated index. On read failure, the lock is released.
| |
| lock | back to summary |
|---|---|
| public static DirCache lock(final Repository repository, final IndexChangedListener indexChangedListener) throws CorruptObjectException, IOException Create a new in-core index representation, lock it, and read from disk. The new index will be locked and then read before it is returned to the caller. Read failures are reported as exceptions and therefore prevent the method from returning a partially populated index. On read failure, the lock is released.
| |
| lock | back to summary |
|---|---|
| public static DirCache lock(final File indexLocation, final FS fs, IndexChangedListener indexChangedListener) throws CorruptObjectException, IOException Create a new in-core index representation, lock it, and read from disk. The new index will be locked and then read before it is returned to the caller. Read failures are reported as exceptions and therefore prevent the method from returning a partially populated index. On read failure, the lock is released.
| |
| lock | back to summary |
|---|---|
| public boolean lock() throws IOException Try to establish an update lock on the cache file.
| |
| newInCore | back to summary |
|---|---|
| public static DirCache newInCore() Create a new empty index which is never stored on disk.
| |
| newMessageDigest | back to summary |
|---|---|
| private MessageDigest newMessageDigest() | |
| nextEntry | back to summary |
|---|---|
| public int nextEntry(int position) Determine the next index position past all entries with the same name. As index entries are sorted by path name, then stage number, this method advances the supplied position to the first position in the index whose path name does not match the path name of the supplied position's entry.
| |
| nextEntry | back to summary |
|---|---|
| pack-priv int nextEntry(byte[] p, int pLen, int nextIdx) | |
| read | back to summary |
|---|---|
| public static DirCache read(ObjectReader reader, AnyObjectId treeId) throws IOException Create a new in memory index read from the contents of a tree.
| |
| read | back to summary |
|---|---|
| public static DirCache read(Repository repository) throws CorruptObjectException, IOException Create a new in-core index representation and read an index from disk. The new index will be read before it is returned to the caller. Read failures are reported as exceptions and therefore prevent the method from returning a partially populated index.
| |
| read | back to summary |
|---|---|
| public static DirCache read(File indexLocation, FS fs) throws CorruptObjectException, IOException Create a new in-core index representation and read an index from disk. The new index will be read before it is returned to the caller. Read failures are reported as exceptions and therefore prevent the method from returning a partially populated index.
| |
| read | back to summary |
|---|---|
| public void read() throws IOException, CorruptObjectException Read the index from disk, if it has changed on disk. This method tries to avoid loading the index if it has not changed since the last time we consulted it. A missing index file will be treated as though it were present but had no file entries in it.
| |
| readConfig | back to summary |
|---|---|
| private void readConfig() | |
| readFrom | back to summary |
|---|---|
| private void readFrom(InputStream inStream) throws IOException, CorruptObjectException | |
| registerIndexChangedListener | back to summary |
|---|---|
| private void registerIndexChangedListener(IndexChangedListener listener) | |
| replace | back to summary |
|---|---|
| pack-priv void replace(DirCacheEntry[] e, int cnt) | |
| requireLocked | back to summary |
|---|---|
| private void requireLocked(LockFile tmp) | |
| skipOptionalExtension | back to summary |
|---|---|
| private void skipOptionalExtension(final InputStream in, final MessageDigest md, final byte[] hdr, long sz) throws IOException | |
| toArray | back to summary |
|---|---|
| pack-priv void toArray(final int i, final DirCacheEntry[] dst, final int off, final int cnt) | |
| unlock | back to summary |
|---|---|
| public void unlock() Unlock this file and abort this change. The temporary file (if created) is deleted before returning. | |
| updateSmudgedEntries | back to summary |
|---|---|
| private void updateSmudgedEntries() throws IOException Update any smudged entries with information from the working tree.
| |
| write | back to summary |
|---|---|
| public void write() throws IOException Write the entry records from memory to disk.
The cache must be locked first by calling
Once written the lock is closed and must be either committed with
| |
| writeTo | back to summary |
|---|---|
| pack-priv void writeTo(File dir, OutputStream os) throws IOException | |
| writeTree | back to summary |
|---|---|
| public ObjectId writeTree(ObjectInserter ow) throws UnmergedPathException, IOException Write all index trees to the object store, returning the root tree.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final DirCache. | |
| private final boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public DirCache. | |
| public boolean |
| indexVersion | back to summary |
|---|---|
| private final DirCache. | |
| skipHash | back to summary |
|---|---|
| private final boolean skipHash | |
| DirCacheConfig | back to summary |
|---|---|
| public DirCacheConfig(Config cfg) | |
| getIndexVersion | back to summary |
|---|---|
| public DirCache. | |
| isSkipHash | back to summary |
|---|---|
| public boolean isSkipHash() | |
| Modifier and Type | Field and Description |
|---|---|
| public static final DirCache. | DIRC_VERSION_EXTENDED
Version 3 supports extended flags. |
| public static final DirCache. | DIRC_VERSION_MINIMUM
Minimum index version on-disk format that we support. |
| public static final DirCache. | DIRC_VERSION_PATHCOMPRESS
Version 4 adds very simple "path compression": it strips out the common prefix between the last entry written and the current entry. |
| private final int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static DirCache. | Returns: the DirCacheVersion instance of the version code.integer value of the version code. val)Create DirCacheVersion from integer value of the version code. |
| public int | |
| public boolean | matchConfigValue(String
the string to match in)Implements org. Checks if the given string matches with enum value. |
| public String | toConfigValue()
Implements org. Converts enumeration value into a string to be save in config. |
| public static DirCache. | |
| public static DirCache. |
| DIRC_VERSION_EXTENDED | back to summary |
|---|---|
| public static final DirCache. Version 3 supports extended flags. | |
| DIRC_VERSION_MINIMUM | back to summary |
|---|---|
| public static final DirCache. Minimum index version on-disk format that we support. | |
| DIRC_VERSION_PATHCOMPRESS | back to summary |
|---|---|
| public static final DirCache. Version 4 adds very simple "path compression": it strips out the common prefix between the last entry written and the current entry. Instead of writing two entries with paths "foo/bar/baz/a.txt" and "foo/bar/baz/b.txt" it only writes "b.txt" for the second entry. It is also not padded. | |
| version | back to summary |
|---|---|
| private final int version | |
| DirCacheVersion | back to summary |
|---|---|
| private DirCacheVersion(int versionCode) | |
| fromInt | back to summary |
|---|---|
| public static DirCache. Create DirCacheVersion from integer value of the version code.
| |
| getVersionCode | back to summary |
|---|---|
public int getVersionCode()
| |
| matchConfigValue | back to summary |
|---|---|
| public boolean matchConfigValue(String in) Implements org. Doc from org. Checks if the given string matches with enum value. | |
| toConfigValue | back to summary |
|---|---|
| public String toConfigValue() Implements org. Doc from org. Converts enumeration value into a string to be save in config. | |
| valueOf | back to summary |
|---|---|
| public static DirCache. | |
| values | back to summary |
|---|---|
| public static DirCache. | |