diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-07-19 13:22:15 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-19 13:22:15 -0700 |
commit | 63641fb07131bede8273c3b3057792c9dcf7356b (patch) | |
tree | 9306790da18384a4ef34a1d4218b081e19b965ec /builtin/shortlog.c | |
parent | Merge branch 'sb/submodule-parallel-fetch' (diff) | |
parent | mingw: fix the shortlog --output=<file> test (diff) | |
download | tgif-63641fb07131bede8273c3b3057792c9dcf7356b.tar.xz |
Merge branch 'js/log-to-diffopt-file'
The commands in the "log/diff" family have had an FILE* pointer in the
data structure they pass around for a long time, but some codepaths
used to always write to the standard output. As a preparatory step
to make "git format-patch" available to the internal callers, these
codepaths have been updated to consistently write into that FILE*
instead.
* js/log-to-diffopt-file:
mingw: fix the shortlog --output=<file> test
diff: do not color output when --color=auto and --output=<file> is given
t4211: ensure that log respects --output=<file>
shortlog: respect the --output=<file> setting
format-patch: use stdout directly
format-patch: avoid freopen()
format-patch: explicitly switch off color when writing to files
shortlog: support outputting to streams other than stdout
graph: respect the diffopt.file setting
line-log: respect diffopt's configured output file stream
log-tree: respect diffopt's configured output file stream
log: prepare log/log-tree to reuse the diffopt.close_file attribute
Diffstat (limited to 'builtin/shortlog.c')
-rw-r--r-- | builtin/shortlog.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/builtin/shortlog.c b/builtin/shortlog.c index f83984e8a1..25fa8a6aed 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -276,6 +276,7 @@ parse_done: log.user_format = rev.commit_format == CMIT_FMT_USERFORMAT; log.abbrev = rev.abbrev; + log.file = rev.diffopt.file; /* assume HEAD if from a tty */ if (!nongit && !rev.pending.nr && isatty(0)) @@ -289,6 +290,8 @@ parse_done: get_from_rev(&rev, &log); shortlog_output(&log); + if (log.file != stdout) + fclose(log.file); return 0; } @@ -310,22 +313,24 @@ void shortlog_output(struct shortlog *log) for (i = 0; i < log->list.nr; i++) { const struct string_list_item *item = &log->list.items[i]; if (log->summary) { - printf("%6d\t%s\n", (int)UTIL_TO_INT(item), item->string); + fprintf(log->file, "%6d\t%s\n", + (int)UTIL_TO_INT(item), item->string); } else { struct string_list *onelines = item->util; - printf("%s (%d):\n", item->string, onelines->nr); + fprintf(log->file, "%s (%d):\n", + item->string, onelines->nr); for (j = onelines->nr - 1; j >= 0; j--) { const char *msg = onelines->items[j].string; if (log->wrap_lines) { strbuf_reset(&sb); add_wrapped_shortlog_msg(&sb, msg, log); - fwrite(sb.buf, sb.len, 1, stdout); + fwrite(sb.buf, sb.len, 1, log->file); } else - printf(" %s\n", msg); + fprintf(log->file, " %s\n", msg); } - putchar('\n'); + putc('\n', log->file); onelines->strdup_strings = 1; string_list_clear(onelines, 0); free(onelines); |