Skip to content

Commit 8f7e3de

Browse files
Martin Ågrengitster
authored andcommitted
wt-status: print to s->fp, not stdout
We pass around a `FILE *` in the `struct wt_status` and almost always print to it. But in a few places, we write to `stdout` instead, either explicitly through `fprintf(stdout, ...)` or implicitly with `printf(...)` (and a few `putchar(...)`). Always be explicit about writing to `s->fp`. To the best of my understanding, this never mattered in practice because these spots are involved in various forms of `git status` which always end up at standard output anyway. When we do write to another file, it's because we're creating a commit message template, and these code paths aren't involved. But let's be consistent to help future readers and avoid future bugs. Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b1f1ade commit 8f7e3de

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

wt-status.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,29 +1801,36 @@ static void wt_longstatus_print(struct wt_status *s)
18011801
; /* nothing */
18021802
else if (s->workdir_dirty) {
18031803
if (s->hints)
1804-
printf(_("no changes added to commit "
1805-
"(use \"git add\" and/or \"git commit -a\")\n"));
1804+
fprintf(s->fp, _("no changes added to commit "
1805+
"(use \"git add\" and/or "
1806+
"\"git commit -a\")\n"));
18061807
else
1807-
printf(_("no changes added to commit\n"));
1808+
fprintf(s->fp, _("no changes added to "
1809+
"commit\n"));
18081810
} else if (s->untracked.nr) {
18091811
if (s->hints)
1810-
printf(_("nothing added to commit but untracked files "
1811-
"present (use \"git add\" to track)\n"));
1812+
fprintf(s->fp, _("nothing added to commit but "
1813+
"untracked files present (use "
1814+
"\"git add\" to track)\n"));
18121815
else
1813-
printf(_("nothing added to commit but untracked files present\n"));
1816+
fprintf(s->fp, _("nothing added to commit but "
1817+
"untracked files present\n"));
18141818
} else if (s->is_initial) {
18151819
if (s->hints)
1816-
printf(_("nothing to commit (create/copy files "
1817-
"and use \"git add\" to track)\n"));
1820+
fprintf(s->fp, _("nothing to commit (create/"
1821+
"copy files and use \"git "
1822+
"add\" to track)\n"));
18181823
else
1819-
printf(_("nothing to commit\n"));
1824+
fprintf(s->fp, _("nothing to commit\n"));
18201825
} else if (!s->show_untracked_files) {
18211826
if (s->hints)
1822-
printf(_("nothing to commit (use -u to show untracked files)\n"));
1827+
fprintf(s->fp, _("nothing to commit (use -u to "
1828+
"show untracked files)\n"));
18231829
else
1824-
printf(_("nothing to commit\n"));
1830+
fprintf(s->fp, _("nothing to commit\n"));
18251831
} else
1826-
printf(_("nothing to commit, working tree clean\n"));
1832+
fprintf(s->fp, _("nothing to commit, working tree "
1833+
"clean\n"));
18271834
}
18281835
if(s->show_stash)
18291836
wt_longstatus_print_stash_summary(s);
@@ -1846,12 +1853,12 @@ static void wt_shortstatus_unmerged(struct string_list_item *it,
18461853
}
18471854
color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how);
18481855
if (s->null_termination) {
1849-
fprintf(stdout, " %s%c", it->string, 0);
1856+
fprintf(s->fp, " %s%c", it->string, 0);
18501857
} else {
18511858
struct strbuf onebuf = STRBUF_INIT;
18521859
const char *one;
18531860
one = quote_path(it->string, s->prefix, &onebuf);
1854-
printf(" %s\n", one);
1861+
fprintf(s->fp, " %s\n", one);
18551862
strbuf_release(&onebuf);
18561863
}
18571864
}
@@ -1864,37 +1871,37 @@ static void wt_shortstatus_status(struct string_list_item *it,
18641871
if (d->index_status)
18651872
color_fprintf(s->fp, color(WT_STATUS_UPDATED, s), "%c", d->index_status);
18661873
else
1867-
putchar(' ');
1874+
fputc(' ', s->fp);
18681875
if (d->worktree_status)
18691876
color_fprintf(s->fp, color(WT_STATUS_CHANGED, s), "%c", d->worktree_status);
18701877
else
1871-
putchar(' ');
1872-
putchar(' ');
1878+
fputc(' ', s->fp);
1879+
fputc(' ', s->fp);
18731880
if (s->null_termination) {
1874-
fprintf(stdout, "%s%c", it->string, 0);
1881+
fprintf(s->fp, "%s%c", it->string, 0);
18751882
if (d->rename_source)
1876-
fprintf(stdout, "%s%c", d->rename_source, 0);
1883+
fprintf(s->fp, "%s%c", d->rename_source, 0);
18771884
} else {
18781885
struct strbuf onebuf = STRBUF_INIT;
18791886
const char *one;
18801887

18811888
if (d->rename_source) {
18821889
one = quote_path(d->rename_source, s->prefix, &onebuf);
18831890
if (*one != '"' && strchr(one, ' ') != NULL) {
1884-
putchar('"');
1891+
fputc('"', s->fp);
18851892
strbuf_addch(&onebuf, '"');
18861893
one = onebuf.buf;
18871894
}
1888-
printf("%s -> ", one);
1895+
fprintf(s->fp, "%s -> ", one);
18891896
strbuf_release(&onebuf);
18901897
}
18911898
one = quote_path(it->string, s->prefix, &onebuf);
18921899
if (*one != '"' && strchr(one, ' ') != NULL) {
1893-
putchar('"');
1900+
fputc('"', s->fp);
18941901
strbuf_addch(&onebuf, '"');
18951902
one = onebuf.buf;
18961903
}
1897-
printf("%s\n", one);
1904+
fprintf(s->fp, "%s\n", one);
18981905
strbuf_release(&onebuf);
18991906
}
19001907
}
@@ -1903,13 +1910,13 @@ static void wt_shortstatus_other(struct string_list_item *it,
19031910
struct wt_status *s, const char *sign)
19041911
{
19051912
if (s->null_termination) {
1906-
fprintf(stdout, "%s %s%c", sign, it->string, 0);
1913+
fprintf(s->fp, "%s %s%c", sign, it->string, 0);
19071914
} else {
19081915
struct strbuf onebuf = STRBUF_INIT;
19091916
const char *one;
19101917
one = quote_path(it->string, s->prefix, &onebuf);
19111918
color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign);
1912-
printf(" %s\n", one);
1919+
fprintf(s->fp, " %s\n", one);
19131920
strbuf_release(&onebuf);
19141921
}
19151922
}

0 commit comments

Comments
 (0)