wt-status.con commit pretty.c: mark file-local function static (cc57114)
   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"
  12
  13static 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 */
  20};
  21
  22static const char *color(int slot, struct wt_status *s)
  23{
  24        return s->use_color > 0 ? s->color_palette[slot] : "";
  25}
  26
  27void wt_status_prepare(struct wt_status *s)
  28{
  29        unsigned char sha1[20];
  30        const char *head;
  31
  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}
  46
  47static void wt_status_print_unmerged_header(struct wt_status *s)
  48{
  49        const char *c = color(WT_STATUS_HEADER, s);
  50
  51        color_fprintf_ln(s->fp, c, "# Unmerged paths:");
  52        if (!advice_status_hints)
  53                return;
  54        if (s->in_merge)
  55                ;
  56        else if (!s->is_initial)
  57                color_fprintf_ln(s->fp, c, "#   (use \"git reset %s <file>...\" to unstage)", s->reference);
  58        else
  59                color_fprintf_ln(s->fp, c, "#   (use \"git rm --cached <file>...\" to unstage)");
  60        color_fprintf_ln(s->fp, c, "#   (use \"git add/rm <file>...\" as appropriate to mark resolution)");
  61        color_fprintf_ln(s->fp, c, "#");
  62}
  63
  64static void wt_status_print_cached_header(struct wt_status *s)
  65{
  66        const char *c = color(WT_STATUS_HEADER, s);
  67
  68        color_fprintf_ln(s->fp, c, "# Changes to be committed:");
  69        if (!advice_status_hints)
  70                return;
  71        if (s->in_merge)
  72                ; /* NEEDSWORK: use "git reset --unresolve"??? */
  73        else if (!s->is_initial)
  74                color_fprintf_ln(s->fp, c, "#   (use \"git reset %s <file>...\" to unstage)", s->reference);
  75        else
  76                color_fprintf_ln(s->fp, c, "#   (use \"git rm --cached <file>...\" to unstage)");
  77        color_fprintf_ln(s->fp, c, "#");
  78}
  79
  80static void wt_status_print_dirty_header(struct wt_status *s,
  81                                         int has_deleted)
  82{
  83        const char *c = color(WT_STATUS_HEADER, s);
  84
  85        color_fprintf_ln(s->fp, c, "# Changed but not updated:");
  86        if (!advice_status_hints)
  87                return;
  88        if (!has_deleted)
  89                color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to update what will be committed)");
  90        else
  91                color_fprintf_ln(s->fp, c, "#   (use \"git add/rm <file>...\" to update what will be committed)");
  92        color_fprintf_ln(s->fp, c, "#   (use \"git checkout -- <file>...\" to discard changes in working directory)");
  93        color_fprintf_ln(s->fp, c, "#");
  94}
  95
  96static void wt_status_print_untracked_header(struct wt_status *s)
  97{
  98        const char *c = color(WT_STATUS_HEADER, s);
  99        color_fprintf_ln(s->fp, c, "# Untracked files:");
 100        if (!advice_status_hints)
 101                return;
 102        color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to include in what will be committed)");
 103        color_fprintf_ln(s->fp, c, "#");
 104}
 105
 106static void wt_status_print_trailer(struct wt_status *s)
 107{
 108        color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
 109}
 110
 111#define quote_path quote_path_relative
 112
 113static void wt_status_print_unmerged_data(struct wt_status *s,
 114                                          struct string_list_item *it)
 115{
 116        const char *c = color(WT_STATUS_UNMERGED, s);
 117        struct wt_status_change_data *d = it->util;
 118        struct strbuf onebuf = STRBUF_INIT;
 119        const char *one, *how = "bug";
 120
 121        one = quote_path(it->string, -1, &onebuf, s->prefix);
 122        color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
 123        switch (d->stagemask) {
 124        case 1: how = "both deleted:"; break;
 125        case 2: how = "added by us:"; break;
 126        case 3: how = "deleted by them:"; break;
 127        case 4: how = "added by them:"; break;
 128        case 5: how = "deleted by us:"; break;
 129        case 6: how = "both added:"; break;
 130        case 7: how = "both modified:"; break;
 131        }
 132        color_fprintf(s->fp, c, "%-20s%s\n", how, one);
 133        strbuf_release(&onebuf);
 134}
 135
 136static void wt_status_print_change_data(struct wt_status *s,
 137                                        int change_type,
 138                                        struct string_list_item *it)
 139{
 140        struct wt_status_change_data *d = it->util;
 141        const char *c = color(change_type, s);
 142        int status = status;
 143        char *one_name;
 144        char *two_name;
 145        const char *one, *two;
 146        struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
 147
 148        one_name = two_name = it->string;
 149        switch (change_type) {
 150        case WT_STATUS_UPDATED:
 151                status = d->index_status;
 152                if (d->head_path)
 153                        one_name = d->head_path;
 154                break;
 155        case WT_STATUS_CHANGED:
 156                status = d->worktree_status;
 157                break;
 158        }
 159
 160        one = quote_path(one_name, -1, &onebuf, s->prefix);
 161        two = quote_path(two_name, -1, &twobuf, s->prefix);
 162
 163        color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
 164        switch (status) {
 165        case DIFF_STATUS_ADDED:
 166                color_fprintf(s->fp, c, "new file:   %s", one);
 167                break;
 168        case DIFF_STATUS_COPIED:
 169                color_fprintf(s->fp, c, "copied:     %s -> %s", one, two);
 170                break;
 171        case DIFF_STATUS_DELETED:
 172                color_fprintf(s->fp, c, "deleted:    %s", one);
 173                break;
 174        case DIFF_STATUS_MODIFIED:
 175                color_fprintf(s->fp, c, "modified:   %s", one);
 176                break;
 177        case DIFF_STATUS_RENAMED:
 178                color_fprintf(s->fp, c, "renamed:    %s -> %s", one, two);
 179                break;
 180        case DIFF_STATUS_TYPE_CHANGED:
 181                color_fprintf(s->fp, c, "typechange: %s", one);
 182                break;
 183        case DIFF_STATUS_UNKNOWN:
 184                color_fprintf(s->fp, c, "unknown:    %s", one);
 185                break;
 186        case DIFF_STATUS_UNMERGED:
 187                color_fprintf(s->fp, c, "unmerged:   %s", one);
 188                break;
 189        default:
 190                die("bug: unhandled diff status %c", status);
 191        }
 192        fprintf(s->fp, "\n");
 193        strbuf_release(&onebuf);
 194        strbuf_release(&twobuf);
 195}
 196
 197static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
 198                                         struct diff_options *options,
 199                                         void *data)
 200{
 201        struct wt_status *s = data;
 202        int i;
 203
 204        if (!q->nr)
 205                return;
 206        s->workdir_dirty = 1;
 207        for (i = 0; i < q->nr; i++) {
 208                struct diff_filepair *p;
 209                struct string_list_item *it;
 210                struct wt_status_change_data *d;
 211
 212                p = q->queue[i];
 213                it = string_list_insert(p->one->path, &s->change);
 214                d = it->util;
 215                if (!d) {
 216                        d = xcalloc(1, sizeof(*d));
 217                        it->util = d;
 218                }
 219                if (!d->worktree_status)
 220                        d->worktree_status = p->status;
 221        }
 222}
 223
 224static int unmerged_mask(const char *path)
 225{
 226        int pos, mask;
 227        struct cache_entry *ce;
 228
 229        pos = cache_name_pos(path, strlen(path));
 230        if (0 <= pos)
 231                return 0;
 232
 233        mask = 0;
 234        pos = -pos-1;
 235        while (pos < active_nr) {
 236                ce = active_cache[pos++];
 237                if (strcmp(ce->name, path) || !ce_stage(ce))
 238                        break;
 239                mask |= (1 << (ce_stage(ce) - 1));
 240        }
 241        return mask;
 242}
 243
 244static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
 245                                         struct diff_options *options,
 246                                         void *data)
 247{
 248        struct wt_status *s = data;
 249        int i;
 250
 251        for (i = 0; i < q->nr; i++) {
 252                struct diff_filepair *p;
 253                struct string_list_item *it;
 254                struct wt_status_change_data *d;
 255
 256                p = q->queue[i];
 257                it = string_list_insert(p->two->path, &s->change);
 258                d = it->util;
 259                if (!d) {
 260                        d = xcalloc(1, sizeof(*d));
 261                        it->util = d;
 262                }
 263                if (!d->index_status)
 264                        d->index_status = p->status;
 265                switch (p->status) {
 266                case DIFF_STATUS_COPIED:
 267                case DIFF_STATUS_RENAMED:
 268                        d->head_path = xstrdup(p->one->path);
 269                        break;
 270                case DIFF_STATUS_UNMERGED:
 271                        d->stagemask = unmerged_mask(p->two->path);
 272                        break;
 273                }
 274        }
 275}
 276
 277static void wt_status_collect_changes_worktree(struct wt_status *s)
 278{
 279        struct rev_info rev;
 280
 281        init_revisions(&rev, NULL);
 282        setup_revisions(0, NULL, &rev, NULL);
 283        rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
 284        rev.diffopt.format_callback = wt_status_collect_changed_cb;
 285        rev.diffopt.format_callback_data = s;
 286        rev.prune_data = s->pathspec;
 287        run_diff_files(&rev, 0);
 288}
 289
 290static void wt_status_collect_changes_index(struct wt_status *s)
 291{
 292        struct rev_info rev;
 293
 294        init_revisions(&rev, NULL);
 295        setup_revisions(0, NULL, &rev,
 296                s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
 297        rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
 298        rev.diffopt.format_callback = wt_status_collect_updated_cb;
 299        rev.diffopt.format_callback_data = s;
 300        rev.diffopt.detect_rename = 1;
 301        rev.diffopt.rename_limit = 200;
 302        rev.diffopt.break_opt = 0;
 303        rev.prune_data = s->pathspec;
 304        run_diff_index(&rev, 1);
 305}
 306
 307static void wt_status_collect_changes_initial(struct wt_status *s)
 308{
 309        int i;
 310
 311        for (i = 0; i < active_nr; i++) {
 312                struct string_list_item *it;
 313                struct wt_status_change_data *d;
 314                struct cache_entry *ce = active_cache[i];
 315
 316                if (!ce_path_match(ce, s->pathspec))
 317                        continue;
 318                it = string_list_insert(ce->name, &s->change);
 319                d = it->util;
 320                if (!d) {
 321                        d = xcalloc(1, sizeof(*d));
 322                        it->util = d;
 323                }
 324                if (ce_stage(ce)) {
 325                        d->index_status = DIFF_STATUS_UNMERGED;
 326                        d->stagemask |= (1 << (ce_stage(ce) - 1));
 327                }
 328                else
 329                        d->index_status = DIFF_STATUS_ADDED;
 330        }
 331}
 332
 333static void wt_status_collect_untracked(struct wt_status *s)
 334{
 335        int i;
 336        struct dir_struct dir;
 337
 338        if (!s->show_untracked_files)
 339                return;
 340        memset(&dir, 0, sizeof(dir));
 341        if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
 342                dir.flags |=
 343                        DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
 344        setup_standard_excludes(&dir);
 345
 346        fill_directory(&dir, NULL);
 347        for (i = 0; i < dir.nr; i++) {
 348                struct dir_entry *ent = dir.entries[i];
 349                if (!cache_name_is_other(ent->name, ent->len))
 350                        continue;
 351                if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))
 352                        continue;
 353                s->workdir_untracked = 1;
 354                string_list_insert(ent->name, &s->untracked);
 355        }
 356}
 357
 358void wt_status_collect(struct wt_status *s)
 359{
 360        wt_status_collect_changes_worktree(s);
 361
 362        if (s->is_initial)
 363                wt_status_collect_changes_initial(s);
 364        else
 365                wt_status_collect_changes_index(s);
 366        wt_status_collect_untracked(s);
 367}
 368
 369static void wt_status_print_unmerged(struct wt_status *s)
 370{
 371        int shown_header = 0;
 372        int i;
 373
 374        for (i = 0; i < s->change.nr; i++) {
 375                struct wt_status_change_data *d;
 376                struct string_list_item *it;
 377                it = &(s->change.items[i]);
 378                d = it->util;
 379                if (!d->stagemask)
 380                        continue;
 381                if (!shown_header) {
 382                        wt_status_print_unmerged_header(s);
 383                        shown_header = 1;
 384                }
 385                wt_status_print_unmerged_data(s, it);
 386        }
 387        if (shown_header)
 388                wt_status_print_trailer(s);
 389
 390}
 391
 392static void wt_status_print_updated(struct wt_status *s)
 393{
 394        int shown_header = 0;
 395        int i;
 396
 397        for (i = 0; i < s->change.nr; i++) {
 398                struct wt_status_change_data *d;
 399                struct string_list_item *it;
 400                it = &(s->change.items[i]);
 401                d = it->util;
 402                if (!d->index_status ||
 403                    d->index_status == DIFF_STATUS_UNMERGED)
 404                        continue;
 405                if (!shown_header) {
 406                        wt_status_print_cached_header(s);
 407                        s->commitable = 1;
 408                        shown_header = 1;
 409                }
 410                wt_status_print_change_data(s, WT_STATUS_UPDATED, it);
 411        }
 412        if (shown_header)
 413                wt_status_print_trailer(s);
 414}
 415
 416/*
 417 * -1 : has delete
 418 *  0 : no change
 419 *  1 : some change but no delete
 420 */
 421static int wt_status_check_worktree_changes(struct wt_status *s)
 422{
 423        int i;
 424        int changes = 0;
 425
 426        for (i = 0; i < s->change.nr; i++) {
 427                struct wt_status_change_data *d;
 428                d = s->change.items[i].util;
 429                if (!d->worktree_status ||
 430                    d->worktree_status == DIFF_STATUS_UNMERGED)
 431                        continue;
 432                changes = 1;
 433                if (d->worktree_status == DIFF_STATUS_DELETED)
 434                        return -1;
 435        }
 436        return changes;
 437}
 438
 439static void wt_status_print_changed(struct wt_status *s)
 440{
 441        int i;
 442        int worktree_changes = wt_status_check_worktree_changes(s);
 443
 444        if (!worktree_changes)
 445                return;
 446
 447        wt_status_print_dirty_header(s, worktree_changes < 0);
 448
 449        for (i = 0; i < s->change.nr; i++) {
 450                struct wt_status_change_data *d;
 451                struct string_list_item *it;
 452                it = &(s->change.items[i]);
 453                d = it->util;
 454                if (!d->worktree_status ||
 455                    d->worktree_status == DIFF_STATUS_UNMERGED)
 456                        continue;
 457                wt_status_print_change_data(s, WT_STATUS_CHANGED, it);
 458        }
 459        wt_status_print_trailer(s);
 460}
 461
 462static void wt_status_print_submodule_summary(struct wt_status *s)
 463{
 464        struct child_process sm_summary;
 465        char summary_limit[64];
 466        char index[PATH_MAX];
 467        const char *env[] = { index, NULL };
 468        const char *argv[] = {
 469                "submodule",
 470                "summary",
 471                "--cached",
 472                "--for-status",
 473                "--summary-limit",
 474                summary_limit,
 475                s->amend ? "HEAD^" : "HEAD",
 476                NULL
 477        };
 478
 479        sprintf(summary_limit, "%d", s->submodule_summary);
 480        snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
 481
 482        memset(&sm_summary, 0, sizeof(sm_summary));
 483        sm_summary.argv = argv;
 484        sm_summary.env = env;
 485        sm_summary.git_cmd = 1;
 486        sm_summary.no_stdin = 1;
 487        fflush(s->fp);
 488        sm_summary.out = dup(fileno(s->fp));    /* run_command closes it */
 489        run_command(&sm_summary);
 490}
 491
 492static void wt_status_print_untracked(struct wt_status *s)
 493{
 494        int i;
 495        struct strbuf buf = STRBUF_INIT;
 496
 497        if (!s->untracked.nr)
 498                return;
 499
 500        wt_status_print_untracked_header(s);
 501        for (i = 0; i < s->untracked.nr; i++) {
 502                struct string_list_item *it;
 503                it = &(s->untracked.items[i]);
 504                color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
 505                color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s",
 506                                 quote_path(it->string, strlen(it->string),
 507                                            &buf, s->prefix));
 508        }
 509        strbuf_release(&buf);
 510}
 511
 512static void wt_status_print_verbose(struct wt_status *s)
 513{
 514        struct rev_info rev;
 515
 516        init_revisions(&rev, NULL);
 517        DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
 518        setup_revisions(0, NULL, &rev,
 519                s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
 520        rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
 521        rev.diffopt.detect_rename = 1;
 522        rev.diffopt.file = s->fp;
 523        rev.diffopt.close_file = 0;
 524        /*
 525         * If we're not going to stdout, then we definitely don't
 526         * want color, since we are going to the commit message
 527         * file (and even the "auto" setting won't work, since it
 528         * will have checked isatty on stdout).
 529         */
 530        if (s->fp != stdout)
 531                DIFF_OPT_CLR(&rev.diffopt, COLOR_DIFF);
 532        run_diff_index(&rev, 1);
 533}
 534
 535static void wt_status_print_tracking(struct wt_status *s)
 536{
 537        struct strbuf sb = STRBUF_INIT;
 538        const char *cp, *ep;
 539        struct branch *branch;
 540
 541        assert(s->branch && !s->is_initial);
 542        if (prefixcmp(s->branch, "refs/heads/"))
 543                return;
 544        branch = branch_get(s->branch + 11);
 545        if (!format_tracking_info(branch, &sb))
 546                return;
 547
 548        for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
 549                color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
 550                                 "# %.*s", (int)(ep - cp), cp);
 551        color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
 552}
 553
 554void wt_status_print(struct wt_status *s)
 555{
 556        const char *branch_color = color(WT_STATUS_HEADER, s);
 557
 558        if (s->branch) {
 559                const char *on_what = "On branch ";
 560                const char *branch_name = s->branch;
 561                if (!prefixcmp(branch_name, "refs/heads/"))
 562                        branch_name += 11;
 563                else if (!strcmp(branch_name, "HEAD")) {
 564                        branch_name = "";
 565                        branch_color = color(WT_STATUS_NOBRANCH, s);
 566                        on_what = "Not currently on any branch.";
 567                }
 568                color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
 569                color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
 570                if (!s->is_initial)
 571                        wt_status_print_tracking(s);
 572        }
 573
 574        if (s->is_initial) {
 575                color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
 576                color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit");
 577                color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
 578        }
 579
 580        wt_status_print_updated(s);
 581        wt_status_print_unmerged(s);
 582        wt_status_print_changed(s);
 583        if (s->submodule_summary)
 584                wt_status_print_submodule_summary(s);
 585        if (s->show_untracked_files)
 586                wt_status_print_untracked(s);
 587        else if (s->commitable)
 588                 fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n");
 589
 590        if (s->verbose)
 591                wt_status_print_verbose(s);
 592        if (!s->commitable) {
 593                if (s->amend)
 594                        fprintf(s->fp, "# No changes\n");
 595                else if (s->nowarn)
 596                        ; /* nothing */
 597                else if (s->workdir_dirty)
 598                        printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n");
 599                else if (s->untracked.nr)
 600                        printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
 601                else if (s->is_initial)
 602                        printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
 603                else if (!s->show_untracked_files)
 604                        printf("nothing to commit (use -u to show untracked files)\n");
 605                else
 606                        printf("nothing to commit (working directory clean)\n");
 607        }
 608}
 609
 610static void wt_shortstatus_unmerged(int null_termination, struct string_list_item *it,
 611                           struct wt_status *s)
 612{
 613        struct wt_status_change_data *d = it->util;
 614        const char *how = "??";
 615
 616        switch (d->stagemask) {
 617        case 1: how = "DD"; break; /* both deleted */
 618        case 2: how = "AU"; break; /* added by us */
 619        case 3: how = "UD"; break; /* deleted by them */
 620        case 4: how = "UA"; break; /* added by them */
 621        case 5: how = "DU"; break; /* deleted by us */
 622        case 6: how = "AA"; break; /* both added */
 623        case 7: how = "UU"; break; /* both modified */
 624        }
 625        color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how);
 626        if (null_termination) {
 627                fprintf(stdout, " %s%c", it->string, 0);
 628        } else {
 629                struct strbuf onebuf = STRBUF_INIT;
 630                const char *one;
 631                one = quote_path(it->string, -1, &onebuf, s->prefix);
 632                printf(" %s\n", one);
 633                strbuf_release(&onebuf);
 634        }
 635}
 636
 637static void wt_shortstatus_status(int null_termination, struct string_list_item *it,
 638                         struct wt_status *s)
 639{
 640        struct wt_status_change_data *d = it->util;
 641
 642        if (d->index_status)
 643                color_fprintf(s->fp, color(WT_STATUS_UPDATED, s), "%c", d->index_status);
 644        else
 645                putchar(' ');
 646        if (d->worktree_status)
 647                color_fprintf(s->fp, color(WT_STATUS_CHANGED, s), "%c", d->worktree_status);
 648        else
 649                putchar(' ');
 650        putchar(' ');
 651        if (null_termination) {
 652                fprintf(stdout, "%s%c", it->string, 0);
 653                if (d->head_path)
 654                        fprintf(stdout, "%s%c", d->head_path, 0);
 655        } else {
 656                struct strbuf onebuf = STRBUF_INIT;
 657                const char *one;
 658                if (d->head_path) {
 659                        one = quote_path(d->head_path, -1, &onebuf, s->prefix);
 660                        printf("%s -> ", one);
 661                        strbuf_release(&onebuf);
 662                }
 663                one = quote_path(it->string, -1, &onebuf, s->prefix);
 664                printf("%s\n", one);
 665                strbuf_release(&onebuf);
 666        }
 667}
 668
 669static void wt_shortstatus_untracked(int null_termination, struct string_list_item *it,
 670                            struct wt_status *s)
 671{
 672        if (null_termination) {
 673                fprintf(stdout, "?? %s%c", it->string, 0);
 674        } else {
 675                struct strbuf onebuf = STRBUF_INIT;
 676                const char *one;
 677                one = quote_path(it->string, -1, &onebuf, s->prefix);
 678                color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "??");
 679                printf(" %s\n", one);
 680                strbuf_release(&onebuf);
 681        }
 682}
 683
 684void wt_shortstatus_print(struct wt_status *s, int null_termination)
 685{
 686        int i;
 687        for (i = 0; i < s->change.nr; i++) {
 688                struct wt_status_change_data *d;
 689                struct string_list_item *it;
 690
 691                it = &(s->change.items[i]);
 692                d = it->util;
 693                if (d->stagemask)
 694                        wt_shortstatus_unmerged(null_termination, it, s);
 695                else
 696                        wt_shortstatus_status(null_termination, it, s);
 697        }
 698        for (i = 0; i < s->untracked.nr; i++) {
 699                struct string_list_item *it;
 700
 701                it = &(s->untracked.items[i]);
 702                wt_shortstatus_untracked(null_termination, it, s);
 703        }
 704}
 705
 706void wt_porcelain_print(struct wt_status *s, int null_termination)
 707{
 708        s->use_color = 0;
 709        s->relative_paths = 0;
 710        s->prefix = NULL;
 711        wt_shortstatus_print(s, null_termination);
 712}