From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH 02/17] cache.h: complete set of git_path_submodule helpers
Date: Mon, 10 Aug 2015 05:32:22 -0400 [thread overview]
Message-ID: <20150810093222.GB30981@sigill.intra.peff.net> (raw)
In-Reply-To: <20150810092731.GA9027@sigill.intra.peff.net>
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>
---
cache.h | 5 +++++
path.c | 35 ++++++++++++++++++++++++++++++-----
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/cache.h b/cache.h
index 8db884e..6f74f33 100644
--- a/cache.h
+++ b/cache.h
@@ -724,10 +724,15 @@ extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
__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, ...)
__attribute__((format (printf, 1, 2)));
extern char *mkpathdup(const char *fmt, ...)
__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);
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;
--
2.5.0.414.g670f2a4
next prev parent reply other threads:[~2015-08-10 9:32 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-10 9:27 [PATCH 0/17] removing questionable uses of git_path Jeff King
2015-08-10 9:32 ` [PATCH 01/17] cache.h: clarify documentation for git_path, et al Jeff King
2015-08-10 9:32 ` Jeff King [this message]
2015-08-10 9:32 ` [PATCH 03/17] t5700: modernize style Jeff King
2015-08-10 9:34 ` [PATCH 04/17] add_to_alternates_file: don't add duplicate entries Jeff King
2015-08-11 4:00 ` Michael Haggerty
2015-08-11 9:54 ` Jeff King
2015-08-10 9:35 ` [PATCH 05/17] remove hold_lock_file_for_append Jeff King
2015-08-10 22:36 ` Junio C Hamano
2015-08-11 9:38 ` Jeff King
2015-08-10 9:35 ` [PATCH 06/17] prefer git_pathdup to git_path in some possibly-dangerous cases Jeff King
2015-08-10 9:35 ` [PATCH 07/17] prefer mkpathdup to mkpath in assignments Jeff King
2015-08-10 9:35 ` [PATCH 08/17] remote.c: drop extraneous local variable from migrate_file Jeff King
2015-08-10 9:36 ` [PATCH 09/17] refs.c: remove extra git_path calls from read_loose_refs Jeff King
2015-08-10 9:36 ` [PATCH 10/17] path.c: drop git_path_submodule Jeff King
2015-08-10 22:50 ` Junio C Hamano
2015-08-10 22:57 ` Junio C Hamano
2015-08-10 23:52 ` Junio C Hamano
2015-08-11 9:53 ` Jeff King
2015-08-10 9:36 ` [PATCH 11/17] refs.c: simplify strbufs in reflog setup and writing Jeff King
2015-08-10 10:34 ` Michael Haggerty
2015-08-10 12:26 ` Jeff King
2015-08-10 9:36 ` [PATCH 12/17] refs.c: avoid repeated git_path calls in rename_tmp_log Jeff King
2015-08-10 9:37 ` [PATCH 13/17] refs.c: avoid git_path assignment in lock_ref_sha1_basic Jeff King
2015-08-10 9:37 ` [PATCH 14/17] refs.c: remove_empty_directories can take a strbuf Jeff King
2015-08-10 9:37 ` [PATCH 15/17] find_hook: keep our own static buffer Jeff King
2015-08-10 9:37 ` [PATCH 16/17] get_repo_path: refactor path-allocation Jeff King
2015-08-10 9:38 ` [PATCH 17/17] memoize common git-path "constant" files Jeff King
2015-08-10 12:05 ` Michael Haggerty
2015-08-10 12:30 ` Jeff King
2015-08-10 12:06 ` [PATCH 0/17] removing questionable uses of git_path Michael Haggerty
2015-08-10 17:31 ` Junio C Hamano
2015-08-10 17:47 ` Jeff King
2015-08-15 9:05 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150810093222.GB30981@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=mhagger@alum.mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).