diff options
author | Heiko Voigt <hvoigt@hvoigt.net> | 2010-07-07 15:39:11 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-07-07 09:48:21 -0700 |
commit | 0bad611b1ebacf170976a10690bd0169f8d372bf (patch) | |
tree | eb0499c1c9a26e85ea3f06843528c900bf1a898f /path.c | |
parent | 78db709ae59da26de76264b79df3a7dc4d87e65c (diff) | |
download | git-0bad611b1ebacf170976a10690bd0169f8d372bf.tar.gz |
Teach ref iteration module about submodules
We will use this in a later patch to extend setup_revisions() to
load revisions directly from a submodule.
Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r-- | path.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -122,6 +122,44 @@ char *git_path(const char *fmt, ...) return cleanup_path(pathname); } +char *git_path_submodule(const char *path, const char *fmt, ...) +{ + char *pathname = get_pathname(); + struct strbuf buf = STRBUF_INIT; + const char *git_dir; + va_list args; + unsigned len; + + len = strlen(path); + if (len > PATH_MAX-100) + return bad_path; + + strbuf_addstr(&buf, path); + if (len && path[len-1] != '/') + strbuf_addch(&buf, '/'); + strbuf_addstr(&buf, ".git"); + + git_dir = read_gitfile_gently(buf.buf); + if (git_dir) { + strbuf_reset(&buf); + strbuf_addstr(&buf, git_dir); + } + strbuf_addch(&buf, '/'); + + if (buf.len >= PATH_MAX) + return bad_path; + memcpy(pathname, buf.buf, buf.len + 1); + + strbuf_release(&buf); + len = strlen(pathname); + + va_start(args, fmt); + len += vsnprintf(pathname + len, PATH_MAX - len, fmt, args); + va_end(args); + if (len >= PATH_MAX) + return bad_path; + return cleanup_path(pathname); +} /* git_mkstemp() - create tmp file honoring TMPDIR variable */ int git_mkstemp(char *path, size_t len, const char *template) |