@@ -320,6 +320,20 @@ static int name_terminate(const char *name, int namelen, int c, int terminate)
320
320
return 1 ;
321
321
}
322
322
323
+ /* remove double slashes to make --index work with such filenames */
324
+ static char * squash_slash (char * name )
325
+ {
326
+ int i = 0 , j = 0 ;
327
+
328
+ while (name [i ]) {
329
+ if ((name [j ++ ] = name [i ++ ]) == '/' )
330
+ while (name [i ] == '/' )
331
+ i ++ ;
332
+ }
333
+ name [j ] = '\0' ;
334
+ return name ;
335
+ }
336
+
323
337
static char * find_name (const char * line , char * def , int p_value , int terminate )
324
338
{
325
339
int len ;
@@ -349,7 +363,7 @@ static char *find_name(const char *line, char *def, int p_value, int terminate)
349
363
free (def );
350
364
if (root )
351
365
strbuf_insert (& name , 0 , root , root_len );
352
- return strbuf_detach (& name , NULL );
366
+ return squash_slash ( strbuf_detach (& name , NULL ) );
353
367
}
354
368
}
355
369
strbuf_release (& name );
@@ -369,10 +383,10 @@ static char *find_name(const char *line, char *def, int p_value, int terminate)
369
383
start = line ;
370
384
}
371
385
if (!start )
372
- return def ;
386
+ return squash_slash ( def ) ;
373
387
len = line - start ;
374
388
if (!len )
375
- return def ;
389
+ return squash_slash ( def ) ;
376
390
377
391
/*
378
392
* Generally we prefer the shorter name, especially
@@ -383,7 +397,7 @@ static char *find_name(const char *line, char *def, int p_value, int terminate)
383
397
if (def ) {
384
398
int deflen = strlen (def );
385
399
if (deflen < len && !strncmp (start , def , deflen ))
386
- return def ;
400
+ return squash_slash ( def ) ;
387
401
free (def );
388
402
}
389
403
@@ -392,10 +406,10 @@ static char *find_name(const char *line, char *def, int p_value, int terminate)
392
406
strcpy (ret , root );
393
407
memcpy (ret + root_len , start , len );
394
408
ret [root_len + len ] = '\0' ;
395
- return ret ;
409
+ return squash_slash ( ret ) ;
396
410
}
397
411
398
- return xmemdupz (start , len );
412
+ return squash_slash ( xmemdupz (start , len ) );
399
413
}
400
414
401
415
static int count_slashes (const char * cp )
0 commit comments