]> git.ipfire.org Git - thirdparty/git.git/commitdiff
shortlog: support outputting to streams other than stdout
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 22 Jun 2016 15:01:49 +0000 (17:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Jun 2016 21:25:49 +0000 (14:25 -0700)
This will be needed to avoid freopen() in `git format-patch`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/shortlog.c
shortlog.h

index bfc082e58467953c1e4c96fd27a884abea4f5127..39d74fe23bb8d29fd58a78109aa49d8add0ae8f9 100644 (file)
@@ -229,6 +229,7 @@ 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)
@@ -310,22 +311,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);
index de4f86fb970e15491f44dfe38b7d7d6fdc3be9ad..5a326c68602610d856ac543b8bd034542d83f64b 100644 (file)
@@ -17,6 +17,7 @@ struct shortlog {
        char *common_repo_prefix;
        int email;
        struct string_list mailmap;
+       FILE *file;
 };
 
 void shortlog_init(struct shortlog *log);