Merge branch 'tb/connect-ipv6-parse-fix'
[gitweb.git] / remote.c
index ce785f8953bd8a51ef1c3ce57da5c8e7cce7cef5..68901b0070d257dc31b59e9292cd7b6d7ef2e952 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -508,7 +508,7 @@ static void read_config(void)
                return;
        default_remote_name = "origin";
        current_branch = NULL;
-       head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
+       head_ref = resolve_ref_unsafe("HEAD", 0, sha1, &flag);
        if (head_ref && (flag & REF_ISSYMREF) &&
            skip_prefix(head_ref, "refs/heads/", &head_ref)) {
                current_branch = make_branch(head_ref, 0);
@@ -975,8 +975,8 @@ struct ref *copy_ref(const struct ref *ref)
        cpy = xmalloc(sizeof(struct ref) + len + 1);
        memcpy(cpy, ref, sizeof(struct ref) + len + 1);
        cpy->next = NULL;
-       cpy->symref = ref->symref ? xstrdup(ref->symref) : NULL;
-       cpy->remote_status = ref->remote_status ? xstrdup(ref->remote_status) : NULL;
+       cpy->symref = xstrdup_or_null(ref->symref);
+       cpy->remote_status = xstrdup_or_null(ref->remote_status);
        cpy->peer_ref = copy_ref(ref->peer_ref);
        return cpy;
 }
@@ -1138,7 +1138,8 @@ static char *guess_ref(const char *name, struct ref *peer)
        struct strbuf buf = STRBUF_INIT;
        unsigned char sha1[20];
 
-       const char *r = resolve_ref_unsafe(peer->name, sha1, 1, NULL);
+       const char *r = resolve_ref_unsafe(peer->name, RESOLVE_REF_READING,
+                                          sha1, NULL);
        if (!r)
                return NULL;
 
@@ -1199,7 +1200,9 @@ static int match_explicit(struct ref *src, struct ref *dst,
                unsigned char sha1[20];
                int flag;
 
-               dst_value = resolve_ref_unsafe(matched_src->name, sha1, 1, &flag);
+               dst_value = resolve_ref_unsafe(matched_src->name,
+                                              RESOLVE_REF_READING,
+                                              sha1, &flag);
                if (!dst_value ||
                    ((flag & REF_ISSYMREF) &&
                     !starts_with(dst_value, "refs/heads/")))
@@ -1353,7 +1356,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
        }
        clear_commit_marks_many(sent_tips.nr, sent_tips.tip, TMP_MARK);
 
-       sort_string_list(&dst_tag);
+       string_list_sort(&dst_tag);
 
        /* Collect tags they do not have. */
        for (ref = src; ref; ref = ref->next) {
@@ -1418,7 +1421,7 @@ static void prepare_ref_index(struct string_list *ref_index, struct ref *ref)
        for ( ; ref; ref = ref->next)
                string_list_append_nodup(ref_index, ref->name)->util = ref;
 
-       sort_string_list(ref_index);
+       string_list_sort(ref_index);
 }
 
 /*
@@ -1628,6 +1631,27 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
        }
 }
 
+static void set_merge(struct branch *ret)
+{
+       char *ref;
+       unsigned char sha1[20];
+       int i;
+
+       ret->merge = xcalloc(ret->merge_nr, sizeof(*ret->merge));
+       for (i = 0; i < ret->merge_nr; i++) {
+               ret->merge[i] = xcalloc(1, sizeof(**ret->merge));
+               ret->merge[i]->src = xstrdup(ret->merge_name[i]);
+               if (!remote_find_tracking(ret->remote, ret->merge[i]) ||
+                   strcmp(ret->remote_name, "."))
+                       continue;
+               if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
+                            sha1, &ref) == 1)
+                       ret->merge[i]->dst = ref;
+               else
+                       ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
+       }
+}
+
 struct branch *branch_get(const char *name)
 {
        struct branch *ret;
@@ -1639,17 +1663,8 @@ struct branch *branch_get(const char *name)
                ret = make_branch(name, 0);
        if (ret && ret->remote_name) {
                ret->remote = remote_get(ret->remote_name);
-               if (ret->merge_nr) {
-                       int i;
-                       ret->merge = xcalloc(ret->merge_nr, sizeof(*ret->merge));
-                       for (i = 0; i < ret->merge_nr; i++) {
-                               ret->merge[i] = xcalloc(1, sizeof(**ret->merge));
-                               ret->merge[i]->src = xstrdup(ret->merge_name[i]);
-                               if (remote_find_tracking(ret->remote, ret->merge[i])
-                                   && !strcmp(ret->remote_name, "."))
-                                       ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
-                       }
-               }
+               if (ret->merge_nr)
+                       set_merge(ret);
        }
        return ret;
 }
@@ -1673,7 +1688,7 @@ static int ignore_symref_update(const char *refname)
        unsigned char sha1[20];
        int flag;
 
-       if (!resolve_ref_unsafe(refname, sha1, 0, &flag))
+       if (!resolve_ref_unsafe(refname, 0, sha1, &flag))
                return 0; /* non-existing refs are OK */
        return (flag & REF_ISSYMREF);
 }
@@ -2132,7 +2147,7 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet
        info.ref_count = ref_count;
        for (ref = fetch_map; ref; ref = ref->next)
                string_list_append(&ref_names, ref->name);
-       sort_string_list(&ref_names);
+       string_list_sort(&ref_names);
        for_each_ref(get_stale_heads_cb, &info);
        string_list_clear(&ref_names, 0);
        return stale_refs;
@@ -2141,7 +2156,7 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet
 /*
  * Compare-and-swap
  */
-void clear_cas_option(struct push_cas_option *cas)
+static void clear_cas_option(struct push_cas_option *cas)
 {
        int i;