+ unsigned long old_size = 0;
+ unsigned long new_size = 0;
+ int binary = 0;
+
+ files++;
+ if (ctx.repo->enable_log_linecount)
+ cgit_diff_files(&pair->one->oid, &pair->two->oid, &old_size,
+ &new_size, &binary, 0, ctx.qry.ignorews,
+ count_lines);
+}
+
+void show_commit_decorations(struct commit *commit)
+{
+ const struct name_decoration *deco;
+ static char buf[1024];
+
+ buf[sizeof(buf) - 1] = 0;
+ deco = get_name_decoration(&commit->object);
+ if (!deco)
+ return;
+ html("<span class='decoration'>");
+ while (deco) {
+ struct object_id peeled;
+ int is_annotated = 0;
+ strncpy(buf, prettify_refname(deco->name), sizeof(buf) - 1);
+ switch(deco->type) {
+ case DECORATION_NONE:
+ /* If the git-core doesn't recognize it,
+ * don't display anything. */
+ break;
+ case DECORATION_REF_LOCAL:
+ cgit_log_link(buf, NULL, "branch-deco", buf, NULL,
+ ctx.qry.vpath, 0, NULL, NULL,
+ ctx.qry.showmsg, 0);
+ break;
+ case DECORATION_REF_TAG:
+ if (!peel_ref(deco->name, &peeled))
+ is_annotated = !oidcmp(&commit->object.oid, &peeled);
+ cgit_tag_link(buf, NULL, is_annotated ? "tag-annotated-deco" : "tag-deco", buf);
+ break;
+ case DECORATION_REF_REMOTE:
+ if (!ctx.repo->enable_remote_branches)
+ break;
+ cgit_log_link(buf, NULL, "remote-deco", NULL,
+ oid_to_hex(&commit->object.oid),
+ ctx.qry.vpath, 0, NULL, NULL,
+ ctx.qry.showmsg, 0);
+ break;
+ default:
+ cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
+ oid_to_hex(&commit->object.oid),
+ ctx.qry.vpath);
+ break;
+ }
+ deco = deco->next;
+ }
+ html("</span>");
+}
+
+static void handle_rename(struct diff_filepair *pair)
+{
+ /*
+ * After we have seen a rename, we generate links to the previous
+ * name of the file so that commit & diff views get fed the path
+ * that is correct for the commit they are showing, avoiding the
+ * need to walk the entire history leading back to every commit we
+ * show in order detect renames.
+ */
+ if (0 != strcmp(ctx.qry.vpath, pair->two->path)) {
+ free(ctx.qry.vpath);
+ ctx.qry.vpath = xstrdup(pair->two->path);
+ }
+ inspect_files(pair);
+}
+
+static int show_commit(struct commit *commit, struct rev_info *revs)
+{
+ struct commit_list *parents = commit->parents;
+ struct commit *parent;
+ int found = 0, saved_fmt;
+ struct diff_flags saved_flags = revs->diffopt.flags;
+
+ /* Always show if we're not in "follow" mode with a single file. */
+ if (!ctx.qry.follow)
+ return 1;
+
+ /*
+ * In "follow" mode, we don't show merges. This is consistent with
+ * "git log --follow -- <file>".
+ */
+ if (parents && parents->next)
+ return 0;
+
+ /*
+ * If this is the root commit, do what rev_info tells us.
+ */
+ if (!parents)
+ return revs->show_root_diff;
+
+ /* When we get here we have precisely one parent. */
+ parent = parents->item;
+ /* If we can't parse the commit, let print_commit() report an error. */
+ if (parse_commit(parent))
+ return 1;
+
+ files = 0;
+ add_lines = 0;
+ rem_lines = 0;
+
+ revs->diffopt.flags.recursive = 1;
+ diff_tree_oid(&parent->maybe_tree->object.oid,
+ &commit->maybe_tree->object.oid,
+ "", &revs->diffopt);
+ diffcore_std(&revs->diffopt);
+
+ found = !diff_queue_is_empty();
+ saved_fmt = revs->diffopt.output_format;
+ revs->diffopt.output_format = DIFF_FORMAT_CALLBACK;
+ revs->diffopt.format_callback = cgit_diff_tree_cb;
+ revs->diffopt.format_callback_data = handle_rename;
+ diff_flush(&revs->diffopt);
+ revs->diffopt.output_format = saved_fmt;
+ revs->diffopt.flags = saved_flags;
+
+ lines_counted = 1;
+ return found;
+}
+
+static void print_commit(struct commit *commit, struct rev_info *revs)
+{
+ struct commitinfo *info;
+ int columns = revs->graph ? 4 : 3;
+ struct strbuf graphbuf = STRBUF_INIT;
+ struct strbuf msgbuf = STRBUF_INIT;
+
+ if (ctx.repo->enable_log_filecount)
+ columns++;
+ if (ctx.repo->enable_log_linecount)
+ columns++;
+
+ 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", columns);
+ 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(info->committer_date, info->committer_tz, TM_WEEK * 2);
+ 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,
+ oid_to_hex(&commit->object.oid), ctx.qry.vpath);
+ show_commit_decorations(commit);