shortlog: respect the --output=<file> setting
[gitweb.git] / builtin / shortlog.c
index bfc082e58467953c1e4c96fd27a884abea4f5127..be8054791e1d4fd656c7e311f2e4f21ff5ca94d4 100644 (file)
@@ -276,6 +276,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
 
        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 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
                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);