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.
This commit is contained in:
Linus Torvalds
2005-07-05 11:31:32 -07:00
parent 7a662e896b
commit 723c31fea2
7 changed files with 37 additions and 14 deletions

9
refs.c
View File

@ -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);