C# Class GitSharp.Core.DirectoryCache.DirCache

Support for the Git dircache (aka index file). 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.
Show file Open project: jagregory/GitSharp Class Usage Examples

Public Methods

Method Description
Compare ( DirCacheEntry a, DirCacheEntry b ) : int
Compare ( byte aPath, int aLen, byte bPath, int bLen ) : int
DirCache ( FileInfo indexLocation ) : System

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

Lock ( FileInfo indexLocation ) : DirCache

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 ( Repository db ) : DirCache

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.

Lock ( ) : bool

Try to establish an update lock on the cache file.

builder ( ) : DirCacheBuilder

Create a new builder to update this cache. Callers should add all entries to the builder, then use DirCacheBuilder.finish() to update this instance.

clear ( ) : void

Empty this index, removing all entries.

commit ( ) : bool

Commit this change and release the lock. If this method fails (returns false) the lock is still released.

editor ( ) : DirCacheEditor

Create a new editor to recreate this cache. Callers should add commands to the editor, then use DirCacheEditor.finish() to update this instance.

findEntry ( byte p, int pLen ) : int
findEntry ( string path ) : int

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.

getCacheTree ( bool build ) : DirCacheTree

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 ( string path ) : GitSharp.Core.DirectoryCache.DirCacheEntry[]

Recursively get all entries within a subtree.

getEntry ( int i ) : DirCacheEntry

Get a specific entry.

getEntry ( string path ) : DirCacheEntry

Get a specific entry.

getEntryCount ( ) : int

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.

newInCore ( ) : DirCache

Create a new empty index which is never stored on disk.

nextEntry ( byte p, int pLen, int nextIdx ) : int
nextEntry ( int position ) : int

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.

read ( FileInfo indexLocation ) : DirCache

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 ( Repository db ) : DirCache

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 ( ) : void

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.

replace ( DirCacheEntry e, int cnt ) : void
toArray ( int i, DirCacheEntry dst, int off, int cnt ) : void
unlock ( ) : void

Unlock this file and abort this change. The temporary file (if created) is deleted before returning.

write ( ) : void

Write the entry records from memory to disk. The cache must be locked first by calling Lock() and receiving true as the return value. Applications are encouraged to lock the index, then invoke read() to ensure the in-memory data is current, prior to updating the in-memory entries. Once written the lock is closed and must be either committed with commit() or rolled back with unlock().

writeTree ( ObjectWriter ow ) : ObjectId

Write all index trees to the object store, returning the root tree.

Private Methods

Method Description
Compare ( byte aPath, int aLen, DirCacheEntry b ) : int
IsDIRC ( byte header ) : bool
ReadFrom ( Stream inStream ) : void
RequireLocked ( LockFile tmp ) : void
WriteTo ( Stream os ) : void

Method Details

Compare() public static method

public static Compare ( DirCacheEntry a, DirCacheEntry b ) : int
a DirCacheEntry
b DirCacheEntry
return int

Compare() public static method

public static Compare ( byte aPath, int aLen, byte bPath, int bLen ) : int
aPath byte
aLen int
bPath byte
bLen int
return int

DirCache() public method

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 read().
public DirCache ( FileInfo indexLocation ) : System
indexLocation System.IO.FileInfo location of the index file on disk.
return System

Lock() public static method

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.
/// The index file is present but could not be read, or the lock /// could not be obtained. /// /// the index file is using a format or extension that this /// library does not support. ///
public static Lock ( FileInfo indexLocation ) : DirCache
indexLocation System.IO.FileInfo /// location of the index file on disk. ///
return DirCache

Lock() public static method

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.
/// The index file is present but could not be read, or the lock /// could not be obtained. /// /// The index file is using a format or extension that this /// library does not support. ///
public static Lock ( Repository db ) : DirCache
db Repository /// Repository the caller wants to read the default index of. ///
return DirCache

Lock() public method

Try to establish an update lock on the cache file.
/// The output file could not be created. The caller does not /// hold the lock. ///
public Lock ( ) : bool
return bool

builder() public method

