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/remote.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/remote.c')
| -rw-r--r-- | src/remote.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/remote.c b/src/remote.c index a222023d8..c6a9173af 100644 --- a/src/remote.c +++ b/src/remote.c @@ -88,14 +88,19 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *url, cons return GIT_SUCCESS; } -int git_remote_get(git_remote **out, git_config *cfg, const char *name) +int git_remote_load(git_remote **out, git_repository *repo, const char *name) { git_remote *remote; char *buf = NULL; const char *val; int ret, error, buf_len; + git_config *config; - assert(out && cfg && name); + assert(out && repo && name); + + error = git_repository_config__weakptr(&config, repo); + if (error < GIT_SUCCESS) + return error; remote = git__malloc(sizeof(git_remote)); if (remote == NULL) @@ -122,13 +127,13 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name) goto cleanup; } - error = git_config_get_string(cfg, buf, &val); + error = git_config_get_string(config, buf, &val); if (error < GIT_SUCCESS) { error = git__rethrow(error, "Remote's url doesn't exist"); goto cleanup; } - remote->repo = cfg->repo; + remote->repo = repo; remote->url = git__strdup(val); if (remote->url == NULL) { error = GIT_ENOMEM; @@ -141,7 +146,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name) goto cleanup; } - error = parse_remote_refspec(cfg, &remote->fetch, buf); + error = parse_remote_refspec(config, &remote->fetch, buf); if (error < GIT_SUCCESS) { error = git__rethrow(error, "Failed to get fetch refspec"); goto cleanup; @@ -153,7 +158,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name) goto cleanup; } - error = parse_remote_refspec(cfg, &remote->push, buf); + error = parse_remote_refspec(config, &remote->push, buf); /* Not finding push is fine */ if (error == GIT_ENOTFOUND) error = GIT_SUCCESS; @@ -165,6 +170,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name) cleanup: git__free(buf); + if (error < GIT_SUCCESS) git_remote_free(remote); |
