summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorDavid Turner <dturner@twopensource.com>2016-04-07 15:02:48 -0400
committerJunio C Hamano <gitster@pobox.com>2016-04-10 11:34:41 -0700
commit2bf68ed5aa79fcccba6ea4c021b15e51c019a85e (patch)
tree1a0a859f6f7dbcb7b88c28f97b6edf303d7b04e3 /refs.c
parent274db840b48d144a8f0f8d8bd324365670c67275 (diff)
downloadgit-2bf68ed5aa79fcccba6ea4c021b15e51c019a85e.tar.gz
refs: move head_ref{,_submodule} to the common code
These don't use any backend-specific functions. These were previously defined in terms of the do_head_ref helper function, but since they are otherwise identical, we don't need that function. Signed-off-by: David Turner <dturner@twopensource.com> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/refs.c b/refs.c
index b0e6ece6f4..6b8c16cdd8 100644
--- a/refs.c
+++ b/refs.c
@@ -1080,3 +1080,26 @@ int rename_ref_available(const char *oldname, const char *newname)
strbuf_release(&err);
return ret;
}
+
+int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
+{
+ struct object_id oid;
+ int flag;
+
+ if (submodule) {
+ if (resolve_gitlink_ref(submodule, "HEAD", oid.hash) == 0)
+ return fn("HEAD", &oid, 0, cb_data);
+
+ return 0;
+ }
+
+ if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag))
+ return fn("HEAD", &oid, flag, cb_data);
+
+ return 0;
+}
+
+int head_ref(each_ref_fn fn, void *cb_data)
+{
+ return head_ref_submodule(NULL, fn, cb_data);
+}