summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-02-03 08:41:47 -0800
committerVicent Martí <vicent@github.com>2013-02-03 08:41:47 -0800
commit3261a3e980b00cf19b971c078d09bc0660ce1f81 (patch)
treed87fc32b4cd9d8435cb51f2d00ed098f891a283b /src
parente963166019de3dca72d18bd4ee8f81519e97fdf3 (diff)
parent0e8e5a6189b84b2817d5916948e963e97d8f3641 (diff)
downloadlibgit2-3261a3e980b00cf19b971c078d09bc0660ce1f81.tar.gz
Merge pull request #1307 from nulltoken/fix/revparse_describe
revparse: Lookup branch before described tag
Diffstat (limited to 'src')
-rw-r--r--src/revparse.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/revparse.c b/src/revparse.c
index 05ee1c57d..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,7 +142,7 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const
int error;
git_reference *ref;
- error = maybe_describe(out, repo, spec);
+ error = maybe_sha(out, repo, spec);
if (!error)
return 0;
@@ -143,7 +159,14 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const
if (error < 0 && error != GIT_ENOTFOUND)
return error;
- error = maybe_sha_or_abbrev(out, repo, spec);
+ 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;
@@ -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;
}