File tree Expand file tree Collapse file tree 2 files changed +44
-15
lines changed Expand file tree Collapse file tree 2 files changed +44
-15
lines changed Original file line number Diff line number Diff line change @@ -508,21 +508,25 @@ void clear_exclude_list(struct exclude_list *el)
508
508
509
509
static void trim_trailing_spaces (char * buf )
510
510
{
511
- int i , last_space = -1 , nr_spaces , len = strlen (buf );
512
- for (i = 0 ; i < len ; i ++ )
513
- if (buf [i ] == '\\' )
514
- i ++ ;
515
- else if (buf [i ] == ' ' ) {
516
- if (last_space == -1 ) {
517
- last_space = i ;
518
- nr_spaces = 1 ;
519
- } else
520
- nr_spaces ++ ;
521
- } else
522
- last_space = -1 ;
523
-
524
- if (last_space != -1 && last_space + nr_spaces == len )
525
- buf [last_space ] = '\0' ;
511
+ char * p , * last_space = NULL ;
512
+
513
+ for (p = buf ; * p ; p ++ )
514
+ switch (* p ) {
515
+ case ' ' :
516
+ if (!last_space )
517
+ last_space = p ;
518
+ break ;
519
+ case '\\' :
520
+ p ++ ;
521
+ if (!* p )
522
+ return ;
523
+ /* fallthrough */
524
+ default :
525
+ last_space = NULL ;
526
+ }
527
+
528
+ if (last_space )
529
+ * last_space = '\0' ;
526
530
}
527
531
528
532
int add_excludes_from_file_to_list (const char * fname ,
Original file line number Diff line number Diff line change @@ -806,4 +806,29 @@ test_expect_success !MINGW 'quoting allows trailing whitespace' '
806
806
test_cmp err.expect err
807
807
'
808
808
809
+ test_expect_success NOT_MINGW,NOT_CYGWIN ' correct handling of backslashes' '
810
+ rm -rf whitespace &&
811
+ mkdir whitespace &&
812
+ >"whitespace/trailing 1 " &&
813
+ >"whitespace/trailing 2 \\\\" &&
814
+ >"whitespace/trailing 3 \\\\" &&
815
+ >"whitespace/trailing 4 \\ " &&
816
+ >"whitespace/trailing 5 \\ \\ " &&
817
+ >"whitespace/trailing 6 \\a\\" &&
818
+ >whitespace/untracked &&
819
+ sed -e "s/Z$//" >ignore <<-\EOF &&
820
+ whitespace/trailing 1 \ Z
821
+ whitespace/trailing 2 \\\\Z
822
+ whitespace/trailing 3 \\\\ Z
823
+ whitespace/trailing 4 \\\ Z
824
+ whitespace/trailing 5 \\ \\\ Z
825
+ whitespace/trailing 6 \\a\\Z
826
+ EOF
827
+ echo whitespace/untracked >expect &&
828
+ >err.expect &&
829
+ git ls-files -o -X ignore whitespace >actual 2>err &&
830
+ test_cmp expect actual &&
831
+ test_cmp err.expect err
832
+ '
833
+
809
834
test_done
You can’t perform that action at this time.
0 commit comments