Support a --quiet option in the test-suite.
[gitweb.git] / log-tree.c
index dbd06490f97c735171974f068b48dbdbbb992723..62edd344558049f05c33888de9d2fc2a854b51e9 100644 (file)
@@ -4,6 +4,8 @@
 #include "log-tree.h"
 #include "reflog-walk.h"
 
+struct decoration name_decoration = { "object names" };
+
 static void show_parents(struct commit *commit, int abbrev)
 {
        struct commit_list *p;
@@ -13,6 +15,23 @@ static void show_parents(struct commit *commit, int abbrev)
        }
 }
 
+static void show_decorations(struct commit *commit)
+{
+       const char *prefix;
+       struct name_decoration *decoration;
+
+       decoration = lookup_decoration(&name_decoration, &commit->object);
+       if (!decoration)
+               return;
+       prefix = " (";
+       while (decoration) {
+               printf("%s%s", prefix, decoration->name);
+               prefix = ", ";
+               decoration = decoration->next;
+       }
+       putchar(')');
+}
+
 /*
  * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
  * Signed-off-by: and Acked-by: lines.
@@ -60,16 +79,14 @@ static int detect_any_signoff(char *letter, int size)
        return seen_head && seen_name;
 }
 
-static int append_signoff(char *buf, int buf_sz, int at, const char *signoff)
+static void append_signoff(struct strbuf *sb, const char *signoff)
 {
        static const char signed_off_by[] = "Signed-off-by: ";
-       int signoff_len = strlen(signoff);
+       size_t signoff_len = strlen(signoff);
        int has_signoff = 0;
-       char *cp = buf;
+       char *cp;
 
-       /* Do we have enough space to add it? */
-       if (buf_sz - at <= strlen(signed_off_by) + signoff_len + 3)
-               return at;
+       cp = sb->buf;
 
        /* First see if we already have the sign-off by the signer */
        while ((cp = strstr(cp, signed_off_by))) {
@@ -77,29 +94,25 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff)
                has_signoff = 1;
 
                cp += strlen(signed_off_by);
-               if (cp + signoff_len >= buf + at)
+               if (cp + signoff_len >= sb->buf + sb->len)
                        break;
                if (strncmp(cp, signoff, signoff_len))
                        continue;
                if (!isspace(cp[signoff_len]))
                        continue;
                /* we already have him */
-               return at;
+               return;
        }
 
        if (!has_signoff)
-               has_signoff = detect_any_signoff(buf, at);
+               has_signoff = detect_any_signoff(sb->buf, sb->len);
 
        if (!has_signoff)
-               buf[at++] = '\n';
-
-       strcpy(buf + at, signed_off_by);
-       at += strlen(signed_off_by);
-       strcpy(buf + at, signoff);
-       at += signoff_len;
-       buf[at++] = '\n';
-       buf[at] = 0;
-       return at;
+               strbuf_addch(sb, '\n');
+
+       strbuf_addstr(sb, signed_off_by);
+       strbuf_add(sb, signoff, signoff_len);
+       strbuf_addch(sb, '\n');
 }
 
 static unsigned int digits_in_number(unsigned int number)
@@ -114,13 +127,12 @@ static unsigned int digits_in_number(unsigned int number)
 
 void show_log(struct rev_info *opt, const char *sep)
 {
-       static char this_header[16384];
+       struct strbuf msgbuf;
        struct log_info *log = opt->loginfo;
        struct commit *commit = log->commit, *parent = log->parent;
        int abbrev = opt->diffopt.abbrev;
        int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
        const char *extra;
-       int len;
        const char *subject = NULL, *extra_headers = opt->extra_headers;
 
        opt->loginfo = NULL;
@@ -136,6 +148,7 @@ void show_log(struct rev_info *opt, const char *sep)
                fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
                if (opt->parents)
                        show_parents(commit, abbrev_commit);
+               show_decorations(commit);
                putchar(opt->diffopt.line_termination);
                return;
        }
@@ -165,14 +178,20 @@ void show_log(struct rev_info *opt, const char *sep)
                if (opt->total > 0) {
                        static char buffer[64];
                        snprintf(buffer, sizeof(buffer),
-                                       "Subject: [PATCH %0*d/%d] ",
+                                       "Subject: [%s %0*d/%d] ",
+                                       opt->subject_prefix,
                                        digits_in_number(opt->total),
                                        opt->nr, opt->total);
                        subject = buffer;
-               } else if (opt->total == 0)
-                       subject = "Subject: [PATCH] ";
-               else
+               } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
+                       static char buffer[256];
+                       snprintf(buffer, sizeof(buffer),
+                                       "Subject: [%s] ",
+                                       opt->subject_prefix);
+                       subject = buffer;
+               } else {
                        subject = "Subject: ";
+               }
 
                printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
                if (opt->message_id)
@@ -234,13 +253,14 @@ void show_log(struct rev_info *opt, const char *sep)
                        printf(" (from %s)",
                               diff_unique_abbrev(parent->object.sha1,
                                                  abbrev_commit));
+               show_decorations(commit);
                printf("%s",
                       diff_get_color(opt->diffopt.color_diff, DIFF_RESET));
                putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
                if (opt->reflog_info) {
                        show_reflog_message(opt->reflog_info,
                                    opt->commit_format == CMIT_FMT_ONELINE,
-                                   opt->relative_date);
+                                   opt->date_mode);
                        if (opt->commit_format == CMIT_FMT_ONELINE) {
                                printf("%s", sep);
                                return;
@@ -251,14 +271,18 @@ void show_log(struct rev_info *opt, const char *sep)
        /*
         * And then the pretty-printed message itself
         */
-       len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header,
-                                 sizeof(this_header), abbrev, subject,
-                                 extra_headers, opt->relative_date);
+       strbuf_init(&msgbuf, 0);
+       pretty_print_commit(opt->commit_format, commit, &msgbuf,
+                                 abbrev, subject, extra_headers, opt->date_mode);
 
        if (opt->add_signoff)
-               len = append_signoff(this_header, sizeof(this_header), len,
-                                    opt->add_signoff);
-       printf("%s%s%s", this_header, extra, sep);
+               append_signoff(&msgbuf, opt->add_signoff);
+       if (opt->show_log_size)
+               printf("log size %i\n", (int)msgbuf.len);
+
+       if (msgbuf.len)
+               printf("%s%s%s", msgbuf.buf, extra, sep);
+       strbuf_release(&msgbuf);
 }
 
 int log_tree_diff_flush(struct rev_info *opt)
@@ -280,7 +304,8 @@ int log_tree_diff_flush(struct rev_info *opt)
                 * output for readability.
                 */
                show_log(opt, opt->diffopt.msg_sep);
-               if (opt->verbose_header &&
+               if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
+                   opt->verbose_header &&
                    opt->commit_format != CMIT_FMT_ONELINE) {
                        int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
                        if ((pch & opt->diffopt.output_format) == pch)
@@ -370,5 +395,6 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)
                shown = 1;
        }
        opt->loginfo = NULL;
+       maybe_flush_or_die(stdout, "stdout");
        return shown;
 }