@@ -217,120 +217,6 @@ static char *get_repo_path(const char *repo, int *is_bundle)
217
217
return canon ;
218
218
}
219
219
220
- static char * guess_dir_name (const char * repo , int is_bundle , int is_bare )
221
- {
222
- const char * end = repo + strlen (repo ), * start , * ptr ;
223
- size_t len ;
224
- char * dir ;
225
-
226
- /*
227
- * Skip scheme.
228
- */
229
- start = strstr (repo , "://" );
230
- if (start == NULL )
231
- start = repo ;
232
- else
233
- start += 3 ;
234
-
235
- /*
236
- * Skip authentication data. The stripping does happen
237
- * greedily, such that we strip up to the last '@' inside
238
- * the host part.
239
- */
240
- for (ptr = start ; ptr < end && !is_dir_sep (* ptr ); ptr ++ ) {
241
- if (* ptr == '@' )
242
- start = ptr + 1 ;
243
- }
244
-
245
- /*
246
- * Strip trailing spaces, slashes and /.git
247
- */
248
- while (start < end && (is_dir_sep (end [-1 ]) || isspace (end [-1 ])))
249
- end -- ;
250
- if (end - start > 5 && is_dir_sep (end [-5 ]) &&
251
- !strncmp (end - 4 , ".git" , 4 )) {
252
- end -= 5 ;
253
- while (start < end && is_dir_sep (end [-1 ]))
254
- end -- ;
255
- }
256
-
257
- /*
258
- * Strip trailing port number if we've got only a
259
- * hostname (that is, there is no dir separator but a
260
- * colon). This check is required such that we do not
261
- * strip URI's like '/foo/bar:2222.git', which should
262
- * result in a dir '2222' being guessed due to backwards
263
- * compatibility.
264
- */
265
- if (memchr (start , '/' , end - start ) == NULL
266
- && memchr (start , ':' , end - start ) != NULL ) {
267
- ptr = end ;
268
- while (start < ptr && isdigit (ptr [-1 ]) && ptr [-1 ] != ':' )
269
- ptr -- ;
270
- if (start < ptr && ptr [-1 ] == ':' )
271
- end = ptr - 1 ;
272
- }
273
-
274
- /*
275
- * Find last component. To remain backwards compatible we
276
- * also regard colons as path separators, such that
277
- * cloning a repository 'foo:bar.git' would result in a
278
- * directory 'bar' being guessed.
279
- */
280
- ptr = end ;
281
- while (start < ptr && !is_dir_sep (ptr [-1 ]) && ptr [-1 ] != ':' )
282
- ptr -- ;
283
- start = ptr ;
284
-
285
- /*
286
- * Strip .{bundle,git}.
287
- */
288
- len = end - start ;
289
- strip_suffix_mem (start , & len , is_bundle ? ".bundle" : ".git" );
290
-
291
- if (!len || (len == 1 && * start == '/' ))
292
- die (_ ("No directory name could be guessed.\n"
293
- "Please specify a directory on the command line" ));
294
-
295
- if (is_bare )
296
- dir = xstrfmt ("%.*s.git" , (int )len , start );
297
- else
298
- dir = xstrndup (start , len );
299
- /*
300
- * Replace sequences of 'control' characters and whitespace
301
- * with one ascii space, remove leading and trailing spaces.
302
- */
303
- if (* dir ) {
304
- char * out = dir ;
305
- int prev_space = 1 /* strip leading whitespace */ ;
306
- for (end = dir ; * end ; ++ end ) {
307
- char ch = * end ;
308
- if ((unsigned char )ch < '\x20' )
309
- ch = '\x20' ;
310
- if (isspace (ch )) {
311
- if (prev_space )
312
- continue ;
313
- prev_space = 1 ;
314
- } else
315
- prev_space = 0 ;
316
- * out ++ = ch ;
317
- }
318
- * out = '\0' ;
319
- if (out > dir && prev_space )
320
- out [-1 ] = '\0' ;
321
- }
322
- return dir ;
323
- }
324
-
325
- static void strip_trailing_slashes (char * dir )
326
- {
327
- char * end = dir + strlen (dir );
328
-
329
- while (dir < end - 1 && is_dir_sep (end [-1 ]))
330
- end -- ;
331
- * end = '\0' ;
332
- }
333
-
334
220
static int add_one_reference (struct string_list_item * item , void * cb_data )
335
221
{
336
222
struct strbuf err = STRBUF_INIT ;
@@ -1039,8 +925,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1039
925
if (argc == 2 )
1040
926
dir = xstrdup (argv [1 ]);
1041
927
else
1042
- dir = guess_dir_name (repo_name , is_bundle , option_bare );
1043
- strip_trailing_slashes (dir );
928
+ dir = git_url_basename (repo_name , is_bundle , option_bare );
929
+ strip_dir_trailing_slashes (dir );
1044
930
1045
931
dest_exists = path_exists (dir );
1046
932
if (dest_exists && !is_empty_dir (dir ))
0 commit comments