From: Junio C Hamano Date: Mon, 5 Jun 2017 00:18:13 +0000 (+0900) Subject: Merge branch 'jk/drop-free-refspecs' X-Git-Tag: v2.14.0-rc0~106 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/6e9b0108c6515510580da1698af893263f8cd7de?ds=inline;hp=-c Merge branch 'jk/drop-free-refspecs' Code clean-up. * jk/drop-free-refspecs: remote: drop free_refspecs() function --- 6e9b0108c6515510580da1698af893263f8cd7de diff --combined remote.c index e43b1460f8,fbb405660a..3649d60cdc --- a/remote.c +++ b/remote.c @@@ -477,26 -477,6 +477,6 @@@ static void read_config(void alias_all_urls(); } - /* - * This function frees a refspec array. - * Warning: code paths should be checked to ensure that the src - * and dst pointers are always freeable pointers as well - * as the refspec pointer itself. - */ - static void free_refspecs(struct refspec *refspec, int nr_refspec) - { - int i; - - if (!refspec) - return; - - for (i = 0; i < nr_refspec; i++) { - free(refspec[i].src); - free(refspec[i].dst); - } - free(refspec); - } - static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify) { int i; @@@ -610,7 -590,7 +590,7 @@@ * since it is only possible to reach this point from within * the for loop above. */ - free_refspecs(rs, i+1); + free_refspec(i+1, rs); return NULL; } die("Invalid refspec '%s'", refspec[i]); @@@ -621,7 -601,7 +601,7 @@@ int valid_fetch_refspec(const char *fet struct refspec *refspec; refspec = parse_refspec_internal(1, &fetch_refspec_str, 1, 1); - free_refspecs(refspec, 1); + free_refspec(1, refspec); return !!refspec; } @@@ -638,6 -618,10 +618,10 @@@ struct refspec *parse_push_refspec(int void free_refspec(int nr_refspec, struct refspec *refspec) { int i; + + if (!refspec) + return; + for (i = 0; i < nr_refspec; i++) { free(refspec[i].src); free(refspec[i].dst); @@@ -649,12 -633,7 +633,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) @@@ -1196,10 -1175,9 +1180,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" @@@ -1302,7 -1280,7 +1286,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; @@@ -1364,8 -1342,7 +1348,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; @@@ -1592,8 -1569,8 +1576,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; @@@ -1960,12 -1937,12 +1944,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; @@@ -2016,13 -1993,13 +2000,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;