summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-08-10 09:32:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-08-10 22:15:41 (GMT)
commitf5895fd399855e782ed0f86f1ac0531517efa0d9 (patch)
tree6760d59bcb5873a737066f26bf562eb5da4d805b /path.c
parent69ddd231fe8d4de64990d42b96d34940a7e43aef (diff)
downloadgit-f5895fd399855e782ed0f86f1ac0531517efa0d9.zip
git-f5895fd399855e782ed0f86f1ac0531517efa0d9.tar.gz
git-f5895fd399855e782ed0f86f1ac0531517efa0d9.tar.bz2
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>
Diffstat (limited to 'path.c')
-rw-r--r--path.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/path.c b/path.c
index 10f4cbf..9aad9a1 100644
--- a/path.c
+++ b/path.c
@@ -224,11 +224,10 @@ const char *mkpath(const char *fmt, ...)
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;
- va_list args;
strbuf_addstr(buf, path);
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, '/');
- va_start(args, fmt);
strbuf_vaddf(buf, fmt, args);
- va_end(args);
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;
}
+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)
{
struct stat st;