diff options
Diffstat (limited to 'src/git')
-rw-r--r-- | src/git/index.h | 50 | ||||
-rw-r--r-- | src/git/repository.h | 33 |
2 files changed, 76 insertions, 7 deletions
diff --git a/src/git/index.h b/src/git/index.h index 46fccbd74..3b262355e 100644 --- a/src/git/index.h +++ b/src/git/index.h @@ -1,6 +1,7 @@ #ifndef INCLUDE_git_index_h__ #define INCLUDE_git_index_h__ +#include <stdint.h> #include "common.h" #include "oid.h" @@ -16,18 +17,50 @@ GIT_BEGIN_DECL /** Memory representation of an index file. */ typedef struct git_index git_index; + +/** Time used in a git index entry */ +typedef struct { + uint32_t seconds; + uint32_t nanoseconds; +} git_index_time; + /** Memory representation of a file entry in the index. */ -typedef struct git_index_entry git_index_entry; +typedef struct git_index_entry { + git_index_time ctime; + git_index_time mtime; + + uint32_t dev; + uint32_t ino; + uint32_t mode; + uint32_t uid; + uint32_t gid; + uint32_t file_size; + + git_oid oid; + + uint16_t flags; + uint16_t flags_extended; + + char *path; +} git_index_entry; /** * Create a new Git index object as a memory representation * of the Git index file in 'index_path'. * + * The argument 'working_dir' is the root path of the indexed + * files in the index and is used to calculate the relative path + * when inserting new entries from existing files on disk. + * + * If 'working _dir' is NULL (e.g for bare repositories), the + * methods working on on-disk files will fail. + * * @param index_path the path to the index file in disk + * @param working_dir working dir for the git repository * @return the index object; NULL if the index could not be created */ -GIT_EXTERN(git_index *) git_index_alloc(const char *index_path); +GIT_EXTERN(git_index *) git_index_alloc(const char *index_path, const char *working_dir); /** * Clear the contents (all the entries) of an index object. @@ -83,6 +116,19 @@ GIT_EXTERN(int) git_index_find(git_index *index, const char *path); */ GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage); +/** + * Get a pointer to one of the entries in the index + * + * This entry can be modified, and the changes will be written + * back to disk on the next write() call. + * + * @param index an existing index object + * @param n the position of the entry + * @return a pointer to the entry; NULL if out of bounds + */ +GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, int n); + + /** @} */ GIT_END_DECL #endif diff --git a/src/git/repository.h b/src/git/repository.h index 0a50fe1ef..058849b7f 100644 --- a/src/git/repository.h +++ b/src/git/repository.h @@ -4,6 +4,7 @@ #include "common.h" #include "odb.h" #include "commit.h" +#include "index.h" /** * @file git/repository.h @@ -15,15 +16,28 @@ GIT_BEGIN_DECL /** - * Allocate a new repository object. + * Open a git repository. * - * TODO: specify the repository's path instead - * of its object database + * The 'path' argument must point to an existing git repository + * folder, e.g. * - * @param odb an existing object database to back the repo + * /path/to/my_repo/.git/ (normal repository) + * objects/ + * index + * HEAD + * + * /path/to/bare_repo/ (bare repository) + * objects/ + * index + * HEAD + * + * The method will automatically detect if 'path' is a normal + * or bare repository or fail is 'path' is neither. + * + * @param path the path to the repository * @return the new repository handle; NULL on error */ -GIT_EXTERN(git_repository *) git_repository_alloc(git_odb *odb); +GIT_EXTERN(git_repository *) git_repository_open(const char *path); /** @@ -58,6 +72,15 @@ GIT_EXTERN(git_object *) git_repository_lookup(git_repository *repo, const git_o GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo); /** + * Get the Index file of a Git repository + * + * @param repo a repository object + * @return a pointer to the Index object; + * NULL if the index cannot be opened + */ +GIT_EXTERN(git_index *) git_repository_index(git_repository *rpeo); + +/** * Create a new in-memory repository object with * the given type. * |