Create a new builder to update this cache. Callers should add all entries to the builder, then use DirCacheBuilder.finish() to update this instance.
public builder ( ) : DirCacheBuilder
return DirCacheBuilder

clear() public method

Empty this index, removing all entries.
public clear ( ) : void
return void

commit() public method

Commit this change and release the lock. If this method fails (returns false) the lock is still released.
/// the lock is not held. ///
public commit ( ) : bool
return bool

editor() public method

Create a new editor to recreate this cache. Callers should add commands to the editor, then use DirCacheEditor.finish() to update this instance.
public editor ( ) : DirCacheEditor
return DirCacheEditor

findEntry() public method

public findEntry ( byte p, int pLen ) : int
p byte
pLen int
return int

findEntry() public method

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.
public findEntry ( string path ) : int
path string The path to search for.
return int

getCacheTree() public method

Obtain (or build) the current cache tree structure. This method can optionally recreate the cache tree, without flushing the tree objects themselves to disk.
public getCacheTree ( bool build ) : DirCacheTree
build bool /// If true and the cache tree is not present in the index it will /// be generated and returned to the caller. ///
return DirCacheTree

getEntriesWithin() public method

Recursively get all entries within a subtree.
public getEntriesWithin ( string path ) : GitSharp.Core.DirectoryCache.DirCacheEntry[]
path string /// The subtree path to get all entries within. ///
return GitSharp.Core.DirectoryCache.DirCacheEntry[]

getEntry() public method

Get a specific entry.
public getEntry ( int i ) : DirCacheEntry
i int /// position of the entry to get. ///
return DirCacheEntry

getEntry() public method

Get a specific entry.
public getEntry ( string path ) : DirCacheEntry
path string The path to search for.
return DirCacheEntry

getEntryCount() public method

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.
public getEntryCount ( ) : int
return int

newInCore() public static method

Create a new empty index which is never stored on disk.
public static newInCore ( ) : DirCache
return DirCache

nextEntry() public method

public nextEntry ( byte p, int pLen, int nextIdx ) : int
p byte
pLen int
nextIdx int
return int

nextEntry() public method

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.
public nextEntry ( int position ) : int
position int /// entry position of the path that should be skipped. ///
return int

read() public static method

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.
/// The index file is present but could not be read. /// /// The index file is using a format or extension that this /// library does not support. ///
public static read ( FileInfo indexLocation ) : DirCache
indexLocation System.IO.FileInfo Location of the index file on disk.
return DirCache

read() public static method

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.
/// The index file is present but could not be read. /// /// The index file is using a format or extension that this /// library does not support. ///
public static read ( Repository db ) : DirCache
db Repository /// repository the caller wants to read the default index of. ///
return DirCache

read() public method

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.
/// The index file is present but could not be read. This /// instance may not be populated correctly. /// /// The index file is using a format or extension that this /// library does not support. ///
public read ( ) : void
return void

replace() public method

public replace ( DirCacheEntry e, int cnt ) : void
e DirCacheEntry
cnt int
return void

toArray() public method

public toArray ( int i, DirCacheEntry dst, int off, int cnt ) : void
i int
dst DirCacheEntry
off int
cnt int
return void

unlock() public method

Unlock this file and abort this change. The temporary file (if created) is deleted before returning.
public unlock ( ) : void
return void

write() public method

Write the entry records from memory to disk. The cache must be locked first by calling Lock() and receiving true as the return value. Applications are encouraged to lock the index, then invoke read() to ensure the in-memory data is current, prior to updating the in-memory entries. Once written the lock is closed and must be either committed with commit() or rolled back with unlock().
/// The output file could not be created. The caller no longer /// holds the lock. ///
public write ( ) : void
return void

writeTree() public method

Write all index trees to the object store, returning the root tree.
/// One or more paths contain higher-order stages (stage > 0), /// which cannot be stored in a tree object. /// /// One or more paths contain an invalid mode which should never /// appear in a tree object. /// /// An unexpected error occurred writing to the object store. ///
public writeTree ( ObjectWriter ow ) : ObjectId
ow ObjectWriter /// The writer to use when serializing to the store. ///
return ObjectId