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/refs.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/refs.c')
-rw-r--r-- | src/refs.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/refs.c b/src/refs.c index 2374cc72f..4c45fec2c 100644 --- a/src/refs.c +++ b/src/refs.c @@ -1195,7 +1195,8 @@ cleanup: */ int git_reference_set_oid(git_reference *ref, const git_oid *id) { - int error = GIT_SUCCESS; + int error = GIT_SUCCESS, exists; + git_odb *odb = NULL; if ((ref->flags & GIT_REF_OID) == 0) return git__throw(GIT_EINVALIDREFSTATE, @@ -1203,23 +1204,29 @@ int git_reference_set_oid(git_reference *ref, const git_oid *id) assert(ref->owner); + error = git_repository_odb__weakptr(&odb, ref->owner); + if (error < GIT_SUCCESS) + return error; + + exists = git_odb_exists(odb, id); + + git_odb_free(odb); + /* Don't let the user create references to OIDs that * don't exist in the ODB */ - if (!git_odb_exists(git_repository_database(ref->owner), id)) + if (!exists) return git__throw(GIT_ENOTFOUND, "Failed to set OID target of reference. OID doesn't exist in ODB"); /* Update the OID value on `ref` */ git_oid_cpy(&ref->target.oid, id); + /* Write back to disk */ error = loose_write(ref); if (error < GIT_SUCCESS) - goto cleanup; + return git__rethrow(error, "Failed to set OID target of reference"); return GIT_SUCCESS; - -cleanup: - return git__rethrow(error, "Failed to set OID target of reference"); } /* |