diff options
| author | Calvin Wan <calvinwan@google.com> | 2023-06-06 19:48:42 +0000 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-06-12 13:49:36 -0700 |
| commit | aba070683295a20bdf4f49146384984961c794b2 (patch) | |
| tree | 7443395ecf2bee3aa871646474576feab241984d /path.c | |
| parent | object-name: move related functions to object-name (diff) | |
| download | git-aba070683295a20bdf4f49146384984961c794b2.tar.gz git-aba070683295a20bdf4f49146384984961c794b2.zip | |
path: move related function to path
Move path-related function from strbuf.[ch] to path.[ch] so that strbuf
is focused on string manipulation routines with minimal dependencies.
repository.h is no longer a necessary dependency after moving this
function out.
Signed-off-by: Calvin Wan <calvinwan@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
| -rw-r--r-- | path.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -1213,6 +1213,26 @@ int normalize_path_copy(char *dst, const char *src) return normalize_path_copy_len(dst, src, NULL); } +int strbuf_normalize_path(struct strbuf *src) +{ + struct strbuf dst = STRBUF_INIT; + + strbuf_grow(&dst, src->len); + if (normalize_path_copy(dst.buf, src->buf) < 0) { + strbuf_release(&dst); + return -1; + } + + /* + * normalize_path does not tell us the new length, so we have to + * compute it by looking for the new NUL it placed + */ + strbuf_setlen(&dst, strlen(dst.buf)); + strbuf_swap(src, &dst); + strbuf_release(&dst); + return 0; +} + /* * path = Canonical absolute path * prefixes = string_list containing normalized, absolute paths without |
