@@ -72,135 +72,6 @@ static char *get_default_remote(void)
72
72
return repo_get_default_remote (the_repository );
73
73
}
74
74
75
- /*
76
- * Returns 1 if it was the last chop before ':'.
77
- */
78
- static int chop_last_dir (char * * remoteurl , int is_relative )
79
- {
80
- char * rfind = find_last_dir_sep (* remoteurl );
81
- if (rfind ) {
82
- * rfind = '\0' ;
83
- return 0 ;
84
- }
85
-
86
- rfind = strrchr (* remoteurl , ':' );
87
- if (rfind ) {
88
- * rfind = '\0' ;
89
- return 1 ;
90
- }
91
-
92
- if (is_relative || !strcmp ("." , * remoteurl ))
93
- die (_ ("cannot strip one component off url '%s'" ),
94
- * remoteurl );
95
-
96
- free (* remoteurl );
97
- * remoteurl = xstrdup ("." );
98
- return 0 ;
99
- }
100
-
101
- static int starts_with_dot_slash (const char * const path )
102
- {
103
- return starts_with_dot_slash_native (path );;
104
- }
105
-
106
- static int starts_with_dot_dot_slash (const char * const path )
107
- {
108
- return starts_with_dot_dot_slash_native (path );
109
- }
110
-
111
- /*
112
- * The `url` argument is the URL that navigates to the submodule origin
113
- * repo. When relative, this URL is relative to the superproject origin
114
- * URL repo. The `up_path` argument, if specified, is the relative
115
- * path that navigates from the submodule working tree to the superproject
116
- * working tree. Returns the origin URL of the submodule.
117
- *
118
- * Return either an absolute URL or filesystem path (if the superproject
119
- * origin URL is an absolute URL or filesystem path, respectively) or a
120
- * relative file system path (if the superproject origin URL is a relative
121
- * file system path).
122
- *
123
- * When the output is a relative file system path, the path is either
124
- * relative to the submodule working tree, if up_path is specified, or to
125
- * the superproject working tree otherwise.
126
- *
127
- * NEEDSWORK: This works incorrectly on the domain and protocol part.
128
- * remote_url url outcome expectation
129
- * http://a.com/b ../c http://a.com/c as is
130
- * http://a.com/b/ ../c http://a.com/c same as previous line, but
131
- * ignore trailing slash in url
132
- * http://a.com/b ../../c http://c error out
133
- * http://a.com/b ../../../c http:/c error out
134
- * http://a.com/b ../../../../c http:c error out
135
- * http://a.com/b ../../../../../c .:c error out
136
- * NEEDSWORK: Given how chop_last_dir() works, this function is broken
137
- * when a local part has a colon in its path component, too.
138
- */
139
- static char * relative_url (const char * remote_url ,
140
- const char * url ,
141
- const char * up_path )
142
- {
143
- int is_relative = 0 ;
144
- int colonsep = 0 ;
145
- char * out ;
146
- char * remoteurl = xstrdup (remote_url );
147
- struct strbuf sb = STRBUF_INIT ;
148
- size_t len = strlen (remoteurl );
149
-
150
- if (is_dir_sep (remoteurl [len - 1 ]))
151
- remoteurl [len - 1 ] = '\0' ;
152
-
153
- if (!url_is_local_not_ssh (remoteurl ) || is_absolute_path (remoteurl ))
154
- is_relative = 0 ;
155
- else {
156
- is_relative = 1 ;
157
- /*
158
- * Prepend a './' to ensure all relative
159
- * remoteurls start with './' or '../'
160
- */
161
- if (!starts_with_dot_slash (remoteurl ) &&
162
- !starts_with_dot_dot_slash (remoteurl )) {
163
- strbuf_reset (& sb );
164
- strbuf_addf (& sb , "./%s" , remoteurl );
165
- free (remoteurl );
166
- remoteurl = strbuf_detach (& sb , NULL );
167
- }
168
- }
169
- /*
170
- * When the url starts with '../', remove that and the
171
- * last directory in remoteurl.
172
- */
173
- while (url ) {
174
- if (starts_with_dot_dot_slash (url )) {
175
- url += 3 ;
176
- colonsep |= chop_last_dir (& remoteurl , is_relative );
177
- } else if (starts_with_dot_slash (url ))
178
- url += 2 ;
179
- else
180
- break ;
181
- }
182
- strbuf_reset (& sb );
183
- strbuf_addf (& sb , "%s%s%s" , remoteurl , colonsep ? ":" : "/" , url );
184
- if (ends_with (url , "/" ))
185
- strbuf_setlen (& sb , sb .len - 1 );
186
- free (remoteurl );
187
-
188
- if (starts_with_dot_slash (sb .buf ))
189
- out = xstrdup (sb .buf + 2 );
190
- else
191
- out = xstrdup (sb .buf );
192
-
193
- if (!up_path || !is_relative ) {
194
- strbuf_release (& sb );
195
- return out ;
196
- }
197
-
198
- strbuf_reset (& sb );
199
- strbuf_addf (& sb , "%s%s" , up_path , out );
200
- free (out );
201
- return strbuf_detach (& sb , NULL );
202
- }
203
-
204
75
static char * resolve_relative_url (const char * rel_url , const char * up_path , int quiet )
205
76
{
206
77
char * remoteurl , * resolved_url ;
@@ -592,6 +463,18 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
592
463
return 0 ;
593
464
}
594
465
466
+ static int starts_with_dot_slash (const char * const path )
467
+ {
468
+ return path_match_flags (path , PATH_MATCH_STARTS_WITH_DOT_SLASH |
469
+ PATH_MATCH_XPLATFORM );
470
+ }
471
+
472
+ static int starts_with_dot_dot_slash (const char * const path )
473
+ {
474
+ return path_match_flags (path , PATH_MATCH_STARTS_WITH_DOT_DOT_SLASH |
475
+ PATH_MATCH_XPLATFORM );
476
+ }
477
+
595
478
struct init_cb {
596
479
const char * prefix ;
597
480
const char * superprefix ;
0 commit comments