diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-11-25 08:16:26 +0100 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-11-26 08:37:08 +0100 |
| commit | 9462c471435b4de74848408bebe41d770dc49a50 (patch) | |
| tree | aac5e696d1b3e7b4cba64082b28255e5c4593b66 /src/tree.c | |
| parent | 880b6f0c22153db164ecb3a18c362ba8337365d3 (diff) | |
| download | libgit2-9462c471435b4de74848408bebe41d770dc49a50.tar.gz | |
repository: Change ownership semantics
The ownership semantics have been changed all over the library to be
consistent. There are no more "borrowed" or duplicated references.
Main changes:
- `git_repository_open2` and `3` have been dropped.
- Added setters and getters to hotswap all the repository owned
objects:
`git_repository_index`
`git_repository_set_index`
`git_repository_odb`
`git_repository_set_odb`
`git_repository_config`
`git_repository_set_config`
`git_repository_workdir`
`git_repository_set_workdir`
Now working directories/index files/ODBs and so on can be
hot-swapped after creating a repository and between operations.
- All these objects now have proper ownership semantics with
refcounting: they all require freeing after they are no longer
needed (the repository always keeps its internal reference).
- Repository open and initialization has been updated to keep in
mind the configuration files. Bare repositories are now always
detected, and a default config file is created on init.
- All the tests affected by these changes have been dropped from the
old test suite and ported to the new one.
Diffstat (limited to 'src/tree.c')
| -rw-r--r-- | src/tree.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/tree.c b/src/tree.c index 92ca5ab77..ec44d2492 100644 --- a/src/tree.c +++ b/src/tree.c @@ -300,9 +300,15 @@ static int append_entry(git_treebuilder *bld, const char *filename, const git_oi return GIT_SUCCESS; } -static int write_tree(git_oid *oid, git_index *index, const char *dirname, unsigned int start) +static int write_tree( + git_oid *oid, + git_repository *repo, + git_index *index, + const char *dirname, + unsigned int start) { git_treebuilder *bld = NULL; + unsigned int i, entries = git_index_entrycount(index); int error; size_t dirname_len = strlen(dirname); @@ -358,7 +364,7 @@ static int write_tree(git_oid *oid, git_index *index, const char *dirname, unsig } /* Write out the subtree */ - written = write_tree(&sub_oid, index, subdir, i); + written = write_tree(&sub_oid, repo, index, subdir, i); if (written < 0) { error = git__rethrow(written, "Failed to write subtree %s", subdir); } else { @@ -391,7 +397,7 @@ static int write_tree(git_oid *oid, git_index *index, const char *dirname, unsig } } - error = git_treebuilder_write(oid, index->repository, bld); + error = git_treebuilder_write(oid, repo, bld); if (error < GIT_SUCCESS) error = git__rethrow(error, "Failed to write tree to db"); @@ -406,10 +412,15 @@ static int write_tree(git_oid *oid, git_index *index, const char *dirname, unsig int git_tree_create_fromindex(git_oid *oid, git_index *index) { + git_repository *repo; int error; - if (index->repository == NULL) - return git__throw(GIT_EBAREINDEX, "Failed to create tree. The index file is not backed up by an existing repository"); + repo = (git_repository *)GIT_REFCOUNT_OWNER(index); + + if (repo == NULL) + return git__throw(GIT_EBAREINDEX, + "Failed to create tree. " + "The index file is not backed up by an existing repository"); if (index->tree != NULL && index->tree->entries >= 0) { git_oid_cpy(oid, &index->tree->oid); @@ -417,7 +428,7 @@ int git_tree_create_fromindex(git_oid *oid, git_index *index) } /* The tree cache didn't help us */ - error = write_tree(oid, index, "", 0); + error = write_tree(oid, repo, index, "", 0); return (error < GIT_SUCCESS) ? git__rethrow(error, "Failed to create tree") : GIT_SUCCESS; } @@ -546,6 +557,7 @@ int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *b unsigned int i; int error; git_buf tree = GIT_BUF_INIT; + git_odb *odb; assert(bld); @@ -570,7 +582,13 @@ int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *b return git__throw(GIT_ENOMEM, "Not enough memory to build the tree data"); } - error = git_odb_write(oid, git_repository_database(repo), tree.ptr, tree.size, GIT_OBJ_TREE); + error = git_repository_odb__weakptr(&odb, repo); + if (error < GIT_SUCCESS) { + git_buf_free(&tree); + return error; + } + + error = git_odb_write(oid, odb, tree.ptr, tree.size, GIT_OBJ_TREE); git_buf_free(&tree); return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write tree"); |
