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/blob.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/blob.c')
-rw-r--r-- | src/blob.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/blob.c b/src/blob.c index f13a5be15..5fd0fd67e 100644 --- a/src/blob.c +++ b/src/blob.c @@ -41,9 +41,14 @@ int git_blob__parse(git_blob *blob, git_odb_object *odb_obj) int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *buffer, size_t len) { int error; + git_odb *odb; git_odb_stream *stream; - if ((error = git_odb_open_wstream(&stream, repo->db, len, GIT_OBJ_BLOB)) < GIT_SUCCESS) + error = git_repository_odb__weakptr(&odb, repo); + if (error < GIT_SUCCESS) + return error; + + if ((error = git_odb_open_wstream(&stream, odb, len, GIT_OBJ_BLOB)) < GIT_SUCCESS) return git__rethrow(error, "Failed to create blob"); if ((error = stream->write(stream, buffer, len)) < GIT_SUCCESS) { @@ -69,11 +74,14 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat git_off_t size; git_odb_stream *stream; struct stat st; + const char *workdir; + git_odb *odb; - if (repo->path_workdir == NULL) + workdir = git_repository_workdir(repo); + if (workdir == NULL) return git__throw(GIT_ENOTFOUND, "Failed to create blob. (No working directory found)"); - git_path_join(full_path, repo->path_workdir, path); + git_path_join(full_path, workdir, path); error = p_lstat(full_path, &st); if (error < 0) { @@ -83,11 +91,16 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat islnk = S_ISLNK(st.st_mode); size = st.st_size; - if (!islnk) + error = git_repository_odb__weakptr(&odb, repo); + if (error < GIT_SUCCESS) + return error; + + if (!islnk) { if ((fd = p_open(full_path, O_RDONLY)) < 0) return git__throw(GIT_ENOTFOUND, "Failed to create blob. Could not open '%s'", full_path); + } - if ((error = git_odb_open_wstream(&stream, repo->db, (size_t)size, GIT_OBJ_BLOB)) < GIT_SUCCESS) { + if ((error = git_odb_open_wstream(&stream, odb, (size_t)size, GIT_OBJ_BLOB)) < GIT_SUCCESS) { if (!islnk) p_close(fd); return git__rethrow(error, "Failed to create blob"); |