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_expanded_map(const struct ref *remote_refs, const struct refspec *refspec) { const struct ref *ref; struct ref *ret = NULL; struct ref **tail = &ret; int remote_prefix_len = strlen(refspec->src); int local_prefix_len = strlen(refspec->dst); for (ref = remote_refs; ref; ref = ref->next) { if (strchr(ref->name, '^')) continue; /* a dereference item */ if (!prefixcmp(ref->name, refspec->src)) { const char *match; struct ref *cpy = copy_ref(ref); match = ref->name + remote_prefix_len; cpy->peer_ref = alloc_ref_with_prefix(refspec->dst, local_prefix_len, match); if (refspec->force) cpy->peer_ref->force = 1; *tail = cpy; tail = &cpy->next; } } return ret; }
struct ref *get_remote_ref(const struct ref *remote_refs, const char *name) { const struct ref *ref = find_ref_by_name_abbrev(remote_refs, name); if (!ref) return NULL; return copy_ref(ref); }
struct ref *copy_ref_list(const struct ref *ref) { struct ref *ret = NULL; struct ref **tail = &ret; while (ref) { *tail = copy_ref(ref); ref = ref->next; tail = &((*tail)->next); } return ret; }
static void add_proc_waiting(DE_Handle *dh, Process *proc, Uint status, Eterm ref) { DE_ProcEntry *p; assert_drv_list_rwlocked(); p = erts_alloc(ERTS_ALC_T_DDLL_PROCESS, sizeof(DE_ProcEntry)); p->proc = proc; p->flags = 0; p->awaiting_status = status; copy_ref(ref, p->heap); p->next = dh->procs; dh->procs = p; }
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 void notify_proc(Process *proc, Eterm ref, Eterm driver_name, Eterm type, Eterm tag, int errcode) { Eterm mess; Eterm r; Eterm *hp; ErtsMessage *mp; ErtsProcLocks rp_locks = 0; ErlOffHeap *ohp; ERTS_CHK_NO_PROC_LOCKS; assert_drv_list_rwlocked(); if (errcode != 0) { int need = load_error_need(errcode); Eterm e; mp = erts_alloc_message_heap(proc, &rp_locks, (6 /* tuple */ + 3 /* Error tuple */ + ERTS_REF_THING_SIZE + need), &hp, &ohp); r = copy_ref(ref,hp); hp += ERTS_REF_THING_SIZE; e = build_load_error_hp(hp, errcode); hp += need; mess = TUPLE2(hp,tag,e); hp += 3; mess = TUPLE5(hp,type,r,am_driver,driver_name,mess); } else { mp = erts_alloc_message_heap(proc, &rp_locks, 6 /* tuple */ + ERTS_REF_THING_SIZE, &hp, &ohp); r = copy_ref(ref,hp); hp += ERTS_REF_THING_SIZE; mess = TUPLE5(hp,type,r,am_driver,driver_name,tag); } erts_queue_message(proc, rp_locks, mp, mess, am_system); erts_proc_unlock(proc, rp_locks); ERTS_CHK_NO_PROC_LOCKS; }
static void filter_refs(struct fetch_pack_args *args, struct ref **refs, struct ref **sought, int nr_sought) { struct ref *newlist = NULL; struct ref **newtail = &newlist; struct ref *unmatched = NULL; struct ref *ref, *next; struct oidset tip_oids = OIDSET_INIT; int i; int strict = !(allow_unadvertised_object_request & (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1)); i = 0; for (ref = *refs; ref; ref = next) { int keep = 0; next = ref->next; if (starts_with(ref->name, "refs/") && check_refname_format(ref->name, 0)) ; /* trash */ else { while (i < nr_sought) { int cmp = strcmp(ref->name, sought[i]->name); if (cmp < 0) break; /* definitely do not have it */ else if (cmp == 0) { keep = 1; /* definitely have it */ sought[i]->match_status = REF_MATCHED; } i++; } if (!keep && args->fetch_all && (!args->deepen || !starts_with(ref->name, "refs/tags/"))) keep = 1; } if (keep) { *newtail = ref; ref->next = NULL; newtail = &ref->next; } else { ref->next = unmatched; unmatched = ref; } } if (strict) { for (i = 0; i < nr_sought; i++) { ref = sought[i]; if (!is_unmatched_ref(ref)) continue; add_refs_to_oidset(&tip_oids, unmatched); add_refs_to_oidset(&tip_oids, newlist); break; } } /* Append unmatched requests to the list */ for (i = 0; i < nr_sought; i++) { ref = sought[i]; if (!is_unmatched_ref(ref)) continue; if (!strict || oidset_contains(&tip_oids, &ref->old_oid)) { ref->match_status = REF_MATCHED; *newtail = copy_ref(ref); newtail = &(*newtail)->next; } else { ref->match_status = REF_UNADVERTISED_NOT_ALLOWED; } } oidset_clear(&tip_oids); for (ref = unmatched; ref; ref = next) { next = ref->next; free(ref); } *refs = newlist; }
static void filter_refs(struct fetch_pack_args *args, struct ref **refs, struct ref **sought, int nr_sought) { struct ref *newlist = NULL; struct ref **newtail = &newlist; struct ref *ref, *next; int i; i = 0; for (ref = *refs; ref; ref = next) { int keep = 0; next = ref->next; if (starts_with(ref->name, "refs/") && check_refname_format(ref->name, 0)) ; /* trash */ else { while (i < nr_sought) { int cmp = strcmp(ref->name, sought[i]->name); if (cmp < 0) break; /* definitely do not have it */ else if (cmp == 0) { keep = 1; /* definitely have it */ sought[i]->matched = 1; } i++; } } if (!keep && args->fetch_all && (!args->depth || !starts_with(ref->name, "refs/tags/"))) keep = 1; if (keep) { *newtail = ref; ref->next = NULL; newtail = &ref->next; } else { free(ref); } } /* Append unmatched requests to the list */ if ((allow_unadvertised_object_request & (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1))) { for (i = 0; i < nr_sought; i++) { unsigned char sha1[20]; ref = sought[i]; if (ref->matched) continue; if (get_sha1_hex(ref->name, sha1) || ref->name[40] != '\0' || hashcmp(sha1, ref->old_oid.hash)) continue; ref->matched = 1; *newtail = copy_ref(ref); newtail = &(*newtail)->next; } } *refs = newlist; }