diff options
Diffstat (limited to 'remote.c')
-rw-r--r-- | remote.c | 128 |
1 files changed, 65 insertions, 63 deletions
@@ -1,21 +1,27 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "remote.h" #include "urlmatch.h" #include "refs.h" #include "refspec.h" -#include "object-store.h" +#include "object-name.h" +#include "object-store-ll.h" +#include "path.h" #include "commit.h" #include "diff.h" #include "revision.h" #include "dir.h" -#include "tag.h" +#include "setup.h" #include "string-list.h" -#include "mergesort.h" #include "strvec.h" #include "commit-reach.h" #include "advice.h" #include "connect.h" +#include "parse-options.h" enum map_direction { FROM_SRC, FROM_DST }; @@ -87,7 +93,7 @@ struct remotes_hash_key { int len; }; -static int remotes_hash_cmp(const void *unused_cmp_data, +static int remotes_hash_cmp(const void *cmp_data UNUSED, const struct hashmap_entry *eptr, const struct hashmap_entry *entry_or_key, const void *keydata) @@ -99,7 +105,7 @@ static int remotes_hash_cmp(const void *unused_cmp_data, b = container_of(entry_or_key, const struct remote, ent); if (key) - return strncmp(a->name, key->str, key->len) || a->name[key->len]; + return !!xstrncmpz(a->name, key->str, key->len); else return strcmp(a->name, b->name); } @@ -171,7 +177,7 @@ struct branches_hash_key { int len; }; -static int branches_hash_cmp(const void *unused_cmp_data, +static int branches_hash_cmp(const void *cmp_data UNUSED, const struct hashmap_entry *eptr, const struct hashmap_entry *entry_or_key, const void *keydata) @@ -183,8 +189,7 @@ static int branches_hash_cmp(const void *unused_cmp_data, b = container_of(entry_or_key, const struct branch, ent); if (key) - return strncmp(a->name, key->str, key->len) || - a->name[key->len]; + return !!xstrncmpz(a->name, key->str, key->len); else return strcmp(a->name, b->name); } @@ -342,7 +347,8 @@ static void read_branches_file(struct remote_state *remote_state, remote->fetch_tags = 1; /* always auto-follow */ } -static int handle_config(const char *key, const char *value, void *cb) +static int handle_config(const char *key, const char *value, + const struct config_context *ctx, void *cb) { const char *name; size_t namelen; @@ -350,6 +356,7 @@ static int handle_config(const char *key, const char *value, void *cb) struct remote *remote; struct branch *branch; struct remote_state *remote_state = cb; + const struct key_value_info *kvi = ctx->kvi; if (parse_config_key(key, "branch", &name, &namelen, &subkey) >= 0) { /* There is no subsection. */ @@ -407,8 +414,8 @@ static int handle_config(const char *key, const char *value, void *cb) } remote = make_remote(remote_state, name, namelen); remote->origin = REMOTE_CONFIG; - if (current_config_scope() == CONFIG_SCOPE_LOCAL || - current_config_scope() == CONFIG_SCOPE_WORKTREE) + if (kvi->scope == CONFIG_SCOPE_LOCAL || + kvi->scope == CONFIG_SCOPE_WORKTREE) remote->configured_in_repo = 1; if (!strcmp(subkey, "mirror")) remote->mirror = git_config_bool(key, value); @@ -500,7 +507,7 @@ static void alias_all_urls(struct remote_state *remote_state) } } -static void read_config(struct repository *repo) +static void read_config(struct repository *repo, int early) { int flag; @@ -509,7 +516,7 @@ static void read_config(struct repository *repo) repo->remote_state->initialized = 1; repo->remote_state->current_branch = NULL; - if (startup_info->have_repository) { + if (startup_info->have_repository && !early) { const char *head_ref = refs_resolve_ref_unsafe( get_main_ref_store(repo), "HEAD", 0, NULL, &flag); if (head_ref && (flag & REF_ISSYMREF) && @@ -552,7 +559,7 @@ static const char *remotes_remote_for_branch(struct remote_state *remote_state, const char *remote_for_branch(struct branch *branch, int *explicit) { - read_config(the_repository); + read_config(the_repository, 0); die_on_missing_branch(the_repository, branch); return remotes_remote_for_branch(the_repository->remote_state, branch, @@ -578,7 +585,7 @@ remotes_pushremote_for_branch(struct remote_state *remote_state, const char *pushremote_for_branch(struct branch *branch, int *explicit) { - read_config(the_repository); + read_config(the_repository, 0); die_on_missing_branch(the_repository, branch); return remotes_pushremote_for_branch(the_repository->remote_state, @@ -590,7 +597,7 @@ static struct remote *remotes_remote_get(struct remote_state *remote_state, const char *remote_ref_for_branch(struct branch *branch, int for_push) { - read_config(the_repository); + read_config(the_repository, 0); die_on_missing_branch(the_repository, branch); if (branch) { @@ -700,7 +707,13 @@ remotes_remote_get(struct remote_state *remote_state, const char *name) struct remote *remote_get(const char *name) { - read_config(the_repository); + read_config(the_repository, 0); + return remotes_remote_get(the_repository->remote_state, name); +} + +struct remote *remote_get_early(const char *name) +{ + read_config(the_repository, 1); return remotes_remote_get(the_repository->remote_state, name); } @@ -713,7 +726,7 @@ remotes_pushremote_get(struct remote_state *remote_state, const char *name) struct remote *pushremote_get(const char *name) { - read_config(the_repository); + read_config(the_repository, 0); return remotes_pushremote_get(the_repository->remote_state, name); } @@ -729,7 +742,7 @@ int remote_is_configured(struct remote *remote, int in_repo) int for_each_remote(each_remote_fn fn, void *priv) { int i, result = 0; - read_config(the_repository); + read_config(the_repository, 0); for (i = 0; i < the_repository->remote_state->remotes_nr && !result; i++) { struct remote *remote = @@ -850,7 +863,7 @@ static int refspec_match(const struct refspec_item *refspec, return !strcmp(refspec->src, name); } -static int omit_name_by_refspec(const char *name, struct refspec *rs) +int omit_name_by_refspec(const char *name, struct refspec *rs) { int i; @@ -883,7 +896,7 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite { int i, matched_negative = 0; int find_src = !query->src; - struct string_list reversed = STRING_LIST_INIT_NODUP; + struct string_list reversed = STRING_LIST_INIT_DUP; const char *needle = find_src ? query->dst : query->src; /* @@ -1082,27 +1095,6 @@ void free_refs(struct ref *ref) } } -int ref_compare_name(const void *va, const void *vb) -{ - const struct ref *a = va, *b = vb; - return strcmp(a->name, b->name); -} - -static void *ref_list_get_next(const void *a) -{ - return ((const struct ref *)a)->next; -} - -static void ref_list_set_next(void *a, void *next) -{ - ((struct ref *)a)->next = next; -} - -void sort_ref_list(struct ref **l, int (*cmp)(const void *, const void *)) -{ - *l = llist_mergesort(*l, ref_list_get_next, ref_list_set_next, cmp); -} - int count_refspec_match(const char *pattern, struct ref *refs, struct ref **matched_ref) @@ -1185,7 +1177,7 @@ static int try_explicit_object_name(const char *name, return 0; } - if (get_oid(name, &oid)) + if (repo_get_oid(the_repository, name, &oid)) return -1; if (match) { @@ -1273,7 +1265,7 @@ static void show_push_unqualified_ref_name_error(const char *dst_value, if (!advice_enabled(ADVICE_PUSH_UNQUALIFIED_REF_NAME)) return; - if (get_oid(matched_src_name, &oid)) + if (repo_get_oid(the_repository, matched_src_name, &oid)) BUG("'%s' is not a valid object, " "match_explicit_lhs() should catch this!", matched_src_name); @@ -1781,7 +1773,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) { if (starts_with(ref->name, "refs/tags/")) reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS; - else if (!has_object_file(&ref->old_oid)) + else if (!repo_has_object_file(the_repository, &ref->old_oid)) reject_reason = REF_STATUS_REJECT_FETCH_FIRST; else if (!lookup_commit_reference_gently(the_repository, &ref->old_oid, 1) || !lookup_commit_reference_gently(the_repository, &ref->new_oid, 1)) @@ -1830,8 +1822,9 @@ static void set_merge(struct remote_state *remote_state, struct branch *ret) if (!remote_find_tracking(remote, ret->merge[i]) || strcmp(ret->remote_name, ".")) continue; - if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]), - &oid, &ref, 0) == 1) + if (repo_dwim_ref(the_repository, ret->merge_name[i], + strlen(ret->merge_name[i]), &oid, &ref, + 0) == 1) ret->merge[i]->dst = ref; else ret->merge[i]->dst = xstrdup(ret->merge_name[i]); @@ -1842,7 +1835,7 @@ struct branch *branch_get(const char *name) { struct branch *ret; - read_config(the_repository); + read_config(the_repository, 0); if (!name || !*name || !strcmp(name, "HEAD")) ret = the_repository->remote_state->current_branch; else @@ -1984,7 +1977,7 @@ static const char *branch_get_push_1(struct remote_state *remote_state, const char *branch_get_push(struct branch *branch, struct strbuf *err) { - read_config(the_repository); + read_config(the_repository, 0); die_on_missing_branch(the_repository, branch); if (!branch) @@ -2169,6 +2162,9 @@ static int stat_branch_pair(const char *branch_name, const char *base, struct object_id oid; struct commit *ours, *theirs; struct rev_info revs; + struct setup_revision_opt opt = { + .free_removed_argv_elements = 1, + }; struct strvec argv = STRVEC_INIT; /* Cannot stat if what we used to build on no longer exists */ @@ -2203,7 +2199,7 @@ static int stat_branch_pair(const char *branch_name, const char *base, strvec_push(&argv, "--"); repo_init_revisions(the_repository, &revs, NULL); - setup_revisions(argv.nr, argv.v, &revs, NULL); + setup_revisions(argv.nr, argv.v, &revs, &opt); if (prepare_revision_walk(&revs)) die(_("revision walk setup failed")); @@ -2267,7 +2263,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs, * Return true when there is anything to report, otherwise false. */ int format_tracking_info(struct branch *branch, struct strbuf *sb, - enum ahead_behind_flags abf) + enum ahead_behind_flags abf, + int show_divergence_advice) { int ours, theirs, sti; const char *full_base; @@ -2330,16 +2327,18 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb, "respectively.\n", ours + theirs), base, ours, theirs); - if (advice_enabled(ADVICE_STATUS_HINTS)) + if (show_divergence_advice && + advice_enabled(ADVICE_STATUS_HINTS)) strbuf_addstr(sb, - _(" (use \"git pull\" to merge the remote branch into yours)\n")); + _(" (use \"git pull\" if you want to integrate the remote branch with yours)\n")); } free(base); return 1; } static int one_local_ref(const char *refname, const struct object_id *oid, - int flag, void *cb_data) + int flag UNUSED, + void *cb_data) { struct ref ***local_tail = cb_data; struct ref *ref; @@ -2523,7 +2522,7 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i entry->use_tracking = 1; else if (!colon[1]) oidclr(&entry->expect); - else if (get_oid(colon + 1, &entry->expect)) + else if (repo_get_oid(the_repository, colon + 1, &entry->expect)) return error(_("cannot parse expected object name '%s'"), colon + 1); return 0; @@ -2595,19 +2594,22 @@ struct check_and_collect_until_cb_data { }; /* Get the timestamp of the latest entry. */ -static int peek_reflog(struct object_id *o_oid, struct object_id *n_oid, - const char *ident, timestamp_t timestamp, - int tz, const char *message, void *cb_data) +static int peek_reflog(struct object_id *o_oid UNUSED, + struct object_id *n_oid UNUSED, + const char *ident UNUSED, + timestamp_t timestamp, int tz UNUSED, + const char *message UNUSED, void *cb_data) { timestamp_t *ts = cb_data; *ts = timestamp; return 1; } -static int check_and_collect_until(struct object_id *o_oid, +static int check_and_collect_until(struct object_id *o_oid UNUSED, struct object_id *n_oid, - const char *ident, timestamp_t timestamp, - int tz, const char *message, void *cb_data) + const char *ident UNUSED, + timestamp_t timestamp, int tz UNUSED, + const char *message UNUSED, void *cb_data) { struct commit *commit; struct check_and_collect_until_cb_data *cb = cb_data; @@ -2677,7 +2679,7 @@ static int is_reachable_in_reflog(const char *local, const struct ref *remote) if (MERGE_BASES_BATCH_SIZE < size) size = MERGE_BASES_BATCH_SIZE; - if ((ret = in_merge_bases_many(commit, size, chunk))) + if ((ret = repo_in_merge_bases_many(the_repository, commit, size, chunk, 0))) break; } |