void graph_show_commit(struct git_graph *graph) { struct strbuf msgbuf = STRBUF_INIT; int shown_commit_line = 0; if (!graph) return; /* * When showing a diff of a merge against each of its parents, we * are called once for each parent without graph_update having been * called. In this case, simply output a single padding line. */ if (graph_is_commit_finished(graph)) { graph_show_padding(graph); shown_commit_line = 1; } while (!shown_commit_line && !graph_is_commit_finished(graph)) { shown_commit_line = graph_next_line(graph, &msgbuf); fwrite(msgbuf.buf, sizeof(char), msgbuf.len, graph->revs->diffopt.file); if (!shown_commit_line) putc('\n', graph->revs->diffopt.file); strbuf_setlen(&msgbuf, 0); } strbuf_release(&msgbuf); }
int graph_show_remainder(struct git_graph *graph) { struct strbuf msgbuf = STRBUF_INIT; int shown = 0; if (!graph) return 0; if (graph_is_commit_finished(graph)) return 0; for (;;) { graph_next_line(graph, &msgbuf); fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); strbuf_setlen(&msgbuf, 0); shown = 1; if (!graph_is_commit_finished(graph)) putchar('\n'); else break; } strbuf_release(&msgbuf); return shown; }
int graph_show_remainder(struct git_graph *graph) { struct strbuf msgbuf = STRBUF_INIT; int shown = 0; graph_show_line_prefix(default_diffopt); if (!graph) return 0; if (graph_is_commit_finished(graph)) return 0; for (;;) { graph_next_line(graph, &msgbuf); fwrite(msgbuf.buf, sizeof(char), msgbuf.len, graph->revs->diffopt.file); strbuf_setlen(&msgbuf, 0); shown = 1; if (!graph_is_commit_finished(graph)) { putc('\n', graph->revs->diffopt.file); graph_show_line_prefix(&graph->revs->diffopt); } else { break; } } strbuf_release(&msgbuf); return shown; }
void graph_show_commit_msg(struct git_graph *graph, struct strbuf const *sb) { int newline_terminated; if (!graph) { /* * If there's no graph, just print the message buffer. * * The message buffer for CMIT_FMT_ONELINE and * CMIT_FMT_USERFORMAT are already missing a terminating * newline. All of the other formats should have it. */ fwrite(sb->buf, sizeof(char), sb->len, graph->revs->diffopt.file); return; } newline_terminated = (sb->len && sb->buf[sb->len - 1] == '\n'); /* * Show the commit message */ graph_show_strbuf(graph, sb); /* * If there is more output needed for this commit, show it now */ if (!graph_is_commit_finished(graph)) { /* * If sb doesn't have a terminating newline, print one now, * so we can start the remainder of the graph output on a * new line. */ if (!newline_terminated) putc('\n', graph->revs->diffopt.file); graph_show_remainder(graph); /* * If sb ends with a newline, our output should too. */ if (newline_terminated) putc('\n', graph->revs->diffopt.file); } }
void graph_show_commit(struct git_graph *graph) { struct strbuf msgbuf = STRBUF_INIT; int shown_commit_line = 0; if (!graph) return; while (!shown_commit_line && !graph_is_commit_finished(graph)) { shown_commit_line = graph_next_line(graph, &msgbuf); fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); if (!shown_commit_line) putchar('\n'); strbuf_setlen(&msgbuf, 0); } strbuf_release(&msgbuf); }
void graph_show_commit_msg(struct git_graph *graph, FILE *file, struct strbuf const *sb) { int newline_terminated; /* * Show the commit message */ graph_show_strbuf(graph, file, sb); if (!graph) return; newline_terminated = (sb->len && sb->buf[sb->len - 1] == '\n'); /* * If there is more output needed for this commit, show it now */ if (!graph_is_commit_finished(graph)) { /* * If sb doesn't have a terminating newline, print one now, * so we can start the remainder of the graph output on a * new line. */ if (!newline_terminated) putc('\n', file); graph_show_remainder(graph); /* * If sb ends with a newline, our output should too. */ if (newline_terminated) putc('\n', file); } }
void show_log(struct rev_info *opt) { struct strbuf msgbuf = STRBUF_INIT; struct log_info *log = opt->loginfo; struct commit *commit = log->commit, *parent = log->parent; int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; const char *extra_headers = opt->extra_headers; struct pretty_print_context ctx = {0}; opt->loginfo = NULL; ctx.show_notes = opt->show_notes; if (!opt->verbose_header) { graph_show_commit(opt->graph); if (!opt->graph) put_revision_mark(opt, commit); fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) show_parents(commit, abbrev_commit); if (opt->children.name) show_children(opt, commit, abbrev_commit); show_decorations(opt, commit); if (opt->graph && !graph_is_commit_finished(opt->graph)) { putchar('\n'); graph_show_remainder(opt->graph); } putchar(opt->diffopt.line_termination); return; } /* * If use_terminator is set, we already handled any record termination * at the end of the last record. * Otherwise, add a diffopt.line_termination character before all * entries but the first. (IOW, as a separator between entries) */ if (opt->shown_one && !opt->use_terminator) { /* * If entries are separated by a newline, the output * should look human-readable. If the last entry ended * with a newline, print the graph output before this * newline. Otherwise it will end up as a completely blank * line and will look like a gap in the graph. * * If the entry separator is not a newline, the output is * primarily intended for programmatic consumption, and we * never want the extra graph output before the entry * separator. */ if (opt->diffopt.line_termination == '\n' && !opt->missing_newline) graph_show_padding(opt->graph); putchar(opt->diffopt.line_termination); } opt->shown_one = 1; /* * If the history graph was requested, * print the graph, up to this commit's line */ graph_show_commit(opt->graph); /* * Print header line of header.. */ if (opt->commit_format == CMIT_FMT_EMAIL) { log_write_email_headers(opt, commit, &ctx.subject, &extra_headers, &ctx.need_8bit_cte); } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout); if (opt->commit_format != CMIT_FMT_ONELINE) fputs("commit ", stdout); if (!opt->graph) put_revision_mark(opt, commit); fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) show_parents(commit, abbrev_commit); if (opt->children.name) show_children(opt, commit, abbrev_commit); if (parent) printf(" (from %s)", find_unique_abbrev(parent->object.sha1, abbrev_commit)); show_decorations(opt, commit); printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET)); if (opt->commit_format == CMIT_FMT_ONELINE) { putchar(' '); } else { putchar('\n'); graph_show_oneline(opt->graph); } if (opt->reflog_info) { /* * setup_revisions() ensures that opt->reflog_info * and opt->graph cannot both be set, * so we don't need to worry about printing the * graph info here. */ show_reflog_message(opt->reflog_info, opt->commit_format == CMIT_FMT_ONELINE, opt->date_mode, opt->date_mode_explicit); if (opt->commit_format == CMIT_FMT_ONELINE) return; } } if (opt->show_signature) { show_signature(opt, commit); show_mergetag(opt, commit); } if (!commit->buffer) return; /* * And then the pretty-printed message itself */ if (ctx.need_8bit_cte >= 0) ctx.need_8bit_cte = has_non_ascii(opt->add_signoff); ctx.date_mode = opt->date_mode; ctx.date_mode_explicit = opt->date_mode_explicit; ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; ctx.preserve_subject = opt->preserve_subject; ctx.reflog_info = opt->reflog_info; ctx.fmt = opt->commit_format; pretty_print_commit(&ctx, commit, &msgbuf); if (opt->add_signoff) append_signoff(&msgbuf, opt->add_signoff); if (opt->show_log_size) { printf("log size %i\n", (int)msgbuf.len); graph_show_oneline(opt->graph); } /* * Set opt->missing_newline if msgbuf doesn't * end in a newline (including if it is empty) */ if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n') opt->missing_newline = 1; else opt->missing_newline = 0; if (opt->graph) graph_show_commit_msg(opt->graph, &msgbuf); else fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); if (opt->use_terminator) { if (!opt->missing_newline) graph_show_padding(opt->graph); putchar(opt->diffopt.line_termination); } strbuf_release(&msgbuf); }
void print_commit(struct commit *commit, struct rev_info *revs) { struct commitinfo *info; int cols = revs->graph ? 3 : 2; struct strbuf graphbuf = STRBUF_INIT; struct strbuf msgbuf = STRBUF_INIT; if (ctx.repo->enable_log_filecount) cols++; if (ctx.repo->enable_log_linecount) cols++; if (revs->graph) { /* Advance graph until current commit */ while (!graph_next_line(revs->graph, &graphbuf)) { /* Print graph segment in otherwise empty table row */ html("<tr class='nohover'><td class='commitgraph'>"); html(graphbuf.buf); htmlf("</td><td colspan='%d' /></tr>\n", cols); strbuf_setlen(&graphbuf, 0); } /* Current commit's graph segment is now ready in graphbuf */ } info = cgit_parse_commit(commit); htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : ""); if (revs->graph) { /* Print graph segment for current commit */ html("<td class='commitgraph'>"); html(graphbuf.buf); html("</td>"); strbuf_setlen(&graphbuf, 0); } else { html("<td>"); cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); html("</td>"); } htmlf("<td%s>", ctx.qry.showmsg ? " class='logsubject'" : ""); if (ctx.qry.showmsg) { /* line-wrap long commit subjects instead of truncating them */ size_t subject_len = strlen(info->subject); if (subject_len > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { /* symbol for signaling line-wrap (in PAGE_ENCODING) */ const char wrap_symbol[] = { ' ', 0xE2, 0x86, 0xB5, 0 }; int i = ctx.cfg.max_msg_len - strlen(wrap_symbol); /* Rewind i to preceding space character */ while (i > 0 && !isspace(info->subject[i])) --i; if (!i) /* Oops, zero spaces. Reset i */ i = ctx.cfg.max_msg_len - strlen(wrap_symbol); /* add remainder starting at i to msgbuf */ strbuf_add(&msgbuf, info->subject + i, subject_len - i); strbuf_trim(&msgbuf); strbuf_add(&msgbuf, "\n\n", 2); /* Place wrap_symbol at position i in info->subject */ strcpy(info->subject + i, wrap_symbol); } } cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); show_commit_decorations(commit); html("</td><td>"); html_txt(info->author); if (revs->graph) { html("</td><td>"); cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); } if (ctx.repo->enable_log_filecount || ctx.repo->enable_log_linecount) { files = 0; add_lines = 0; rem_lines = 0; cgit_diff_commit(commit, inspect_files, ctx.qry.vpath); } if (ctx.repo->enable_log_filecount) htmlf("</td><td>%d", files); if (ctx.repo->enable_log_linecount) htmlf("</td><td>-%d/+%d", rem_lines, add_lines); html("</td></tr>\n"); if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */ html("<tr class='nohover'>"); if (ctx.qry.showmsg) { /* Concatenate commit message + notes in msgbuf */ if (info->msg && *(info->msg)) { strbuf_addstr(&msgbuf, info->msg); strbuf_addch(&msgbuf, '\n'); } format_note(NULL, commit->object.sha1, &msgbuf, PAGE_ENCODING, NOTES_SHOW_HEADER | NOTES_INDENT); strbuf_addch(&msgbuf, '\n'); strbuf_ltrim(&msgbuf); } if (revs->graph) { int lines = 0; /* Calculate graph padding */ if (ctx.qry.showmsg) { /* Count #lines in commit message + notes */ const char *p = msgbuf.buf; lines = 1; while ((p = strchr(p, '\n'))) { p++; lines++; } } /* Print graph padding */ html("<td class='commitgraph'>"); while (lines > 0 || !graph_is_commit_finished(revs->graph)) { if (graphbuf.len) html("\n"); strbuf_setlen(&graphbuf, 0); graph_next_line(revs->graph, &graphbuf); html(graphbuf.buf); lines--; } html("</td>\n"); } else html("<td/>"); /* Empty 'Age' column */ /* Print msgbuf into remainder of table row */ htmlf("<td colspan='%d'%s>\n", cols, ctx.qry.showmsg ? " class='logmsg'" : ""); html_txt(msgbuf.buf); html("</td></tr>\n"); } strbuf_release(&msgbuf); strbuf_release(&graphbuf); cgit_free_commitinfo(info); }
void show_log(struct rev_info *opt) { struct strbuf msgbuf = STRBUF_INIT; struct log_info *log = opt->loginfo; struct commit *commit = log->commit, *parent = log->parent; int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; const char *extra_headers = opt->extra_headers; struct pretty_print_context ctx = {0}; opt->loginfo = NULL; if (!opt->verbose_header) { graph_show_commit(opt->graph); if (!opt->graph) put_revision_mark(opt, commit); fputs(find_unique_abbrev(commit->object.oid.hash, abbrev_commit), opt->diffopt.file); if (opt->print_parents) show_parents(commit, abbrev_commit, opt->diffopt.file); if (opt->children.name) show_children(opt, commit, abbrev_commit); show_decorations(opt, commit); if (opt->graph && !graph_is_commit_finished(opt->graph)) { putc('\n', opt->diffopt.file); graph_show_remainder(opt->graph); } putc(opt->diffopt.line_termination, opt->diffopt.file); return; } /* * If use_terminator is set, we already handled any record termination * at the end of the last record. * Otherwise, add a diffopt.line_termination character before all * entries but the first. (IOW, as a separator between entries) */ if (opt->shown_one && !opt->use_terminator) { /* * If entries are separated by a newline, the output * should look human-readable. If the last entry ended * with a newline, print the graph output before this * newline. Otherwise it will end up as a completely blank * line and will look like a gap in the graph. * * If the entry separator is not a newline, the output is * primarily intended for programmatic consumption, and we * never want the extra graph output before the entry * separator. */ if (opt->diffopt.line_termination == '\n' && !opt->missing_newline) graph_show_padding(opt->graph); putc(opt->diffopt.line_termination, opt->diffopt.file); } opt->shown_one = 1; /* * If the history graph was requested, * print the graph, up to this commit's line */ graph_show_commit(opt->graph); /* * Print header line of header.. */ if (cmit_fmt_is_mail(opt->commit_format)) { log_write_email_headers(opt, commit, &ctx.subject, &extra_headers, &ctx.need_8bit_cte); } else if (opt->commit_format != CMIT_FMT_USERFORMAT) { fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), opt->diffopt.file); if (opt->commit_format != CMIT_FMT_ONELINE) fputs("commit ", opt->diffopt.file); if (!opt->graph) put_revision_mark(opt, commit); fputs(find_unique_abbrev(commit->object.oid.hash, abbrev_commit), opt->diffopt.file); if (opt->print_parents) show_parents(commit, abbrev_commit, opt->diffopt.file); if (opt->children.name) show_children(opt, commit, abbrev_commit); if (parent) fprintf(opt->diffopt.file, " (from %s)", find_unique_abbrev(parent->object.oid.hash, abbrev_commit)); fputs(diff_get_color_opt(&opt->diffopt, DIFF_RESET), opt->diffopt.file); show_decorations(opt, commit); if (opt->commit_format == CMIT_FMT_ONELINE) { putc(' ', opt->diffopt.file); } else { putc('\n', opt->diffopt.file); graph_show_oneline(opt->graph); } if (opt->reflog_info) { /* * setup_revisions() ensures that opt->reflog_info * and opt->graph cannot both be set, * so we don't need to worry about printing the * graph info here. */ show_reflog_message(opt->reflog_info, opt->commit_format == CMIT_FMT_ONELINE, &opt->date_mode, opt->date_mode_explicit); if (opt->commit_format == CMIT_FMT_ONELINE) return; } } if (opt->show_signature) { show_signature(opt, commit); show_mergetag(opt, commit); } if (!get_cached_commit_buffer(commit, NULL)) return; if (opt->show_notes) { int raw; struct strbuf notebuf = STRBUF_INIT; raw = (opt->commit_format == CMIT_FMT_USERFORMAT); format_display_notes(commit->object.oid.hash, ¬ebuf, get_log_output_encoding(), raw); ctx.notes_message = notebuf.len ? strbuf_detach(¬ebuf, NULL) : xcalloc(1, 1); } /* * And then the pretty-printed message itself */ if (ctx.need_8bit_cte >= 0 && opt->add_signoff) ctx.need_8bit_cte = has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"), getenv("GIT_COMMITTER_EMAIL"))); ctx.date_mode = opt->date_mode; ctx.date_mode_explicit = opt->date_mode_explicit; ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; ctx.preserve_subject = opt->preserve_subject; ctx.reflog_info = opt->reflog_info; ctx.fmt = opt->commit_format; ctx.mailmap = opt->mailmap; ctx.color = opt->diffopt.use_color; ctx.expand_tabs_in_log = opt->expand_tabs_in_log; ctx.output_encoding = get_log_output_encoding(); if (opt->from_ident.mail_begin && opt->from_ident.name_begin) ctx.from_ident = &opt->from_ident; if (opt->graph) ctx.graph_width = graph_width(opt->graph); pretty_print_commit(&ctx, commit, &msgbuf); if (opt->add_signoff) append_signoff(&msgbuf, 0, APPEND_SIGNOFF_DEDUP); if ((ctx.fmt != CMIT_FMT_USERFORMAT) && ctx.notes_message && *ctx.notes_message) { if (cmit_fmt_is_mail(ctx.fmt)) { strbuf_addstr(&msgbuf, "---\n"); opt->shown_dashes = 1; } strbuf_addstr(&msgbuf, ctx.notes_message); } if (opt->show_log_size) { fprintf(opt->diffopt.file, "log size %i\n", (int)msgbuf.len); graph_show_oneline(opt->graph); } /* * Set opt->missing_newline if msgbuf doesn't * end in a newline (including if it is empty) */ if (!msgbuf.len || msgbuf.buf[msgbuf.len - 1] != '\n') opt->missing_newline = 1; else opt->missing_newline = 0; graph_show_commit_msg(opt->graph, opt->diffopt.file, &msgbuf); if (opt->use_terminator && !commit_format_is_empty(opt->commit_format)) { if (!opt->missing_newline) graph_show_padding(opt->graph); putc(opt->diffopt.line_termination, opt->diffopt.file); } strbuf_release(&msgbuf); free(ctx.notes_message); }