From 0e8e5a6189b84b2817d5916948e963e97d8f3641 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 3 Feb 2013 11:44:26 +0100 Subject: revparse: Lookup sha before branch --- src/revparse.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'src/revparse.c') diff --git a/src/revparse.c b/src/revparse.c index 7c5d9bd79..884879975 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -67,10 +67,9 @@ cleanup: return error; } -static int maybe_sha_or_abbrev(git_object**out, git_repository *repo, const char *spec) +static int maybe_sha_or_abbrev(git_object** out, git_repository *repo, const char *spec, size_t speclen) { git_oid oid; - size_t speclen = strlen(spec); if (git_oid_fromstrn(&oid, spec, speclen) < 0) return GIT_ENOTFOUND; @@ -78,6 +77,23 @@ static int maybe_sha_or_abbrev(git_object**out, git_repository *repo, const char return git_object_lookup_prefix(out, repo, &oid, speclen, GIT_OBJ_ANY); } +static int maybe_sha(git_object** out, git_repository *repo, const char *spec) +{ + size_t speclen = strlen(spec); + + if (speclen != GIT_OID_HEXSZ) + return GIT_ENOTFOUND; + + return maybe_sha_or_abbrev(out, repo, spec, speclen); +} + +static int maybe_abbrev(git_object** out, git_repository *repo, const char *spec) +{ + size_t speclen = strlen(spec); + + return maybe_sha_or_abbrev(out, repo, spec, speclen); +} + static int build_regex(regex_t *regex, const char *pattern) { int error; @@ -118,7 +134,7 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe if (error) return GIT_ENOTFOUND; - return maybe_sha_or_abbrev(out, repo, substr+2); + return maybe_abbrev(out, repo, substr+2); } static int revparse_lookup_object(git_object **out, git_repository *repo, const char *spec) @@ -126,6 +142,13 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const 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); @@ -136,14 +159,14 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const if (error < 0 && error != GIT_ENOTFOUND) return error; - error = maybe_describe(out, repo, spec); + error = maybe_abbrev(out, repo, spec); if (!error) return 0; if (error < 0 && error != GIT_ENOTFOUND) return error; - error = maybe_sha_or_abbrev(out, repo, spec); + error = maybe_describe(out, repo, spec); if (!error) return 0; @@ -217,7 +240,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out, if (error < 0 && error != GIT_ENOTFOUND) goto cleanup; - error = maybe_sha_or_abbrev(out, repo, git_buf_cstr(&buf)); + error = maybe_abbrev(out, repo, git_buf_cstr(&buf)); goto cleanup; } -- cgit v1.2.1