Example #1
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/");
	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;
}
Example #2
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;
}
Example #3
0
File: describe.c Project: 9b/git
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;
}
Example #4
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;
}