Add support for git index files
commite34dee0c7f0ac8abf228369e1016eb6016c40758
authorVicent Marti <tanoku@gmail.com>
Fri, 9 Jul 2010 18:19:56 +0000 (9 20:19 +0200)
committerVicent Marti <tanoku@gmail.com>
Sun, 25 Jul 2010 23:36:27 +0000 (26 01:36 +0200)
tree0238a56890c6185070331056033f4dfe61a275f7
parent5fdc7166eac68b0b0923439b8685a29ff4c2be27
Add support for git index files

The new 'git_index' structure is an in-memory representation
of a git index on disk; the 'git_index_entry' structures represent
each one of the file entries on the index.

The following calls for index instantiation have been added:

git_index_alloc(): instantiate a new index structure
git_index_free(): free an existing index
git_index_clear(): clear all the entires in an existing file

The following calls for index reading and writing have been added:

git_index_read(): update the contents of the index structure from
  its file on disk.

Internally implemented through:
git_index__parse()
git_index__parse_header()
git_index__parse_entry()
git_index__parse_extension()
git_index__parse_treecache()

Index files are stored on disk in network byte order; all integer fields
inside them are properly converted to the machine's byte order when
loading them in memory. The parsing engine also distinguishes
between normal index entries and extended entries with 2 extra bytes
of flags.

The 'TREE' extension for index entries is also loaded into memory:
Tree caches stored in Index files are loaded into the
'git_index_tree' structure pointed by the 'tree' pointer inside
'git_index'.

'index->tree' points to the root node of the tree cache; the full tree
can be traversed through each of the node's 'tree->children'.

Index files can be written back to disk through:

git_index_write(): atomic writing of existing index objects
backed by internal method git_index__write()

The following calls for entry manipulation have been added:

git_index_add(): insert an empty entry to the index

git_index_find(): search an entry by its path name

git_index__append(): appends a new index entry to the end of the
 list, resizing the entries array if required

New index entries are always inserted at the end of the array; since the
index entries must be sorted for it to be internally consistent, the
index object is only sorted once, and if required, before accessing the
whole entriea array (e.g. before writing to disk, before traversing,
etc).

git_index__remove_pos(): remove an index entry in a specific position

git_index__sort(): sort the entries in the array by path name

The entries array is sorted stably and in place using an
insertion sort, which ought to be the most efficient approach
since the entries array is always mostly-sorted.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
src/git/index.h [new file with mode: 0644]
src/index.c [new file with mode: 0644]
src/index.h [new file with mode: 0644]