Merge branch 'mc/maint-zoneparse' into next
[git/dscho.git] / wt-status.c
blobfd423c1c3f8c0a40dcf8c28711e6a767d9533674
1 #include "cache.h"
2 #include "wt-status.h"
3 #include "object.h"
4 #include "dir.h"
5 #include "commit.h"
6 #include "diff.h"
7 #include "revision.h"
8 #include "diffcore.h"
9 #include "quote.h"
10 #include "run-command.h"
11 #include "remote.h"
13 static char default_wt_status_colors[][COLOR_MAXLEN] = {
14 GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
15 GIT_COLOR_GREEN, /* WT_STATUS_UPDATED */
16 GIT_COLOR_RED, /* WT_STATUS_CHANGED */
17 GIT_COLOR_RED, /* WT_STATUS_UNTRACKED */
18 GIT_COLOR_RED, /* WT_STATUS_NOBRANCH */
19 GIT_COLOR_RED, /* WT_STATUS_UNMERGED */
22 static const char *color(int slot, struct wt_status *s)
24 return s->use_color > 0 ? s->color_palette[slot] : "";
27 void wt_status_prepare(struct wt_status *s)
29 unsigned char sha1[20];
30 const char *head;
32 memset(s, 0, sizeof(*s));
33 memcpy(s->color_palette, default_wt_status_colors,
34 sizeof(default_wt_status_colors));
35 s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
36 s->use_color = -1;
37 s->relative_paths = 1;
38 head = resolve_ref("HEAD", sha1, 0, NULL);
39 s->branch = head ? xstrdup(head) : NULL;
40 s->reference = "HEAD";
41 s->fp = stdout;
42 s->index_file = get_index_file();
43 s->change.strdup_strings = 1;
44 s->untracked.strdup_strings = 1;
45 s->ignored.strdup_strings = 1;
48 static void wt_status_print_unmerged_header(struct wt_status *s)
50 const char *c = color(WT_STATUS_HEADER, s);
52 color_fprintf_ln(s->fp, c, "# Unmerged paths:");
53 if (!advice_status_hints)
54 return;
55 if (s->in_merge)
57 else if (!s->is_initial)
58 color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
59 else
60 color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
61 color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" as appropriate to mark resolution)");
62 color_fprintf_ln(s->fp, c, "#");
65 static void wt_status_print_cached_header(struct wt_status *s)
67 const char *c = color(WT_STATUS_HEADER, s);
69 color_fprintf_ln(s->fp, c, "# Changes to be committed:");
70 if (!advice_status_hints)
71 return;
72 if (s->in_merge)
73 ; /* NEEDSWORK: use "git reset --unresolve"??? */
74 else if (!s->is_initial)
75 color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
76 else
77 color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
78 color_fprintf_ln(s->fp, c, "#");
81 static void wt_status_print_dirty_header(struct wt_status *s,
82 int has_deleted,
83 int has_dirty_submodules)
85 const char *c = color(WT_STATUS_HEADER, s);
87 color_fprintf_ln(s->fp, c, "# Changed but not updated:");
88 if (!advice_status_hints)
89 return;
90 if (!has_deleted)
91 color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to update what will be committed)");
92 else
93 color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" to update what will be committed)");
94 color_fprintf_ln(s->fp, c, "# (use \"git checkout -- <file>...\" to discard changes in working directory)");
95 if (has_dirty_submodules)
96 color_fprintf_ln(s->fp, c, "# (commit or discard the untracked or modified content in submodules)");
97 color_fprintf_ln(s->fp, c, "#");
100 static void wt_status_print_other_header(struct wt_status *s,
101 const char *what,
102 const char *how)
104 const char *c = color(WT_STATUS_HEADER, s);
105 color_fprintf_ln(s->fp, c, "# %s files:", what);
106 if (!advice_status_hints)
107 return;
108 color_fprintf_ln(s->fp, c, "# (use \"git %s <file>...\" to include in what will be committed)", how);
109 color_fprintf_ln(s->fp, c, "#");
112 static void wt_status_print_trailer(struct wt_status *s)
114 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
117 #define quote_path quote_path_relative
119 static void wt_status_print_unmerged_data(struct wt_status *s,
120 struct string_list_item *it)
122 const char *c = color(WT_STATUS_UNMERGED, s);
123 struct wt_status_change_data *d = it->util;
124 struct strbuf onebuf = STRBUF_INIT;
125 const char *one, *how = "bug";
127 one = quote_path(it->string, -1, &onebuf, s->prefix);
128 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
129 switch (d->stagemask) {
130 case 1: how = "both deleted:"; break;
131 case 2: how = "added by us:"; break;
132 case 3: how = "deleted by them:"; break;
133 case 4: how = "added by them:"; break;
134 case 5: how = "deleted by us:"; break;
135 case 6: how = "both added:"; break;
136 case 7: how = "both modified:"; break;
138 color_fprintf(s->fp, c, "%-20s%s\n", how, one);
139 strbuf_release(&onebuf);
142 static void wt_status_print_change_data(struct wt_status *s,
143 int change_type,
144 struct string_list_item *it)
146 struct wt_status_change_data *d = it->util;
147 const char *c = color(change_type, s);
148 int status = status;
149 char *one_name;
150 char *two_name;
151 const char *one, *two;
152 struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
153 struct strbuf extra = STRBUF_INIT;
155 one_name = two_name = it->string;
156 switch (change_type) {
157 case WT_STATUS_UPDATED:
158 status = d->index_status;
159 if (d->head_path)
160 one_name = d->head_path;
161 break;
162 case WT_STATUS_CHANGED:
163 if (d->new_submodule_commits || d->dirty_submodule) {
164 strbuf_addstr(&extra, " (");
165 if (d->new_submodule_commits)
166 strbuf_addf(&extra, "new commits, ");
167 if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
168 strbuf_addf(&extra, "modified content, ");
169 if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
170 strbuf_addf(&extra, "untracked content, ");
171 strbuf_setlen(&extra, extra.len - 2);
172 strbuf_addch(&extra, ')');
174 status = d->worktree_status;
175 break;
178 one = quote_path(one_name, -1, &onebuf, s->prefix);
179 two = quote_path(two_name, -1, &twobuf, s->prefix);
181 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
182 switch (status) {
183 case DIFF_STATUS_ADDED:
184 color_fprintf(s->fp, c, "new file: %s", one);
185 break;
186 case DIFF_STATUS_COPIED:
187 color_fprintf(s->fp, c, "copied: %s -> %s", one, two);
188 break;
189 case DIFF_STATUS_DELETED:
190 color_fprintf(s->fp, c, "deleted: %s", one);
191 break;
192 case DIFF_STATUS_MODIFIED:
193 color_fprintf(s->fp, c, "modified: %s", one);
194 break;
195 case DIFF_STATUS_RENAMED:
196 color_fprintf(s->fp, c, "renamed: %s -> %s", one, two);
197 break;
198 case DIFF_STATUS_TYPE_CHANGED:
199 color_fprintf(s->fp, c, "typechange: %s", one);
200 break;
201 case DIFF_STATUS_UNKNOWN:
202 color_fprintf(s->fp, c, "unknown: %s", one);
203 break;
204 case DIFF_STATUS_UNMERGED:
205 color_fprintf(s->fp, c, "unmerged: %s", one);
206 break;
207 default:
208 die("bug: unhandled diff status %c", status);
210 if (extra.len) {
211 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf);
212 strbuf_release(&extra);
214 fprintf(s->fp, "\n");
215 strbuf_release(&onebuf);
216 strbuf_release(&twobuf);
219 static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
220 struct diff_options *options,
221 void *data)
223 struct wt_status *s = data;
224 int i;
226 if (!q->nr)
227 return;
228 s->workdir_dirty = 1;
229 for (i = 0; i < q->nr; i++) {
230 struct diff_filepair *p;
231 struct string_list_item *it;
232 struct wt_status_change_data *d;
234 p = q->queue[i];
235 it = string_list_insert(p->one->path, &s->change);
236 d = it->util;
237 if (!d) {
238 d = xcalloc(1, sizeof(*d));
239 it->util = d;
241 if (!d->worktree_status)
242 d->worktree_status = p->status;
243 d->dirty_submodule = p->two->dirty_submodule;
244 if (S_ISGITLINK(p->two->mode))
245 d->new_submodule_commits = !!hashcmp(p->one->sha1, p->two->sha1);
249 static int unmerged_mask(const char *path)
251 int pos, mask;
252 struct cache_entry *ce;
254 pos = cache_name_pos(path, strlen(path));
255 if (0 <= pos)
256 return 0;
258 mask = 0;
259 pos = -pos-1;
260 while (pos < active_nr) {
261 ce = active_cache[pos++];
262 if (strcmp(ce->name, path) || !ce_stage(ce))
263 break;
264 mask |= (1 << (ce_stage(ce) - 1));
266 return mask;
269 static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
270 struct diff_options *options,
271 void *data)
273 struct wt_status *s = data;
274 int i;
276 for (i = 0; i < q->nr; i++) {
277 struct diff_filepair *p;
278 struct string_list_item *it;
279 struct wt_status_change_data *d;
281 p = q->queue[i];
282 it = string_list_insert(p->two->path, &s->change);
283 d = it->util;
284 if (!d) {
285 d = xcalloc(1, sizeof(*d));
286 it->util = d;
288 if (!d->index_status)
289 d->index_status = p->status;
290 switch (p->status) {
291 case DIFF_STATUS_COPIED:
292 case DIFF_STATUS_RENAMED:
293 d->head_path = xstrdup(p->one->path);
294 break;
295 case DIFF_STATUS_UNMERGED:
296 d->stagemask = unmerged_mask(p->two->path);
297 break;
302 static void wt_status_collect_changes_worktree(struct wt_status *s)
304 struct rev_info rev;
306 init_revisions(&rev, NULL);
307 setup_revisions(0, NULL, &rev, NULL);
308 rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
309 DIFF_OPT_SET(&rev.diffopt, DIRTY_SUBMODULES);
310 if (!s->show_untracked_files)
311 DIFF_OPT_SET(&rev.diffopt, IGNORE_UNTRACKED_IN_SUBMODULES);
312 rev.diffopt.format_callback = wt_status_collect_changed_cb;
313 rev.diffopt.format_callback_data = s;
314 rev.prune_data = s->pathspec;
315 run_diff_files(&rev, 0);
318 static void wt_status_collect_changes_index(struct wt_status *s)
320 struct rev_info rev;
321 struct setup_revision_opt opt;
323 init_revisions(&rev, NULL);
324 memset(&opt, 0, sizeof(opt));
325 opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
326 setup_revisions(0, NULL, &rev, &opt);
328 rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
329 rev.diffopt.format_callback = wt_status_collect_updated_cb;
330 rev.diffopt.format_callback_data = s;
331 rev.diffopt.detect_rename = 1;
332 rev.diffopt.rename_limit = 200;
333 rev.diffopt.break_opt = 0;
334 rev.prune_data = s->pathspec;
335 run_diff_index(&rev, 1);
338 static void wt_status_collect_changes_initial(struct wt_status *s)
340 int i;
342 for (i = 0; i < active_nr; i++) {
343 struct string_list_item *it;
344 struct wt_status_change_data *d;
345 struct cache_entry *ce = active_cache[i];
347 if (!ce_path_match(ce, s->pathspec))
348 continue;
349 it = string_list_insert(ce->name, &s->change);
350 d = it->util;
351 if (!d) {
352 d = xcalloc(1, sizeof(*d));
353 it->util = d;
355 if (ce_stage(ce)) {
356 d->index_status = DIFF_STATUS_UNMERGED;
357 d->stagemask |= (1 << (ce_stage(ce) - 1));
359 else
360 d->index_status = DIFF_STATUS_ADDED;
364 static void wt_status_collect_untracked(struct wt_status *s)
366 int i;
367 struct dir_struct dir;
369 if (!s->show_untracked_files)
370 return;
371 memset(&dir, 0, sizeof(dir));
372 if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
373 dir.flags |=
374 DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
375 setup_standard_excludes(&dir);
377 fill_directory(&dir, s->pathspec);
378 for (i = 0; i < dir.nr; i++) {
379 struct dir_entry *ent = dir.entries[i];
380 if (!cache_name_is_other(ent->name, ent->len))
381 continue;
382 if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
383 continue;
384 string_list_insert(ent->name, &s->untracked);
385 free(ent);
388 if (s->show_ignored_files) {
389 dir.nr = 0;
390 dir.flags = DIR_SHOW_IGNORED | DIR_SHOW_OTHER_DIRECTORIES;
391 fill_directory(&dir, s->pathspec);
392 for (i = 0; i < dir.nr; i++) {
393 struct dir_entry *ent = dir.entries[i];
394 if (!cache_name_is_other(ent->name, ent->len))
395 continue;
396 if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
397 continue;
398 string_list_insert(ent->name, &s->ignored);
399 free(ent);
403 free(dir.entries);
406 void wt_status_collect(struct wt_status *s)
408 wt_status_collect_changes_worktree(s);
410 if (s->is_initial)
411 wt_status_collect_changes_initial(s);
412 else
413 wt_status_collect_changes_index(s);
414 wt_status_collect_untracked(s);
417 static void wt_status_print_unmerged(struct wt_status *s)
419 int shown_header = 0;
420 int i;
422 for (i = 0; i < s->change.nr; i++) {
423 struct wt_status_change_data *d;
424 struct string_list_item *it;
425 it = &(s->change.items[i]);
426 d = it->util;
427 if (!d->stagemask)
428 continue;
429 if (!shown_header) {
430 wt_status_print_unmerged_header(s);
431 shown_header = 1;
433 wt_status_print_unmerged_data(s, it);
435 if (shown_header)
436 wt_status_print_trailer(s);
440 static void wt_status_print_updated(struct wt_status *s)
442 int shown_header = 0;
443 int i;
445 for (i = 0; i < s->change.nr; i++) {
446 struct wt_status_change_data *d;
447 struct string_list_item *it;
448 it = &(s->change.items[i]);
449 d = it->util;
450 if (!d->index_status ||
451 d->index_status == DIFF_STATUS_UNMERGED)
452 continue;
453 if (!shown_header) {
454 wt_status_print_cached_header(s);
455 s->commitable = 1;
456 shown_header = 1;
458 wt_status_print_change_data(s, WT_STATUS_UPDATED, it);
460 if (shown_header)
461 wt_status_print_trailer(s);
465 * -1 : has delete
466 * 0 : no change
467 * 1 : some change but no delete
469 static int wt_status_check_worktree_changes(struct wt_status *s,
470 int *dirty_submodules)
472 int i;
473 int changes = 0;
475 *dirty_submodules = 0;
477 for (i = 0; i < s->change.nr; i++) {
478 struct wt_status_change_data *d;
479 d = s->change.items[i].util;
480 if (!d->worktree_status ||
481 d->worktree_status == DIFF_STATUS_UNMERGED)
482 continue;
483 if (!changes)
484 changes = 1;
485 if (d->dirty_submodule)
486 *dirty_submodules = 1;
487 if (d->worktree_status == DIFF_STATUS_DELETED)
488 changes = -1;
490 return changes;
493 static void wt_status_print_changed(struct wt_status *s)
495 int i, dirty_submodules;
496 int worktree_changes = wt_status_check_worktree_changes(s, &dirty_submodules);
498 if (!worktree_changes)
499 return;
501 wt_status_print_dirty_header(s, worktree_changes < 0, dirty_submodules);
503 for (i = 0; i < s->change.nr; i++) {
504 struct wt_status_change_data *d;
505 struct string_list_item *it;
506 it = &(s->change.items[i]);
507 d = it->util;
508 if (!d->worktree_status ||
509 d->worktree_status == DIFF_STATUS_UNMERGED)
510 continue;
511 wt_status_print_change_data(s, WT_STATUS_CHANGED, it);
513 wt_status_print_trailer(s);
516 static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitted)
518 struct child_process sm_summary;
519 char summary_limit[64];
520 char index[PATH_MAX];
521 const char *env[] = { NULL, NULL };
522 const char *argv[8];
524 env[0] = index;
525 argv[0] = "submodule";
526 argv[1] = "summary";
527 argv[2] = uncommitted ? "--files" : "--cached";
528 argv[3] = "--for-status";
529 argv[4] = "--summary-limit";
530 argv[5] = summary_limit;
531 argv[6] = uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD");
532 argv[7] = NULL;
534 sprintf(summary_limit, "%d", s->submodule_summary);
535 snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
537 memset(&sm_summary, 0, sizeof(sm_summary));
538 sm_summary.argv = argv;
539 sm_summary.env = env;
540 sm_summary.git_cmd = 1;
541 sm_summary.no_stdin = 1;
542 fflush(s->fp);
543 sm_summary.out = dup(fileno(s->fp)); /* run_command closes it */
544 run_command(&sm_summary);
547 static void wt_status_print_other(struct wt_status *s,
548 struct string_list *l,
549 const char *what,
550 const char *how)
552 int i;
553 struct strbuf buf = STRBUF_INIT;
555 if (!s->untracked.nr)
556 return;
558 wt_status_print_other_header(s, what, how);
560 for (i = 0; i < l->nr; i++) {
561 struct string_list_item *it;
562 it = &(l->items[i]);
563 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
564 color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s",
565 quote_path(it->string, strlen(it->string),
566 &buf, s->prefix));
568 strbuf_release(&buf);
571 static void wt_status_print_verbose(struct wt_status *s)
573 struct rev_info rev;
574 struct setup_revision_opt opt;
576 init_revisions(&rev, NULL);
577 DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
579 memset(&opt, 0, sizeof(opt));
580 opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
581 setup_revisions(0, NULL, &rev, &opt);
583 rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
584 rev.diffopt.detect_rename = 1;
585 rev.diffopt.file = s->fp;
586 rev.diffopt.close_file = 0;
588 * If we're not going to stdout, then we definitely don't
589 * want color, since we are going to the commit message
590 * file (and even the "auto" setting won't work, since it
591 * will have checked isatty on stdout).
593 if (s->fp != stdout)
594 DIFF_OPT_CLR(&rev.diffopt, COLOR_DIFF);
595 run_diff_index(&rev, 1);
598 static void wt_status_print_tracking(struct wt_status *s)
600 struct strbuf sb = STRBUF_INIT;
601 const char *cp, *ep;
602 struct branch *branch;
604 assert(s->branch && !s->is_initial);
605 if (prefixcmp(s->branch, "refs/heads/"))
606 return;
607 branch = branch_get(s->branch + 11);
608 if (!format_tracking_info(branch, &sb))
609 return;
611 for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
612 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
613 "# %.*s", (int)(ep - cp), cp);
614 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
617 void wt_status_print(struct wt_status *s)
619 const char *branch_color = color(WT_STATUS_HEADER, s);
621 if (s->branch) {
622 const char *on_what = "On branch ";
623 const char *branch_name = s->branch;
624 if (!prefixcmp(branch_name, "refs/heads/"))
625 branch_name += 11;
626 else if (!strcmp(branch_name, "HEAD")) {
627 branch_name = "";
628 branch_color = color(WT_STATUS_NOBRANCH, s);
629 on_what = "Not currently on any branch.";
631 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
632 color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
633 if (!s->is_initial)
634 wt_status_print_tracking(s);
637 if (s->is_initial) {
638 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
639 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit");
640 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
643 wt_status_print_updated(s);
644 wt_status_print_unmerged(s);
645 wt_status_print_changed(s);
646 if (s->submodule_summary) {
647 wt_status_print_submodule_summary(s, 0); /* staged */
648 wt_status_print_submodule_summary(s, 1); /* unstaged */
650 if (s->show_untracked_files) {
651 wt_status_print_other(s, &s->untracked, "Untracked", "add");
652 if (s->show_ignored_files)
653 wt_status_print_other(s, &s->ignored, "Ignored", "add -f");
654 } else if (s->commitable)
655 fprintf(s->fp, "# Untracked files not listed%s\n",
656 advice_status_hints
657 ? " (use -u option to show untracked files)" : "");
659 if (s->verbose)
660 wt_status_print_verbose(s);
661 if (!s->commitable) {
662 if (s->amend)
663 fprintf(s->fp, "# No changes\n");
664 else if (s->nowarn)
665 ; /* nothing */
666 else if (s->workdir_dirty)
667 printf("no changes added to commit%s\n",
668 advice_status_hints
669 ? " (use \"git add\" and/or \"git commit -a\")" : "");
670 else if (s->untracked.nr)
671 printf("nothing added to commit but untracked files present%s\n",
672 advice_status_hints
673 ? " (use \"git add\" to track)" : "");
674 else if (s->is_initial)
675 printf("nothing to commit%s\n", advice_status_hints
676 ? " (create/copy files and use \"git add\" to track)" : "");
677 else if (!s->show_untracked_files)
678 printf("nothing to commit%s\n", advice_status_hints
679 ? " (use -u to show untracked files)" : "");
680 else
681 printf("nothing to commit%s\n", advice_status_hints
682 ? " (working directory clean)" : "");
686 static void wt_shortstatus_unmerged(int null_termination, struct string_list_item *it,
687 struct wt_status *s)
689 struct wt_status_change_data *d = it->util;
690 const char *how = "??";
692 switch (d->stagemask) {
693 case 1: how = "DD"; break; /* both deleted */
694 case 2: how = "AU"; break; /* added by us */
695 case 3: how = "UD"; break; /* deleted by them */
696 case 4: how = "UA"; break; /* added by them */
697 case 5: how = "DU"; break; /* deleted by us */
698 case 6: how = "AA"; break; /* both added */
699 case 7: how = "UU"; break; /* both modified */
701 color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how);
702 if (null_termination) {
703 fprintf(stdout, " %s%c", it->string, 0);
704 } else {
705 struct strbuf onebuf = STRBUF_INIT;
706 const char *one;
707 one = quote_path(it->string, -1, &onebuf, s->prefix);
708 printf(" %s\n", one);
709 strbuf_release(&onebuf);
713 static void wt_shortstatus_status(int null_termination, struct string_list_item *it,
714 struct wt_status *s)
716 struct wt_status_change_data *d = it->util;
718 if (d->index_status)
719 color_fprintf(s->fp, color(WT_STATUS_UPDATED, s), "%c", d->index_status);
720 else
721 putchar(' ');
722 if (d->worktree_status)
723 color_fprintf(s->fp, color(WT_STATUS_CHANGED, s), "%c", d->worktree_status);
724 else
725 putchar(' ');
726 putchar(' ');
727 if (null_termination) {
728 fprintf(stdout, "%s%c", it->string, 0);
729 if (d->head_path)
730 fprintf(stdout, "%s%c", d->head_path, 0);
731 } else {
732 struct strbuf onebuf = STRBUF_INIT;
733 const char *one;
734 if (d->head_path) {
735 one = quote_path(d->head_path, -1, &onebuf, s->prefix);
736 printf("%s -> ", one);
737 strbuf_release(&onebuf);
739 one = quote_path(it->string, -1, &onebuf, s->prefix);
740 printf("%s\n", one);
741 strbuf_release(&onebuf);
745 static void wt_shortstatus_other(int null_termination, struct string_list_item *it,
746 struct wt_status *s, const char *sign)
748 if (null_termination) {
749 fprintf(stdout, "%s %s%c", sign, it->string, 0);
750 } else {
751 struct strbuf onebuf = STRBUF_INIT;
752 const char *one;
753 one = quote_path(it->string, -1, &onebuf, s->prefix);
754 color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign);
755 printf(" %s\n", one);
756 strbuf_release(&onebuf);
760 void wt_shortstatus_print(struct wt_status *s, int null_termination)
762 int i;
763 for (i = 0; i < s->change.nr; i++) {
764 struct wt_status_change_data *d;
765 struct string_list_item *it;
767 it = &(s->change.items[i]);
768 d = it->util;
769 if (d->stagemask)
770 wt_shortstatus_unmerged(null_termination, it, s);
771 else
772 wt_shortstatus_status(null_termination, it, s);
774 for (i = 0; i < s->untracked.nr; i++) {
775 struct string_list_item *it;
777 it = &(s->untracked.items[i]);
778 wt_shortstatus_other(null_termination, it, s, "??");
780 for (i = 0; i < s->ignored.nr; i++) {
781 struct string_list_item *it;
783 it = &(s->ignored.items[i]);
784 wt_shortstatus_other(null_termination, it, s, "!!");
788 void wt_porcelain_print(struct wt_status *s, int null_termination)
790 s->use_color = 0;
791 s->relative_paths = 0;
792 s->prefix = NULL;
793 wt_shortstatus_print(s, null_termination);