@@ -41,6 +41,7 @@ void wt_status_prepare(struct wt_status *s)
4141 s -> fp = stdout ;
4242 s -> index_file = get_index_file ();
4343 s -> change .strdup_strings = 1 ;
44+ s -> untracked .strdup_strings = 1 ;
4445}
4546
4647static void wt_status_print_unmerged_header (struct wt_status * s )
@@ -311,14 +312,38 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
311312 }
312313}
313314
314- void wt_status_collect_changes (struct wt_status * s )
315+ static void wt_status_collect_untracked (struct wt_status * s )
316+ {
317+ int i ;
318+ struct dir_struct dir ;
319+
320+ if (!s -> show_untracked_files )
321+ return ;
322+ memset (& dir , 0 , sizeof (dir ));
323+ if (s -> show_untracked_files != SHOW_ALL_UNTRACKED_FILES )
324+ dir .flags |=
325+ DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES ;
326+ setup_standard_excludes (& dir );
327+
328+ fill_directory (& dir , NULL );
329+ for (i = 0 ; i < dir .nr ; i ++ ) {
330+ struct dir_entry * ent = dir .entries [i ];
331+ if (!cache_name_is_other (ent -> name , ent -> len ))
332+ continue ;
333+ s -> workdir_untracked = 1 ;
334+ string_list_insert (ent -> name , & s -> untracked );
335+ }
336+ }
337+
338+ void wt_status_collect (struct wt_status * s )
315339{
316340 wt_status_collect_changes_worktree (s );
317341
318342 if (s -> is_initial )
319343 wt_status_collect_changes_initial (s );
320344 else
321345 wt_status_collect_changes_index (s );
346+ wt_status_collect_untracked (s );
322347}
323348
324349static void wt_status_print_unmerged (struct wt_status * s )
@@ -446,31 +471,20 @@ static void wt_status_print_submodule_summary(struct wt_status *s)
446471
447472static void wt_status_print_untracked (struct wt_status * s )
448473{
449- struct dir_struct dir ;
450474 int i ;
451- int shown_header = 0 ;
452475 struct strbuf buf = STRBUF_INIT ;
453476
454- memset (& dir , 0 , sizeof (dir ));
455- if (s -> show_untracked_files != SHOW_ALL_UNTRACKED_FILES )
456- dir .flags |=
457- DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES ;
458- setup_standard_excludes (& dir );
477+ if (!s -> untracked .nr )
478+ return ;
459479
460- fill_directory (& dir , NULL );
461- for (i = 0 ; i < dir .nr ; i ++ ) {
462- struct dir_entry * ent = dir .entries [i ];
463- if (!cache_name_is_other (ent -> name , ent -> len ))
464- continue ;
465- if (!shown_header ) {
466- s -> workdir_untracked = 1 ;
467- wt_status_print_untracked_header (s );
468- shown_header = 1 ;
469- }
480+ wt_status_print_untracked_header (s );
481+ for (i = 0 ; i < s -> untracked .nr ; i ++ ) {
482+ struct string_list_item * it ;
483+ it = & (s -> untracked .items [i ]);
470484 color_fprintf (s -> fp , color (WT_STATUS_HEADER , s ), "#\t" );
471485 color_fprintf_ln (s -> fp , color (WT_STATUS_UNTRACKED , s ), "%s" ,
472- quote_path (ent -> name , ent -> len ,
473- & buf , s -> prefix ));
486+ quote_path (it -> string , strlen ( it -> string ) ,
487+ & buf , s -> prefix ));
474488 }
475489 strbuf_release (& buf );
476490}
@@ -539,7 +553,7 @@ void wt_status_print(struct wt_status *s)
539553 wt_status_print_tracking (s );
540554 }
541555
542- wt_status_collect_changes (s );
556+ wt_status_collect (s );
543557
544558 if (s -> is_initial ) {
545559 color_fprintf_ln (s -> fp , color (WT_STATUS_HEADER , s ), "#" );
@@ -566,7 +580,7 @@ void wt_status_print(struct wt_status *s)
566580 ; /* nothing */
567581 else if (s -> workdir_dirty )
568582 printf ("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n" );
569- else if (s -> workdir_untracked )
583+ else if (s -> untracked . nr )
570584 printf ("nothing added to commit but untracked files present (use \"git add\" to track)\n" );
571585 else if (s -> is_initial )
572586 printf ("nothing to commit (create/copy files and use \"git add\" to track)\n" );
0 commit comments