From 723c31fea2f1c4994de837bda9022ffa8b6de1bb Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 5 Jul 2005 11:31:32 -0700 Subject: Add "git_path()" and "head_ref()" helper functions. "git_path()" returns a static pathname pointer into the git directory using a printf-like format specifier. "head_ref()" works like "for_each_ref()", except for just the HEAD. --- refs.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'refs.c') diff --git a/refs.c b/refs.c index 7ccd721a4a..6ca04d3b0f 100644 --- a/refs.c +++ b/refs.c @@ -68,6 +68,15 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, const u return retval; } +int head_ref(int (*fn)(const char *path, const unsigned char *sha1)) +{ + unsigned char sha1[20]; + const char *headpath = git_path("HEAD"); + if (!read_ref(headpath, sha1)) + fn(headpath, sha1); + return do_for_each_ref(get_refs_directory(), fn); +} + int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1)) { return do_for_each_ref(get_refs_directory(), fn); -- cgit v1.2.1