cache.h: complete set of git_path_submodule helpers
The git_path function has "git_pathdup" and "strbuf_git_path" variants, but git_submodule_path only comes in the dangerous, static-buffer variant. That makes refactoring callers to use the safer functions hard (since they don't exist). Since we're already using a strbuf behind the scenes, it's easy to expose all three of these interfaces with thin wrappers. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
69ddd231fe
commit
f5895fd399
5
cache.h
5
cache.h
@ -724,10 +724,15 @@ extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
|
|||||||
__attribute__((format (printf, 3, 4)));
|
__attribute__((format (printf, 3, 4)));
|
||||||
extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
|
extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
|
||||||
__attribute__((format (printf, 2, 3)));
|
__attribute__((format (printf, 2, 3)));
|
||||||
|
extern void strbuf_git_path_submodule(struct strbuf *sb, const char *path,
|
||||||
|
const char *fmt, ...)
|
||||||
|
__attribute__((format (printf, 3, 4)));
|
||||||
extern char *git_pathdup(const char *fmt, ...)
|
extern char *git_pathdup(const char *fmt, ...)
|
||||||
__attribute__((format (printf, 1, 2)));
|
__attribute__((format (printf, 1, 2)));
|
||||||
extern char *mkpathdup(const char *fmt, ...)
|
extern char *mkpathdup(const char *fmt, ...)
|
||||||
__attribute__((format (printf, 1, 2)));
|
__attribute__((format (printf, 1, 2)));
|
||||||
|
extern char *git_pathdup_submodule(const char *path, const char *fmt, ...)
|
||||||
|
__attribute__((format (printf, 2, 3)));
|
||||||
|
|
||||||
extern void report_linked_checkout_garbage(void);
|
extern void report_linked_checkout_garbage(void);
|
||||||
|
|
||||||
|
35
path.c
35
path.c
@ -224,11 +224,10 @@ const char *mkpath(const char *fmt, ...)
|
|||||||
return cleanup_path(pathname->buf);
|
return cleanup_path(pathname->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *git_path_submodule(const char *path, const char *fmt, ...)
|
static void do_submodule_path(struct strbuf *buf, const char *path,
|
||||||
|
const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
struct strbuf *buf = get_pathname();
|
|
||||||
const char *git_dir;
|
const char *git_dir;
|
||||||
va_list args;
|
|
||||||
|
|
||||||
strbuf_addstr(buf, path);
|
strbuf_addstr(buf, path);
|
||||||
if (buf->len && buf->buf[buf->len - 1] != '/')
|
if (buf->len && buf->buf[buf->len - 1] != '/')
|
||||||
@ -242,13 +241,39 @@ const char *git_path_submodule(const char *path, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
strbuf_addch(buf, '/');
|
strbuf_addch(buf, '/');
|
||||||
|
|
||||||
va_start(args, fmt);
|
|
||||||
strbuf_vaddf(buf, fmt, args);
|
strbuf_vaddf(buf, fmt, args);
|
||||||
va_end(args);
|
|
||||||
strbuf_cleanup_path(buf);
|
strbuf_cleanup_path(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *git_path_submodule(const char *path, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
struct strbuf *buf = get_pathname();
|
||||||
|
va_start(args, fmt);
|
||||||
|
do_submodule_path(buf, path, fmt, args);
|
||||||
|
va_end(args);
|
||||||
return buf->buf;
|
return buf->buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *git_pathdup_submodule(const char *path, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
va_start(args, fmt);
|
||||||
|
do_submodule_path(&buf, path, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
return strbuf_detach(&buf, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void strbuf_git_path_submodule(struct strbuf *buf, const char *path,
|
||||||
|
const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
do_submodule_path(buf, path, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
int validate_headref(const char *path)
|
int validate_headref(const char *path)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
Loading…
Reference in New Issue
Block a user