10 #include "run-command.h"
14 static char default_wt_status_colors
[][COLOR_MAXLEN
] = {
15 GIT_COLOR_NORMAL
, /* WT_STATUS_HEADER */
16 GIT_COLOR_GREEN
, /* WT_STATUS_UPDATED */
17 GIT_COLOR_RED
, /* WT_STATUS_CHANGED */
18 GIT_COLOR_RED
, /* WT_STATUS_UNTRACKED */
19 GIT_COLOR_RED
, /* WT_STATUS_NOBRANCH */
20 GIT_COLOR_RED
, /* WT_STATUS_UNMERGED */
21 GIT_COLOR_GREEN
, /* WT_STATUS_LOCAL_BRANCH */
22 GIT_COLOR_RED
, /* WT_STATUS_REMOTE_BRANCH */
25 static const char *color(int slot
, struct wt_status
*s
)
27 return s
->use_color
> 0 ? s
->color_palette
[slot
] : "";
30 void wt_status_prepare(struct wt_status
*s
)
32 unsigned char sha1
[20];
35 memset(s
, 0, sizeof(*s
));
36 memcpy(s
->color_palette
, default_wt_status_colors
,
37 sizeof(default_wt_status_colors
));
38 s
->show_untracked_files
= SHOW_NORMAL_UNTRACKED_FILES
;
40 s
->relative_paths
= 1;
41 head
= resolve_ref("HEAD", sha1
, 0, NULL
);
42 s
->branch
= head
? xstrdup(head
) : NULL
;
43 s
->reference
= "HEAD";
45 s
->index_file
= get_index_file();
46 s
->change
.strdup_strings
= 1;
47 s
->untracked
.strdup_strings
= 1;
48 s
->ignored
.strdup_strings
= 1;
51 static void wt_status_print_unmerged_header(struct wt_status
*s
)
53 const char *c
= color(WT_STATUS_HEADER
, s
);
55 color_fprintf_ln(s
->fp
, c
, "# Unmerged paths:");
56 if (!advice_status_hints
)
60 else if (!s
->is_initial
)
61 color_fprintf_ln(s
->fp
, c
, "# (use \"git reset %s <file>...\" to unstage)", s
->reference
);
63 color_fprintf_ln(s
->fp
, c
, "# (use \"git rm --cached <file>...\" to unstage)");
64 color_fprintf_ln(s
->fp
, c
, "# (use \"git add/rm <file>...\" as appropriate to mark resolution)");
65 color_fprintf_ln(s
->fp
, c
, "#");
68 static void wt_status_print_cached_header(struct wt_status
*s
)
70 const char *c
= color(WT_STATUS_HEADER
, s
);
72 color_fprintf_ln(s
->fp
, c
, "# Changes to be committed:");
73 if (!advice_status_hints
)
76 ; /* NEEDSWORK: use "git reset --unresolve"??? */
77 else if (!s
->is_initial
)
78 color_fprintf_ln(s
->fp
, c
, "# (use \"git reset %s <file>...\" to unstage)", s
->reference
);
80 color_fprintf_ln(s
->fp
, c
, "# (use \"git rm --cached <file>...\" to unstage)");
81 color_fprintf_ln(s
->fp
, c
, "#");
84 static void wt_status_print_dirty_header(struct wt_status
*s
,
86 int has_dirty_submodules
)
88 const char *c
= color(WT_STATUS_HEADER
, s
);
90 color_fprintf_ln(s
->fp
, c
, "# Changed but not updated:");
91 if (!advice_status_hints
)
94 color_fprintf_ln(s
->fp
, c
, "# (use \"git add <file>...\" to update what will be committed)");
96 color_fprintf_ln(s
->fp
, c
, "# (use \"git add/rm <file>...\" to update what will be committed)");
97 color_fprintf_ln(s
->fp
, c
, "# (use \"git checkout -- <file>...\" to discard changes in working directory)");
98 if (has_dirty_submodules
)
99 color_fprintf_ln(s
->fp
, c
, "# (commit or discard the untracked or modified content in submodules)");
100 color_fprintf_ln(s
->fp
, c
, "#");
103 static void wt_status_print_other_header(struct wt_status
*s
,
107 const char *c
= color(WT_STATUS_HEADER
, s
);
108 color_fprintf_ln(s
->fp
, c
, "# %s files:", what
);
109 if (!advice_status_hints
)
111 color_fprintf_ln(s
->fp
, c
, "# (use \"git %s <file>...\" to include in what will be committed)", how
);
112 color_fprintf_ln(s
->fp
, c
, "#");
115 static void wt_status_print_trailer(struct wt_status
*s
)
117 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
), "#");
120 #define quote_path quote_path_relative
122 static void wt_status_print_unmerged_data(struct wt_status
*s
,
123 struct string_list_item
*it
)
125 const char *c
= color(WT_STATUS_UNMERGED
, s
);
126 struct wt_status_change_data
*d
= it
->util
;
127 struct strbuf onebuf
= STRBUF_INIT
;
128 const char *one
, *how
= "bug";
130 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
131 color_fprintf(s
->fp
, color(WT_STATUS_HEADER
, s
), "#\t");
132 switch (d
->stagemask
) {
133 case 1: how
= "both deleted:"; break;
134 case 2: how
= "added by us:"; break;
135 case 3: how
= "deleted by them:"; break;
136 case 4: how
= "added by them:"; break;
137 case 5: how
= "deleted by us:"; break;
138 case 6: how
= "both added:"; break;
139 case 7: how
= "both modified:"; break;
141 color_fprintf(s
->fp
, c
, "%-20s%s\n", how
, one
);
142 strbuf_release(&onebuf
);
145 static void wt_status_print_change_data(struct wt_status
*s
,
147 struct string_list_item
*it
)
149 struct wt_status_change_data
*d
= it
->util
;
150 const char *c
= color(change_type
, s
);
154 const char *one
, *two
;
155 struct strbuf onebuf
= STRBUF_INIT
, twobuf
= STRBUF_INIT
;
156 struct strbuf extra
= STRBUF_INIT
;
158 one_name
= two_name
= it
->string
;
159 switch (change_type
) {
160 case WT_STATUS_UPDATED
:
161 status
= d
->index_status
;
163 one_name
= d
->head_path
;
165 case WT_STATUS_CHANGED
:
166 if (d
->new_submodule_commits
|| d
->dirty_submodule
) {
167 strbuf_addstr(&extra
, " (");
168 if (d
->new_submodule_commits
)
169 strbuf_addf(&extra
, "new commits, ");
170 if (d
->dirty_submodule
& DIRTY_SUBMODULE_MODIFIED
)
171 strbuf_addf(&extra
, "modified content, ");
172 if (d
->dirty_submodule
& DIRTY_SUBMODULE_UNTRACKED
)
173 strbuf_addf(&extra
, "untracked content, ");
174 strbuf_setlen(&extra
, extra
.len
- 2);
175 strbuf_addch(&extra
, ')');
177 status
= d
->worktree_status
;
181 one
= quote_path(one_name
, -1, &onebuf
, s
->prefix
);
182 two
= quote_path(two_name
, -1, &twobuf
, s
->prefix
);
184 color_fprintf(s
->fp
, color(WT_STATUS_HEADER
, s
), "#\t");
186 case DIFF_STATUS_ADDED
:
187 color_fprintf(s
->fp
, c
, "new file: %s", one
);
189 case DIFF_STATUS_COPIED
:
190 color_fprintf(s
->fp
, c
, "copied: %s -> %s", one
, two
);
192 case DIFF_STATUS_DELETED
:
193 color_fprintf(s
->fp
, c
, "deleted: %s", one
);
195 case DIFF_STATUS_MODIFIED
:
196 color_fprintf(s
->fp
, c
, "modified: %s", one
);
198 case DIFF_STATUS_RENAMED
:
199 color_fprintf(s
->fp
, c
, "renamed: %s -> %s", one
, two
);
201 case DIFF_STATUS_TYPE_CHANGED
:
202 color_fprintf(s
->fp
, c
, "typechange: %s", one
);
204 case DIFF_STATUS_UNKNOWN
:
205 color_fprintf(s
->fp
, c
, "unknown: %s", one
);
207 case DIFF_STATUS_UNMERGED
:
208 color_fprintf(s
->fp
, c
, "unmerged: %s", one
);
211 die("bug: unhandled diff status %c", status
);
214 color_fprintf(s
->fp
, color(WT_STATUS_HEADER
, s
), "%s", extra
.buf
);
215 strbuf_release(&extra
);
217 fprintf(s
->fp
, "\n");
218 strbuf_release(&onebuf
);
219 strbuf_release(&twobuf
);
222 static void wt_status_collect_changed_cb(struct diff_queue_struct
*q
,
223 struct diff_options
*options
,
226 struct wt_status
*s
= data
;
231 s
->workdir_dirty
= 1;
232 for (i
= 0; i
< q
->nr
; i
++) {
233 struct diff_filepair
*p
;
234 struct string_list_item
*it
;
235 struct wt_status_change_data
*d
;
238 it
= string_list_insert(p
->one
->path
, &s
->change
);
241 d
= xcalloc(1, sizeof(*d
));
244 if (!d
->worktree_status
)
245 d
->worktree_status
= p
->status
;
246 d
->dirty_submodule
= p
->two
->dirty_submodule
;
247 if (S_ISGITLINK(p
->two
->mode
))
248 d
->new_submodule_commits
= !!hashcmp(p
->one
->sha1
, p
->two
->sha1
);
252 static int unmerged_mask(const char *path
)
255 struct cache_entry
*ce
;
257 pos
= cache_name_pos(path
, strlen(path
));
263 while (pos
< active_nr
) {
264 ce
= active_cache
[pos
++];
265 if (strcmp(ce
->name
, path
) || !ce_stage(ce
))
267 mask
|= (1 << (ce_stage(ce
) - 1));
272 static void wt_status_collect_updated_cb(struct diff_queue_struct
*q
,
273 struct diff_options
*options
,
276 struct wt_status
*s
= data
;
279 for (i
= 0; i
< q
->nr
; i
++) {
280 struct diff_filepair
*p
;
281 struct string_list_item
*it
;
282 struct wt_status_change_data
*d
;
285 it
= string_list_insert(p
->two
->path
, &s
->change
);
288 d
= xcalloc(1, sizeof(*d
));
291 if (!d
->index_status
)
292 d
->index_status
= p
->status
;
294 case DIFF_STATUS_COPIED
:
295 case DIFF_STATUS_RENAMED
:
296 d
->head_path
= xstrdup(p
->one
->path
);
298 case DIFF_STATUS_UNMERGED
:
299 d
->stagemask
= unmerged_mask(p
->two
->path
);
305 static void wt_status_collect_changes_worktree(struct wt_status
*s
)
309 init_revisions(&rev
, NULL
);
310 setup_revisions(0, NULL
, &rev
, NULL
);
311 rev
.diffopt
.output_format
|= DIFF_FORMAT_CALLBACK
;
312 DIFF_OPT_SET(&rev
.diffopt
, DIRTY_SUBMODULES
);
313 if (!s
->show_untracked_files
)
314 DIFF_OPT_SET(&rev
.diffopt
, IGNORE_UNTRACKED_IN_SUBMODULES
);
315 rev
.diffopt
.format_callback
= wt_status_collect_changed_cb
;
316 rev
.diffopt
.format_callback_data
= s
;
317 rev
.prune_data
= s
->pathspec
;
318 run_diff_files(&rev
, 0);
321 static void wt_status_collect_changes_index(struct wt_status
*s
)
324 struct setup_revision_opt opt
;
326 init_revisions(&rev
, NULL
);
327 memset(&opt
, 0, sizeof(opt
));
328 opt
.def
= s
->is_initial
? EMPTY_TREE_SHA1_HEX
: s
->reference
;
329 setup_revisions(0, NULL
, &rev
, &opt
);
331 rev
.diffopt
.output_format
|= DIFF_FORMAT_CALLBACK
;
332 rev
.diffopt
.format_callback
= wt_status_collect_updated_cb
;
333 rev
.diffopt
.format_callback_data
= s
;
334 rev
.diffopt
.detect_rename
= 1;
335 rev
.diffopt
.rename_limit
= 200;
336 rev
.diffopt
.break_opt
= 0;
337 rev
.prune_data
= s
->pathspec
;
338 run_diff_index(&rev
, 1);
341 static void wt_status_collect_changes_initial(struct wt_status
*s
)
345 for (i
= 0; i
< active_nr
; i
++) {
346 struct string_list_item
*it
;
347 struct wt_status_change_data
*d
;
348 struct cache_entry
*ce
= active_cache
[i
];
350 if (!ce_path_match(ce
, s
->pathspec
))
352 it
= string_list_insert(ce
->name
, &s
->change
);
355 d
= xcalloc(1, sizeof(*d
));
359 d
->index_status
= DIFF_STATUS_UNMERGED
;
360 d
->stagemask
|= (1 << (ce_stage(ce
) - 1));
363 d
->index_status
= DIFF_STATUS_ADDED
;
367 static void wt_status_collect_untracked(struct wt_status
*s
)
370 struct dir_struct dir
;
372 if (!s
->show_untracked_files
)
374 memset(&dir
, 0, sizeof(dir
));
375 if (s
->show_untracked_files
!= SHOW_ALL_UNTRACKED_FILES
)
377 DIR_SHOW_OTHER_DIRECTORIES
| DIR_HIDE_EMPTY_DIRECTORIES
;
378 setup_standard_excludes(&dir
);
380 fill_directory(&dir
, s
->pathspec
);
381 for (i
= 0; i
< dir
.nr
; i
++) {
382 struct dir_entry
*ent
= dir
.entries
[i
];
383 if (!cache_name_is_other(ent
->name
, ent
->len
))
385 if (!match_pathspec(s
->pathspec
, ent
->name
, ent
->len
, 0, NULL
))
387 string_list_insert(ent
->name
, &s
->untracked
);
391 if (s
->show_ignored_files
) {
393 dir
.flags
= DIR_SHOW_IGNORED
| DIR_SHOW_OTHER_DIRECTORIES
;
394 fill_directory(&dir
, s
->pathspec
);
395 for (i
= 0; i
< dir
.nr
; i
++) {
396 struct dir_entry
*ent
= dir
.entries
[i
];
397 if (!cache_name_is_other(ent
->name
, ent
->len
))
399 if (!match_pathspec(s
->pathspec
, ent
->name
, ent
->len
, 0, NULL
))
401 string_list_insert(ent
->name
, &s
->ignored
);
409 void wt_status_collect(struct wt_status
*s
)
411 wt_status_collect_changes_worktree(s
);
414 wt_status_collect_changes_initial(s
);
416 wt_status_collect_changes_index(s
);
417 wt_status_collect_untracked(s
);
420 static void wt_status_print_unmerged(struct wt_status
*s
)
422 int shown_header
= 0;
425 for (i
= 0; i
< s
->change
.nr
; i
++) {
426 struct wt_status_change_data
*d
;
427 struct string_list_item
*it
;
428 it
= &(s
->change
.items
[i
]);
433 wt_status_print_unmerged_header(s
);
436 wt_status_print_unmerged_data(s
, it
);
439 wt_status_print_trailer(s
);
443 static void wt_status_print_updated(struct wt_status
*s
)
445 int shown_header
= 0;
448 for (i
= 0; i
< s
->change
.nr
; i
++) {
449 struct wt_status_change_data
*d
;
450 struct string_list_item
*it
;
451 it
= &(s
->change
.items
[i
]);
453 if (!d
->index_status
||
454 d
->index_status
== DIFF_STATUS_UNMERGED
)
457 wt_status_print_cached_header(s
);
461 wt_status_print_change_data(s
, WT_STATUS_UPDATED
, it
);
464 wt_status_print_trailer(s
);
470 * 1 : some change but no delete
472 static int wt_status_check_worktree_changes(struct wt_status
*s
,
473 int *dirty_submodules
)
478 *dirty_submodules
= 0;
480 for (i
= 0; i
< s
->change
.nr
; i
++) {
481 struct wt_status_change_data
*d
;
482 d
= s
->change
.items
[i
].util
;
483 if (!d
->worktree_status
||
484 d
->worktree_status
== DIFF_STATUS_UNMERGED
)
488 if (d
->dirty_submodule
)
489 *dirty_submodules
= 1;
490 if (d
->worktree_status
== DIFF_STATUS_DELETED
)
496 static void wt_status_print_changed(struct wt_status
*s
)
498 int i
, dirty_submodules
;
499 int worktree_changes
= wt_status_check_worktree_changes(s
, &dirty_submodules
);
501 if (!worktree_changes
)
504 wt_status_print_dirty_header(s
, worktree_changes
< 0, dirty_submodules
);
506 for (i
= 0; i
< s
->change
.nr
; i
++) {
507 struct wt_status_change_data
*d
;
508 struct string_list_item
*it
;
509 it
= &(s
->change
.items
[i
]);
511 if (!d
->worktree_status
||
512 d
->worktree_status
== DIFF_STATUS_UNMERGED
)
514 wt_status_print_change_data(s
, WT_STATUS_CHANGED
, it
);
516 wt_status_print_trailer(s
);
519 static void wt_status_print_submodule_summary(struct wt_status
*s
, int uncommitted
)
521 struct child_process sm_summary
;
522 char summary_limit
[64];
523 char index
[PATH_MAX
];
524 const char *env
[] = { index
, NULL
};
525 const char *argv
[] = {
528 uncommitted
? "--files" : "--cached",
532 uncommitted
? NULL
: (s
->amend
? "HEAD^" : "HEAD"),
536 sprintf(summary_limit
, "%d", s
->submodule_summary
);
537 snprintf(index
, sizeof(index
), "GIT_INDEX_FILE=%s", s
->index_file
);
539 memset(&sm_summary
, 0, sizeof(sm_summary
));
540 sm_summary
.argv
= argv
;
541 sm_summary
.env
= env
;
542 sm_summary
.git_cmd
= 1;
543 sm_summary
.no_stdin
= 1;
545 sm_summary
.out
= dup(fileno(s
->fp
)); /* run_command closes it */
546 run_command(&sm_summary
);
549 static void wt_status_print_other(struct wt_status
*s
,
550 struct string_list
*l
,
555 struct strbuf buf
= STRBUF_INIT
;
557 if (!s
->untracked
.nr
)
560 wt_status_print_other_header(s
, what
, how
);
562 for (i
= 0; i
< l
->nr
; i
++) {
563 struct string_list_item
*it
;
565 color_fprintf(s
->fp
, color(WT_STATUS_HEADER
, s
), "#\t");
566 color_fprintf_ln(s
->fp
, color(WT_STATUS_UNTRACKED
, s
), "%s",
567 quote_path(it
->string
, strlen(it
->string
),
570 strbuf_release(&buf
);
573 static void wt_status_print_verbose(struct wt_status
*s
)
576 struct setup_revision_opt opt
;
578 init_revisions(&rev
, NULL
);
579 DIFF_OPT_SET(&rev
.diffopt
, ALLOW_TEXTCONV
);
581 memset(&opt
, 0, sizeof(opt
));
582 opt
.def
= s
->is_initial
? EMPTY_TREE_SHA1_HEX
: s
->reference
;
583 setup_revisions(0, NULL
, &rev
, &opt
);
585 rev
.diffopt
.output_format
|= DIFF_FORMAT_PATCH
;
586 rev
.diffopt
.detect_rename
= 1;
587 rev
.diffopt
.file
= s
->fp
;
588 rev
.diffopt
.close_file
= 0;
590 * If we're not going to stdout, then we definitely don't
591 * want color, since we are going to the commit message
592 * file (and even the "auto" setting won't work, since it
593 * will have checked isatty on stdout).
596 DIFF_OPT_CLR(&rev
.diffopt
, COLOR_DIFF
);
597 run_diff_index(&rev
, 1);
600 static void wt_status_print_tracking(struct wt_status
*s
)
602 struct strbuf sb
= STRBUF_INIT
;
604 struct branch
*branch
;
606 assert(s
->branch
&& !s
->is_initial
);
607 if (prefixcmp(s
->branch
, "refs/heads/"))
609 branch
= branch_get(s
->branch
+ 11);
610 if (!format_tracking_info(branch
, &sb
))
613 for (cp
= sb
.buf
; (ep
= strchr(cp
, '\n')) != NULL
; cp
= ep
+ 1)
614 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
),
615 "# %.*s", (int)(ep
- cp
), cp
);
616 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
), "#");
619 void wt_status_print(struct wt_status
*s
)
621 const char *branch_color
= color(WT_STATUS_HEADER
, s
);
624 const char *on_what
= "On branch ";
625 const char *branch_name
= s
->branch
;
626 if (!prefixcmp(branch_name
, "refs/heads/"))
628 else if (!strcmp(branch_name
, "HEAD")) {
630 branch_color
= color(WT_STATUS_NOBRANCH
, s
);
631 on_what
= "Not currently on any branch.";
633 color_fprintf(s
->fp
, color(WT_STATUS_HEADER
, s
), "# ");
634 color_fprintf_ln(s
->fp
, branch_color
, "%s%s", on_what
, branch_name
);
636 wt_status_print_tracking(s
);
640 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
), "#");
641 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
), "# Initial commit");
642 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
), "#");
645 wt_status_print_updated(s
);
646 wt_status_print_unmerged(s
);
647 wt_status_print_changed(s
);
648 if (s
->submodule_summary
) {
649 wt_status_print_submodule_summary(s
, 0); /* staged */
650 wt_status_print_submodule_summary(s
, 1); /* unstaged */
652 if (s
->show_untracked_files
) {
653 wt_status_print_other(s
, &s
->untracked
, "Untracked", "add");
654 if (s
->show_ignored_files
)
655 wt_status_print_other(s
, &s
->ignored
, "Ignored", "add -f");
656 } else if (s
->commitable
)
657 fprintf(s
->fp
, "# Untracked files not listed%s\n",
659 ? " (use -u option to show untracked files)" : "");
662 wt_status_print_verbose(s
);
663 if (!s
->commitable
) {
665 fprintf(s
->fp
, "# No changes\n");
668 else if (s
->workdir_dirty
)
669 printf("no changes added to commit%s\n",
671 ? " (use \"git add\" and/or \"git commit -a\")" : "");
672 else if (s
->untracked
.nr
)
673 printf("nothing added to commit but untracked files present%s\n",
675 ? " (use \"git add\" to track)" : "");
676 else if (s
->is_initial
)
677 printf("nothing to commit%s\n", advice_status_hints
678 ? " (create/copy files and use \"git add\" to track)" : "");
679 else if (!s
->show_untracked_files
)
680 printf("nothing to commit%s\n", advice_status_hints
681 ? " (use -u to show untracked files)" : "");
683 printf("nothing to commit%s\n", advice_status_hints
684 ? " (working directory clean)" : "");
688 static void wt_shortstatus_unmerged(int null_termination
, struct string_list_item
*it
,
691 struct wt_status_change_data
*d
= it
->util
;
692 const char *how
= "??";
694 switch (d
->stagemask
) {
695 case 1: how
= "DD"; break; /* both deleted */
696 case 2: how
= "AU"; break; /* added by us */
697 case 3: how
= "UD"; break; /* deleted by them */
698 case 4: how
= "UA"; break; /* added by them */
699 case 5: how
= "DU"; break; /* deleted by us */
700 case 6: how
= "AA"; break; /* both added */
701 case 7: how
= "UU"; break; /* both modified */
703 color_fprintf(s
->fp
, color(WT_STATUS_UNMERGED
, s
), "%s", how
);
704 if (null_termination
) {
705 fprintf(stdout
, " %s%c", it
->string
, 0);
707 struct strbuf onebuf
= STRBUF_INIT
;
709 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
710 printf(" %s\n", one
);
711 strbuf_release(&onebuf
);
715 static void wt_shortstatus_status(int null_termination
, struct string_list_item
*it
,
718 struct wt_status_change_data
*d
= it
->util
;
721 color_fprintf(s
->fp
, color(WT_STATUS_UPDATED
, s
), "%c", d
->index_status
);
724 if (d
->worktree_status
)
725 color_fprintf(s
->fp
, color(WT_STATUS_CHANGED
, s
), "%c", d
->worktree_status
);
729 if (null_termination
) {
730 fprintf(stdout
, "%s%c", it
->string
, 0);
732 fprintf(stdout
, "%s%c", d
->head_path
, 0);
734 struct strbuf onebuf
= STRBUF_INIT
;
737 one
= quote_path(d
->head_path
, -1, &onebuf
, s
->prefix
);
738 printf("%s -> ", one
);
739 strbuf_release(&onebuf
);
741 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
743 strbuf_release(&onebuf
);
747 static void wt_shortstatus_other(int null_termination
, struct string_list_item
*it
,
748 struct wt_status
*s
, const char *sign
)
750 if (null_termination
) {
751 fprintf(stdout
, "%s %s%c", sign
, it
->string
, 0);
753 struct strbuf onebuf
= STRBUF_INIT
;
755 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
756 color_fprintf(s
->fp
, color(WT_STATUS_UNTRACKED
, s
), "%s", sign
);
757 printf(" %s\n", one
);
758 strbuf_release(&onebuf
);
762 static void wt_shortstatus_print_tracking(struct wt_status
*s
)
764 struct branch
*branch
;
765 const char *header_color
= color(WT_STATUS_HEADER
, s
);
766 const char *branch_color_local
= color(WT_STATUS_LOCAL_BRANCH
, s
);
767 const char *branch_color_remote
= color(WT_STATUS_REMOTE_BRANCH
, s
);
770 const char *branch_name
;
771 int num_ours
, num_theirs
;
773 color_fprintf(s
->fp
, color(WT_STATUS_HEADER
, s
), "## ");
777 branch_name
= s
->branch
;
779 if (!prefixcmp(branch_name
, "refs/heads/"))
781 else if (!strcmp(branch_name
, "HEAD")) {
782 branch_name
= "HEAD (no branch)";
783 branch_color_local
= color(WT_STATUS_NOBRANCH
, s
);
786 branch
= branch_get(s
->branch
+ 11);
788 color_fprintf(s
->fp
, header_color
, "Initial commit on ");
789 if (!stat_tracking_info(branch
, &num_ours
, &num_theirs
)) {
790 color_fprintf_ln(s
->fp
, branch_color_local
,
795 base
= branch
->merge
[0]->dst
;
796 base
= shorten_unambiguous_ref(base
, 0);
797 color_fprintf(s
->fp
, branch_color_local
, "%s", branch_name
);
798 color_fprintf(s
->fp
, header_color
, "...");
799 color_fprintf(s
->fp
, branch_color_remote
, "%s", base
);
801 color_fprintf(s
->fp
, header_color
, " [");
803 color_fprintf(s
->fp
, header_color
, "behind ");
804 color_fprintf(s
->fp
, branch_color_remote
, "%d", num_theirs
);
805 } else if (!num_theirs
) {
806 color_fprintf(s
->fp
, header_color
, "ahead ");
807 color_fprintf(s
->fp
, branch_color_local
, "%d", num_ours
);
809 color_fprintf(s
->fp
, header_color
, "ahead ");
810 color_fprintf(s
->fp
, branch_color_local
, "%d", num_ours
);
811 color_fprintf(s
->fp
, header_color
, ", behind ");
812 color_fprintf(s
->fp
, branch_color_remote
, "%d", num_theirs
);
815 color_fprintf_ln(s
->fp
, header_color
, "]");
818 void wt_shortstatus_print(struct wt_status
*s
, int null_termination
, int show_branch
)
823 wt_shortstatus_print_tracking(s
);
825 for (i
= 0; i
< s
->change
.nr
; i
++) {
826 struct wt_status_change_data
*d
;
827 struct string_list_item
*it
;
829 it
= &(s
->change
.items
[i
]);
832 wt_shortstatus_unmerged(null_termination
, it
, s
);
834 wt_shortstatus_status(null_termination
, it
, s
);
836 for (i
= 0; i
< s
->untracked
.nr
; i
++) {
837 struct string_list_item
*it
;
839 it
= &(s
->untracked
.items
[i
]);
840 wt_shortstatus_other(null_termination
, it
, s
, "??");
842 for (i
= 0; i
< s
->ignored
.nr
; i
++) {
843 struct string_list_item
*it
;
845 it
= &(s
->ignored
.items
[i
]);
846 wt_shortstatus_other(null_termination
, it
, s
, "!!");
850 void wt_porcelain_print(struct wt_status
*s
, int null_termination
)
853 s
->relative_paths
= 0;
855 wt_shortstatus_print(s
, null_termination
, 0);