File tree Expand file tree Collapse file tree 3 files changed +25
-21
lines changed
Expand file tree Collapse file tree 3 files changed +25
-21
lines changed Original file line number Diff line number Diff line change @@ -1213,6 +1213,26 @@ int normalize_path_copy(char *dst, const char *src)
12131213 return normalize_path_copy_len (dst , src , NULL );
12141214}
12151215
1216+ int strbuf_normalize_path (struct strbuf * src )
1217+ {
1218+ struct strbuf dst = STRBUF_INIT ;
1219+
1220+ strbuf_grow (& dst , src -> len );
1221+ if (normalize_path_copy (dst .buf , src -> buf ) < 0 ) {
1222+ strbuf_release (& dst );
1223+ return -1 ;
1224+ }
1225+
1226+ /*
1227+ * normalize_path does not tell us the new length, so we have to
1228+ * compute it by looking for the new NUL it placed
1229+ */
1230+ strbuf_setlen (& dst , strlen (dst .buf ));
1231+ strbuf_swap (src , & dst );
1232+ strbuf_release (& dst );
1233+ return 0 ;
1234+ }
1235+
12161236/*
12171237 * path = Canonical absolute path
12181238 * prefixes = string_list containing normalized, absolute paths without
Original file line number Diff line number Diff line change @@ -191,6 +191,11 @@ const char *remove_leading_path(const char *in, const char *prefix);
191191const char * relative_path (const char * in , const char * prefix , struct strbuf * sb );
192192int normalize_path_copy_len (char * dst , const char * src , int * prefix_len );
193193int normalize_path_copy (char * dst , const char * src );
194+ /**
195+ * Normalize in-place the path contained in the strbuf. If an error occurs,
196+ * the contents of "sb" are left untouched, and -1 is returned.
197+ */
198+ int strbuf_normalize_path (struct strbuf * src );
194199int longest_ancestor_length (const char * path , struct string_list * prefixes );
195200char * strip_path_suffix (const char * path , const char * suffix );
196201int daemon_avoid_alias (const char * path );
Original file line number Diff line number Diff line change 33#include "environment.h"
44#include "gettext.h"
55#include "hex.h"
6- #include "repository.h"
76#include "strbuf.h"
87#include "string-list.h"
98#include "utf8.h"
@@ -1089,26 +1088,6 @@ void strbuf_stripspace(struct strbuf *sb, int skip_comments)
10891088 strbuf_setlen (sb , j );
10901089}
10911090
1092- int strbuf_normalize_path (struct strbuf * src )
1093- {
1094- struct strbuf dst = STRBUF_INIT ;
1095-
1096- strbuf_grow (& dst , src -> len );
1097- if (normalize_path_copy (dst .buf , src -> buf ) < 0 ) {
1098- strbuf_release (& dst );
1099- return -1 ;
1100- }
1101-
1102- /*
1103- * normalize_path does not tell us the new length, so we have to
1104- * compute it by looking for the new NUL it placed
1105- */
1106- strbuf_setlen (& dst , strlen (dst .buf ));
1107- strbuf_swap (src , & dst );
1108- strbuf_release (& dst );
1109- return 0 ;
1110- }
1111-
11121091void strbuf_strip_file_from_path (struct strbuf * sb )
11131092{
11141093 char * path_sep = find_last_dir_sep (sb -> buf );
You can’t perform that action at this time.
0 commit comments