diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-07-06 21:54:46 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-07-06 21:54:46 +0300 |
commit | 67e7305e64fea8d15879e9dc3831fc8e31cfe619 (patch) | |
tree | d8ed9ee0a2b54f3df4619af5757d938bb5247986 /path.c | |
parent | da269af9207e38e820daad8aa993caa7d2fad76c (diff) | |
parent | 787cb8a48ae24ff07fa7c763909bb204bfdc84a7 (diff) |
Merge branch 'cw/strbuf-cleanup'
Move functions that are not about pure string manipulation out of
strbuf.[ch]
* cw/strbuf-cleanup:
strbuf: remove global variable
path: move related function to path
object-name: move related functions to object-name
credential-store: move related functions to credential-store file
abspath: move related functions to abspath
strbuf: clarify dependency
strbuf: clarify API boundary
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 |