wt-status: collect untracked files in a separate "collect" phase
In a way similar to updated and locally modified files are collected. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 10, 2009 at 00:36 UTC
7637868362ab64fe22521c645006ba70c4ef83a9
2 files changed
+38
-23
wt-status.c
+36
-22
@@ -41,6 +41,7 @@ void wt_status_prepare(struct wt_status *s)
41
s->fp = stdout;
42
s->index_file = get_index_file();
43
s->change.strdup_strings = 1;
44
+ s->untracked.strdup_strings = 1;
45
}
46
47
static void wt_status_print_unmerged_header(struct wt_status *s)
@@ -311,7 +312,30 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
312
}
313
}
314
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)
339
{
340
wt_status_collect_changes_worktree(s);
341
@@ -319,6 +343,7 @@ void wt_status_collect_changes(struct wt_status *s)
343
wt_status_collect_changes_initial(s);
344
else
345
wt_status_collect_changes_index(s);
346
+ wt_status_collect_untracked(s);
347
}
348
349
static void wt_status_print_unmerged(struct wt_status *s)
@@ -446,31 +471,20 @@ static void wt_status_print_submodule_summary(struct wt_status *s)
471
472
static void wt_status_print_untracked(struct wt_status *s)
473
{
449
- struct dir_struct dir;
474
int i;
451
- int shown_header = 0;
475
struct strbuf buf = STRBUF_INIT;
476
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;
479
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]);
484
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
485
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));
488
}
489
strbuf_release(&buf);
490
}
@@ -539,7 +553,7 @@ void wt_status_print(struct wt_status *s)
553
wt_status_print_tracking(s);
554
}
555
542
- wt_status_collect_changes(s);
556
+ wt_status_collect(s);
557
558
if (s->is_initial) {
559
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
@@ -566,7 +580,7 @@ void wt_status_print(struct wt_status *s)
580
; /* nothing */
581
else if (s->workdir_dirty)
582
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)
584
printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
585
else if (s->is_initial)
586
printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
wt-status.h
+2
-1
@@ -48,10 +48,11 @@ struct wt_status {
48
FILE *fp;
49
const char *prefix;
50
struct string_list change;
51
+ struct string_list untracked;
52
};
53
54
void wt_status_prepare(struct wt_status *s);
55
void wt_status_print(struct wt_status *s);
55
-void wt_status_collect_changes(struct wt_status *s);
56
+void wt_status_collect(struct wt_status *s);
57
58
#endif /* STATUS_H */