]> git.ipfire.org Git - thirdparty/git.git/commitdiff
shortlog: respect the --output=<file> setting
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 22 Jun 2016 15:02:07 +0000 (17:02 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Jun 2016 22:20:47 +0000 (15:20 -0700)
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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/shortlog.c
t/t4201-shortlog.sh

index 39d74fe23bb8d29fd58a78109aa49d8add0ae8f9..be8054791e1d4fd656c7e311f2e4f21ff5ca94d4 100644 (file)
@@ -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;
 }
 
index a9773658f09e92578b489b1b5b65fc87599cb8ae..bd699e11f130d55ab37a036319ee3be448e5297b 100755 (executable)
@@ -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=<file>' '
+       git shortlog --output=shortlog master >output &&
+       test ! -s output &&
+       test_line_count = 7 shortlog
+'
+
 test_done