diff options
| author | Russell Belfer <rb@github.com> | 2012-04-13 10:33:14 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2012-04-17 10:44:50 -0700 |
| commit | f201d613a80f7ad6f54d90eb7a7a0d8b8c72676b (patch) | |
| tree | c3cd8f0eee145f40b640519e06ae628cdb942eb3 /src/repository.c | |
| parent | 1a6e8f8a54eea1159a950cd8a49cedae3699ff9a (diff) | |
| download | libgit2-f201d613a80f7ad6f54d90eb7a7a0d8b8c72676b.tar.gz | |
Add git_reference_lookup_oid and lookup_resolved
Adds a new public reference function `git_reference_lookup_oid`
that directly resolved a reference name to an OID without returning
the intermediate `git_reference` object (hence, no free needed).
Internally, this adds a `git_reference_lookup_resolved` function
that combines looking up and resolving a reference. This allows
us to be more efficient with memory reallocation.
The existing `git_reference_lookup` and `git_reference_resolve`
are reimplmented on top of the new utility and a few places in the
code are changed to use one of the two new functions.
Diffstat (limited to 'src/repository.c')
| -rw-r--r-- | src/repository.c | 19 |
1 files changed, 1 insertions, 18 deletions
diff --git a/src/repository.c b/src/repository.c index 18881ecce..572b51622 100644 --- a/src/repository.c +++ b/src/repository.c @@ -772,24 +772,7 @@ int git_repository_head_detached(git_repository *repo) int git_repository_head(git_reference **head_out, git_repository *repo) { - git_reference *ref, *resolved_ref; - int error; - - *head_out = NULL; - - error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE); - if (error < 0) - return error; - - error = git_reference_resolve(&resolved_ref, ref); - if (error < 0) { - git_reference_free(ref); - return error; - } - - git_reference_free(ref); - *head_out = resolved_ref; - return 0; + return git_reference_lookup_resolved(head_out, repo, GIT_HEAD_FILE, -1); } int git_repository_head_orphan(git_repository *repo) |
