summaryrefslogtreecommitdiffstats
path: root/strbuf.h
diff options
context:
space:
mode:
authorDerrick Stolee <derrickstolee@github.com>2022-12-22 16:14:14 +0100
committerJunio C Hamano <gitster@pobox.com>2022-12-25 08:24:24 +0100
commit9ea57964953dec11dcbbd5d4bf44a5e3781f5880 (patch)
tree7f4738556b871d07a2c35dd4697e965d03afe97a /strbuf.h
parentbundle-uri: serve bundle.* keys from config (diff)
downloadgit-9ea57964953dec11dcbbd5d4bf44a5e3781f5880.tar.xz
git-9ea57964953dec11dcbbd5d4bf44a5e3781f5880.zip
strbuf: introduce strbuf_strip_file_from_path()
The strbuf_parent_directory() method was added as a static method in contrib/scalar by d0feac4e8c0 (scalar: 'register' sets recommended config and starts maintenance, 2021-12-03) and then removed in 65f6a9eb0b9 (scalar: constrain enlistment search, 2022-08-18), but now there is a need for a similar method in the bundle URI feature. Re-add the method, this time in strbuf.c, but with a new name: strbuf_strip_file_from_path(). The method requirements are slightly modified to allow a trailing slash, in which case nothing is done, which makes the name change valuable. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
-rw-r--r--strbuf.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/strbuf.h b/strbuf.h
index 76965a17d4..f6dbb9681e 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -664,6 +664,17 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer,
int strbuf_edit_interactively(struct strbuf *buffer, const char *path,
const char *const *env);
+/*
+ * Remove the filename from the provided path string. If the path
+ * contains a trailing separator, then the path is considered a directory
+ * and nothing is modified.
+ *
+ * Examples:
+ * - "/path/to/file" -> "/path/to/"
+ * - "/path/to/dir/" -> "/path/to/dir/"
+ */
+void strbuf_strip_file_from_path(struct strbuf *sb);
+
void strbuf_add_lines(struct strbuf *sb,
const char *prefix,
const char *buf,