diff options
Diffstat (limited to 'builtin/remote.c')
| -rw-r--r-- | builtin/remote.c | 109 |
1 files changed, 66 insertions, 43 deletions
diff --git a/builtin/remote.c b/builtin/remote.c index 0435963286..8961ae6a89 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -14,7 +14,7 @@ #include "rebase.h" #include "refs.h" #include "refspec.h" -#include "object-store-ll.h" +#include "odb.h" #include "strvec.h" #include "commit-reach.h" #include "progress.h" @@ -132,7 +132,7 @@ static void add_branch(const char *key, const char *branchname, else strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s", branchname, remotename, branchname); - git_config_set_multivar(key, tmp->buf, "^$", 0); + repo_config_set_multivar(the_repository, key, tmp->buf, "^$", 0); } static const char mirror_advice[] = @@ -157,6 +157,21 @@ static int parse_mirror_opt(const struct option *opt, const char *arg, int not) return 0; } +static int check_remote_collision(struct remote *remote, void *data) +{ + const char *name = data; + const char *p; + + if (skip_prefix(name, remote->name, &p) && *p == '/') + die(_("remote name '%s' is a subset of existing remote '%s'"), + name, remote->name); + if (skip_prefix(remote->name, name, &p) && *p == '/') + die(_("remote name '%s' is a superset of existing remote '%s'"), + name, remote->name); + + return 0; +} + static int add(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) { @@ -208,8 +223,10 @@ static int add(int argc, const char **argv, const char *prefix, if (!valid_remote_name(name)) die(_("'%s' is not a valid remote name"), name); + for_each_remote(check_remote_collision, (void *)name); + strbuf_addf(&buf, "remote.%s.url", name); - git_config_set(buf.buf, url); + repo_config_set(the_repository, buf.buf, url); if (!mirror || mirror & MIRROR_FETCH) { strbuf_reset(&buf); @@ -225,14 +242,14 @@ static int add(int argc, const char **argv, const char *prefix, if (mirror & MIRROR_PUSH) { strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.mirror", name); - git_config_set(buf.buf, "true"); + repo_config_set(the_repository, buf.buf, "true"); } if (fetch_tags != TAGS_DEFAULT) { strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.tagOpt", name); - git_config_set(buf.buf, - fetch_tags == TAGS_SET ? "--tags" : "--no-tags"); + repo_config_set(the_repository, buf.buf, + fetch_tags == TAGS_SET ? "--tags" : "--no-tags"); } if (fetch && fetch_remote(name)) { @@ -353,7 +370,7 @@ static void read_branches(void) { if (branch_list.nr) return; - git_config(config_read_branches, NULL); + repo_config(the_repository, config_read_branches, NULL); } struct ref_states { @@ -383,7 +400,7 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat states->remote->fetch.items[i].raw); for (ref = fetch_map; ref; ref = ref->next) { - if (omit_name_by_refspec(ref->name, &states->remote->fetch)) + if (refname_matches_negative_refspec_item(ref->name, &states->remote->fetch)) string_list_append(&states->skipped, abbrev_branch(ref->name)); else if (!ref->peer_ref || !refs_ref_exists(get_main_ref_store(the_repository), ref->peer_ref->name)) string_list_append(&states->new_refs, abbrev_branch(ref->name)); @@ -454,7 +471,8 @@ static int get_push_ref_states(const struct ref *remote_refs, info->status = PUSH_STATUS_UPTODATE; else if (is_null_oid(&ref->old_oid)) info->status = PUSH_STATUS_CREATE; - else if (repo_has_object_file(the_repository, &ref->old_oid) && + else if (odb_has_object(the_repository->objects, &ref->old_oid, + HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR) && ref_newer(&ref->new_oid, &ref->old_oid)) info->status = PUSH_STATUS_FASTFORWARD; else @@ -511,7 +529,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0); matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"), - fetch_map, 1); + fetch_map, REMOTE_GUESS_HEAD_ALL); for (ref = matches; ref; ref = ref->next) string_list_append(&states->heads, abbrev_branch(ref->name)); @@ -633,19 +651,23 @@ static int migrate_file(struct remote *remote) strbuf_addf(&buf, "remote.%s.url", remote->name); for (i = 0; i < remote->url.nr; i++) - git_config_set_multivar(buf.buf, remote->url.v[i], "^$", 0); + repo_config_set_multivar(the_repository, buf.buf, remote->url.v[i], "^$", 0); strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.push", remote->name); for (i = 0; i < remote->push.nr; i++) - git_config_set_multivar(buf.buf, remote->push.items[i].raw, "^$", 0); + repo_config_set_multivar(the_repository, buf.buf, remote->push.items[i].raw, "^$", 0); strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", remote->name); for (i = 0; i < remote->fetch.nr; i++) - git_config_set_multivar(buf.buf, remote->fetch.items[i].raw, "^$", 0); + repo_config_set_multivar(the_repository, buf.buf, remote->fetch.items[i].raw, "^$", 0); +#ifndef WITH_BREAKING_CHANGES if (remote->origin == REMOTE_REMOTES) - unlink_or_warn(git_path("remotes/%s", remote->name)); + unlink_or_warn(repo_git_path_replace(the_repository, &buf, + "remotes/%s", remote->name)); else if (remote->origin == REMOTE_BRANCHES) - unlink_or_warn(git_path("branches/%s", remote->name)); + unlink_or_warn(repo_git_path_replace(the_repository, &buf, + "branches/%s", remote->name)); +#endif /* WITH_BREAKING_CHANGES */ strbuf_release(&buf); return 0; @@ -685,12 +707,12 @@ static void handle_push_default(const char* old_name, const char* new_name) .origin = STRBUF_INIT, .linenr = -1, }; - git_config(config_read_push_default, &push_default); + repo_config(the_repository, config_read_push_default, &push_default); if (push_default.scope >= CONFIG_SCOPE_COMMAND) ; /* pass */ else if (push_default.scope >= CONFIG_SCOPE_LOCAL) { - int result = git_config_set_gently("remote.pushDefault", - new_name); + int result = repo_config_set_gently(the_repository, "remote.pushDefault", + new_name); if (new_name && result && result != CONFIG_NOTHING_SET) die(_("could not set '%s'"), "remote.pushDefault"); else if (!new_name && result && result != CONFIG_NOTHING_SET) @@ -766,7 +788,7 @@ static int mv(int argc, const char **argv, const char *prefix, if (oldremote->fetch.nr) { strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", rename.new_name); - git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); + repo_config_set_multivar(the_repository, buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name); for (i = 0; i < oldremote->fetch.nr; i++) { char *ptr; @@ -786,7 +808,7 @@ static int mv(int argc, const char **argv, const char *prefix, "\tPlease update the configuration manually if necessary."), buf2.buf); - git_config_set_multivar(buf.buf, buf2.buf, "^$", 0); + repo_config_set_multivar(the_repository, buf.buf, buf2.buf, "^$", 0); } } @@ -797,12 +819,12 @@ static int mv(int argc, const char **argv, const char *prefix, if (info->remote_name && !strcmp(info->remote_name, rename.old_name)) { strbuf_reset(&buf); strbuf_addf(&buf, "branch.%s.remote", item->string); - git_config_set(buf.buf, rename.new_name); + repo_config_set(the_repository, buf.buf, rename.new_name); } if (info->push_remote_name && !strcmp(info->push_remote_name, rename.old_name)) { strbuf_reset(&buf); strbuf_addf(&buf, "branch.%s.pushRemote", item->string); - git_config_set(buf.buf, rename.new_name); + repo_config_set(the_repository, buf.buf, rename.new_name); } } @@ -820,7 +842,8 @@ static int mv(int argc, const char **argv, const char *prefix, * Count symrefs twice, since "renaming" them is done by * deleting and recreating them in two separate passes. */ - progress = start_progress(_("Renaming remote references"), + progress = start_progress(the_repository, + _("Renaming remote references"), rename.remote_branches->nr + rename.symrefs_nr); } for (i = 0; i < remote_branches.nr; i++) { @@ -928,7 +951,7 @@ static int rm(int argc, const char **argv, const char *prefix, strbuf_reset(&buf); strbuf_addf(&buf, "branch.%s.%s", item->string, *k); - result = git_config_set_gently(buf.buf, NULL); + result = repo_config_set_gently(the_repository, buf.buf, NULL); if (result && result != CONFIG_NOTHING_SET) die(_("could not unset '%s'"), buf.buf); } @@ -936,7 +959,7 @@ static int rm(int argc, const char **argv, const char *prefix, if (info->push_remote_name && !strcmp(info->push_remote_name, remote->name)) { strbuf_reset(&buf); strbuf_addf(&buf, "branch.%s.pushremote", item->string); - result = git_config_set_gently(buf.buf, NULL); + result = repo_config_set_gently(the_repository, buf.buf, NULL); if (result && result != CONFIG_NOTHING_SET) die(_("could not unset '%s'"), buf.buf); } @@ -1262,7 +1285,7 @@ static int get_one_entry(struct remote *remote, void *priv) strbuf_addf(&promisor_config, "remote.%s.partialclonefilter", remote->name); strbuf_addf(&remote_info_buf, "%s (fetch)", remote->url.v[0]); - if (!git_config_get_string_tmp(promisor_config.buf, &partial_clone_filter)) + if (!repo_config_get_string_tmp(the_repository, promisor_config.buf, &partial_clone_filter)) strbuf_addf(&remote_info_buf, " [%s]", partial_clone_filter); strbuf_release(&promisor_config); @@ -1451,10 +1474,13 @@ static int set_head(int argc, const char **argv, const char *prefix, }; argc = parse_options(argc, argv, prefix, options, builtin_remote_sethead_usage, 0); - if (argc) { - strbuf_addf(&b_head, "refs/remotes/%s/HEAD", argv[0]); - remote = remote_get(argv[0]); - } + + /* All modes require at least a remote name. */ + if (!argc) + usage_with_options(builtin_remote_sethead_usage, options); + + strbuf_addf(&b_head, "refs/remotes/%s/HEAD", argv[0]); + remote = remote_get(argv[0]); if (!opt_a && !opt_d && argc == 2) { head_name = xstrdup(argv[1]); @@ -1497,7 +1523,7 @@ static int set_head(int argc, const char **argv, const char *prefix, struct strbuf config_name = STRBUF_INIT; strbuf_addf(&config_name, "remote.%s.followremotehead", remote->name); - git_config_set(config_name.buf, "warn"); + repo_config_set(the_repository, config_name.buf, "warn"); strbuf_release(&config_name); } @@ -1515,9 +1541,6 @@ static int prune_remote(const char *remote, int dry_run) struct ref_states states = REF_STATES_INIT; struct string_list refs_to_prune = STRING_LIST_INIT_NODUP; struct string_list_item *item; - const char *dangling_msg = dry_run - ? _(" %s will become dangling!") - : _(" %s has become dangling!"); get_remote_ref_states(remote, &states, GET_REF_STATES); @@ -1549,7 +1572,7 @@ static int prune_remote(const char *remote, int dry_run) } refs_warn_dangling_symrefs(get_main_ref_store(the_repository), - stdout, dangling_msg, &refs_to_prune); + stdout, " ", dry_run, &refs_to_prune); string_list_clear(&refs_to_prune, 0); free_remote_ref_states(&states); @@ -1617,7 +1640,7 @@ static int update(int argc, const char **argv, const char *prefix, strvec_push(&cmd.args, argv[i]); if (strcmp(cmd.args.v[cmd.args.nr-1], "default") == 0) { - git_config(get_remote_default, &default_defined); + repo_config(the_repository, get_remote_default, &default_defined); if (!default_defined) { strvec_pop(&cmd.args); strvec_push(&cmd.args, "--all"); @@ -1630,8 +1653,8 @@ static int update(int argc, const char **argv, const char *prefix, static int remove_all_fetch_refspecs(const char *key) { - return git_config_set_multivar_gently(key, NULL, NULL, - CONFIG_FLAGS_MULTI_REPLACE); + return repo_config_set_multivar_gently(the_repository, key, NULL, NULL, + CONFIG_FLAGS_MULTI_REPLACE); } static void add_branches(struct remote *remote, const char **branches, @@ -1787,10 +1810,10 @@ static int set_url(int argc, const char **argv, const char *prefix, /* Special cases that add new entry. */ if ((!oldurl && !delete_mode) || add_mode) { if (add_mode) - git_config_set_multivar(name_buf.buf, newurl, + repo_config_set_multivar(the_repository, name_buf.buf, newurl, "^$", 0); else - git_config_set(name_buf.buf, newurl); + repo_config_set(the_repository, name_buf.buf, newurl); goto out; } @@ -1811,10 +1834,10 @@ static int set_url(int argc, const char **argv, const char *prefix, regfree(&old_regex); if (!delete_mode) - git_config_set_multivar(name_buf.buf, newurl, oldurl, 0); + repo_config_set_multivar(the_repository, name_buf.buf, newurl, oldurl, 0); else - git_config_set_multivar(name_buf.buf, NULL, oldurl, - CONFIG_FLAGS_MULTI_REPLACE); + repo_config_set_multivar(the_repository, name_buf.buf, NULL, oldurl, + CONFIG_FLAGS_MULTI_REPLACE); out: strbuf_release(&name_buf); return 0; |
