]> git.ipfire.org Git - thirdparty/git.git/commitdiff
path: add repo_git_path and strbuf_repo_git_path
authorBrandon Williams <bmwill@google.com>
Thu, 22 Jun 2017 18:43:40 +0000 (11:43 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 24 Jun 2017 01:24:34 +0000 (18:24 -0700)
Introduce 'repo_git_path' and 'strbuf_repo_git_path' which take a
repository struct and constructs a path into the repository's git
directory.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
path.c
path.h

diff --git a/path.c b/path.c
index 2bdd0044f084a4e16c662f553d92abcded358210..ffc0f10fde9bfc4881de085329133486015e28e8 100644 (file)
--- a/path.c
+++ b/path.c
@@ -416,6 +416,27 @@ static void do_git_path(const struct repository *repo,
        strbuf_cleanup_path(buf);
 }
 
+char *repo_git_path(const struct repository *repo,
+                   const char *fmt, ...)
+{
+       struct strbuf path = STRBUF_INIT;
+       va_list args;
+       va_start(args, fmt);
+       do_git_path(repo, NULL, &path, fmt, args);
+       va_end(args);
+       return strbuf_detach(&path, NULL);
+}
+
+void strbuf_repo_git_path(struct strbuf *sb,
+                         const struct repository *repo,
+                         const char *fmt, ...)
+{
+       va_list args;
+       va_start(args, fmt);
+       do_git_path(repo, NULL, sb, fmt, args);
+       va_end(args);
+}
+
 char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
 {
        va_list args;
diff --git a/path.h b/path.h
index 568d63be5ad68665d270500b2b29949cec8e4989..c779c4aa2878b6cc566f046a1140e47e9361cb33 100644 (file)
--- a/path.h
+++ b/path.h
@@ -35,6 +35,14 @@ extern char *mkpathdup(const char *fmt, ...)
 extern char *git_pathdup_submodule(const char *path, const char *fmt, ...)
        __attribute__((format (printf, 2, 3)));
 
+extern char *repo_git_path(const struct repository *repo,
+                          const char *fmt, ...)
+       __attribute__((format (printf, 2, 3)));
+extern void strbuf_repo_git_path(struct strbuf *sb,
+                                const struct repository *repo,
+                                const char *fmt, ...)
+       __attribute__((format (printf, 3, 4)));
+
 extern void report_linked_checkout_garbage(void);
 
 /*