static struct ref *wanted_peer_refs(const struct ref *refs, struct refspec *refspec) { struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD")); struct ref *local_refs = head; struct ref **tail = head ? &head->next : &local_refs; if (option_single_branch) { struct ref *remote_head = NULL; if (!option_branch) remote_head = guess_remote_head(head, refs, 0); else { local_refs = NULL; tail = &local_refs; remote_head = copy_ref(find_remote_branch(refs, option_branch)); } if (!remote_head && option_branch) warning(_("Could not find remote branch %s to clone."), option_branch); else { get_fetch_map(remote_head, refspec, &tail, 0); /* if --branch=tag, pull the requested tag explicitly */ get_fetch_map(remote_head, tag_refspec, &tail, 0); } } else get_fetch_map(refs, refspec, &tail, 0); if (!option_mirror && !option_single_branch) get_fetch_map(refs, tag_refspec, &tail, 0); return local_refs; }
static struct ref *get_ref_map(struct transport *transport, struct refspec *refs, int ref_count, int tags, int *autotags) { int i; struct ref *rm; struct ref *ref_map = NULL; struct ref **tail = &ref_map; const struct ref *remote_refs = transport_get_remote_refs(transport); if (ref_count || tags == TAGS_SET) { for (i = 0; i < ref_count; i++) { get_fetch_map(remote_refs, &refs[i], &tail, 0); if (refs[i].dst && refs[i].dst[0]) *autotags = 1; } /* Merge everything on the command line, but not --tags */ for (rm = ref_map; rm; rm = rm->next) rm->merge = 1; if (tags == TAGS_SET) get_fetch_map(remote_refs, tag_refspec, &tail, 0); } else { /* Use the defaults */ struct remote *remote = transport->remote; struct branch *branch = branch_get(NULL); int has_merge = branch_has_merge_config(branch); if (remote && (remote->fetch_refspec_nr || has_merge)) { for (i = 0; i < remote->fetch_refspec_nr; i++) { get_fetch_map(remote_refs, &remote->fetch[i], &tail, 0); if (remote->fetch[i].dst && remote->fetch[i].dst[0]) *autotags = 1; if (!i && !has_merge && ref_map && !remote->fetch[0].pattern) ref_map->merge = 1; } /* * if the remote we're fetching from is the same * as given in branch.<name>.remote, we add the * ref given in branch.<name>.merge, too. */ if (has_merge && !strcmp(branch->remote_name, remote->name)) add_merge_config(&ref_map, remote_refs, branch, &tail); } else { ref_map = get_remote_ref(remote_refs, "HEAD"); if (!ref_map) die("Couldn't find remote ref HEAD"); ref_map->merge = 1; tail = &ref_map->next; } } if (tags == TAGS_DEFAULT && *autotags) find_non_local_tags(transport, &ref_map, &tail); ref_remove_duplicates(ref_map); return ref_map; }
static struct ref *wanted_peer_refs(const struct ref *refs, struct refspec *refspec) { struct ref *local_refs = NULL; struct ref **tail = &local_refs; get_fetch_map(refs, refspec, &tail, 0); if (!option_mirror) get_fetch_map(refs, tag_refspec, &tail, 0); return local_refs; }
static struct ref *wanted_peer_refs(const struct ref *refs, struct refspec *refspec) { struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD")); struct ref *local_refs = head; struct ref **tail = head ? &head->next : &local_refs; get_fetch_map(refs, refspec, &tail, 0); if (!option_mirror) get_fetch_map(refs, tag_refspec, &tail, 0); return local_refs; }
static struct ref *write_remote_refs(const struct ref *refs, struct refspec *refspec, const char *reflog) { struct ref *local_refs = NULL; struct ref **tail = &local_refs; struct ref *r; get_fetch_map(refs, refspec, &tail, 0); if (!option_mirror) get_fetch_map(refs, tag_refspec, &tail, 0); for (r = local_refs; r; r = r->next) add_extra_ref(r->peer_ref->name, r->old_sha1, 0); pack_refs(PACK_REFS_ALL); clear_extra_refs(); return local_refs; }
static void add_merge_config(struct ref **head, const struct ref *remote_refs, struct branch *branch, struct ref ***tail) { int i; for (i = 0; i < branch->merge_nr; i++) { struct ref *rm, **old_tail = *tail; struct refspec refspec; for (rm = *head; rm; rm = rm->next) { if (branch_merge_matches(branch, i, rm->name)) { rm->merge = 1; break; } } if (rm) continue; /* * Not fetched to a tracking branch? We need to fetch * it anyway to allow this branch's "branch.$name.merge" * to be honored by 'git pull', but we do not have to * fail if branch.$name.merge is misconfigured to point * at a nonexisting branch. If we were indeed called by * 'git pull', it will notice the misconfiguration because * there is no entry in the resulting FETCH_HEAD marked * for merging. */ refspec.src = branch->merge[i]->src; refspec.dst = NULL; refspec.pattern = 0; refspec.force = 0; get_fetch_map(remote_refs, &refspec, tail, 1); for (rm = *old_tail; rm; rm = rm->next) rm->merge = 1; } }