Xgit v0.1.6 Xgit.Core.DirCache View Source
A directory cache records the current (intended) contents of a working tree when last scanned or created by git.
In Xgit, the DirCache
structure is an abstract, in-memory data structure
without any tie to a specific persistence mechanism. Persistence is implemented
by a specific implementation of the Xgit.Repository
behaviour.
This content is commonly persisted on disk as an index
file at the root of
the git tree. The module Xgit.Repository.WorkingTree.ParseIndexFile
can
parse that file format.
Changes in the working tree can be detected by comparing the modification times to the cached modification time within the dir cache.
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.
Link to this section Summary
Types
Error reason codes returned by add_entries/2
.
An entry for the remove
option for remove_entries/2
.
Error reason codes returned by remove_entries/2
.
This struct describes an entire working tree as understood by git.
Version number for an index file.
Functions
Returns a dir cache that has new directory entries added in.
Returns a dir cache that is the canonical "empty" dir cache (i.e. contains no entries).
Returns a dir cache that has some directory entries removed.
Return true
if the value is a DirCache
struct that is valid.
Link to this section Types
add_entries_reason()
View Sourceadd_entries_reason() :: :invalid_dir_cache | :invalid_entries | :duplicate_entries
Error reason codes returned by add_entries/2
.
entry_to_remove()
View Sourceentry_to_remove() :: {path :: [byte()], stage :: 0..3 | :all}
An entry for the remove
option for remove_entries/2
.
remove_entries_reason()
View Sourceremove_entries_reason() :: :invalid_dir_cache | :invalid_entries
Error reason codes returned by remove_entries/2
.
t()
View Sourcet() :: %Xgit.Core.DirCache{ entries: [Xgit.Core.DirCache.Entry.t()], entry_count: non_neg_integer(), version: version() }
This struct describes an entire working tree as understood by git.
Struct Members
:version
: the version number as read from disk (typically 2, 3, or 4):entry_count
: the number of items inentries
:entries
: a list ofEntry
structs in sorted order:extensions
: a list ofExtension
structs (not yet implemented)
Version number for an index file.
Link to this section Functions
add_entries(dir_cache, new_entries)
View Sourceadd_entries(dir_cache :: t(), new_entries :: [Xgit.Core.DirCache.Entry.t()]) :: {:ok, t()} | {:error, add_entries_reason()}
Returns a dir cache that has new directory entries added in.
In the event of a collision between entries (same path and stage), the existing entry will be replaced by the new one.
Parameters
entries
a list of entries to add to the existing dir cache
Return Value
{:ok, dir_cache}
where dir_cache
is the original dir_cache
with the new
entries added (and properly sorted).
{:error, :invalid_dir_cache}
if the original dir_cache
was invalid.
{:error, :invalid_entries}
if one or more of the entries is invalid.
{:error, :duplicate_entries}
if one or more of the entries in the new list
are duplicates of other entries in the new list. (As stated earlier, duplicates
from the original list are acceptable; in that event, the new entry will replace
the old one.)
Returns a dir cache that is the canonical "empty" dir cache (i.e. contains no entries).
remove_entries(dir_cache, entries_to_remove)
View Sourceremove_entries(dir_cache :: t(), entries_to_remove :: [entry_to_remove()]) :: {:ok, t()} | {:error, remove_entries_reason()}
Returns a dir cache that has some directory entries removed.
Parameters
entries_to_remove
is a list of {path, stage}
tuples identifying tuples to be removed.
path
should be a byte list for the path.stage
should be 0..3 or:all
, meaning any entry that matches the path, regardless of stage, should be removed.
Return Value
{:ok, dir_cache}
where dir_cache
is the original dir_cache
with any matching
entries removed.
{:error, :invalid_dir_cache}
if the original dir_cache
was invalid.
{:error, :invalid_entries}
if one or more of the entries is invalid.
Return true
if the value is a DirCache
struct that is valid.
All of the following must be true for this to occur:
- The value is a
DirCache
struct. - The version is supported by Xgit. (Currently, only version 2 is supported.)
- The
entry_count
matches the actual number of entries. - The entries are properly sorted.
- All entries are valid, as determined by
Xgit.Core.DirCache.Entry.valid?/1
.