diff options
| author | Vicent Marti <tanoku@gmail.com> | 2010-11-14 22:11:46 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2010-11-16 02:59:28 +0200 |
| commit | c3a20d5cab7d17cf55e769c39a3d50882e3d341d (patch) | |
| tree | b00021319f63036e8a08c2b99d70e409adf111ef /src/git | |
| parent | 7a3924fc38b63313e84c6339d2fd56084f5aeea6 (diff) | |
| download | libgit2-c3a20d5cab7d17cf55e769c39a3d50882e3d341d.tar.gz | |
Add support for 'index add'
Actually add files to the index by creating their corresponding blob and
storing it on the repository, then getting the hash and updating the
index file.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/git')
| -rw-r--r-- | src/git/common.h | 3 | ||||
| -rw-r--r-- | src/git/index.h | 39 |
2 files changed, 28 insertions, 14 deletions
diff --git a/src/git/common.h b/src/git/common.h index 82f08ac5d..cbc77e991 100644 --- a/src/git/common.h +++ b/src/git/common.h @@ -105,6 +105,9 @@ /** The queried object is currently busy */ #define GIT_EBUSY (GIT_ERROR - 13) +/** The index file is not backed up by an existing repository */ +#define GIT_EBAREINDEX (GIT_ERROR -14) + GIT_BEGIN_DECL diff --git a/src/git/index.h b/src/git/index.h index 8220e6290..6cf270baa 100644 --- a/src/git/index.h +++ b/src/git/index.h @@ -47,21 +47,28 @@ typedef struct git_index_entry { /** * Create a new Git index object as a memory representation - * of the Git index file in 'index_path'. + * of the Git index file in 'index_path', without a repository + * to back it. * - * 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. + * Since there is no ODB behind this index, any Index methods + * which rely on the ODB (e.g. index_add) will fail with the + * GIT_EBAREINDEX error code. * * @param index the pointer for the new index * @param index_path the path to the index file in disk - * @param working_dir working dir for the git repository * @return 0 on success; error code otherwise */ -GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path, const char *working_dir); +GIT_EXTERN(int) git_index_open_bare(git_index **index, const char *index_path); + +/** + * Open the Index inside the git repository pointed + * by 'repo'. + * + * @param repo the git repo which owns the index + * @param index_path the path to the index file in disk + * @return 0 on success; error code otherwise + */ +GIT_EXTERN(int) git_index_open_inrepo(git_index **index, git_repository *repo); /** * Clear the contents (all the entries) of an index object. @@ -108,14 +115,14 @@ GIT_EXTERN(int) git_index_write(git_index *index); GIT_EXTERN(int) git_index_find(git_index *index, const char *path); /** - * Add a new empty entry to the index with a given path. + * Add or update an index entry from a file in disk. * * @param index an existing index object - * @param path filename pointed to by the entry + * @param path filename to add * @param stage stage for the entry * @return 0 on success, otherwise an error code */ -GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path, int stage); +GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage); /** * Remove an entry from the index @@ -127,13 +134,17 @@ GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path, int sta GIT_EXTERN(int) git_index_remove(git_index *index, int position); /** - * Add a new entry to the index + * Insert an entry into the index. + * A full copy (including the 'path' string) of the given + * 'source_entry' will be inserted on the index; if the index + * already contains an entry for the same path, the entry + * will be updated. * * @param index an existing index object * @param source_entry new entry object * @return 0 on success, otherwise an error code */ -GIT_EXTERN(int) git_index_add(git_index *index, const git_index_entry *source_entry); +GIT_EXTERN(int) git_index_insert(git_index *index, const git_index_entry *source_entry); /** * Get a pointer to one of the entries in the index |
