summaryrefslogtreecommitdiff
path: root/src/refs.h
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-04-13 10:33:14 -0700
committerRussell Belfer <rb@github.com>2012-04-17 10:44:50 -0700
commitf201d613a80f7ad6f54d90eb7a7a0d8b8c72676b (patch)
treec3cd8f0eee145f40b640519e06ae628cdb942eb3 /src/refs.h
parent1a6e8f8a54eea1159a950cd8a49cedae3699ff9a (diff)
downloadlibgit2-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/refs.h')
-rw-r--r--src/refs.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/refs.h b/src/refs.h
index 13b9abf15..e4a225ca3 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -55,4 +55,27 @@ void git_repository__refcache_free(git_refcache *refs);
int git_reference__normalize_name(char *buffer_out, size_t out_size, const char *name);
int git_reference__normalize_name_oid(char *buffer_out, size_t out_size, const char *name);
+/**
+ * Lookup a reference by name and try to resolve to an OID.
+ *
+ * You can control how many dereferences this will attempt to resolve the
+ * reference with the `max_deref` parameter, or pass -1 to use a sane
+ * default. If you pass 0 for `max_deref`, this will not attempt to resolve
+ * the reference. For any value of `max_deref` other than 0, not
+ * successfully resolving the reference will be reported as an error.
+
+ * The generated reference must be freed by the user.
+ *
+ * @param reference_out Pointer to the looked-up reference
+ * @param repo The repository to look up the reference
+ * @param name The long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...)
+ * @param max_deref Maximum number of dereferences to make of symbolic refs, 0 means simple lookup, < 0 means use default reasonable value
+ * @return 0 on success or < 0 on error; not being able to resolve the reference is an error unless 0 was passed for max_deref
+ */
+int git_reference_lookup_resolved(
+ git_reference **reference_out,
+ git_repository *repo,
+ const char *name,
+ int max_deref);
+
#endif