diff options
| author | Vicent Marti <tanoku@gmail.com> | 2010-09-20 01:57:53 +0300 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2010-09-20 02:04:06 +0300 |
| commit | 0c3596f18a6f07d8a61f8d6e2fd730a276a51599 (patch) | |
| tree | 02add71c1efc95d8c9eead36edca9b2996f5d602 /src/repository.c | |
| parent | e802d8cca8b7fddb8ae157b84fb7c1e84671546d (diff) | |
| download | libgit2-0c3596f18a6f07d8a61f8d6e2fd730a276a51599.tar.gz | |
Add setter methods & write support for git_commit
All the required git_commit_set_XXX methods have been implemented; all
the attributes of a commit object can now be modified in-memory.
The new method git_object_write() automatically writes back the
in-memory changes of any object to the repository. So far it only
supports git_commit objects.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/repository.c')
| -rw-r--r-- | src/repository.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/repository.c b/src/repository.c index 14c8f456a..f353ce06b 100644 --- a/src/repository.c +++ b/src/repository.c @@ -205,6 +205,8 @@ int git_object__source_writeback(git_object *object) object->source.write_ptr = NULL; object->source.written_bytes = 0; + object->modified = 0; + git_object__source_close(object); return GIT_SUCCESS; } @@ -241,6 +243,38 @@ void git_object__source_close(git_object *object) } } +int git_object_write(git_object *object) +{ + int error; + git_odb_source *source; + + assert(object); + + if (object->modified == 0) + return GIT_SUCCESS; + + git_object__source_prepare_write(object); + source = &object->source; + + switch (source->raw.type) { + case GIT_OBJ_COMMIT: + error = git_commit__writeback((git_commit *)object, source); + break; + + case GIT_OBJ_TREE: + case GIT_OBJ_TAG: + default: + error = GIT_ERROR; + } + + if (error < 0) { + git_object__source_close(object); + return error; + } + + return git_object__source_writeback(object); +} + void git_object_free(git_object *object) { assert(object); @@ -328,7 +362,7 @@ git_object *git_repository_lookup(git_repository *repo, const git_oid *id, git_o switch (type) { case GIT_OBJ_COMMIT: - if (git_commit__parse_basic((git_commit *)object) < 0) { + if (git_commit__parse((git_commit *)object) < 0) { free(object); return NULL; } |
