@@ -14,8 +14,7 @@ struct path_simplify {
14
14
const char * path ;
15
15
};
16
16
17
- static int read_directory_recursive (struct dir_struct * dir ,
18
- const char * path , const char * base , int baselen ,
17
+ static int read_directory_recursive (struct dir_struct * dir , const char * path , int len ,
19
18
int check_only , const struct path_simplify * simplify );
20
19
static int get_dtype (struct dirent * de , const char * path );
21
20
@@ -54,23 +53,22 @@ static int common_prefix(const char **pathspec)
54
53
55
54
int fill_directory (struct dir_struct * dir , const char * * pathspec )
56
55
{
57
- const char * path , * base ;
58
- int baselen ;
56
+ const char * path ;
57
+ int len ;
59
58
60
59
/*
61
60
* Calculate common prefix for the pathspec, and
62
61
* use that to optimize the directory walk
63
62
*/
64
- baselen = common_prefix (pathspec );
63
+ len = common_prefix (pathspec );
65
64
path = "" ;
66
- base = "" ;
67
65
68
- if (baselen )
69
- path = base = xmemdupz (* pathspec , baselen );
66
+ if (len )
67
+ path = xmemdupz (* pathspec , len );
70
68
71
69
/* Read the directory and prune it */
72
- read_directory (dir , path , base , baselen , pathspec );
73
- return baselen ;
70
+ read_directory (dir , path , len , pathspec );
71
+ return len ;
74
72
}
75
73
76
74
/*
@@ -526,7 +524,7 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
526
524
/* This is the "show_other_directories" case */
527
525
if (!(dir -> flags & DIR_HIDE_EMPTY_DIRECTORIES ))
528
526
return show_directory ;
529
- if (!read_directory_recursive (dir , dirname , dirname , len , 1 , simplify ))
527
+ if (!read_directory_recursive (dir , dirname , len , 1 , simplify ))
530
528
return ignore_directory ;
531
529
return show_directory ;
532
530
}
@@ -595,15 +593,15 @@ static int get_dtype(struct dirent *de, const char *path)
595
593
* Also, we ignore the name ".git" (even if it is not a directory).
596
594
* That likely will not change.
597
595
*/
598
- static int read_directory_recursive (struct dir_struct * dir , const char * path , const char * base , int baselen , int check_only , const struct path_simplify * simplify )
596
+ static int read_directory_recursive (struct dir_struct * dir , const char * base , int baselen , int check_only , const struct path_simplify * simplify )
599
597
{
600
- DIR * fdir = opendir (* path ? path : "." );
598
+ DIR * fdir = opendir (* base ? base : "." );
601
599
int contents = 0 ;
602
600
603
601
if (fdir ) {
604
602
struct dirent * de ;
605
- char fullname [PATH_MAX + 1 ];
606
- memcpy (fullname , base , baselen );
603
+ char path [PATH_MAX + 1 ];
604
+ memcpy (path , base , baselen );
607
605
608
606
while ((de = readdir (fdir )) != NULL ) {
609
607
int len , dtype ;
@@ -614,17 +612,18 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
614
612
continue ;
615
613
len = strlen (de -> d_name );
616
614
/* Ignore overly long pathnames! */
617
- if (len + baselen + 8 > sizeof (fullname ))
615
+ if (len + baselen + 8 > sizeof (path ))
618
616
continue ;
619
- memcpy (fullname + baselen , de -> d_name , len + 1 );
620
- if (simplify_away (fullname , baselen + len , simplify ))
617
+ memcpy (path + baselen , de -> d_name , len + 1 );
618
+ len = baselen + len ;
619
+ if (simplify_away (path , len , simplify ))
621
620
continue ;
622
621
623
622
dtype = DTYPE (de );
624
- exclude = excluded (dir , fullname , & dtype );
623
+ exclude = excluded (dir , path , & dtype );
625
624
if (exclude && (dir -> flags & DIR_COLLECT_IGNORED )
626
- && in_pathspec (fullname , baselen + len , simplify ))
627
- dir_add_ignored (dir , fullname , baselen + len );
625
+ && in_pathspec (path , len , simplify ))
626
+ dir_add_ignored (dir , path , len );
628
627
629
628
/*
630
629
* Excluded? If we don't explicitly want to show
@@ -634,7 +633,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
634
633
continue ;
635
634
636
635
if (dtype == DT_UNKNOWN )
637
- dtype = get_dtype (de , fullname );
636
+ dtype = get_dtype (de , path );
638
637
639
638
/*
640
639
* Do we want to see just the ignored files?
@@ -651,17 +650,17 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
651
650
default :
652
651
continue ;
653
652
case DT_DIR :
654
- memcpy (fullname + baselen + len , "/" , 2 );
653
+ memcpy (path + len , "/" , 2 );
655
654
len ++ ;
656
- switch (treat_directory (dir , fullname , baselen + len , simplify )) {
655
+ switch (treat_directory (dir , path , len , simplify )) {
657
656
case show_directory :
658
657
if (exclude != !!(dir -> flags
659
658
& DIR_SHOW_IGNORED ))
660
659
continue ;
661
660
break ;
662
661
case recurse_into_directory :
663
662
contents += read_directory_recursive (dir ,
664
- fullname , fullname , baselen + len , 0 , simplify );
663
+ path , len , 0 , simplify );
665
664
continue ;
666
665
case ignore_directory :
667
666
continue ;
@@ -675,7 +674,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
675
674
if (check_only )
676
675
goto exit_early ;
677
676
else
678
- dir_add_name (dir , fullname , baselen + len );
677
+ dir_add_name (dir , path , len );
679
678
}
680
679
exit_early :
681
680
closedir (fdir );
@@ -738,15 +737,15 @@ static void free_simplify(struct path_simplify *simplify)
738
737
free (simplify );
739
738
}
740
739
741
- int read_directory (struct dir_struct * dir , const char * path , const char * base , int baselen , const char * * pathspec )
740
+ int read_directory (struct dir_struct * dir , const char * path , int len , const char * * pathspec )
742
741
{
743
742
struct path_simplify * simplify ;
744
743
745
- if (has_symlink_leading_path (path , strlen ( path ) ))
744
+ if (has_symlink_leading_path (path , len ))
746
745
return dir -> nr ;
747
746
748
747
simplify = create_simplify (pathspec );
749
- read_directory_recursive (dir , path , base , baselen , 0 , simplify );
748
+ read_directory_recursive (dir , path , len , 0 , simplify );
750
749
free_simplify (simplify );
751
750
qsort (dir -> entries , dir -> nr , sizeof (struct dir_entry * ), cmp_name );
752
751
qsort (dir -> ignored , dir -> ignored_nr , sizeof (struct dir_entry * ), cmp_name );
0 commit comments