Skip to content

Commit 0a7b357

Browse files
dschogitster
authored andcommitted
shortlog: support outputting to streams other than stdout
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>
1 parent c61008f commit 0a7b357

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

builtin/shortlog.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ void shortlog_init(struct shortlog *log)
229229
log->wrap = DEFAULT_WRAPLEN;
230230
log->in1 = DEFAULT_INDENT1;
231231
log->in2 = DEFAULT_INDENT2;
232+
log->file = stdout;
232233
}
233234

234235
int cmd_shortlog(int argc, const char **argv, const char *prefix)
@@ -310,22 +311,24 @@ void shortlog_output(struct shortlog *log)
310311
for (i = 0; i < log->list.nr; i++) {
311312
const struct string_list_item *item = &log->list.items[i];
312313
if (log->summary) {
313-
printf("%6d\t%s\n", (int)UTIL_TO_INT(item), item->string);
314+
fprintf(log->file, "%6d\t%s\n",
315+
(int)UTIL_TO_INT(item), item->string);
314316
} else {
315317
struct string_list *onelines = item->util;
316-
printf("%s (%d):\n", item->string, onelines->nr);
318+
fprintf(log->file, "%s (%d):\n",
319+
item->string, onelines->nr);
317320
for (j = onelines->nr - 1; j >= 0; j--) {
318321
const char *msg = onelines->items[j].string;
319322

320323
if (log->wrap_lines) {
321324
strbuf_reset(&sb);
322325
add_wrapped_shortlog_msg(&sb, msg, log);
323-
fwrite(sb.buf, sb.len, 1, stdout);
326+
fwrite(sb.buf, sb.len, 1, log->file);
324327
}
325328
else
326-
printf(" %s\n", msg);
329+
fprintf(log->file, " %s\n", msg);
327330
}
328-
putchar('\n');
331+
putc('\n', log->file);
329332
onelines->strdup_strings = 1;
330333
string_list_clear(onelines, 0);
331334
free(onelines);

shortlog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct shortlog {
1717
char *common_repo_prefix;
1818
int email;
1919
struct string_list mailmap;
20+
FILE *file;
2021
};
2122

2223
void shortlog_init(struct shortlog *log);

0 commit comments

Comments
 (0)