static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) { static const char *capabilities = "multi_ack thin-pack side-band" " side-band-64k ofs-delta shallow no-progress" " include-tag multi_ack_detailed"; const char *refname_nons = strip_namespace(refname); unsigned char peeled[20]; if (mark_our_ref(refname, sha1, flag, NULL)) return 0; if (capabilities) { struct strbuf symref_info = STRBUF_INIT; format_symref_info(&symref_info, cb_data); packet_write(1, "%s %s%c%s%s%s%s agent=%s\n", sha1_to_hex(sha1), refname_nons, 0, capabilities, allow_tip_sha1_in_want ? " allow-tip-sha1-in-want" : "", stateless_rpc ? " no-done" : "", symref_info.buf, git_user_agent_sanitized()); strbuf_release(&symref_info); } else { packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons); } capabilities = NULL; if (!peel_ref(refname, peeled)) packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons); return 0; }
static int send_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data) { static const char *capabilities = "multi_ack thin-pack side-band" " side-band-64k ofs-delta shallow no-progress" " include-tag multi_ack_detailed"; const char *refname_nons = strip_namespace(refname); struct object_id peeled; if (mark_our_ref(refname_nons, refname, oid)) return 0; if (capabilities) { struct strbuf symref_info = STRBUF_INIT; format_symref_info(&symref_info, cb_data); packet_write(1, "%s %s%c%s%s%s%s%s agent=%s\n", oid_to_hex(oid), refname_nons, 0, capabilities, (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ? " allow-tip-sha1-in-want" : "", (allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ? " allow-reachable-sha1-in-want" : "", stateless_rpc ? " no-done" : "", symref_info.buf, git_user_agent_sanitized()); strbuf_release(&symref_info); } else { packet_write(1, "%s %s\n", oid_to_hex(oid), refname_nons); } capabilities = NULL; if (!peel_ref(refname, peeled.hash)) packet_write(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons); return 0; }
static void show_one(const char *refname, const struct object_id *oid) { const char *hex; struct object_id peeled; if (!has_sha1_file(oid->hash)) die("git show-ref: bad ref %s (%s)", refname, oid_to_hex(oid)); if (quiet) return; hex = find_unique_abbrev(oid->hash, abbrev); if (hash_only) printf("%s\n", hex); else printf("%s %s\n", hex, refname); if (!deref_tags) return; if (!peel_ref(refname, &peeled)) { hex = find_unique_abbrev(peeled.hash, abbrev); printf("%s %s^{}\n", hex, refname); } }
static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data) { int might_be_tag = !prefixcmp(path, "refs/tags/"); struct commit *commit; struct object *object; unsigned char peeled[20]; int is_tag, prio; if (!all && !might_be_tag) return 0; if (!peel_ref(path, peeled) && !is_null_sha1(peeled)) { commit = lookup_commit_reference_gently(peeled, 1); if (!commit) return 0; is_tag = !!hashcmp(sha1, commit->object.sha1); } else { commit = lookup_commit_reference_gently(sha1, 1); object = parse_object(sha1); if (!commit || !object) return 0; is_tag = object->type == OBJ_TAG; } /* If --all, then any refs are used. * If --tags, then any tags are used. * Otherwise only annotated tags are used. */ if (might_be_tag) { if (is_tag) prio = 2; else prio = 1; if (pattern && fnmatch(pattern, path + 10, 0)) prio = 0; } else prio = 0; if (!all) { if (!prio) return 0; if (!tags && prio < 2) return 0; } add_to_known_names(all ? path + 5 : path + 10, commit, prio, sha1); return 0; }
static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data) { int might_be_tag = !prefixcmp(path, "refs/tags/"); unsigned char peeled[20]; int is_tag, prio; if (!all && !might_be_tag) return 0; if (!peel_ref(path, peeled)) { is_tag = !!hashcmp(sha1, peeled); } else { hashcpy(peeled, sha1); is_tag = 0; } /* If --all, then any refs are used. * If --tags, then any tags are used. * Otherwise only annotated tags are used. */ if (might_be_tag) { if (is_tag) prio = 2; else prio = 1; if (pattern && fnmatch(pattern, path + 10, 0)) prio = 0; } else prio = 0; if (!all) { if (!prio) return 0; } add_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1); return 0; }
static int get_name(const char *path, const struct object_id *oid, int flag, void *cb_data) { int is_tag = starts_with(path, "refs/tags/"); struct object_id peeled; int is_annotated, prio; /* Reject anything outside refs/tags/ unless --all */ if (!all && !is_tag) return 0; /* Accept only tags that match the pattern, if given */ if (pattern && (!is_tag || wildmatch(pattern, path + 10, 0, NULL))) return 0; /* Is it annotated? */ if (!peel_ref(path, peeled.hash)) { is_annotated = !!oidcmp(oid, &peeled); } else { oidcpy(&peeled, oid); is_annotated = 0; } /* * By default, we only use annotated tags, but with --tags * we fall back to lightweight ones (even without --tags, * we still remember lightweight ones, only to give hints * in an error message). --all allows any refs to be used. */ if (is_annotated) prio = 2; else if (is_tag) prio = 1; else prio = 0; add_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash); return 0; }
static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data) { int is_tag = !prefixcmp(path, "refs/tags/"); unsigned char peeled[20]; int is_annotated, prio; /* Reject anything outside refs/tags/ unless --all */ if (!all && !is_tag) return 0; /* Accept only tags that match the pattern, if given */ if (pattern && (!is_tag || fnmatch(pattern, path + 10, 0))) return 0; /* Is it annotated? */ if (!peel_ref(path, peeled)) { is_annotated = !!hashcmp(sha1, peeled); } else { hashcpy(peeled, sha1); is_annotated = 0; } /* * By default, we only use annotated tags, but with --tags * we fall back to lightweight ones (even without --tags, * we still remember lightweight ones, only to give hints * in an error message). --all allows any refs to be used. */ if (is_annotated) prio = 2; else if (is_tag) prio = 1; else prio = 0; add_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1); return 0; }
static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata) { const char *hex; unsigned char peeled[20]; if (show_head && !strcmp(refname, "HEAD")) goto match; if (tags_only || heads_only) { int match; match = heads_only && !prefixcmp(refname, "refs/heads/"); match |= tags_only && !prefixcmp(refname, "refs/tags/"); if (!match) return 0; } if (pattern) { int reflen = strlen(refname); const char **p = pattern, *m; while ((m = *p++) != NULL) { int len = strlen(m); if (len > reflen) continue; if (memcmp(m, refname + reflen - len, len)) continue; if (len == reflen) goto match; /* "--verify" requires an exact match */ if (verify) continue; if (refname[reflen - len - 1] == '/') goto match; } return 0; } match: found_match++; /* This changes the semantics slightly that even under quiet we * detect and return error if the repository is corrupt and * ref points at a nonexistent object. */ if (!has_sha1_file(sha1)) die("git show-ref: bad ref %s (%s)", refname, sha1_to_hex(sha1)); if (quiet) return 0; show_one(refname, sha1); if (!deref_tags) return 0; if (!peel_ref(refname, peeled)) { hex = find_unique_abbrev(peeled, abbrev); printf("%s %s^{}\n", hex, refname); } return 0; }