shortlog: respect the --output=<file> 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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jun 22, 2016 at 17:02 UTC
7f7d712bcfde8afe0a007042d5cb4b809617fb96
2 files changed
+9
-1
builtin/shortlog.c
+3
-1
@@ -229,7 +229,6 @@ void shortlog_init(struct shortlog *log)
229
log->wrap = DEFAULT_WRAPLEN;
230
log->in1 = DEFAULT_INDENT1;
231
log->in2 = DEFAULT_INDENT2;
232
- log->file = stdout;
232
}
233
234
int cmd_shortlog(int argc, const char **argv, const char *prefix)
@@ -277,6 +276,7 @@ parse_done:
276
277
log.user_format = rev.commit_format == CMIT_FMT_USERFORMAT;
278
log.abbrev = rev.abbrev;
279
+ log.file = rev.diffopt.file;
280
281
/* assume HEAD if from a tty */
282
if (!nongit && !rev.pending.nr && isatty(0))
@@ -290,6 +290,8 @@ parse_done:
290
get_from_rev(&rev, &log);
291
292
shortlog_output(&log);
293
+ if (log.file != stdout)
294
+ fclose(log.file);
295
return 0;
296
}
297
t/t4201-shortlog.sh
+6
@@ -184,4 +184,10 @@ test_expect_success 'shortlog with revision pseudo options' '
184
git shortlog --exclude=refs/heads/m* --all
185
'
186
187
+test_expect_success 'shortlog with --output=<file>' '
188
+ git shortlog --output=shortlog master >output &&
189
+ test ! -s output &&
190
+ test_line_count = 7 shortlog
191
+'
192
+
193
test_done