summaryrefslogtreecommitdiff
path: root/builtin/shortlog.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-07-19 20:22:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-07-19 20:22:15 (GMT)
commit63641fb07131bede8273c3b3057792c9dcf7356b (patch)
tree9306790da18384a4ef34a1d4218b081e19b965ec /builtin/shortlog.c
parent7725bebe21dfa4877dad74b1ac3d921f26f949cf (diff)
parentbac233f2c28428c3e2c5279910bc4c027cd0b540 (diff)
downloadgit-63641fb07131bede8273c3b3057792c9dcf7356b.zip
git-63641fb07131bede8273c3b3057792c9dcf7356b.tar.gz
git-63641fb07131bede8273c3b3057792c9dcf7356b.tar.bz2
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.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index f83984e..25fa8a6 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);