static int revparse_lookup_object(git_object **out, git_repository *repo, const char *spec)
{
	int error;
	git_reference *ref;

	error = maybe_sha(out, repo, spec);
	if (!error)
		return 0;

	if (error < 0 && error != GIT_ENOTFOUND)
		return error;

	error = disambiguate_refname(&ref, repo, spec);
	if (!error) {
		error = git_object_lookup(out, repo, git_reference_target(ref), GIT_OBJ_ANY);
		git_reference_free(ref);
		return error;
	}

	if (error < 0 && error != GIT_ENOTFOUND)
		return error;

	error = maybe_abbrev(out, repo, spec);
	if (!error)
		return 0;

	if (error < 0 && error != GIT_ENOTFOUND)
		return error;

	error = maybe_describe(out, repo, spec);
	if (!error)
		return 0;

	if (error < 0 && error != GIT_ENOTFOUND)
		return error;

	giterr_set(GITERR_REFERENCE, "Refspec '%s' not found.", spec);
	return GIT_ENOTFOUND;
}
예제 #2
0
파일: revparse.c 프로젝트: Arhzi/libgit2
static int revparse_lookup_object(
	git_object **object_out,
	git_reference **reference_out,
	git_repository *repo,
	const char *spec)
{
	int error;
	git_reference *ref;

	if ((error = maybe_sha(object_out, repo, spec)) != GIT_ENOTFOUND)
		return error;

	error = git_reference_dwim(&ref, repo, spec);
	if (!error) {

		error = git_object_lookup(
			object_out, repo, git_reference_target(ref), GIT_OBJ_ANY);

		if (!error)
			*reference_out = ref;

		return error;
	}

	if (error != GIT_ENOTFOUND)
		return error;

	if ((strlen(spec) < GIT_OID_HEXSZ) &&
		((error = maybe_abbrev(object_out, repo, spec)) != GIT_ENOTFOUND))
			return error;

	if ((error = maybe_describe(object_out, repo, spec)) != GIT_ENOTFOUND)
		return error;

	giterr_set(GITERR_REFERENCE, "revspec '%s' not found", spec);
	return GIT_ENOTFOUND;
}