Re: [PATCH 6/9] strbuf: reintroduce strbuf_parent_directory()
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Nov 3, 2022, 09:28 UTC
- Message-ID
- <6efed789-7ea8-5135-aafb-59da1312b80d@dunelm.org.uk>
- In-Reply-To
- <2200a70d279adcc6460dcb7bef7b0e681d19a414.1667264854.git.gitgitgadget@gmail.com>
Hi Stolee
On 01/11/2022 01:07, Derrick Stolee via GitGitGadget wrote:
Show 21 quoted lines
> +size_t strbuf_parent_directory(struct strbuf *buf)
> +{
> + size_t len = buf->len;
> + size_t offset = offset_1st_component(buf->buf);
> + char *path_sep = find_last_dir_sep(buf->buf + offset);
> + strbuf_setlen(buf, path_sep ? path_sep - buf->buf : offset);
> + return len - buf->len;
> +}
> diff --git a/strbuf.h b/strbuf.h
> index 76965a17d44..8a964a08c31 100644
> --- a/strbuf.h
> +++ b/strbuf.h
> @@ -664,6 +664,13 @@ 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 deepest subdirectory in the provided path string. If path
> + * contains a trailing separator, then the path is considered a directory
> + * and nothing is modified.
> + */I found the name and description a bit confusing, if I've understood correctly it isn't really removing the deepest subdirectory but removes the file name if there is one from the path. As such perhaps strbuf_strip_filename() might make it clearer that it is a no-op if the path ends with a slash. It returns the number of characters removed but that is undocumented.
Best Wishes
Phillip
Show 5 quoted lines
> +size_t strbuf_parent_directory(struct strbuf *buf); > + > void strbuf_add_lines(struct strbuf *sb, > const char *prefix, > const char *buf,