summaryrefslogtreecommitdiff
path: root/src/submodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/submodule.c')
-rw-r--r--src/submodule.c297
1 files changed, 154 insertions, 143 deletions
diff --git a/src/submodule.c b/src/submodule.c
index 7cbb9fa3a..b0f7294be 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -7,11 +7,8 @@
#include "submodule.h"
-#include "git2/config.h"
-#include "git2/sys/config.h"
-#include "git2/types.h"
-#include "git2/index.h"
-#include "buffer.h"
+#include "buf.h"
+#include "branch.h"
#include "vector.h"
#include "posix.h"
#include "config_backend.h"
@@ -20,10 +17,16 @@
#include "tree.h"
#include "iterator.h"
#include "path.h"
+#include "str.h"
#include "index.h"
#include "worktree.h"
#include "clone.h"
+#include "git2/config.h"
+#include "git2/sys/config.h"
+#include "git2/types.h"
+#include "git2/index.h"
+
#define GIT_MODULES_FILE ".gitmodules"
static git_configmap _sm_update_map[] = {
@@ -63,8 +66,8 @@ enum {
static int submodule_alloc(git_submodule **out, git_repository *repo, const char *name);
static git_config_backend *open_gitmodules(git_repository *repo, int gitmod);
static int gitmodules_snapshot(git_config **snap, git_repository *repo);
-static int get_url_base(git_buf *url, git_repository *repo);
-static int lookup_head_remote_key(git_buf *remote_key, git_repository *repo);
+static int get_url_base(git_str *url, git_repository *repo);
+static int lookup_head_remote_key(git_str *remote_key, git_repository *repo);
static int lookup_default_remote(git_remote **remote, git_repository *repo);
static int submodule_load_each(const git_config_entry *entry, void *payload);
static int submodule_read_config(git_submodule *sm, git_config *cfg);
@@ -79,11 +82,11 @@ static int submodule_cmp(const void *a, const void *b)
return strcmp(((git_submodule *)a)->name, ((git_submodule *)b)->name);
}
-static int submodule_config_key_trunc_puts(git_buf *key, const char *suffix)
+static int submodule_config_key_trunc_puts(git_str *key, const char *suffix)
{
- ssize_t idx = git_buf_rfind(key, '.');
- git_buf_truncate(key, (size_t)(idx + 1));
- return git_buf_puts(key, suffix);
+ ssize_t idx = git_str_rfind(key, '.');
+ git_str_truncate(key, (size_t)(idx + 1));
+ return git_str_puts(key, suffix);
}
/*
@@ -128,7 +131,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa
{
int error = 0;
git_index *index;
- git_buf dir = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT;
*occupied = false;
if ((error = git_repository_index__weakptr(&index, repo)) < 0)
@@ -143,7 +146,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa
goto out;
}
- if ((error = git_buf_sets(&dir, path)) < 0)
+ if ((error = git_str_sets(&dir, path)) < 0)
goto out;
if ((error = git_path_to_dir(&dir)) < 0)
@@ -161,7 +164,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa
error = 0;
out:
- git_buf_dispose(&dir);
+ git_str_dispose(&dir);
return error;
}
@@ -195,7 +198,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
const char *key = "submodule\\..*\\.path";
git_config_iterator *iter = NULL;
git_config_entry *entry;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_strmap *names;
int isvalid, error;
@@ -219,8 +222,8 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
goto out;
}
- git_buf_clear(&buf);
- git_buf_put(&buf, fdot + 1, ldot - fdot - 1);
+ git_str_clear(&buf);
+ git_str_put(&buf, fdot + 1, ldot - fdot - 1);
isvalid = git_submodule_name_is_valid(repo, buf.ptr, 0);
if (isvalid < 0) {
error = isvalid;
@@ -229,7 +232,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
if (!isvalid)
continue;
- if ((error = git_strmap_set(names, git__strdup(entry->value), git_buf_detach(&buf))) < 0) {
+ if ((error = git_strmap_set(names, git__strdup(entry->value), git_str_detach(&buf))) < 0) {
git_error_set(GIT_ERROR_NOMEMORY, "error inserting submodule into hash table");
error = -1;
goto out;
@@ -243,7 +246,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf
out:
free_submodule_names(names);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_config_iterator_free(iter);
return error;
}
@@ -329,10 +332,10 @@ int git_submodule__lookup_with_cache(
if (location == 0 || location == GIT_SUBMODULE_STATUS_IN_WD) {
git_config_backend *mods;
const char *pattern = "submodule\\..*\\.path";
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
fbp_data data = { NULL, NULL };
- git_buf_puts(&path, name);
+ git_str_puts(&path, name);
while (path.ptr[path.size-1] == '/') {
path.ptr[--path.size] = '\0';
}
@@ -347,14 +350,14 @@ int git_submodule__lookup_with_cache(
if (error < 0) {
git_submodule_free(sm);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
if (data.name) {
git__free(sm->name);
sm->name = data.name;
- sm->path = git_buf_detach(&path);
+ sm->path = git_str_detach(&path);
/* Try to load again with the right name */
if ((error = git_submodule_reload(sm, false)) < 0) {
@@ -363,7 +366,7 @@ int git_submodule__lookup_with_cache(
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
if ((error = git_submodule_location(&location, sm)) < 0) {
@@ -378,8 +381,8 @@ int git_submodule__lookup_with_cache(
/* If it's not configured, we still check if there's a repo at the path */
if (git_repository_workdir(repo)) {
- git_buf path = GIT_BUF_INIT;
- if (git_buf_join3(&path, '/',
+ git_str path = GIT_STR_INIT;
+ if (git_str_join3(&path, '/',
git_repository_workdir(repo),
name, DOT_GIT) < 0 ||
git_path_validate_workdir_buf(NULL, &path) < 0)
@@ -388,7 +391,7 @@ int git_submodule__lookup_with_cache(
if (git_path_exists(path.ptr))
error = GIT_EEXISTS;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
submodule_set_lookup_error(error, name);
@@ -405,7 +408,7 @@ int git_submodule__lookup_with_cache(
int git_submodule_name_is_valid(git_repository *repo, const char *name, int flags)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int error, isvalid;
if (flags == 0)
@@ -416,11 +419,11 @@ int git_submodule_name_is_valid(git_repository *repo, const char *name, int flag
if ((error = git_path_normalize_slashes(&buf, name)) < 0)
return error;
} else {
- git_buf_attach_notowned(&buf, name, strlen(name));
+ git_str_attach_notowned(&buf, name, strlen(name));
}
isvalid = git_path_validate(repo, buf.ptr, 0, flags);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return isvalid;
}
@@ -554,7 +557,7 @@ int git_submodule__map(git_repository *repo, git_strmap *map)
int error = 0;
git_index *idx = NULL;
git_tree *head = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_submodule *sm;
git_config *mods = NULL;
bool has_workdir;
@@ -613,7 +616,7 @@ cleanup:
/* TODO: if we got an error, mark submodule config as invalid? */
git_index_free(idx);
git_tree_free(head);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -682,7 +685,7 @@ static int submodule_repo_init(
bool use_gitlink)
{
int error = 0;
- git_buf workdir = GIT_BUF_INIT, repodir = GIT_BUF_INIT;
+ git_str workdir = GIT_STR_INIT, repodir = GIT_STR_INIT;
git_repository_init_options initopt = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_repository *subrepo = NULL;
@@ -701,10 +704,10 @@ static int submodule_repo_init(
* Old style: sub-repo goes directly into repo/<name>/.git/
*/
if (use_gitlink) {
- error = git_repository_item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
+ error = git_repository__item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
if (error < 0)
goto cleanup;
- error = git_buf_joinpath(&repodir, repodir.ptr, path);
+ error = git_str_joinpath(&repodir, repodir.ptr, path);
if (error < 0)
goto cleanup;
@@ -718,14 +721,57 @@ static int submodule_repo_init(
error = git_repository_init_ext(&subrepo, workdir.ptr, &initopt);
cleanup:
- git_buf_dispose(&workdir);
- git_buf_dispose(&repodir);
+ git_str_dispose(&workdir);
+ git_str_dispose(&repodir);
*out = subrepo;
return error;
}
+static int git_submodule__resolve_url(
+ git_str *out,
+ git_repository *repo,
+ const char *url)
+{
+ int error = 0;
+ git_str normalized = GIT_STR_INIT;
+
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(url);
+
+ /* We do this in all platforms in case someone on Windows created the .gitmodules */
+ if (strchr(url, '\\')) {
+ if ((error = git_path_normalize_slashes(&normalized, url)) < 0)
+ return error;
+
+ url = normalized.ptr;
+ }
+
+
+ if (git_path_is_relative(url)) {
+ if (!(error = get_url_base(out, repo)))
+ error = git_path_apply_relative(out, url);
+ } else if (strchr(url, ':') != NULL || url[0] == '/') {
+ error = git_str_sets(out, url);
+ } else {
+ git_error_set(GIT_ERROR_SUBMODULE, "invalid format for submodule URL");
+ error = -1;
+ }
+
+ git_str_dispose(&normalized);
+ return error;
+}
+
+int git_submodule_resolve_url(
+ git_buf *out,
+ git_repository *repo,
+ const char *url)
+{
+ GIT_BUF_WRAP_PRIVATE(out, git_submodule__resolve_url, repo, url);
+}
+
int git_submodule_add_setup(
git_submodule **out,
git_repository *repo,
@@ -736,7 +782,7 @@ int git_submodule_add_setup(
int error = 0;
git_config_backend *mods = NULL;
git_submodule *sm = NULL;
- git_buf name = GIT_BUF_INIT, real_url = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT, real_url = GIT_STR_INIT;
git_repository *subrepo = NULL;
bool path_occupied;
@@ -781,7 +827,7 @@ int git_submodule_add_setup(
return -1;
}
- if ((error = git_buf_printf(&name, "submodule.%s.path", path)) < 0 ||
+ if ((error = git_str_printf(&name, "submodule.%s.path", path)) < 0 ||
(error = git_config_backend_set_string(mods, name.ptr, path)) < 0)
goto cleanup;
@@ -789,7 +835,7 @@ int git_submodule_add_setup(
(error = git_config_backend_set_string(mods, name.ptr, url)) < 0)
goto cleanup;
- git_buf_clear(&name);
+ git_str_clear(&name);
/* init submodule repository and add origin remote as needed */
@@ -804,7 +850,7 @@ int git_submodule_add_setup(
git_path_contains(&name, DOT_GIT))) {
/* resolve the actual URL to use */
- if ((error = git_submodule_resolve_url(&real_url, repo, url)) < 0)
+ if ((error = git_submodule__resolve_url(&real_url, repo, url)) < 0)
goto cleanup;
if ((error = submodule_repo_init(&subrepo, repo, path, real_url.ptr, use_gitlink)) < 0)
@@ -826,8 +872,8 @@ cleanup:
git_config_backend_free(mods);
git_repository_free(subrepo);
- git_buf_dispose(&real_url);
- git_buf_dispose(&name);
+ git_str_dispose(&real_url);
+ git_str_dispose(&name);
return error;
}
@@ -841,13 +887,13 @@ int git_submodule_repo_init(
git_repository *sub_repo = NULL;
const char *configured_url;
git_config *cfg = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(sm);
/* get the configured remote url of the submodule */
- if ((error = git_buf_printf(&buf, "submodule.%s.url", sm->name)) < 0 ||
+ if ((error = git_str_printf(&buf, "submodule.%s.url", sm->name)) < 0 ||
(error = git_repository_config_snapshot(&cfg, sm->repo)) < 0 ||
(error = git_config_get_string(&configured_url, cfg, buf.ptr)) < 0 ||
(error = submodule_repo_init(&sub_repo, sm->repo, sm->path, configured_url, use_gitlink)) < 0)
@@ -857,7 +903,7 @@ int git_submodule_repo_init(
done:
git_config_free(cfg);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
@@ -881,7 +927,7 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
{
int error;
git_repository *clone;
- git_buf rel_path = GIT_BUF_INIT;
+ git_str rel_path = GIT_STR_INIT;
git_submodule_update_options sub_opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
@@ -903,7 +949,7 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
if (error < 0)
goto cleanup;
- error = git_clone__submodule(&clone, git_submodule_url(submodule), git_buf_cstr(&rel_path), &opts);
+ error = git_clone__submodule(&clone, git_submodule_url(submodule), git_str_cstr(&rel_path), &opts);
if (error < 0)
goto cleanup;
@@ -913,7 +959,7 @@ int git_submodule_clone(git_repository **out, git_submodule *submodule, const gi
*out = clone;
cleanup:
- git_buf_dispose(&rel_path);
+ git_str_dispose(&rel_path);
return error;
}
@@ -937,7 +983,7 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
int error;
git_repository *sm_repo = NULL;
git_index *index;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_commit *head;
git_index_entry entry;
struct stat st;
@@ -997,7 +1043,7 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
cleanup:
git_repository_free(sm_repo);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -1034,44 +1080,9 @@ const char *git_submodule_url(git_submodule *submodule)
return submodule->url;
}
-int git_submodule_resolve_url(git_buf *out, git_repository *repo, const char *url)
-{
- int error = 0;
- git_buf normalized = GIT_BUF_INIT;
-
- GIT_ASSERT_ARG(out);
- GIT_ASSERT_ARG(repo);
- GIT_ASSERT_ARG(url);
-
- if ((error = git_buf_sanitize(out)) < 0)
- return error;
-
- /* We do this in all platforms in case someone on Windows created the .gitmodules */
- if (strchr(url, '\\')) {
- if ((error = git_path_normalize_slashes(&normalized, url)) < 0)
- return error;
-
- url = normalized.ptr;
- }
-
-
- if (git_path_is_relative(url)) {
- if (!(error = get_url_base(out, repo)))
- error = git_path_apply_relative(out, url);
- } else if (strchr(url, ':') != NULL || url[0] == '/') {
- error = git_buf_sets(out, url);
- } else {
- git_error_set(GIT_ERROR_SUBMODULE, "invalid format for submodule URL");
- error = -1;
- }
-
- git_buf_dispose(&normalized);
- return error;
-}
-
static int write_var(git_repository *repo, const char *name, const char *var, const char *val)
{
- git_buf key = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT;
git_config_backend *mods;
int error;
@@ -1079,7 +1090,7 @@ static int write_var(git_repository *repo, const char *name, const char *var, co
if (!mods)
return -1;
- if ((error = git_buf_printf(&key, "submodule.%s.%s", name, var)) < 0)
+ if ((error = git_str_printf(&key, "submodule.%s.%s", name, var)) < 0)
goto cleanup;
if (val)
@@ -1087,7 +1098,7 @@ static int write_var(git_repository *repo, const char *name, const char *var, co
else
error = git_config_backend_delete(mods, key.ptr);
- git_buf_dispose(&key);
+ git_str_dispose(&key);
cleanup:
git_config_backend_free(mods);
@@ -1227,7 +1238,7 @@ static int submodule_repo_create(
const char *path)
{
int error = 0;
- git_buf workdir = GIT_BUF_INIT, repodir = GIT_BUF_INIT;
+ git_str workdir = GIT_STR_INIT, repodir = GIT_STR_INIT;
git_repository_init_options initopt = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_repository *subrepo = NULL;
@@ -1249,18 +1260,18 @@ static int submodule_repo_create(
* <repo-dir>/modules/<name>/ with a gitlink in the
* sub-repo workdir directory to that repository.
*/
- error = git_repository_item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
+ error = git_repository__item_path(&repodir, parent_repo, GIT_REPOSITORY_ITEM_MODULES);
if (error < 0)
goto cleanup;
- error = git_buf_joinpath(&repodir, repodir.ptr, path);
+ error = git_str_joinpath(&repodir, repodir.ptr, path);
if (error < 0)
goto cleanup;
error = git_repository_init_ext(&subrepo, repodir.ptr, &initopt);
cleanup:
- git_buf_dispose(&workdir);
- git_buf_dispose(&repodir);
+ git_str_dispose(&workdir);
+ git_str_dispose(&repodir);
*out = subrepo;
@@ -1309,7 +1320,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
git_repository *sub_repo = NULL;
git_remote *remote = NULL;
git_object *target_commit = NULL;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
git_clone_options clone_options = GIT_CLONE_OPTIONS_INIT;
@@ -1337,10 +1348,10 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
* info has been copied into .git/config
*/
if ((error = git_repository_config_snapshot(&config, sm->repo)) < 0 ||
- (error = git_buf_printf(&buf, "submodule.%s.url", git_submodule_name(sm))) < 0)
+ (error = git_str_printf(&buf, "submodule.%s.url", git_submodule_name(sm))) < 0)
goto done;
- if ((error = git_config_get_string(&submodule_url, config, git_buf_cstr(&buf))) < 0) {
+ if ((error = git_config_get_string(&submodule_url, config, git_str_cstr(&buf))) < 0) {
/*
* If the error is not "not found" or if it is "not found" and we are not
* initializing the submodule, then return error.
@@ -1362,7 +1373,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
config = NULL;
if ((error = git_repository_config_snapshot(&config, sm->repo)) < 0 ||
- (error = git_config_get_string(&submodule_url, config, git_buf_cstr(&buf))) < 0)
+ (error = git_config_get_string(&submodule_url, config, git_str_cstr(&buf))) < 0)
goto done;
}
@@ -1420,7 +1431,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
}
done:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_config_free(config);
git_object_free(target_commit);
git_remote_free(remote);
@@ -1433,7 +1444,7 @@ int git_submodule_init(git_submodule *sm, int overwrite)
{
int error;
const char *val;
- git_buf key = GIT_BUF_INIT, effective_submodule_url = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT, effective_submodule_url = GIT_STR_INIT;
git_config *cfg = NULL;
if (!sm->url) {
@@ -1447,8 +1458,8 @@ int git_submodule_init(git_submodule *sm, int overwrite)
/* write "submodule.NAME.url" */
- if ((error = git_submodule_resolve_url(&effective_submodule_url, sm->repo, sm->url)) < 0 ||
- (error = git_buf_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
+ if ((error = git_submodule__resolve_url(&effective_submodule_url, sm->repo, sm->url)) < 0 ||
+ (error = git_str_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
(error = git_config__update_entry(
cfg, key.ptr, effective_submodule_url.ptr, overwrite != 0, false)) < 0)
goto cleanup;
@@ -1458,7 +1469,7 @@ int git_submodule_init(git_submodule *sm, int overwrite)
val = (sm->update == GIT_SUBMODULE_UPDATE_CHECKOUT) ?
NULL : submodule_update_to_str(sm->update);
- if ((error = git_buf_printf(&key, "submodule.%s.update", sm->name)) < 0 ||
+ if ((error = git_str_printf(&key, "submodule.%s.update", sm->name)) < 0 ||
(error = git_config__update_entry(
cfg, key.ptr, val, overwrite != 0, false)) < 0)
goto cleanup;
@@ -1467,15 +1478,15 @@ int git_submodule_init(git_submodule *sm, int overwrite)
cleanup:
git_config_free(cfg);
- git_buf_dispose(&key);
- git_buf_dispose(&effective_submodule_url);
+ git_str_dispose(&key);
+ git_str_dispose(&effective_submodule_url);
return error;
}
int git_submodule_sync(git_submodule *sm)
{
- git_buf key = GIT_BUF_INIT, url = GIT_BUF_INIT, remote_name = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT, url = GIT_STR_INIT, remote_name = GIT_STR_INIT;
git_repository *smrepo = NULL;
git_config *cfg = NULL;
int error = 0;
@@ -1487,8 +1498,8 @@ int git_submodule_sync(git_submodule *sm)
/* copy URL over to config only if it already exists */
if ((error = git_repository_config__weakptr(&cfg, sm->repo)) < 0 ||
- (error = git_buf_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
- (error = git_submodule_resolve_url(&url, sm->repo, sm->url)) < 0 ||
+ (error = git_str_printf(&key, "submodule.%s.url", sm->name)) < 0 ||
+ (error = git_submodule__resolve_url(&url, sm->repo, sm->url)) < 0 ||
(error = git_config__update_entry(cfg, key.ptr, url.ptr, true, true)) < 0)
goto out;
@@ -1501,9 +1512,9 @@ int git_submodule_sync(git_submodule *sm)
goto out;
if (lookup_head_remote_key(&remote_name, smrepo) == 0) {
- if ((error = git_buf_join3(&key, '.', "remote", remote_name.ptr, "url")) < 0)
+ if ((error = git_str_join3(&key, '.', "remote", remote_name.ptr, "url")) < 0)
goto out;
- } else if ((error = git_buf_sets(&key, "remote.origin.url")) < 0) {
+ } else if ((error = git_str_sets(&key, "remote.origin.url")) < 0) {
goto out;
}
@@ -1512,9 +1523,9 @@ int git_submodule_sync(git_submodule *sm)
out:
git_repository_free(smrepo);
- git_buf_dispose(&remote_name);
- git_buf_dispose(&key);
- git_buf_dispose(&url);
+ git_str_dispose(&remote_name);
+ git_str_dispose(&key);
+ git_str_dispose(&url);
return error;
}
@@ -1522,7 +1533,7 @@ static int git_submodule__open(
git_repository **subrepo, git_submodule *sm, bool bare)
{
int error;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
unsigned int flags = GIT_REPOSITORY_OPEN_NO_SEARCH;
const char *wd;
@@ -1535,7 +1546,7 @@ static int git_submodule__open(
wd = git_repository_workdir(sm->repo);
- if (git_buf_join3(&path, '/', wd, sm->path, DOT_GIT) < 0)
+ if (git_str_join3(&path, '/', wd, sm->path, DOT_GIT) < 0)
return -1;
sm->flags = sm->flags &
@@ -1561,13 +1572,13 @@ static int git_submodule__open(
sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED |
GIT_SUBMODULE_STATUS_IN_WD;
} else {
- git_buf_rtruncate_at_char(&path, '/'); /* remove "/.git" */
+ git_str_rtruncate_at_char(&path, '/'); /* remove "/.git" */
if (git_path_isdir(path.ptr))
sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED;
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -1921,13 +1932,13 @@ static int submodule_parse_recurse(git_submodule_recurse_t *out, const char *val
return 0;
}
-static int get_value(const char **out, git_config *cfg, git_buf *buf, const char *name, const char *field)
+static int get_value(const char **out, git_config *cfg, git_str *buf, const char *name, const char *field)
{
int error;
- git_buf_clear(buf);
+ git_str_clear(buf);
- if ((error = git_buf_printf(buf, "submodule.%s.%s", name, field)) < 0 ||
+ if ((error = git_str_printf(buf, "submodule.%s.%s", name, field)) < 0 ||
(error = git_config_get_string(out, cfg, buf->ptr)) < 0)
return error;
@@ -1944,7 +1955,7 @@ static bool looks_like_command_line_option(const char *s)
static int submodule_read_config(git_submodule *sm, git_config *cfg)
{
- git_buf key = GIT_BUF_INIT;
+ git_str key = GIT_STR_INIT;
const char *value;
int error, in_config = 0;
@@ -2025,7 +2036,7 @@ static int submodule_read_config(git_submodule *sm, git_config *cfg)
error = 0;
cleanup:
- git_buf_dispose(&key);
+ git_str_dispose(&key);
return error;
}
@@ -2034,7 +2045,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
lfc_data *data = payload;
const char *namestart, *property;
git_strmap *map = data->map;
- git_buf name = GIT_BUF_INIT;
+ git_str name = GIT_STR_INIT;
git_submodule *sm;
int error, isvalid;
@@ -2049,7 +2060,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
property++;
- if ((error = git_buf_set(&name, namestart, property - namestart -1)) < 0)
+ if ((error = git_str_set(&name, namestart, property - namestart -1)) < 0)
return error;
isvalid = git_submodule_name_is_valid(data->repo, name.ptr, 0);
@@ -2083,13 +2094,13 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
error = 0;
done:
- git_buf_dispose(&name);
+ git_str_dispose(&name);
return error;
}
static int submodule_load_from_wd_lite(git_submodule *sm)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
if (git_repository_workdir_path(&path, sm->repo, sm->path) < 0)
return -1;
@@ -2100,7 +2111,7 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
if (git_path_contains(&path, DOT_GIT))
sm->flags |= GIT_SUBMODULE_STATUS_IN_WD;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return 0;
}
@@ -2112,7 +2123,7 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
static int gitmodules_snapshot(git_config **snap, git_repository *repo)
{
git_config *mods = NULL;
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
int error;
if (git_repository_workdir(repo) == NULL)
@@ -2123,7 +2134,7 @@ static int gitmodules_snapshot(git_config **snap, git_repository *repo)
if ((error = git_config_open_ondisk(&mods, path.ptr)) < 0)
goto cleanup;
- git_buf_dispose(&path);
+ git_str_dispose(&path);
if ((error = git_config_snapshot(snap, mods)) < 0)
goto cleanup;
@@ -2133,7 +2144,7 @@ static int gitmodules_snapshot(git_config **snap, git_repository *repo)
cleanup:
if (mods)
git_config_free(mods);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return error;
}
@@ -2142,7 +2153,7 @@ static git_config_backend *open_gitmodules(
git_repository *repo,
int okay_to_create)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
git_config_backend *mods = NULL;
if (git_repository_workdir(repo) != NULL) {
@@ -2161,17 +2172,17 @@ static git_config_backend *open_gitmodules(
}
}
- git_buf_dispose(&path);
+ git_str_dispose(&path);
return mods;
}
/* Lookup name of remote of the local tracking branch HEAD points to */
-static int lookup_head_remote_key(git_buf *remote_name, git_repository *repo)
+static int lookup_head_remote_key(git_str *remote_name, git_repository *repo)
{
int error;
git_reference *head = NULL;
- git_buf upstream_name = GIT_BUF_INIT;
+ git_str upstream_name = GIT_STR_INIT;
/* lookup and dereference HEAD */
if ((error = git_repository_head(&head, repo)) < 0)
@@ -2190,18 +2201,18 @@ static int lookup_head_remote_key(git_buf *remote_name, git_repository *repo)
}
/* lookup remote tracking branch of HEAD */
- if ((error = git_branch_upstream_name(
+ if ((error = git_branch__upstream_name(
&upstream_name,
repo,
git_reference_name(head))) < 0)
goto done;
/* lookup remote of remote tracking branch */
- if ((error = git_branch_remote_name(remote_name, repo, upstream_name.ptr)) < 0)
+ if ((error = git_branch__remote_name(remote_name, repo, upstream_name.ptr)) < 0)
goto done;
done:
- git_buf_dispose(&upstream_name);
+ git_str_dispose(&upstream_name);
git_reference_free(head);
return error;
@@ -2211,13 +2222,13 @@ done:
static int lookup_head_remote(git_remote **remote, git_repository *repo)
{
int error;
- git_buf remote_name = GIT_BUF_INIT;
+ git_str remote_name = GIT_STR_INIT;
/* lookup remote of remote tracking branch name */
if (!(error = lookup_head_remote_key(&remote_name, repo)))
error = git_remote_lookup(remote, repo, remote_name.ptr);
- git_buf_dispose(&remote_name);
+ git_str_dispose(&remote_name);
return error;
}
@@ -2240,14 +2251,14 @@ static int lookup_default_remote(git_remote **remote, git_repository *repo)
return error;
}
-static int get_url_base(git_buf *url, git_repository *repo)
+static int get_url_base(git_str *url, git_repository *repo)
{
int error;
git_worktree *wt = NULL;
git_remote *remote = NULL;
if ((error = lookup_default_remote(&remote, repo)) == 0) {
- error = git_buf_sets(url, git_remote_url(remote));
+ error = git_str_sets(url, git_remote_url(remote));
goto out;
} else if (error != GIT_ENOTFOUND)
goto out;
@@ -2258,9 +2269,9 @@ static int get_url_base(git_buf *url, git_repository *repo)
if (git_repository_is_worktree(repo)) {
if ((error = git_worktree_open_from_repository(&wt, repo)) < 0)
goto out;
- error = git_buf_sets(url, wt->parent_path);
+ error = git_str_sets(url, wt->parent_path);
} else {
- error = git_buf_sets(url, git_repository_workdir(repo));
+ error = git_str_sets(url, git_repository_workdir(repo));
}
out: