From 7f7d712bcfde8afe0a007042d5cb4b809617fb96 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 22 Jun 2016 17:02:07 +0200 Subject: [PATCH] shortlog: respect the --output= setting Thanks to the diff option parsing, we already know about this option. We just have to make use of it. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin/shortlog.c | 4 +++- t/t4201-shortlog.sh | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 39d74fe23b..be8054791e 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -229,7 +229,6 @@ void shortlog_init(struct shortlog *log) log->wrap = DEFAULT_WRAPLEN; log->in1 = DEFAULT_INDENT1; log->in2 = DEFAULT_INDENT2; - log->file = stdout; } int cmd_shortlog(int argc, const char **argv, const char *prefix) @@ -277,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)) @@ -290,6 +290,8 @@ parse_done: get_from_rev(&rev, &log); shortlog_output(&log); + if (log.file != stdout) + fclose(log.file); return 0; } diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index a9773658f0..bd699e11f1 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -184,4 +184,10 @@ test_expect_success 'shortlog with revision pseudo options' ' git shortlog --exclude=refs/heads/m* --all ' +test_expect_success 'shortlog with --output=' ' + git shortlog --output=shortlog master >output && + test ! -s output && + test_line_count = 7 shortlog +' + test_done -- 2.43.2