From: Junio C Hamano Date: Fri, 2 Jun 2017 06:05:58 +0000 (+0900) Subject: Merge branch 'js/bs-is-a-dir-sep-on-windows' X-Git-Tag: v2.14.0-rc0~134 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7d26aa32309a2a5979c4ae4b85b25b20e8aae0d4?ds=inline;hp=-c Merge branch 'js/bs-is-a-dir-sep-on-windows' "foo\bar\baz" in "git fetch foo\bar\baz", even though there is no slashes in it, cannot be a nickname for a remote on Windows, as that is likely to be a pathname on a local filesystem. * js/bs-is-a-dir-sep-on-windows: Windows: do not treat a path with backslashes as a remote's nick name mingw.h: permit arguments with side effects for is_dir_sep --- 7d26aa32309a2a5979c4ae4b85b25b20e8aae0d4 diff --combined compat/mingw.h index 3350169555,d2168c1e5e..e03aecfe2e --- a/compat/mingw.h +++ b/compat/mingw.h @@@ -384,9 -384,6 +384,9 @@@ int mingw_raise(int sig) * ANSI emulation wrappers */ +int winansi_isatty(int fd); +#define isatty winansi_isatty + void winansi_init(void); HANDLE winansi_get_osfhandle(int fd); @@@ -398,7 -395,11 +398,11 @@@ (isalpha(*(path)) && (path)[1] == ':' ? 2 : 0) int mingw_skip_dos_drive_prefix(char **path); #define skip_dos_drive_prefix mingw_skip_dos_drive_prefix - #define is_dir_sep(c) ((c) == '/' || (c) == '\\') + static inline int mingw_is_dir_sep(int c) + { + return c == '/' || c == '\\'; + } + #define is_dir_sep mingw_is_dir_sep static inline char *mingw_find_last_dir_sep(const char *path) { char *ret = NULL; diff --combined remote.c index fdc52d802c,1949882c10..e43b1460f8 --- a/remote.c +++ b/remote.c @@@ -255,7 -255,6 +255,7 @@@ static void read_remotes_file(struct re if (!f) return; + remote->configured_in_repo = 1; remote->origin = REMOTE_REMOTES; while (strbuf_getline(&buf, f) != EOF) { const char *v; @@@ -290,7 -289,6 +290,7 @@@ static void read_branches_file(struct r return; } + remote->configured_in_repo = 1; remote->origin = REMOTE_BRANCHES; /* @@@ -373,8 -371,6 +373,8 @@@ static int handle_config(const char *ke } remote = make_remote(name, namelen); remote->origin = REMOTE_CONFIG; + if (current_config_scope() == CONFIG_SCOPE_REPO) + remote->configured_in_repo = 1; if (!strcmp(subkey, "mirror")) remote->mirror = git_config_bool(key, value); else if (!strcmp(subkey, "skipdefaultupdate")) @@@ -630,7 -626,7 +630,7 @@@ struct refspec *parse_fetch_refspec(in return parse_refspec_internal(nr_refspec, refspec, 1, 0); } -static struct refspec *parse_push_refspec(int nr_refspec, const char **refspec) +struct refspec *parse_push_refspec(int nr_refspec, const char **refspec) { return parse_refspec_internal(nr_refspec, refspec, 0, 0); } @@@ -649,7 -645,12 +649,12 @@@ static int valid_remote_nick(const cha { if (!name[0] || is_dot_or_dotdot(name)) return 0; - return !strchr(name, '/'); /* no slash */ + + /* remote nicknames cannot contain slashes */ + while (*name) + if (is_dir_sep(*name++)) + return 0; + return 1; } const char *remote_for_branch(struct branch *branch, int *explicit) @@@ -693,7 -694,7 +698,7 @@@ static struct remote *remote_get_1(cons name = get_default(current_branch, &name_given); ret = make_remote(name, 0); - if (valid_remote_nick(name)) { + if (valid_remote_nick(name) && have_git_dir()) { if (!valid_remote(ret)) read_remotes_file(ret); if (!valid_remote(ret)) @@@ -718,13 -719,9 +723,13 @@@ struct remote *pushremote_get(const cha return remote_get_1(name, pushremote_for_branch); } -int remote_is_configured(struct remote *remote) +int remote_is_configured(struct remote *remote, int in_repo) { - return remote && remote->origin; + if (!remote) + return 0; + if (in_repo) + return remote->configured_in_repo; + return !!remote->origin; } int for_each_remote(each_remote_fn fn, void *priv) @@@ -1191,10 -1188,9 +1196,10 @@@ static int match_explicit(struct ref *s else if (is_null_oid(&matched_src->new_oid)) error("unable to delete '%s': remote ref does not exist", dst_value); - else if ((dst_guess = guess_ref(dst_value, matched_src))) + else if ((dst_guess = guess_ref(dst_value, matched_src))) { matched_dst = make_linked_ref(dst_guess, dst_tail); - else + free(dst_guess); + } else error("unable to push to unqualified destination: %s\n" "The destination refspec neither matches an " "existing ref on the remote nor\n" @@@ -1297,7 -1293,7 +1302,7 @@@ static void add_to_tips(struct tips *ti if (is_null_oid(oid)) return; - commit = lookup_commit_reference_gently(oid->hash, 1); + commit = lookup_commit_reference_gently(oid, 1); if (!commit || (commit->object.flags & TMP_MARK)) return; commit->object.flags |= TMP_MARK; @@@ -1359,8 -1355,7 +1364,8 @@@ static void add_missing_tags(struct re if (is_null_oid(&ref->new_oid)) continue; - commit = lookup_commit_reference_gently(ref->new_oid.hash, 1); + commit = lookup_commit_reference_gently(&ref->new_oid, + 1); if (!commit) /* not pushing a commit, which is not an error */ continue; @@@ -1587,8 -1582,8 +1592,8 @@@ void set_ref_status_for_push(struct re reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS; else if (!has_object_file(&ref->old_oid)) reject_reason = REF_STATUS_REJECT_FETCH_FIRST; - else if (!lookup_commit_reference_gently(ref->old_oid.hash, 1) || - !lookup_commit_reference_gently(ref->new_oid.hash, 1)) + else if (!lookup_commit_reference_gently(&ref->old_oid, 1) || + !lookup_commit_reference_gently(&ref->new_oid, 1)) reject_reason = REF_STATUS_REJECT_NEEDS_FORCE; else if (!ref_newer(&ref->new_oid, &ref->old_oid)) reject_reason = REF_STATUS_REJECT_NONFASTFORWARD; @@@ -1726,6 -1721,9 +1731,6 @@@ static const char *branch_get_push_1(st { struct remote *remote; - if (!branch) - return error_buf(err, _("HEAD does not point to a branch")); - remote = remote_get(pushremote_for_branch(branch, NULL)); if (!remote) return error_buf(err, @@@ -1785,9 -1783,6 +1790,9 @@@ const char *branch_get_push(struct branch *branch, struct strbuf *err) { + if (!branch) + return error_buf(err, _("HEAD does not point to a branch")); + if (!branch->push_tracking_ref) branch->push_tracking_ref = branch_get_push_1(branch, err); return branch->push_tracking_ref; @@@ -1955,12 -1950,12 +1960,12 @@@ int ref_newer(const struct object_id *n * Both new and old must be commit-ish and new is descendant of * old. Otherwise we require --force. */ - o = deref_tag(parse_object(old_oid->hash), NULL, 0); + o = deref_tag(parse_object(old_oid), NULL, 0); if (!o || o->type != OBJ_COMMIT) return 0; old = (struct commit *) o; - o = deref_tag(parse_object(new_oid->hash), NULL, 0); + o = deref_tag(parse_object(new_oid), NULL, 0); if (!o || o->type != OBJ_COMMIT) return 0; new = (struct commit *) o; @@@ -2011,13 -2006,13 +2016,13 @@@ int stat_tracking_info(struct branch *b /* Cannot stat if what we used to build on no longer exists */ if (read_ref(base, oid.hash)) return -1; - theirs = lookup_commit_reference(oid.hash); + theirs = lookup_commit_reference(&oid); if (!theirs) return -1; if (read_ref(branch->refname, oid.hash)) return -1; - ours = lookup_commit_reference(oid.hash); + ours = lookup_commit_reference(&oid); if (!ours) return -1; @@@ -2281,7 -2276,7 +2286,7 @@@ static struct push_cas *add_cas_entry(s return entry; } -int parse_push_cas_option(struct push_cas_option *cas, const char *arg, int unset) +static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, int unset) { const char *colon; struct push_cas *entry;