2828
2929typedef struct {
3030 int error_unmatch ;
31- git_array_t (char * ) files ;
31+ char * files [1024 ];
32+ int file_count ;
3233} ls_options ;
3334
3435/* Print a usage message for the program. */
@@ -46,10 +47,8 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
4647{
4748 int parsing_files = 0 ;
4849 int i ;
49- char * * file ;
5050
5151 memset (opts , 0 , sizeof (ls_options ));
52- git_array_init (opts -> files );
5352
5453 if (argc < 2 )
5554 return 0 ;
@@ -61,9 +60,12 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
6160 if (a [0 ] != '-' || parsing_files ) {
6261 parsing_files = 1 ;
6362
64- file = git_array_alloc (opts -> files );
65- GITERR_CHECK_ALLOC (file );
66- * file = a ;
63+ // watch for overflows (just in case)
64+ if (opts -> file_count == 1024 ) {
65+ break ;
66+ }
67+
68+ opts -> files [opts -> file_count ++ ] = a ;
6769 } else if (!strcmp (a , "--" )) {
6870 parsing_files = 1 ;
6971 } else if (!strcmp (a , "--error-unmatch" )) {
@@ -79,12 +81,12 @@ static int parse_options(ls_options *opts, int argc, char *argv[])
7981
8082static int print_paths (ls_options * opts , git_index * index )
8183{
82- size_t i ;
84+ int i ;
8385 const git_index_entry * entry ;
8486
8587 /* loop through the files found in the args and print them if they exist */
86- for (i = 0 ; i < git_array_size ( opts -> files ) ; ++ i ) {
87- const char * path = * ( char * * ) git_array_get ( opts -> files , i ) ;
88+ for (i = 0 ; i < opts -> file_count ; ++ i ) {
89+ const char * path = opts -> files [ i ] ;
8890
8991 entry = git_index_get_bypath (index , path , GIT_INDEX_STAGE_NORMAL );
9092 if (!entry && opts -> error_unmatch ) {
@@ -121,7 +123,7 @@ int main(int argc, char *argv[])
121123 goto cleanup ;
122124
123125 /* if there are files explicitly listed by the user, we need to treat this command differently */
124- if (git_array_size ( opts .files ) > 0 ) {
126+ if (opts .file_count > 0 ) {
125127 error = print_paths (& opts , index );
126128 } else {
127129 entry_count = git_index_entrycount (index );
@@ -133,7 +135,6 @@ int main(int argc, char *argv[])
133135 }
134136
135137cleanup :
136- git_array_clear (opts .files );
137138 git_index_free (index );
138139 git_repository_free (repo );
139140 git_libgit2_shutdown ();
0 commit comments